xfs_ioctl32.c 18 KB

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