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