Patch : dynamic alloc bug and implement p7 list for human read

This commit is contained in:
Lailouezzz 2019-12-31 00:43:01 +01:00
parent 06057a578b
commit acda498903
Signed by: Lailouezzz
GPG Key ID: 03FCE8A99EF8482C
2 changed files with 21 additions and 8 deletions

View File

@ -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;

View File

@ -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;