]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
fat cp: block buffer --> heap
authorLeo C <erbl259-lmu@yahoo.de>
Wed, 11 Apr 2018 23:53:08 +0000 (01:53 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Wed, 11 Apr 2018 23:53:08 +0000 (01:53 +0200)
avr/cmd_fat.c
include/debug.h

index 29d96dec13becbd934fb999ae0525d3a7ef5bb24..303cf7a7a3b2d363095c2702cf20d7069e7d8265 100644 (file)
@@ -551,16 +551,24 @@ setfile(FILINFO *fs, FIL *fd)
 
 void copy_file(FILINFO *fs, uint_fast8_t dne)
 {
-       static char buf[MAXBSIZE];
        FIL from_fd, to_fd;
        UINT rcount, wcount;
        //FILINFO to_stat;
        //char *p;
        FRESULT fr;
 
-debug("==== copy_file(): dne: %u\n", dne);
+       int buf_size = get_freemem() / 512 * 512;
+       uint8_t * buf = (uint8_t *) malloc(buf_size);
+       if (buf == NULL) {
+               free(buf);
+               err(PSTR("cp: Out of Memory!\n"));
+               return;
+       }
+
+debug("==== copy_file(): dne: %u, buf_zize: %d\n", dne, buf_size);
 debug("     from:'%s'  to:'%s'\n", from->p_path, to->p_path);
 
+
        if ((fr = f_open(&from_fd, from->p_path, FA_READ)) != FR_OK) {
                err(PSTR("%s: %S"), from->p_path, rctostr(fr));
                return;
@@ -576,7 +584,7 @@ debug("     from:'%s'  to:'%s'\n", from->p_path, to->p_path);
         */
        if (!dne) {
                if (flags & I_FLAG) {
-                       printf_P(PSTR("overwrite %s? "), to->p_path);
+                       printf_P(PSTR("overwrite '%s'? "), to->p_path);
                        if (!confirm_yes()) {
                                f_close(&from_fd);
                                return;
@@ -592,7 +600,7 @@ debug("     from:'%s'  to:'%s'\n", from->p_path, to->p_path);
                return;
        }
 
-       while ((fr = f_read(&from_fd, buf, MAXBSIZE, &rcount)) == FR_OK &&
+       while ((fr = f_read(&from_fd, buf, buf_size, &rcount)) == FR_OK &&
                                                                                        rcount > 0) {
                fr = f_write(&to_fd, buf, rcount, &wcount);
                if (fr || wcount < rcount) {
index ae6f28ae1ba8c43f5676f22fe8afa25de63c0239..b7b6deafb5497f58206aca825e9a2334dcc9f0ea 100644 (file)
@@ -21,6 +21,7 @@ command_ret_t do_pr_free_avr(cmd_tbl_t *, uint_fast8_t, int, char * const []);
 command_ret_t do_pr_heap_avr(cmd_tbl_t *, uint_fast8_t, int, char * const []);
 
 void printfreelist(const char * title);
+size_t get_freemem(void);
 
 
 #ifdef DEBUG