xfs_ioctl32.c 18 KB

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