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 <fsclient/client.h> 29 #include <systypes/format.h> 30 31 #include "ops.h" 32 33 #define FMT64d "%" pFMT64 "d" 34 #define FMTnlinkd "%" pFMTnlink "d" 35 36 37 38 /* Show statistics for files and directories. */ 39 40 int stat_objects(int argc, char *argv[]) 41 { 42 int i; 43 const char *path; 44 struct stat st; 45 46 for (i = 0; i < argc; i++) 47 { 48 path = argv[i]; 49 50 /* Detect missing objects. */ 51 52 if (client_stat(path, &st)) 53 { 54 fprintf(stderr, "Cannot stat object: %s\n", path); 55 return 1; 56 } 57 58 /* Terse stat output: 59 %n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %W %o %C */ 60 61 printf("%s %ld %ld %x %d %d ", 62 path, st.st_size, st.st_blocks, st.st_mode, st.st_uid, st.st_gid); 63 64 printf(FMT64d " %ld " FMTnlinkd " %x %x ", 65 st.st_dev, st.st_ino, st.st_nlink, 66 major(st.st_rdev), minor(st.st_rdev)); 67 68 printf("%ld %ld %ld ", 69 st.st_atim.tv_sec, st.st_mtim.tv_sec, st.st_ctim.tv_sec); 70 71 /* NOTE: Arbitrary values: 72 %W (creation time) given as 0 73 %o (I/O transfer size hint) given as 0 74 %C (SELinux security context) given as empty string */ 75 76 printf("%d %d %s\n", 77 0, 0, ""); 78 } 79 80 return 0; 81 } 82 83 /* vim: tabstop=4 expandtab shiftwidth=4 84 */