1 From: "Amit K. Arora" <aarora@linux.vnet.ibm.com>
2 Subject: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
3 Cc: linux-ext4@vger.kernel.org, xfs@oss.sgi.com, suparna@in.ibm.com,
6 This patch implements the fallocate() system call and adds support for
7 i386, x86_64 and powerpc.
9 NOTE: It is based on 2.6.21 kernel version.
11 Signed-off-by: Amit Arora <aarora@in.ibm.com>
13 arch/i386/kernel/syscall_table.S | 1
14 arch/powerpc/kernel/sys_ppc32.c | 7 ++++++
15 arch/x86_64/kernel/functionlist | 1
16 fs/open.c | 41 +++++++++++++++++++++++++++++++++++++++
17 include/asm-i386/unistd.h | 3 +-
18 include/asm-powerpc/systbl.h | 1
19 include/asm-powerpc/unistd.h | 3 +-
20 include/asm-x86_64/unistd.h | 4 ++-
21 include/linux/fs.h | 7 ++++++
22 include/linux/syscalls.h | 1
23 10 files changed, 66 insertions(+), 3 deletions(-)
25 Index: linux-2.6.21/arch/i386/kernel/syscall_table.S
26 ===================================================================
27 --- linux-2.6.21.orig/arch/i386/kernel/syscall_table.S
28 +++ linux-2.6.21/arch/i386/kernel/syscall_table.S
29 @@ -319,3 +319,4 @@ ENTRY(sys_call_table)
33 + .long sys_fallocate /* 320 */
34 Index: linux-2.6.21/arch/x86_64/kernel/functionlist
35 ===================================================================
36 --- linux-2.6.21.orig/arch/x86_64/kernel/functionlist
37 +++ linux-2.6.21/arch/x86_64/kernel/functionlist
39 *(.text.sys_getitimer)
40 *(.text.sys_getgroups)
41 *(.text.sys_ftruncate)
42 +*(.text.sys_fallocate)
44 *(.text.sys_exit_group)
46 Index: linux-2.6.21/fs/open.c
47 ===================================================================
48 --- linux-2.6.21.orig/fs/open.c
49 +++ linux-2.6.21/fs/open.c
50 @@ -350,6 +350,47 @@ asmlinkage long sys_ftruncate64(unsigned
54 +asmlinkage long sys_fallocate(int fd, int mode, loff_t offset, loff_t len)
57 + struct inode *inode;
60 + if (len == 0 || offset < 0)
67 + if (!(file->f_mode & FMODE_WRITE))
70 + inode = file->f_path.dentry->d_inode;
73 + if (S_ISFIFO(inode->i_mode))
77 + if (!S_ISREG(inode->i_mode))
81 + if (offset + len > inode->i_sb->s_maxbytes)
84 + if (inode->i_op && inode->i_op->fallocate)
85 + ret = inode->i_op->fallocate(inode, mode, offset, len);
93 +EXPORT_SYMBOL(sys_fallocate);
96 * access() needs to use the real uid/gid, not the effective uid/gid.
97 * We do this by temporarily clearing all FS-related capabilities and
98 Index: linux-2.6.21/include/asm-i386/unistd.h
99 ===================================================================
100 --- linux-2.6.21.orig/include/asm-i386/unistd.h
101 +++ linux-2.6.21/include/asm-i386/unistd.h
102 @@ -325,10 +325,11 @@
103 #define __NR_move_pages 317
104 #define __NR_getcpu 318
105 #define __NR_epoll_pwait 319
106 +#define __NR_fallocate 320
110 -#define NR_syscalls 320
111 +#define NR_syscalls 321
113 #define __ARCH_WANT_IPC_PARSE_VERSION
114 #define __ARCH_WANT_OLD_READDIR
115 Index: linux-2.6.21/include/asm-powerpc/systbl.h
116 ===================================================================
117 --- linux-2.6.21.orig/include/asm-powerpc/systbl.h
118 +++ linux-2.6.21/include/asm-powerpc/systbl.h
119 @@ -307,3 +307,4 @@ COMPAT_SYS_SPU(set_robust_list)
120 COMPAT_SYS_SPU(move_pages)
122 COMPAT_SYS(epoll_pwait)
123 +COMPAT_SYS(fallocate)
124 Index: linux-2.6.21/include/asm-powerpc/unistd.h
125 ===================================================================
126 --- linux-2.6.21.orig/include/asm-powerpc/unistd.h
127 +++ linux-2.6.21/include/asm-powerpc/unistd.h
128 @@ -326,10 +326,11 @@
129 #define __NR_move_pages 301
130 #define __NR_getcpu 302
131 #define __NR_epoll_pwait 303
132 +#define __NR_fallocate 304
136 -#define __NR_syscalls 304
137 +#define __NR_syscalls 305
139 #define __NR__exit __NR_exit
140 #define NR_syscalls __NR_syscalls
141 Index: linux-2.6.21/include/asm-x86_64/unistd.h
142 ===================================================================
143 --- linux-2.6.21.orig/include/asm-x86_64/unistd.h
144 +++ linux-2.6.21/include/asm-x86_64/unistd.h
145 @@ -619,8 +619,10 @@ __SYSCALL(__NR_sync_file_range, sys_sync
146 __SYSCALL(__NR_vmsplice, sys_vmsplice)
147 #define __NR_move_pages 279
148 __SYSCALL(__NR_move_pages, sys_move_pages)
149 +#define __NR_fallocate 280
150 +__SYSCALL(__NR_fallocate, sys_fallocate)
152 -#define __NR_syscall_max __NR_move_pages
153 +#define __NR_syscall_max __NR_fallocate
156 #define __ARCH_WANT_OLD_READDIR
157 Index: linux-2.6.21/include/linux/fs.h
158 ===================================================================
159 --- linux-2.6.21.orig/include/linux/fs.h
160 +++ linux-2.6.21/include/linux/fs.h
161 @@ -264,6 +264,12 @@ extern int dir_notify_enable;
162 #define SYNC_FILE_RANGE_WRITE 2
163 #define SYNC_FILE_RANGE_WAIT_AFTER 4
166 + * fallocate() modes
168 +#define FA_ALLOCATE 0x1
169 +#define FA_DEALLOCATE 0x2
173 #include <linux/linkage.h>
174 @@ -1125,6 +1131,7 @@ struct inode_operations {
175 ssize_t (*listxattr) (struct dentry *, char *, size_t);
176 int (*removexattr) (struct dentry *, const char *);
177 void (*truncate_range)(struct inode *, loff_t, loff_t);
178 + long (*fallocate)(struct inode *, int, loff_t, loff_t);
182 Index: linux-2.6.21/include/linux/syscalls.h
183 ===================================================================
184 --- linux-2.6.21.orig/include/linux/syscalls.h
185 +++ linux-2.6.21/include/linux/syscalls.h
186 @@ -602,6 +602,7 @@ asmlinkage long sys_get_robust_list(int
187 asmlinkage long sys_set_robust_list(struct robust_list_head __user *head,
189 asmlinkage long sys_getcpu(unsigned __user *cpu, unsigned __user *node, struct getcpu_cache __user *cache);
190 +asmlinkage long sys_fallocate(int fd, int mode, loff_t offset, loff_t len);
192 int kernel_execve(const char *filename, char *const argv[], char *const envp[]);
194 Index: linux-2.6.21/arch/powerpc/kernel/sys_ppc32.c
195 ===================================================================
196 --- linux-2.6.21.orig/arch/powerpc/kernel/sys_ppc32.c
197 +++ linux-2.6.21/arch/powerpc/kernel/sys_ppc32.c
198 @@ -777,6 +777,13 @@ asmlinkage int compat_sys_truncate64(con
199 return sys_truncate(path, (high << 32) | low);
202 +asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
203 + u32 lenhi, u32 lenlo)
205 + return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
206 + ((loff_t)lenhi << 32) | lenlo);
209 asmlinkage int compat_sys_ftruncate64(unsigned int fd, u32 reg4, unsigned long high,
213 To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
214 the body of a message to majordomo@vger.kernel.org
215 More majordomo info at http://vger.kernel.org/majordomo-info.html