xfs_ioctl.c 28 KB

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