xfs_ioctl.c 28 KB

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