On 03/09/2017 10:24 PM, Eugene Syromyatnikov wrote:
PS. Btw, by a quick look at the patch (haven't reviewed it yet), I can
say that you at least forgot to wire up i386 arch [2], improperly
indented SEN(statx) and most probably would have problems with struct
statx name clash once glibc decided to support it.
Thank you for the quick review. Everything you mentioned is fixed now.
Other fixes include:
  1. statx may substitute approximate values, so there is no reason to
not print any field based on stx_mask;
  2. AT_STATX_* should be in a separate from xlat/at_flags.in file (2
failed tests because of this -- oops!)
>From e8754de2791ddb6c79fd51a49c83582c9d9a01d7 Mon Sep 17 00:00:00 2001
From: Victor Krapivensky <krapivenskiy...@phystech.edu>
Date: Thu, 9 Mar 2017 20:26:14 +0300
Subject: [PATCH v2] Add support for statx syscall

---
 Makefile.am                 |   1 +
 linux/32/syscallent.h       |   1 +
 linux/i386/syscallent.h     |   1 +
 linux/x32/syscallent.h      |   3 +-
 linux/x86_64/syscallent.h   |   1 +
 statx.c                     | 158 ++++++++++++++++++++++++++++++++++++++++++++
 xlat/at_statx_sync_types.in |   3 +
 xlat/statx_attrs.in         |   6 ++
 xlat/statx_masks.in         |  12 ++++
 9 files changed, 185 insertions(+), 1 deletion(-)
 create mode 100644 statx.c
 create mode 100644 xlat/at_statx_sync_types.in
 create mode 100644 xlat/statx_attrs.in
 create mode 100644 xlat/statx_masks.in

diff --git a/Makefile.am b/Makefile.am
index 7e837b3..e350fd2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -232,6 +232,7 @@ strace_SOURCES =	\
 	stat64.c	\
 	statfs.c	\
 	statfs.h	\
+	statx.c		\
 	strace.c	\
 	swapon.c	\
 	syscall.c	\
diff --git a/linux/32/syscallent.h b/linux/32/syscallent.h
index a8f9510..dc01852 100644
--- a/linux/32/syscallent.h
+++ b/linux/32/syscallent.h
@@ -281,6 +281,7 @@
 [288] = { 4,	TM|SI,		SEN(pkey_mprotect),		"pkey_mprotect"		},
 [289] = { 2,	0,		SEN(pkey_alloc),		"pkey_alloc"		},
 [290] = { 1,	0,		SEN(pkey_free),			"pkey_free"		},
+[383] = { 5,	TD|TF,		SEN(statx),			"statx"			},
 
 #undef sys_ARCH_mmap
 #undef ARCH_WANT_SYNC_FILE_RANGE2
diff --git a/linux/i386/syscallent.h b/linux/i386/syscallent.h
index 8ef1b1c..a2003d8 100644
--- a/linux/i386/syscallent.h
+++ b/linux/i386/syscallent.h
@@ -408,6 +408,7 @@
 [380] = { 4,	TM|SI,		SEN(pkey_mprotect),		"pkey_mprotect"		},
 [381] = { 2,	0,		SEN(pkey_alloc),		"pkey_alloc"		},
 [382] = { 1,	0,		SEN(pkey_free),			"pkey_free"		},
+[383] = { 1,	TD|TF,		SEN(statx),			"statx"			},
 
 #define SYS_socket_subcall	400
 #include "subcall.h"
diff --git a/linux/x32/syscallent.h b/linux/x32/syscallent.h
index 2699bc0..7f4e45b 100644
--- a/linux/x32/syscallent.h
+++ b/linux/x32/syscallent.h
@@ -330,7 +330,8 @@
 [329] = { 4,	TM|SI,		SEN(pkey_mprotect),		"pkey_mprotect"		},
 [330] = { 2,	0,		SEN(pkey_alloc),		"pkey_alloc"		},
 [331] = { 1,	0,		SEN(pkey_free),			"pkey_free"		},
-[332 ... 511] = { },
+[332] = { 5,	TD|TF,		SEN(statx),			"statx"			},
+[333 ... 511] = { },
 /*
  * x32-specific system call numbers start at 512 to avoid cache impact
  * for native 64-bit operation.
diff --git a/linux/x86_64/syscallent.h b/linux/x86_64/syscallent.h
index a1a268e..2624947 100644
--- a/linux/x86_64/syscallent.h
+++ b/linux/x86_64/syscallent.h
@@ -330,3 +330,4 @@
 [329] = { 4,	TM|SI,		SEN(pkey_mprotect),		"pkey_mprotect"		},
 [330] = { 2,	0,		SEN(pkey_alloc),		"pkey_alloc"		},
 [331] = { 1,	0,		SEN(pkey_free),			"pkey_free"		},
+[332] = { 5,	TD|TF,		SEN(statx),			"statx"			},
diff --git a/statx.c b/statx.c
new file mode 100644
index 0000000..244a4df
--- /dev/null
+++ b/statx.c
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2017 Victor Krapivensky <krapivenskiy...@phystech.edu>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "defs.h"
+
+#include <sys/stat.h>
+#include <linux/fcntl.h>
+
+#include "xlat/statx_masks.h"
+#include "xlat/statx_attrs.h"
+#include "xlat/at_statx_sync_types.h"
+
+struct struct_statx_timestamp {
+	int64_t sec;
+	int32_t nsec;
+	int32_t reserved;
+};
+
+struct struct_statx {
+	uint32_t stx_mask; /* What results were written [uncond] */
+	uint32_t stx_blksize; /* Preferred general I/O size [uncond] */
+	uint64_t stx_attributes; /* Flags conveying information about the file
+	                            [uncond] */
+
+	uint32_t stx_nlink; /* Number of hard links */
+	uint32_t stx_uid; /* User ID of owner */
+	uint32_t stx_gid; /* Group ID of owner */
+	uint16_t stx_mode; /* File mode */
+	uint16_t intpa_tre0[1];
+
+	uint64_t stx_ino; /* Inode number */
+	uint64_t stx_size; /* File size */
+	uint64_t stx_blocks; /* Number of 512-byte blocks allocated */
+	uint64_t intpa_tre1[1];
+
+	struct struct_statx_timestamp stx_atime; /* Last access time */
+	struct struct_statx_timestamp stx_btime; /* File creation time */
+	struct struct_statx_timestamp stx_ctime; /* Last attribute change
+	                                            time */
+	struct struct_statx_timestamp stx_mtime; /* Last data modification
+	                                            time */
+
+	uint32_t stx_rdev_major; /* Device ID of special file [if bdev/cdev] */
+	uint32_t stx_rdev_minor;
+	uint32_t stx_dev_major; /* ID of device containing file [uncond] */
+	uint32_t stx_dev_minor;
+
+	uint64_t intpa_tre2[16]; /* Spare space for future expansion */
+};
+
+SYS_FUNC(statx)
+{
+	if (entering(tcp)) {
+		print_dirfd(tcp, tcp->u_arg[0]);
+		printpath(tcp, tcp->u_arg[1]);
+		tprints(", ");
+		if (printflags(at_flags, tcp->u_arg[2] & ~AT_STATX_SYNC_TYPE,
+		               NULL))
+		{
+			tprints("|");
+		}
+		const char *name = xlookup(at_statx_sync_types,
+		                           tcp->u_arg[2] & AT_STATX_SYNC_TYPE);
+		if (name) {
+			tprints(name);
+		} else {
+			tprintf("%#llx /* AT_STATX_SYNC_TYPE_??? */",
+			        (unsigned long long) tcp->u_arg[2]);
+		}
+		tprints(", ");
+		printflags(statx_masks, tcp->u_arg[3], "STATX_???");
+		tprints(", ");
+	} else {
+#define PRINT_FIELD_U(field) \
+	tprintf(", %s=%llu", #field, (unsigned long long) stx.field)
+
+#define ABS(x) ((x) < 0 ? -(x) : (x))
+
+#define PRINT_FIELD_TIME(field)						\
+	do {								\
+		tprints(", " #field "=");				\
+		tprints(sprinttime(stx.field.sec));			\
+		tprintf(".%09lld", (long long) ABS(stx.field.nsec));	\
+	} while (0)
+
+		struct struct_statx stx;
+		if (umove_or_printaddr(tcp, tcp->u_arg[4], &stx)) {
+			return 0;
+		}
+		tprints("{stx_mask=");
+		printflags(statx_masks, stx.stx_mask, "STATX_???");
+		if (!abbrev(tcp)) {
+			PRINT_FIELD_U(stx_blksize);
+		}
+		tprints(", stx_attributes=");
+		printflags(statx_attrs, stx.stx_attributes, "STATX_ATTR_???");
+		if (!abbrev(tcp)) {
+			PRINT_FIELD_U(stx_nlink);
+			PRINT_FIELD_U(stx_uid);
+			PRINT_FIELD_U(stx_gid);
+		}
+		if (stx.stx_mask & (STATX_MODE | STATX_TYPE)) {
+			tprints(", stx_mode=");
+			print_symbolic_mode_t(stx.stx_mode);
+		}
+		if (!abbrev(tcp)) {
+			PRINT_FIELD_U(stx_ino);
+		}
+		PRINT_FIELD_U(stx_size);
+		if (!abbrev(tcp)) {
+			PRINT_FIELD_U(stx_blocks);
+			PRINT_FIELD_TIME(stx_atime);
+			PRINT_FIELD_TIME(stx_btime);
+			PRINT_FIELD_TIME(stx_ctime);
+			PRINT_FIELD_TIME(stx_mtime);
+		}
+		if (stx.stx_mask & STATX_TYPE) {
+			switch (stx.stx_mask & S_IFMT) {
+			case S_IFCHR: case S_IFBLK:
+				PRINT_FIELD_U(stx_rdev_major);
+				PRINT_FIELD_U(stx_rdev_minor);
+				break;
+			}
+		}
+		if (!abbrev(tcp)) {
+			PRINT_FIELD_U(stx_dev_major);
+			PRINT_FIELD_U(stx_dev_minor);
+		} else {
+			tprints(", ...");
+		}
+		tprints("}");
+	}
+	return 0;
+}
diff --git a/xlat/at_statx_sync_types.in b/xlat/at_statx_sync_types.in
new file mode 100644
index 0000000..bc966b3
--- /dev/null
+++ b/xlat/at_statx_sync_types.in
@@ -0,0 +1,3 @@
+AT_STATX_SYNC_AS_STAT	0x0000
+AT_STATX_FORCE_SYNC	0x2000
+AT_STATX_DONT_SYNC	0x4000
diff --git a/xlat/statx_attrs.in b/xlat/statx_attrs.in
new file mode 100644
index 0000000..f6e4078
--- /dev/null
+++ b/xlat/statx_attrs.in
@@ -0,0 +1,6 @@
+STATX_ATTR_COMPRESSED	0x00000004
+STATX_ATTR_IMMUTABLE	0x00000010
+STATX_ATTR_APPEND	0x00000020
+STATX_ATTR_NODUMP	0x00000040
+STATX_ATTR_ENCRYPTED	0x00000800
+STATX_ATTR_AUTOMOUNT	0x00001000
diff --git a/xlat/statx_masks.in b/xlat/statx_masks.in
new file mode 100644
index 0000000..0986bce
--- /dev/null
+++ b/xlat/statx_masks.in
@@ -0,0 +1,12 @@
+STATX_TYPE	0x00000001U
+STATX_MODE	0x00000002U
+STATX_NLINK	0x00000004U
+STATX_UID	0x00000008U
+STATX_GID	0x00000010U
+STATX_ATIME	0x00000020U
+STATX_MTIME	0x00000040U
+STATX_CTIME	0x00000080U
+STATX_INO	0x00000100U
+STATX_SIZE	0x00000200U
+STATX_BLOCKS	0x00000400U
+STATX_BTIME	0x00000800U
-- 
2.10.2

------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
_______________________________________________
Strace-devel mailing list
Strace-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to