1 Implement new flags and values for mode argument.
3 This patch implements the new flags and values for the "mode" argument
4 of the fallocate system call. It is based on the discussion between
5 Andreas Dilger and David Chinner on the man page proposed (by the later)
8 Signed-off-by: Amit Arora <aarora@in.ibm.com>
10 Index: linux-2.6.22-rc4/include/linux/fs.h
11 ===================================================================
12 --- linux-2.6.22-rc4.orig/include/linux/fs.h
13 +++ linux-2.6.22-rc4/include/linux/fs.h
14 @@ -267,15 +267,16 @@ extern int dir_notify_enable;
15 #define SYNC_FILE_RANGE_WAIT_AFTER 4
18 - * sys_fallocate modes
19 - * Currently sys_fallocate supports two modes:
20 - * FA_ALLOCATE : This is the preallocate mode, using which an application/user
21 - * may request (pre)allocation of blocks.
22 - * FA_DEALLOCATE: This is the deallocate mode, which can be used to free
23 - * the preallocated blocks.
24 + * sys_fallocate mode flags and values
26 -#define FA_ALLOCATE 0x1
27 -#define FA_DEALLOCATE 0x2
28 +#define FA_FL_DEALLOC 0x01 /* default is allocate */
29 +#define FA_FL_KEEP_SIZE 0x02 /* default is extend/shrink size */
30 +#define FA_FL_DEL_DATA 0x04 /* default is keep written data on DEALLOC */
32 +#define FA_ALLOCATE 0
33 +#define FA_DEALLOCATE FA_FL_DEALLOC
34 +#define FA_RESV_SPACE FA_FL_KEEP_SIZE
35 +#define FA_UNRESV_SPACE (FA_FL_DEALLOC | FA_FL_KEEP_SIZE | FA_FL_DEL_DATA)
39 Index: linux-2.6.22-rc4/fs/open.c
40 ===================================================================
41 --- linux-2.6.22-rc4.orig/fs/open.c
42 +++ linux-2.6.22-rc4/fs/open.c
43 @@ -356,23 +356,26 @@ asmlinkage long sys_ftruncate64(unsigned
44 * sys_fallocate - preallocate blocks or free preallocated blocks
45 * @fd: the file descriptor
46 * @mode: mode specifies if fallocate should preallocate blocks OR free
47 - * (unallocate) preallocated blocks. Currently only FA_ALLOCATE and
48 - * FA_DEALLOCATE modes are supported.
49 + * (unallocate) preallocated blocks.
50 * @offset: The offset within file, from where (un)allocation is being
51 * requested. It should not have a negative value.
52 * @len: The amount (in bytes) of space to be (un)allocated, from the offset.
54 * This system call, depending on the mode, preallocates or unallocates blocks
55 * for a file. The range of blocks depends on the value of offset and len
56 - * arguments provided by the user/application. For FA_ALLOCATE mode, if this
57 + * arguments provided by the user/application. For FA_ALLOCATE and
58 + * FA_RESV_SPACE modes, if the sys_fallocate()
59 * system call succeeds, subsequent writes to the file in the given range
60 * (specified by offset & len) should not fail - even if the file system
61 * later becomes full. Hence the preallocation done is persistent (valid
62 - * even after reopen of the file and remount/reboot).
63 + * even after reopen of the file and remount/reboot). If FA_RESV_SPACE mode
64 + * is passed, the file size will not be changed even if the preallocation
67 * It is expected that the ->fallocate() inode operation implemented by the
68 * individual file systems will update the file size and/or ctime/mtime
69 - * depending on the mode and also on the success of the operation.
70 + * depending on the mode (change is visible to user or not - say file size)
71 + * and obviously, on the success of the operation.
73 * Note: Incase the file system does not support preallocation,
74 * posix_fallocate() should fall back to the library implementation (i.e.
75 @@ -398,7 +401,8 @@ asmlinkage long sys_fallocate(int fd, in
77 /* Return error if mode is not supported */
79 - if (mode != FA_ALLOCATE && mode != FA_DEALLOCATE)
80 + if (!(mode == FA_ALLOCATE || mode == FA_DEALLOCATE ||
81 + mode == FA_RESV_SPACE || mode == FA_UNRESV_SPACE))