]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/stat.c
cde7780a5fcec31abb521dfbb93114ca0e368fce
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2003-2005 Silicon Graphics, Inc.
5 * Copyright (C) 2015, 2017 Red Hat, Inc.
6 * Portions of statx support written by David Howells (dhowells@redhat.com)
18 static cmdinfo_t stat_cmd
;
19 static cmdinfo_t statfs_cmd
;
20 static cmdinfo_t statx_cmd
;
27 if (fstat(file
->fd
, &st
) < 0) {
37 switch (mode
& S_IFMT
) {
41 return _("directory");
43 return _("char device");
45 return _("block device");
47 return _("regular file");
49 return _("symbolic link");
57 dump_raw_stat(struct stat
*st
)
59 printf("stat.blksize = %lu\n", (unsigned long)st
->st_blksize
);
60 printf("stat.nlink = %lu\n", (unsigned long)st
->st_nlink
);
61 printf("stat.uid = %u\n", st
->st_uid
);
62 printf("stat.gid = %u\n", st
->st_gid
);
63 printf("stat.mode: 0%o\n", st
->st_mode
);
64 printf("stat.ino = %llu\n", (unsigned long long)st
->st_ino
);
65 printf("stat.size = %lld\n", (long long)st
->st_size
);
66 printf("stat.blocks = %lld\n", (long long)st
->st_blocks
);
67 printf("stat.atime.tv_sec = %ld\n", st
->st_atim
.tv_sec
);
68 printf("stat.atime.tv_nsec = %ld\n", st
->st_atim
.tv_nsec
);
69 printf("stat.ctime.tv_sec = %ld\n", st
->st_ctim
.tv_sec
);
70 printf("stat.ctime.tv_nsec = %ld\n", st
->st_ctim
.tv_nsec
);
71 printf("stat.mtime.tv_sec = %ld\n", st
->st_mtim
.tv_sec
);
72 printf("stat.mtime.tv_nsec = %ld\n", st
->st_mtim
.tv_nsec
);
73 printf("stat.rdev_major = %u\n", major(st
->st_rdev
));
74 printf("stat.rdev_minor = %u\n", minor(st
->st_rdev
));
75 printf("stat.dev_major = %u\n", major(st
->st_dev
));
76 printf("stat.dev_minor = %u\n", minor(st
->st_dev
));
80 void print_file_info(void)
82 printf(_("fd.path = \"%s\"\n"), file
->name
);
83 printf(_("fd.flags = %s,%s,%s%s%s%s%s\n"),
84 file
->flags
& IO_OSYNC
? _("sync") : _("non-sync"),
85 file
->flags
& IO_DIRECT
? _("direct") : _("non-direct"),
86 file
->flags
& IO_READONLY
? _("read-only") : _("read-write"),
87 file
->flags
& IO_REALTIME
? _(",real-time") : "",
88 file
->flags
& IO_APPEND
? _(",append-only") : "",
89 file
->flags
& IO_NONBLOCK
? _(",non-block") : "",
90 file
->flags
& IO_TMPFILE
? _(",tmpfile") : "");
93 void print_xfs_info(int verbose
)
96 struct fsxattr fsx
, fsxa
;
98 if ((xfsctl(file
->name
, file
->fd
, FS_IOC_FSGETXATTR
, &fsx
)) < 0 ||
99 (xfsctl(file
->name
, file
->fd
, XFS_IOC_FSGETXATTRA
, &fsxa
)) < 0) {
100 perror("FS_IOC_FSGETXATTR");
102 printf(_("fsxattr.xflags = 0x%x "), fsx
.fsx_xflags
);
103 printxattr(fsx
.fsx_xflags
, verbose
, 0, file
->name
, 1, 1);
104 printf(_("fsxattr.projid = %u\n"), fsx
.fsx_projid
);
105 printf(_("fsxattr.extsize = %u\n"), fsx
.fsx_extsize
);
106 printf(_("fsxattr.cowextsize = %u\n"), fsx
.fsx_cowextsize
);
107 printf(_("fsxattr.nextents = %u\n"), fsx
.fsx_nextents
);
108 printf(_("fsxattr.naextents = %u\n"), fsxa
.fsx_nextents
);
110 if ((xfsctl(file
->name
, file
->fd
, XFS_IOC_DIOINFO
, &dio
)) < 0) {
111 perror("XFS_IOC_DIOINFO");
113 printf(_("dioattr.mem = 0x%x\n"), dio
.d_mem
);
114 printf(_("dioattr.miniosz = %u\n"), dio
.d_miniosz
);
115 printf(_("dioattr.maxiosz = %u\n"), dio
.d_maxiosz
);
125 int c
, verbose
= 0, raw
= 0;
127 while ((c
= getopt(argc
, argv
, "rv")) != EOF
) {
136 return command_usage(&stat_cmd
);
141 return command_usage(&stat_cmd
);
143 if (fstat(file
->fd
, &st
) < 0) {
149 return dump_raw_stat(&st
);
153 printf(_("stat.ino = %lld\n"), (long long)st
.st_ino
);
154 printf(_("stat.type = %s\n"), filetype(st
.st_mode
));
155 printf(_("stat.size = %lld\n"), (long long)st
.st_size
);
156 printf(_("stat.blocks = %lld\n"), (long long)st
.st_blocks
);
158 printf(_("stat.atime = %s"), ctime(&st
.st_atime
));
159 printf(_("stat.mtime = %s"), ctime(&st
.st_mtime
));
160 printf(_("stat.ctime = %s"), ctime(&st
.st_ctime
));
163 if (file
->flags
& IO_FOREIGN
)
166 print_xfs_info(verbose
);
176 struct xfs_fsop_counts fscounts
;
177 struct xfs_fsop_geom fsgeo
;
180 printf(_("fd.path = \"%s\"\n"), file
->name
);
181 if (platform_fstatfs(file
->fd
, &st
) < 0) {
184 printf(_("statfs.f_bsize = %lld\n"), (long long) st
.f_bsize
);
185 printf(_("statfs.f_blocks = %lld\n"), (long long) st
.f_blocks
);
186 printf(_("statfs.f_bavail = %lld\n"), (long long) st
.f_bavail
);
187 printf(_("statfs.f_files = %lld\n"), (long long) st
.f_files
);
188 printf(_("statfs.f_ffree = %lld\n"), (long long) st
.f_ffree
);
189 #ifdef HAVE_STATFS_FLAGS
190 printf(_("statfs.f_flags = 0x%llx\n"), (long long) st
.f_flags
);
193 if (file
->flags
& IO_FOREIGN
)
195 if ((xfsctl(file
->name
, file
->fd
, XFS_IOC_FSGEOMETRY_V1
, &fsgeo
)) < 0) {
196 perror("XFS_IOC_FSGEOMETRY_V1");
198 printf(_("geom.bsize = %u\n"), fsgeo
.blocksize
);
199 printf(_("geom.agcount = %u\n"), fsgeo
.agcount
);
200 printf(_("geom.agblocks = %u\n"), fsgeo
.agblocks
);
201 printf(_("geom.datablocks = %llu\n"),
202 (unsigned long long) fsgeo
.datablocks
);
203 printf(_("geom.rtblocks = %llu\n"),
204 (unsigned long long) fsgeo
.rtblocks
);
205 printf(_("geom.rtextents = %llu\n"),
206 (unsigned long long) fsgeo
.rtextents
);
207 printf(_("geom.rtextsize = %u\n"), fsgeo
.rtextsize
);
208 printf(_("geom.sunit = %u\n"), fsgeo
.sunit
);
209 printf(_("geom.swidth = %u\n"), fsgeo
.swidth
);
211 if ((xfsctl(file
->name
, file
->fd
, XFS_IOC_FSCOUNTS
, &fscounts
)) < 0) {
212 perror("XFS_IOC_FSCOUNTS");
214 printf(_("counts.freedata = %llu\n"),
215 (unsigned long long) fscounts
.freedata
);
216 printf(_("counts.freertx = %llu\n"),
217 (unsigned long long) fscounts
.freertx
);
218 printf(_("counts.freeino = %llu\n"),
219 (unsigned long long) fscounts
.freeino
);
220 printf(_("counts.allocino = %llu\n"),
221 (unsigned long long) fscounts
.allocino
);
229 const char *filename
,
232 struct statx
*buffer
)
235 return syscall(__NR_statx
, dfd
, filename
, flags
, mask
, buffer
);
247 " Display extended file status.\n"
250 " -v -- More verbose output\n"
251 " -r -- Print raw statx structure fields\n"
252 " -m mask -- Specify the field mask for the statx call\n"
253 " (can also be 'basic' or 'all'; default STATX_ALL)\n"
254 " -D -- Don't sync attributes with the server\n"
255 " -F -- Force the attributes to be sync'd with the server\n"
261 dump_raw_statx(struct statx
*stx
)
263 printf("stat.mask = 0x%x\n", stx
->stx_mask
);
264 printf("stat.blksize = %u\n", stx
->stx_blksize
);
265 printf("stat.attributes = 0x%llx\n", (unsigned long long)stx
->stx_attributes
);
266 printf("stat.nlink = %u\n", stx
->stx_nlink
);
267 printf("stat.uid = %u\n", stx
->stx_uid
);
268 printf("stat.gid = %u\n", stx
->stx_gid
);
269 printf("stat.mode: 0%o\n", stx
->stx_mode
);
270 printf("stat.ino = %llu\n", (unsigned long long)stx
->stx_ino
);
271 printf("stat.size = %llu\n", (unsigned long long)stx
->stx_size
);
272 printf("stat.blocks = %llu\n", (unsigned long long)stx
->stx_blocks
);
273 printf("stat.atime.tv_sec = %lld\n", (long long)stx
->stx_atime
.tv_sec
);
274 printf("stat.atime.tv_nsec = %d\n", stx
->stx_atime
.tv_nsec
);
275 printf("stat.btime.tv_sec = %lld\n", (long long)stx
->stx_btime
.tv_sec
);
276 printf("stat.btime.tv_nsec = %d\n", stx
->stx_btime
.tv_nsec
);
277 printf("stat.ctime.tv_sec = %lld\n", (long long)stx
->stx_ctime
.tv_sec
);
278 printf("stat.ctime.tv_nsec = %d\n", stx
->stx_ctime
.tv_nsec
);
279 printf("stat.mtime.tv_sec = %lld\n", (long long)stx
->stx_mtime
.tv_sec
);
280 printf("stat.mtime.tv_nsec = %d\n", stx
->stx_mtime
.tv_nsec
);
281 printf("stat.rdev_major = %u\n", stx
->stx_rdev_major
);
282 printf("stat.rdev_minor = %u\n", stx
->stx_rdev_minor
);
283 printf("stat.dev_major = %u\n", stx
->stx_dev_major
);
284 printf("stat.dev_minor = %u\n", stx
->stx_dev_minor
);
290 * - input flags - query type
291 * - output style for flags (and all else?) (chars vs. hex?)
292 * - output - mask out incidental flag or not?
299 int c
, verbose
= 0, raw
= 0;
303 unsigned int mask
= STATX_ALL
;
305 while ((c
= getopt(argc
, argv
, "m:rvFD")) != EOF
) {
308 if (strcmp(optarg
, "basic") == 0)
309 mask
= STATX_BASIC_STATS
;
310 else if (strcmp(optarg
, "all") == 0)
313 mask
= strtoul(optarg
, &p
, 0);
314 if (!p
|| p
== optarg
) {
316 _("non-numeric mask -- %s\n"), optarg
);
328 atflag
&= ~AT_STATX_SYNC_TYPE
;
329 atflag
|= AT_STATX_FORCE_SYNC
;
332 atflag
&= ~AT_STATX_SYNC_TYPE
;
333 atflag
|= AT_STATX_DONT_SYNC
;
336 return command_usage(&statx_cmd
);
341 return command_usage(&statx_cmd
);
343 memset(&stx
, 0xbf, sizeof(stx
));
344 if (_statx(file
->fd
, "", atflag
| AT_EMPTY_PATH
, mask
, &stx
) < 0) {
350 return dump_raw_statx(&stx
);
354 printf(_("stat.ino = %lld\n"), (long long)stx
.stx_ino
);
355 printf(_("stat.type = %s\n"), filetype(stx
.stx_mode
));
356 printf(_("stat.size = %lld\n"), (long long)stx
.stx_size
);
357 printf(_("stat.blocks = %lld\n"), (long long)stx
.stx_blocks
);
359 printf(_("stat.atime = %s"), ctime((time_t *)&stx
.stx_atime
.tv_sec
));
360 printf(_("stat.mtime = %s"), ctime((time_t *)&stx
.stx_mtime
.tv_sec
));
361 printf(_("stat.ctime = %s"), ctime((time_t *)&stx
.stx_ctime
.tv_sec
));
362 if (stx
.stx_mask
& STATX_BTIME
)
363 printf(_("stat.btime = %s"),
364 ctime((time_t *)&stx
.stx_btime
.tv_sec
));
367 if (file
->flags
& IO_FOREIGN
)
370 print_xfs_info(verbose
);
378 stat_cmd
.name
= "stat";
379 stat_cmd
.cfunc
= stat_f
;
382 stat_cmd
.flags
= CMD_NOMAP_OK
| CMD_FOREIGN_OK
;
383 stat_cmd
.args
= _("[-v|-r]");
384 stat_cmd
.oneline
= _("statistics on the currently open file");
386 statx_cmd
.name
= "statx";
387 statx_cmd
.cfunc
= statx_f
;
388 statx_cmd
.argmin
= 0;
389 statx_cmd
.argmax
= -1;
390 statx_cmd
.flags
= CMD_NOMAP_OK
| CMD_FOREIGN_OK
;
391 statx_cmd
.args
= _("[-v|-r][-m basic | -m all | -m <mask>][-FD]");
392 statx_cmd
.oneline
= _("extended statistics on the currently open file");
393 statx_cmd
.help
= statx_help
;
395 statfs_cmd
.name
= "statfs";
396 statfs_cmd
.cfunc
= statfs_f
;
397 statfs_cmd
.flags
= CMD_NOMAP_OK
| CMD_FOREIGN_OK
;
399 _("statistics on the filesystem of the currently open file");
401 add_command(&stat_cmd
);
402 add_command(&statx_cmd
);
403 add_command(&statfs_cmd
);