1
0
Fork 0

Change read to return LFS return values when reading a directory or nonexistant file

This commit is contained in:
Tim Keller 2021-11-20 20:18:14 +00:00
parent 09b9130244
commit b62c62ee1f

View file

@ -89,7 +89,7 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
resp.chunkoff = header->chunkoff; resp.chunkoff = header->chunkoff;
int res = fs.Stat(filepath, &info); int res = fs.Stat(filepath, &info);
if (res == LFS_ERR_NOENT && info.type != LFS_TYPE_DIR) { if (res == LFS_ERR_NOENT && info.type != LFS_TYPE_DIR) {
resp.status = 0x03; resp.status = (int8_t) res;
resp.chunklen = 0; resp.chunklen = 0;
resp.totallen = 0; resp.totallen = 0;
om = ble_hs_mbuf_from_flat(&resp, sizeof(ReadResponse)); om = ble_hs_mbuf_from_flat(&resp, sizeof(ReadResponse));
@ -118,7 +118,7 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
resp.chunkoff = header->chunkoff; resp.chunkoff = header->chunkoff;
int res = fs.Stat(filepath, &info); int res = fs.Stat(filepath, &info);
if (res == LFS_ERR_NOENT && info.type != LFS_TYPE_DIR) { if (res == LFS_ERR_NOENT && info.type != LFS_TYPE_DIR) {
resp.status = 0x03; resp.status = (int8_t) res;
resp.chunklen = 0; resp.chunklen = 0;
resp.totallen = 0; resp.totallen = 0;
} else { } else {
@ -157,7 +157,7 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
resp.offset = header->offset; resp.offset = header->offset;
resp.modTime = 0; resp.modTime = 0;
int res = fs.FileOpen(&f, filepath, LFS_O_WRONLY | LFS_O_CREAT); int res = fs.FileOpen(&f, filepath, LFS_O_WRONLY | LFS_O_CREAT);
resp.status = (res==0) ? 0x01: (int8_t)res; resp.status = (res == 0) ? 0x01 : (int8_t) res;
fs.FileClose(&f); fs.FileClose(&f);
resp.freespace = std::min(fs.getSize() - (fs.GetFSSize() * fs.getBlockSize()), fileSize - header->offset); resp.freespace = std::min(fs.getSize() - (fs.GetFSSize() * fs.getBlockSize()), fileSize - header->offset);
auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(WriteResponse)); auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(WriteResponse));
@ -171,13 +171,13 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
WriteResponse resp; WriteResponse resp;
resp.command = commands::WRITE_PACING; resp.command = commands::WRITE_PACING;
resp.offset = header->offset; resp.offset = header->offset;
resp.status = 1; resp.status = 0x01;
fs.FileOpen(&f, filepath, LFS_O_RDWR | LFS_O_CREAT); fs.FileOpen(&f, filepath, LFS_O_RDWR | LFS_O_CREAT);
fs.FileSeek(&f, header->offset); fs.FileSeek(&f, header->offset);
int res = fs.FileWrite(&f, header->data, header->dataSize); int res = fs.FileWrite(&f, header->data, header->dataSize);
fs.FileClose(&f); fs.FileClose(&f);
if(res < 0 ){ if (res < 0) {
resp.status = (int8_t)res; resp.status = (int8_t) res;
} }
resp.freespace = std::min(fs.getSize() - (fs.GetFSSize() * fs.getBlockSize()), fileSize - header->offset); resp.freespace = std::min(fs.getSize() - (fs.GetFSSize() * fs.getBlockSize()), fileSize - header->offset);
auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(WriteResponse)); auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(WriteResponse));
@ -194,7 +194,7 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
DelResponse resp {}; DelResponse resp {};
resp.command = commands::DELETE_STATUS; resp.command = commands::DELETE_STATUS;
int res = fs.FileDelete(path); int res = fs.FileDelete(path);
resp.status = (res==0) ? 0x01 : (int8_t)res; resp.status = (res == 0) ? 0x01 : (int8_t) res;
auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(DelResponse)); auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(DelResponse));
ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om); ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om);
break; break;
@ -210,7 +210,7 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
resp.command = commands::MKDIR_STATUS; resp.command = commands::MKDIR_STATUS;
resp.modification_time = 0; resp.modification_time = 0;
int res = fs.DirCreate(path); int res = fs.DirCreate(path);
resp.status = (res==0) ? 0x01 : (int8_t)res; resp.status = (res == 0) ? 0x01 : (int8_t) res;
auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(MKDirResponse)); auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(MKDirResponse));
ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om); ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om);
break; break;
@ -226,13 +226,13 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
ListDirResponse resp {}; ListDirResponse resp {};
resp.command = commands::LISTDIR_ENTRY; resp.command = commands::LISTDIR_ENTRY;
resp.status = 1; resp.status = 0x01;
resp.totalentries = 0; resp.totalentries = 0;
resp.entry = 0; resp.entry = 0;
resp.modification_time = 0; resp.modification_time = 0;
int res = fs.DirOpen(path, &dir); int res = fs.DirOpen(path, &dir);
if (res != 0) { if (res != 0) {
resp.status = (int8_t)res; resp.status = (int8_t) res;
auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(ListDirResponse)); auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(ListDirResponse));
ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om); ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om);
break; break;
@ -290,7 +290,7 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
path[header->NewPathLength] = 0; // Copy and null teminate string path[header->NewPathLength] = 0; // Copy and null teminate string
MoveResponse resp {}; MoveResponse resp {};
resp.command = commands::MOVE_STATUS; resp.command = commands::MOVE_STATUS;
int8_t res = (int8_t)fs.Rename(header->pathstr, path); int8_t res = (int8_t) fs.Rename(header->pathstr, path);
resp.status = (res == 0) ? 1 : res; resp.status = (res == 0) ? 1 : res;
auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(MoveResponse)); auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(MoveResponse));
ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om); ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om);