Commit | Line | Data |
---|---|---|
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/config.h> |
19 | #include <linux/compat.h> | |
20 | #include <linux/init.h> | |
21 | #include <linux/ioctl.h> | |
22 | #include <linux/ioctl32.h> | |
23 | #include <linux/syscalls.h> | |
24 | #include <linux/types.h> | |
25 | #include <linux/fs.h> | |
26 | #include <asm/uaccess.h> | |
1da177e4 LT |
27 | #include "xfs.h" |
28 | #include "xfs_types.h" | |
29 | #include "xfs_fs.h" | |
30 | #include "xfs_vfs.h" | |
31 | #include "xfs_vnode.h" | |
32 | #include "xfs_dfrag.h" | |
33 | ||
526c420c ES |
34 | #define _NATIVE_IOC(cmd, type) \ |
35 | _IOC(_IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd), sizeof(type)) | |
36 | ||
1da177e4 LT |
37 | #if defined(CONFIG_IA64) || defined(CONFIG_X86_64) |
38 | #define BROKEN_X86_ALIGNMENT | |
526c420c ES |
39 | /* on ia32 l_start is on a 32-bit boundary */ |
40 | typedef struct xfs_flock64_32 { | |
41 | __s16 l_type; | |
42 | __s16 l_whence; | |
43 | __s64 l_start __attribute__((packed)); | |
44 | /* len == 0 means until end of file */ | |
45 | __s64 l_len __attribute__((packed)); | |
46 | __s32 l_sysid; | |
47 | __u32 l_pid; | |
48 | __s32 l_pad[4]; /* reserve area */ | |
49 | } xfs_flock64_32_t; | |
50 | ||
51 | #define XFS_IOC_ALLOCSP_32 _IOW ('X', 10, struct xfs_flock64_32) | |
52 | #define XFS_IOC_FREESP_32 _IOW ('X', 11, struct xfs_flock64_32) | |
53 | #define XFS_IOC_ALLOCSP64_32 _IOW ('X', 36, struct xfs_flock64_32) | |
54 | #define XFS_IOC_FREESP64_32 _IOW ('X', 37, struct xfs_flock64_32) | |
55 | #define XFS_IOC_RESVSP_32 _IOW ('X', 40, struct xfs_flock64_32) | |
56 | #define XFS_IOC_UNRESVSP_32 _IOW ('X', 41, struct xfs_flock64_32) | |
57 | #define XFS_IOC_RESVSP64_32 _IOW ('X', 42, struct xfs_flock64_32) | |
58 | #define XFS_IOC_UNRESVSP64_32 _IOW ('X', 43, struct xfs_flock64_32) | |
59 | ||
60 | /* just account for different alignment */ | |
61 | STATIC unsigned long | |
62 | xfs_ioctl32_flock( | |
63 | unsigned long arg) | |
64 | { | |
65 | xfs_flock64_32_t __user *p32 = (void __user *)arg; | |
66 | xfs_flock64_t __user *p = compat_alloc_user_space(sizeof(*p)); | |
67 | ||
68 | if (copy_in_user(&p->l_type, &p32->l_type, sizeof(s16)) || | |
69 | copy_in_user(&p->l_whence, &p32->l_whence, sizeof(s16)) || | |
70 | copy_in_user(&p->l_start, &p32->l_start, sizeof(s64)) || | |
71 | copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) || | |
72 | copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) || | |
73 | copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) || | |
74 | copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32))) | |
75 | return -EFAULT; | |
76 | ||
77 | return (unsigned long)p; | |
78 | } | |
79 | ||
1da177e4 LT |
80 | #else |
81 | ||
82 | typedef struct xfs_fsop_bulkreq32 { | |
83 | compat_uptr_t lastip; /* last inode # pointer */ | |
84 | __s32 icount; /* count of entries in buffer */ | |
85 | compat_uptr_t ubuffer; /* user buffer for inode desc. */ | |
86 | __s32 ocount; /* output count pointer */ | |
87 | } xfs_fsop_bulkreq32_t; | |
88 | ||
d3870398 NS |
89 | STATIC unsigned long |
90 | xfs_ioctl32_bulkstat( | |
91 | unsigned long arg) | |
1da177e4 LT |
92 | { |
93 | xfs_fsop_bulkreq32_t __user *p32 = (void __user *)arg; | |
94 | xfs_fsop_bulkreq_t __user *p = compat_alloc_user_space(sizeof(*p)); | |
95 | u32 addr; | |
96 | ||
97 | if (get_user(addr, &p32->lastip) || | |
98 | put_user(compat_ptr(addr), &p->lastip) || | |
99 | copy_in_user(&p->icount, &p32->icount, sizeof(s32)) || | |
100 | get_user(addr, &p32->ubuffer) || | |
101 | put_user(compat_ptr(addr), &p->ubuffer) || | |
102 | get_user(addr, &p32->ocount) || | |
103 | put_user(compat_ptr(addr), &p->ocount)) | |
104 | return -EFAULT; | |
105 | ||
106 | return (unsigned long)p; | |
107 | } | |
108 | #endif | |
109 | ||
d3870398 NS |
110 | STATIC long |
111 | __linvfs_compat_ioctl(int mode, struct file *f, unsigned cmd, unsigned long arg) | |
1da177e4 LT |
112 | { |
113 | int error; | |
d3870398 | 114 | struct inode *inode = f->f_dentry->d_inode; |
1da177e4 LT |
115 | vnode_t *vp = LINVFS_GET_VP(inode); |
116 | ||
117 | switch (cmd) { | |
118 | case XFS_IOC_DIOINFO: | |
119 | case XFS_IOC_FSGEOMETRY_V1: | |
120 | case XFS_IOC_FSGEOMETRY: | |
121 | case XFS_IOC_GETVERSION: | |
122 | case XFS_IOC_GETXFLAGS: | |
123 | case XFS_IOC_SETXFLAGS: | |
124 | case XFS_IOC_FSGETXATTR: | |
125 | case XFS_IOC_FSSETXATTR: | |
126 | case XFS_IOC_FSGETXATTRA: | |
127 | case XFS_IOC_FSSETDM: | |
128 | case XFS_IOC_GETBMAP: | |
129 | case XFS_IOC_GETBMAPA: | |
130 | case XFS_IOC_GETBMAPX: | |
131 | /* not handled | |
132 | case XFS_IOC_FD_TO_HANDLE: | |
133 | case XFS_IOC_PATH_TO_HANDLE: | |
1da177e4 LT |
134 | case XFS_IOC_PATH_TO_FSHANDLE: |
135 | case XFS_IOC_OPEN_BY_HANDLE: | |
136 | case XFS_IOC_FSSETDM_BY_HANDLE: | |
137 | case XFS_IOC_READLINK_BY_HANDLE: | |
138 | case XFS_IOC_ATTRLIST_BY_HANDLE: | |
139 | case XFS_IOC_ATTRMULTI_BY_HANDLE: | |
140 | */ | |
141 | case XFS_IOC_FSCOUNTS: | |
142 | case XFS_IOC_SET_RESBLKS: | |
143 | case XFS_IOC_GET_RESBLKS: | |
144 | case XFS_IOC_FSGROWFSDATA: | |
145 | case XFS_IOC_FSGROWFSLOG: | |
146 | case XFS_IOC_FSGROWFSRT: | |
147 | case XFS_IOC_FREEZE: | |
148 | case XFS_IOC_THAW: | |
149 | case XFS_IOC_GOINGDOWN: | |
150 | case XFS_IOC_ERROR_INJECTION: | |
151 | case XFS_IOC_ERROR_CLEARALL: | |
152 | break; | |
153 | ||
526c420c ES |
154 | #ifdef BROKEN_X86_ALIGNMENT |
155 | /* xfs_flock_t has wrong u32 vs u64 alignment */ | |
156 | case XFS_IOC_ALLOCSP_32: | |
157 | case XFS_IOC_FREESP_32: | |
158 | case XFS_IOC_ALLOCSP64_32: | |
159 | case XFS_IOC_FREESP64_32: | |
160 | case XFS_IOC_RESVSP_32: | |
161 | case XFS_IOC_UNRESVSP_32: | |
162 | case XFS_IOC_RESVSP64_32: | |
163 | case XFS_IOC_UNRESVSP64_32: | |
164 | arg = xfs_ioctl32_flock(arg); | |
165 | cmd = _NATIVE_IOC(cmd, struct xfs_flock64); | |
166 | break; | |
167 | ||
168 | #else /* These are handled fine if no alignment issues */ | |
1da177e4 LT |
169 | case XFS_IOC_ALLOCSP: |
170 | case XFS_IOC_FREESP: | |
171 | case XFS_IOC_RESVSP: | |
172 | case XFS_IOC_UNRESVSP: | |
173 | case XFS_IOC_ALLOCSP64: | |
174 | case XFS_IOC_FREESP64: | |
175 | case XFS_IOC_RESVSP64: | |
176 | case XFS_IOC_UNRESVSP64: | |
526c420c ES |
177 | break; |
178 | ||
179 | /* xfs_bstat_t still has wrong u32 vs u64 alignment */ | |
1da177e4 LT |
180 | case XFS_IOC_SWAPEXT: |
181 | break; | |
182 | ||
183 | case XFS_IOC_FSBULKSTAT_SINGLE: | |
184 | case XFS_IOC_FSBULKSTAT: | |
185 | case XFS_IOC_FSINUMBERS: | |
186 | arg = xfs_ioctl32_bulkstat(arg); | |
187 | break; | |
188 | #endif | |
189 | default: | |
190 | return -ENOIOCTLCMD; | |
191 | } | |
192 | ||
193 | VOP_IOCTL(vp, inode, f, mode, cmd, (void __user *)arg, error); | |
194 | VMODIFY(vp); | |
195 | ||
196 | return error; | |
197 | } | |
198 | ||
d3870398 NS |
199 | long |
200 | linvfs_compat_ioctl( | |
201 | struct file *f, | |
202 | unsigned cmd, | |
203 | unsigned long arg) | |
1da177e4 | 204 | { |
d3870398 | 205 | return __linvfs_compat_ioctl(0, f, cmd, arg); |
1da177e4 LT |
206 | } |
207 | ||
d3870398 NS |
208 | long |
209 | linvfs_compat_invis_ioctl( | |
210 | struct file *f, | |
211 | unsigned cmd, | |
212 | unsigned long arg) | |
1da177e4 | 213 | { |
d3870398 | 214 | return __linvfs_compat_ioctl(IO_INVIS, f, cmd, arg); |
1da177e4 | 215 | } |