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