2 * Copyright (c) 2016 Jeff Mahoney <jeffm@suse.com>
3 * Copyright (c) 2016-2018 The strace developers.
6 * SPDX-License-Identifier: LGPL-2.1-or-later
10 #include <linux/ioctl.h>
13 #ifdef HAVE_LINUX_FIEMAP_H
14 # include <linux/fiemap.h>
15 # include "xlat/fiemap_flags.h"
16 # include "xlat/fiemap_extent_flags.h"
20 # define FICLONE _IOW(0x94, 9, int)
24 # define FICLONERANGE _IOW(0x94, 13, struct file_clone_range)
25 struct file_clone_range {
34 # define FIDEDUPERANGE _IOWR(0x94, 54, struct file_dedupe_range)
35 struct file_dedupe_range_info {
36 int64_t dest_fd; /* in - destination file */
37 uint64_t dest_offset; /* in - start of extent in destination */
38 uint64_t bytes_deduped; /* out - total # of bytes we were able
39 * to dedupe from this file. */
40 /* status of this dedupe operation:
42 * == FILE_DEDUPE_RANGE_SAME if dedupe succeeds
43 * == FILE_DEDUPE_RANGE_DIFFERS if data differs
45 int32_t status; /* out - see above description */
46 uint32_t reserved; /* must be zero */
49 struct file_dedupe_range {
50 uint64_t src_offset; /* in - start of extent in source */
51 uint64_t src_length; /* in - length of extent */
52 uint16_t dest_count; /* in - total elements in info array */
53 uint16_t reserved1; /* must be zero */
54 uint32_t reserved2; /* must be zero */
55 struct file_dedupe_range_info info[0];
60 print_file_dedupe_range_info(struct tcb *tcp, void *elem_buf,
61 size_t elem_size, void *data)
63 const struct file_dedupe_range_info *info = elem_buf;
64 unsigned int *count = data;
76 printfd(tcp, info->dest_fd);
77 tprintf(", dest_offset=%" PRIu64 "}",
78 (uint64_t) info->dest_offset);
80 tprintf("{bytes_deduped=%" PRIu64 ", status=%d}",
81 (uint64_t) info->bytes_deduped, info->status);
87 #ifdef HAVE_LINUX_FIEMAP_H
89 print_fiemap_extent(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
91 const struct fiemap_extent *fe = elem_buf;
93 tprintf("{fe_logical=%" PRI__u64
94 ", fe_physical=%" PRI__u64
95 ", fe_length=%" PRI__u64 ", ",
96 fe->fe_logical, fe->fe_physical, fe->fe_length);
98 printflags64(fiemap_extent_flags, fe->fe_flags,
104 #endif /* HAVE_LINUX_FIEMAP_H */
107 file_ioctl(struct tcb *const tcp, const unsigned int code,
108 const kernel_ulong_t arg)
111 case FICLONE: /* W */
112 tprintf(", %d", (int) arg);
115 case FICLONERANGE: { /* W */
116 struct file_clone_range args;
119 if (umove_or_printaddr(tcp, arg, &args))
123 printfd(tcp, args.src_fd);
124 tprintf(", src_offset=%" PRIu64
125 ", src_length=%" PRIu64
126 ", dest_offset=%" PRIu64 "}",
127 (uint64_t) args.src_offset,
128 (uint64_t) args.src_length,
129 (uint64_t) args.dest_offset);
133 case FIDEDUPERANGE: { /* RW */
134 struct file_dedupe_range args;
135 struct file_dedupe_range_info info;
136 unsigned int *limit = NULL;
137 unsigned int count = 2;
142 else if (syserror(tcp))
147 if (umove_or_printaddr(tcp, arg, &args))
152 tprintf("src_offset=%" PRIu64
153 ", src_length=%" PRIu64
154 ", dest_count=%hu, ",
155 (uint64_t) args.src_offset,
156 (uint64_t) args.src_length,
157 (uint16_t) args.dest_count);
162 /* Limit how many elements we print in abbrev mode. */
163 if (abbrev(tcp) && args.dest_count > count)
166 rc = print_array(tcp, arg + offsetof(typeof(args), info),
167 args.dest_count, &info, sizeof(info),
169 print_file_dedupe_range_info, limit);
172 if (!rc || exiting(tcp))
178 #ifdef HAVE_LINUX_FIEMAP_H
179 case FS_IOC_FIEMAP: {
184 else if (syserror(tcp))
189 if (umove_or_printaddr(tcp, arg, &args))
193 tprintf("{fm_start=%" PRI__u64 ", "
194 "fm_length=%" PRI__u64 ", "
196 args.fm_start, args.fm_length);
197 printflags64(fiemap_flags, args.fm_flags,
199 tprintf(", fm_extent_count=%u}", args.fm_extent_count);
203 tprints("{fm_flags=");
204 printflags64(fiemap_flags, args.fm_flags,
206 tprintf(", fm_mapped_extents=%u",
207 args.fm_mapped_extents);
211 struct fiemap_extent fe;
212 tprints(", fm_extents=");
214 arg + offsetof(typeof(args), fm_extents),
215 args.fm_mapped_extents, &fe, sizeof(fe),
217 print_fiemap_extent, 0);
223 #endif /* HAVE_LINUX_FIEMAP_H */
229 return RVAL_IOCTL_DECODED;