xfs_ioctl.c 28 KB

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