Skip to content

Conversation

@nicogou
Copy link
Contributor

@nicogou nicogou commented Mar 23, 2025

Added a hook on the FS group that notify applications when a file download/upload has completed.
#87380

@zephyrbot zephyrbot requested review from de-nordic and nordicjm March 23, 2025 16:53
@nicogou nicogou force-pushed the fs-hook-87380 branch 2 times, most recently from 248e873 to bccc023 Compare March 23, 2025 19:52
Comment on lines 202 to 203
status = mgmt_callback_notify(MGMT_EVT_OP_FS_MGMT_UPLOAD_DOWNLOAD_DONE,
&upload_or_download, sizeof(upload_or_download), &err_rc, &err_group);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be a struct which also has the filename

Comment on lines 196 to 199
enum mgmt_cb_return status;
int32_t err_rc;
uint16_t err_group;
zcbor_state_t *zse = ctxt->writer->zs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variables declared at top of scope

Comment on lines 28 to 32
enum {
STATE_NO_UPLOAD_OR_DOWNLOAD = 0,
STATE_UPLOAD,
STATE_DOWNLOAD,
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a name for the enum starting with fs_mgmt_ and FS_MGMT_ prefix on values. Also as other comment states, should be encapsulated within a struct which includes the filename

/** Callback when a file has been accessed, data is fs_mgmt_file_access(). */
MGMT_EVT_OP_FS_MGMT_FILE_ACCESS = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_FS, 0),

MGMT_EVT_OP_FS_MGMT_UPLOAD_DOWNLOAD_DONE = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_FS, 1),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MGMT_EVT_OP_FS_MGMT_FILE_ACCESS_COMPLETE or
MGMT_EVT_OP_FS_MGMT_FILE_ACCESS_FINISHED or MGMT_EVT_OP_FS_MGMT_FILE_ACCESS_DONE perhaps so it fits in the alignment?

@nicogou
Copy link
Contributor Author

nicogou commented Mar 24, 2025

I did the requested changes by using the already existing fs_mgmt_file_access struct to store the filename and operation (read = download, write = upload). I also fixed an error in the comments around the fs_mgmt_file_access_types enum where upload and download where switched.

@nicogou nicogou force-pushed the fs-hook-87380 branch 2 times, most recently from 94a592f to 0935965 Compare March 24, 2025 11:30
@nicogou nicogou requested a review from nordicjm March 24, 2025 16:41
Copy link
Contributor

@nordicjm nordicjm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not tested but changes look OK, some changes to tidy up and remove status since this is a notification hook, doesn't make sense to be able to return an error


strcpy(path, fs_mgmt_ctxt.path);
file_access_data.filename = path;
LOG_ERR("fs_mgmt.c path: %s", file_access_data.filename);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LOG_ERR("fs_mgmt.c path: %s", file_access_data.filename);

enum fs_mgmt_group_events {
/** Callback when a file has been accessed, data is fs_mgmt_file_access(). */
MGMT_EVT_OP_FS_MGMT_FILE_ACCESS = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_FS, 0),
MGMT_EVT_OP_FS_MGMT_FILE_ACCESS = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_FS, 0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go back to old alignment

#if defined(CONFIG_MCUMGR_GRP_FS_FILE_ACCESS_HOOK)
/* Warn application that file download/upload is done. */
status = mgmt_callback_notify(MGMT_EVT_OP_FS_MGMT_FILE_ACCESS_DONE,
&file_access_data, sizeof(file_access_data), &err_rc, &err_group);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

align to the variable on the previous line

enum mgmt_cb_return status;
int32_t err_rc;
uint16_t err_group;
zcbor_state_t *zse = ctxt->writer->zs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zcbor_state_t *zse = ctxt->writer->zs;

struct fs_mgmt_file_access file_access_data;
char path[CONFIG_MCUMGR_GRP_FS_PATH_LEN + 1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
struct fs_mgmt_file_access file_access_data;
char path[CONFIG_MCUMGR_GRP_FS_PATH_LEN + 1];
char path[CONFIG_MCUMGR_GRP_FS_PATH_LEN + 1];
struct fs_mgmt_file_access file_access_data = {
.filename = path,
};

zcbor_state_t *zse = ctxt->writer->zs;

strcpy(path, fs_mgmt_ctxt.path);
file_access_data.filename = path;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
file_access_data.filename = path;

Comment on lines 228 to 231

if (status != MGMT_CB_OK) {
smp_add_cmd_err(zse, err_group, (uint16_t)err_rc);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (status != MGMT_CB_OK) {
smp_add_cmd_err(zse, err_group, (uint16_t)err_rc);
}

The file has been uploaded/downloaded, doesn't really make sense to be able to return an error here

#if defined(CONFIG_MCUMGR_GRP_FS_FILE_ACCESS_HOOK)
struct fs_mgmt_file_access file_access_data;
char path[CONFIG_MCUMGR_GRP_FS_PATH_LEN + 1];
enum mgmt_cb_return status;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
enum mgmt_cb_return status;


#if defined(CONFIG_MCUMGR_GRP_FS_FILE_ACCESS_HOOK)
/* Warn application that file download/upload is done. */
status = mgmt_callback_notify(MGMT_EVT_OP_FS_MGMT_FILE_ACCESS_DONE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
status = mgmt_callback_notify(MGMT_EVT_OP_FS_MGMT_FILE_ACCESS_DONE,
(void)mgmt_callback_notify(MGMT_EVT_OP_FS_MGMT_FILE_ACCESS_DONE, &file_access_data,

@nicogou nicogou force-pushed the fs-hook-87380 branch 2 times, most recently from f637e0a to d6e6425 Compare April 2, 2025 21:30
@nicogou nicogou force-pushed the fs-hook-87380 branch 3 times, most recently from 4bf671a to c6ddf87 Compare April 12, 2025 10:13
@nicogou
Copy link
Contributor Author

nicogou commented Apr 13, 2025

@nordicjm took a little while to come back to this, but I made the requested changes

nordicjm
nordicjm previously approved these changes Apr 14, 2025
/** Callback when a file has been accessed, data is fs_mgmt_file_access(). */
MGMT_EVT_OP_FS_MGMT_FILE_ACCESS = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_FS, 0),

MGMT_EVT_OP_FS_MGMT_FILE_ACCESS_DONE = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_FS, 1),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing a doxygen comment

Added a hook on the FS group that notify applications when a
 file download/upload has completed.

Signed-off-by: Nicolas Goualard <nicolas.goualard@sfr.fr>
@kartben kartben merged commit 27bfeea into zephyrproject-rtos:main Apr 24, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants