xfs_ioctl32.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /*
  2. * Copyright (c) 2004-2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  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
  7. * published by the Free Software Foundation.
  8. *
  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.
  13. *
  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
  17. */
  18. #include <linux/compat.h>
  19. #include <linux/ioctl.h>
  20. #include <linux/mount.h>
  21. #include <linux/slab.h>
  22. #include <asm/uaccess.h>
  23. #include "xfs.h"
  24. #include "xfs_fs.h"
  25. #include "xfs_format.h"
  26. #include "xfs_log_format.h"
  27. #include "xfs_trans_resv.h"
  28. #include "xfs_mount.h"
  29. #include "xfs_inode.h"
  30. #include "xfs_itable.h"
  31. #include "xfs_error.h"
  32. #include "xfs_fsops.h"
  33. #include "xfs_alloc.h"
  34. #include "xfs_rtalloc.h"
  35. #include "xfs_attr.h"
  36. #include "xfs_ioctl.h"
  37. #include "xfs_ioctl32.h"
  38. #include "xfs_trace.h"
  39. #define _NATIVE_IOC(cmd, type) \
  40. _IOC(_IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd), sizeof(type))
  41. #ifdef BROKEN_X86_ALIGNMENT
  42. STATIC int
  43. xfs_compat_flock64_copyin(
  44. xfs_flock64_t *bf,
  45. compat_xfs_flock64_t __user *arg32)
  46. {
  47. if (get_user(bf->l_type, &arg32->l_type) ||
  48. get_user(bf->l_whence, &arg32->l_whence) ||
  49. get_user(bf->l_start, &arg32->l_start) ||
  50. get_user(bf->l_len, &arg32->l_len) ||
  51. get_user(bf->l_sysid, &arg32->l_sysid) ||
  52. get_user(bf->l_pid, &arg32->l_pid) ||
  53. copy_from_user(bf->l_pad, &arg32->l_pad, 4*sizeof(u32)))
  54. return -EFAULT;
  55. return 0;
  56. }
  57. STATIC int
  58. xfs_compat_ioc_fsgeometry_v1(
  59. struct xfs_mount *mp,
  60. compat_xfs_fsop_geom_v1_t __user *arg32)
  61. {
  62. xfs_fsop_geom_t fsgeo;
  63. int error;
  64. error = xfs_fs_geometry(mp, &fsgeo, 3);
  65. if (error)
  66. return error;
  67. /* The 32-bit variant simply has some padding at the end */
  68. if (copy_to_user(arg32, &fsgeo, sizeof(struct compat_xfs_fsop_geom_v1)))
  69. return -EFAULT;
  70. return 0;
  71. }
  72. STATIC int
  73. xfs_compat_growfs_data_copyin(
  74. struct xfs_growfs_data *in,
  75. compat_xfs_growfs_data_t __user *arg32)
  76. {
  77. if (get_user(in->newblocks, &arg32->newblocks) ||
  78. get_user(in->imaxpct, &arg32->imaxpct))
  79. return -EFAULT;
  80. return 0;
  81. }
  82. STATIC int
  83. xfs_compat_growfs_rt_copyin(
  84. struct xfs_growfs_rt *in,
  85. compat_xfs_growfs_rt_t __user *arg32)
  86. {
  87. if (get_user(in->newblocks, &arg32->newblocks) ||
  88. get_user(in->extsize, &arg32->extsize))
  89. return -EFAULT;
  90. return 0;
  91. }
  92. STATIC int
  93. xfs_inumbers_fmt_compat(
  94. void __user *ubuffer,
  95. const struct xfs_inogrp *buffer,
  96. long count,
  97. long *written)
  98. {
  99. compat_xfs_inogrp_t __user *p32 = ubuffer;
  100. long i;
  101. for (i = 0; i < count; i++) {
  102. if (put_user(buffer[i].xi_startino, &p32[i].xi_startino) ||
  103. put_user(buffer[i].xi_alloccount, &p32[i].xi_alloccount) ||
  104. put_user(buffer[i].xi_allocmask, &p32[i].xi_allocmask))
  105. return -EFAULT;
  106. }
  107. *written = count * sizeof(*p32);
  108. return 0;
  109. }
  110. #else
  111. #define xfs_inumbers_fmt_compat xfs_inumbers_fmt
  112. #endif /* BROKEN_X86_ALIGNMENT */
  113. STATIC int
  114. xfs_ioctl32_bstime_copyin(
  115. xfs_bstime_t *bstime,
  116. compat_xfs_bstime_t __user *bstime32)
  117. {
  118. compat_time_t sec32; /* tv_sec differs on 64 vs. 32 */
  119. if (get_user(sec32, &bstime32->tv_sec) ||
  120. get_user(bstime->tv_nsec, &bstime32->tv_nsec))
  121. return -EFAULT;
  122. bstime->tv_sec = sec32;
  123. return 0;
  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_lo, &bstat32->bs_projid_lo) ||
  148. get_user(bstat->bs_projid_hi, &bstat32->bs_projid_hi) ||
  149. get_user(bstat->bs_forkoff, &bstat32->bs_forkoff) ||
  150. get_user(bstat->bs_dmevmask, &bstat32->bs_dmevmask) ||
  151. get_user(bstat->bs_dmstate, &bstat32->bs_dmstate) ||
  152. get_user(bstat->bs_aextents, &bstat32->bs_aextents))
  153. return -EFAULT;
  154. return 0;
  155. }
  156. /* XFS_IOC_FSBULKSTAT and friends */
  157. STATIC int
  158. xfs_bstime_store_compat(
  159. compat_xfs_bstime_t __user *p32,
  160. const xfs_bstime_t *p)
  161. {
  162. __s32 sec32;
  163. sec32 = p->tv_sec;
  164. if (put_user(sec32, &p32->tv_sec) ||
  165. put_user(p->tv_nsec, &p32->tv_nsec))
  166. return -EFAULT;
  167. return 0;
  168. }
  169. /* Return 0 on success or positive error (to xfs_bulkstat()) */
  170. STATIC int
  171. xfs_bulkstat_one_fmt_compat(
  172. void __user *ubuffer,
  173. int ubsize,
  174. int *ubused,
  175. const xfs_bstat_t *buffer)
  176. {
  177. compat_xfs_bstat_t __user *p32 = ubuffer;
  178. if (ubsize < sizeof(*p32))
  179. return -ENOMEM;
  180. if (put_user(buffer->bs_ino, &p32->bs_ino) ||
  181. put_user(buffer->bs_mode, &p32->bs_mode) ||
  182. put_user(buffer->bs_nlink, &p32->bs_nlink) ||
  183. put_user(buffer->bs_uid, &p32->bs_uid) ||
  184. put_user(buffer->bs_gid, &p32->bs_gid) ||
  185. put_user(buffer->bs_rdev, &p32->bs_rdev) ||
  186. put_user(buffer->bs_blksize, &p32->bs_blksize) ||
  187. put_user(buffer->bs_size, &p32->bs_size) ||
  188. xfs_bstime_store_compat(&p32->bs_atime, &buffer->bs_atime) ||
  189. xfs_bstime_store_compat(&p32->bs_mtime, &buffer->bs_mtime) ||
  190. xfs_bstime_store_compat(&p32->bs_ctime, &buffer->bs_ctime) ||
  191. put_user(buffer->bs_blocks, &p32->bs_blocks) ||
  192. put_user(buffer->bs_xflags, &p32->bs_xflags) ||
  193. put_user(buffer->bs_extsize, &p32->bs_extsize) ||
  194. put_user(buffer->bs_extents, &p32->bs_extents) ||
  195. put_user(buffer->bs_gen, &p32->bs_gen) ||
  196. put_user(buffer->bs_projid, &p32->bs_projid) ||
  197. put_user(buffer->bs_projid_hi, &p32->bs_projid_hi) ||
  198. put_user(buffer->bs_forkoff, &p32->bs_forkoff) ||
  199. put_user(buffer->bs_dmevmask, &p32->bs_dmevmask) ||
  200. put_user(buffer->bs_dmstate, &p32->bs_dmstate) ||
  201. put_user(buffer->bs_aextents, &p32->bs_aextents))
  202. return -EFAULT;
  203. if (ubused)
  204. *ubused = sizeof(*p32);
  205. return 0;
  206. }
  207. STATIC int
  208. xfs_bulkstat_one_compat(
  209. xfs_mount_t *mp, /* mount point for filesystem */
  210. xfs_ino_t ino, /* inode number to get data for */
  211. void __user *buffer, /* buffer to place output in */
  212. int ubsize, /* size of buffer */
  213. int *ubused, /* bytes used by me */
  214. int *stat) /* BULKSTAT_RV_... */
  215. {
  216. return xfs_bulkstat_one_int(mp, ino, buffer, ubsize,
  217. xfs_bulkstat_one_fmt_compat,
  218. ubused, stat);
  219. }
  220. /* copied from xfs_ioctl.c */
  221. STATIC int
  222. xfs_compat_ioc_bulkstat(
  223. xfs_mount_t *mp,
  224. unsigned int cmd,
  225. compat_xfs_fsop_bulkreq_t __user *p32)
  226. {
  227. u32 addr;
  228. xfs_fsop_bulkreq_t bulkreq;
  229. int count; /* # of records returned */
  230. xfs_ino_t inlast; /* last inode number */
  231. int done;
  232. int error;
  233. /* done = 1 if there are more stats to get and if bulkstat */
  234. /* should be called again (unused here, but used in dmapi) */
  235. if (!capable(CAP_SYS_ADMIN))
  236. return -EPERM;
  237. if (XFS_FORCED_SHUTDOWN(mp))
  238. return -EIO;
  239. if (get_user(addr, &p32->lastip))
  240. return -EFAULT;
  241. bulkreq.lastip = compat_ptr(addr);
  242. if (get_user(bulkreq.icount, &p32->icount) ||
  243. get_user(addr, &p32->ubuffer))
  244. return -EFAULT;
  245. bulkreq.ubuffer = compat_ptr(addr);
  246. if (get_user(addr, &p32->ocount))
  247. return -EFAULT;
  248. bulkreq.ocount = compat_ptr(addr);
  249. if (copy_from_user(&inlast, bulkreq.lastip, sizeof(__s64)))
  250. return -EFAULT;
  251. if ((count = bulkreq.icount) <= 0)
  252. return -EINVAL;
  253. if (bulkreq.ubuffer == NULL)
  254. return -EINVAL;
  255. if (cmd == XFS_IOC_FSINUMBERS_32) {
  256. error = xfs_inumbers(mp, &inlast, &count,
  257. bulkreq.ubuffer, xfs_inumbers_fmt_compat);
  258. } else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE_32) {
  259. int res;
  260. error = xfs_bulkstat_one_compat(mp, inlast, bulkreq.ubuffer,
  261. sizeof(compat_xfs_bstat_t), NULL, &res);
  262. } else if (cmd == XFS_IOC_FSBULKSTAT_32) {
  263. error = xfs_bulkstat(mp, &inlast, &count,
  264. xfs_bulkstat_one_compat, sizeof(compat_xfs_bstat_t),
  265. bulkreq.ubuffer, &done);
  266. } else
  267. error = -EINVAL;
  268. if (error)
  269. return error;
  270. if (bulkreq.ocount != NULL) {
  271. if (copy_to_user(bulkreq.lastip, &inlast,
  272. sizeof(xfs_ino_t)))
  273. return -EFAULT;
  274. if (copy_to_user(bulkreq.ocount, &count, sizeof(count)))
  275. return -EFAULT;
  276. }
  277. return 0;
  278. }
  279. STATIC int
  280. xfs_compat_handlereq_copyin(
  281. xfs_fsop_handlereq_t *hreq,
  282. compat_xfs_fsop_handlereq_t __user *arg32)
  283. {
  284. compat_xfs_fsop_handlereq_t hreq32;
  285. if (copy_from_user(&hreq32, arg32, sizeof(compat_xfs_fsop_handlereq_t)))
  286. return -EFAULT;
  287. hreq->fd = hreq32.fd;
  288. hreq->path = compat_ptr(hreq32.path);
  289. hreq->oflags = hreq32.oflags;
  290. hreq->ihandle = compat_ptr(hreq32.ihandle);
  291. hreq->ihandlen = hreq32.ihandlen;
  292. hreq->ohandle = compat_ptr(hreq32.ohandle);
  293. hreq->ohandlen = compat_ptr(hreq32.ohandlen);
  294. return 0;
  295. }
  296. STATIC struct dentry *
  297. xfs_compat_handlereq_to_dentry(
  298. struct file *parfilp,
  299. compat_xfs_fsop_handlereq_t *hreq)
  300. {
  301. return xfs_handle_to_dentry(parfilp,
  302. compat_ptr(hreq->ihandle), hreq->ihandlen);
  303. }
  304. STATIC int
  305. xfs_compat_attrlist_by_handle(
  306. struct file *parfilp,
  307. void __user *arg)
  308. {
  309. int error;
  310. attrlist_cursor_kern_t *cursor;
  311. compat_xfs_fsop_attrlist_handlereq_t al_hreq;
  312. struct dentry *dentry;
  313. char *kbuf;
  314. if (!capable(CAP_SYS_ADMIN))
  315. return -EPERM;
  316. if (copy_from_user(&al_hreq, arg,
  317. sizeof(compat_xfs_fsop_attrlist_handlereq_t)))
  318. return -EFAULT;
  319. if (al_hreq.buflen < sizeof(struct attrlist) ||
  320. al_hreq.buflen > XFS_XATTR_LIST_MAX)
  321. return -EINVAL;
  322. /*
  323. * Reject flags, only allow namespaces.
  324. */
  325. if (al_hreq.flags & ~(ATTR_ROOT | ATTR_SECURE))
  326. return -EINVAL;
  327. dentry = xfs_compat_handlereq_to_dentry(parfilp, &al_hreq.hreq);
  328. if (IS_ERR(dentry))
  329. return PTR_ERR(dentry);
  330. error = -ENOMEM;
  331. kbuf = kmem_zalloc_large(al_hreq.buflen, KM_SLEEP);
  332. if (!kbuf)
  333. goto out_dput;
  334. cursor = (attrlist_cursor_kern_t *)&al_hreq.pos;
  335. error = xfs_attr_list(XFS_I(d_inode(dentry)), kbuf, al_hreq.buflen,
  336. al_hreq.flags, cursor);
  337. if (error)
  338. goto out_kfree;
  339. if (copy_to_user(compat_ptr(al_hreq.buffer), kbuf, al_hreq.buflen))
  340. error = -EFAULT;
  341. out_kfree:
  342. kmem_free(kbuf);
  343. out_dput:
  344. dput(dentry);
  345. return error;
  346. }
  347. STATIC int
  348. xfs_compat_attrmulti_by_handle(
  349. struct file *parfilp,
  350. void __user *arg)
  351. {
  352. int error;
  353. compat_xfs_attr_multiop_t *ops;
  354. compat_xfs_fsop_attrmulti_handlereq_t am_hreq;
  355. struct dentry *dentry;
  356. unsigned int i, size;
  357. unsigned char *attr_name;
  358. if (!capable(CAP_SYS_ADMIN))
  359. return -EPERM;
  360. if (copy_from_user(&am_hreq, arg,
  361. sizeof(compat_xfs_fsop_attrmulti_handlereq_t)))
  362. return -EFAULT;
  363. /* overflow check */
  364. if (am_hreq.opcount >= INT_MAX / sizeof(compat_xfs_attr_multiop_t))
  365. return -E2BIG;
  366. dentry = xfs_compat_handlereq_to_dentry(parfilp, &am_hreq.hreq);
  367. if (IS_ERR(dentry))
  368. return PTR_ERR(dentry);
  369. error = -E2BIG;
  370. size = am_hreq.opcount * sizeof(compat_xfs_attr_multiop_t);
  371. if (!size || size > 16 * PAGE_SIZE)
  372. goto out_dput;
  373. ops = memdup_user(compat_ptr(am_hreq.ops), size);
  374. if (IS_ERR(ops)) {
  375. error = PTR_ERR(ops);
  376. goto out_dput;
  377. }
  378. error = -ENOMEM;
  379. attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL);
  380. if (!attr_name)
  381. goto out_kfree_ops;
  382. error = 0;
  383. for (i = 0; i < am_hreq.opcount; i++) {
  384. ops[i].am_error = strncpy_from_user((char *)attr_name,
  385. compat_ptr(ops[i].am_attrname),
  386. MAXNAMELEN);
  387. if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN)
  388. error = -ERANGE;
  389. if (ops[i].am_error < 0)
  390. break;
  391. switch (ops[i].am_opcode) {
  392. case ATTR_OP_GET:
  393. ops[i].am_error = xfs_attrmulti_attr_get(
  394. d_inode(dentry), attr_name,
  395. compat_ptr(ops[i].am_attrvalue),
  396. &ops[i].am_length, ops[i].am_flags);
  397. break;
  398. case ATTR_OP_SET:
  399. ops[i].am_error = mnt_want_write_file(parfilp);
  400. if (ops[i].am_error)
  401. break;
  402. ops[i].am_error = xfs_attrmulti_attr_set(
  403. d_inode(dentry), attr_name,
  404. compat_ptr(ops[i].am_attrvalue),
  405. ops[i].am_length, ops[i].am_flags);
  406. mnt_drop_write_file(parfilp);
  407. break;
  408. case ATTR_OP_REMOVE:
  409. ops[i].am_error = mnt_want_write_file(parfilp);
  410. if (ops[i].am_error)
  411. break;
  412. ops[i].am_error = xfs_attrmulti_attr_remove(
  413. d_inode(dentry), attr_name,
  414. ops[i].am_flags);
  415. mnt_drop_write_file(parfilp);
  416. break;
  417. default:
  418. ops[i].am_error = -EINVAL;
  419. }
  420. }
  421. if (copy_to_user(compat_ptr(am_hreq.ops), ops, size))
  422. error = -EFAULT;
  423. kfree(attr_name);
  424. out_kfree_ops:
  425. kfree(ops);
  426. out_dput:
  427. dput(dentry);
  428. return error;
  429. }
  430. STATIC int
  431. xfs_compat_fssetdm_by_handle(
  432. struct file *parfilp,
  433. void __user *arg)
  434. {
  435. int error;
  436. struct fsdmidata fsd;
  437. compat_xfs_fsop_setdm_handlereq_t dmhreq;
  438. struct dentry *dentry;
  439. if (!capable(CAP_MKNOD))
  440. return -EPERM;
  441. if (copy_from_user(&dmhreq, arg,
  442. sizeof(compat_xfs_fsop_setdm_handlereq_t)))
  443. return -EFAULT;
  444. dentry = xfs_compat_handlereq_to_dentry(parfilp, &dmhreq.hreq);
  445. if (IS_ERR(dentry))
  446. return PTR_ERR(dentry);
  447. if (IS_IMMUTABLE(d_inode(dentry)) || IS_APPEND(d_inode(dentry))) {
  448. error = -EPERM;
  449. goto out;
  450. }
  451. if (copy_from_user(&fsd, compat_ptr(dmhreq.data), sizeof(fsd))) {
  452. error = -EFAULT;
  453. goto out;
  454. }
  455. error = xfs_set_dmattrs(XFS_I(d_inode(dentry)), fsd.fsd_dmevmask,
  456. fsd.fsd_dmstate);
  457. out:
  458. dput(dentry);
  459. return error;
  460. }
  461. long
  462. xfs_file_compat_ioctl(
  463. struct file *filp,
  464. unsigned cmd,
  465. unsigned long p)
  466. {
  467. struct inode *inode = file_inode(filp);
  468. struct xfs_inode *ip = XFS_I(inode);
  469. struct xfs_mount *mp = ip->i_mount;
  470. void __user *arg = (void __user *)p;
  471. int ioflags = 0;
  472. int error;
  473. if (filp->f_mode & FMODE_NOCMTIME)
  474. ioflags |= XFS_IO_INVIS;
  475. trace_xfs_file_compat_ioctl(ip);
  476. switch (cmd) {
  477. /* No size or alignment issues on any arch */
  478. case XFS_IOC_DIOINFO:
  479. case XFS_IOC_FSGEOMETRY:
  480. case XFS_IOC_FSGETXATTR:
  481. case XFS_IOC_FSSETXATTR:
  482. case XFS_IOC_FSGETXATTRA:
  483. case XFS_IOC_FSSETDM:
  484. case XFS_IOC_GETBMAP:
  485. case XFS_IOC_GETBMAPA:
  486. case XFS_IOC_GETBMAPX:
  487. case XFS_IOC_FSCOUNTS:
  488. case XFS_IOC_SET_RESBLKS:
  489. case XFS_IOC_GET_RESBLKS:
  490. case XFS_IOC_FSGROWFSLOG:
  491. case XFS_IOC_GOINGDOWN:
  492. case XFS_IOC_ERROR_INJECTION:
  493. case XFS_IOC_ERROR_CLEARALL:
  494. return xfs_file_ioctl(filp, cmd, p);
  495. #ifndef BROKEN_X86_ALIGNMENT
  496. /* These are handled fine if no alignment issues */
  497. case XFS_IOC_ALLOCSP:
  498. case XFS_IOC_FREESP:
  499. case XFS_IOC_RESVSP:
  500. case XFS_IOC_UNRESVSP:
  501. case XFS_IOC_ALLOCSP64:
  502. case XFS_IOC_FREESP64:
  503. case XFS_IOC_RESVSP64:
  504. case XFS_IOC_UNRESVSP64:
  505. case XFS_IOC_FSGEOMETRY_V1:
  506. case XFS_IOC_FSGROWFSDATA:
  507. case XFS_IOC_FSGROWFSRT:
  508. case XFS_IOC_ZERO_RANGE:
  509. return xfs_file_ioctl(filp, cmd, p);
  510. #else
  511. case XFS_IOC_ALLOCSP_32:
  512. case XFS_IOC_FREESP_32:
  513. case XFS_IOC_ALLOCSP64_32:
  514. case XFS_IOC_FREESP64_32:
  515. case XFS_IOC_RESVSP_32:
  516. case XFS_IOC_UNRESVSP_32:
  517. case XFS_IOC_RESVSP64_32:
  518. case XFS_IOC_UNRESVSP64_32:
  519. case XFS_IOC_ZERO_RANGE_32: {
  520. struct xfs_flock64 bf;
  521. if (xfs_compat_flock64_copyin(&bf, arg))
  522. return -EFAULT;
  523. cmd = _NATIVE_IOC(cmd, struct xfs_flock64);
  524. return xfs_ioc_space(ip, inode, filp, ioflags, cmd, &bf);
  525. }
  526. case XFS_IOC_FSGEOMETRY_V1_32:
  527. return xfs_compat_ioc_fsgeometry_v1(mp, arg);
  528. case XFS_IOC_FSGROWFSDATA_32: {
  529. struct xfs_growfs_data in;
  530. if (xfs_compat_growfs_data_copyin(&in, arg))
  531. return -EFAULT;
  532. error = mnt_want_write_file(filp);
  533. if (error)
  534. return error;
  535. error = xfs_growfs_data(mp, &in);
  536. mnt_drop_write_file(filp);
  537. return error;
  538. }
  539. case XFS_IOC_FSGROWFSRT_32: {
  540. struct xfs_growfs_rt in;
  541. if (xfs_compat_growfs_rt_copyin(&in, arg))
  542. return -EFAULT;
  543. error = mnt_want_write_file(filp);
  544. if (error)
  545. return error;
  546. error = xfs_growfs_rt(mp, &in);
  547. mnt_drop_write_file(filp);
  548. return error;
  549. }
  550. #endif
  551. /* long changes size, but xfs only copiese out 32 bits */
  552. case XFS_IOC_GETXFLAGS_32:
  553. case XFS_IOC_SETXFLAGS_32:
  554. case XFS_IOC_GETVERSION_32:
  555. cmd = _NATIVE_IOC(cmd, long);
  556. return xfs_file_ioctl(filp, cmd, p);
  557. case XFS_IOC_SWAPEXT_32: {
  558. struct xfs_swapext sxp;
  559. struct compat_xfs_swapext __user *sxu = arg;
  560. /* Bulk copy in up to the sx_stat field, then copy bstat */
  561. if (copy_from_user(&sxp, sxu,
  562. offsetof(struct xfs_swapext, sx_stat)) ||
  563. xfs_ioctl32_bstat_copyin(&sxp.sx_stat, &sxu->sx_stat))
  564. return -EFAULT;
  565. error = mnt_want_write_file(filp);
  566. if (error)
  567. return error;
  568. error = xfs_ioc_swapext(&sxp);
  569. mnt_drop_write_file(filp);
  570. return error;
  571. }
  572. case XFS_IOC_FSBULKSTAT_32:
  573. case XFS_IOC_FSBULKSTAT_SINGLE_32:
  574. case XFS_IOC_FSINUMBERS_32:
  575. return xfs_compat_ioc_bulkstat(mp, cmd, arg);
  576. case XFS_IOC_FD_TO_HANDLE_32:
  577. case XFS_IOC_PATH_TO_HANDLE_32:
  578. case XFS_IOC_PATH_TO_FSHANDLE_32: {
  579. struct xfs_fsop_handlereq hreq;
  580. if (xfs_compat_handlereq_copyin(&hreq, arg))
  581. return -EFAULT;
  582. cmd = _NATIVE_IOC(cmd, struct xfs_fsop_handlereq);
  583. return xfs_find_handle(cmd, &hreq);
  584. }
  585. case XFS_IOC_OPEN_BY_HANDLE_32: {
  586. struct xfs_fsop_handlereq hreq;
  587. if (xfs_compat_handlereq_copyin(&hreq, arg))
  588. return -EFAULT;
  589. return xfs_open_by_handle(filp, &hreq);
  590. }
  591. case XFS_IOC_READLINK_BY_HANDLE_32: {
  592. struct xfs_fsop_handlereq hreq;
  593. if (xfs_compat_handlereq_copyin(&hreq, arg))
  594. return -EFAULT;
  595. return xfs_readlink_by_handle(filp, &hreq);
  596. }
  597. case XFS_IOC_ATTRLIST_BY_HANDLE_32:
  598. return xfs_compat_attrlist_by_handle(filp, arg);
  599. case XFS_IOC_ATTRMULTI_BY_HANDLE_32:
  600. return xfs_compat_attrmulti_by_handle(filp, arg);
  601. case XFS_IOC_FSSETDM_BY_HANDLE_32:
  602. return xfs_compat_fssetdm_by_handle(filp, arg);
  603. default:
  604. return -ENOIOCTLCMD;
  605. }
  606. }