[PATCH v2] file_ioctl: decode FS_IOC{32,}_{G,S}ETFLAGS ioctls

Pierre Marsais pierre.marsais at lse.epita.fr
Sun Sep 15 16:44:51 UTC 2019


* xlat/inode_flags.in: New file.
* file_ioctl.c: Include "xlat/inode_flags.h".
(file_ioctl): Add decoding of FS_IOC_GETFLAGS, FS_IOC32_GETFLAGS,
FS_IOC_SETFLAGS, and FS_IOC32_SETFLAGS.
* tests/file_ioctl_inode_flags.c: New file.
* tests/gen_tests.in (file_ioctl_inode_flags): New entry.
* tests/pure_executables.list: Add file_ioctl_inode_flags.
* tests/.gitignore: Likewise.

Signed-off-by: Pierre Marsais <pierre.marsais at lse.epita.fr>
---
Hi,

Thank you for your comments, here is a v2 with some changes:
 - print flags in square brackets to reflect the indirection
 - remove meaningless preprocessor indentation in test
 - fix type issue in test (flags were stored in &arg instead of arg)

 file_ioctl.c                   | 21 +++++++++++++++++
 tests/.gitignore               |  1 +
 tests/file_ioctl_inode_flags.c | 43 ++++++++++++++++++++++++++++++++++
 tests/gen_tests.in             |  1 +
 tests/pure_executables.list    |  1 +
 xlat/inode_flags.in            | 28 ++++++++++++++++++++++
 6 files changed, 95 insertions(+)
 create mode 100644 tests/file_ioctl_inode_flags.c
 create mode 100644 xlat/inode_flags.in

diff --git a/file_ioctl.c b/file_ioctl.c
index 27ba4c82..214910d9 100644
--- a/file_ioctl.c
+++ b/file_ioctl.c
@@ -10,6 +10,8 @@
 #include <linux/ioctl.h>
 #include <linux/fs.h>
 
+#include "xlat/inode_flags.h"
+
 #ifdef HAVE_LINUX_FIEMAP_H
 # include <linux/fiemap.h>
 # include "xlat/fiemap_flags.h"
@@ -175,6 +177,25 @@ file_ioctl(struct tcb *const tcp, const unsigned int code,
 		return 0;
 	}
 
+	case FS_IOC_GETFLAGS:
+	case FS_IOC32_GETFLAGS:
+		if (entering(tcp))
+			return 0;
+		ATTRIBUTE_FALLTHROUGH;
+	case FS_IOC_SETFLAGS:
+	case FS_IOC32_SETFLAGS: {
+		uint32_t flags;
+
+		tprints(", ");
+		if (umove_or_printaddr(tcp, arg, &flags))
+			break;
+
+		tprints("[");
+		printflags(inode_flags, flags, "FS_???_FL");
+		tprints("]");
+		break;
+	}
+
 #ifdef HAVE_LINUX_FIEMAP_H
 	case FS_IOC_FIEMAP: {
 		struct fiemap args;
diff --git a/tests/.gitignore b/tests/.gitignore
index 4c854db8..e3ac0bb0 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -85,6 +85,7 @@ fdatasync
 fflush
 file_handle
 file_ioctl
+file_ioctl_inode_flags
 filter-unavailable
 finit_module
 flock
diff --git a/tests/file_ioctl_inode_flags.c b/tests/file_ioctl_inode_flags.c
new file mode 100644
index 00000000..3b8b3581
--- /dev/null
+++ b/tests/file_ioctl_inode_flags.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <linux/fs.h>
+#include "xlat.h"
+#include "xlat/inode_flags.h"
+
+int
+main(int argc, char *argv[])
+{
+	unsigned int *arg = tail_alloc(sizeof(unsigned int));
+
+	printf("ioctl(-1, "
+#if SIZEOF_LONG == 4
+	       "FS_IOC32_GETFLAGS or "
+#endif
+	       "FS_IOC_GETFLAGS, %p", arg);
+	ioctl(-1, FS_IOC_GETFLAGS, arg);
+	printf(") = -1 EBADF (%m)\n");
+
+	*arg = FS_EXTENT_FL | FS_NODUMP_FL;
+
+	printf("ioctl(-1, "
+#if SIZEOF_LONG == 4
+	       "FS_IOC32_SETFLAGS or "
+#endif
+	       "FS_IOC_SETFLAGS, [");
+	printflags(inode_flags, *arg, "FS_???_FL");
+	ioctl(-1, FS_IOC_SETFLAGS, arg);
+	printf("]) = -1 EBADF (%m)\n");
+
+	puts("+++ exited with 0 +++");
+
+	return 0;
+}
diff --git a/tests/gen_tests.in b/tests/gen_tests.in
index 13a46194..4329cc23 100644
--- a/tests/gen_tests.in
+++ b/tests/gen_tests.in
@@ -65,6 +65,7 @@ fcntl64	-a8
 fdatasync	-a14
 file_handle	-e trace=name_to_handle_at,open_by_handle_at
 file_ioctl	+ioctl.test
+file_ioctl_inode_flags	+ioctl.test
 finit_module	-a25
 flock	-a19
 fork-f	-a26 -qq -f -e signal=none -e trace=chdir
diff --git a/tests/pure_executables.list b/tests/pure_executables.list
index b565eb9c..02aa75f2 100755
--- a/tests/pure_executables.list
+++ b/tests/pure_executables.list
@@ -69,6 +69,7 @@ fdatasync
 fflush
 file_handle
 file_ioctl
+file_ioctl_inode_flags
 finit_module
 flock
 fsconfig
diff --git a/xlat/inode_flags.in b/xlat/inode_flags.in
new file mode 100644
index 00000000..c1ede511
--- /dev/null
+++ b/xlat/inode_flags.in
@@ -0,0 +1,28 @@
+FS_SECRM_FL		0x00000001
+FS_UNRM_FL		0x00000002
+FS_COMPR_FL		0x00000004
+FS_SYNC_FL		0x00000008
+FS_IMMUTABLE_FL		0x00000010
+FS_APPEND_FL		0x00000020
+FS_NODUMP_FL		0x00000040
+FS_NOATIME_FL		0x00000080
+
+FS_DIRTY_FL		0x00000100
+FS_COMPRBLK_FL		0x00000200
+FS_NOCOMP_FL		0x00000400
+
+FS_ENCRYPT_FL		0x00000800
+FS_BTREE_FL		0x00001000
+FS_INDEX_FL		0x00001000
+FS_IMAGIC_FL		0x00002000
+FS_JOURNAL_DATA_FL	0x00004000
+FS_NOTAIL_FL		0x00008000
+FS_DIRSYNC_FL		0x00010000
+FS_TOPDIR_FL		0x00020000
+FS_HUGE_FILE_FL		0x00040000
+FS_EXTENT_FL		0x00080000
+FS_EA_INODE_FL		0x00200000
+FS_EOFBLOCKS_FL		0x00400000
+FS_NOCOW_FL		0x00800000
+FS_INLINE_DATA_FL	0x10000000
+FS_PROJINHERIT_FL	0x20000000
-- 
2.23.0



More information about the Strace-devel mailing list