summaryrefslogtreecommitdiff
path: root/fs/open.c
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2021-09-01 11:25:39 -0700
committerDarrick J. Wong <djwong@kernel.org>2021-12-15 17:29:29 -0800
commit9ce7cdaa061e17128626e0b880adfed00455931d (patch)
treefb53e2ea4d95e13a23e512f19d15dc8f78d77c55 /fs/open.c
parentb68950039f7467e0f1e439cfa144211b23b9dc61 (diff)
xfs: fallocate free space into a file
Add a new fallocate mode to map free physical space into a file, at the same file offset as if the file were a sparse image of the physical device backing the filesystem. The intent here is to use this to prototype a free space defragmentation tool. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Diffstat (limited to 'fs/open.c')
-rw-r--r--fs/open.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/fs/open.c b/fs/open.c
index f732fb94600c..0b56adadb986 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -261,6 +261,11 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
(mode & ~(FALLOC_FL_UNSHARE_RANGE | FALLOC_FL_KEEP_SIZE)))
return -EINVAL;
+ /* Mapping free space should only be used by itself. */
+ if ((mode & FALLOC_FL_MAP_FREE_SPACE) &&
+ (mode & ~FALLOC_FL_MAP_FREE_SPACE))
+ return -EINVAL;
+
if (!(file->f_mode & FMODE_WRITE))
return -EBADF;