# HG changeset patch # User Paul Boddie # Date 1645738483 -3600 # Node ID dd4fc2b5a18c7322b005de46aa06a1e0f3cee5e8 # Parent 9edfe5795697a1580331366832f936bde834fd30 Added a stat operation. diff -r 9edfe5795697 -r dd4fc2b5a18c libe2access/host/e2access.c --- a/libe2access/host/e2access.c Sat Feb 19 01:34:52 2022 +0100 +++ b/libe2access/host/e2access.c Thu Feb 24 22:34:43 2022 +0100 @@ -26,6 +26,7 @@ #include #include +#include /* major, minor */ #include @@ -216,11 +217,10 @@ const char *target = argv[argc - 1]; const char *target_remaining = argv[argc - 1]; const char *basename; - int target_is_file; /* Target file and directory details. */ - int target_is_new; + int target_is_file, target_is_new; ext2_ino_t ino_file, ino_target; int flags; @@ -649,6 +649,60 @@ return 0; } +/* Show statistics for files and directories. */ + +int stat_objects(ext2_filsys fs, int argc, char *argv[]) +{ + int i; + const char *path; + ext2_ino_t ino; + struct stat st; + + for (i = 0; i < argc; i++) + { + path = argv[i]; + + /* Detect missing objects. */ + + if (image_find_by_path(fs, path, &ino)) + { + fprintf(stderr, "Not found: %s\n", path); + return 1; + } + + /* Even though the statistics could be read directly out of ext2 data + structures, it is convenient to use the standard stat structure. */ + + if (image_stat_inode(fs, ino, &st)) + { + fprintf(stderr, "Cannot stat object: %s\n", path); + return 1; + } + + /* Terse stat output: + %n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %W %o %C */ + + printf("%s %ld %ld %x %d %d ", + path, st.st_size, st.st_blocks, st.st_mode, st.st_uid, st.st_gid); + + printf("%d %d %d %x %x ", + st.st_dev, st.st_ino, st.st_nlink, + major(st.st_rdev), minor(st.st_rdev)); + + printf("%d %d %d ", + st.st_atim, st.st_mtim, st.st_ctim); + + /* NOTE: Arbitrary values: + %W (creation time) given as 0 + %o (I/O transfer size hint) given as 0 + %C (SELinux security context) given as empty string */ + + printf("%d %d %s\n", + 0, 0, ""); + } + + return 0; +} @@ -677,6 +731,7 @@ mkdir Make directories within the image\n\ rm Remove non-directory objects from the image\n\ rmdir Remove directories from the image\n\ + stat Show statistics for files and directories\n\ \n\ Script operations:\n\ \n\ @@ -699,6 +754,7 @@ {"rm", remove_non_dirs}, {"rmdir", remove_dirs}, {"script", run_script}, + {"stat", stat_objects}, {NULL, NULL}, };