blob: e9da0bde36a6e957d331880483a2c62aec4faf76 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2004-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/config.h>
19#include <linux/compat.h>
20#include <linux/init.h>
21#include <linux/ioctl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/syscalls.h>
23#include <linux/types.h>
24#include <linux/fs.h>
25#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "xfs.h"
27#include "xfs_types.h"
28#include "xfs_fs.h"
29#include "xfs_vfs.h"
30#include "xfs_vnode.h"
31#include "xfs_dfrag.h"
32
Eric Sandeen526c4202005-09-05 08:25:06 +100033#define _NATIVE_IOC(cmd, type) \
34 _IOC(_IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd), sizeof(type))
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
37#define BROKEN_X86_ALIGNMENT
Eric Sandeen526c4202005-09-05 08:25:06 +100038/* on ia32 l_start is on a 32-bit boundary */
39typedef struct xfs_flock64_32 {
40 __s16 l_type;
41 __s16 l_whence;
42 __s64 l_start __attribute__((packed));
43 /* len == 0 means until end of file */
44 __s64 l_len __attribute__((packed));
45 __s32 l_sysid;
46 __u32 l_pid;
47 __s32 l_pad[4]; /* reserve area */
48} xfs_flock64_32_t;
49
50#define XFS_IOC_ALLOCSP_32 _IOW ('X', 10, struct xfs_flock64_32)
51#define XFS_IOC_FREESP_32 _IOW ('X', 11, struct xfs_flock64_32)
52#define XFS_IOC_ALLOCSP64_32 _IOW ('X', 36, struct xfs_flock64_32)
53#define XFS_IOC_FREESP64_32 _IOW ('X', 37, struct xfs_flock64_32)
54#define XFS_IOC_RESVSP_32 _IOW ('X', 40, struct xfs_flock64_32)
55#define XFS_IOC_UNRESVSP_32 _IOW ('X', 41, struct xfs_flock64_32)
56#define XFS_IOC_RESVSP64_32 _IOW ('X', 42, struct xfs_flock64_32)
57#define XFS_IOC_UNRESVSP64_32 _IOW ('X', 43, struct xfs_flock64_32)
58
59/* just account for different alignment */
60STATIC unsigned long
61xfs_ioctl32_flock(
62 unsigned long arg)
63{
64 xfs_flock64_32_t __user *p32 = (void __user *)arg;
65 xfs_flock64_t __user *p = compat_alloc_user_space(sizeof(*p));
66
67 if (copy_in_user(&p->l_type, &p32->l_type, sizeof(s16)) ||
68 copy_in_user(&p->l_whence, &p32->l_whence, sizeof(s16)) ||
69 copy_in_user(&p->l_start, &p32->l_start, sizeof(s64)) ||
70 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
71 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
72 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
73 copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
74 return -EFAULT;
75
76 return (unsigned long)p;
77}
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#else
80
81typedef struct xfs_fsop_bulkreq32 {
82 compat_uptr_t lastip; /* last inode # pointer */
83 __s32 icount; /* count of entries in buffer */
84 compat_uptr_t ubuffer; /* user buffer for inode desc. */
85 __s32 ocount; /* output count pointer */
86} xfs_fsop_bulkreq32_t;
87
Nathan Scottd3870392005-05-06 06:44:46 -070088STATIC unsigned long
89xfs_ioctl32_bulkstat(
90 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
92 xfs_fsop_bulkreq32_t __user *p32 = (void __user *)arg;
93 xfs_fsop_bulkreq_t __user *p = compat_alloc_user_space(sizeof(*p));
94 u32 addr;
95
96 if (get_user(addr, &p32->lastip) ||
97 put_user(compat_ptr(addr), &p->lastip) ||
98 copy_in_user(&p->icount, &p32->icount, sizeof(s32)) ||
99 get_user(addr, &p32->ubuffer) ||
100 put_user(compat_ptr(addr), &p->ubuffer) ||
101 get_user(addr, &p32->ocount) ||
102 put_user(compat_ptr(addr), &p->ocount))
103 return -EFAULT;
104
105 return (unsigned long)p;
106}
107#endif
108
Nathan Scottd3870392005-05-06 06:44:46 -0700109STATIC long
Nathan Scotta50cd262006-03-14 14:06:18 +1100110xfs_compat_ioctl(int mode, struct file *f, unsigned cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
112 int error;
Nathan Scottd3870392005-05-06 06:44:46 -0700113 struct inode *inode = f->f_dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 vnode_t *vp = LINVFS_GET_VP(inode);
115
116 switch (cmd) {
117 case XFS_IOC_DIOINFO:
118 case XFS_IOC_FSGEOMETRY_V1:
119 case XFS_IOC_FSGEOMETRY:
120 case XFS_IOC_GETVERSION:
121 case XFS_IOC_GETXFLAGS:
122 case XFS_IOC_SETXFLAGS:
123 case XFS_IOC_FSGETXATTR:
124 case XFS_IOC_FSSETXATTR:
125 case XFS_IOC_FSGETXATTRA:
126 case XFS_IOC_FSSETDM:
127 case XFS_IOC_GETBMAP:
128 case XFS_IOC_GETBMAPA:
129 case XFS_IOC_GETBMAPX:
130/* not handled
131 case XFS_IOC_FD_TO_HANDLE:
132 case XFS_IOC_PATH_TO_HANDLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 case XFS_IOC_PATH_TO_FSHANDLE:
134 case XFS_IOC_OPEN_BY_HANDLE:
135 case XFS_IOC_FSSETDM_BY_HANDLE:
136 case XFS_IOC_READLINK_BY_HANDLE:
137 case XFS_IOC_ATTRLIST_BY_HANDLE:
138 case XFS_IOC_ATTRMULTI_BY_HANDLE:
139*/
140 case XFS_IOC_FSCOUNTS:
141 case XFS_IOC_SET_RESBLKS:
142 case XFS_IOC_GET_RESBLKS:
143 case XFS_IOC_FSGROWFSDATA:
144 case XFS_IOC_FSGROWFSLOG:
145 case XFS_IOC_FSGROWFSRT:
146 case XFS_IOC_FREEZE:
147 case XFS_IOC_THAW:
148 case XFS_IOC_GOINGDOWN:
149 case XFS_IOC_ERROR_INJECTION:
150 case XFS_IOC_ERROR_CLEARALL:
151 break;
152
Eric Sandeen526c4202005-09-05 08:25:06 +1000153#ifdef BROKEN_X86_ALIGNMENT
154 /* xfs_flock_t has wrong u32 vs u64 alignment */
155 case XFS_IOC_ALLOCSP_32:
156 case XFS_IOC_FREESP_32:
157 case XFS_IOC_ALLOCSP64_32:
158 case XFS_IOC_FREESP64_32:
159 case XFS_IOC_RESVSP_32:
160 case XFS_IOC_UNRESVSP_32:
161 case XFS_IOC_RESVSP64_32:
162 case XFS_IOC_UNRESVSP64_32:
163 arg = xfs_ioctl32_flock(arg);
164 cmd = _NATIVE_IOC(cmd, struct xfs_flock64);
165 break;
166
167#else /* These are handled fine if no alignment issues */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 case XFS_IOC_ALLOCSP:
169 case XFS_IOC_FREESP:
170 case XFS_IOC_RESVSP:
171 case XFS_IOC_UNRESVSP:
172 case XFS_IOC_ALLOCSP64:
173 case XFS_IOC_FREESP64:
174 case XFS_IOC_RESVSP64:
175 case XFS_IOC_UNRESVSP64:
Eric Sandeen526c4202005-09-05 08:25:06 +1000176 break;
177
178 /* xfs_bstat_t still has wrong u32 vs u64 alignment */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 case XFS_IOC_SWAPEXT:
180 break;
181
182 case XFS_IOC_FSBULKSTAT_SINGLE:
183 case XFS_IOC_FSBULKSTAT:
184 case XFS_IOC_FSINUMBERS:
185 arg = xfs_ioctl32_bulkstat(arg);
186 break;
187#endif
188 default:
189 return -ENOIOCTLCMD;
190 }
191
192 VOP_IOCTL(vp, inode, f, mode, cmd, (void __user *)arg, error);
193 VMODIFY(vp);
194
195 return error;
196}
197
Nathan Scottd3870392005-05-06 06:44:46 -0700198long
Nathan Scotta50cd262006-03-14 14:06:18 +1100199xfs_file_compat_ioctl(
Nathan Scottd3870392005-05-06 06:44:46 -0700200 struct file *f,
201 unsigned cmd,
202 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203{
Nathan Scotta50cd262006-03-14 14:06:18 +1100204 return xfs_compat_ioctl(0, f, cmd, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
206
Nathan Scottd3870392005-05-06 06:44:46 -0700207long
Nathan Scotta50cd262006-03-14 14:06:18 +1100208xfs_file_compat_invis_ioctl(
Nathan Scottd3870392005-05-06 06:44:46 -0700209 struct file *f,
210 unsigned cmd,
211 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
Nathan Scotta50cd262006-03-14 14:06:18 +1100213 return xfs_compat_ioctl(IO_INVIS, f, cmd, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214}