diff options
author | Darrick J. Wong <djwong@kernel.org> | 2022-07-14 11:16:23 -0700 |
---|---|---|
committer | Darrick J. Wong <djwong@kernel.org> | 2022-11-09 19:08:16 -0800 |
commit | e936e495ae1b7cf83a33e9b530dfa903a30dfad6 (patch) | |
tree | f28737b2e7b35c8ff74eee3df5588caa1a92d506 /fs/open.c | |
parent | 59f8bca3c5e494751aaded276dc0366dc4b87a82 (diff) |
xfs: fallocate free space into a filedefrag-freespace_2022-11-09
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.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/fs/open.c b/fs/open.c index a81319b6177f..4b6096014c9c 100644 --- a/fs/open.c +++ b/fs/open.c @@ -277,6 +277,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; |