xfs_ioctl32.c 18 KB

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