On 2/7/25 13:45, Daniel Venzin wrote:
The FAT rename file command supports renaming of a file,
used by fs_test test suite.

Signed-off-by: Daniel Venzin <daniel.ven...@mt.com>

---

Changes in v3:
- Add fatrnfile command for renaming files in a FAT file system

  cmd/fat.c    | 13 +++++++++++++
  fs/fs.c      | 20 ++++++++++++++++++++
  include/fs.h |  2 ++
  3 files changed, 35 insertions(+)

diff --git a/cmd/fat.c b/cmd/fat.c
index 5b7484dc1af..c66583cb427 100644
--- a/cmd/fat.c
+++ b/cmd/fat.c
@@ -132,4 +132,17 @@ U_BOOT_CMD(
        "<interface> [<dev[:part]>] <directory>\n"
        "    - create a directory in 'dev' on 'interface'"
  );
+
+static int do_fat_rnfile(struct cmd_tbl *cmdtp, int flag, int argc,
+                       char *const argv[])
+{
+       return do_rnfile(cmdtp, flag, argc, argv, FS_TYPE_FAT);
+}
+
+U_BOOT_CMD(
+       fatrnfile,      5,      1,      do_fat_rnfile,
+       "rename a file",
+       "<interface> [<dev[:part]>] <source> <destination>\n"
+       "    - rename <source> to <destination> in 'dev' on 'interface'"
+);
  #endif
diff --git a/fs/fs.c b/fs/fs.c
index 3576d5c6644..fafe00cdb9c 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -990,6 +990,26 @@ int do_mkdir(struct cmd_tbl *cmdtp, int flag, int argc, 
char *const argv[],
        return 0;
  }

+int do_rnfile(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
+            int fstype)
+{
+       int ret;
+
+       if (argc != 5)
+               return CMD_RET_USAGE;
+
+       if (fs_set_blk_dev(argv[1], argv[2], fstype))
+               return 1;
+
+       ret = fs_rename(argv[3], argv[4]);
+       if (ret) {
+               log_err("** Unable to rename file from \"%s\" to \"%s\" **\n", 
argv[3], argv[4]);
+               return 1;

The test should test not only test the positive case but also the cases
where we expect moving or renaming a file to fail.

Best regards

Heinrich

+       }
+
+       return 0;
+}
+
  int do_ln(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
          int fstype)
  {
diff --git a/include/fs.h b/include/fs.h
index 8c1aa9c1a7b..79dc442ea75 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -297,6 +297,8 @@ int do_rm(struct cmd_tbl *cmdtp, int flag, int argc, char 
*const argv[],
          int fstype);
  int do_mkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
             int fstype);
+int do_rnfile(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
+            int fstype);
  int do_ln(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
          int fstype);


Reply via email to