X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/6204987c3539b71856b4456f218511530af12c6f..e4c4b148ced1347935dff6200380e90cb3bfcde3:/avr/cmd_fat.c diff --git a/avr/cmd_fat.c b/avr/cmd_fat.c index df2ae69..8ed7ae3 100644 --- a/avr/cmd_fat.c +++ b/avr/cmd_fat.c @@ -1,3 +1,13 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/* + * FAT filesystem commands + */ + #include "common.h" #include #include @@ -290,6 +300,39 @@ command_ret_t do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ return CMD_RET_SUCCESS; } +static +FRESULT mkpath(TCHAR *path) +{ + /* TODO: */ + (void) path; +#if 0 + FILINFO fd + TCHAR *p, *q; + FRESULT ret; + +#if _USE_LFN + fd.lfname = 0; +#endif + + + res = f_stat (path, &fd) + + p = strchr(path, ':'); + if (p == NULL || *++p == '\0' || *p++ != '/') + return FR_OK; + + while ((q = strchr(p, '/')) != NULL) { + *q = '\0'; + ret = f_mkdir(path); + *q = '/'; + if (ret != FR_OK && ret != FR_EXIST) + return ret; + p = q + 1; + } +#endif + + return FR_OK; +} /* * fatread/write - load binary file to/from a dos filesystem @@ -343,6 +386,12 @@ command_ret_t do_fat_rw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ } res = f_mount(FatFs, argv[1], 0); + + if (!res) { + if (dowrite) { + res = mkpath(argv[1]); + } + } if (!res) { res = f_open(&File, argv[1], dowrite ? FA_WRITE | FA_CREATE_ALWAYS : FA_READ );