From: Leo C. Date: Tue, 23 Jul 2024 19:07:38 +0000 (+0200) Subject: add fat command mv X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/commitdiff_plain/64db7d7a152ab5677faf83a4ea8370019993b1b5 add fat command mv --- diff --git a/avr/cmd_fat.c b/avr/cmd_fat.c index c97fd79..41821e1 100644 --- a/avr/cmd_fat.c +++ b/avr/cmd_fat.c @@ -408,6 +408,19 @@ void ff_copy(const TCHAR* path_old, const TCHAR* path_new) return; } +void ff_move(const TCHAR* path_old, const TCHAR* path_new) +{ + FRESULT res; + + if (cmd_flags & V_FLAG) + printf_P(PSTR("'%s' -> '%s'\n"), path_old, path_new); + if ((res = f_rename(path_old, path_new)) != FR_OK) + cmd_error(0, res, PSTR("error copying '%s' to '%s'"), path_old, path_new); + + exit_val = (res != FR_OK); + return; +} + void ff_iterate(fatfunc_t fatfunc, int count, char* const file[], char* dest) { FRESULT res = 0; @@ -491,10 +504,11 @@ command_ret_t do_rm(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, return exit_val; } -command_ret_t do_cp(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[]) +command_ret_t do_cp_or_mv(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[]) { exit_val = CMD_RET_SUCCESS; cmd_flags = 0; + fatfunc_t func = (argv[0][0] == 'c') ? ff_copy : ff_move; int opt; while ((opt = getopt(argc, argv, PSTR("v"))) != -1) { @@ -515,7 +529,7 @@ command_ret_t do_cp(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, if (argc < 2) return CMD_RET_USAGE; - ff_iterate(ff_copy, argc - 1, argv, argv[argc - 1]); + ff_iterate(func, argc - 1, argv, argv[argc - 1]); return exit_val; } @@ -851,7 +865,7 @@ CMD_TBL_ITEM( " -v explain what is being done" ), CMD_TBL_ITEM( - cp, CONFIG_SYS_MAXARGS, 0, do_cp, + cp, CONFIG_SYS_MAXARGS, 0, do_cp_or_mv, "Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.", "[OPTION]... SOURCE... DEST\n" // " -f overwrite existing file ignoring write protection\n" @@ -861,6 +875,12 @@ CMD_TBL_ITEM( // " -p preserve attributes and timestamps\n" " -v explain what is being done" ), +CMD_TBL_ITEM( + mv, CONFIG_SYS_MAXARGS, 0, do_cp_or_mv, + "Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.", + "[OPTION]... SOURCE DEST\n" + " -v explain what is being done" +), CMD_TBL_ITEM( load, 5, 0, do_rw,