xfs_ioctl32.c 18 KB

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