1.1 --- a/conf/fsaccess.txt Fri Mar 18 00:14:07 2022 +0100
1.2 +++ b/conf/fsaccess.txt Sat Mar 19 00:41:11 2022 +0100
1.3 @@ -3,3 +3,5 @@
1.4 mkdir home/paulb/newdir
1.5 ls home/paulb
1.6 ls home/paulb/newdir
1.7 +stat home/paulb
1.8 +stat home/paulb/newdir
2.1 --- a/fsaccess/Makefile Fri Mar 18 00:14:07 2022 +0100
2.2 +++ b/fsaccess/Makefile Sat Mar 19 00:41:11 2022 +0100
2.3 @@ -7,7 +7,8 @@
2.4
2.5 SRC_C = \
2.6 fsaccess.c input.c session.c \
2.7 - ops.c op_list_objects.c op_make_dirs.c op_script.c
2.8 + ops.c op_list_objects.c op_make_dirs.c op_script.c \
2.9 + op_stat_objects.c
2.10
2.11 REQUIRES_LIBS = l4re_c-util libfsclient libmem libipc libsystypes libe2access_blockserver
2.12
3.1 --- a/fsaccess/fsaccess.c Fri Mar 18 00:14:07 2022 +0100
3.2 +++ b/fsaccess/fsaccess.c Sat Mar 19 00:41:11 2022 +0100
3.3 @@ -68,9 +68,7 @@
3.4 {"rmdir", remove_dirs},
3.5 #endif
3.6 {"script", run_script},
3.7 -#if 0
3.8 {"stat", stat_objects},
3.9 -#endif
3.10 {NULL, NULL},
3.11 };
3.12
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/fsaccess/op_stat_objects.c Sat Mar 19 00:41:11 2022 +0100
4.3 @@ -0,0 +1,80 @@
4.4 +/*
4.5 + * Obtain object statistics from a filesystem.
4.6 + *
4.7 + * Copyright (C) 2019, 2022 Paul Boddie <paul@boddie.org.uk>
4.8 + *
4.9 + * This program is free software; you can redistribute it and/or
4.10 + * modify it under the terms of the GNU General Public License as
4.11 + * published by the Free Software Foundation; either version 2 of
4.12 + * the License, or (at your option) any later version.
4.13 + *
4.14 + * This program is distributed in the hope that it will be useful,
4.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.17 + * GNU General Public License for more details.
4.18 + *
4.19 + * You should have received a copy of the GNU General Public License
4.20 + * along with this program; if not, write to the Free Software
4.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
4.22 + * Boston, MA 02110-1301, USA
4.23 + */
4.24 +
4.25 +#include <stdio.h>
4.26 +
4.27 +#include <sys/stat.h>
4.28 +#include <sys/sysmacros.h> /* major, minor */
4.29 +#include <sys/types.h>
4.30 +
4.31 +#include <fsclient/client.h>
4.32 +
4.33 +#include "ops.h"
4.34 +
4.35 +
4.36 +
4.37 +/* Show statistics for files and directories. */
4.38 +
4.39 +int stat_objects(int argc, char *argv[])
4.40 +{
4.41 + int i;
4.42 + const char *path;
4.43 + struct stat st;
4.44 +
4.45 + for (i = 0; i < argc; i++)
4.46 + {
4.47 + path = argv[i];
4.48 +
4.49 + /* Detect missing objects. */
4.50 +
4.51 + if (client_stat(path, &st))
4.52 + {
4.53 + fprintf(stderr, "Cannot stat object: %s\n", path);
4.54 + return 1;
4.55 + }
4.56 +
4.57 + /* Terse stat output:
4.58 + %n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %W %o %C */
4.59 +
4.60 + printf("%s %ld %ld %x %d %d ",
4.61 + path, st.st_size, st.st_blocks, st.st_mode, st.st_uid, st.st_gid);
4.62 +
4.63 + printf("%ld %ld %ld %x %x ",
4.64 + st.st_dev, st.st_ino, st.st_nlink,
4.65 + major(st.st_rdev), minor(st.st_rdev));
4.66 +
4.67 + printf("%ld %ld %ld ",
4.68 + st.st_atim.tv_sec, st.st_mtim.tv_sec, st.st_ctim.tv_sec);
4.69 +
4.70 + /* NOTE: Arbitrary values:
4.71 + %W (creation time) given as 0
4.72 + %o (I/O transfer size hint) given as 0
4.73 + %C (SELinux security context) given as empty string */
4.74 +
4.75 + printf("%d %d %s\n",
4.76 + 0, 0, "");
4.77 + }
4.78 +
4.79 + return 0;
4.80 +}
4.81 +
4.82 +/* vim: tabstop=4 expandtab shiftwidth=4
4.83 +*/