2 * Copyright (c) 2004-2005 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
33 #include <linux/config.h>
34 #include <linux/compat.h>
35 #include <linux/init.h>
36 #include <linux/ioctl.h>
37 #include <linux/ioctl32.h>
38 #include <linux/syscalls.h>
39 #include <linux/types.h>
41 #include <asm/uaccess.h>
44 #include "xfs_types.h"
47 #include "xfs_vnode.h"
48 #include "xfs_dfrag.h"
50 #define _NATIVE_IOC(cmd, type) \
51 _IOC(_IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd), sizeof(type))
53 #if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
54 #define BROKEN_X86_ALIGNMENT
55 /* on ia32 l_start is on a 32-bit boundary */
56 typedef struct xfs_flock64_32 {
59 __s64 l_start __attribute__((packed));
60 /* len == 0 means until end of file */
61 __s64 l_len __attribute__((packed));
64 __s32 l_pad[4]; /* reserve area */
67 #define XFS_IOC_ALLOCSP_32 _IOW ('X', 10, struct xfs_flock64_32)
68 #define XFS_IOC_FREESP_32 _IOW ('X', 11, struct xfs_flock64_32)
69 #define XFS_IOC_ALLOCSP64_32 _IOW ('X', 36, struct xfs_flock64_32)
70 #define XFS_IOC_FREESP64_32 _IOW ('X', 37, struct xfs_flock64_32)
71 #define XFS_IOC_RESVSP_32 _IOW ('X', 40, struct xfs_flock64_32)
72 #define XFS_IOC_UNRESVSP_32 _IOW ('X', 41, struct xfs_flock64_32)
73 #define XFS_IOC_RESVSP64_32 _IOW ('X', 42, struct xfs_flock64_32)
74 #define XFS_IOC_UNRESVSP64_32 _IOW ('X', 43, struct xfs_flock64_32)
76 /* just account for different alignment */
81 xfs_flock64_32_t __user *p32 = (void __user *)arg;
82 xfs_flock64_t __user *p = compat_alloc_user_space(sizeof(*p));
84 if (copy_in_user(&p->l_type, &p32->l_type, sizeof(s16)) ||
85 copy_in_user(&p->l_whence, &p32->l_whence, sizeof(s16)) ||
86 copy_in_user(&p->l_start, &p32->l_start, sizeof(s64)) ||
87 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
88 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
89 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
90 copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
93 return (unsigned long)p;
98 typedef struct xfs_fsop_bulkreq32 {
99 compat_uptr_t lastip; /* last inode # pointer */
100 __s32 icount; /* count of entries in buffer */
101 compat_uptr_t ubuffer; /* user buffer for inode desc. */
102 __s32 ocount; /* output count pointer */
103 } xfs_fsop_bulkreq32_t;
106 xfs_ioctl32_bulkstat(
109 xfs_fsop_bulkreq32_t __user *p32 = (void __user *)arg;
110 xfs_fsop_bulkreq_t __user *p = compat_alloc_user_space(sizeof(*p));
113 if (get_user(addr, &p32->lastip) ||
114 put_user(compat_ptr(addr), &p->lastip) ||
115 copy_in_user(&p->icount, &p32->icount, sizeof(s32)) ||
116 get_user(addr, &p32->ubuffer) ||
117 put_user(compat_ptr(addr), &p->ubuffer) ||
118 get_user(addr, &p32->ocount) ||
119 put_user(compat_ptr(addr), &p->ocount))
122 return (unsigned long)p;
127 __linvfs_compat_ioctl(int mode, struct file *f, unsigned cmd, unsigned long arg)
130 struct inode *inode = f->f_dentry->d_inode;
131 vnode_t *vp = LINVFS_GET_VP(inode);
134 case XFS_IOC_DIOINFO:
135 case XFS_IOC_FSGEOMETRY_V1:
136 case XFS_IOC_FSGEOMETRY:
137 case XFS_IOC_GETVERSION:
138 case XFS_IOC_GETXFLAGS:
139 case XFS_IOC_SETXFLAGS:
140 case XFS_IOC_FSGETXATTR:
141 case XFS_IOC_FSSETXATTR:
142 case XFS_IOC_FSGETXATTRA:
143 case XFS_IOC_FSSETDM:
144 case XFS_IOC_GETBMAP:
145 case XFS_IOC_GETBMAPA:
146 case XFS_IOC_GETBMAPX:
148 case XFS_IOC_FD_TO_HANDLE:
149 case XFS_IOC_PATH_TO_HANDLE:
150 case XFS_IOC_PATH_TO_FSHANDLE:
151 case XFS_IOC_OPEN_BY_HANDLE:
152 case XFS_IOC_FSSETDM_BY_HANDLE:
153 case XFS_IOC_READLINK_BY_HANDLE:
154 case XFS_IOC_ATTRLIST_BY_HANDLE:
155 case XFS_IOC_ATTRMULTI_BY_HANDLE:
157 case XFS_IOC_FSCOUNTS:
158 case XFS_IOC_SET_RESBLKS:
159 case XFS_IOC_GET_RESBLKS:
160 case XFS_IOC_FSGROWFSDATA:
161 case XFS_IOC_FSGROWFSLOG:
162 case XFS_IOC_FSGROWFSRT:
165 case XFS_IOC_GOINGDOWN:
166 case XFS_IOC_ERROR_INJECTION:
167 case XFS_IOC_ERROR_CLEARALL:
170 #ifdef BROKEN_X86_ALIGNMENT
171 /* xfs_flock_t has wrong u32 vs u64 alignment */
172 case XFS_IOC_ALLOCSP_32:
173 case XFS_IOC_FREESP_32:
174 case XFS_IOC_ALLOCSP64_32:
175 case XFS_IOC_FREESP64_32:
176 case XFS_IOC_RESVSP_32:
177 case XFS_IOC_UNRESVSP_32:
178 case XFS_IOC_RESVSP64_32:
179 case XFS_IOC_UNRESVSP64_32:
180 arg = xfs_ioctl32_flock(arg);
181 cmd = _NATIVE_IOC(cmd, struct xfs_flock64);
184 #else /* These are handled fine if no alignment issues */
185 case XFS_IOC_ALLOCSP:
188 case XFS_IOC_UNRESVSP:
189 case XFS_IOC_ALLOCSP64:
190 case XFS_IOC_FREESP64:
191 case XFS_IOC_RESVSP64:
192 case XFS_IOC_UNRESVSP64:
195 /* xfs_bstat_t still has wrong u32 vs u64 alignment */
196 case XFS_IOC_SWAPEXT:
199 case XFS_IOC_FSBULKSTAT_SINGLE:
200 case XFS_IOC_FSBULKSTAT:
201 case XFS_IOC_FSINUMBERS:
202 arg = xfs_ioctl32_bulkstat(arg);
209 VOP_IOCTL(vp, inode, f, mode, cmd, (void __user *)arg, error);
221 return __linvfs_compat_ioctl(0, f, cmd, arg);
225 linvfs_compat_invis_ioctl(
230 return __linvfs_compat_ioctl(IO_INVIS, f, cmd, arg);