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" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include "xfs_fs.h" |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 27 | #include "xfs_bit.h" |
| 28 | #include "xfs_log.h" |
| 29 | #include "xfs_inum.h" |
| 30 | #include "xfs_trans.h" |
| 31 | #include "xfs_sb.h" |
| 32 | #include "xfs_ag.h" |
| 33 | #include "xfs_dir2.h" |
| 34 | #include "xfs_dmapi.h" |
| 35 | #include "xfs_mount.h" |
| 36 | #include "xfs_bmap_btree.h" |
| 37 | #include "xfs_attr_sf.h" |
| 38 | #include "xfs_dir2_sf.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include "xfs_vnode.h" |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 40 | #include "xfs_dinode.h" |
| 41 | #include "xfs_inode.h" |
| 42 | #include "xfs_itable.h" |
| 43 | #include "xfs_error.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include "xfs_dfrag.h" |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 45 | #include "xfs_vnodeops.h" |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 46 | #include "xfs_fsops.h" |
| 47 | #include "xfs_ioctl.h" |
David Chinner | a8272ce | 2007-11-23 16:28:09 +1100 | [diff] [blame] | 48 | #include "xfs_ioctl32.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Eric Sandeen | 526c420 | 2005-09-05 08:25:06 +1000 | [diff] [blame] | 50 | #define _NATIVE_IOC(cmd, type) \ |
| 51 | _IOC(_IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd), sizeof(type)) |
| 52 | |
sandeen@sandeen.net | ffae263 | 2008-11-25 21:20:07 -0600 | [diff] [blame] | 53 | #ifdef BROKEN_X86_ALIGNMENT |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 54 | STATIC int |
| 55 | xfs_compat_flock64_copyin( |
| 56 | xfs_flock64_t *bf, |
| 57 | compat_xfs_flock64_t __user *arg32) |
Eric Sandeen | 526c420 | 2005-09-05 08:25:06 +1000 | [diff] [blame] | 58 | { |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 59 | if (get_user(bf->l_type, &arg32->l_type) || |
| 60 | get_user(bf->l_whence, &arg32->l_whence) || |
| 61 | get_user(bf->l_start, &arg32->l_start) || |
| 62 | get_user(bf->l_len, &arg32->l_len) || |
| 63 | get_user(bf->l_sysid, &arg32->l_sysid) || |
| 64 | get_user(bf->l_pid, &arg32->l_pid) || |
| 65 | copy_from_user(bf->l_pad, &arg32->l_pad, 4*sizeof(u32))) |
| 66 | return -XFS_ERROR(EFAULT); |
| 67 | return 0; |
Eric Sandeen | 526c420 | 2005-09-05 08:25:06 +1000 | [diff] [blame] | 68 | } |
| 69 | |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 70 | STATIC int |
| 71 | xfs_compat_ioc_fsgeometry_v1( |
| 72 | struct xfs_mount *mp, |
| 73 | compat_xfs_fsop_geom_v1_t __user *arg32) |
Michal Marek | 547e00c | 2007-07-11 11:09:57 +1000 | [diff] [blame] | 74 | { |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 75 | xfs_fsop_geom_t fsgeo; |
| 76 | int error; |
Michal Marek | 547e00c | 2007-07-11 11:09:57 +1000 | [diff] [blame] | 77 | |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 78 | error = xfs_fs_geometry(mp, &fsgeo, 3); |
| 79 | if (error) |
| 80 | return -error; |
| 81 | /* The 32-bit variant simply has some padding at the end */ |
| 82 | if (copy_to_user(arg32, &fsgeo, sizeof(struct compat_xfs_fsop_geom_v1))) |
| 83 | return -XFS_ERROR(EFAULT); |
| 84 | return 0; |
Michal Marek | 547e00c | 2007-07-11 11:09:57 +1000 | [diff] [blame] | 85 | } |
| 86 | |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 87 | STATIC int |
| 88 | xfs_inumbers_fmt_compat( |
| 89 | void __user *ubuffer, |
| 90 | const xfs_inogrp_t *buffer, |
| 91 | long count, |
| 92 | long *written) |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 93 | { |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 94 | compat_xfs_inogrp_t __user *p32 = ubuffer; |
| 95 | long i; |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 96 | |
| 97 | for (i = 0; i < count; i++) { |
| 98 | if (put_user(buffer[i].xi_startino, &p32[i].xi_startino) || |
| 99 | put_user(buffer[i].xi_alloccount, &p32[i].xi_alloccount) || |
| 100 | put_user(buffer[i].xi_allocmask, &p32[i].xi_allocmask)) |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 101 | return -XFS_ERROR(EFAULT); |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 102 | } |
| 103 | *written = count * sizeof(*p32); |
| 104 | return 0; |
| 105 | } |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | #else |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 108 | #define xfs_inumbers_fmt_compat xfs_inumbers_fmt |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 109 | #endif |
| 110 | |
sandeen@sandeen.net | e94fc4a | 2008-11-25 21:20:09 -0600 | [diff] [blame^] | 111 | STATIC int |
| 112 | xfs_ioctl32_bstime_copyin( |
| 113 | xfs_bstime_t *bstime, |
| 114 | compat_xfs_bstime_t __user *bstime32) |
| 115 | { |
| 116 | compat_time_t sec32; /* tv_sec differs on 64 vs. 32 */ |
| 117 | |
| 118 | if (get_user(sec32, &bstime32->tv_sec) || |
| 119 | get_user(bstime->tv_nsec, &bstime32->tv_nsec)) |
| 120 | return -XFS_ERROR(EFAULT); |
| 121 | bstime->tv_sec = sec32; |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | /* xfs_bstat_t has differing alignment on intel, & bstime_t sizes everywhere */ |
| 126 | STATIC int |
| 127 | xfs_ioctl32_bstat_copyin( |
| 128 | xfs_bstat_t *bstat, |
| 129 | compat_xfs_bstat_t __user *bstat32) |
| 130 | { |
| 131 | if (get_user(bstat->bs_ino, &bstat32->bs_ino) || |
| 132 | get_user(bstat->bs_mode, &bstat32->bs_mode) || |
| 133 | get_user(bstat->bs_nlink, &bstat32->bs_nlink) || |
| 134 | get_user(bstat->bs_uid, &bstat32->bs_uid) || |
| 135 | get_user(bstat->bs_gid, &bstat32->bs_gid) || |
| 136 | get_user(bstat->bs_rdev, &bstat32->bs_rdev) || |
| 137 | get_user(bstat->bs_blksize, &bstat32->bs_blksize) || |
| 138 | get_user(bstat->bs_size, &bstat32->bs_size) || |
| 139 | xfs_ioctl32_bstime_copyin(&bstat->bs_atime, &bstat32->bs_atime) || |
| 140 | xfs_ioctl32_bstime_copyin(&bstat->bs_mtime, &bstat32->bs_mtime) || |
| 141 | xfs_ioctl32_bstime_copyin(&bstat->bs_ctime, &bstat32->bs_ctime) || |
| 142 | get_user(bstat->bs_blocks, &bstat32->bs_size) || |
| 143 | get_user(bstat->bs_xflags, &bstat32->bs_size) || |
| 144 | get_user(bstat->bs_extsize, &bstat32->bs_extsize) || |
| 145 | get_user(bstat->bs_extents, &bstat32->bs_extents) || |
| 146 | get_user(bstat->bs_gen, &bstat32->bs_gen) || |
| 147 | get_user(bstat->bs_projid, &bstat32->bs_projid) || |
| 148 | get_user(bstat->bs_dmevmask, &bstat32->bs_dmevmask) || |
| 149 | get_user(bstat->bs_dmstate, &bstat32->bs_dmstate) || |
| 150 | get_user(bstat->bs_aextents, &bstat32->bs_aextents)) |
| 151 | return -XFS_ERROR(EFAULT); |
| 152 | return 0; |
| 153 | } |
| 154 | |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 155 | /* XFS_IOC_FSBULKSTAT and friends */ |
| 156 | |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 157 | STATIC int |
| 158 | xfs_bstime_store_compat( |
| 159 | compat_xfs_bstime_t __user *p32, |
| 160 | const xfs_bstime_t *p) |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 161 | { |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 162 | __s32 sec32; |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 163 | |
| 164 | sec32 = p->tv_sec; |
| 165 | if (put_user(sec32, &p32->tv_sec) || |
| 166 | put_user(p->tv_nsec, &p32->tv_nsec)) |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 167 | return -XFS_ERROR(EFAULT); |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 168 | return 0; |
| 169 | } |
| 170 | |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 171 | STATIC int |
| 172 | xfs_bulkstat_one_fmt_compat( |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 173 | void __user *ubuffer, |
| 174 | const xfs_bstat_t *buffer) |
| 175 | { |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 176 | compat_xfs_bstat_t __user *p32 = ubuffer; |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 177 | |
| 178 | if (put_user(buffer->bs_ino, &p32->bs_ino) || |
| 179 | put_user(buffer->bs_mode, &p32->bs_mode) || |
| 180 | put_user(buffer->bs_nlink, &p32->bs_nlink) || |
| 181 | put_user(buffer->bs_uid, &p32->bs_uid) || |
| 182 | put_user(buffer->bs_gid, &p32->bs_gid) || |
| 183 | put_user(buffer->bs_rdev, &p32->bs_rdev) || |
| 184 | put_user(buffer->bs_blksize, &p32->bs_blksize) || |
| 185 | put_user(buffer->bs_size, &p32->bs_size) || |
| 186 | xfs_bstime_store_compat(&p32->bs_atime, &buffer->bs_atime) || |
| 187 | xfs_bstime_store_compat(&p32->bs_mtime, &buffer->bs_mtime) || |
| 188 | xfs_bstime_store_compat(&p32->bs_ctime, &buffer->bs_ctime) || |
| 189 | put_user(buffer->bs_blocks, &p32->bs_blocks) || |
| 190 | put_user(buffer->bs_xflags, &p32->bs_xflags) || |
| 191 | put_user(buffer->bs_extsize, &p32->bs_extsize) || |
| 192 | put_user(buffer->bs_extents, &p32->bs_extents) || |
| 193 | put_user(buffer->bs_gen, &p32->bs_gen) || |
| 194 | put_user(buffer->bs_projid, &p32->bs_projid) || |
| 195 | put_user(buffer->bs_dmevmask, &p32->bs_dmevmask) || |
| 196 | put_user(buffer->bs_dmstate, &p32->bs_dmstate) || |
| 197 | put_user(buffer->bs_aextents, &p32->bs_aextents)) |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 198 | return -XFS_ERROR(EFAULT); |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 199 | return sizeof(*p32); |
| 200 | } |
| 201 | |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 202 | /* copied from xfs_ioctl.c */ |
| 203 | STATIC int |
| 204 | xfs_ioc_bulkstat_compat( |
| 205 | xfs_mount_t *mp, |
| 206 | unsigned int cmd, |
| 207 | void __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | { |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 209 | compat_xfs_fsop_bulkreq_t __user *p32 = (void __user *)arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | u32 addr; |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 211 | xfs_fsop_bulkreq_t bulkreq; |
| 212 | int count; /* # of records returned */ |
| 213 | xfs_ino_t inlast; /* last inode number */ |
| 214 | int done; |
| 215 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 217 | /* done = 1 if there are more stats to get and if bulkstat */ |
| 218 | /* should be called again (unused here, but used in dmapi) */ |
| 219 | |
| 220 | if (!capable(CAP_SYS_ADMIN)) |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 221 | return -XFS_ERROR(EPERM); |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 222 | |
| 223 | if (XFS_FORCED_SHUTDOWN(mp)) |
| 224 | return -XFS_ERROR(EIO); |
| 225 | |
| 226 | if (get_user(addr, &p32->lastip)) |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 227 | return -XFS_ERROR(EFAULT); |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 228 | bulkreq.lastip = compat_ptr(addr); |
| 229 | if (get_user(bulkreq.icount, &p32->icount) || |
| 230 | get_user(addr, &p32->ubuffer)) |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 231 | return -XFS_ERROR(EFAULT); |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 232 | bulkreq.ubuffer = compat_ptr(addr); |
| 233 | if (get_user(addr, &p32->ocount)) |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 234 | return -XFS_ERROR(EFAULT); |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 235 | bulkreq.ocount = compat_ptr(addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 237 | if (copy_from_user(&inlast, bulkreq.lastip, sizeof(__s64))) |
| 238 | return -XFS_ERROR(EFAULT); |
| 239 | |
| 240 | if ((count = bulkreq.icount) <= 0) |
| 241 | return -XFS_ERROR(EINVAL); |
| 242 | |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 243 | if (bulkreq.ubuffer == NULL) |
| 244 | return -XFS_ERROR(EINVAL); |
| 245 | |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 246 | if (cmd == XFS_IOC_FSINUMBERS) |
| 247 | error = xfs_inumbers(mp, &inlast, &count, |
| 248 | bulkreq.ubuffer, xfs_inumbers_fmt_compat); |
| 249 | else { |
| 250 | /* declare a var to get a warning in case the type changes */ |
| 251 | bulkstat_one_fmt_pf formatter = xfs_bulkstat_one_fmt_compat; |
| 252 | error = xfs_bulkstat(mp, &inlast, &count, |
| 253 | xfs_bulkstat_one, formatter, |
| 254 | sizeof(compat_xfs_bstat_t), bulkreq.ubuffer, |
| 255 | BULKSTAT_FG_QUICK, &done); |
| 256 | } |
| 257 | if (error) |
| 258 | return -error; |
| 259 | |
| 260 | if (bulkreq.ocount != NULL) { |
| 261 | if (copy_to_user(bulkreq.lastip, &inlast, |
| 262 | sizeof(xfs_ino_t))) |
| 263 | return -XFS_ERROR(EFAULT); |
| 264 | |
| 265 | if (copy_to_user(bulkreq.ocount, &count, sizeof(count))) |
| 266 | return -XFS_ERROR(EFAULT); |
| 267 | } |
| 268 | |
| 269 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | } |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 271 | |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 272 | STATIC int |
| 273 | xfs_compat_handlereq_copyin( |
| 274 | xfs_fsop_handlereq_t *hreq, |
| 275 | compat_xfs_fsop_handlereq_t __user *arg32) |
Michal Marek | 1fa503d | 2007-07-11 11:10:09 +1000 | [diff] [blame] | 276 | { |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 277 | compat_xfs_fsop_handlereq_t hreq32; |
Michal Marek | 1fa503d | 2007-07-11 11:10:09 +1000 | [diff] [blame] | 278 | |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 279 | if (copy_from_user(&hreq32, arg32, sizeof(compat_xfs_fsop_handlereq_t))) |
| 280 | return -XFS_ERROR(EFAULT); |
Michal Marek | 1fa503d | 2007-07-11 11:10:09 +1000 | [diff] [blame] | 281 | |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 282 | hreq->fd = hreq32.fd; |
| 283 | hreq->path = compat_ptr(hreq32.path); |
| 284 | hreq->oflags = hreq32.oflags; |
| 285 | hreq->ihandle = compat_ptr(hreq32.ihandle); |
| 286 | hreq->ihandlen = hreq32.ihandlen; |
| 287 | hreq->ohandle = compat_ptr(hreq32.ohandle); |
| 288 | hreq->ohandlen = compat_ptr(hreq32.ohandlen); |
| 289 | |
| 290 | return 0; |
Michal Marek | 1fa503d | 2007-07-11 11:10:09 +1000 | [diff] [blame] | 291 | } |
| 292 | |
Nathan Scott | d387039 | 2005-05-06 06:44:46 -0700 | [diff] [blame] | 293 | STATIC long |
Nathan Scott | e0edd59 | 2006-03-29 08:55:47 +1000 | [diff] [blame] | 294 | xfs_compat_ioctl( |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 295 | xfs_inode_t *ip, |
| 296 | struct file *filp, |
| 297 | int ioflags, |
Nathan Scott | e0edd59 | 2006-03-29 08:55:47 +1000 | [diff] [blame] | 298 | unsigned cmd, |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 299 | void __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | { |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 301 | struct inode *inode = filp->f_path.dentry->d_inode; |
| 302 | xfs_mount_t *mp = ip->i_mount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 305 | xfs_itrace_entry(XFS_I(inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | switch (cmd) { |
| 307 | case XFS_IOC_DIOINFO: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | case XFS_IOC_FSGEOMETRY: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | case XFS_IOC_FSGETXATTR: |
| 310 | case XFS_IOC_FSSETXATTR: |
| 311 | case XFS_IOC_FSGETXATTRA: |
| 312 | case XFS_IOC_FSSETDM: |
| 313 | case XFS_IOC_GETBMAP: |
| 314 | case XFS_IOC_GETBMAPA: |
| 315 | case XFS_IOC_GETBMAPX: |
| 316 | /* not handled |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | case XFS_IOC_FSSETDM_BY_HANDLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | case XFS_IOC_ATTRLIST_BY_HANDLE: |
| 319 | case XFS_IOC_ATTRMULTI_BY_HANDLE: |
| 320 | */ |
| 321 | case XFS_IOC_FSCOUNTS: |
| 322 | case XFS_IOC_SET_RESBLKS: |
| 323 | case XFS_IOC_GET_RESBLKS: |
| 324 | case XFS_IOC_FSGROWFSDATA: |
| 325 | case XFS_IOC_FSGROWFSLOG: |
| 326 | case XFS_IOC_FSGROWFSRT: |
| 327 | case XFS_IOC_FREEZE: |
| 328 | case XFS_IOC_THAW: |
| 329 | case XFS_IOC_GOINGDOWN: |
| 330 | case XFS_IOC_ERROR_INJECTION: |
| 331 | case XFS_IOC_ERROR_CLEARALL: |
| 332 | break; |
| 333 | |
sandeen@sandeen.net | ffae263 | 2008-11-25 21:20:07 -0600 | [diff] [blame] | 334 | case XFS_IOC_GETXFLAGS_32: |
| 335 | case XFS_IOC_SETXFLAGS_32: |
| 336 | case XFS_IOC_GETVERSION_32: |
Eric Sandeen | bc58f9b | 2007-10-12 11:13:22 +1000 | [diff] [blame] | 337 | cmd = _NATIVE_IOC(cmd, long); |
| 338 | break; |
sandeen@sandeen.net | e94fc4a | 2008-11-25 21:20:09 -0600 | [diff] [blame^] | 339 | case XFS_IOC_SWAPEXT: { |
| 340 | struct xfs_swapext sxp; |
| 341 | struct compat_xfs_swapext __user *sxu = arg; |
| 342 | |
| 343 | /* Bulk copy in up to the sx_stat field, then grab bstat */ |
| 344 | if (copy_from_user(&sxp, sxu, |
| 345 | offsetof(xfs_swapext_t, sx_stat)) || |
| 346 | xfs_ioctl32_bstat_copyin(&sxp.sx_stat, &sxu->sx_stat)) |
| 347 | return -XFS_ERROR(EFAULT); |
| 348 | error = xfs_swapext(&sxp); |
| 349 | return -error; |
| 350 | } |
Eric Sandeen | 526c420 | 2005-09-05 08:25:06 +1000 | [diff] [blame] | 351 | #ifdef BROKEN_X86_ALIGNMENT |
| 352 | /* xfs_flock_t has wrong u32 vs u64 alignment */ |
| 353 | case XFS_IOC_ALLOCSP_32: |
| 354 | case XFS_IOC_FREESP_32: |
| 355 | case XFS_IOC_ALLOCSP64_32: |
| 356 | case XFS_IOC_FREESP64_32: |
| 357 | case XFS_IOC_RESVSP_32: |
| 358 | case XFS_IOC_UNRESVSP_32: |
| 359 | case XFS_IOC_RESVSP64_32: |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 360 | case XFS_IOC_UNRESVSP64_32: { |
| 361 | struct xfs_flock64 bf; |
| 362 | |
| 363 | if (xfs_compat_flock64_copyin(&bf, arg)) |
| 364 | return -XFS_ERROR(EFAULT); |
Eric Sandeen | 526c420 | 2005-09-05 08:25:06 +1000 | [diff] [blame] | 365 | cmd = _NATIVE_IOC(cmd, struct xfs_flock64); |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 366 | return xfs_ioc_space(ip, inode, filp, ioflags, cmd, &bf); |
| 367 | } |
Michal Marek | 547e00c | 2007-07-11 11:09:57 +1000 | [diff] [blame] | 368 | case XFS_IOC_FSGEOMETRY_V1_32: |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 369 | return xfs_compat_ioc_fsgeometry_v1(mp, arg); |
Eric Sandeen | 526c420 | 2005-09-05 08:25:06 +1000 | [diff] [blame] | 370 | #else /* These are handled fine if no alignment issues */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | case XFS_IOC_ALLOCSP: |
| 372 | case XFS_IOC_FREESP: |
| 373 | case XFS_IOC_RESVSP: |
| 374 | case XFS_IOC_UNRESVSP: |
| 375 | case XFS_IOC_ALLOCSP64: |
| 376 | case XFS_IOC_FREESP64: |
| 377 | case XFS_IOC_RESVSP64: |
| 378 | case XFS_IOC_UNRESVSP64: |
Michal Marek | 547e00c | 2007-07-11 11:09:57 +1000 | [diff] [blame] | 379 | case XFS_IOC_FSGEOMETRY_V1: |
Eric Sandeen | 526c420 | 2005-09-05 08:25:06 +1000 | [diff] [blame] | 380 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | #endif |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 382 | case XFS_IOC_FSBULKSTAT_32: |
| 383 | case XFS_IOC_FSBULKSTAT_SINGLE_32: |
| 384 | case XFS_IOC_FSINUMBERS_32: |
| 385 | cmd = _NATIVE_IOC(cmd, struct xfs_fsop_bulkreq); |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 386 | return xfs_ioc_bulkstat_compat(XFS_I(inode)->i_mount, |
Al Viro | ad690ef | 2007-07-26 17:35:59 +0100 | [diff] [blame] | 387 | cmd, (void __user*)arg); |
Michal Marek | 1fa503d | 2007-07-11 11:10:09 +1000 | [diff] [blame] | 388 | case XFS_IOC_FD_TO_HANDLE_32: |
| 389 | case XFS_IOC_PATH_TO_HANDLE_32: |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 390 | case XFS_IOC_PATH_TO_FSHANDLE_32: { |
| 391 | struct xfs_fsop_handlereq hreq; |
| 392 | |
| 393 | if (xfs_compat_handlereq_copyin(&hreq, arg)) |
| 394 | return -XFS_ERROR(EFAULT); |
Michal Marek | 1fa503d | 2007-07-11 11:10:09 +1000 | [diff] [blame] | 395 | cmd = _NATIVE_IOC(cmd, struct xfs_fsop_handlereq); |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 396 | return xfs_find_handle(cmd, &hreq); |
| 397 | } |
| 398 | case XFS_IOC_OPEN_BY_HANDLE_32: { |
| 399 | struct xfs_fsop_handlereq hreq; |
| 400 | |
| 401 | if (xfs_compat_handlereq_copyin(&hreq, arg)) |
| 402 | return -XFS_ERROR(EFAULT); |
| 403 | return xfs_open_by_handle(mp, &hreq, filp, inode); |
| 404 | } |
| 405 | case XFS_IOC_READLINK_BY_HANDLE_32: { |
| 406 | struct xfs_fsop_handlereq hreq; |
| 407 | |
| 408 | if (xfs_compat_handlereq_copyin(&hreq, arg)) |
| 409 | return -XFS_ERROR(EFAULT); |
| 410 | return xfs_readlink_by_handle(mp, &hreq, inode); |
| 411 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | default: |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 413 | return -XFS_ERROR(ENOIOCTLCMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | } |
| 415 | |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 416 | error = xfs_ioctl(ip, filp, ioflags, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | return error; |
| 418 | } |
| 419 | |
Nathan Scott | d387039 | 2005-05-06 06:44:46 -0700 | [diff] [blame] | 420 | long |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 421 | xfs_file_compat_ioctl( |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 422 | struct file *filp, |
| 423 | unsigned int cmd, |
| 424 | unsigned long p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | { |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 426 | struct inode *inode = filp->f_path.dentry->d_inode; |
| 427 | |
| 428 | return xfs_compat_ioctl(XFS_I(inode), filp, 0, cmd, (void __user *)p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Nathan Scott | d387039 | 2005-05-06 06:44:46 -0700 | [diff] [blame] | 431 | long |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 432 | xfs_file_compat_invis_ioctl( |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 433 | struct file *filp, |
| 434 | unsigned int cmd, |
| 435 | unsigned long p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | { |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 437 | struct inode *inode = filp->f_path.dentry->d_inode; |
| 438 | |
| 439 | return xfs_compat_ioctl(XFS_I(inode), filp, IO_INVIS, cmd, |
| 440 | (void __user *)p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | } |