# HG changeset patch # User Paul Boddie # Date 1647646871 -3600 # Node ID e35acec6b7768023d83da784f6a2865322f870dc # Parent 600f688dc4495291b4d0bd8f32c657935a5824a8 Introduced the stat operation to fsaccess from e2access. diff -r 600f688dc449 -r e35acec6b776 conf/fsaccess.txt --- a/conf/fsaccess.txt Fri Mar 18 00:14:07 2022 +0100 +++ b/conf/fsaccess.txt Sat Mar 19 00:41:11 2022 +0100 @@ -3,3 +3,5 @@ mkdir home/paulb/newdir ls home/paulb ls home/paulb/newdir +stat home/paulb +stat home/paulb/newdir diff -r 600f688dc449 -r e35acec6b776 fsaccess/Makefile --- a/fsaccess/Makefile Fri Mar 18 00:14:07 2022 +0100 +++ b/fsaccess/Makefile Sat Mar 19 00:41:11 2022 +0100 @@ -7,7 +7,8 @@ SRC_C = \ fsaccess.c input.c session.c \ - ops.c op_list_objects.c op_make_dirs.c op_script.c + ops.c op_list_objects.c op_make_dirs.c op_script.c \ + op_stat_objects.c REQUIRES_LIBS = l4re_c-util libfsclient libmem libipc libsystypes libe2access_blockserver diff -r 600f688dc449 -r e35acec6b776 fsaccess/fsaccess.c --- a/fsaccess/fsaccess.c Fri Mar 18 00:14:07 2022 +0100 +++ b/fsaccess/fsaccess.c Sat Mar 19 00:41:11 2022 +0100 @@ -68,9 +68,7 @@ {"rmdir", remove_dirs}, #endif {"script", run_script}, -#if 0 {"stat", stat_objects}, -#endif {NULL, NULL}, }; diff -r 600f688dc449 -r e35acec6b776 fsaccess/op_stat_objects.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fsaccess/op_stat_objects.c Sat Mar 19 00:41:11 2022 +0100 @@ -0,0 +1,80 @@ +/* + * Obtain object statistics from a filesystem. + * + * Copyright (C) 2019, 2022 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#include + +#include +#include /* major, minor */ +#include + +#include + +#include "ops.h" + + + +/* Show statistics for files and directories. */ + +int stat_objects(int argc, char *argv[]) +{ + int i; + const char *path; + struct stat st; + + for (i = 0; i < argc; i++) + { + path = argv[i]; + + /* Detect missing objects. */ + + if (client_stat(path, &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("%ld %ld %ld %x %x ", + st.st_dev, st.st_ino, st.st_nlink, + major(st.st_rdev), minor(st.st_rdev)); + + printf("%ld %ld %ld ", + st.st_atim.tv_sec, st.st_mtim.tv_sec, st.st_ctim.tv_sec); + + /* 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; +} + +/* vim: tabstop=4 expandtab shiftwidth=4 +*/