1.1 --- a/libe2access/host/e2access.c Sat Feb 19 01:34:52 2022 +0100
1.2 +++ b/libe2access/host/e2access.c Thu Feb 24 22:34:43 2022 +0100
1.3 @@ -26,6 +26,7 @@
1.4
1.5 #include <sys/types.h>
1.6 #include <sys/stat.h>
1.7 +#include <sys/sysmacros.h> /* major, minor */
1.8
1.9 #include <ext2fs/ext2fs.h>
1.10
1.11 @@ -216,11 +217,10 @@
1.12 const char *target = argv[argc - 1];
1.13 const char *target_remaining = argv[argc - 1];
1.14 const char *basename;
1.15 - int target_is_file;
1.16
1.17 /* Target file and directory details. */
1.18
1.19 - int target_is_new;
1.20 + int target_is_file, target_is_new;
1.21 ext2_ino_t ino_file, ino_target;
1.22 int flags;
1.23
1.24 @@ -649,6 +649,60 @@
1.25 return 0;
1.26 }
1.27
1.28 +/* Show statistics for files and directories. */
1.29 +
1.30 +int stat_objects(ext2_filsys fs, int argc, char *argv[])
1.31 +{
1.32 + int i;
1.33 + const char *path;
1.34 + ext2_ino_t ino;
1.35 + struct stat st;
1.36 +
1.37 + for (i = 0; i < argc; i++)
1.38 + {
1.39 + path = argv[i];
1.40 +
1.41 + /* Detect missing objects. */
1.42 +
1.43 + if (image_find_by_path(fs, path, &ino))
1.44 + {
1.45 + fprintf(stderr, "Not found: %s\n", path);
1.46 + return 1;
1.47 + }
1.48 +
1.49 + /* Even though the statistics could be read directly out of ext2 data
1.50 + structures, it is convenient to use the standard stat structure. */
1.51 +
1.52 + if (image_stat_inode(fs, ino, &st))
1.53 + {
1.54 + fprintf(stderr, "Cannot stat object: %s\n", path);
1.55 + return 1;
1.56 + }
1.57 +
1.58 + /* Terse stat output:
1.59 + %n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %W %o %C */
1.60 +
1.61 + printf("%s %ld %ld %x %d %d ",
1.62 + path, st.st_size, st.st_blocks, st.st_mode, st.st_uid, st.st_gid);
1.63 +
1.64 + printf("%d %d %d %x %x ",
1.65 + st.st_dev, st.st_ino, st.st_nlink,
1.66 + major(st.st_rdev), minor(st.st_rdev));
1.67 +
1.68 + printf("%d %d %d ",
1.69 + st.st_atim, st.st_mtim, st.st_ctim);
1.70 +
1.71 + /* NOTE: Arbitrary values:
1.72 + %W (creation time) given as 0
1.73 + %o (I/O transfer size hint) given as 0
1.74 + %C (SELinux security context) given as empty string */
1.75 +
1.76 + printf("%d %d %s\n",
1.77 + 0, 0, "");
1.78 + }
1.79 +
1.80 + return 0;
1.81 +}
1.82
1.83
1.84
1.85 @@ -677,6 +731,7 @@
1.86 mkdir Make directories within the image\n\
1.87 rm Remove non-directory objects from the image\n\
1.88 rmdir Remove directories from the image\n\
1.89 + stat Show statistics for files and directories\n\
1.90 \n\
1.91 Script operations:\n\
1.92 \n\
1.93 @@ -699,6 +754,7 @@
1.94 {"rm", remove_non_dirs},
1.95 {"rmdir", remove_dirs},
1.96 {"script", run_script},
1.97 + {"stat", stat_objects},
1.98 {NULL, NULL},
1.99 };
1.100