[PATCH 4/6] fs: fat: update parent dirs metadata on rename
Gabriel Dalimonte
gabriel.dalimonte at gmail.com
Wed Jan 22 06:32:29 CET 2025
None of the existing fat code appears to update parent dir properties
however, the POSIX specification for rename() mentions that the
last modified timestamp should be updated. In addition, I believe
the ATTR_ARCH attribute should also be reset on the parent directories
as the content of those directories has changed.
Signed-off-by: Gabriel Dalimonte <gabriel.dalimonte at gmail.com>
---
fs/fat/fat_write.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index f9f7051e30..2559e38d5b 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -1912,6 +1912,42 @@ exit:
return ret;
}
+/**
+ * update_parent_dir_props - updates the modified time and resets the archive
+ * attribute for the parent directory
+ *
+ * @itr: iterator positioned anywhere in a directory whose parent should be
+ * updated
+ * @Return: 0 for success
+ */
+static int update_parent_dir_props(fat_itr *itr)
+{
+ int ret = 0;
+ __u32 target_clust = itr->start_clust;
+ /* For START macro */
+ fsdata *mydata = itr->fsdata;
+
+ if (!itr->is_root) {
+ ret = fat_itr_parent(itr);
+ if (ret)
+ return ret;
+
+ while (fat_itr_next(itr)) {
+ if (START(itr->dent) == target_clust)
+ goto update;
+ }
+
+ /* dent not found */
+ return -EIO;
+update:
+ dentry_set_time(itr->dent);
+ itr->dent->attr |= ATTR_ARCH;
+ ret = flush_dir(itr);
+ }
+
+ return ret;
+}
+
/**
* fat_rename - rename/move a file or directory
*
@@ -2086,7 +2122,12 @@ int fat_rename(const char *old_path, const char *new_path)
ret = flush_dir(new_itr);
if (ret)
goto exit;
+ /* restore directory location to update parent props below */
+ fat_itr_child(new_itr, new_itr);
}
+ ret = update_parent_dir_props(new_itr);
+ if (ret)
+ goto exit;
/* refresh old in case write happened to the same block. */
ret = fat_move_to_cluster(old_itr, old_itr->dent_clust);
@@ -2097,6 +2138,7 @@ int fat_rename(const char *old_path, const char *new_path)
if (ret)
goto exit;
+ ret = update_parent_dir_props(old_itr);
exit:
free(new_datablock.fatbuf);
free(old_datablock.fatbuf);
--
2.34.1
More information about the U-Boot
mailing list