xfs_ioctl.c 28 KB

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