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