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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | #else |
| 79 | |
| 80 | typedef struct xfs_fsop_bulkreq32 { |
| 81 | compat_uptr_t lastip; /* last inode # pointer */ |
| 82 | __s32 icount; /* count of entries in buffer */ |
| 83 | compat_uptr_t ubuffer; /* user buffer for inode desc. */ |
| 84 | __s32 ocount; /* output count pointer */ |
| 85 | } xfs_fsop_bulkreq32_t; |
| 86 | |
Nathan Scott | d387039 | 2005-05-06 06:44:46 -0700 | [diff] [blame] | 87 | STATIC unsigned long |
| 88 | xfs_ioctl32_bulkstat( |
| 89 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | { |
| 91 | xfs_fsop_bulkreq32_t __user *p32 = (void __user *)arg; |
| 92 | xfs_fsop_bulkreq_t __user *p = compat_alloc_user_space(sizeof(*p)); |
| 93 | u32 addr; |
| 94 | |
| 95 | if (get_user(addr, &p32->lastip) || |
| 96 | put_user(compat_ptr(addr), &p->lastip) || |
| 97 | copy_in_user(&p->icount, &p32->icount, sizeof(s32)) || |
| 98 | get_user(addr, &p32->ubuffer) || |
| 99 | put_user(compat_ptr(addr), &p->ubuffer) || |
| 100 | get_user(addr, &p32->ocount) || |
| 101 | put_user(compat_ptr(addr), &p->ocount)) |
| 102 | return -EFAULT; |
| 103 | |
| 104 | return (unsigned long)p; |
| 105 | } |
| 106 | #endif |
| 107 | |
Nathan Scott | d387039 | 2005-05-06 06:44:46 -0700 | [diff] [blame] | 108 | STATIC long |
Nathan Scott | e0edd59 | 2006-03-29 08:55:47 +1000 | [diff] [blame] | 109 | xfs_compat_ioctl( |
| 110 | int mode, |
| 111 | struct file *file, |
| 112 | unsigned cmd, |
| 113 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
Josef "Jeff" Sipek | e678fb0 | 2006-12-08 02:36:49 -0800 | [diff] [blame^] | 115 | struct inode *inode = file->f_path.dentry->d_inode; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 116 | bhv_vnode_t *vp = vn_from_inode(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
| 119 | switch (cmd) { |
| 120 | case XFS_IOC_DIOINFO: |
| 121 | case XFS_IOC_FSGEOMETRY_V1: |
| 122 | case XFS_IOC_FSGEOMETRY: |
| 123 | case XFS_IOC_GETVERSION: |
| 124 | case XFS_IOC_GETXFLAGS: |
| 125 | case XFS_IOC_SETXFLAGS: |
| 126 | case XFS_IOC_FSGETXATTR: |
| 127 | case XFS_IOC_FSSETXATTR: |
| 128 | case XFS_IOC_FSGETXATTRA: |
| 129 | case XFS_IOC_FSSETDM: |
| 130 | case XFS_IOC_GETBMAP: |
| 131 | case XFS_IOC_GETBMAPA: |
| 132 | case XFS_IOC_GETBMAPX: |
| 133 | /* not handled |
| 134 | case XFS_IOC_FD_TO_HANDLE: |
| 135 | case XFS_IOC_PATH_TO_HANDLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | case XFS_IOC_PATH_TO_FSHANDLE: |
| 137 | case XFS_IOC_OPEN_BY_HANDLE: |
| 138 | case XFS_IOC_FSSETDM_BY_HANDLE: |
| 139 | case XFS_IOC_READLINK_BY_HANDLE: |
| 140 | case XFS_IOC_ATTRLIST_BY_HANDLE: |
| 141 | case XFS_IOC_ATTRMULTI_BY_HANDLE: |
| 142 | */ |
| 143 | case XFS_IOC_FSCOUNTS: |
| 144 | case XFS_IOC_SET_RESBLKS: |
| 145 | case XFS_IOC_GET_RESBLKS: |
| 146 | case XFS_IOC_FSGROWFSDATA: |
| 147 | case XFS_IOC_FSGROWFSLOG: |
| 148 | case XFS_IOC_FSGROWFSRT: |
| 149 | case XFS_IOC_FREEZE: |
| 150 | case XFS_IOC_THAW: |
| 151 | case XFS_IOC_GOINGDOWN: |
| 152 | case XFS_IOC_ERROR_INJECTION: |
| 153 | case XFS_IOC_ERROR_CLEARALL: |
| 154 | break; |
| 155 | |
Eric Sandeen | 526c420 | 2005-09-05 08:25:06 +1000 | [diff] [blame] | 156 | #ifdef BROKEN_X86_ALIGNMENT |
| 157 | /* xfs_flock_t has wrong u32 vs u64 alignment */ |
| 158 | case XFS_IOC_ALLOCSP_32: |
| 159 | case XFS_IOC_FREESP_32: |
| 160 | case XFS_IOC_ALLOCSP64_32: |
| 161 | case XFS_IOC_FREESP64_32: |
| 162 | case XFS_IOC_RESVSP_32: |
| 163 | case XFS_IOC_UNRESVSP_32: |
| 164 | case XFS_IOC_RESVSP64_32: |
| 165 | case XFS_IOC_UNRESVSP64_32: |
| 166 | arg = xfs_ioctl32_flock(arg); |
| 167 | cmd = _NATIVE_IOC(cmd, struct xfs_flock64); |
| 168 | break; |
| 169 | |
| 170 | #else /* These are handled fine if no alignment issues */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | case XFS_IOC_ALLOCSP: |
| 172 | case XFS_IOC_FREESP: |
| 173 | case XFS_IOC_RESVSP: |
| 174 | case XFS_IOC_UNRESVSP: |
| 175 | case XFS_IOC_ALLOCSP64: |
| 176 | case XFS_IOC_FREESP64: |
| 177 | case XFS_IOC_RESVSP64: |
| 178 | case XFS_IOC_UNRESVSP64: |
Eric Sandeen | 526c420 | 2005-09-05 08:25:06 +1000 | [diff] [blame] | 179 | break; |
| 180 | |
| 181 | /* xfs_bstat_t still has wrong u32 vs u64 alignment */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | case XFS_IOC_SWAPEXT: |
| 183 | break; |
| 184 | |
| 185 | case XFS_IOC_FSBULKSTAT_SINGLE: |
| 186 | case XFS_IOC_FSBULKSTAT: |
| 187 | case XFS_IOC_FSINUMBERS: |
| 188 | arg = xfs_ioctl32_bulkstat(arg); |
| 189 | break; |
| 190 | #endif |
| 191 | default: |
| 192 | return -ENOIOCTLCMD; |
| 193 | } |
| 194 | |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 195 | error = bhv_vop_ioctl(vp, inode, file, mode, cmd, (void __user *)arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | VMODIFY(vp); |
| 197 | |
| 198 | return error; |
| 199 | } |
| 200 | |
Nathan Scott | d387039 | 2005-05-06 06:44:46 -0700 | [diff] [blame] | 201 | long |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 202 | xfs_file_compat_ioctl( |
Nathan Scott | e0edd59 | 2006-03-29 08:55:47 +1000 | [diff] [blame] | 203 | struct file *file, |
Nathan Scott | d387039 | 2005-05-06 06:44:46 -0700 | [diff] [blame] | 204 | unsigned cmd, |
| 205 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | { |
Nathan Scott | e0edd59 | 2006-03-29 08:55:47 +1000 | [diff] [blame] | 207 | return xfs_compat_ioctl(0, file, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Nathan Scott | d387039 | 2005-05-06 06:44:46 -0700 | [diff] [blame] | 210 | long |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 211 | xfs_file_compat_invis_ioctl( |
Nathan Scott | e0edd59 | 2006-03-29 08:55:47 +1000 | [diff] [blame] | 212 | struct file *file, |
Nathan Scott | d387039 | 2005-05-06 06:44:46 -0700 | [diff] [blame] | 213 | unsigned cmd, |
| 214 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | { |
Nathan Scott | e0edd59 | 2006-03-29 08:55:47 +1000 | [diff] [blame] | 216 | return xfs_compat_ioctl(IO_INVIS, file, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | } |