summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@strace.io>2021-01-04 08:00:00 +0000
committerDmitry V. Levin <ldv@strace.io>2021-01-04 08:00:00 +0000
commit5af15448d3580950b463154fa3c5445b6179dd71 (patch)
tree01d469516873d9a4d0de945ab8277716c15de854
parent15af9719511da8485d3f93c3290e64d66586b4b3 (diff)
downloadstrace-5af15448d3580950b463154fa3c5445b6179dd71.tar.gz
file_ioctl: refactor FS_IOC_FIEMAP decoding
* file_ioctl.c (decode_fiemap): New function. (file_ioctl): Use it.
-rw-r--r--file_ioctl.c80
1 files changed, 41 insertions, 39 deletions
diff --git a/file_ioctl.c b/file_ioctl.c
index 1dada177d..86fae81a9 100644
--- a/file_ioctl.c
+++ b/file_ioctl.c
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2016 Jeff Mahoney <jeffm@suse.com>
- * Copyright (c) 2016-2020 The strace developers.
+ * Copyright (c) 2016-2021 The strace developers.
* All rights reserved.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
@@ -31,52 +31,54 @@ print_fiemap_extent(struct tcb *tcp, void *elem_buf, size_t elem_size, void *dat
return true;
}
-int
-file_ioctl(struct tcb *const tcp, const unsigned int code,
- const kernel_ulong_t arg)
+static int
+decode_fiemap(struct tcb *const tcp, const kernel_ulong_t arg)
{
- switch (code) {
- case FS_IOC_FIEMAP: {
- struct_fiemap args;
+ struct_fiemap args;
- if (entering(tcp))
- tprints(", ");
- else if (syserror(tcp))
- break;
- else
- tprints(" => ");
+ if (entering(tcp))
+ tprints(", ");
+ else if (syserror(tcp))
+ return RVAL_IOCTL_DECODED;
+ else
+ tprints(" => ");
- if (umove_or_printaddr(tcp, arg, &args))
- break;
+ if (umove_or_printaddr(tcp, arg, &args))
+ return RVAL_IOCTL_DECODED;
- if (entering(tcp)) {
- PRINT_FIELD_U("{", args, fm_start);
- PRINT_FIELD_U(", ", args, fm_length);
- PRINT_FIELD_FLAGS(", ", args, fm_flags, fiemap_flags,
- "FIEMAP_FLAG_???");
- PRINT_FIELD_U(", ", args, fm_extent_count);
- tprints("}");
- return 0;
- }
-
- PRINT_FIELD_FLAGS("{", args, fm_flags, fiemap_flags,
+ if (entering(tcp)) {
+ PRINT_FIELD_U("{", args, fm_start);
+ PRINT_FIELD_U(", ", args, fm_length);
+ PRINT_FIELD_FLAGS(", ", args, fm_flags, fiemap_flags,
"FIEMAP_FLAG_???");
- PRINT_FIELD_U(", ", args, fm_mapped_extents);
- if (abbrev(tcp)) {
- tprints(", ...");
- } else {
- struct_fiemap_extent fe;
- tprints(", fm_extents=");
- print_array(tcp,
- arg + offsetof(typeof(args), fm_extents),
- args.fm_mapped_extents, &fe, sizeof(fe),
- tfetch_mem,
- print_fiemap_extent, 0);
- }
+ PRINT_FIELD_U(", ", args, fm_extent_count);
tprints("}");
+ return 0;
+ }
- break;
+ PRINT_FIELD_FLAGS("{", args, fm_flags, fiemap_flags, "FIEMAP_FLAG_???");
+ PRINT_FIELD_U(", ", args, fm_mapped_extents);
+ if (abbrev(tcp)) {
+ tprints(", ...");
+ } else {
+ struct_fiemap_extent fe;
+ tprints(", fm_extents=");
+ print_array(tcp, arg + offsetof(typeof(args), fm_extents),
+ args.fm_mapped_extents, &fe, sizeof(fe),
+ tfetch_mem, print_fiemap_extent, 0);
}
+ tprints("}");
+
+ return RVAL_IOCTL_DECODED;
+}
+
+int
+file_ioctl(struct tcb *const tcp, const unsigned int code,
+ const kernel_ulong_t arg)
+{
+ switch (code) {
+ case FS_IOC_FIEMAP:
+ return decode_fiemap(tcp, arg);
default:
return RVAL_DECODED;