From: David Howells <dhowells@redhat.com>
To: Eric Sandeen <sandeen@sandeen.net>
Cc: dhowells@redhat.com, linux-xfs <linux-xfs@vger.kernel.org>,
Andreas Dilger <adilger@dilger.ca>,
Christoph Hellwig <hch@infradead.org>,
fsdevel <linux-fsdevel@vger.kernel.org>
Subject: [PATCH] xfs_io: changes to statx interface [ver #3]
Date: Wed, 29 Mar 2017 16:49:49 +0100 [thread overview]
Message-ID: <8127.1490802589@warthog.procyon.org.uk> (raw)
In-Reply-To: <3791d155-b448-5257-d8b9-8a6f20e12180@sandeen.net>
Here's my third attempt at changing Eric's statx patch. I've got rid of the
compare option to statx and added a raw output option to stat. They're still
not directly comparable since the stat output lacks some fields, but it will
hopefully be possible to load them into associative arrays in bash and compare
them that way.
---
diff --git a/io/stat.c b/io/stat.c
index a7aebcd..d2ea854 100644
--- a/io/stat.c
+++ b/io/stat.c
@@ -44,6 +44,35 @@ filesize(void)
return st.st_size;
}
+static int
+dump_raw_stat(struct stat *st)
+{
+ if (fstat(file->fd, st) < 0) {
+ perror("fstat");
+ return -1;
+ }
+
+ printf("stat.blksize: %lu\n", st->st_blksize);
+ printf("stat.nlink: %lu\n", st->st_nlink);
+ printf("stat.uid: %u\n", st->st_uid);
+ printf("stat.gid: %u\n", st->st_gid);
+ printf("stat.mode: 0%o\n", st->st_mode);
+ printf("stat.ino: %lu\n", st->st_ino);
+ printf("stat.size: %lu\n", st->st_size);
+ printf("stat.blocks: %lu\n", st->st_blocks);
+ printf("stat.atime.tv_sec: %ld\n", st->st_atim.tv_sec);
+ printf("stat.atime.tv_nsec: %ld\n", st->st_atim.tv_nsec);
+ printf("stat.ctime.tv_sec: %ld\n", st->st_ctim.tv_sec);
+ printf("stat.ctime.tv_nsec: %ld\n", st->st_ctim.tv_nsec);
+ printf("stat.mtime.tv_sec: %ld\n", st->st_mtim.tv_sec);
+ printf("stat.mtime.tv_nsec: %ld\n", st->st_mtim.tv_nsec);
+ printf("stat.rdev_major: %u\n", major(st->st_rdev));
+ printf("stat.rdev_minor: %u\n", minor(st->st_rdev));
+ printf("stat.dev_major: %u\n", major(st->st_dev));
+ printf("stat.dev_minor: %u\n", minor(st->st_dev));
+ return 0;
+}
+
static char *
filetype(mode_t mode)
{
@@ -74,7 +103,23 @@ stat_f(
struct dioattr dio;
struct fsxattr fsx, fsxa;
struct stat st;
- int verbose = (argc == 2 && !strcmp(argv[1], "-v"));
+ int c, verbose = 0, raw = 0;
+
+ while ((c = getopt(argc, argv, "rv")) != EOF) {
+ switch (c) {
+ case 'r':
+ raw = 1;
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ default:
+ return command_usage(&stat_cmd);
+ }
+ }
+
+ if (raw)
+ return dump_raw_stat(&st);
printf(_("fd.path = \"%s\"\n"), file->name);
printf(_("fd.flags = %s,%s,%s%s%s%s%s\n"),
@@ -189,12 +234,9 @@ statx_help(void)
" Display extended file status.\n"
"\n"
" Options:\n"
-" -m mask -- Specify the field mask for the statx call (default STATX_ALL)\n"
-" -A -- Suppress terminal automount traversal\n"
+" -m mask -- Specify the field mask for the statx call (can also be 'basic' or 'all'; default STATX_ALL)\n"
" -D -- Don't sync attributes with the server\n"
" -F -- Force the attributes to be sync'd with the server\n"
-" -L -- Follow symlinks (statx link target)\n"
-" -O -- Add only basic stats (STATX_BASIC_STATS) to default mask\n"
"\n"));
}
@@ -202,28 +244,28 @@ statx_help(void)
static void
dump_statx(struct statx *stx)
{
- printf("stx_mask: 0x%x\n", stx->stx_mask);
- printf("stx_blksize: %u\n", stx->stx_blksize);
- printf("stx_attributes: 0x%llx\n", stx->stx_attributes);
- printf("stx_nlink: %u\n", stx->stx_nlink);
- printf("stx_uid: %u\n", stx->stx_uid);
- printf("stx_gid: %u\n", stx->stx_gid);
- printf("stx_mode: 0%o\n", stx->stx_mode);
- printf("stx_ino: %llu\n", stx->stx_ino);
- printf("stx_size: %llu\n", stx->stx_size);
- printf("stx_blocks: %llu\n", stx->stx_blocks);
- printf("stx_atime.tv_sec: %lld\n", stx->stx_atime.tv_sec);
- printf("stx_atime.tv_nsec: %d\n", stx->stx_atime.tv_nsec);
- printf("stx_btime.tv_sec: %lld\n", stx->stx_btime.tv_sec);
- printf("stx_btime.tv_nsec: %d\n", stx->stx_btime.tv_nsec);
- printf("stx_ctime.tv_sec: %lld\n", stx->stx_ctime.tv_sec);
- printf("stx_ctime.tv_nsec: %d\n", stx->stx_ctime.tv_nsec);
- printf("stx_mtime.tv_sec: %lld\n", stx->stx_mtime.tv_sec);
- printf("stx_mtime.tv_nsec: %d\n", stx->stx_mtime.tv_nsec);
- printf("stx_rdev_major: %u\n", stx->stx_rdev_major);
- printf("stx_rdev_minor: %u\n", stx->stx_rdev_minor);
- printf("stx_dev_major: %u\n", stx->stx_dev_major);
- printf("stx_dev_minor: %u\n", stx->stx_dev_minor);
+ printf("stat.mask: 0x%x\n", stx->stx_mask);
+ printf("stat.blksize: %u\n", stx->stx_blksize);
+ printf("stat.attributes: 0x%llx\n", stx->stx_attributes);
+ printf("stat.nlink: %u\n", stx->stx_nlink);
+ printf("stat.uid: %u\n", stx->stx_uid);
+ printf("stat.gid: %u\n", stx->stx_gid);
+ printf("stat.mode: 0%o\n", stx->stx_mode);
+ printf("stat.ino: %llu\n", stx->stx_ino);
+ printf("stat.size: %llu\n", stx->stx_size);
+ printf("stat.blocks: %llu\n", stx->stx_blocks);
+ printf("stat.atime.tv_sec: %lld\n", stx->stx_atime.tv_sec);
+ printf("stat.atime.tv_nsec: %d\n", stx->stx_atime.tv_nsec);
+ printf("stat.btime.tv_sec: %lld\n", stx->stx_btime.tv_sec);
+ printf("stat.btime.tv_nsec: %d\n", stx->stx_btime.tv_nsec);
+ printf("stat.ctime.tv_sec: %lld\n", stx->stx_ctime.tv_sec);
+ printf("stat.ctime.tv_nsec: %d\n", stx->stx_ctime.tv_nsec);
+ printf("stat.mtime.tv_sec: %lld\n", stx->stx_mtime.tv_sec);
+ printf("stat.mtime.tv_nsec: %d\n", stx->stx_mtime.tv_nsec);
+ printf("stat.rdev_major: %u\n", stx->stx_rdev_major);
+ printf("stat.rdev_minor: %u\n", stx->stx_rdev_minor);
+ printf("stat.dev_major: %u\n", stx->stx_dev_major);
+ printf("stat.dev_minor: %u\n", stx->stx_dev_minor);
}
/*
@@ -239,16 +281,18 @@ statx_f(
{
int c;
struct statx stx;
- int atflag = AT_SYMLINK_NOFOLLOW;
- unsigned int m_mask = 0; /* mask requested with -m */
- int Oflag = 0, mflag = 0; /* -O or -m was used */
+ int atflag = 0;
unsigned int mask = STATX_ALL;
- while ((c = getopt(argc, argv, "m:FDLOA")) != EOF) {
+ while ((c = getopt(argc, argv, "m:FD")) != EOF) {
switch (c) {
case 'm':
- m_mask = atoi(optarg);
- mflag = 1;
+ if (strcmp(optarg, "basic") == 0)
+ mask = STATX_BASIC_STATS;
+ else if (strcmp(optarg, "all") == 0)
+ mask = STATX_ALL;
+ else
+ mask = strtoul(optarg, NULL, 0);
break;
case 'F':
atflag &= ~AT_STATX_SYNC_TYPE;
@@ -258,38 +302,19 @@ statx_f(
atflag &= ~AT_STATX_SYNC_TYPE;
atflag |= AT_STATX_DONT_SYNC;
break;
- case 'L':
- atflag &= ~AT_SYMLINK_NOFOLLOW;
- break;
- case 'O':
- mask = STATX_BASIC_STATS;
- Oflag = 1;
- break;
- case 'A':
- atflag |= AT_NO_AUTOMOUNT;
- break;
default:
return command_usage(&statx_cmd);
}
}
- if (Oflag && mflag) {
- printf("Cannot specify both -m mask and -O\n");
- return 0;
- }
-
- /* -m overrides any other mask options */
- if (mflag)
- mask = m_mask;
-
memset(&stx, 0xbf, sizeof(stx));
- if (statx(AT_FDCWD, file->name, atflag, mask, &stx) < 0) {
+
+ if (statx(file->fd, NULL, atflag, mask, &stx) < 0) {
perror("statx");
return 0;
}
-
+
dump_statx(&stx);
-
return 0;
}
@@ -301,7 +326,7 @@ stat_init(void)
stat_cmd.argmin = 0;
stat_cmd.argmax = 1;
stat_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
- stat_cmd.args = _("[-v]");
+ stat_cmd.args = _("[-rv]");
stat_cmd.oneline = _("information about the currently open file");
statfs_cmd.name = "statfs";
@@ -315,7 +340,7 @@ stat_init(void)
statx_cmd.argmin = 0;
statx_cmd.argmax = -1;
statx_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
- statx_cmd.args = _("[-O | -m mask][-FDLAP]");
+ statx_cmd.args = _("[-m basic | -m all | -m <mask>][-FD]");
statx_cmd.oneline =
_("extended information about the currently open file");
statx_cmd.help = statx_help;
diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
index 77ba760..486ad11 100644
--- a/man/man8/xfs_io.8
+++ b/man/man8/xfs_io.8
@@ -876,24 +876,29 @@ Only available in expert mode and requires privileges.
Force the filesystem to shutdown (with or without flushing the log).
Only available in expert mode and requires privileges.
.TP
-.BR stat " [ " \-v " ]"
+.BR stat " [ \-" rv " ]"
Selected statistics from
.BR stat (2)
and the XFS_IOC_GETXATTR system call on the current file. If the
.B \-v
option is specified, the atime (last access), mtime
-(last modify), and ctime (last change) timestamps are also displayed.
+(last modify), and ctime (last change) timestamps are also displayed. If the
+.B \-r
+option is specified, the raw output will be dumped in the same form as the
+output for the statx command, but with some fields missing.
.TP
-.BR statx " [ " \-O " | " "\-m mask" " ][ \-" FDLA " ]"
+.BR statx " [ " "\-m mask" " ][ \-" FD " ]"
Extended information from the statx syscall.
.RS 1.0i
.PD 0
.TP 0.4i
.B \-m mask
-Specify the field mask for the statx call (default STATX_ALL)
-.TP
-.B \-O
-Add only basic stats (STATX_BASIC_STATS) to default mask
+Specify the field mask for the statx call as an decimal, hex or octal integer
+or
+.RI \" basic "\" or \"" all \"
+to specify the basic stats that
+.IR stat ()
+returns or all the stats known by the header file. All is the default.
.TP
.B \-F
Force the attributes to be sync'd with the server
@@ -901,12 +906,6 @@ Force the attributes to be sync'd with the server
.B \-D
Don't sync attributes with the server
.TP
-.B \-L
-Follow symlinks (statx link target)
-.TP
-.B \-A
-Suppress terminal automount traversal
-.TP
.RE
.IP
.TP
next prev parent reply other threads:[~2017-03-29 15:49 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-24 4:32 [PATCH 0/2 V2] xfs_io: hook up statx Eric Sandeen
2017-03-24 4:34 ` [PATCH 1/2 V2] xfs_io: move stat functions to new file Eric Sandeen
2017-03-27 15:52 ` Darrick J. Wong
2017-03-24 4:45 ` [PATCH 2/2 V2] xfs_io: hook up statx Eric Sandeen
2017-03-27 15:54 ` Darrick J. Wong
2017-03-27 20:58 ` Eric Biggers
2017-03-28 21:57 ` Eric Sandeen
2017-03-27 10:00 ` [PATCH 0/2 " David Howells
2017-03-27 17:47 ` Eric Sandeen
2017-03-27 18:05 ` Eric Sandeen
2017-03-27 21:58 ` Dave Chinner
2017-03-28 7:30 ` Amir Goldstein
2017-03-28 9:39 ` David Howells
2017-03-27 20:20 ` [PATCH 2/2 " David Howells
2017-03-27 20:26 ` [PATCH 1/2 V2] xfs_io: move stat functions to new file David Howells
2017-03-27 20:32 ` Darrick J. Wong
2017-03-28 10:22 ` [PATCH] xfs_io: changes to statx interface David Howells
2017-03-28 10:51 ` Amir Goldstein
2017-03-28 12:31 ` David Howells
2017-03-28 13:34 ` Amir Goldstein
2017-03-28 14:04 ` David Howells
2017-03-28 18:01 ` Amir Goldstein
2017-03-28 14:38 ` [PATCH] xfs_io: changes to statx interface [ver #2] David Howells
2017-03-28 18:40 ` Andreas Dilger
2017-03-28 19:07 ` Amir Goldstein
2017-03-28 22:12 ` Eric Sandeen
2017-03-28 23:18 ` Dave Chinner
2017-03-29 15:24 ` David Howells
2017-03-28 14:41 ` David Howells
2017-03-28 16:42 ` Eric Sandeen
2017-03-28 17:35 ` Amir Goldstein
2017-03-28 20:36 ` Eric Sandeen
2017-03-28 17:56 ` David Howells
2017-03-28 18:11 ` Amir Goldstein
2017-03-29 15:49 ` David Howells [this message]
2017-03-29 21:32 ` [PATCH] xfs_io: changes to statx interface [ver #3] Eric Sandeen
2017-03-29 16:40 ` David Howells
2017-03-29 21:55 ` [PATCH] xfs_io: changes to statx interface [ver #4] David Howells
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8127.1490802589@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=adilger@dilger.ca \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@sandeen.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).