]> bbs.cooldavid.org Git - net-next-2.6.git/blame - fs/xfs/linux-2.6/xfs_ioctl32.c
[XFS] Compat ioctl handler for handle operations
[net-next-2.6.git] / fs / xfs / linux-2.6 / xfs_ioctl32.c
CommitLineData
1da177e4 1/*
7b718769
NS
2 * Copyright (c) 2004-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
1da177e4 4 *
7b718769
NS
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
1da177e4
LT
7 * published by the Free Software Foundation.
8 *
7b718769
NS
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
1da177e4 13 *
7b718769
NS
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1da177e4 17 */
1da177e4
LT
18#include <linux/compat.h>
19#include <linux/init.h>
20#include <linux/ioctl.h>
1da177e4
LT
21#include <linux/syscalls.h>
22#include <linux/types.h>
23#include <linux/fs.h>
24#include <asm/uaccess.h>
1da177e4
LT
25#include "xfs.h"
26#include "xfs_types.h"
27#include "xfs_fs.h"
28#include "xfs_vfs.h"
29#include "xfs_vnode.h"
30#include "xfs_dfrag.h"
31
526c420c
ES
32#define _NATIVE_IOC(cmd, type) \
33 _IOC(_IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd), sizeof(type))
34
1da177e4
LT
35#if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
36#define BROKEN_X86_ALIGNMENT
526c420c
ES
37/* on ia32 l_start is on a 32-bit boundary */
38typedef struct xfs_flock64_32 {
39 __s16 l_type;
40 __s16 l_whence;
41 __s64 l_start __attribute__((packed));
42 /* len == 0 means until end of file */
43 __s64 l_len __attribute__((packed));
44 __s32 l_sysid;
45 __u32 l_pid;
46 __s32 l_pad[4]; /* reserve area */
47} xfs_flock64_32_t;
48
49#define XFS_IOC_ALLOCSP_32 _IOW ('X', 10, struct xfs_flock64_32)
50#define XFS_IOC_FREESP_32 _IOW ('X', 11, struct xfs_flock64_32)
51#define XFS_IOC_ALLOCSP64_32 _IOW ('X', 36, struct xfs_flock64_32)
52#define XFS_IOC_FREESP64_32 _IOW ('X', 37, struct xfs_flock64_32)
53#define XFS_IOC_RESVSP_32 _IOW ('X', 40, struct xfs_flock64_32)
54#define XFS_IOC_UNRESVSP_32 _IOW ('X', 41, struct xfs_flock64_32)
55#define XFS_IOC_RESVSP64_32 _IOW ('X', 42, struct xfs_flock64_32)
56#define XFS_IOC_UNRESVSP64_32 _IOW ('X', 43, struct xfs_flock64_32)
57
58/* just account for different alignment */
59STATIC unsigned long
60xfs_ioctl32_flock(
61 unsigned long arg)
62{
63 xfs_flock64_32_t __user *p32 = (void __user *)arg;
64 xfs_flock64_t __user *p = compat_alloc_user_space(sizeof(*p));
65
66 if (copy_in_user(&p->l_type, &p32->l_type, sizeof(s16)) ||
67 copy_in_user(&p->l_whence, &p32->l_whence, sizeof(s16)) ||
68 copy_in_user(&p->l_start, &p32->l_start, sizeof(s64)) ||
69 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
70 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
71 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
72 copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
73 return -EFAULT;
e0edd596 74
526c420c
ES
75 return (unsigned long)p;
76}
77
547e00c3
MM
78typedef struct compat_xfs_fsop_geom_v1 {
79 __u32 blocksize; /* filesystem (data) block size */
80 __u32 rtextsize; /* realtime extent size */
81 __u32 agblocks; /* fsblocks in an AG */
82 __u32 agcount; /* number of allocation groups */
83 __u32 logblocks; /* fsblocks in the log */
84 __u32 sectsize; /* (data) sector size, bytes */
85 __u32 inodesize; /* inode size in bytes */
86 __u32 imaxpct; /* max allowed inode space(%) */
87 __u64 datablocks; /* fsblocks in data subvolume */
88 __u64 rtblocks; /* fsblocks in realtime subvol */
89 __u64 rtextents; /* rt extents in realtime subvol*/
90 __u64 logstart; /* starting fsblock of the log */
91 unsigned char uuid[16]; /* unique id of the filesystem */
92 __u32 sunit; /* stripe unit, fsblocks */
93 __u32 swidth; /* stripe width, fsblocks */
94 __s32 version; /* structure version */
95 __u32 flags; /* superblock version flags */
96 __u32 logsectsize; /* log sector size, bytes */
97 __u32 rtsectsize; /* realtime sector size, bytes */
98 __u32 dirblocksize; /* directory block size, bytes */
99} __attribute__((packed)) compat_xfs_fsop_geom_v1_t;
100
101#define XFS_IOC_FSGEOMETRY_V1_32 \
102 _IOR ('X', 100, struct compat_xfs_fsop_geom_v1)
103
104STATIC unsigned long xfs_ioctl32_geom_v1(unsigned long arg)
105{
106 compat_xfs_fsop_geom_v1_t __user *p32 = (void __user *)arg;
107 xfs_fsop_geom_v1_t __user *p = compat_alloc_user_space(sizeof(*p));
108
109 if (copy_in_user(p, p32, sizeof(*p32)))
110 return -EFAULT;
111 return (unsigned long)p;
112}
113
1da177e4
LT
114#else
115
116typedef struct xfs_fsop_bulkreq32 {
117 compat_uptr_t lastip; /* last inode # pointer */
118 __s32 icount; /* count of entries in buffer */
119 compat_uptr_t ubuffer; /* user buffer for inode desc. */
120 __s32 ocount; /* output count pointer */
121} xfs_fsop_bulkreq32_t;
122
d3870398
NS
123STATIC unsigned long
124xfs_ioctl32_bulkstat(
125 unsigned long arg)
1da177e4
LT
126{
127 xfs_fsop_bulkreq32_t __user *p32 = (void __user *)arg;
128 xfs_fsop_bulkreq_t __user *p = compat_alloc_user_space(sizeof(*p));
129 u32 addr;
130
131 if (get_user(addr, &p32->lastip) ||
132 put_user(compat_ptr(addr), &p->lastip) ||
133 copy_in_user(&p->icount, &p32->icount, sizeof(s32)) ||
134 get_user(addr, &p32->ubuffer) ||
135 put_user(compat_ptr(addr), &p->ubuffer) ||
136 get_user(addr, &p32->ocount) ||
137 put_user(compat_ptr(addr), &p->ocount))
138 return -EFAULT;
139
140 return (unsigned long)p;
141}
142#endif
143
1fa503df
MM
144typedef struct compat_xfs_fsop_handlereq {
145 __u32 fd; /* fd for FD_TO_HANDLE */
146 compat_uptr_t path; /* user pathname */
147 __u32 oflags; /* open flags */
148 compat_uptr_t ihandle; /* user supplied handle */
149 __u32 ihandlen; /* user supplied length */
150 compat_uptr_t ohandle; /* user buffer for handle */
151 compat_uptr_t ohandlen; /* user buffer length */
152} compat_xfs_fsop_handlereq_t;
153
154#define XFS_IOC_PATH_TO_FSHANDLE_32 \
155 _IOWR('X', 104, struct compat_xfs_fsop_handlereq)
156#define XFS_IOC_PATH_TO_HANDLE_32 \
157 _IOWR('X', 105, struct compat_xfs_fsop_handlereq)
158#define XFS_IOC_FD_TO_HANDLE_32 \
159 _IOWR('X', 106, struct compat_xfs_fsop_handlereq)
160#define XFS_IOC_OPEN_BY_HANDLE_32 \
161 _IOWR('X', 107, struct compat_xfs_fsop_handlereq)
162#define XFS_IOC_READLINK_BY_HANDLE_32 \
163 _IOWR('X', 108, struct compat_xfs_fsop_handlereq)
164
165STATIC unsigned long xfs_ioctl32_fshandle(unsigned long arg)
166{
167 compat_xfs_fsop_handlereq_t __user *p32 = (void __user *)arg;
168 xfs_fsop_handlereq_t __user *p = compat_alloc_user_space(sizeof(*p));
169 u32 addr;
170
171 if (copy_in_user(&p->fd, &p32->fd, sizeof(__u32)) ||
172 get_user(addr, &p32->path) ||
173 put_user(compat_ptr(addr), &p->path) ||
174 copy_in_user(&p->oflags, &p32->oflags, sizeof(__u32)) ||
175 get_user(addr, &p32->ihandle) ||
176 put_user(compat_ptr(addr), &p->ihandle) ||
177 copy_in_user(&p->ihandlen, &p32->ihandlen, sizeof(__u32)) ||
178 get_user(addr, &p32->ohandle) ||
179 put_user(compat_ptr(addr), &p->ohandle) ||
180 get_user(addr, &p32->ohandlen) ||
181 put_user(compat_ptr(addr), &p->ohandlen))
182 return -EFAULT;
183
184 return (unsigned long)p;
185}
186
187
d3870398 188STATIC long
e0edd596
NS
189xfs_compat_ioctl(
190 int mode,
191 struct file *file,
192 unsigned cmd,
193 unsigned long arg)
1da177e4 194{
e678fb0d 195 struct inode *inode = file->f_path.dentry->d_inode;
67fcaa73 196 bhv_vnode_t *vp = vn_from_inode(inode);
1da177e4 197 int error;
1da177e4
LT
198
199 switch (cmd) {
200 case XFS_IOC_DIOINFO:
1da177e4
LT
201 case XFS_IOC_FSGEOMETRY:
202 case XFS_IOC_GETVERSION:
203 case XFS_IOC_GETXFLAGS:
204 case XFS_IOC_SETXFLAGS:
205 case XFS_IOC_FSGETXATTR:
206 case XFS_IOC_FSSETXATTR:
207 case XFS_IOC_FSGETXATTRA:
208 case XFS_IOC_FSSETDM:
209 case XFS_IOC_GETBMAP:
210 case XFS_IOC_GETBMAPA:
211 case XFS_IOC_GETBMAPX:
212/* not handled
1da177e4 213 case XFS_IOC_FSSETDM_BY_HANDLE:
1da177e4
LT
214 case XFS_IOC_ATTRLIST_BY_HANDLE:
215 case XFS_IOC_ATTRMULTI_BY_HANDLE:
216*/
217 case XFS_IOC_FSCOUNTS:
218 case XFS_IOC_SET_RESBLKS:
219 case XFS_IOC_GET_RESBLKS:
220 case XFS_IOC_FSGROWFSDATA:
221 case XFS_IOC_FSGROWFSLOG:
222 case XFS_IOC_FSGROWFSRT:
223 case XFS_IOC_FREEZE:
224 case XFS_IOC_THAW:
225 case XFS_IOC_GOINGDOWN:
226 case XFS_IOC_ERROR_INJECTION:
227 case XFS_IOC_ERROR_CLEARALL:
228 break;
229
526c420c
ES
230#ifdef BROKEN_X86_ALIGNMENT
231 /* xfs_flock_t has wrong u32 vs u64 alignment */
232 case XFS_IOC_ALLOCSP_32:
233 case XFS_IOC_FREESP_32:
234 case XFS_IOC_ALLOCSP64_32:
235 case XFS_IOC_FREESP64_32:
236 case XFS_IOC_RESVSP_32:
237 case XFS_IOC_UNRESVSP_32:
238 case XFS_IOC_RESVSP64_32:
239 case XFS_IOC_UNRESVSP64_32:
240 arg = xfs_ioctl32_flock(arg);
241 cmd = _NATIVE_IOC(cmd, struct xfs_flock64);
242 break;
547e00c3
MM
243 case XFS_IOC_FSGEOMETRY_V1_32:
244 arg = xfs_ioctl32_geom_v1(arg);
245 cmd = _NATIVE_IOC(cmd, struct xfs_fsop_geom_v1);
246 break;
526c420c
ES
247
248#else /* These are handled fine if no alignment issues */
1da177e4
LT
249 case XFS_IOC_ALLOCSP:
250 case XFS_IOC_FREESP:
251 case XFS_IOC_RESVSP:
252 case XFS_IOC_UNRESVSP:
253 case XFS_IOC_ALLOCSP64:
254 case XFS_IOC_FREESP64:
255 case XFS_IOC_RESVSP64:
256 case XFS_IOC_UNRESVSP64:
547e00c3 257 case XFS_IOC_FSGEOMETRY_V1:
526c420c
ES
258 break;
259
260 /* xfs_bstat_t still has wrong u32 vs u64 alignment */
1da177e4
LT
261 case XFS_IOC_SWAPEXT:
262 break;
263
264 case XFS_IOC_FSBULKSTAT_SINGLE:
265 case XFS_IOC_FSBULKSTAT:
266 case XFS_IOC_FSINUMBERS:
267 arg = xfs_ioctl32_bulkstat(arg);
268 break;
269#endif
1fa503df
MM
270 case XFS_IOC_FD_TO_HANDLE_32:
271 case XFS_IOC_PATH_TO_HANDLE_32:
272 case XFS_IOC_PATH_TO_FSHANDLE_32:
273 case XFS_IOC_OPEN_BY_HANDLE_32:
274 case XFS_IOC_READLINK_BY_HANDLE_32:
275 arg = xfs_ioctl32_fshandle(arg);
276 cmd = _NATIVE_IOC(cmd, struct xfs_fsop_handlereq);
277 break;
1da177e4
LT
278 default:
279 return -ENOIOCTLCMD;
280 }
281
67fcaa73 282 error = bhv_vop_ioctl(vp, inode, file, mode, cmd, (void __user *)arg);
1da177e4
LT
283 VMODIFY(vp);
284
285 return error;
286}
287
d3870398 288long
a50cd269 289xfs_file_compat_ioctl(
e0edd596 290 struct file *file,
d3870398
NS
291 unsigned cmd,
292 unsigned long arg)
1da177e4 293{
e0edd596 294 return xfs_compat_ioctl(0, file, cmd, arg);
1da177e4
LT
295}
296
d3870398 297long
a50cd269 298xfs_file_compat_invis_ioctl(
e0edd596 299 struct file *file,
d3870398
NS
300 unsigned cmd,
301 unsigned long arg)
1da177e4 302{
e0edd596 303 return xfs_compat_ioctl(IO_INVIS, file, cmd, arg);
1da177e4 304}