};
-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];
unsigned long block, i, j, mode, uid, size;
long mod_time, m, prot;
+ buf = xmalloc (61 + strlen (fn) + 1);
+
while (*p1 && *p1 == '/') {
p1++;
}
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;
}
if (!(ino = find_entry (ino, p1))) {
if (!list) {
- return 2;
+ report_at (program_name, 0, REPORT_ERROR, "cannot access '%s'", fn);
}
+ return 1;
}
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) {
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;
}
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;
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;
}