1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2018 Red Hat, Inc.
12 static cmdinfo_t swapext_cmd
;
19 " Swaps extents between the open file descriptor and the supplied filename.\n"
27 struct xfs_bstat
*ubuffer
)
29 struct xfs_fsop_bulkreq bulkreq
;
31 bulkreq
.lastip
= (__u64
*)lastip
;
33 bulkreq
.ubuffer
= ubuffer
;
34 bulkreq
.ocount
= NULL
;
35 return ioctl(fd
, XFS_IOC_FSBULKSTAT_SINGLE
, &bulkreq
);
45 struct xfs_swapext sx
;
48 /* open the donor file */
49 fd
= openfile(argv
[1], NULL
, 0, 0, NULL
);
54 * stat the target file to get the inode number and use the latter to
55 * get the bulkstat info for the swapext cmd.
57 error
= fstat(file
->fd
, &stat
);
63 error
= xfs_bulkstat_single(file
->fd
, &stat
.st_ino
, &sx
.sx_stat
);
68 sx
.sx_version
= XFS_SX_VERSION
;
69 sx
.sx_fdtarget
= file
->fd
;
72 sx
.sx_length
= stat
.st_size
;
73 error
= ioctl(file
->fd
, XFS_IOC_SWAPEXT
, &sx
);
85 swapext_cmd
.name
= "swapext";
86 swapext_cmd
.cfunc
= swapext_f
;
87 swapext_cmd
.argmin
= 1;
88 swapext_cmd
.argmax
= 1;
89 swapext_cmd
.flags
= CMD_NOMAP_OK
;
90 swapext_cmd
.args
= _("<donorfile>");
91 swapext_cmd
.oneline
= _("Swap extents between files.");
92 swapext_cmd
.help
= swapext_help
;
94 add_command(&swapext_cmd
);