L4Re/departure

libe2access/host/op_stat_objects.c

391:bc65615a8fed
2022-06-30 Paul Boddie Added missing structure members. mmap-region-flags
     1 /*     2  * Obtain object statistics from a filesystem.     3  *     4  * Copyright (C) 2019, 2022 Paul Boddie <paul@boddie.org.uk>     5  *     6  * This program is free software; you can redistribute it and/or     7  * modify it under the terms of the GNU General Public License as     8  * published by the Free Software Foundation; either version 2 of     9  * the License, or (at your option) any later version.    10  *    11  * This program is distributed in the hope that it will be useful,    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    14  * GNU General Public License for more details.    15  *    16  * You should have received a copy of the GNU General Public License    17  * along with this program; if not, write to the Free Software    18  * Foundation, Inc., 51 Franklin Street, Fifth Floor,    19  * Boston, MA  02110-1301, USA    20  */    21     22 #include <stdio.h>    23     24 #include <sys/stat.h>    25 #include <sys/sysmacros.h>  /* major, minor */    26 #include <sys/types.h>    27     28 #include <ext2fs/ext2fs.h>    29     30 #include "image.h"    31     32     33     34 /* Show statistics for files and directories. */    35     36 int stat_objects(ext2_filsys fs, int argc, char *argv[])    37 {    38     int i;    39     const char *path;    40     ext2_ino_t ino;    41     struct stat st;    42     43     for (i = 0; i < argc; i++)    44     {    45         path = argv[i];    46     47         /* Detect missing objects. */    48     49         if (image_find_by_path(fs, path, &ino))    50         {    51             fprintf(stderr, "Not found: %s\n", path);    52             return 1;    53         }    54     55         /* Even though the statistics could be read directly out of ext2 data    56            structures, it is convenient to use the standard stat structure. */    57     58         if (image_stat_inode(fs, ino, &st))    59         {    60             fprintf(stderr, "Cannot stat object: %s\n", path);    61             return 1;    62         }    63     64         /* Terse stat output:    65            %n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %W %o %C */    66     67         printf("%s %ld %ld %x %d %d ",    68             path, st.st_size, st.st_blocks, st.st_mode, st.st_uid, st.st_gid);    69     70         printf("%d %d %d %x %x ",    71             st.st_dev, st.st_ino, st.st_nlink,    72             major(st.st_rdev), minor(st.st_rdev));    73     74         printf("%d %d %d ",    75             st.st_atim, st.st_mtim, st.st_ctim);    76     77         /* NOTE: Arbitrary values:    78            %W (creation time) given as 0    79            %o (I/O transfer size hint) given as 0    80            %C (SELinux security context) given as empty string */    81     82         printf("%d %d %s\n",    83             0, 0, "");    84     }    85     86     return 0;    87 }    88     89 /* vim: tabstop=4 expandtab shiftwidth=4    90 */