[XFS] Compat ioctl handler for XFS_IOC_FSGEOMETRY_V1.
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / xfs / linux-2.6 / xfs_ioctl32.c
CommitLineData
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/compat.h>
19#include <linux/init.h>
20#include <linux/ioctl.h>
1da177e4
LT
21#include <linux/syscalls.h>
22#include <linux/types.h>
23#include <linux/fs.h>
24#include <asm/uaccess.h>
1da177e4
LT
25#include "xfs.h"
26#include "xfs_types.h"
27#include "xfs_fs.h"
28#include "xfs_vfs.h"
29#include "xfs_vnode.h"
30#include "xfs_dfrag.h"
31
526c420c
ES
32#define _NATIVE_IOC(cmd, type) \
33 _IOC(_IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd), sizeof(type))
34
1da177e4
LT
35#if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
36#define BROKEN_X86_ALIGNMENT
526c420c
ES
37/* on ia32 l_start is on a 32-bit boundary */
38typedef struct xfs_flock64_32 {
39 __s16 l_type;
40 __s16 l_whence;
41 __s64 l_start __attribute__((packed));
42 /* len == 0 means until end of file */
43 __s64 l_len __attribute__((packed));
44 __s32 l_sysid;
45 __u32 l_pid;
46 __s32 l_pad[4]; /* reserve area */
47} xfs_flock64_32_t;
48
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)
57
58/* just account for different alignment */
59STATIC unsigned long
60xfs_ioctl32_flock(
61 unsigned long arg)
62{
63 xfs_flock64_32_t __user *p32 = (void __user *)arg;
64 xfs_flock64_t __user *p = compat_alloc_user_space(sizeof(*p));
65
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)))
73 return -EFAULT;
e0edd596 74
526c420c
ES
75 return (unsigned long)p;
76}
77
547e00c3
MM
78typedef 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;
100
101#define XFS_IOC_FSGEOMETRY_V1_32 \
102 _IOR ('X', 100, struct compat_xfs_fsop_geom_v1)
103
104STATIC unsigned long xfs_ioctl32_geom_v1(unsigned long arg)
105{
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));
108
109 if (copy_in_user(p, p32, sizeof(*p32)))
110 return -EFAULT;
111 return (unsigned long)p;
112}
113
1da177e4
LT
114#else
115
116typedef 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;
122
d3870398
NS
123STATIC unsigned long
124xfs_ioctl32_bulkstat(
125 unsigned long arg)
1da177e4
LT
126{
127 xfs_fsop_bulkreq32_t __user *p32 = (void __user *)arg;
128 xfs_fsop_bulkreq_t __user *p = compat_alloc_user_space(sizeof(*p));
129 u32 addr;
130
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))
138 return -EFAULT;
139
140 return (unsigned long)p;
141}
142#endif
143
d3870398 144STATIC long
e0edd596
NS
145xfs_compat_ioctl(
146 int mode,
147 struct file *file,
148 unsigned cmd,
149 unsigned long arg)
1da177e4 150{
e678fb0d 151 struct inode *inode = file->f_path.dentry->d_inode;
67fcaa73 152 bhv_vnode_t *vp = vn_from_inode(inode);
1da177e4 153 int error;
1da177e4
LT
154
155 switch (cmd) {
156 case XFS_IOC_DIOINFO:
1da177e4
LT
157 case XFS_IOC_FSGEOMETRY:
158 case XFS_IOC_GETVERSION:
159 case XFS_IOC_GETXFLAGS:
160 case XFS_IOC_SETXFLAGS:
161 case XFS_IOC_FSGETXATTR:
162 case XFS_IOC_FSSETXATTR:
163 case XFS_IOC_FSGETXATTRA:
164 case XFS_IOC_FSSETDM:
165 case XFS_IOC_GETBMAP:
166 case XFS_IOC_GETBMAPA:
167 case XFS_IOC_GETBMAPX:
168/* not handled
169 case XFS_IOC_FD_TO_HANDLE:
170 case XFS_IOC_PATH_TO_HANDLE:
1da177e4
LT
171 case XFS_IOC_PATH_TO_FSHANDLE:
172 case XFS_IOC_OPEN_BY_HANDLE:
173 case XFS_IOC_FSSETDM_BY_HANDLE:
174 case XFS_IOC_READLINK_BY_HANDLE:
175 case XFS_IOC_ATTRLIST_BY_HANDLE:
176 case XFS_IOC_ATTRMULTI_BY_HANDLE:
177*/
178 case XFS_IOC_FSCOUNTS:
179 case XFS_IOC_SET_RESBLKS:
180 case XFS_IOC_GET_RESBLKS:
181 case XFS_IOC_FSGROWFSDATA:
182 case XFS_IOC_FSGROWFSLOG:
183 case XFS_IOC_FSGROWFSRT:
184 case XFS_IOC_FREEZE:
185 case XFS_IOC_THAW:
186 case XFS_IOC_GOINGDOWN:
187 case XFS_IOC_ERROR_INJECTION:
188 case XFS_IOC_ERROR_CLEARALL:
189 break;
190
526c420c
ES
191#ifdef BROKEN_X86_ALIGNMENT
192 /* xfs_flock_t has wrong u32 vs u64 alignment */
193 case XFS_IOC_ALLOCSP_32:
194 case XFS_IOC_FREESP_32:
195 case XFS_IOC_ALLOCSP64_32:
196 case XFS_IOC_FREESP64_32:
197 case XFS_IOC_RESVSP_32:
198 case XFS_IOC_UNRESVSP_32:
199 case XFS_IOC_RESVSP64_32:
200 case XFS_IOC_UNRESVSP64_32:
201 arg = xfs_ioctl32_flock(arg);
202 cmd = _NATIVE_IOC(cmd, struct xfs_flock64);
203 break;
547e00c3
MM
204 case XFS_IOC_FSGEOMETRY_V1_32:
205 arg = xfs_ioctl32_geom_v1(arg);
206 cmd = _NATIVE_IOC(cmd, struct xfs_fsop_geom_v1);
207 break;
526c420c
ES
208
209#else /* These are handled fine if no alignment issues */
1da177e4
LT
210 case XFS_IOC_ALLOCSP:
211 case XFS_IOC_FREESP:
212 case XFS_IOC_RESVSP:
213 case XFS_IOC_UNRESVSP:
214 case XFS_IOC_ALLOCSP64:
215 case XFS_IOC_FREESP64:
216 case XFS_IOC_RESVSP64:
217 case XFS_IOC_UNRESVSP64:
547e00c3 218 case XFS_IOC_FSGEOMETRY_V1:
526c420c
ES
219 break;
220
221 /* xfs_bstat_t still has wrong u32 vs u64 alignment */
1da177e4
LT
222 case XFS_IOC_SWAPEXT:
223 break;
224
225 case XFS_IOC_FSBULKSTAT_SINGLE:
226 case XFS_IOC_FSBULKSTAT:
227 case XFS_IOC_FSINUMBERS:
228 arg = xfs_ioctl32_bulkstat(arg);
229 break;
230#endif
231 default:
232 return -ENOIOCTLCMD;
233 }
234
67fcaa73 235 error = bhv_vop_ioctl(vp, inode, file, mode, cmd, (void __user *)arg);
1da177e4
LT
236 VMODIFY(vp);
237
238 return error;
239}
240
d3870398 241long
a50cd269 242xfs_file_compat_ioctl(
e0edd596 243 struct file *file,
d3870398
NS
244 unsigned cmd,
245 unsigned long arg)
1da177e4 246{
e0edd596 247 return xfs_compat_ioctl(0, file, cmd, arg);
1da177e4
LT
248}
249
d3870398 250long
a50cd269 251xfs_file_compat_invis_ioctl(
e0edd596 252 struct file *file,
d3870398
NS
253 unsigned cmd,
254 unsigned long arg)
1da177e4 255{
e0edd596 256 return xfs_compat_ioctl(IO_INVIS, file, cmd, arg);
1da177e4 257}