From: Robert Pengelly Date: Sat, 26 Oct 2024 03:42:51 +0000 (+0100) Subject: Bug and formatting fixes X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;h=89bd93dcdd8e7d73651bfb8d9d55250005f91a4d;p=minixfstools.git Bug and formatting fixes --- diff --git a/mcopy.c b/mcopy.c index fd0d3da..bc48cde 100644 --- a/mcopy.c +++ b/mcopy.c @@ -417,9 +417,9 @@ static int walk_path (char *dirname) { if (!(ino = find_entry (ino, p1))) { - *p2 = '/'; + report_at (program_name, 0, REPORT_ERROR, "cannot access '%s'", dirname); - report_at (program_name, 0, REPORT_ERROR, "failed to enter '%s'", dirname); + *p2 = '/'; return 0; } @@ -430,7 +430,7 @@ static int walk_path (char *dirname) { if (!(ino = find_entry (ino, p1))) { - report_at (program_name, 0, REPORT_ERROR, "failed to enter '%s'", dirname); + report_at (program_name, 0, REPORT_ERROR, "cannot access '%s'", dirname); return 0; } @@ -585,6 +585,6 @@ int main (int argc, char **argv) { } - return EXIT_SUCCESS; + return (get_error_count () > 0) ? EXIT_FAILURE : EXIT_SUCCESS; } diff --git a/mls.c b/mls.c index 2b6c960..9411d92 100644 --- a/mls.c +++ b/mls.c @@ -371,10 +371,13 @@ static char *rwx[] = { }; -static int walk_dir (char *dirname, int list, int multi) { +static char **files = 0; +static long nb_files = 0; +static int walk_dir (char *fn, int list, int multi) { + + char *p1 = fn, dt[32], *buf, *p2, *m1, *m2, *m3, c; unsigned long ino = first_inode; - char *p1 = dirname, dt[32], *p2, *m1, *m2, *m3, c; struct inode inode[INODES_PER_BLOCK], inode2[INODES_PER_BLOCK]; struct dirent de[NR_DIR_ENTRIES]; @@ -385,6 +388,8 @@ static int walk_dir (char *dirname, int list, int multi) { unsigned long block, i, j, mode, uid, size; long mod_time, m, prot; + buf = xmalloc (61 + strlen (fn) + 1); + while (*p1 && *p1 == '/') { p1++; } @@ -401,11 +406,12 @@ static int walk_dir (char *dirname, int list, int multi) { if (!(ino = find_entry (ino, p1))) { - *p2 = '/'; - if (!list) { - return 1; + report_at (program_name, 0, REPORT_ERROR, "cannot access '%s'", fn); } + + *p2 = '/'; + return 1; } @@ -416,9 +422,10 @@ static int walk_dir (char *dirname, int list, int multi) { if (!(ino = find_entry (ino, p1))) { if (!list) { - return 2; + report_at (program_name, 0, REPORT_ERROR, "cannot access '%s'", fn); } + return 1; } @@ -436,7 +443,7 @@ static int walk_dir (char *dirname, int list, int multi) { if (list) { - if (multi) { printf ("%s:\n\n", dirname); } + if (multi) { printf ("%s:\n\n", fn); } for (i = 0; i < NR_DZONE_NUM * 2; i += 2) { @@ -558,19 +565,22 @@ static int walk_dir (char *dirname, int list, int multi) { m2 = rwx[prot]; m3 = rwx[m & 07]; - printf ("%c%s%s%s %2d", c, m1, m2, m3, ip1->i_nlinks); - + sprintf (buf, "%c%s%s%s %2d", c, m1, m2, m3, ip1->i_nlinks); + size = ((unsigned long) ip1->i_size[0]) | (((unsigned long) ip1->i_size[1]) << 8) | (((unsigned long) ip1->i_size[2]) << 16) | (((unsigned long) ip1->i_size[3]) << 24); - printf (" %10lu", size); + sprintf (buf + 14, " %10lu", size); uid = ((unsigned long) ip1->uid[0]) | (((unsigned long) ip1->uid[1]) << 8); - printf (" %2ld", uid); + sprintf (buf + 26, " %2ld", uid); mod_time = ((unsigned long) ip1->i_mod_time[0]) | (((unsigned long) ip1->i_mod_time[1]) << 8) | (((unsigned long) ip1->i_mod_time[2]) << 16) | (((unsigned long) ip1->i_mod_time[3]) << 24); strftime (dt, sizeof (dt), "%Y-%m-%d %H:%M:%S", localtime (&mod_time)); + /*strftime (dt, sizeof (dt), "%b %d %Y %H:%M:%S", localtime (&mod_time));*/ + + sprintf (buf + 30, " %2d %s %s", ip1->gid, dt, fn); - printf (" %2d %s %s\n", ip1->gid, dt, dirname); - return 3; + dynarray_add (&files, &nb_files, buf); + return 2; } @@ -579,7 +589,7 @@ int main (int argc, char **argv) { struct super_block sup = { 0 }; unsigned long s_imap_blocks, s_zmap_blocks; - long multi = 0, i; + long errors = 0, i; char **found_entries = 0; long nb_found_entries = 0; @@ -637,32 +647,32 @@ int main (int argc, char **argv) { int ret = walk_dir (entries[i], 0, 0); - if (ret == 0 || ret == 3) { - - if (ret == 0) { - dynarray_add (&found_entries, &nb_found_entries, entries[i]); - } - - multi++; - + if (ret == 0) { + dynarray_add (&found_entries, &nb_found_entries, entries[i]); } else if (ret == 1) { - report_at (program_name, 0, REPORT_ERROR, "unable to enter '%s'", entries[i]); - } else if (ret == 2) { - report_at (program_name, 0, REPORT_ERROR, "unable to list '%s'", entries[i]); + errors++; } } - if (multi > 1) { printf ("\n"); } + if (nb_files > 0 || errors > 0) { + + for (i = 0; i < nb_files; i++) { + printf ("%s\n", files[i]); + } + + printf ("\n"); + + } for (i = 0; i < nb_found_entries; i++) { if (found_entries[i]) { - walk_dir (found_entries[i], 1, multi > 1); + walk_dir (found_entries[i], 1, nb_entries > 1); } } - return EXIT_SUCCESS; + return (get_error_count () > 0) ? EXIT_FAILURE : EXIT_SUCCESS; } diff --git a/mmd.c b/mmd.c index bc2bf92..a22e6a9 100644 --- a/mmd.c +++ b/mmd.c @@ -386,9 +386,9 @@ static void walk_dir (char *dirname) { if (!(parent_ino = find_entry (parent_ino, p1))) { - *p2 = '/'; + report_at (program_name, 0, REPORT_ERROR, "cannot access '%s'", dirname); - report_at (program_name, 0, REPORT_ERROR, "failed to enter '%s'", dirname); + *p2 = '/'; return; } @@ -492,6 +492,6 @@ int main (int argc, char **argv) { walk_dir (dirs[i]); } - return EXIT_SUCCESS; + return (get_error_count () > 0) ? EXIT_FAILURE : EXIT_SUCCESS; }