]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/stat.c
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
));
83 printf(_("fd.path = \"%s\"\n"), file
->name
);
84 printf(_("fd.flags = %s,%s,%s%s%s%s%s\n"),
85 file
->flags
& IO_OSYNC
? _("sync") : _("non-sync"),
86 file
->flags
& IO_DIRECT
? _("direct") : _("non-direct"),
87 file
->flags
& IO_READONLY
? _("read-only") : _("read-write"),
88 file
->flags
& IO_REALTIME
? _(",real-time") : "",
89 file
->flags
& IO_APPEND
? _(",append-only") : "",
90 file
->flags
& IO_NONBLOCK
? _(",non-block") : "",
91 file
->flags
& IO_TMPFILE
? _(",tmpfile") : "");
95 print_xfs_info(int verbose
)
98 struct fsxattr fsx
, fsxa
;
100 if ((xfsctl(file
->name
, file
->fd
, FS_IOC_FSGETXATTR
, &fsx
)) < 0 ||
101 (xfsctl(file
->name
, file
->fd
, XFS_IOC_FSGETXATTRA
, &fsxa
)) < 0) {
102 perror("FS_IOC_FSGETXATTR");
104 printf(_("fsxattr.xflags = 0x%x "), fsx
.fsx_xflags
);
105 printxattr(fsx
.fsx_xflags
, verbose
, 0, file
->name
, 1, 1);
106 printf(_("fsxattr.projid = %u\n"), fsx
.fsx_projid
);
107 printf(_("fsxattr.extsize = %u\n"), fsx
.fsx_extsize
);
108 printf(_("fsxattr.cowextsize = %u\n"), fsx
.fsx_cowextsize
);
109 printf(_("fsxattr.nextents = %u\n"), fsx
.fsx_nextents
);
110 printf(_("fsxattr.naextents = %u\n"), fsxa
.fsx_nextents
);
112 if ((xfsctl(file
->name
, file
->fd
, XFS_IOC_DIOINFO
, &dio
)) < 0) {
113 perror("XFS_IOC_DIOINFO");
115 printf(_("dioattr.mem = 0x%x\n"), dio
.d_mem
);
116 printf(_("dioattr.miniosz = %u\n"), dio
.d_miniosz
);
117 printf(_("dioattr.maxiosz = %u\n"), dio
.d_maxiosz
);
127 int c
, verbose
= 0, raw
= 0;
129 while ((c
= getopt(argc
, argv
, "rv")) != EOF
) {
138 return command_usage(&stat_cmd
);
143 return command_usage(&stat_cmd
);
145 if (fstat(file
->fd
, &st
) < 0) {
151 return dump_raw_stat(&st
);
155 printf(_("stat.ino = %lld\n"), (long long)st
.st_ino
);
156 printf(_("stat.type = %s\n"), filetype(st
.st_mode
));
157 printf(_("stat.size = %lld\n"), (long long)st
.st_size
);
158 printf(_("stat.blocks = %lld\n"), (long long)st
.st_blocks
);
160 printf(_("stat.atime = %s"), ctime(&st
.st_atime
));
161 printf(_("stat.mtime = %s"), ctime(&st
.st_mtime
));
162 printf(_("stat.ctime = %s"), ctime(&st
.st_ctime
));
165 if (file
->flags
& IO_FOREIGN
)
168 print_xfs_info(verbose
);
178 struct xfs_fsop_counts fscounts
;
179 struct xfs_fsop_geom fsgeo
;
182 printf(_("fd.path = \"%s\"\n"), file
->name
);
183 if (platform_fstatfs(file
->fd
, &st
) < 0) {
186 printf(_("statfs.f_bsize = %lld\n"), (long long) st
.f_bsize
);
187 printf(_("statfs.f_blocks = %lld\n"), (long long) st
.f_blocks
);
188 printf(_("statfs.f_bavail = %lld\n"), (long long) st
.f_bavail
);
189 printf(_("statfs.f_files = %lld\n"), (long long) st
.f_files
);
190 printf(_("statfs.f_ffree = %lld\n"), (long long) st
.f_ffree
);
191 #ifdef HAVE_STATFS_FLAGS
192 printf(_("statfs.f_flags = 0x%llx\n"), (long long) st
.f_flags
);
195 if (file
->flags
& IO_FOREIGN
)
197 if ((xfsctl(file
->name
, file
->fd
, XFS_IOC_FSGEOMETRY_V1
, &fsgeo
)) < 0) {
198 perror("XFS_IOC_FSGEOMETRY_V1");
200 printf(_("geom.bsize = %u\n"), fsgeo
.blocksize
);
201 printf(_("geom.agcount = %u\n"), fsgeo
.agcount
);
202 printf(_("geom.agblocks = %u\n"), fsgeo
.agblocks
);
203 printf(_("geom.datablocks = %llu\n"),
204 (unsigned long long) fsgeo
.datablocks
);
205 printf(_("geom.rtblocks = %llu\n"),
206 (unsigned long long) fsgeo
.rtblocks
);
207 printf(_("geom.rtextents = %llu\n"),
208 (unsigned long long) fsgeo
.rtextents
);
209 printf(_("geom.rtextsize = %u\n"), fsgeo
.rtextsize
);
210 printf(_("geom.sunit = %u\n"), fsgeo
.sunit
);
211 printf(_("geom.swidth = %u\n"), fsgeo
.swidth
);
213 if ((xfsctl(file
->name
, file
->fd
, XFS_IOC_FSCOUNTS
, &fscounts
)) < 0) {
214 perror("XFS_IOC_FSCOUNTS");
216 printf(_("counts.freedata = %llu\n"),
217 (unsigned long long) fscounts
.freedata
);
218 printf(_("counts.freertx = %llu\n"),
219 (unsigned long long) fscounts
.freertx
);
220 printf(_("counts.freeino = %llu\n"),
221 (unsigned long long) fscounts
.freeino
);
222 printf(_("counts.allocino = %llu\n"),
223 (unsigned long long) fscounts
.allocino
);
231 const char *filename
,
234 struct statx
*buffer
)
237 return syscall(__NR_statx
, dfd
, filename
, flags
, mask
, buffer
);
249 " Display extended file status.\n"
252 " -v -- More verbose output\n"
253 " -r -- Print raw statx structure fields\n"
254 " -m mask -- Specify the field mask for the statx call\n"
255 " (can also be 'basic' or 'all'; default STATX_ALL)\n"
256 " -D -- Don't sync attributes with the server\n"
257 " -F -- Force the attributes to be sync'd with the server\n"
263 dump_raw_statx(struct statx
*stx
)
265 printf("stat.mask = 0x%x\n", stx
->stx_mask
);
266 printf("stat.blksize = %u\n", stx
->stx_blksize
);
267 printf("stat.attributes = 0x%llx\n", (unsigned long long)stx
->stx_attributes
);
268 printf("stat.nlink = %u\n", stx
->stx_nlink
);
269 printf("stat.uid = %u\n", stx
->stx_uid
);
270 printf("stat.gid = %u\n", stx
->stx_gid
);
271 printf("stat.mode: 0%o\n", stx
->stx_mode
);
272 printf("stat.ino = %llu\n", (unsigned long long)stx
->stx_ino
);
273 printf("stat.size = %llu\n", (unsigned long long)stx
->stx_size
);
274 printf("stat.blocks = %llu\n", (unsigned long long)stx
->stx_blocks
);
275 printf("stat.atime.tv_sec = %lld\n", (long long)stx
->stx_atime
.tv_sec
);
276 printf("stat.atime.tv_nsec = %d\n", stx
->stx_atime
.tv_nsec
);
277 printf("stat.btime.tv_sec = %lld\n", (long long)stx
->stx_btime
.tv_sec
);
278 printf("stat.btime.tv_nsec = %d\n", stx
->stx_btime
.tv_nsec
);
279 printf("stat.ctime.tv_sec = %lld\n", (long long)stx
->stx_ctime
.tv_sec
);
280 printf("stat.ctime.tv_nsec = %d\n", stx
->stx_ctime
.tv_nsec
);
281 printf("stat.mtime.tv_sec = %lld\n", (long long)stx
->stx_mtime
.tv_sec
);
282 printf("stat.mtime.tv_nsec = %d\n", stx
->stx_mtime
.tv_nsec
);
283 printf("stat.rdev_major = %u\n", stx
->stx_rdev_major
);
284 printf("stat.rdev_minor = %u\n", stx
->stx_rdev_minor
);
285 printf("stat.dev_major = %u\n", stx
->stx_dev_major
);
286 printf("stat.dev_minor = %u\n", stx
->stx_dev_minor
);
292 * - input flags - query type
293 * - output style for flags (and all else?) (chars vs. hex?)
294 * - output - mask out incidental flag or not?
301 int c
, verbose
= 0, raw
= 0;
305 unsigned int mask
= STATX_ALL
;
307 while ((c
= getopt(argc
, argv
, "m:rvFD")) != EOF
) {
310 if (strcmp(optarg
, "basic") == 0)
311 mask
= STATX_BASIC_STATS
;
312 else if (strcmp(optarg
, "all") == 0)
315 mask
= strtoul(optarg
, &p
, 0);
316 if (!p
|| p
== optarg
) {
318 _("non-numeric mask -- %s\n"), optarg
);
330 atflag
&= ~AT_STATX_SYNC_TYPE
;
331 atflag
|= AT_STATX_FORCE_SYNC
;
334 atflag
&= ~AT_STATX_SYNC_TYPE
;
335 atflag
|= AT_STATX_DONT_SYNC
;
338 return command_usage(&statx_cmd
);
343 return command_usage(&statx_cmd
);
345 memset(&stx
, 0xbf, sizeof(stx
));
346 if (_statx(file
->fd
, "", atflag
| AT_EMPTY_PATH
, mask
, &stx
) < 0) {
352 return dump_raw_statx(&stx
);
356 printf(_("stat.ino = %lld\n"), (long long)stx
.stx_ino
);
357 printf(_("stat.type = %s\n"), filetype(stx
.stx_mode
));
358 printf(_("stat.size = %lld\n"), (long long)stx
.stx_size
);
359 printf(_("stat.blocks = %lld\n"), (long long)stx
.stx_blocks
);
361 printf(_("stat.atime = %s"), ctime((time_t *)&stx
.stx_atime
.tv_sec
));
362 printf(_("stat.mtime = %s"), ctime((time_t *)&stx
.stx_mtime
.tv_sec
));
363 printf(_("stat.ctime = %s"), ctime((time_t *)&stx
.stx_ctime
.tv_sec
));
364 if (stx
.stx_mask
& STATX_BTIME
)
365 printf(_("stat.btime = %s"),
366 ctime((time_t *)&stx
.stx_btime
.tv_sec
));
369 if (file
->flags
& IO_FOREIGN
)
372 print_xfs_info(verbose
);
380 stat_cmd
.name
= "stat";
381 stat_cmd
.cfunc
= stat_f
;
384 stat_cmd
.flags
= CMD_NOMAP_OK
| CMD_FOREIGN_OK
;
385 stat_cmd
.args
= _("[-v|-r]");
386 stat_cmd
.oneline
= _("statistics on the currently open file");
388 statx_cmd
.name
= "statx";
389 statx_cmd
.cfunc
= statx_f
;
390 statx_cmd
.argmin
= 0;
391 statx_cmd
.argmax
= -1;
392 statx_cmd
.flags
= CMD_NOMAP_OK
| CMD_FOREIGN_OK
;
393 statx_cmd
.args
= _("[-v|-r][-m basic | -m all | -m <mask>][-FD]");
394 statx_cmd
.oneline
= _("extended statistics on the currently open file");
395 statx_cmd
.help
= statx_help
;
397 statfs_cmd
.name
= "statfs";
398 statfs_cmd
.cfunc
= statfs_f
;
399 statfs_cmd
.flags
= CMD_NOMAP_OK
| CMD_FOREIGN_OK
;
401 _("statistics on the filesystem of the currently open file");
403 add_command(&stat_cmd
);
404 add_command(&statx_cmd
);
405 add_command(&statfs_cmd
);