aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/open.c8
-rw-r--r--include/linux/falloc.h6
-rw-r--r--include/uapi/linux/falloc.h17
3 files changed, 29 insertions, 2 deletions
diff --git a/fs/open.c b/fs/open.c
index 33f9cbf2610b..b724cc0e0228 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -231,8 +231,7 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
231 return -EINVAL; 231 return -EINVAL;
232 232
233 /* Return error if mode is not supported */ 233 /* Return error if mode is not supported */
234 if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | 234 if (mode & ~FALLOC_FL_SUPPORTED_MASK)
235 FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE))
236 return -EOPNOTSUPP; 235 return -EOPNOTSUPP;
237 236
238 /* Punch hole and zero range are mutually exclusive */ 237 /* Punch hole and zero range are mutually exclusive */
@@ -250,6 +249,11 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
250 (mode & ~FALLOC_FL_COLLAPSE_RANGE)) 249 (mode & ~FALLOC_FL_COLLAPSE_RANGE))
251 return -EINVAL; 250 return -EINVAL;
252 251
252 /* Insert range should only be used exclusively. */
253 if ((mode & FALLOC_FL_INSERT_RANGE) &&
254 (mode & ~FALLOC_FL_INSERT_RANGE))
255 return -EINVAL;
256
253 if (!(file->f_mode & FMODE_WRITE)) 257 if (!(file->f_mode & FMODE_WRITE))
254 return -EBADF; 258 return -EBADF;
255 259
diff --git a/include/linux/falloc.h b/include/linux/falloc.h
index 31591686ac2d..996111000a8c 100644
--- a/include/linux/falloc.h
+++ b/include/linux/falloc.h
@@ -21,4 +21,10 @@ struct space_resv {
21#define FS_IOC_RESVSP _IOW('X', 40, struct space_resv) 21#define FS_IOC_RESVSP _IOW('X', 40, struct space_resv)
22#define FS_IOC_RESVSP64 _IOW('X', 42, struct space_resv) 22#define FS_IOC_RESVSP64 _IOW('X', 42, struct space_resv)
23 23
24#define FALLOC_FL_SUPPORTED_MASK (FALLOC_FL_KEEP_SIZE | \
25 FALLOC_FL_PUNCH_HOLE | \
26 FALLOC_FL_COLLAPSE_RANGE | \
27 FALLOC_FL_ZERO_RANGE | \
28 FALLOC_FL_INSERT_RANGE)
29
24#endif /* _FALLOC_H_ */ 30#endif /* _FALLOC_H_ */
diff --git a/include/uapi/linux/falloc.h b/include/uapi/linux/falloc.h
index d1197ae3723c..3e445a760f14 100644
--- a/include/uapi/linux/falloc.h
+++ b/include/uapi/linux/falloc.h
@@ -41,4 +41,21 @@
41 */ 41 */
42#define FALLOC_FL_ZERO_RANGE 0x10 42#define FALLOC_FL_ZERO_RANGE 0x10
43 43
44/*
45 * FALLOC_FL_INSERT_RANGE is use to insert space within the file size without
46 * overwriting any existing data. The contents of the file beyond offset are
47 * shifted towards right by len bytes to create a hole. As such, this
48 * operation will increase the size of the file by len bytes.
49 *
50 * Different filesystems may implement different limitations on the granularity
51 * of the operation. Most will limit operations to filesystem block size
52 * boundaries, but this boundary may be larger or smaller depending on
53 * the filesystem and/or the configuration of the filesystem or file.
54 *
55 * Attempting to insert space using this flag at OR beyond the end of
56 * the file is considered an illegal operation - just use ftruncate(2) or
57 * fallocate(2) with mode 0 for such type of operations.
58 */
59#define FALLOC_FL_INSERT_RANGE 0x20
60
44#endif /* _UAPI_FALLOC_H_ */ 61#endif /* _UAPI_FALLOC_H_ */