1 /*
2 * Copyright (c) 2014 Mike Frysinger <vapier@gentoo.org>
3 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@strace.io>
4 * Copyright (c) 2016-2021 The strace developers.
5 * All rights reserved.
6 *
7 * SPDX-License-Identifier: LGPL-2.1-or-later
8 */
9
10 #include "defs.h"
11 #include <linux/fs.h>
12
13 static void
14 decode_fstrim_range(struct tcb *const tcp, const kernel_ulong_t arg)
15 {
16 struct fstrim_range range;
17
18 if (!umove_or_printaddr(tcp, arg, &range)) {
19 tprint_struct_begin();
20 PRINT_FIELD_X(range, start);
21 tprint_struct_next();
22 PRINT_FIELD_U(range, len);
23 tprint_struct_next();
24 PRINT_FIELD_U(range, minlen);
25 tprint_struct_end();
26 }
27 }
28
29 #include "xlat/fs_xflags.h"
30
31 static void
32 decode_fsxattr(struct tcb *const tcp, const kernel_ulong_t arg,
33 const bool is_get)
34 {
35 struct fsxattr fsxattr;
36
37 if (!umove_or_printaddr(tcp, arg, &fsxattr)) {
38 tprint_struct_begin();
39 PRINT_FIELD_FLAGS(fsxattr, fsx_xflags, fs_xflags, "FS_XFLAG_???");
40 tprint_struct_next();
41 PRINT_FIELD_U(fsxattr, fsx_extsize);
42 if (is_get) {
43 tprint_struct_next();
44 PRINT_FIELD_U(fsxattr, fsx_nextents);
45 }
46 tprint_struct_next();
47 PRINT_FIELD_X(fsxattr, fsx_projid);
48 tprint_struct_next();
49 PRINT_FIELD_U(fsxattr, fsx_cowextsize);
50 tprint_struct_end();
51 }
52 }
53
54 int
55 fs_x_ioctl(struct tcb *const tcp, const unsigned int code,
56 const kernel_ulong_t arg)
57 {
58 switch (code) {
59 case FITRIM:
60 tprint_arg_next();
61 decode_fstrim_range(tcp, arg);
62 break;
63
64 case FS_IOC_FSGETXATTR:
65 if (entering(tcp))
66 return 0;
67 tprint_arg_next();
68 decode_fsxattr(tcp, arg, true);
69 break;
70
71 case FS_IOC_FSSETXATTR:
72 tprint_arg_next();
73 decode_fsxattr(tcp, arg, false);
74 break;
75
76 /* No arguments */
77 case FIFREEZE:
78 case FITHAW:
79 break;
80
81 default:
82 return RVAL_DECODED;
83 }
84
85 return RVAL_IOCTL_DECODED;
86 }