]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/stat.c
2 * 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)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it would be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 static cmdinfo_t stat_cmd
;
32 static cmdinfo_t statfs_cmd
;
33 static cmdinfo_t statx_cmd
;
40 if (fstat(file
->fd
, &st
) < 0) {
50 switch (mode
& S_IFMT
) {
54 return _("directory");
56 return _("char device");
58 return _("block device");
60 return _("regular file");
62 return _("symbolic link");
70 dump_raw_stat(struct stat
*st
)
72 printf("stat.blksize = %lu\n", st
->st_blksize
);
73 printf("stat.nlink = %lu\n", st
->st_nlink
);
74 printf("stat.uid = %u\n", st
->st_uid
);
75 printf("stat.gid = %u\n", st
->st_gid
);
76 printf("stat.mode: 0%o\n", st
->st_mode
);
77 printf("stat.ino = %lu\n", st
->st_ino
);
78 printf("stat.size = %lu\n", st
->st_size
);
79 printf("stat.blocks = %lu\n", st
->st_blocks
);
80 printf("stat.atime.tv_sec = %ld\n", st
->st_atim
.tv_sec
);
81 printf("stat.atime.tv_nsec = %ld\n", st
->st_atim
.tv_nsec
);
82 printf("stat.ctime.tv_sec = %ld\n", st
->st_ctim
.tv_sec
);
83 printf("stat.ctime.tv_nsec = %ld\n", st
->st_ctim
.tv_nsec
);
84 printf("stat.mtime.tv_sec = %ld\n", st
->st_mtim
.tv_sec
);
85 printf("stat.mtime.tv_nsec = %ld\n", st
->st_mtim
.tv_nsec
);
86 printf("stat.rdev_major = %u\n", major(st
->st_rdev
));
87 printf("stat.rdev_minor = %u\n", minor(st
->st_rdev
));
88 printf("stat.dev_major = %u\n", major(st
->st_dev
));
89 printf("stat.dev_minor = %u\n", minor(st
->st_dev
));
93 void print_file_info(void)
95 printf(_("fd.path = \"%s\"\n"), file
->name
);
96 printf(_("fd.flags = %s,%s,%s%s%s%s%s\n"),
97 file
->flags
& IO_OSYNC
? _("sync") : _("non-sync"),
98 file
->flags
& IO_DIRECT
? _("direct") : _("non-direct"),
99 file
->flags
& IO_READONLY
? _("read-only") : _("read-write"),
100 file
->flags
& IO_REALTIME
? _(",real-time") : "",
101 file
->flags
& IO_APPEND
? _(",append-only") : "",
102 file
->flags
& IO_NONBLOCK
? _(",non-block") : "",
103 file
->flags
& IO_TMPFILE
? _(",tmpfile") : "");
106 void print_xfs_info(int verbose
)
109 struct fsxattr fsx
, fsxa
;
111 if ((xfsctl(file
->name
, file
->fd
, FS_IOC_FSGETXATTR
, &fsx
)) < 0 ||
112 (xfsctl(file
->name
, file
->fd
, XFS_IOC_FSGETXATTRA
, &fsxa
)) < 0) {
113 perror("FS_IOC_FSGETXATTR");
115 printf(_("fsxattr.xflags = 0x%x "), fsx
.fsx_xflags
);
116 printxattr(fsx
.fsx_xflags
, verbose
, 0, file
->name
, 1, 1);
117 printf(_("fsxattr.projid = %u\n"), fsx
.fsx_projid
);
118 printf(_("fsxattr.extsize = %u\n"), fsx
.fsx_extsize
);
119 printf(_("fsxattr.cowextsize = %u\n"), fsx
.fsx_cowextsize
);
120 printf(_("fsxattr.nextents = %u\n"), fsx
.fsx_nextents
);
121 printf(_("fsxattr.naextents = %u\n"), fsxa
.fsx_nextents
);
123 if ((xfsctl(file
->name
, file
->fd
, XFS_IOC_DIOINFO
, &dio
)) < 0) {
124 perror("XFS_IOC_DIOINFO");
126 printf(_("dioattr.mem = 0x%x\n"), dio
.d_mem
);
127 printf(_("dioattr.miniosz = %u\n"), dio
.d_miniosz
);
128 printf(_("dioattr.maxiosz = %u\n"), dio
.d_maxiosz
);
138 int c
, verbose
= 0, raw
= 0;
140 while ((c
= getopt(argc
, argv
, "rv")) != EOF
) {
149 return command_usage(&stat_cmd
);
154 return command_usage(&stat_cmd
);
156 if (fstat(file
->fd
, &st
) < 0) {
162 return dump_raw_stat(&st
);
166 printf(_("stat.ino = %lld\n"), (long long)st
.st_ino
);
167 printf(_("stat.type = %s\n"), filetype(st
.st_mode
));
168 printf(_("stat.size = %lld\n"), (long long)st
.st_size
);
169 printf(_("stat.blocks = %lld\n"), (long long)st
.st_blocks
);
171 printf(_("stat.atime = %s"), ctime(&st
.st_atime
));
172 printf(_("stat.mtime = %s"), ctime(&st
.st_mtime
));
173 printf(_("stat.ctime = %s"), ctime(&st
.st_ctime
));
176 if (file
->flags
& IO_FOREIGN
)
179 print_xfs_info(verbose
);
189 struct xfs_fsop_counts fscounts
;
190 struct xfs_fsop_geom fsgeo
;
193 printf(_("fd.path = \"%s\"\n"), file
->name
);
194 if (platform_fstatfs(file
->fd
, &st
) < 0) {
197 printf(_("statfs.f_bsize = %lld\n"), (long long) st
.f_bsize
);
198 printf(_("statfs.f_blocks = %lld\n"), (long long) st
.f_blocks
);
199 printf(_("statfs.f_bavail = %lld\n"), (long long) st
.f_bavail
);
200 printf(_("statfs.f_files = %lld\n"), (long long) st
.f_files
);
201 printf(_("statfs.f_ffree = %lld\n"), (long long) st
.f_ffree
);
203 if (file
->flags
& IO_FOREIGN
)
205 if ((xfsctl(file
->name
, file
->fd
, XFS_IOC_FSGEOMETRY_V1
, &fsgeo
)) < 0) {
206 perror("XFS_IOC_FSGEOMETRY_V1");
208 printf(_("geom.bsize = %u\n"), fsgeo
.blocksize
);
209 printf(_("geom.agcount = %u\n"), fsgeo
.agcount
);
210 printf(_("geom.agblocks = %u\n"), fsgeo
.agblocks
);
211 printf(_("geom.datablocks = %llu\n"),
212 (unsigned long long) fsgeo
.datablocks
);
213 printf(_("geom.rtblocks = %llu\n"),
214 (unsigned long long) fsgeo
.rtblocks
);
215 printf(_("geom.rtextents = %llu\n"),
216 (unsigned long long) fsgeo
.rtextents
);
217 printf(_("geom.rtextsize = %u\n"), fsgeo
.rtextsize
);
218 printf(_("geom.sunit = %u\n"), fsgeo
.sunit
);
219 printf(_("geom.swidth = %u\n"), fsgeo
.swidth
);
221 if ((xfsctl(file
->name
, file
->fd
, XFS_IOC_FSCOUNTS
, &fscounts
)) < 0) {
222 perror("XFS_IOC_FSCOUNTS");
224 printf(_("counts.freedata = %llu\n"),
225 (unsigned long long) fscounts
.freedata
);
226 printf(_("counts.freertx = %llu\n"),
227 (unsigned long long) fscounts
.freertx
);
228 printf(_("counts.freeino = %llu\n"),
229 (unsigned long long) fscounts
.freeino
);
230 printf(_("counts.allocino = %llu\n"),
231 (unsigned long long) fscounts
.allocino
);
239 const char *filename
,
242 struct statx
*buffer
)
245 return syscall(__NR_statx
, dfd
, filename
, flags
, mask
, buffer
);
257 " Display extended file status.\n"
260 " -v -- More verbose output\n"
261 " -r -- Print raw statx structure fields\n"
262 " -m mask -- Specify the field mask for the statx call\n"
263 " (can also be 'basic' or 'all'; default STATX_ALL)\n"
264 " -D -- Don't sync attributes with the server\n"
265 " -F -- Force the attributes to be sync'd with the server\n"
271 dump_raw_statx(struct statx
*stx
)
273 printf("stat.mask = 0x%x\n", stx
->stx_mask
);
274 printf("stat.blksize = %u\n", stx
->stx_blksize
);
275 printf("stat.attributes = 0x%llx\n", stx
->stx_attributes
);
276 printf("stat.nlink = %u\n", stx
->stx_nlink
);
277 printf("stat.uid = %u\n", stx
->stx_uid
);
278 printf("stat.gid = %u\n", stx
->stx_gid
);
279 printf("stat.mode: 0%o\n", stx
->stx_mode
);
280 printf("stat.ino = %llu\n", stx
->stx_ino
);
281 printf("stat.size = %llu\n", stx
->stx_size
);
282 printf("stat.blocks = %llu\n", stx
->stx_blocks
);
283 printf("stat.atime.tv_sec = %lld\n", stx
->stx_atime
.tv_sec
);
284 printf("stat.atime.tv_nsec = %d\n", stx
->stx_atime
.tv_nsec
);
285 printf("stat.btime.tv_sec = %lld\n", stx
->stx_btime
.tv_sec
);
286 printf("stat.btime.tv_nsec = %d\n", stx
->stx_btime
.tv_nsec
);
287 printf("stat.ctime.tv_sec = %lld\n", stx
->stx_ctime
.tv_sec
);
288 printf("stat.ctime.tv_nsec = %d\n", stx
->stx_ctime
.tv_nsec
);
289 printf("stat.mtime.tv_sec = %lld\n", stx
->stx_mtime
.tv_sec
);
290 printf("stat.mtime.tv_nsec = %d\n", stx
->stx_mtime
.tv_nsec
);
291 printf("stat.rdev_major = %u\n", stx
->stx_rdev_major
);
292 printf("stat.rdev_minor = %u\n", stx
->stx_rdev_minor
);
293 printf("stat.dev_major = %u\n", stx
->stx_dev_major
);
294 printf("stat.dev_minor = %u\n", stx
->stx_dev_minor
);
300 * - input flags - query type
301 * - output style for flags (and all else?) (chars vs. hex?)
302 * - output - mask out incidental flag or not?
309 int c
, verbose
= 0, raw
= 0;
313 unsigned int mask
= STATX_ALL
;
315 while ((c
= getopt(argc
, argv
, "m:rvFD")) != EOF
) {
318 if (strcmp(optarg
, "basic") == 0)
319 mask
= STATX_BASIC_STATS
;
320 else if (strcmp(optarg
, "all") == 0)
323 mask
= strtoul(optarg
, &p
, 0);
324 if (!p
|| p
== optarg
) {
326 _("non-numeric mask -- %s\n"), optarg
);
338 atflag
&= ~AT_STATX_SYNC_TYPE
;
339 atflag
|= AT_STATX_FORCE_SYNC
;
342 atflag
&= ~AT_STATX_SYNC_TYPE
;
343 atflag
|= AT_STATX_DONT_SYNC
;
346 return command_usage(&statx_cmd
);
351 return command_usage(&statx_cmd
);
353 memset(&stx
, 0xbf, sizeof(stx
));
354 if (_statx(file
->fd
, "", atflag
| AT_EMPTY_PATH
, mask
, &stx
) < 0) {
360 return dump_raw_statx(&stx
);
364 printf(_("stat.ino = %lld\n"), (long long)stx
.stx_ino
);
365 printf(_("stat.type = %s\n"), filetype(stx
.stx_mode
));
366 printf(_("stat.size = %lld\n"), (long long)stx
.stx_size
);
367 printf(_("stat.blocks = %lld\n"), (long long)stx
.stx_blocks
);
369 printf(_("stat.atime = %s"), ctime((time_t *)&stx
.stx_atime
.tv_sec
));
370 printf(_("stat.mtime = %s"), ctime((time_t *)&stx
.stx_mtime
.tv_sec
));
371 printf(_("stat.ctime = %s"), ctime((time_t *)&stx
.stx_ctime
.tv_sec
));
372 if (stx
.stx_mask
& STATX_BTIME
)
373 printf(_("stat.btime = %s"),
374 ctime((time_t *)&stx
.stx_btime
.tv_sec
));
377 if (file
->flags
& IO_FOREIGN
)
380 print_xfs_info(verbose
);
388 stat_cmd
.name
= "stat";
389 stat_cmd
.cfunc
= stat_f
;
392 stat_cmd
.flags
= CMD_NOMAP_OK
| CMD_FOREIGN_OK
;
393 stat_cmd
.args
= _("[-v|-r]");
394 stat_cmd
.oneline
= _("statistics on the currently open file");
396 statx_cmd
.name
= "statx";
397 statx_cmd
.cfunc
= statx_f
;
398 statx_cmd
.argmin
= 0;
399 statx_cmd
.argmax
= -1;
400 statx_cmd
.flags
= CMD_NOMAP_OK
| CMD_FOREIGN_OK
;
401 statx_cmd
.args
= _("[-v|-r][-m basic | -m all | -m <mask>][-FD]");
402 statx_cmd
.oneline
= _("extended statistics on the currently open file");
403 statx_cmd
.help
= statx_help
;
405 statfs_cmd
.name
= "statfs";
406 statfs_cmd
.cfunc
= statfs_f
;
407 statfs_cmd
.flags
= CMD_NOMAP_OK
| CMD_FOREIGN_OK
;
409 _("statistics on the filesystem of the currently open file");
411 add_command(&stat_cmd
);
412 add_command(&statx_cmd
);
413 add_command(&statfs_cmd
);