]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libfrog: add support for exchange range ioctl family
authorDarrick J. Wong <djwong@kernel.org>
Mon, 29 Jul 2024 23:23:00 +0000 (16:23 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:01:05 +0000 (17:01 -0700)
Add some library code to support the new file range exchange and commit
ioctls.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
libfrog/Makefile
libfrog/file_exchange.c [new file with mode: 0644]
libfrog/file_exchange.h [new file with mode: 0644]

index cafee073fe3cb9327cb8eb7aa5a50f8b19f0a815..53e3c3492377d8a7d346ca29425b285fdd2df988 100644 (file)
@@ -18,6 +18,7 @@ bitmap.c \
 bulkstat.c \
 convert.c \
 crc32.c \
+file_exchange.c \
 fsgeom.c \
 list_sort.c \
 linux.c \
@@ -42,6 +43,7 @@ crc32defs.h \
 crc32table.h \
 dahashselftest.h \
 div64.h \
+file_exchange.h \
 fsgeom.h \
 logging.h \
 paths.h \
diff --git a/libfrog/file_exchange.c b/libfrog/file_exchange.c
new file mode 100644 (file)
index 0000000..29fdc17
--- /dev/null
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020-2024 Oracle.  All Rights Reserved.
+ * Author: Darrick J. Wong <djwong@kernel.org>
+ */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <string.h>
+#include "xfs.h"
+#include "fsgeom.h"
+#include "bulkstat.h"
+#include "libfrog/file_exchange.h"
+
+/* Prepare for a file contents exchange. */
+void
+xfrog_exchangerange_prep(
+       struct xfs_exchange_range       *fxr,
+       off_t                           file2_offset,
+       int                             file1_fd,
+       off_t                           file1_offset,
+       uint64_t                        length)
+{
+       memset(fxr, 0, sizeof(*fxr));
+
+       fxr->file1_fd                   = file1_fd;
+       fxr->file1_offset               = file1_offset;
+       fxr->length                     = length;
+       fxr->file2_offset               = file2_offset;
+}
+
+/*
+ * Execute an exchange-range operation.  Returns 0 for success or a negative
+ * errno.
+ */
+int
+xfrog_exchangerange(
+       int                             file2_fd,
+       struct xfs_exchange_range       *fxr,
+       uint64_t                        flags)
+{
+       int                             ret;
+
+       fxr->flags = flags;
+
+       ret = ioctl(file2_fd, XFS_IOC_EXCHANGE_RANGE, fxr);
+       if (ret)
+               return -errno;
+
+       return 0;
+}
diff --git a/libfrog/file_exchange.h b/libfrog/file_exchange.h
new file mode 100644 (file)
index 0000000..b6f6f9f
--- /dev/null
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2020-2024 Oracle.  All rights reserved.
+ * All Rights Reserved.
+ */
+#ifndef __LIBFROG_FILE_EXCHANGE_H__
+#define __LIBFROG_FILE_EXCHANGE_H__
+
+void xfrog_exchangerange_prep(struct xfs_exchange_range *fxr,
+               off_t file2_offset, int file1_fd,
+               off_t file1_offset, uint64_t length);
+int xfrog_exchangerange(int file2_fd, struct xfs_exchange_range *fxr,
+               uint64_t flags);
+
+#endif /* __LIBFROG_FILE_EXCHANGE_H__ */