]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/cmd_fat.c
Add CP/M 3 file i/o (initial version)
[z180-stamp.git] / avr / cmd_fat.c
index df2ae69fccde3895ad42b11e270c8facd278e1cc..c5791e55eed2fcda1d4e30bc062ec6be5a32f40e 100644 (file)
@@ -1,3 +1,13 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * FAT filesystem commands
+ */
+
 #include "common.h"
 #include <stdlib.h>
 #include <string.h>
@@ -12,8 +22,8 @@
 #include "timer.h"
 #include "debug.h"
 
-
-#define MAX_MEMORY     (1ul << 20)
+/* TODO: use memory size test function (cmd_mem.c) */
+#define MAX_MEMORY     (1ul << 19)
 #define BUFFER_SIZE    512
 
 
@@ -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 );