blob: 4636b7f86f1fa204be576d8eb976c1711effa200 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scottd3870392005-05-06 06:44:46 -07002 * Copyright (c) 2004-2005 Silicon Graphics, Inc. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
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.
7 *
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.
11 *
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.
18 *
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.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
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>
40#include <linux/fs.h>
41#include <asm/uaccess.h>
42
43#include "xfs.h"
44#include "xfs_types.h"
45#include "xfs_fs.h"
46#include "xfs_vfs.h"
47#include "xfs_vnode.h"
48#include "xfs_dfrag.h"
49
Eric Sandeen526c4202005-09-05 08:25:06 +100050#define _NATIVE_IOC(cmd, type) \
51 _IOC(_IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd), sizeof(type))
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
54#define BROKEN_X86_ALIGNMENT
Eric Sandeen526c4202005-09-05 08:25:06 +100055/* on ia32 l_start is on a 32-bit boundary */
56typedef struct xfs_flock64_32 {
57 __s16 l_type;
58 __s16 l_whence;
59 __s64 l_start __attribute__((packed));
60 /* len == 0 means until end of file */
61 __s64 l_len __attribute__((packed));
62 __s32 l_sysid;
63 __u32 l_pid;
64 __s32 l_pad[4]; /* reserve area */
65} xfs_flock64_32_t;
66
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)
75
76/* just account for different alignment */
77STATIC unsigned long
78xfs_ioctl32_flock(
79 unsigned long arg)
80{
81 xfs_flock64_32_t __user *p32 = (void __user *)arg;
82 xfs_flock64_t __user *p = compat_alloc_user_space(sizeof(*p));
83
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)))
91 return -EFAULT;
92
93 return (unsigned long)p;
94}
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#else
97
98typedef 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;
104
Nathan Scottd3870392005-05-06 06:44:46 -0700105STATIC unsigned long
106xfs_ioctl32_bulkstat(
107 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
109 xfs_fsop_bulkreq32_t __user *p32 = (void __user *)arg;
110 xfs_fsop_bulkreq_t __user *p = compat_alloc_user_space(sizeof(*p));
111 u32 addr;
112
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))
120 return -EFAULT;
121
122 return (unsigned long)p;
123}
124#endif
125
Nathan Scottd3870392005-05-06 06:44:46 -0700126STATIC long
127__linvfs_compat_ioctl(int mode, struct file *f, unsigned cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
129 int error;
Nathan Scottd3870392005-05-06 06:44:46 -0700130 struct inode *inode = f->f_dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 vnode_t *vp = LINVFS_GET_VP(inode);
132
133 switch (cmd) {
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:
147/* not handled
148 case XFS_IOC_FD_TO_HANDLE:
149 case XFS_IOC_PATH_TO_HANDLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 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:
156*/
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:
163 case XFS_IOC_FREEZE:
164 case XFS_IOC_THAW:
165 case XFS_IOC_GOINGDOWN:
166 case XFS_IOC_ERROR_INJECTION:
167 case XFS_IOC_ERROR_CLEARALL:
168 break;
169
Eric Sandeen526c4202005-09-05 08:25:06 +1000170#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);
182 break;
183
184#else /* These are handled fine if no alignment issues */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 case XFS_IOC_ALLOCSP:
186 case XFS_IOC_FREESP:
187 case XFS_IOC_RESVSP:
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:
Eric Sandeen526c4202005-09-05 08:25:06 +1000193 break;
194
195 /* xfs_bstat_t still has wrong u32 vs u64 alignment */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 case XFS_IOC_SWAPEXT:
197 break;
198
199 case XFS_IOC_FSBULKSTAT_SINGLE:
200 case XFS_IOC_FSBULKSTAT:
201 case XFS_IOC_FSINUMBERS:
202 arg = xfs_ioctl32_bulkstat(arg);
203 break;
204#endif
205 default:
206 return -ENOIOCTLCMD;
207 }
208
209 VOP_IOCTL(vp, inode, f, mode, cmd, (void __user *)arg, error);
210 VMODIFY(vp);
211
212 return error;
213}
214
Nathan Scottd3870392005-05-06 06:44:46 -0700215long
216linvfs_compat_ioctl(
217 struct file *f,
218 unsigned cmd,
219 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Nathan Scottd3870392005-05-06 06:44:46 -0700221 return __linvfs_compat_ioctl(0, f, cmd, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222}
223
Nathan Scottd3870392005-05-06 06:44:46 -0700224long
225linvfs_compat_invis_ioctl(
226 struct file *f,
227 unsigned cmd,
228 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
Nathan Scottd3870392005-05-06 06:44:46 -0700230 return __linvfs_compat_ioctl(IO_INVIS, f, cmd, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231}