xfs_ioctl.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336
  1. /*
  2. * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it would be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. * Further, this software is distributed without any warranty that it is
  13. * free of the rightful claim of any third person regarding infringement
  14. * or the like. Any license provided herein, whether implied or
  15. * otherwise, applies only to this software file. Patent licenses, if
  16. * any, provided herein do not apply to combinations of this program with
  17. * other software, or any other product whatsoever.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston MA 02111-1307, USA.
  22. *
  23. * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  24. * Mountain View, CA 94043, or:
  25. *
  26. * http://www.sgi.com
  27. *
  28. * For further information regarding this notice, see:
  29. *
  30. * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
  31. */
  32. #include "xfs.h"
  33. #include "xfs_fs.h"
  34. #include "xfs_inum.h"
  35. #include "xfs_log.h"
  36. #include "xfs_trans.h"
  37. #include "xfs_sb.h"
  38. #include "xfs_dir.h"
  39. #include "xfs_dir2.h"
  40. #include "xfs_alloc.h"
  41. #include "xfs_dmapi.h"
  42. #include "xfs_mount.h"
  43. #include "xfs_alloc_btree.h"
  44. #include "xfs_bmap_btree.h"
  45. #include "xfs_ialloc_btree.h"
  46. #include "xfs_btree.h"
  47. #include "xfs_ialloc.h"
  48. #include "xfs_attr_sf.h"
  49. #include "xfs_dir_sf.h"
  50. #include "xfs_dir2_sf.h"
  51. #include "xfs_dinode.h"
  52. #include "xfs_inode.h"
  53. #include "xfs_bmap.h"
  54. #include "xfs_bit.h"
  55. #include "xfs_rtalloc.h"
  56. #include "xfs_error.h"
  57. #include "xfs_itable.h"
  58. #include "xfs_rw.h"
  59. #include "xfs_acl.h"
  60. #include "xfs_cap.h"
  61. #include "xfs_mac.h"
  62. #include "xfs_attr.h"
  63. #include "xfs_buf_item.h"
  64. #include "xfs_utils.h"
  65. #include "xfs_dfrag.h"
  66. #include "xfs_fsops.h"
  67. #include <linux/dcache.h>
  68. #include <linux/mount.h>
  69. #include <linux/namei.h>
  70. #include <linux/pagemap.h>
  71. /*
  72. * xfs_find_handle maps from userspace xfs_fsop_handlereq structure to
  73. * a file or fs handle.
  74. *
  75. * XFS_IOC_PATH_TO_FSHANDLE
  76. * returns fs handle for a mount point or path within that mount point
  77. * XFS_IOC_FD_TO_HANDLE
  78. * returns full handle for a FD opened in user space
  79. * XFS_IOC_PATH_TO_HANDLE
  80. * returns full handle for a path
  81. */
  82. STATIC int
  83. xfs_find_handle(
  84. unsigned int cmd,
  85. void __user *arg)
  86. {
  87. int hsize;
  88. xfs_handle_t handle;
  89. xfs_fsop_handlereq_t hreq;
  90. struct inode *inode;
  91. struct vnode *vp;
  92. if (copy_from_user(&hreq, arg, sizeof(hreq)))
  93. return -XFS_ERROR(EFAULT);
  94. memset((char *)&handle, 0, sizeof(handle));
  95. switch (cmd) {
  96. case XFS_IOC_PATH_TO_FSHANDLE:
  97. case XFS_IOC_PATH_TO_HANDLE: {
  98. struct nameidata nd;
  99. int error;
  100. error = user_path_walk_link((const char __user *)hreq.path, &nd);
  101. if (error)
  102. return error;
  103. ASSERT(nd.dentry);
  104. ASSERT(nd.dentry->d_inode);
  105. inode = igrab(nd.dentry->d_inode);
  106. path_release(&nd);
  107. break;
  108. }
  109. case XFS_IOC_FD_TO_HANDLE: {
  110. struct file *file;
  111. file = fget(hreq.fd);
  112. if (!file)
  113. return -EBADF;
  114. ASSERT(file->f_dentry);
  115. ASSERT(file->f_dentry->d_inode);
  116. inode = igrab(file->f_dentry->d_inode);
  117. fput(file);
  118. break;
  119. }
  120. default:
  121. ASSERT(0);
  122. return -XFS_ERROR(EINVAL);
  123. }
  124. if (inode->i_sb->s_magic != XFS_SB_MAGIC) {
  125. /* we're not in XFS anymore, Toto */
  126. iput(inode);
  127. return -XFS_ERROR(EINVAL);
  128. }
  129. /* we need the vnode */
  130. vp = LINVFS_GET_VP(inode);
  131. if (vp->v_type != VREG && vp->v_type != VDIR && vp->v_type != VLNK) {
  132. iput(inode);
  133. return -XFS_ERROR(EBADF);
  134. }
  135. /* now we can grab the fsid */
  136. memcpy(&handle.ha_fsid, vp->v_vfsp->vfs_altfsid, sizeof(xfs_fsid_t));
  137. hsize = sizeof(xfs_fsid_t);
  138. if (cmd != XFS_IOC_PATH_TO_FSHANDLE) {
  139. xfs_inode_t *ip;
  140. bhv_desc_t *bhv;
  141. int lock_mode;
  142. /* need to get access to the xfs_inode to read the generation */
  143. bhv = vn_bhv_lookup_unlocked(VN_BHV_HEAD(vp), &xfs_vnodeops);
  144. ASSERT(bhv);
  145. ip = XFS_BHVTOI(bhv);
  146. ASSERT(ip);
  147. lock_mode = xfs_ilock_map_shared(ip);
  148. /* fill in fid section of handle from inode */
  149. handle.ha_fid.xfs_fid_len = sizeof(xfs_fid_t) -
  150. sizeof(handle.ha_fid.xfs_fid_len);
  151. handle.ha_fid.xfs_fid_pad = 0;
  152. handle.ha_fid.xfs_fid_gen = ip->i_d.di_gen;
  153. handle.ha_fid.xfs_fid_ino = ip->i_ino;
  154. xfs_iunlock_map_shared(ip, lock_mode);
  155. hsize = XFS_HSIZE(handle);
  156. }
  157. /* now copy our handle into the user buffer & write out the size */
  158. if (copy_to_user(hreq.ohandle, &handle, hsize) ||
  159. copy_to_user(hreq.ohandlen, &hsize, sizeof(__s32))) {
  160. iput(inode);
  161. return -XFS_ERROR(EFAULT);
  162. }
  163. iput(inode);
  164. return 0;
  165. }
  166. /*
  167. * Convert userspace handle data into vnode (and inode).
  168. * We [ab]use the fact that all the fsop_handlereq ioctl calls
  169. * have a data structure argument whose first component is always
  170. * a xfs_fsop_handlereq_t, so we can cast to and from this type.
  171. * This allows us to optimise the copy_from_user calls and gives
  172. * a handy, shared routine.
  173. *
  174. * If no error, caller must always VN_RELE the returned vp.
  175. */
  176. STATIC int
  177. xfs_vget_fsop_handlereq(
  178. xfs_mount_t *mp,
  179. struct inode *parinode, /* parent inode pointer */
  180. xfs_fsop_handlereq_t *hreq,
  181. vnode_t **vp,
  182. struct inode **inode)
  183. {
  184. void __user *hanp;
  185. size_t hlen;
  186. xfs_fid_t *xfid;
  187. xfs_handle_t *handlep;
  188. xfs_handle_t handle;
  189. xfs_inode_t *ip;
  190. struct inode *inodep;
  191. vnode_t *vpp;
  192. xfs_ino_t ino;
  193. __u32 igen;
  194. int error;
  195. /*
  196. * Only allow handle opens under a directory.
  197. */
  198. if (!S_ISDIR(parinode->i_mode))
  199. return XFS_ERROR(ENOTDIR);
  200. hanp = hreq->ihandle;
  201. hlen = hreq->ihandlen;
  202. handlep = &handle;
  203. if (hlen < sizeof(handlep->ha_fsid) || hlen > sizeof(*handlep))
  204. return XFS_ERROR(EINVAL);
  205. if (copy_from_user(handlep, hanp, hlen))
  206. return XFS_ERROR(EFAULT);
  207. if (hlen < sizeof(*handlep))
  208. memset(((char *)handlep) + hlen, 0, sizeof(*handlep) - hlen);
  209. if (hlen > sizeof(handlep->ha_fsid)) {
  210. if (handlep->ha_fid.xfs_fid_len !=
  211. (hlen - sizeof(handlep->ha_fsid)
  212. - sizeof(handlep->ha_fid.xfs_fid_len))
  213. || handlep->ha_fid.xfs_fid_pad)
  214. return XFS_ERROR(EINVAL);
  215. }
  216. /*
  217. * Crack the handle, obtain the inode # & generation #
  218. */
  219. xfid = (struct xfs_fid *)&handlep->ha_fid;
  220. if (xfid->xfs_fid_len == sizeof(*xfid) - sizeof(xfid->xfs_fid_len)) {
  221. ino = xfid->xfs_fid_ino;
  222. igen = xfid->xfs_fid_gen;
  223. } else {
  224. return XFS_ERROR(EINVAL);
  225. }
  226. /*
  227. * Get the XFS inode, building a vnode to go with it.
  228. */
  229. error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
  230. if (error)
  231. return error;
  232. if (ip == NULL)
  233. return XFS_ERROR(EIO);
  234. if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
  235. xfs_iput_new(ip, XFS_ILOCK_SHARED);
  236. return XFS_ERROR(ENOENT);
  237. }
  238. vpp = XFS_ITOV(ip);
  239. inodep = LINVFS_GET_IP(vpp);
  240. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  241. *vp = vpp;
  242. *inode = inodep;
  243. return 0;
  244. }
  245. STATIC int
  246. xfs_open_by_handle(
  247. xfs_mount_t *mp,
  248. void __user *arg,
  249. struct file *parfilp,
  250. struct inode *parinode)
  251. {
  252. int error;
  253. int new_fd;
  254. int permflag;
  255. struct file *filp;
  256. struct inode *inode;
  257. struct dentry *dentry;
  258. vnode_t *vp;
  259. xfs_fsop_handlereq_t hreq;
  260. if (!capable(CAP_SYS_ADMIN))
  261. return -XFS_ERROR(EPERM);
  262. if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
  263. return -XFS_ERROR(EFAULT);
  264. error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &vp, &inode);
  265. if (error)
  266. return -error;
  267. /* Restrict xfs_open_by_handle to directories & regular files. */
  268. if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) {
  269. iput(inode);
  270. return -XFS_ERROR(EINVAL);
  271. }
  272. #if BITS_PER_LONG != 32
  273. hreq.oflags |= O_LARGEFILE;
  274. #endif
  275. /* Put open permission in namei format. */
  276. permflag = hreq.oflags;
  277. if ((permflag+1) & O_ACCMODE)
  278. permflag++;
  279. if (permflag & O_TRUNC)
  280. permflag |= 2;
  281. if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) &&
  282. (permflag & FMODE_WRITE) && IS_APPEND(inode)) {
  283. iput(inode);
  284. return -XFS_ERROR(EPERM);
  285. }
  286. if ((permflag & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
  287. iput(inode);
  288. return -XFS_ERROR(EACCES);
  289. }
  290. /* Can't write directories. */
  291. if ( S_ISDIR(inode->i_mode) && (permflag & FMODE_WRITE)) {
  292. iput(inode);
  293. return -XFS_ERROR(EISDIR);
  294. }
  295. if ((new_fd = get_unused_fd()) < 0) {
  296. iput(inode);
  297. return new_fd;
  298. }
  299. dentry = d_alloc_anon(inode);
  300. if (dentry == NULL) {
  301. iput(inode);
  302. put_unused_fd(new_fd);
  303. return -XFS_ERROR(ENOMEM);
  304. }
  305. /* Ensure umount returns EBUSY on umounts while this file is open. */
  306. mntget(parfilp->f_vfsmnt);
  307. /* Create file pointer. */
  308. filp = dentry_open(dentry, parfilp->f_vfsmnt, hreq.oflags);
  309. if (IS_ERR(filp)) {
  310. put_unused_fd(new_fd);
  311. return -XFS_ERROR(-PTR_ERR(filp));
  312. }
  313. if (inode->i_mode & S_IFREG)
  314. filp->f_op = &linvfs_invis_file_operations;
  315. fd_install(new_fd, filp);
  316. return new_fd;
  317. }
  318. STATIC int
  319. xfs_readlink_by_handle(
  320. xfs_mount_t *mp,
  321. void __user *arg,
  322. struct file *parfilp,
  323. struct inode *parinode)
  324. {
  325. int error;
  326. struct iovec aiov;
  327. struct uio auio;
  328. struct inode *inode;
  329. xfs_fsop_handlereq_t hreq;
  330. vnode_t *vp;
  331. __u32 olen;
  332. if (!capable(CAP_SYS_ADMIN))
  333. return -XFS_ERROR(EPERM);
  334. if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
  335. return -XFS_ERROR(EFAULT);
  336. error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &vp, &inode);
  337. if (error)
  338. return -error;
  339. /* Restrict this handle operation to symlinks only. */
  340. if (vp->v_type != VLNK) {
  341. VN_RELE(vp);
  342. return -XFS_ERROR(EINVAL);
  343. }
  344. if (copy_from_user(&olen, hreq.ohandlen, sizeof(__u32))) {
  345. VN_RELE(vp);
  346. return -XFS_ERROR(EFAULT);
  347. }
  348. aiov.iov_len = olen;
  349. aiov.iov_base = hreq.ohandle;
  350. auio.uio_iov = &aiov;
  351. auio.uio_iovcnt = 1;
  352. auio.uio_offset = 0;
  353. auio.uio_segflg = UIO_USERSPACE;
  354. auio.uio_resid = olen;
  355. VOP_READLINK(vp, &auio, IO_INVIS, NULL, error);
  356. VN_RELE(vp);
  357. return (olen - auio.uio_resid);
  358. }
  359. STATIC int
  360. xfs_fssetdm_by_handle(
  361. xfs_mount_t *mp,
  362. void __user *arg,
  363. struct file *parfilp,
  364. struct inode *parinode)
  365. {
  366. int error;
  367. struct fsdmidata fsd;
  368. xfs_fsop_setdm_handlereq_t dmhreq;
  369. struct inode *inode;
  370. bhv_desc_t *bdp;
  371. vnode_t *vp;
  372. if (!capable(CAP_MKNOD))
  373. return -XFS_ERROR(EPERM);
  374. if (copy_from_user(&dmhreq, arg, sizeof(xfs_fsop_setdm_handlereq_t)))
  375. return -XFS_ERROR(EFAULT);
  376. error = xfs_vget_fsop_handlereq(mp, parinode, &dmhreq.hreq, &vp, &inode);
  377. if (error)
  378. return -error;
  379. if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) {
  380. VN_RELE(vp);
  381. return -XFS_ERROR(EPERM);
  382. }
  383. if (copy_from_user(&fsd, dmhreq.data, sizeof(fsd))) {
  384. VN_RELE(vp);
  385. return -XFS_ERROR(EFAULT);
  386. }
  387. bdp = bhv_base_unlocked(VN_BHV_HEAD(vp));
  388. error = xfs_set_dmattrs(bdp, fsd.fsd_dmevmask, fsd.fsd_dmstate, NULL);
  389. VN_RELE(vp);
  390. if (error)
  391. return -error;
  392. return 0;
  393. }
  394. STATIC int
  395. xfs_attrlist_by_handle(
  396. xfs_mount_t *mp,
  397. void __user *arg,
  398. struct file *parfilp,
  399. struct inode *parinode)
  400. {
  401. int error;
  402. attrlist_cursor_kern_t *cursor;
  403. xfs_fsop_attrlist_handlereq_t al_hreq;
  404. struct inode *inode;
  405. vnode_t *vp;
  406. char *kbuf;
  407. if (!capable(CAP_SYS_ADMIN))
  408. return -XFS_ERROR(EPERM);
  409. if (copy_from_user(&al_hreq, arg, sizeof(xfs_fsop_attrlist_handlereq_t)))
  410. return -XFS_ERROR(EFAULT);
  411. if (al_hreq.buflen > XATTR_LIST_MAX)
  412. return -XFS_ERROR(EINVAL);
  413. error = xfs_vget_fsop_handlereq(mp, parinode, &al_hreq.hreq,
  414. &vp, &inode);
  415. if (error)
  416. goto out;
  417. kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL);
  418. if (!kbuf)
  419. goto out_vn_rele;
  420. cursor = (attrlist_cursor_kern_t *)&al_hreq.pos;
  421. VOP_ATTR_LIST(vp, kbuf, al_hreq.buflen, al_hreq.flags,
  422. cursor, NULL, error);
  423. if (error)
  424. goto out_kfree;
  425. if (copy_to_user(al_hreq.buffer, kbuf, al_hreq.buflen))
  426. error = -EFAULT;
  427. out_kfree:
  428. kfree(kbuf);
  429. out_vn_rele:
  430. VN_RELE(vp);
  431. out:
  432. return -error;
  433. }
  434. STATIC int
  435. xfs_attrmulti_attr_get(
  436. struct vnode *vp,
  437. char *name,
  438. char __user *ubuf,
  439. __uint32_t *len,
  440. __uint32_t flags)
  441. {
  442. char *kbuf;
  443. int error = EFAULT;
  444. if (*len > XATTR_SIZE_MAX)
  445. return EINVAL;
  446. kbuf = kmalloc(*len, GFP_KERNEL);
  447. if (!kbuf)
  448. return ENOMEM;
  449. VOP_ATTR_GET(vp, name, kbuf, len, flags, NULL, error);
  450. if (error)
  451. goto out_kfree;
  452. if (copy_to_user(ubuf, kbuf, *len))
  453. error = EFAULT;
  454. out_kfree:
  455. kfree(kbuf);
  456. return error;
  457. }
  458. STATIC int
  459. xfs_attrmulti_attr_set(
  460. struct vnode *vp,
  461. char *name,
  462. const char __user *ubuf,
  463. __uint32_t len,
  464. __uint32_t flags)
  465. {
  466. char *kbuf;
  467. int error = EFAULT;
  468. if (IS_IMMUTABLE(&vp->v_inode) || IS_APPEND(&vp->v_inode))
  469. return EPERM;
  470. if (len > XATTR_SIZE_MAX)
  471. return EINVAL;
  472. kbuf = kmalloc(len, GFP_KERNEL);
  473. if (!kbuf)
  474. return ENOMEM;
  475. if (copy_from_user(kbuf, ubuf, len))
  476. goto out_kfree;
  477. VOP_ATTR_SET(vp, name, kbuf, len, flags, NULL, error);
  478. out_kfree:
  479. kfree(kbuf);
  480. return error;
  481. }
  482. STATIC int
  483. xfs_attrmulti_attr_remove(
  484. struct vnode *vp,
  485. char *name,
  486. __uint32_t flags)
  487. {
  488. int error;
  489. if (IS_IMMUTABLE(&vp->v_inode) || IS_APPEND(&vp->v_inode))
  490. return EPERM;
  491. VOP_ATTR_REMOVE(vp, name, flags, NULL, error);
  492. return error;
  493. }
  494. STATIC int
  495. xfs_attrmulti_by_handle(
  496. xfs_mount_t *mp,
  497. void __user *arg,
  498. struct file *parfilp,
  499. struct inode *parinode)
  500. {
  501. int error;
  502. xfs_attr_multiop_t *ops;
  503. xfs_fsop_attrmulti_handlereq_t am_hreq;
  504. struct inode *inode;
  505. vnode_t *vp;
  506. unsigned int i, size;
  507. char *attr_name;
  508. if (!capable(CAP_SYS_ADMIN))
  509. return -XFS_ERROR(EPERM);
  510. if (copy_from_user(&am_hreq, arg, sizeof(xfs_fsop_attrmulti_handlereq_t)))
  511. return -XFS_ERROR(EFAULT);
  512. error = xfs_vget_fsop_handlereq(mp, parinode, &am_hreq.hreq, &vp, &inode);
  513. if (error)
  514. goto out;
  515. error = E2BIG;
  516. size = am_hreq.opcount * sizeof(attr_multiop_t);
  517. if (!size || size > 16 * PAGE_SIZE)
  518. goto out_vn_rele;
  519. error = ENOMEM;
  520. ops = kmalloc(size, GFP_KERNEL);
  521. if (!ops)
  522. goto out_vn_rele;
  523. error = EFAULT;
  524. if (copy_from_user(ops, am_hreq.ops, size))
  525. goto out_kfree_ops;
  526. attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL);
  527. if (!attr_name)
  528. goto out_kfree_ops;
  529. error = 0;
  530. for (i = 0; i < am_hreq.opcount; i++) {
  531. ops[i].am_error = strncpy_from_user(attr_name,
  532. ops[i].am_attrname, MAXNAMELEN);
  533. if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN)
  534. error = -ERANGE;
  535. if (ops[i].am_error < 0)
  536. break;
  537. switch (ops[i].am_opcode) {
  538. case ATTR_OP_GET:
  539. ops[i].am_error = xfs_attrmulti_attr_get(vp,
  540. attr_name, ops[i].am_attrvalue,
  541. &ops[i].am_length, ops[i].am_flags);
  542. break;
  543. case ATTR_OP_SET:
  544. ops[i].am_error = xfs_attrmulti_attr_set(vp,
  545. attr_name, ops[i].am_attrvalue,
  546. ops[i].am_length, ops[i].am_flags);
  547. break;
  548. case ATTR_OP_REMOVE:
  549. ops[i].am_error = xfs_attrmulti_attr_remove(vp,
  550. attr_name, ops[i].am_flags);
  551. break;
  552. default:
  553. ops[i].am_error = EINVAL;
  554. }
  555. }
  556. if (copy_to_user(am_hreq.ops, ops, size))
  557. error = XFS_ERROR(EFAULT);
  558. kfree(attr_name);
  559. out_kfree_ops:
  560. kfree(ops);
  561. out_vn_rele:
  562. VN_RELE(vp);
  563. out:
  564. return -error;
  565. }
  566. /* prototypes for a few of the stack-hungry cases that have
  567. * their own functions. Functions are defined after their use
  568. * so gcc doesn't get fancy and inline them with -03 */
  569. STATIC int
  570. xfs_ioc_space(
  571. bhv_desc_t *bdp,
  572. vnode_t *vp,
  573. struct file *filp,
  574. int flags,
  575. unsigned int cmd,
  576. void __user *arg);
  577. STATIC int
  578. xfs_ioc_bulkstat(
  579. xfs_mount_t *mp,
  580. unsigned int cmd,
  581. void __user *arg);
  582. STATIC int
  583. xfs_ioc_fsgeometry_v1(
  584. xfs_mount_t *mp,
  585. void __user *arg);
  586. STATIC int
  587. xfs_ioc_fsgeometry(
  588. xfs_mount_t *mp,
  589. void __user *arg);
  590. STATIC int
  591. xfs_ioc_xattr(
  592. vnode_t *vp,
  593. xfs_inode_t *ip,
  594. struct file *filp,
  595. unsigned int cmd,
  596. void __user *arg);
  597. STATIC int
  598. xfs_ioc_getbmap(
  599. bhv_desc_t *bdp,
  600. struct file *filp,
  601. int flags,
  602. unsigned int cmd,
  603. void __user *arg);
  604. STATIC int
  605. xfs_ioc_getbmapx(
  606. bhv_desc_t *bdp,
  607. void __user *arg);
  608. int
  609. xfs_ioctl(
  610. bhv_desc_t *bdp,
  611. struct inode *inode,
  612. struct file *filp,
  613. int ioflags,
  614. unsigned int cmd,
  615. void __user *arg)
  616. {
  617. int error;
  618. vnode_t *vp;
  619. xfs_inode_t *ip;
  620. xfs_mount_t *mp;
  621. vp = LINVFS_GET_VP(inode);
  622. vn_trace_entry(vp, "xfs_ioctl", (inst_t *)__return_address);
  623. ip = XFS_BHVTOI(bdp);
  624. mp = ip->i_mount;
  625. switch (cmd) {
  626. case XFS_IOC_ALLOCSP:
  627. case XFS_IOC_FREESP:
  628. case XFS_IOC_RESVSP:
  629. case XFS_IOC_UNRESVSP:
  630. case XFS_IOC_ALLOCSP64:
  631. case XFS_IOC_FREESP64:
  632. case XFS_IOC_RESVSP64:
  633. case XFS_IOC_UNRESVSP64:
  634. /*
  635. * Only allow the sys admin to reserve space unless
  636. * unwritten extents are enabled.
  637. */
  638. if (!XFS_SB_VERSION_HASEXTFLGBIT(&mp->m_sb) &&
  639. !capable(CAP_SYS_ADMIN))
  640. return -EPERM;
  641. return xfs_ioc_space(bdp, vp, filp, ioflags, cmd, arg);
  642. case XFS_IOC_DIOINFO: {
  643. struct dioattr da;
  644. xfs_buftarg_t *target =
  645. (ip->i_d.di_flags & XFS_DIFLAG_REALTIME) ?
  646. mp->m_rtdev_targp : mp->m_ddev_targp;
  647. da.d_mem = da.d_miniosz = 1 << target->pbr_sshift;
  648. /* The size dio will do in one go */
  649. da.d_maxiosz = 64 * PAGE_CACHE_SIZE;
  650. if (copy_to_user(arg, &da, sizeof(da)))
  651. return -XFS_ERROR(EFAULT);
  652. return 0;
  653. }
  654. case XFS_IOC_FSBULKSTAT_SINGLE:
  655. case XFS_IOC_FSBULKSTAT:
  656. case XFS_IOC_FSINUMBERS:
  657. return xfs_ioc_bulkstat(mp, cmd, arg);
  658. case XFS_IOC_FSGEOMETRY_V1:
  659. return xfs_ioc_fsgeometry_v1(mp, arg);
  660. case XFS_IOC_FSGEOMETRY:
  661. return xfs_ioc_fsgeometry(mp, arg);
  662. case XFS_IOC_GETVERSION:
  663. case XFS_IOC_GETXFLAGS:
  664. case XFS_IOC_SETXFLAGS:
  665. case XFS_IOC_FSGETXATTR:
  666. case XFS_IOC_FSSETXATTR:
  667. case XFS_IOC_FSGETXATTRA:
  668. return xfs_ioc_xattr(vp, ip, filp, cmd, arg);
  669. case XFS_IOC_FSSETDM: {
  670. struct fsdmidata dmi;
  671. if (copy_from_user(&dmi, arg, sizeof(dmi)))
  672. return -XFS_ERROR(EFAULT);
  673. error = xfs_set_dmattrs(bdp, dmi.fsd_dmevmask, dmi.fsd_dmstate,
  674. NULL);
  675. return -error;
  676. }
  677. case XFS_IOC_GETBMAP:
  678. case XFS_IOC_GETBMAPA:
  679. return xfs_ioc_getbmap(bdp, filp, ioflags, cmd, arg);
  680. case XFS_IOC_GETBMAPX:
  681. return xfs_ioc_getbmapx(bdp, arg);
  682. case XFS_IOC_FD_TO_HANDLE:
  683. case XFS_IOC_PATH_TO_HANDLE:
  684. case XFS_IOC_PATH_TO_FSHANDLE:
  685. return xfs_find_handle(cmd, arg);
  686. case XFS_IOC_OPEN_BY_HANDLE:
  687. return xfs_open_by_handle(mp, arg, filp, inode);
  688. case XFS_IOC_FSSETDM_BY_HANDLE:
  689. return xfs_fssetdm_by_handle(mp, arg, filp, inode);
  690. case XFS_IOC_READLINK_BY_HANDLE:
  691. return xfs_readlink_by_handle(mp, arg, filp, inode);
  692. case XFS_IOC_ATTRLIST_BY_HANDLE:
  693. return xfs_attrlist_by_handle(mp, arg, filp, inode);
  694. case XFS_IOC_ATTRMULTI_BY_HANDLE:
  695. return xfs_attrmulti_by_handle(mp, arg, filp, inode);
  696. case XFS_IOC_SWAPEXT: {
  697. error = xfs_swapext((struct xfs_swapext __user *)arg);
  698. return -error;
  699. }
  700. case XFS_IOC_FSCOUNTS: {
  701. xfs_fsop_counts_t out;
  702. error = xfs_fs_counts(mp, &out);
  703. if (error)
  704. return -error;
  705. if (copy_to_user(arg, &out, sizeof(out)))
  706. return -XFS_ERROR(EFAULT);
  707. return 0;
  708. }
  709. case XFS_IOC_SET_RESBLKS: {
  710. xfs_fsop_resblks_t inout;
  711. __uint64_t in;
  712. if (!capable(CAP_SYS_ADMIN))
  713. return -EPERM;
  714. if (copy_from_user(&inout, arg, sizeof(inout)))
  715. return -XFS_ERROR(EFAULT);
  716. /* input parameter is passed in resblks field of structure */
  717. in = inout.resblks;
  718. error = xfs_reserve_blocks(mp, &in, &inout);
  719. if (error)
  720. return -error;
  721. if (copy_to_user(arg, &inout, sizeof(inout)))
  722. return -XFS_ERROR(EFAULT);
  723. return 0;
  724. }
  725. case XFS_IOC_GET_RESBLKS: {
  726. xfs_fsop_resblks_t out;
  727. if (!capable(CAP_SYS_ADMIN))
  728. return -EPERM;
  729. error = xfs_reserve_blocks(mp, NULL, &out);
  730. if (error)
  731. return -error;
  732. if (copy_to_user(arg, &out, sizeof(out)))
  733. return -XFS_ERROR(EFAULT);
  734. return 0;
  735. }
  736. case XFS_IOC_FSGROWFSDATA: {
  737. xfs_growfs_data_t in;
  738. if (!capable(CAP_SYS_ADMIN))
  739. return -EPERM;
  740. if (copy_from_user(&in, arg, sizeof(in)))
  741. return -XFS_ERROR(EFAULT);
  742. error = xfs_growfs_data(mp, &in);
  743. return -error;
  744. }
  745. case XFS_IOC_FSGROWFSLOG: {
  746. xfs_growfs_log_t in;
  747. if (!capable(CAP_SYS_ADMIN))
  748. return -EPERM;
  749. if (copy_from_user(&in, arg, sizeof(in)))
  750. return -XFS_ERROR(EFAULT);
  751. error = xfs_growfs_log(mp, &in);
  752. return -error;
  753. }
  754. case XFS_IOC_FSGROWFSRT: {
  755. xfs_growfs_rt_t in;
  756. if (!capable(CAP_SYS_ADMIN))
  757. return -EPERM;
  758. if (copy_from_user(&in, arg, sizeof(in)))
  759. return -XFS_ERROR(EFAULT);
  760. error = xfs_growfs_rt(mp, &in);
  761. return -error;
  762. }
  763. case XFS_IOC_FREEZE:
  764. if (!capable(CAP_SYS_ADMIN))
  765. return -EPERM;
  766. if (inode->i_sb->s_frozen == SB_UNFROZEN)
  767. freeze_bdev(inode->i_sb->s_bdev);
  768. return 0;
  769. case XFS_IOC_THAW:
  770. if (!capable(CAP_SYS_ADMIN))
  771. return -EPERM;
  772. if (inode->i_sb->s_frozen != SB_UNFROZEN)
  773. thaw_bdev(inode->i_sb->s_bdev, inode->i_sb);
  774. return 0;
  775. case XFS_IOC_GOINGDOWN: {
  776. __uint32_t in;
  777. if (!capable(CAP_SYS_ADMIN))
  778. return -EPERM;
  779. if (get_user(in, (__uint32_t __user *)arg))
  780. return -XFS_ERROR(EFAULT);
  781. error = xfs_fs_goingdown(mp, in);
  782. return -error;
  783. }
  784. case XFS_IOC_ERROR_INJECTION: {
  785. xfs_error_injection_t in;
  786. if (!capable(CAP_SYS_ADMIN))
  787. return -EPERM;
  788. if (copy_from_user(&in, arg, sizeof(in)))
  789. return -XFS_ERROR(EFAULT);
  790. error = xfs_errortag_add(in.errtag, mp);
  791. return -error;
  792. }
  793. case XFS_IOC_ERROR_CLEARALL:
  794. if (!capable(CAP_SYS_ADMIN))
  795. return -EPERM;
  796. error = xfs_errortag_clearall(mp);
  797. return -error;
  798. default:
  799. return -ENOTTY;
  800. }
  801. }
  802. STATIC int
  803. xfs_ioc_space(
  804. bhv_desc_t *bdp,
  805. vnode_t *vp,
  806. struct file *filp,
  807. int ioflags,
  808. unsigned int cmd,
  809. void __user *arg)
  810. {
  811. xfs_flock64_t bf;
  812. int attr_flags = 0;
  813. int error;
  814. if (vp->v_inode.i_flags & (S_IMMUTABLE|S_APPEND))
  815. return -XFS_ERROR(EPERM);
  816. if (!(filp->f_flags & FMODE_WRITE))
  817. return -XFS_ERROR(EBADF);
  818. if (vp->v_type != VREG)
  819. return -XFS_ERROR(EINVAL);
  820. if (copy_from_user(&bf, arg, sizeof(bf)))
  821. return -XFS_ERROR(EFAULT);
  822. if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
  823. attr_flags |= ATTR_NONBLOCK;
  824. if (ioflags & IO_INVIS)
  825. attr_flags |= ATTR_DMI;
  826. error = xfs_change_file_space(bdp, cmd, &bf, filp->f_pos,
  827. NULL, attr_flags);
  828. return -error;
  829. }
  830. STATIC int
  831. xfs_ioc_bulkstat(
  832. xfs_mount_t *mp,
  833. unsigned int cmd,
  834. void __user *arg)
  835. {
  836. xfs_fsop_bulkreq_t bulkreq;
  837. int count; /* # of records returned */
  838. xfs_ino_t inlast; /* last inode number */
  839. int done;
  840. int error;
  841. /* done = 1 if there are more stats to get and if bulkstat */
  842. /* should be called again (unused here, but used in dmapi) */
  843. if (!capable(CAP_SYS_ADMIN))
  844. return -EPERM;
  845. if (XFS_FORCED_SHUTDOWN(mp))
  846. return -XFS_ERROR(EIO);
  847. if (copy_from_user(&bulkreq, arg, sizeof(xfs_fsop_bulkreq_t)))
  848. return -XFS_ERROR(EFAULT);
  849. if (copy_from_user(&inlast, bulkreq.lastip, sizeof(__s64)))
  850. return -XFS_ERROR(EFAULT);
  851. if ((count = bulkreq.icount) <= 0)
  852. return -XFS_ERROR(EINVAL);
  853. if (cmd == XFS_IOC_FSINUMBERS)
  854. error = xfs_inumbers(mp, &inlast, &count,
  855. bulkreq.ubuffer);
  856. else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE)
  857. error = xfs_bulkstat_single(mp, &inlast,
  858. bulkreq.ubuffer, &done);
  859. else { /* XFS_IOC_FSBULKSTAT */
  860. if (count == 1 && inlast != 0) {
  861. inlast++;
  862. error = xfs_bulkstat_single(mp, &inlast,
  863. bulkreq.ubuffer, &done);
  864. } else {
  865. error = xfs_bulkstat(mp, &inlast, &count,
  866. (bulkstat_one_pf)xfs_bulkstat_one, NULL,
  867. sizeof(xfs_bstat_t), bulkreq.ubuffer,
  868. BULKSTAT_FG_QUICK, &done);
  869. }
  870. }
  871. if (error)
  872. return -error;
  873. if (bulkreq.ocount != NULL) {
  874. if (copy_to_user(bulkreq.lastip, &inlast,
  875. sizeof(xfs_ino_t)))
  876. return -XFS_ERROR(EFAULT);
  877. if (copy_to_user(bulkreq.ocount, &count, sizeof(count)))
  878. return -XFS_ERROR(EFAULT);
  879. }
  880. return 0;
  881. }
  882. STATIC int
  883. xfs_ioc_fsgeometry_v1(
  884. xfs_mount_t *mp,
  885. void __user *arg)
  886. {
  887. xfs_fsop_geom_v1_t fsgeo;
  888. int error;
  889. error = xfs_fs_geometry(mp, (xfs_fsop_geom_t *)&fsgeo, 3);
  890. if (error)
  891. return -error;
  892. if (copy_to_user(arg, &fsgeo, sizeof(fsgeo)))
  893. return -XFS_ERROR(EFAULT);
  894. return 0;
  895. }
  896. STATIC int
  897. xfs_ioc_fsgeometry(
  898. xfs_mount_t *mp,
  899. void __user *arg)
  900. {
  901. xfs_fsop_geom_t fsgeo;
  902. int error;
  903. error = xfs_fs_geometry(mp, &fsgeo, 4);
  904. if (error)
  905. return -error;
  906. if (copy_to_user(arg, &fsgeo, sizeof(fsgeo)))
  907. return -XFS_ERROR(EFAULT);
  908. return 0;
  909. }
  910. /*
  911. * Linux extended inode flags interface.
  912. */
  913. #define LINUX_XFLAG_SYNC 0x00000008 /* Synchronous updates */
  914. #define LINUX_XFLAG_IMMUTABLE 0x00000010 /* Immutable file */
  915. #define LINUX_XFLAG_APPEND 0x00000020 /* writes to file may only append */
  916. #define LINUX_XFLAG_NODUMP 0x00000040 /* do not dump file */
  917. #define LINUX_XFLAG_NOATIME 0x00000080 /* do not update atime */
  918. STATIC unsigned int
  919. xfs_merge_ioc_xflags(
  920. unsigned int flags,
  921. unsigned int start)
  922. {
  923. unsigned int xflags = start;
  924. if (flags & LINUX_XFLAG_IMMUTABLE)
  925. xflags |= XFS_XFLAG_IMMUTABLE;
  926. else
  927. xflags &= ~XFS_XFLAG_IMMUTABLE;
  928. if (flags & LINUX_XFLAG_APPEND)
  929. xflags |= XFS_XFLAG_APPEND;
  930. else
  931. xflags &= ~XFS_XFLAG_APPEND;
  932. if (flags & LINUX_XFLAG_SYNC)
  933. xflags |= XFS_XFLAG_SYNC;
  934. else
  935. xflags &= ~XFS_XFLAG_SYNC;
  936. if (flags & LINUX_XFLAG_NOATIME)
  937. xflags |= XFS_XFLAG_NOATIME;
  938. else
  939. xflags &= ~XFS_XFLAG_NOATIME;
  940. if (flags & LINUX_XFLAG_NODUMP)
  941. xflags |= XFS_XFLAG_NODUMP;
  942. else
  943. xflags &= ~XFS_XFLAG_NODUMP;
  944. return xflags;
  945. }
  946. STATIC unsigned int
  947. xfs_di2lxflags(
  948. __uint16_t di_flags)
  949. {
  950. unsigned int flags = 0;
  951. if (di_flags & XFS_DIFLAG_IMMUTABLE)
  952. flags |= LINUX_XFLAG_IMMUTABLE;
  953. if (di_flags & XFS_DIFLAG_APPEND)
  954. flags |= LINUX_XFLAG_APPEND;
  955. if (di_flags & XFS_DIFLAG_SYNC)
  956. flags |= LINUX_XFLAG_SYNC;
  957. if (di_flags & XFS_DIFLAG_NOATIME)
  958. flags |= LINUX_XFLAG_NOATIME;
  959. if (di_flags & XFS_DIFLAG_NODUMP)
  960. flags |= LINUX_XFLAG_NODUMP;
  961. return flags;
  962. }
  963. STATIC int
  964. xfs_ioc_xattr(
  965. vnode_t *vp,
  966. xfs_inode_t *ip,
  967. struct file *filp,
  968. unsigned int cmd,
  969. void __user *arg)
  970. {
  971. struct fsxattr fa;
  972. vattr_t va;
  973. int error;
  974. int attr_flags;
  975. unsigned int flags;
  976. switch (cmd) {
  977. case XFS_IOC_FSGETXATTR: {
  978. va.va_mask = XFS_AT_XFLAGS|XFS_AT_EXTSIZE|XFS_AT_NEXTENTS;
  979. VOP_GETATTR(vp, &va, 0, NULL, error);
  980. if (error)
  981. return -error;
  982. fa.fsx_xflags = va.va_xflags;
  983. fa.fsx_extsize = va.va_extsize;
  984. fa.fsx_nextents = va.va_nextents;
  985. if (copy_to_user(arg, &fa, sizeof(fa)))
  986. return -XFS_ERROR(EFAULT);
  987. return 0;
  988. }
  989. case XFS_IOC_FSSETXATTR: {
  990. if (copy_from_user(&fa, arg, sizeof(fa)))
  991. return -XFS_ERROR(EFAULT);
  992. attr_flags = 0;
  993. if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
  994. attr_flags |= ATTR_NONBLOCK;
  995. va.va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE;
  996. va.va_xflags = fa.fsx_xflags;
  997. va.va_extsize = fa.fsx_extsize;
  998. VOP_SETATTR(vp, &va, attr_flags, NULL, error);
  999. if (!error)
  1000. vn_revalidate(vp); /* update Linux inode flags */
  1001. return -error;
  1002. }
  1003. case XFS_IOC_FSGETXATTRA: {
  1004. va.va_mask = XFS_AT_XFLAGS|XFS_AT_EXTSIZE|XFS_AT_ANEXTENTS;
  1005. VOP_GETATTR(vp, &va, 0, NULL, error);
  1006. if (error)
  1007. return -error;
  1008. fa.fsx_xflags = va.va_xflags;
  1009. fa.fsx_extsize = va.va_extsize;
  1010. fa.fsx_nextents = va.va_anextents;
  1011. if (copy_to_user(arg, &fa, sizeof(fa)))
  1012. return -XFS_ERROR(EFAULT);
  1013. return 0;
  1014. }
  1015. case XFS_IOC_GETXFLAGS: {
  1016. flags = xfs_di2lxflags(ip->i_d.di_flags);
  1017. if (copy_to_user(arg, &flags, sizeof(flags)))
  1018. return -XFS_ERROR(EFAULT);
  1019. return 0;
  1020. }
  1021. case XFS_IOC_SETXFLAGS: {
  1022. if (copy_from_user(&flags, arg, sizeof(flags)))
  1023. return -XFS_ERROR(EFAULT);
  1024. if (flags & ~(LINUX_XFLAG_IMMUTABLE | LINUX_XFLAG_APPEND | \
  1025. LINUX_XFLAG_NOATIME | LINUX_XFLAG_NODUMP | \
  1026. LINUX_XFLAG_SYNC))
  1027. return -XFS_ERROR(EOPNOTSUPP);
  1028. attr_flags = 0;
  1029. if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
  1030. attr_flags |= ATTR_NONBLOCK;
  1031. va.va_mask = XFS_AT_XFLAGS;
  1032. va.va_xflags = xfs_merge_ioc_xflags(flags,
  1033. xfs_ip2xflags(ip));
  1034. VOP_SETATTR(vp, &va, attr_flags, NULL, error);
  1035. if (!error)
  1036. vn_revalidate(vp); /* update Linux inode flags */
  1037. return -error;
  1038. }
  1039. case XFS_IOC_GETVERSION: {
  1040. flags = LINVFS_GET_IP(vp)->i_generation;
  1041. if (copy_to_user(arg, &flags, sizeof(flags)))
  1042. return -XFS_ERROR(EFAULT);
  1043. return 0;
  1044. }
  1045. default:
  1046. return -ENOTTY;
  1047. }
  1048. }
  1049. STATIC int
  1050. xfs_ioc_getbmap(
  1051. bhv_desc_t *bdp,
  1052. struct file *filp,
  1053. int ioflags,
  1054. unsigned int cmd,
  1055. void __user *arg)
  1056. {
  1057. struct getbmap bm;
  1058. int iflags;
  1059. int error;
  1060. if (copy_from_user(&bm, arg, sizeof(bm)))
  1061. return -XFS_ERROR(EFAULT);
  1062. if (bm.bmv_count < 2)
  1063. return -XFS_ERROR(EINVAL);
  1064. iflags = (cmd == XFS_IOC_GETBMAPA ? BMV_IF_ATTRFORK : 0);
  1065. if (ioflags & IO_INVIS)
  1066. iflags |= BMV_IF_NO_DMAPI_READ;
  1067. error = xfs_getbmap(bdp, &bm, (struct getbmap __user *)arg+1, iflags);
  1068. if (error)
  1069. return -error;
  1070. if (copy_to_user(arg, &bm, sizeof(bm)))
  1071. return -XFS_ERROR(EFAULT);
  1072. return 0;
  1073. }
  1074. STATIC int
  1075. xfs_ioc_getbmapx(
  1076. bhv_desc_t *bdp,
  1077. void __user *arg)
  1078. {
  1079. struct getbmapx bmx;
  1080. struct getbmap bm;
  1081. int iflags;
  1082. int error;
  1083. if (copy_from_user(&bmx, arg, sizeof(bmx)))
  1084. return -XFS_ERROR(EFAULT);
  1085. if (bmx.bmv_count < 2)
  1086. return -XFS_ERROR(EINVAL);
  1087. /*
  1088. * Map input getbmapx structure to a getbmap
  1089. * structure for xfs_getbmap.
  1090. */
  1091. GETBMAP_CONVERT(bmx, bm);
  1092. iflags = bmx.bmv_iflags;
  1093. if (iflags & (~BMV_IF_VALID))
  1094. return -XFS_ERROR(EINVAL);
  1095. iflags |= BMV_IF_EXTENDED;
  1096. error = xfs_getbmap(bdp, &bm, (struct getbmapx __user *)arg+1, iflags);
  1097. if (error)
  1098. return -error;
  1099. GETBMAP_CONVERT(bm, bmx);
  1100. if (copy_to_user(arg, &bmx, sizeof(bmx)))
  1101. return -XFS_ERROR(EFAULT);
  1102. return 0;
  1103. }