]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/stat.c
db3357805499b6d14d23f08b10657757841dad40
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)
15 #include "libfrog/logging.h"
16 #include "libfrog/fsgeom.h"
20 static cmdinfo_t stat_cmd
;
21 static cmdinfo_t statfs_cmd
;
22 static cmdinfo_t statx_cmd
;
29 if (fstat(file
->fd
, &st
) < 0) {
39 switch (mode
& S_IFMT
) {
43 return _("directory");
45 return _("char device");
47 return _("block device");
49 return _("regular file");
51 return _("symbolic link");
59 dump_raw_stat(struct stat
*st
)
61 printf("stat.blksize = %lu\n", (unsigned long)st
->st_blksize
);
62 printf("stat.nlink = %lu\n", (unsigned long)st
->st_nlink
);
63 printf("stat.uid = %u\n", st
->st_uid
);
64 printf("stat.gid = %u\n", st
->st_gid
);
65 printf("stat.mode: 0%o\n", st
->st_mode
);
66 printf("stat.ino = %llu\n", (unsigned long long)st
->st_ino
);
67 printf("stat.size = %lld\n", (long long)st
->st_size
);
68 printf("stat.blocks = %lld\n", (long long)st
->st_blocks
);
69 printf("stat.atime.tv_sec = %ld\n", st
->st_atim
.tv_sec
);
70 printf("stat.atime.tv_nsec = %ld\n", st
->st_atim
.tv_nsec
);
71 printf("stat.ctime.tv_sec = %ld\n", st
->st_ctim
.tv_sec
);
72 printf("stat.ctime.tv_nsec = %ld\n", st
->st_ctim
.tv_nsec
);
73 printf("stat.mtime.tv_sec = %ld\n", st
->st_mtim
.tv_sec
);
74 printf("stat.mtime.tv_nsec = %ld\n", st
->st_mtim
.tv_nsec
);
75 printf("stat.rdev_major = %u\n", major(st
->st_rdev
));
76 printf("stat.rdev_minor = %u\n", minor(st
->st_rdev
));
77 printf("stat.dev_major = %u\n", major(st
->st_dev
));
78 printf("stat.dev_minor = %u\n", minor(st
->st_dev
));
85 printf(_("fd.path = \"%s\"\n"), file
->name
);
86 printf(_("fd.flags = %s,%s,%s%s%s%s%s\n"),
87 file
->flags
& IO_OSYNC
? _("sync") : _("non-sync"),
88 file
->flags
& IO_DIRECT
? _("direct") : _("non-direct"),
89 file
->flags
& IO_READONLY
? _("read-only") : _("read-write"),
90 file
->flags
& IO_REALTIME
? _(",real-time") : "",
91 file
->flags
& IO_APPEND
? _(",append-only") : "",
92 file
->flags
& IO_NONBLOCK
? _(",non-block") : "",
93 file
->flags
& IO_TMPFILE
? _(",tmpfile") : "");
97 print_xfs_info(int verbose
)
100 struct fsxattr fsx
, fsxa
;
102 if ((xfsctl(file
->name
, file
->fd
, FS_IOC_FSGETXATTR
, &fsx
)) < 0 ||
103 (xfsctl(file
->name
, file
->fd
, XFS_IOC_FSGETXATTRA
, &fsxa
)) < 0) {
104 perror("FS_IOC_FSGETXATTR");
106 printf(_("fsxattr.xflags = 0x%x "), fsx
.fsx_xflags
);
107 printxattr(fsx
.fsx_xflags
, verbose
, 0, file
->name
, 1, 1);
108 printf(_("fsxattr.projid = %u\n"), fsx
.fsx_projid
);
109 printf(_("fsxattr.extsize = %u\n"), fsx
.fsx_extsize
);
110 printf(_("fsxattr.cowextsize = %u\n"), fsx
.fsx_cowextsize
);
111 printf(_("fsxattr.nextents = %u\n"), fsx
.fsx_nextents
);
112 printf(_("fsxattr.naextents = %u\n"), fsxa
.fsx_nextents
);
114 if ((xfsctl(file
->name
, file
->fd
, XFS_IOC_DIOINFO
, &dio
)) < 0) {
115 perror("XFS_IOC_DIOINFO");
117 printf(_("dioattr.mem = 0x%x\n"), dio
.d_mem
);
118 printf(_("dioattr.miniosz = %u\n"), dio
.d_miniosz
);
119 printf(_("dioattr.maxiosz = %u\n"), dio
.d_maxiosz
);
129 int c
, verbose
= 0, raw
= 0;
131 while ((c
= getopt(argc
, argv
, "rv")) != EOF
) {
140 return command_usage(&stat_cmd
);
145 return command_usage(&stat_cmd
);
147 if (fstat(file
->fd
, &st
) < 0) {
153 return dump_raw_stat(&st
);
157 printf(_("stat.ino = %lld\n"), (long long)st
.st_ino
);
158 printf(_("stat.type = %s\n"), filetype(st
.st_mode
));
159 printf(_("stat.size = %lld\n"), (long long)st
.st_size
);
160 printf(_("stat.blocks = %lld\n"), (long long)st
.st_blocks
);
162 printf(_("stat.atime = %s"), ctime(&st
.st_atime
));
163 printf(_("stat.mtime = %s"), ctime(&st
.st_mtime
));
164 printf(_("stat.ctime = %s"), ctime(&st
.st_ctime
));
167 if (file
->flags
& IO_FOREIGN
)
170 print_xfs_info(verbose
);
180 struct xfs_fsop_counts fscounts
;
181 struct xfs_fsop_geom fsgeo
;
185 printf(_("fd.path = \"%s\"\n"), file
->name
);
186 if (platform_fstatfs(file
->fd
, &st
) < 0) {
189 printf(_("statfs.f_bsize = %lld\n"), (long long) st
.f_bsize
);
190 printf(_("statfs.f_blocks = %lld\n"), (long long) st
.f_blocks
);
191 printf(_("statfs.f_bavail = %lld\n"), (long long) st
.f_bavail
);
192 printf(_("statfs.f_files = %lld\n"), (long long) st
.f_files
);
193 printf(_("statfs.f_ffree = %lld\n"), (long long) st
.f_ffree
);
194 #ifdef HAVE_STATFS_FLAGS
195 printf(_("statfs.f_flags = 0x%llx\n"), (long long) st
.f_flags
);
198 if (file
->flags
& IO_FOREIGN
)
200 ret
= xfrog_geometry(file
->fd
, &fsgeo
);
202 xfrog_perror(ret
, "XFS_IOC_FSGEOMETRY");
204 printf(_("geom.bsize = %u\n"), fsgeo
.blocksize
);
205 printf(_("geom.agcount = %u\n"), fsgeo
.agcount
);
206 printf(_("geom.agblocks = %u\n"), fsgeo
.agblocks
);
207 printf(_("geom.datablocks = %llu\n"),
208 (unsigned long long) fsgeo
.datablocks
);
209 printf(_("geom.rtblocks = %llu\n"),
210 (unsigned long long) fsgeo
.rtblocks
);
211 printf(_("geom.rtextents = %llu\n"),
212 (unsigned long long) fsgeo
.rtextents
);
213 printf(_("geom.rtextsize = %u\n"), fsgeo
.rtextsize
);
214 printf(_("geom.sunit = %u\n"), fsgeo
.sunit
);
215 printf(_("geom.swidth = %u\n"), fsgeo
.swidth
);
217 if ((xfsctl(file
->name
, file
->fd
, XFS_IOC_FSCOUNTS
, &fscounts
)) < 0) {
218 perror("XFS_IOC_FSCOUNTS");
220 printf(_("counts.freedata = %llu\n"),
221 (unsigned long long) fscounts
.freedata
);
222 printf(_("counts.freertx = %llu\n"),
223 (unsigned long long) fscounts
.freertx
);
224 printf(_("counts.freeino = %llu\n"),
225 (unsigned long long) fscounts
.freeino
);
226 printf(_("counts.allocino = %llu\n"),
227 (unsigned long long) fscounts
.allocino
);
235 const char *filename
,
238 struct statx
*buffer
)
241 return syscall(__NR_statx
, dfd
, filename
, flags
, mask
, buffer
);
253 " Display extended file status.\n"
256 " -v -- More verbose output\n"
257 " -r -- Print raw statx structure fields\n"
258 " -m mask -- Specify the field mask for the statx call\n"
259 " (can also be 'basic' or 'all'; default STATX_ALL)\n"
260 " -D -- Don't sync attributes with the server\n"
261 " -F -- Force the attributes to be sync'd with the server\n"
267 dump_raw_statx(struct statx
*stx
)
269 printf("stat.mask = 0x%x\n", stx
->stx_mask
);
270 printf("stat.blksize = %u\n", stx
->stx_blksize
);
271 printf("stat.attributes = 0x%llx\n", (unsigned long long)stx
->stx_attributes
);
272 printf("stat.nlink = %u\n", stx
->stx_nlink
);
273 printf("stat.uid = %u\n", stx
->stx_uid
);
274 printf("stat.gid = %u\n", stx
->stx_gid
);
275 printf("stat.mode: 0%o\n", stx
->stx_mode
);
276 printf("stat.ino = %llu\n", (unsigned long long)stx
->stx_ino
);
277 printf("stat.size = %llu\n", (unsigned long long)stx
->stx_size
);
278 printf("stat.blocks = %llu\n", (unsigned long long)stx
->stx_blocks
);
279 printf("stat.attributes_mask = 0x%llx\n", (unsigned long long)stx
->stx_attributes_mask
);
280 printf("stat.atime.tv_sec = %lld\n", (long long)stx
->stx_atime
.tv_sec
);
281 printf("stat.atime.tv_nsec = %d\n", stx
->stx_atime
.tv_nsec
);
282 printf("stat.btime.tv_sec = %lld\n", (long long)stx
->stx_btime
.tv_sec
);
283 printf("stat.btime.tv_nsec = %d\n", stx
->stx_btime
.tv_nsec
);
284 printf("stat.ctime.tv_sec = %lld\n", (long long)stx
->stx_ctime
.tv_sec
);
285 printf("stat.ctime.tv_nsec = %d\n", stx
->stx_ctime
.tv_nsec
);
286 printf("stat.mtime.tv_sec = %lld\n", (long long)stx
->stx_mtime
.tv_sec
);
287 printf("stat.mtime.tv_nsec = %d\n", stx
->stx_mtime
.tv_nsec
);
288 printf("stat.rdev_major = %u\n", stx
->stx_rdev_major
);
289 printf("stat.rdev_minor = %u\n", stx
->stx_rdev_minor
);
290 printf("stat.dev_major = %u\n", stx
->stx_dev_major
);
291 printf("stat.dev_minor = %u\n", stx
->stx_dev_minor
);
297 * - input flags - query type
298 * - output style for flags (and all else?) (chars vs. hex?)
299 * - output - mask out incidental flag or not?
306 int c
, verbose
= 0, raw
= 0;
310 unsigned int mask
= STATX_ALL
;
312 while ((c
= getopt(argc
, argv
, "m:rvFD")) != EOF
) {
315 if (strcmp(optarg
, "basic") == 0)
316 mask
= STATX_BASIC_STATS
;
317 else if (strcmp(optarg
, "all") == 0)
320 mask
= strtoul(optarg
, &p
, 0);
321 if (!p
|| p
== optarg
) {
323 _("non-numeric mask -- %s\n"), optarg
);
335 atflag
&= ~AT_STATX_SYNC_TYPE
;
336 atflag
|= AT_STATX_FORCE_SYNC
;
339 atflag
&= ~AT_STATX_SYNC_TYPE
;
340 atflag
|= AT_STATX_DONT_SYNC
;
343 return command_usage(&statx_cmd
);
348 return command_usage(&statx_cmd
);
350 memset(&stx
, 0xbf, sizeof(stx
));
351 if (_statx(file
->fd
, "", atflag
| AT_EMPTY_PATH
, mask
, &stx
) < 0) {
357 return dump_raw_statx(&stx
);
361 printf(_("stat.ino = %lld\n"), (long long)stx
.stx_ino
);
362 printf(_("stat.type = %s\n"), filetype(stx
.stx_mode
));
363 printf(_("stat.size = %lld\n"), (long long)stx
.stx_size
);
364 printf(_("stat.blocks = %lld\n"), (long long)stx
.stx_blocks
);
366 printf(_("stat.atime = %s"), ctime((time_t *)&stx
.stx_atime
.tv_sec
));
367 printf(_("stat.mtime = %s"), ctime((time_t *)&stx
.stx_mtime
.tv_sec
));
368 printf(_("stat.ctime = %s"), ctime((time_t *)&stx
.stx_ctime
.tv_sec
));
369 if (stx
.stx_mask
& STATX_BTIME
)
370 printf(_("stat.btime = %s"),
371 ctime((time_t *)&stx
.stx_btime
.tv_sec
));
374 if (file
->flags
& IO_FOREIGN
)
377 print_xfs_info(verbose
);
385 stat_cmd
.name
= "stat";
386 stat_cmd
.cfunc
= stat_f
;
389 stat_cmd
.flags
= CMD_NOMAP_OK
| CMD_FOREIGN_OK
;
390 stat_cmd
.args
= _("[-v|-r]");
391 stat_cmd
.oneline
= _("statistics on the currently open file");
393 statx_cmd
.name
= "statx";
394 statx_cmd
.cfunc
= statx_f
;
395 statx_cmd
.argmin
= 0;
396 statx_cmd
.argmax
= -1;
397 statx_cmd
.flags
= CMD_NOMAP_OK
| CMD_FOREIGN_OK
;
398 statx_cmd
.args
= _("[-v|-r][-m basic | -m all | -m <mask>][-FD]");
399 statx_cmd
.oneline
= _("extended statistics on the currently open file");
400 statx_cmd
.help
= statx_help
;
402 statfs_cmd
.name
= "statfs";
403 statfs_cmd
.cfunc
= statfs_f
;
404 statfs_cmd
.flags
= CMD_NOMAP_OK
| CMD_FOREIGN_OK
;
406 _("statistics on the filesystem of the currently open file");
408 add_command(&stat_cmd
);
409 add_command(&statx_cmd
);
410 add_command(&statfs_cmd
);