public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Gabriel Dalimonte <gabriel.dalimonte@gmail.com>
To: u-boot@lists.denx.de
Cc: Gabriel Dalimonte <gabriel.dalimonte@gmail.com>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Tom Rini <trini@konsulko.com>
Subject: [PATCH 4/6] fs: fat: update parent dirs metadata on rename
Date: Wed, 22 Jan 2025 00:32:29 -0500	[thread overview]
Message-ID: <20250122053232.17365-5-gabriel.dalimonte@gmail.com> (raw)
In-Reply-To: <20250122053232.17365-1-gabriel.dalimonte@gmail.com>

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@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


  parent reply	other threads:[~2025-01-22 13:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-22  5:32 [PATCH 0/6] add support for renaming to EFI_FILE_PROTOCOL.SetInfo() Gabriel Dalimonte
2025-01-22  5:32 ` [PATCH 1/6] fs: fat: factor out dentry link create/delete Gabriel Dalimonte
2025-01-22  7:08   ` Heinrich Schuchardt
2025-01-26  4:34     ` Gabriel D'Alimonte
2025-01-22  5:32 ` [PATCH 2/6] fs: add rename infrastructure Gabriel Dalimonte
2025-01-22  8:10   ` Heinrich Schuchardt
2025-01-22  9:18     ` Heinrich Schuchardt
2025-01-26  4:38       ` Gabriel D'Alimonte
2025-01-22  5:32 ` [PATCH 3/6] fs: fat: add rename Gabriel Dalimonte
2025-01-22  8:41   ` Heinrich Schuchardt
2025-01-22  5:32 ` Gabriel Dalimonte [this message]
2025-01-22  9:00   ` [PATCH 4/6] fs: fat: update parent dirs metadata on rename Heinrich Schuchardt
2025-01-26  4:39     ` Gabriel D'Alimonte
2025-01-22  5:32 ` [PATCH 5/6] efi_loader: move path out of file_handle Gabriel Dalimonte
2025-01-22  5:32 ` [PATCH 6/6] efi_loader: support file rename in SetInfo() Gabriel Dalimonte
2025-02-04 12:53   ` Ilias Apalodimas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250122053232.17365-5-gabriel.dalimonte@gmail.com \
    --to=gabriel.dalimonte@gmail.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox