From ac8bda05fd64f3b5853ca5909b5c06e35232ee7d Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Tue, 12 Sep 2023 11:46:57 +0100 Subject: [PATCH] mgmt: mcumgr: grp: fs_mgmt: Update file upload errors Updates possible return errors for fs mgmt file upload, to clarify when a provided path is on a read-only filesystem or if the mount point does not exist. (cherry picked from commit 0d5c508fc78b002ffae3d4445acb6c5cf4fa8cff) Original-Signed-off-by: Jamie McCrae GitOrigin-RevId: 0d5c508fc78b002ffae3d4445acb6c5cf4fa8cff Change-Id: Ie0cbd96febc2aac1e5281ab64b5539409d526b5b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/4882968 Reviewed-by: Al Semjonovs Commit-Queue: Al Semjonovs Tested-by: ChromeOS Prod (Robot) Tested-by: Al Semjonovs --- include/zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt.h | 6 ++++++ subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt.c | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt.h b/include/zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt.h index 5f07c2ed2d8..b48ea8edc8e 100644 --- a/include/zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt.h +++ b/include/zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt.h @@ -73,6 +73,12 @@ enum fs_mgmt_err_code_t { /** The requested checksum or hash type was not found or is not supported by this build. */ FS_MGMT_ERR_CHECKSUM_HASH_NOT_FOUND, + + /** The specified mount point was not found or is not mounted. */ + FS_MGMT_ERR_MOUNT_POINT_NOT_FOUND, + + /** The specified mount point is that of a read-only filesystem. */ + FS_MGMT_ERR_READ_ONLY_FILESYSTEM, }; #ifdef __cplusplus diff --git a/subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt.c b/subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt.c index 571d4c01515..2d0402fc451 100644 --- a/subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt.c +++ b/subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt.c @@ -425,7 +425,9 @@ static int fs_mgmt_file_upload(struct smp_streamer *ctxt) if (rc == -EINVAL) { rc = FS_MGMT_ERR_FILE_INVALID_NAME; } else if (rc == -ENOENT) { - rc = FS_MGMT_ERR_FILE_NOT_FOUND; + rc = FS_MGMT_ERR_MOUNT_POINT_NOT_FOUND; + } else if (rc == -EROFS) { + rc = FS_MGMT_ERR_READ_ONLY_FILESYSTEM; } else { rc = FS_MGMT_ERR_UNKNOWN; } @@ -909,7 +911,18 @@ static int fs_mgmt_translate_error_code(uint16_t err) int rc; switch (err) { + case FS_MGMT_ERR_FILE_INVALID_NAME: + case FS_MGMT_ERR_CHECKSUM_HASH_NOT_FOUND: + rc = MGMT_ERR_EINVAL; + break; + + case FS_MGMT_ERR_FILE_NOT_FOUND: + case FS_MGMT_ERR_MOUNT_POINT_NOT_FOUND: + rc = MGMT_ERR_ENOENT; + break; + case FS_MGMT_ERR_UNKNOWN: + case FS_MGMT_ERR_FILE_IS_DIRECTORY: case FS_MGMT_ERR_FILE_OPEN_FAILED: case FS_MGMT_ERR_FILE_SEEK_FAILED: case FS_MGMT_ERR_FILE_READ_FAILED: @@ -918,6 +931,7 @@ static int fs_mgmt_translate_error_code(uint16_t err) case FS_MGMT_ERR_FILE_WRITE_FAILED: case FS_MGMT_ERR_FILE_OFFSET_NOT_VALID: case FS_MGMT_ERR_FILE_OFFSET_LARGER_THAN_FILE: + case FS_MGMT_ERR_READ_ONLY_FILESYSTEM: default: rc = MGMT_ERR_EUNKNOWN; }