From acda498903fd800c7eb4a0aa5b449e46677383f5 Mon Sep 17 00:00:00 2001 From: Lailouezzz Date: Tue, 31 Dec 2019 00:43:01 +0100 Subject: [PATCH] Patch : dynamic alloc bug and implement p7 list for human read --- lib/link/seven_fs/list.c | 12 +++++------- src/p7/main.c | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/link/seven_fs/list.c b/lib/link/seven_fs/list.c index ac3dbe9..cc56876 100644 --- a/lib/link/seven_fs/list.c +++ b/lib/link/seven_fs/list.c @@ -64,7 +64,7 @@ int CASIO_EXPORT casio_sevenfs_list(sevenfs_cookie_t *cookie, sevenfs_path_t *pa /* check answer */ char *dir, *filename, *cdev; unsigned int fs, ldir, lfilename; casio_pathnode_t *fnode = NULL; - casio_stat_t fstat; + casio_stat_t fstat = { 0 }; switch (response.casio_seven_packet_type) { /* - If is roleswap, we have finished our job here - */ @@ -74,7 +74,6 @@ int CASIO_EXPORT casio_sevenfs_list(sevenfs_cookie_t *cookie, sevenfs_path_t *pa /* - If is command, should be another file info - */ case casio_seven_type_cmd: - /* Check args */ dir = response.casio_seven_packet_args[0]; filename = response.casio_seven_packet_args[1]; @@ -87,10 +86,6 @@ int CASIO_EXPORT casio_sevenfs_list(sevenfs_cookie_t *cookie, sevenfs_path_t *pa /* Create node and stat */ ldir = dir ? strlen(dir) : 0; lfilename = filename ? strlen(filename) : 0; - if(dir && filename) { - } else { - casio_make_pathnode(&fnode, 1); - } if(dir && filename) { /* Create node size 2 */ @@ -120,6 +115,9 @@ int CASIO_EXPORT casio_sevenfs_list(sevenfs_cookie_t *cookie, sevenfs_path_t *pa fnode->casio_pathnode_name[ldir] = '\0'; } + fstat.casio_stat_size = fs; + fstat.casio_stat_type = (dir && !filename) ? CASIO_STAT_TYPE_DIR : CASIO_STAT_TYPE_REG; + /* Call callback and free node */ (*callback)(cbcookie, fnode, &fstat); if(dir && filename) { @@ -131,7 +129,7 @@ int CASIO_EXPORT casio_sevenfs_list(sevenfs_cookie_t *cookie, sevenfs_path_t *pa break; default: - // Unknown + /* Unknown */ msg((ll_fatal, "Error packet type unknown")); return (casio_error_unknown); break; diff --git a/src/p7/main.c b/src/p7/main.c index 56d1524..1185b27 100644 --- a/src/p7/main.c +++ b/src/p7/main.c @@ -169,7 +169,21 @@ static void print_file_info(void *cookie, (void)cookie; /* initialize buffer */ static char buf[45]; - printf("callback called : %s\n", node->casio_pathnode_name); + memset(buf, ' ', sizeof(buf)); + + /* File into dir */ + if (node->casio_pathnode_size >= 2) { + char *b = buf; + b += sprintf(b, "%s/", node->casio_pathnode_name); + b[sprintf(b, "%s", node->casio_pathnode_next->casio_pathnode_name)] = ' '; // replace '\0' by ' ' + } else if (node->casio_pathnode_size == 1) { /* Juste one file or dir */ + buf[sprintf(buf, (stat->casio_stat_type == CASIO_STAT_TYPE_DIR) ? "%s/" : "%s", node->casio_pathnode_name)] = ' '; // replace '\0' by ' ' + } + /* Put the size */ + sprintf(&buf[28], "%10uo", (unsigned) stat->casio_stat_size); + + /* Put the string to stdout */ + puts(buf); } /* --- @@ -284,6 +298,7 @@ int main(int ac, char **av) case mn_list: path.casio_path_device = args.storage; casio_make_pathnode(&path.casio_path_nodes, 1); + path.casio_path_flags = casio_pathflag_rel; if ((err = casio_open_seven_fs(&fs, handle)) || (err = casio_list(fs, &path, print_file_info, NULL))) break;