]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/swapext.c
dc4e418f2650fc4246f3303eca311a4c10182891
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2018 Red Hat, Inc.
11 #include "libfrog/logging.h"
12 #include "libfrog/fsgeom.h"
13 #include "libfrog/bulkstat.h"
15 static cmdinfo_t swapext_cmd
;
22 " Swaps extents between the open file descriptor and the supplied filename.\n"
31 struct xfs_fd fxfd
= XFS_FD_INIT(file
->fd
);
32 struct xfs_bulkstat bulkstat
;
35 struct xfs_swapext sx
;
38 /* open the donor file */
39 fd
= openfile(argv
[1], NULL
, 0, 0, NULL
);
44 * stat the target file to get the inode number and use the latter to
45 * get the bulkstat info for the swapext cmd.
47 error
= fstat(file
->fd
, &stat
);
53 error
= xfrog_bulkstat_single(&fxfd
, stat
.st_ino
, 0, &bulkstat
);
55 xfrog_perror(error
, "bulkstat");
58 error
= xfrog_bulkstat_v5_to_v1(&fxfd
, &sx
.sx_stat
, &bulkstat
);
60 xfrog_perror(error
, "bulkstat conversion");
63 sx
.sx_version
= XFS_SX_VERSION
;
64 sx
.sx_fdtarget
= file
->fd
;
67 sx
.sx_length
= stat
.st_size
;
68 error
= ioctl(file
->fd
, XFS_IOC_SWAPEXT
, &sx
);
80 swapext_cmd
.name
= "swapext";
81 swapext_cmd
.cfunc
= swapext_f
;
82 swapext_cmd
.argmin
= 1;
83 swapext_cmd
.argmax
= 1;
84 swapext_cmd
.flags
= CMD_NOMAP_OK
;
85 swapext_cmd
.args
= _("<donorfile>");
86 swapext_cmd
.oneline
= _("Swap extents between files.");
87 swapext_cmd
.help
= swapext_help
;
89 add_command(&swapext_cmd
);