This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new b99e7617aa fs/inode: refresh tcb after each file sync() is completed
b99e7617aa is described below
commit b99e7617aa2fa70f8724a2a7db4b08e723a09bb4
Author: chao an <[email protected]>
AuthorDate: Tue Oct 22 13:26:41 2024 +0800
fs/inode: refresh tcb after each file sync() is completed
After tcb is destroyed, it is very dangerous to back reference tcb through
file.
This commit will perform file operations while ensuring the validity of tcb
during
fsync, with will avoid tcb check in each subsystem.
Signed-off-by: chao an <[email protected]>
---
fs/inode/fs_files.c | 29 ++++++++++++++++++++---------
1 file changed, 20 insertions(+), 9 deletions(-)
diff --git a/fs/inode/fs_files.c b/fs/inode/fs_files.c
index 42cd054759..8374ad06d3 100644
--- a/fs/inode/fs_files.c
+++ b/fs/inode/fs_files.c
@@ -208,32 +208,43 @@ static int files_extend(FAR struct filelist *list, size_t
row)
static void task_fssync(FAR struct tcb_s *tcb, FAR void *arg)
{
- FAR struct filelist *list;
+ FAR struct tcb_s *ctcb;
+ FAR struct file *filep;
+ int pid = tcb->pid;
+ uint8_t rows;
int i;
int j;
- list = files_getlist(tcb);
- if (list == NULL)
+ if (tcb->group == NULL)
{
return;
}
- for (i = 0; i < list->fl_rows; i++)
+ rows = tcb->group->tg_filelist.fl_rows;
+
+ for (i = 0; i < rows; i++)
{
for (j = 0; j < CONFIG_NFILE_DESCRIPTORS_PER_BLOCK; j++)
{
- FAR struct file *filep;
+ ctcb = nxsched_get_tcb(pid);
+ if (ctcb == NULL || ctcb->group == NULL || ctcb != tcb)
+ {
+ return;
+ }
- filep = files_fget_by_index(list, i, j, NULL);
+ filep = files_fget_by_index(&ctcb->group->tg_filelist,
+ i, j, NULL);
if (filep != NULL)
{
file_fsync(filep);
- fs_putfilep(filep);
+ ctcb = nxsched_get_tcb(pid);
+ if (ctcb != NULL && ctcb->group != NULL && ctcb == tcb)
+ {
+ fs_putfilep(filep);
+ }
}
}
}
-
- files_putlist(list);
}
/****************************************************************************