Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 | * Copyright (c) 2004-2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. |
| 8 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/compat.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/ioctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/syscalls.h> |
| 22 | #include <linux/types.h> |
| 23 | #include <linux/fs.h> |
| 24 | #include <asm/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Eric Sandeen | 526c420 | 2005-09-05 08:25:06 +1000 | [diff] [blame] | 32 | #define _NATIVE_IOC(cmd, type) \ |
| 33 | _IOC(_IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd), sizeof(type)) |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #if defined(CONFIG_IA64) || defined(CONFIG_X86_64) |
| 36 | #define BROKEN_X86_ALIGNMENT |
Eric Sandeen | 526c420 | 2005-09-05 08:25:06 +1000 | [diff] [blame] | 37 | /* on ia32 l_start is on a 32-bit boundary */ |
| 38 | typedef 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 */ |
| 59 | STATIC unsigned long |
| 60 | xfs_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; |
Nathan Scott | e0edd59 | 2006-03-29 08:55:47 +1000 | [diff] [blame] | 74 | |
Eric Sandeen | 526c420 | 2005-09-05 08:25:06 +1000 | [diff] [blame] | 75 | return (unsigned long)p; |
| 76 | } |
| 77 | |
Michal Marek | 547e00c | 2007-07-11 11:09:57 +1000 | [diff] [blame] | 78 | typedef 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 | |
| 104 | STATIC 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | #else |
| 115 | |
| 116 | typedef 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 | |
Nathan Scott | d387039 | 2005-05-06 06:44:46 -0700 | [diff] [blame] | 123 | STATIC unsigned long |
| 124 | xfs_ioctl32_bulkstat( |
| 125 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Michal Marek | 1fa503d | 2007-07-11 11:10:09 +1000 | [diff] [blame^] | 144 | typedef struct compat_xfs_fsop_handlereq { |
| 145 | __u32 fd; /* fd for FD_TO_HANDLE */ |
| 146 | compat_uptr_t path; /* user pathname */ |
| 147 | __u32 oflags; /* open flags */ |
| 148 | compat_uptr_t ihandle; /* user supplied handle */ |
| 149 | __u32 ihandlen; /* user supplied length */ |
| 150 | compat_uptr_t ohandle; /* user buffer for handle */ |
| 151 | compat_uptr_t ohandlen; /* user buffer length */ |
| 152 | } compat_xfs_fsop_handlereq_t; |
| 153 | |
| 154 | #define XFS_IOC_PATH_TO_FSHANDLE_32 \ |
| 155 | _IOWR('X', 104, struct compat_xfs_fsop_handlereq) |
| 156 | #define XFS_IOC_PATH_TO_HANDLE_32 \ |
| 157 | _IOWR('X', 105, struct compat_xfs_fsop_handlereq) |
| 158 | #define XFS_IOC_FD_TO_HANDLE_32 \ |
| 159 | _IOWR('X', 106, struct compat_xfs_fsop_handlereq) |
| 160 | #define XFS_IOC_OPEN_BY_HANDLE_32 \ |
| 161 | _IOWR('X', 107, struct compat_xfs_fsop_handlereq) |
| 162 | #define XFS_IOC_READLINK_BY_HANDLE_32 \ |
| 163 | _IOWR('X', 108, struct compat_xfs_fsop_handlereq) |
| 164 | |
| 165 | STATIC unsigned long xfs_ioctl32_fshandle(unsigned long arg) |
| 166 | { |
| 167 | compat_xfs_fsop_handlereq_t __user *p32 = (void __user *)arg; |
| 168 | xfs_fsop_handlereq_t __user *p = compat_alloc_user_space(sizeof(*p)); |
| 169 | u32 addr; |
| 170 | |
| 171 | if (copy_in_user(&p->fd, &p32->fd, sizeof(__u32)) || |
| 172 | get_user(addr, &p32->path) || |
| 173 | put_user(compat_ptr(addr), &p->path) || |
| 174 | copy_in_user(&p->oflags, &p32->oflags, sizeof(__u32)) || |
| 175 | get_user(addr, &p32->ihandle) || |
| 176 | put_user(compat_ptr(addr), &p->ihandle) || |
| 177 | copy_in_user(&p->ihandlen, &p32->ihandlen, sizeof(__u32)) || |
| 178 | get_user(addr, &p32->ohandle) || |
| 179 | put_user(compat_ptr(addr), &p->ohandle) || |
| 180 | get_user(addr, &p32->ohandlen) || |
| 181 | put_user(compat_ptr(addr), &p->ohandlen)) |
| 182 | return -EFAULT; |
| 183 | |
| 184 | return (unsigned long)p; |
| 185 | } |
| 186 | |
| 187 | |
Nathan Scott | d387039 | 2005-05-06 06:44:46 -0700 | [diff] [blame] | 188 | STATIC long |
Nathan Scott | e0edd59 | 2006-03-29 08:55:47 +1000 | [diff] [blame] | 189 | xfs_compat_ioctl( |
| 190 | int mode, |
| 191 | struct file *file, |
| 192 | unsigned cmd, |
| 193 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | { |
Josef "Jeff" Sipek | e678fb0 | 2006-12-08 02:36:49 -0800 | [diff] [blame] | 195 | struct inode *inode = file->f_path.dentry->d_inode; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 196 | bhv_vnode_t *vp = vn_from_inode(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | |
| 199 | switch (cmd) { |
| 200 | case XFS_IOC_DIOINFO: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | case XFS_IOC_FSGEOMETRY: |
| 202 | case XFS_IOC_GETVERSION: |
| 203 | case XFS_IOC_GETXFLAGS: |
| 204 | case XFS_IOC_SETXFLAGS: |
| 205 | case XFS_IOC_FSGETXATTR: |
| 206 | case XFS_IOC_FSSETXATTR: |
| 207 | case XFS_IOC_FSGETXATTRA: |
| 208 | case XFS_IOC_FSSETDM: |
| 209 | case XFS_IOC_GETBMAP: |
| 210 | case XFS_IOC_GETBMAPA: |
| 211 | case XFS_IOC_GETBMAPX: |
| 212 | /* not handled |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | case XFS_IOC_FSSETDM_BY_HANDLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | case XFS_IOC_ATTRLIST_BY_HANDLE: |
| 215 | case XFS_IOC_ATTRMULTI_BY_HANDLE: |
| 216 | */ |
| 217 | case XFS_IOC_FSCOUNTS: |
| 218 | case XFS_IOC_SET_RESBLKS: |
| 219 | case XFS_IOC_GET_RESBLKS: |
| 220 | case XFS_IOC_FSGROWFSDATA: |
| 221 | case XFS_IOC_FSGROWFSLOG: |
| 222 | case XFS_IOC_FSGROWFSRT: |
| 223 | case XFS_IOC_FREEZE: |
| 224 | case XFS_IOC_THAW: |
| 225 | case XFS_IOC_GOINGDOWN: |
| 226 | case XFS_IOC_ERROR_INJECTION: |
| 227 | case XFS_IOC_ERROR_CLEARALL: |
| 228 | break; |
| 229 | |
Eric Sandeen | 526c420 | 2005-09-05 08:25:06 +1000 | [diff] [blame] | 230 | #ifdef BROKEN_X86_ALIGNMENT |
| 231 | /* xfs_flock_t has wrong u32 vs u64 alignment */ |
| 232 | case XFS_IOC_ALLOCSP_32: |
| 233 | case XFS_IOC_FREESP_32: |
| 234 | case XFS_IOC_ALLOCSP64_32: |
| 235 | case XFS_IOC_FREESP64_32: |
| 236 | case XFS_IOC_RESVSP_32: |
| 237 | case XFS_IOC_UNRESVSP_32: |
| 238 | case XFS_IOC_RESVSP64_32: |
| 239 | case XFS_IOC_UNRESVSP64_32: |
| 240 | arg = xfs_ioctl32_flock(arg); |
| 241 | cmd = _NATIVE_IOC(cmd, struct xfs_flock64); |
| 242 | break; |
Michal Marek | 547e00c | 2007-07-11 11:09:57 +1000 | [diff] [blame] | 243 | case XFS_IOC_FSGEOMETRY_V1_32: |
| 244 | arg = xfs_ioctl32_geom_v1(arg); |
| 245 | cmd = _NATIVE_IOC(cmd, struct xfs_fsop_geom_v1); |
| 246 | break; |
Eric Sandeen | 526c420 | 2005-09-05 08:25:06 +1000 | [diff] [blame] | 247 | |
| 248 | #else /* These are handled fine if no alignment issues */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | case XFS_IOC_ALLOCSP: |
| 250 | case XFS_IOC_FREESP: |
| 251 | case XFS_IOC_RESVSP: |
| 252 | case XFS_IOC_UNRESVSP: |
| 253 | case XFS_IOC_ALLOCSP64: |
| 254 | case XFS_IOC_FREESP64: |
| 255 | case XFS_IOC_RESVSP64: |
| 256 | case XFS_IOC_UNRESVSP64: |
Michal Marek | 547e00c | 2007-07-11 11:09:57 +1000 | [diff] [blame] | 257 | case XFS_IOC_FSGEOMETRY_V1: |
Eric Sandeen | 526c420 | 2005-09-05 08:25:06 +1000 | [diff] [blame] | 258 | break; |
| 259 | |
| 260 | /* xfs_bstat_t still has wrong u32 vs u64 alignment */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | case XFS_IOC_SWAPEXT: |
| 262 | break; |
| 263 | |
| 264 | case XFS_IOC_FSBULKSTAT_SINGLE: |
| 265 | case XFS_IOC_FSBULKSTAT: |
| 266 | case XFS_IOC_FSINUMBERS: |
| 267 | arg = xfs_ioctl32_bulkstat(arg); |
| 268 | break; |
| 269 | #endif |
Michal Marek | 1fa503d | 2007-07-11 11:10:09 +1000 | [diff] [blame^] | 270 | case XFS_IOC_FD_TO_HANDLE_32: |
| 271 | case XFS_IOC_PATH_TO_HANDLE_32: |
| 272 | case XFS_IOC_PATH_TO_FSHANDLE_32: |
| 273 | case XFS_IOC_OPEN_BY_HANDLE_32: |
| 274 | case XFS_IOC_READLINK_BY_HANDLE_32: |
| 275 | arg = xfs_ioctl32_fshandle(arg); |
| 276 | cmd = _NATIVE_IOC(cmd, struct xfs_fsop_handlereq); |
| 277 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | default: |
| 279 | return -ENOIOCTLCMD; |
| 280 | } |
| 281 | |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 282 | error = bhv_vop_ioctl(vp, inode, file, mode, cmd, (void __user *)arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | VMODIFY(vp); |
| 284 | |
| 285 | return error; |
| 286 | } |
| 287 | |
Nathan Scott | d387039 | 2005-05-06 06:44:46 -0700 | [diff] [blame] | 288 | long |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 289 | xfs_file_compat_ioctl( |
Nathan Scott | e0edd59 | 2006-03-29 08:55:47 +1000 | [diff] [blame] | 290 | struct file *file, |
Nathan Scott | d387039 | 2005-05-06 06:44:46 -0700 | [diff] [blame] | 291 | unsigned cmd, |
| 292 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | { |
Nathan Scott | e0edd59 | 2006-03-29 08:55:47 +1000 | [diff] [blame] | 294 | return xfs_compat_ioctl(0, file, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Nathan Scott | d387039 | 2005-05-06 06:44:46 -0700 | [diff] [blame] | 297 | long |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 298 | xfs_file_compat_invis_ioctl( |
Nathan Scott | e0edd59 | 2006-03-29 08:55:47 +1000 | [diff] [blame] | 299 | struct file *file, |
Nathan Scott | d387039 | 2005-05-06 06:44:46 -0700 | [diff] [blame] | 300 | unsigned cmd, |
| 301 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | { |
Nathan Scott | e0edd59 | 2006-03-29 08:55:47 +1000 | [diff] [blame] | 303 | return xfs_compat_ioctl(IO_INVIS, file, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |