xfs_ioctl32.c 17 KB

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