2 * Copyright (c) 2004-2005 Silicon Graphics, Inc.
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
7 * published by the Free Software Foundation.
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.
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
18 #include <linux/compat.h>
19 #include <linux/init.h>
20 #include <linux/ioctl.h>
21 #include <linux/syscalls.h>
22 #include <linux/types.h>
24 #include <asm/uaccess.h>
26 #include "xfs_types.h"
29 #include "xfs_vnode.h"
30 #include "xfs_dfrag.h"
32 #define _NATIVE_IOC(cmd, type) \
33 _IOC(_IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd), sizeof(type))
35 #if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
36 #define BROKEN_X86_ALIGNMENT
37 /* on ia32 l_start is on a 32-bit boundary */
38 typedef struct xfs_flock64_32 {
41 __s64 l_start __attribute__((packed));
42 /* len == 0 means until end of file */
43 __s64 l_len __attribute__((packed));
46 __s32 l_pad[4]; /* reserve area */
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)
58 /* just account for different alignment */
63 xfs_flock64_32_t __user *p32 = (void __user *)arg;
64 xfs_flock64_t __user *p = compat_alloc_user_space(sizeof(*p));
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)))
75 return (unsigned long)p;
78 typedef 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;
101 #define XFS_IOC_FSGEOMETRY_V1_32 \
102 _IOR ('X', 100, struct compat_xfs_fsop_geom_v1)
104 STATIC unsigned long xfs_ioctl32_geom_v1(unsigned long arg)
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));
109 if (copy_in_user(p, p32, sizeof(*p32)))
111 return (unsigned long)p;
116 typedef 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;
124 xfs_ioctl32_bulkstat(
127 xfs_fsop_bulkreq32_t __user *p32 = (void __user *)arg;
128 xfs_fsop_bulkreq_t __user *p = compat_alloc_user_space(sizeof(*p));
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))
140 return (unsigned long)p;
144 typedef 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;
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)
165 STATIC unsigned long xfs_ioctl32_fshandle(unsigned long arg)
167 compat_xfs_fsop_handlereq_t __user *p32 = (void __user *)arg;
168 xfs_fsop_handlereq_t __user *p = compat_alloc_user_space(sizeof(*p));
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))
184 return (unsigned long)p;
195 struct inode *inode = file->f_path.dentry->d_inode;
196 bhv_vnode_t *vp = vn_from_inode(inode);
200 case XFS_IOC_DIOINFO:
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:
213 case XFS_IOC_FSSETDM_BY_HANDLE:
214 case XFS_IOC_ATTRLIST_BY_HANDLE:
215 case XFS_IOC_ATTRMULTI_BY_HANDLE:
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:
225 case XFS_IOC_GOINGDOWN:
226 case XFS_IOC_ERROR_INJECTION:
227 case XFS_IOC_ERROR_CLEARALL:
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);
243 case XFS_IOC_FSGEOMETRY_V1_32:
244 arg = xfs_ioctl32_geom_v1(arg);
245 cmd = _NATIVE_IOC(cmd, struct xfs_fsop_geom_v1);
248 #else /* These are handled fine if no alignment issues */
249 case XFS_IOC_ALLOCSP:
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:
257 case XFS_IOC_FSGEOMETRY_V1:
260 /* xfs_bstat_t still has wrong u32 vs u64 alignment */
261 case XFS_IOC_SWAPEXT:
264 case XFS_IOC_FSBULKSTAT_SINGLE:
265 case XFS_IOC_FSBULKSTAT:
266 case XFS_IOC_FSINUMBERS:
267 arg = xfs_ioctl32_bulkstat(arg);
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);
282 error = bhv_vop_ioctl(vp, inode, file, mode, cmd, (void __user *)arg);
289 xfs_file_compat_ioctl(
294 return xfs_compat_ioctl(0, file, cmd, arg);
298 xfs_file_compat_invis_ioctl(
303 return xfs_compat_ioctl(IO_INVIS, file, cmd, arg);