aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_ioctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_ioctl.c')
-rw-r--r--fs/xfs/xfs_ioctl.c266
1 files changed, 130 insertions, 136 deletions
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index 8bc1bbce7451..3799695b9249 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -207,7 +207,7 @@ xfs_open_by_handle(
207 struct path path; 207 struct path path;
208 208
209 if (!capable(CAP_SYS_ADMIN)) 209 if (!capable(CAP_SYS_ADMIN))
210 return -XFS_ERROR(EPERM); 210 return -EPERM;
211 211
212 dentry = xfs_handlereq_to_dentry(parfilp, hreq); 212 dentry = xfs_handlereq_to_dentry(parfilp, hreq);
213 if (IS_ERR(dentry)) 213 if (IS_ERR(dentry))
@@ -216,7 +216,7 @@ xfs_open_by_handle(
216 216
217 /* Restrict xfs_open_by_handle to directories & regular files. */ 217 /* Restrict xfs_open_by_handle to directories & regular files. */
218 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) { 218 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) {
219 error = -XFS_ERROR(EPERM); 219 error = -EPERM;
220 goto out_dput; 220 goto out_dput;
221 } 221 }
222 222
@@ -228,18 +228,18 @@ xfs_open_by_handle(
228 fmode = OPEN_FMODE(permflag); 228 fmode = OPEN_FMODE(permflag);
229 if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) && 229 if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) &&
230 (fmode & FMODE_WRITE) && IS_APPEND(inode)) { 230 (fmode & FMODE_WRITE) && IS_APPEND(inode)) {
231 error = -XFS_ERROR(EPERM); 231 error = -EPERM;
232 goto out_dput; 232 goto out_dput;
233 } 233 }
234 234
235 if ((fmode & FMODE_WRITE) && IS_IMMUTABLE(inode)) { 235 if ((fmode & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
236 error = -XFS_ERROR(EACCES); 236 error = -EACCES;
237 goto out_dput; 237 goto out_dput;
238 } 238 }
239 239
240 /* Can't write directories. */ 240 /* Can't write directories. */
241 if (S_ISDIR(inode->i_mode) && (fmode & FMODE_WRITE)) { 241 if (S_ISDIR(inode->i_mode) && (fmode & FMODE_WRITE)) {
242 error = -XFS_ERROR(EISDIR); 242 error = -EISDIR;
243 goto out_dput; 243 goto out_dput;
244 } 244 }
245 245
@@ -282,7 +282,7 @@ xfs_readlink_by_handle(
282 int error; 282 int error;
283 283
284 if (!capable(CAP_SYS_ADMIN)) 284 if (!capable(CAP_SYS_ADMIN))
285 return -XFS_ERROR(EPERM); 285 return -EPERM;
286 286
287 dentry = xfs_handlereq_to_dentry(parfilp, hreq); 287 dentry = xfs_handlereq_to_dentry(parfilp, hreq);
288 if (IS_ERR(dentry)) 288 if (IS_ERR(dentry))
@@ -290,22 +290,22 @@ xfs_readlink_by_handle(
290 290
291 /* Restrict this handle operation to symlinks only. */ 291 /* Restrict this handle operation to symlinks only. */
292 if (!S_ISLNK(dentry->d_inode->i_mode)) { 292 if (!S_ISLNK(dentry->d_inode->i_mode)) {
293 error = -XFS_ERROR(EINVAL); 293 error = -EINVAL;
294 goto out_dput; 294 goto out_dput;
295 } 295 }
296 296
297 if (copy_from_user(&olen, hreq->ohandlen, sizeof(__u32))) { 297 if (copy_from_user(&olen, hreq->ohandlen, sizeof(__u32))) {
298 error = -XFS_ERROR(EFAULT); 298 error = -EFAULT;
299 goto out_dput; 299 goto out_dput;
300 } 300 }
301 301
302 link = kmalloc(MAXPATHLEN+1, GFP_KERNEL); 302 link = kmalloc(MAXPATHLEN+1, GFP_KERNEL);
303 if (!link) { 303 if (!link) {
304 error = -XFS_ERROR(ENOMEM); 304 error = -ENOMEM;
305 goto out_dput; 305 goto out_dput;
306 } 306 }
307 307
308 error = -xfs_readlink(XFS_I(dentry->d_inode), link); 308 error = xfs_readlink(XFS_I(dentry->d_inode), link);
309 if (error) 309 if (error)
310 goto out_kfree; 310 goto out_kfree;
311 error = readlink_copy(hreq->ohandle, olen, link); 311 error = readlink_copy(hreq->ohandle, olen, link);
@@ -330,10 +330,10 @@ xfs_set_dmattrs(
330 int error; 330 int error;
331 331
332 if (!capable(CAP_SYS_ADMIN)) 332 if (!capable(CAP_SYS_ADMIN))
333 return XFS_ERROR(EPERM); 333 return -EPERM;
334 334
335 if (XFS_FORCED_SHUTDOWN(mp)) 335 if (XFS_FORCED_SHUTDOWN(mp))
336 return XFS_ERROR(EIO); 336 return -EIO;
337 337
338 tp = xfs_trans_alloc(mp, XFS_TRANS_SET_DMATTRS); 338 tp = xfs_trans_alloc(mp, XFS_TRANS_SET_DMATTRS);
339 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_ichange, 0, 0); 339 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_ichange, 0, 0);
@@ -364,9 +364,9 @@ xfs_fssetdm_by_handle(
364 struct dentry *dentry; 364 struct dentry *dentry;
365 365
366 if (!capable(CAP_MKNOD)) 366 if (!capable(CAP_MKNOD))
367 return -XFS_ERROR(EPERM); 367 return -EPERM;
368 if (copy_from_user(&dmhreq, arg, sizeof(xfs_fsop_setdm_handlereq_t))) 368 if (copy_from_user(&dmhreq, arg, sizeof(xfs_fsop_setdm_handlereq_t)))
369 return -XFS_ERROR(EFAULT); 369 return -EFAULT;
370 370
371 error = mnt_want_write_file(parfilp); 371 error = mnt_want_write_file(parfilp);
372 if (error) 372 if (error)
@@ -379,16 +379,16 @@ xfs_fssetdm_by_handle(
379 } 379 }
380 380
381 if (IS_IMMUTABLE(dentry->d_inode) || IS_APPEND(dentry->d_inode)) { 381 if (IS_IMMUTABLE(dentry->d_inode) || IS_APPEND(dentry->d_inode)) {
382 error = -XFS_ERROR(EPERM); 382 error = -EPERM;
383 goto out; 383 goto out;
384 } 384 }
385 385
386 if (copy_from_user(&fsd, dmhreq.data, sizeof(fsd))) { 386 if (copy_from_user(&fsd, dmhreq.data, sizeof(fsd))) {
387 error = -XFS_ERROR(EFAULT); 387 error = -EFAULT;
388 goto out; 388 goto out;
389 } 389 }
390 390
391 error = -xfs_set_dmattrs(XFS_I(dentry->d_inode), fsd.fsd_dmevmask, 391 error = xfs_set_dmattrs(XFS_I(dentry->d_inode), fsd.fsd_dmevmask,
392 fsd.fsd_dmstate); 392 fsd.fsd_dmstate);
393 393
394 out: 394 out:
@@ -409,18 +409,18 @@ xfs_attrlist_by_handle(
409 char *kbuf; 409 char *kbuf;
410 410
411 if (!capable(CAP_SYS_ADMIN)) 411 if (!capable(CAP_SYS_ADMIN))
412 return -XFS_ERROR(EPERM); 412 return -EPERM;
413 if (copy_from_user(&al_hreq, arg, sizeof(xfs_fsop_attrlist_handlereq_t))) 413 if (copy_from_user(&al_hreq, arg, sizeof(xfs_fsop_attrlist_handlereq_t)))
414 return -XFS_ERROR(EFAULT); 414 return -EFAULT;
415 if (al_hreq.buflen < sizeof(struct attrlist) || 415 if (al_hreq.buflen < sizeof(struct attrlist) ||
416 al_hreq.buflen > XATTR_LIST_MAX) 416 al_hreq.buflen > XATTR_LIST_MAX)
417 return -XFS_ERROR(EINVAL); 417 return -EINVAL;
418 418
419 /* 419 /*
420 * Reject flags, only allow namespaces. 420 * Reject flags, only allow namespaces.
421 */ 421 */
422 if (al_hreq.flags & ~(ATTR_ROOT | ATTR_SECURE)) 422 if (al_hreq.flags & ~(ATTR_ROOT | ATTR_SECURE))
423 return -XFS_ERROR(EINVAL); 423 return -EINVAL;
424 424
425 dentry = xfs_handlereq_to_dentry(parfilp, &al_hreq.hreq); 425 dentry = xfs_handlereq_to_dentry(parfilp, &al_hreq.hreq);
426 if (IS_ERR(dentry)) 426 if (IS_ERR(dentry))
@@ -431,7 +431,7 @@ xfs_attrlist_by_handle(
431 goto out_dput; 431 goto out_dput;
432 432
433 cursor = (attrlist_cursor_kern_t *)&al_hreq.pos; 433 cursor = (attrlist_cursor_kern_t *)&al_hreq.pos;
434 error = -xfs_attr_list(XFS_I(dentry->d_inode), kbuf, al_hreq.buflen, 434 error = xfs_attr_list(XFS_I(dentry->d_inode), kbuf, al_hreq.buflen,
435 al_hreq.flags, cursor); 435 al_hreq.flags, cursor);
436 if (error) 436 if (error)
437 goto out_kfree; 437 goto out_kfree;
@@ -455,20 +455,20 @@ xfs_attrmulti_attr_get(
455 __uint32_t flags) 455 __uint32_t flags)
456{ 456{
457 unsigned char *kbuf; 457 unsigned char *kbuf;
458 int error = EFAULT; 458 int error = -EFAULT;
459 459
460 if (*len > XATTR_SIZE_MAX) 460 if (*len > XATTR_SIZE_MAX)
461 return EINVAL; 461 return -EINVAL;
462 kbuf = kmem_zalloc_large(*len, KM_SLEEP); 462 kbuf = kmem_zalloc_large(*len, KM_SLEEP);
463 if (!kbuf) 463 if (!kbuf)
464 return ENOMEM; 464 return -ENOMEM;
465 465
466 error = xfs_attr_get(XFS_I(inode), name, kbuf, (int *)len, flags); 466 error = xfs_attr_get(XFS_I(inode), name, kbuf, (int *)len, flags);
467 if (error) 467 if (error)
468 goto out_kfree; 468 goto out_kfree;
469 469
470 if (copy_to_user(ubuf, kbuf, *len)) 470 if (copy_to_user(ubuf, kbuf, *len))
471 error = EFAULT; 471 error = -EFAULT;
472 472
473out_kfree: 473out_kfree:
474 kmem_free(kbuf); 474 kmem_free(kbuf);
@@ -484,20 +484,17 @@ xfs_attrmulti_attr_set(
484 __uint32_t flags) 484 __uint32_t flags)
485{ 485{
486 unsigned char *kbuf; 486 unsigned char *kbuf;
487 int error = EFAULT;
488 487
489 if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) 488 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
490 return EPERM; 489 return -EPERM;
491 if (len > XATTR_SIZE_MAX) 490 if (len > XATTR_SIZE_MAX)
492 return EINVAL; 491 return -EINVAL;
493 492
494 kbuf = memdup_user(ubuf, len); 493 kbuf = memdup_user(ubuf, len);
495 if (IS_ERR(kbuf)) 494 if (IS_ERR(kbuf))
496 return PTR_ERR(kbuf); 495 return PTR_ERR(kbuf);
497 496
498 error = xfs_attr_set(XFS_I(inode), name, kbuf, len, flags); 497 return xfs_attr_set(XFS_I(inode), name, kbuf, len, flags);
499
500 return error;
501} 498}
502 499
503int 500int
@@ -507,7 +504,7 @@ xfs_attrmulti_attr_remove(
507 __uint32_t flags) 504 __uint32_t flags)
508{ 505{
509 if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) 506 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
510 return EPERM; 507 return -EPERM;
511 return xfs_attr_remove(XFS_I(inode), name, flags); 508 return xfs_attr_remove(XFS_I(inode), name, flags);
512} 509}
513 510
@@ -524,9 +521,9 @@ xfs_attrmulti_by_handle(
524 unsigned char *attr_name; 521 unsigned char *attr_name;
525 522
526 if (!capable(CAP_SYS_ADMIN)) 523 if (!capable(CAP_SYS_ADMIN))
527 return -XFS_ERROR(EPERM); 524 return -EPERM;
528 if (copy_from_user(&am_hreq, arg, sizeof(xfs_fsop_attrmulti_handlereq_t))) 525 if (copy_from_user(&am_hreq, arg, sizeof(xfs_fsop_attrmulti_handlereq_t)))
529 return -XFS_ERROR(EFAULT); 526 return -EFAULT;
530 527
531 /* overflow check */ 528 /* overflow check */
532 if (am_hreq.opcount >= INT_MAX / sizeof(xfs_attr_multiop_t)) 529 if (am_hreq.opcount >= INT_MAX / sizeof(xfs_attr_multiop_t))
@@ -536,18 +533,18 @@ xfs_attrmulti_by_handle(
536 if (IS_ERR(dentry)) 533 if (IS_ERR(dentry))
537 return PTR_ERR(dentry); 534 return PTR_ERR(dentry);
538 535
539 error = E2BIG; 536 error = -E2BIG;
540 size = am_hreq.opcount * sizeof(xfs_attr_multiop_t); 537 size = am_hreq.opcount * sizeof(xfs_attr_multiop_t);
541 if (!size || size > 16 * PAGE_SIZE) 538 if (!size || size > 16 * PAGE_SIZE)
542 goto out_dput; 539 goto out_dput;
543 540
544 ops = memdup_user(am_hreq.ops, size); 541 ops = memdup_user(am_hreq.ops, size);
545 if (IS_ERR(ops)) { 542 if (IS_ERR(ops)) {
546 error = -PTR_ERR(ops); 543 error = PTR_ERR(ops);
547 goto out_dput; 544 goto out_dput;
548 } 545 }
549 546
550 error = ENOMEM; 547 error = -ENOMEM;
551 attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL); 548 attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL);
552 if (!attr_name) 549 if (!attr_name)
553 goto out_kfree_ops; 550 goto out_kfree_ops;
@@ -557,7 +554,7 @@ xfs_attrmulti_by_handle(
557 ops[i].am_error = strncpy_from_user((char *)attr_name, 554 ops[i].am_error = strncpy_from_user((char *)attr_name,
558 ops[i].am_attrname, MAXNAMELEN); 555 ops[i].am_attrname, MAXNAMELEN);
559 if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN) 556 if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN)
560 error = ERANGE; 557 error = -ERANGE;
561 if (ops[i].am_error < 0) 558 if (ops[i].am_error < 0)
562 break; 559 break;
563 560
@@ -588,19 +585,19 @@ xfs_attrmulti_by_handle(
588 mnt_drop_write_file(parfilp); 585 mnt_drop_write_file(parfilp);
589 break; 586 break;
590 default: 587 default:
591 ops[i].am_error = EINVAL; 588 ops[i].am_error = -EINVAL;
592 } 589 }
593 } 590 }
594 591
595 if (copy_to_user(am_hreq.ops, ops, size)) 592 if (copy_to_user(am_hreq.ops, ops, size))
596 error = XFS_ERROR(EFAULT); 593 error = -EFAULT;
597 594
598 kfree(attr_name); 595 kfree(attr_name);
599 out_kfree_ops: 596 out_kfree_ops:
600 kfree(ops); 597 kfree(ops);
601 out_dput: 598 out_dput:
602 dput(dentry); 599 dput(dentry);
603 return -error; 600 return error;
604} 601}
605 602
606int 603int
@@ -625,16 +622,16 @@ xfs_ioc_space(
625 */ 622 */
626 if (!xfs_sb_version_hasextflgbit(&ip->i_mount->m_sb) && 623 if (!xfs_sb_version_hasextflgbit(&ip->i_mount->m_sb) &&
627 !capable(CAP_SYS_ADMIN)) 624 !capable(CAP_SYS_ADMIN))
628 return -XFS_ERROR(EPERM); 625 return -EPERM;
629 626
630 if (inode->i_flags & (S_IMMUTABLE|S_APPEND)) 627 if (inode->i_flags & (S_IMMUTABLE|S_APPEND))
631 return -XFS_ERROR(EPERM); 628 return -EPERM;
632 629
633 if (!(filp->f_mode & FMODE_WRITE)) 630 if (!(filp->f_mode & FMODE_WRITE))
634 return -XFS_ERROR(EBADF); 631 return -EBADF;
635 632
636 if (!S_ISREG(inode->i_mode)) 633 if (!S_ISREG(inode->i_mode))
637 return -XFS_ERROR(EINVAL); 634 return -EINVAL;
638 635
639 error = mnt_want_write_file(filp); 636 error = mnt_want_write_file(filp);
640 if (error) 637 if (error)
@@ -652,7 +649,7 @@ xfs_ioc_space(
652 bf->l_start += XFS_ISIZE(ip); 649 bf->l_start += XFS_ISIZE(ip);
653 break; 650 break;
654 default: 651 default:
655 error = XFS_ERROR(EINVAL); 652 error = -EINVAL;
656 goto out_unlock; 653 goto out_unlock;
657 } 654 }
658 655
@@ -669,7 +666,7 @@ xfs_ioc_space(
669 case XFS_IOC_UNRESVSP: 666 case XFS_IOC_UNRESVSP:
670 case XFS_IOC_UNRESVSP64: 667 case XFS_IOC_UNRESVSP64:
671 if (bf->l_len <= 0) { 668 if (bf->l_len <= 0) {
672 error = XFS_ERROR(EINVAL); 669 error = -EINVAL;
673 goto out_unlock; 670 goto out_unlock;
674 } 671 }
675 break; 672 break;
@@ -682,7 +679,7 @@ xfs_ioc_space(
682 bf->l_start > mp->m_super->s_maxbytes || 679 bf->l_start > mp->m_super->s_maxbytes ||
683 bf->l_start + bf->l_len < 0 || 680 bf->l_start + bf->l_len < 0 ||
684 bf->l_start + bf->l_len >= mp->m_super->s_maxbytes) { 681 bf->l_start + bf->l_len >= mp->m_super->s_maxbytes) {
685 error = XFS_ERROR(EINVAL); 682 error = -EINVAL;
686 goto out_unlock; 683 goto out_unlock;
687 } 684 }
688 685
@@ -723,7 +720,7 @@ xfs_ioc_space(
723 break; 720 break;
724 default: 721 default:
725 ASSERT(0); 722 ASSERT(0);
726 error = XFS_ERROR(EINVAL); 723 error = -EINVAL;
727 } 724 }
728 725
729 if (error) 726 if (error)
@@ -739,7 +736,7 @@ xfs_ioc_space(
739 xfs_ilock(ip, XFS_ILOCK_EXCL); 736 xfs_ilock(ip, XFS_ILOCK_EXCL);
740 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); 737 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
741 738
742 if (!(ioflags & IO_INVIS)) { 739 if (!(ioflags & XFS_IO_INVIS)) {
743 ip->i_d.di_mode &= ~S_ISUID; 740 ip->i_d.di_mode &= ~S_ISUID;
744 if (ip->i_d.di_mode & S_IXGRP) 741 if (ip->i_d.di_mode & S_IXGRP)
745 ip->i_d.di_mode &= ~S_ISGID; 742 ip->i_d.di_mode &= ~S_ISGID;
@@ -759,7 +756,7 @@ xfs_ioc_space(
759out_unlock: 756out_unlock:
760 xfs_iunlock(ip, XFS_IOLOCK_EXCL); 757 xfs_iunlock(ip, XFS_IOLOCK_EXCL);
761 mnt_drop_write_file(filp); 758 mnt_drop_write_file(filp);
762 return -error; 759 return error;
763} 760}
764 761
765STATIC int 762STATIC int
@@ -781,41 +778,41 @@ xfs_ioc_bulkstat(
781 return -EPERM; 778 return -EPERM;
782 779
783 if (XFS_FORCED_SHUTDOWN(mp)) 780 if (XFS_FORCED_SHUTDOWN(mp))
784 return -XFS_ERROR(EIO); 781 return -EIO;
785 782
786 if (copy_from_user(&bulkreq, arg, sizeof(xfs_fsop_bulkreq_t))) 783 if (copy_from_user(&bulkreq, arg, sizeof(xfs_fsop_bulkreq_t)))
787 return -XFS_ERROR(EFAULT); 784 return -EFAULT;
788 785
789 if (copy_from_user(&inlast, bulkreq.lastip, sizeof(__s64))) 786 if (copy_from_user(&inlast, bulkreq.lastip, sizeof(__s64)))
790 return -XFS_ERROR(EFAULT); 787 return -EFAULT;
791 788
792 if ((count = bulkreq.icount) <= 0) 789 if ((count = bulkreq.icount) <= 0)
793 return -XFS_ERROR(EINVAL); 790 return -EINVAL;
794 791
795 if (bulkreq.ubuffer == NULL) 792 if (bulkreq.ubuffer == NULL)
796 return -XFS_ERROR(EINVAL); 793 return -EINVAL;
797 794
798 if (cmd == XFS_IOC_FSINUMBERS) 795 if (cmd == XFS_IOC_FSINUMBERS)
799 error = xfs_inumbers(mp, &inlast, &count, 796 error = xfs_inumbers(mp, &inlast, &count,
800 bulkreq.ubuffer, xfs_inumbers_fmt); 797 bulkreq.ubuffer, xfs_inumbers_fmt);
801 else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE) 798 else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE)
802 error = xfs_bulkstat_single(mp, &inlast, 799 error = xfs_bulkstat_one(mp, inlast, bulkreq.ubuffer,
803 bulkreq.ubuffer, &done); 800 sizeof(xfs_bstat_t), NULL, &done);
804 else /* XFS_IOC_FSBULKSTAT */ 801 else /* XFS_IOC_FSBULKSTAT */
805 error = xfs_bulkstat(mp, &inlast, &count, xfs_bulkstat_one, 802 error = xfs_bulkstat(mp, &inlast, &count, xfs_bulkstat_one,
806 sizeof(xfs_bstat_t), bulkreq.ubuffer, 803 sizeof(xfs_bstat_t), bulkreq.ubuffer,
807 &done); 804 &done);
808 805
809 if (error) 806 if (error)
810 return -error; 807 return error;
811 808
812 if (bulkreq.ocount != NULL) { 809 if (bulkreq.ocount != NULL) {
813 if (copy_to_user(bulkreq.lastip, &inlast, 810 if (copy_to_user(bulkreq.lastip, &inlast,
814 sizeof(xfs_ino_t))) 811 sizeof(xfs_ino_t)))
815 return -XFS_ERROR(EFAULT); 812 return -EFAULT;
816 813
817 if (copy_to_user(bulkreq.ocount, &count, sizeof(count))) 814 if (copy_to_user(bulkreq.ocount, &count, sizeof(count)))
818 return -XFS_ERROR(EFAULT); 815 return -EFAULT;
819 } 816 }
820 817
821 return 0; 818 return 0;
@@ -831,7 +828,7 @@ xfs_ioc_fsgeometry_v1(
831 828
832 error = xfs_fs_geometry(mp, &fsgeo, 3); 829 error = xfs_fs_geometry(mp, &fsgeo, 3);
833 if (error) 830 if (error)
834 return -error; 831 return error;
835 832
836 /* 833 /*
837 * Caller should have passed an argument of type 834 * Caller should have passed an argument of type
@@ -839,7 +836,7 @@ xfs_ioc_fsgeometry_v1(
839 * xfs_fsop_geom_t that xfs_fs_geometry() fills in. 836 * xfs_fsop_geom_t that xfs_fs_geometry() fills in.
840 */ 837 */
841 if (copy_to_user(arg, &fsgeo, sizeof(xfs_fsop_geom_v1_t))) 838 if (copy_to_user(arg, &fsgeo, sizeof(xfs_fsop_geom_v1_t)))
842 return -XFS_ERROR(EFAULT); 839 return -EFAULT;
843 return 0; 840 return 0;
844} 841}
845 842
@@ -853,10 +850,10 @@ xfs_ioc_fsgeometry(
853 850
854 error = xfs_fs_geometry(mp, &fsgeo, 4); 851 error = xfs_fs_geometry(mp, &fsgeo, 4);
855 if (error) 852 if (error)
856 return -error; 853 return error;
857 854
858 if (copy_to_user(arg, &fsgeo, sizeof(fsgeo))) 855 if (copy_to_user(arg, &fsgeo, sizeof(fsgeo)))
859 return -XFS_ERROR(EFAULT); 856 return -EFAULT;
860 return 0; 857 return 0;
861} 858}
862 859
@@ -1041,16 +1038,16 @@ xfs_ioctl_setattr(
1041 trace_xfs_ioctl_setattr(ip); 1038 trace_xfs_ioctl_setattr(ip);
1042 1039
1043 if (mp->m_flags & XFS_MOUNT_RDONLY) 1040 if (mp->m_flags & XFS_MOUNT_RDONLY)
1044 return XFS_ERROR(EROFS); 1041 return -EROFS;
1045 if (XFS_FORCED_SHUTDOWN(mp)) 1042 if (XFS_FORCED_SHUTDOWN(mp))
1046 return XFS_ERROR(EIO); 1043 return -EIO;
1047 1044
1048 /* 1045 /*
1049 * Disallow 32bit project ids when projid32bit feature is not enabled. 1046 * Disallow 32bit project ids when projid32bit feature is not enabled.
1050 */ 1047 */
1051 if ((mask & FSX_PROJID) && (fa->fsx_projid > (__uint16_t)-1) && 1048 if ((mask & FSX_PROJID) && (fa->fsx_projid > (__uint16_t)-1) &&
1052 !xfs_sb_version_hasprojid32bit(&ip->i_mount->m_sb)) 1049 !xfs_sb_version_hasprojid32bit(&ip->i_mount->m_sb))
1053 return XFS_ERROR(EINVAL); 1050 return -EINVAL;
1054 1051
1055 /* 1052 /*
1056 * If disk quotas is on, we make sure that the dquots do exist on disk, 1053 * If disk quotas is on, we make sure that the dquots do exist on disk,
@@ -1088,7 +1085,7 @@ xfs_ioctl_setattr(
1088 * CAP_FSETID capability is applicable. 1085 * CAP_FSETID capability is applicable.
1089 */ 1086 */
1090 if (!inode_owner_or_capable(VFS_I(ip))) { 1087 if (!inode_owner_or_capable(VFS_I(ip))) {
1091 code = XFS_ERROR(EPERM); 1088 code = -EPERM;
1092 goto error_return; 1089 goto error_return;
1093 } 1090 }
1094 1091
@@ -1099,7 +1096,7 @@ xfs_ioctl_setattr(
1099 */ 1096 */
1100 if (mask & FSX_PROJID) { 1097 if (mask & FSX_PROJID) {
1101 if (current_user_ns() != &init_user_ns) { 1098 if (current_user_ns() != &init_user_ns) {
1102 code = XFS_ERROR(EINVAL); 1099 code = -EINVAL;
1103 goto error_return; 1100 goto error_return;
1104 } 1101 }
1105 1102
@@ -1122,7 +1119,7 @@ xfs_ioctl_setattr(
1122 if (ip->i_d.di_nextents && 1119 if (ip->i_d.di_nextents &&
1123 ((ip->i_d.di_extsize << mp->m_sb.sb_blocklog) != 1120 ((ip->i_d.di_extsize << mp->m_sb.sb_blocklog) !=
1124 fa->fsx_extsize)) { 1121 fa->fsx_extsize)) {
1125 code = XFS_ERROR(EINVAL); /* EFBIG? */ 1122 code = -EINVAL; /* EFBIG? */
1126 goto error_return; 1123 goto error_return;
1127 } 1124 }
1128 1125
@@ -1141,7 +1138,7 @@ xfs_ioctl_setattr(
1141 1138
1142 extsize_fsb = XFS_B_TO_FSB(mp, fa->fsx_extsize); 1139 extsize_fsb = XFS_B_TO_FSB(mp, fa->fsx_extsize);
1143 if (extsize_fsb > MAXEXTLEN) { 1140 if (extsize_fsb > MAXEXTLEN) {
1144 code = XFS_ERROR(EINVAL); 1141 code = -EINVAL;
1145 goto error_return; 1142 goto error_return;
1146 } 1143 }
1147 1144
@@ -1153,13 +1150,13 @@ xfs_ioctl_setattr(
1153 } else { 1150 } else {
1154 size = mp->m_sb.sb_blocksize; 1151 size = mp->m_sb.sb_blocksize;
1155 if (extsize_fsb > mp->m_sb.sb_agblocks / 2) { 1152 if (extsize_fsb > mp->m_sb.sb_agblocks / 2) {
1156 code = XFS_ERROR(EINVAL); 1153 code = -EINVAL;
1157 goto error_return; 1154 goto error_return;
1158 } 1155 }
1159 } 1156 }
1160 1157
1161 if (fa->fsx_extsize % size) { 1158 if (fa->fsx_extsize % size) {
1162 code = XFS_ERROR(EINVAL); 1159 code = -EINVAL;
1163 goto error_return; 1160 goto error_return;
1164 } 1161 }
1165 } 1162 }
@@ -1173,7 +1170,7 @@ xfs_ioctl_setattr(
1173 if ((ip->i_d.di_nextents || ip->i_delayed_blks) && 1170 if ((ip->i_d.di_nextents || ip->i_delayed_blks) &&
1174 (XFS_IS_REALTIME_INODE(ip)) != 1171 (XFS_IS_REALTIME_INODE(ip)) !=
1175 (fa->fsx_xflags & XFS_XFLAG_REALTIME)) { 1172 (fa->fsx_xflags & XFS_XFLAG_REALTIME)) {
1176 code = XFS_ERROR(EINVAL); /* EFBIG? */ 1173 code = -EINVAL; /* EFBIG? */
1177 goto error_return; 1174 goto error_return;
1178 } 1175 }
1179 1176
@@ -1184,7 +1181,7 @@ xfs_ioctl_setattr(
1184 if ((mp->m_sb.sb_rblocks == 0) || 1181 if ((mp->m_sb.sb_rblocks == 0) ||
1185 (mp->m_sb.sb_rextsize == 0) || 1182 (mp->m_sb.sb_rextsize == 0) ||
1186 (ip->i_d.di_extsize % mp->m_sb.sb_rextsize)) { 1183 (ip->i_d.di_extsize % mp->m_sb.sb_rextsize)) {
1187 code = XFS_ERROR(EINVAL); 1184 code = -EINVAL;
1188 goto error_return; 1185 goto error_return;
1189 } 1186 }
1190 } 1187 }
@@ -1198,7 +1195,7 @@ xfs_ioctl_setattr(
1198 (fa->fsx_xflags & 1195 (fa->fsx_xflags &
1199 (XFS_XFLAG_IMMUTABLE | XFS_XFLAG_APPEND))) && 1196 (XFS_XFLAG_IMMUTABLE | XFS_XFLAG_APPEND))) &&
1200 !capable(CAP_LINUX_IMMUTABLE)) { 1197 !capable(CAP_LINUX_IMMUTABLE)) {
1201 code = XFS_ERROR(EPERM); 1198 code = -EPERM;
1202 goto error_return; 1199 goto error_return;
1203 } 1200 }
1204 } 1201 }
@@ -1301,7 +1298,7 @@ xfs_ioc_fssetxattr(
1301 return error; 1298 return error;
1302 error = xfs_ioctl_setattr(ip, &fa, mask); 1299 error = xfs_ioctl_setattr(ip, &fa, mask);
1303 mnt_drop_write_file(filp); 1300 mnt_drop_write_file(filp);
1304 return -error; 1301 return error;
1305} 1302}
1306 1303
1307STATIC int 1304STATIC int
@@ -1346,7 +1343,7 @@ xfs_ioc_setxflags(
1346 return error; 1343 return error;
1347 error = xfs_ioctl_setattr(ip, &fa, mask); 1344 error = xfs_ioctl_setattr(ip, &fa, mask);
1348 mnt_drop_write_file(filp); 1345 mnt_drop_write_file(filp);
1349 return -error; 1346 return error;
1350} 1347}
1351 1348
1352STATIC int 1349STATIC int
@@ -1356,7 +1353,7 @@ xfs_getbmap_format(void **ap, struct getbmapx *bmv, int *full)
1356 1353
1357 /* copy only getbmap portion (not getbmapx) */ 1354 /* copy only getbmap portion (not getbmapx) */
1358 if (copy_to_user(base, bmv, sizeof(struct getbmap))) 1355 if (copy_to_user(base, bmv, sizeof(struct getbmap)))
1359 return XFS_ERROR(EFAULT); 1356 return -EFAULT;
1360 1357
1361 *ap += sizeof(struct getbmap); 1358 *ap += sizeof(struct getbmap);
1362 return 0; 1359 return 0;
@@ -1373,23 +1370,23 @@ xfs_ioc_getbmap(
1373 int error; 1370 int error;
1374 1371
1375 if (copy_from_user(&bmx, arg, sizeof(struct getbmapx))) 1372 if (copy_from_user(&bmx, arg, sizeof(struct getbmapx)))
1376 return -XFS_ERROR(EFAULT); 1373 return -EFAULT;
1377 1374
1378 if (bmx.bmv_count < 2) 1375 if (bmx.bmv_count < 2)
1379 return -XFS_ERROR(EINVAL); 1376 return -EINVAL;
1380 1377
1381 bmx.bmv_iflags = (cmd == XFS_IOC_GETBMAPA ? BMV_IF_ATTRFORK : 0); 1378 bmx.bmv_iflags = (cmd == XFS_IOC_GETBMAPA ? BMV_IF_ATTRFORK : 0);
1382 if (ioflags & IO_INVIS) 1379 if (ioflags & XFS_IO_INVIS)
1383 bmx.bmv_iflags |= BMV_IF_NO_DMAPI_READ; 1380 bmx.bmv_iflags |= BMV_IF_NO_DMAPI_READ;
1384 1381
1385 error = xfs_getbmap(ip, &bmx, xfs_getbmap_format, 1382 error = xfs_getbmap(ip, &bmx, xfs_getbmap_format,
1386 (struct getbmap *)arg+1); 1383 (struct getbmap *)arg+1);
1387 if (error) 1384 if (error)
1388 return -error; 1385 return error;
1389 1386
1390 /* copy back header - only size of getbmap */ 1387 /* copy back header - only size of getbmap */
1391 if (copy_to_user(arg, &bmx, sizeof(struct getbmap))) 1388 if (copy_to_user(arg, &bmx, sizeof(struct getbmap)))
1392 return -XFS_ERROR(EFAULT); 1389 return -EFAULT;
1393 return 0; 1390 return 0;
1394} 1391}
1395 1392
@@ -1399,7 +1396,7 @@ xfs_getbmapx_format(void **ap, struct getbmapx *bmv, int *full)
1399 struct getbmapx __user *base = *ap; 1396 struct getbmapx __user *base = *ap;
1400 1397
1401 if (copy_to_user(base, bmv, sizeof(struct getbmapx))) 1398 if (copy_to_user(base, bmv, sizeof(struct getbmapx)))
1402 return XFS_ERROR(EFAULT); 1399 return -EFAULT;
1403 1400
1404 *ap += sizeof(struct getbmapx); 1401 *ap += sizeof(struct getbmapx);
1405 return 0; 1402 return 0;
@@ -1414,22 +1411,22 @@ xfs_ioc_getbmapx(
1414 int error; 1411 int error;
1415 1412
1416 if (copy_from_user(&bmx, arg, sizeof(bmx))) 1413 if (copy_from_user(&bmx, arg, sizeof(bmx)))
1417 return -XFS_ERROR(EFAULT); 1414 return -EFAULT;
1418 1415
1419 if (bmx.bmv_count < 2) 1416 if (bmx.bmv_count < 2)
1420 return -XFS_ERROR(EINVAL); 1417 return -EINVAL;
1421 1418
1422 if (bmx.bmv_iflags & (~BMV_IF_VALID)) 1419 if (bmx.bmv_iflags & (~BMV_IF_VALID))
1423 return -XFS_ERROR(EINVAL); 1420 return -EINVAL;
1424 1421
1425 error = xfs_getbmap(ip, &bmx, xfs_getbmapx_format, 1422 error = xfs_getbmap(ip, &bmx, xfs_getbmapx_format,
1426 (struct getbmapx *)arg+1); 1423 (struct getbmapx *)arg+1);
1427 if (error) 1424 if (error)
1428 return -error; 1425 return error;
1429 1426
1430 /* copy back header */ 1427 /* copy back header */
1431 if (copy_to_user(arg, &bmx, sizeof(struct getbmapx))) 1428 if (copy_to_user(arg, &bmx, sizeof(struct getbmapx)))
1432 return -XFS_ERROR(EFAULT); 1429 return -EFAULT;
1433 1430
1434 return 0; 1431 return 0;
1435} 1432}
@@ -1445,33 +1442,33 @@ xfs_ioc_swapext(
1445 /* Pull information for the target fd */ 1442 /* Pull information for the target fd */
1446 f = fdget((int)sxp->sx_fdtarget); 1443 f = fdget((int)sxp->sx_fdtarget);
1447 if (!f.file) { 1444 if (!f.file) {
1448 error = XFS_ERROR(EINVAL); 1445 error = -EINVAL;
1449 goto out; 1446 goto out;
1450 } 1447 }
1451 1448
1452 if (!(f.file->f_mode & FMODE_WRITE) || 1449 if (!(f.file->f_mode & FMODE_WRITE) ||
1453 !(f.file->f_mode & FMODE_READ) || 1450 !(f.file->f_mode & FMODE_READ) ||
1454 (f.file->f_flags & O_APPEND)) { 1451 (f.file->f_flags & O_APPEND)) {
1455 error = XFS_ERROR(EBADF); 1452 error = -EBADF;
1456 goto out_put_file; 1453 goto out_put_file;
1457 } 1454 }
1458 1455
1459 tmp = fdget((int)sxp->sx_fdtmp); 1456 tmp = fdget((int)sxp->sx_fdtmp);
1460 if (!tmp.file) { 1457 if (!tmp.file) {
1461 error = XFS_ERROR(EINVAL); 1458 error = -EINVAL;
1462 goto out_put_file; 1459 goto out_put_file;
1463 } 1460 }
1464 1461
1465 if (!(tmp.file->f_mode & FMODE_WRITE) || 1462 if (!(tmp.file->f_mode & FMODE_WRITE) ||
1466 !(tmp.file->f_mode & FMODE_READ) || 1463 !(tmp.file->f_mode & FMODE_READ) ||
1467 (tmp.file->f_flags & O_APPEND)) { 1464 (tmp.file->f_flags & O_APPEND)) {
1468 error = XFS_ERROR(EBADF); 1465 error = -EBADF;
1469 goto out_put_tmp_file; 1466 goto out_put_tmp_file;
1470 } 1467 }
1471 1468
1472 if (IS_SWAPFILE(file_inode(f.file)) || 1469 if (IS_SWAPFILE(file_inode(f.file)) ||
1473 IS_SWAPFILE(file_inode(tmp.file))) { 1470 IS_SWAPFILE(file_inode(tmp.file))) {
1474 error = XFS_ERROR(EINVAL); 1471 error = -EINVAL;
1475 goto out_put_tmp_file; 1472 goto out_put_tmp_file;
1476 } 1473 }
1477 1474
@@ -1479,17 +1476,17 @@ xfs_ioc_swapext(
1479 tip = XFS_I(file_inode(tmp.file)); 1476 tip = XFS_I(file_inode(tmp.file));
1480 1477
1481 if (ip->i_mount != tip->i_mount) { 1478 if (ip->i_mount != tip->i_mount) {
1482 error = XFS_ERROR(EINVAL); 1479 error = -EINVAL;
1483 goto out_put_tmp_file; 1480 goto out_put_tmp_file;
1484 } 1481 }
1485 1482
1486 if (ip->i_ino == tip->i_ino) { 1483 if (ip->i_ino == tip->i_ino) {
1487 error = XFS_ERROR(EINVAL); 1484 error = -EINVAL;
1488 goto out_put_tmp_file; 1485 goto out_put_tmp_file;
1489 } 1486 }
1490 1487
1491 if (XFS_FORCED_SHUTDOWN(ip->i_mount)) { 1488 if (XFS_FORCED_SHUTDOWN(ip->i_mount)) {
1492 error = XFS_ERROR(EIO); 1489 error = -EIO;
1493 goto out_put_tmp_file; 1490 goto out_put_tmp_file;
1494 } 1491 }
1495 1492
@@ -1523,7 +1520,7 @@ xfs_file_ioctl(
1523 int error; 1520 int error;
1524 1521
1525 if (filp->f_mode & FMODE_NOCMTIME) 1522 if (filp->f_mode & FMODE_NOCMTIME)
1526 ioflags |= IO_INVIS; 1523 ioflags |= XFS_IO_INVIS;
1527 1524
1528 trace_xfs_file_ioctl(ip); 1525 trace_xfs_file_ioctl(ip);
1529 1526
@@ -1542,7 +1539,7 @@ xfs_file_ioctl(
1542 xfs_flock64_t bf; 1539 xfs_flock64_t bf;
1543 1540
1544 if (copy_from_user(&bf, arg, sizeof(bf))) 1541 if (copy_from_user(&bf, arg, sizeof(bf)))
1545 return -XFS_ERROR(EFAULT); 1542 return -EFAULT;
1546 return xfs_ioc_space(ip, inode, filp, ioflags, cmd, &bf); 1543 return xfs_ioc_space(ip, inode, filp, ioflags, cmd, &bf);
1547 } 1544 }
1548 case XFS_IOC_DIOINFO: { 1545 case XFS_IOC_DIOINFO: {
@@ -1555,7 +1552,7 @@ xfs_file_ioctl(
1555 da.d_maxiosz = INT_MAX & ~(da.d_miniosz - 1); 1552 da.d_maxiosz = INT_MAX & ~(da.d_miniosz - 1);
1556 1553
1557 if (copy_to_user(arg, &da, sizeof(da))) 1554 if (copy_to_user(arg, &da, sizeof(da)))
1558 return -XFS_ERROR(EFAULT); 1555 return -EFAULT;
1559 return 0; 1556 return 0;
1560 } 1557 }
1561 1558
@@ -1588,7 +1585,7 @@ xfs_file_ioctl(
1588 struct fsdmidata dmi; 1585 struct fsdmidata dmi;
1589 1586
1590 if (copy_from_user(&dmi, arg, sizeof(dmi))) 1587 if (copy_from_user(&dmi, arg, sizeof(dmi)))
1591 return -XFS_ERROR(EFAULT); 1588 return -EFAULT;
1592 1589
1593 error = mnt_want_write_file(filp); 1590 error = mnt_want_write_file(filp);
1594 if (error) 1591 if (error)
@@ -1597,7 +1594,7 @@ xfs_file_ioctl(
1597 error = xfs_set_dmattrs(ip, dmi.fsd_dmevmask, 1594 error = xfs_set_dmattrs(ip, dmi.fsd_dmevmask,
1598 dmi.fsd_dmstate); 1595 dmi.fsd_dmstate);
1599 mnt_drop_write_file(filp); 1596 mnt_drop_write_file(filp);
1600 return -error; 1597 return error;
1601 } 1598 }
1602 1599
1603 case XFS_IOC_GETBMAP: 1600 case XFS_IOC_GETBMAP:
@@ -1613,14 +1610,14 @@ xfs_file_ioctl(
1613 xfs_fsop_handlereq_t hreq; 1610 xfs_fsop_handlereq_t hreq;
1614 1611
1615 if (copy_from_user(&hreq, arg, sizeof(hreq))) 1612 if (copy_from_user(&hreq, arg, sizeof(hreq)))
1616 return -XFS_ERROR(EFAULT); 1613 return -EFAULT;
1617 return xfs_find_handle(cmd, &hreq); 1614 return xfs_find_handle(cmd, &hreq);
1618 } 1615 }
1619 case XFS_IOC_OPEN_BY_HANDLE: { 1616 case XFS_IOC_OPEN_BY_HANDLE: {
1620 xfs_fsop_handlereq_t hreq; 1617 xfs_fsop_handlereq_t hreq;
1621 1618
1622 if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t))) 1619 if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
1623 return -XFS_ERROR(EFAULT); 1620 return -EFAULT;
1624 return xfs_open_by_handle(filp, &hreq); 1621 return xfs_open_by_handle(filp, &hreq);
1625 } 1622 }
1626 case XFS_IOC_FSSETDM_BY_HANDLE: 1623 case XFS_IOC_FSSETDM_BY_HANDLE:
@@ -1630,7 +1627,7 @@ xfs_file_ioctl(
1630 xfs_fsop_handlereq_t hreq; 1627 xfs_fsop_handlereq_t hreq;
1631 1628
1632 if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t))) 1629 if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
1633 return -XFS_ERROR(EFAULT); 1630 return -EFAULT;
1634 return xfs_readlink_by_handle(filp, &hreq); 1631 return xfs_readlink_by_handle(filp, &hreq);
1635 } 1632 }
1636 case XFS_IOC_ATTRLIST_BY_HANDLE: 1633 case XFS_IOC_ATTRLIST_BY_HANDLE:
@@ -1643,13 +1640,13 @@ xfs_file_ioctl(
1643 struct xfs_swapext sxp; 1640 struct xfs_swapext sxp;
1644 1641
1645 if (copy_from_user(&sxp, arg, sizeof(xfs_swapext_t))) 1642 if (copy_from_user(&sxp, arg, sizeof(xfs_swapext_t)))
1646 return -XFS_ERROR(EFAULT); 1643 return -EFAULT;
1647 error = mnt_want_write_file(filp); 1644 error = mnt_want_write_file(filp);
1648 if (error) 1645 if (error)
1649 return error; 1646 return error;
1650 error = xfs_ioc_swapext(&sxp); 1647 error = xfs_ioc_swapext(&sxp);
1651 mnt_drop_write_file(filp); 1648 mnt_drop_write_file(filp);
1652 return -error; 1649 return error;
1653 } 1650 }
1654 1651
1655 case XFS_IOC_FSCOUNTS: { 1652 case XFS_IOC_FSCOUNTS: {
@@ -1657,10 +1654,10 @@ xfs_file_ioctl(
1657 1654
1658 error = xfs_fs_counts(mp, &out); 1655 error = xfs_fs_counts(mp, &out);
1659 if (error) 1656 if (error)
1660 return -error; 1657 return error;
1661 1658
1662 if (copy_to_user(arg, &out, sizeof(out))) 1659 if (copy_to_user(arg, &out, sizeof(out)))
1663 return -XFS_ERROR(EFAULT); 1660 return -EFAULT;
1664 return 0; 1661 return 0;
1665 } 1662 }
1666 1663
@@ -1672,10 +1669,10 @@ xfs_file_ioctl(
1672 return -EPERM; 1669 return -EPERM;
1673 1670
1674 if (mp->m_flags & XFS_MOUNT_RDONLY) 1671 if (mp->m_flags & XFS_MOUNT_RDONLY)
1675 return -XFS_ERROR(EROFS); 1672 return -EROFS;
1676 1673
1677 if (copy_from_user(&inout, arg, sizeof(inout))) 1674 if (copy_from_user(&inout, arg, sizeof(inout)))
1678 return -XFS_ERROR(EFAULT); 1675 return -EFAULT;
1679 1676
1680 error = mnt_want_write_file(filp); 1677 error = mnt_want_write_file(filp);
1681 if (error) 1678 if (error)
@@ -1686,10 +1683,10 @@ xfs_file_ioctl(
1686 error = xfs_reserve_blocks(mp, &in, &inout); 1683 error = xfs_reserve_blocks(mp, &in, &inout);
1687 mnt_drop_write_file(filp); 1684 mnt_drop_write_file(filp);
1688 if (error) 1685 if (error)
1689 return -error; 1686 return error;
1690 1687
1691 if (copy_to_user(arg, &inout, sizeof(inout))) 1688 if (copy_to_user(arg, &inout, sizeof(inout)))
1692 return -XFS_ERROR(EFAULT); 1689 return -EFAULT;
1693 return 0; 1690 return 0;
1694 } 1691 }
1695 1692
@@ -1701,10 +1698,10 @@ xfs_file_ioctl(
1701 1698
1702 error = xfs_reserve_blocks(mp, NULL, &out); 1699 error = xfs_reserve_blocks(mp, NULL, &out);
1703 if (error) 1700 if (error)
1704 return -error; 1701 return error;
1705 1702
1706 if (copy_to_user(arg, &out, sizeof(out))) 1703 if (copy_to_user(arg, &out, sizeof(out)))
1707 return -XFS_ERROR(EFAULT); 1704 return -EFAULT;
1708 1705
1709 return 0; 1706 return 0;
1710 } 1707 }
@@ -1713,42 +1710,42 @@ xfs_file_ioctl(
1713 xfs_growfs_data_t in; 1710 xfs_growfs_data_t in;
1714 1711
1715 if (copy_from_user(&in, arg, sizeof(in))) 1712 if (copy_from_user(&in, arg, sizeof(in)))
1716 return -XFS_ERROR(EFAULT); 1713 return -EFAULT;
1717 1714
1718 error = mnt_want_write_file(filp); 1715 error = mnt_want_write_file(filp);
1719 if (error) 1716 if (error)
1720 return error; 1717 return error;
1721 error = xfs_growfs_data(mp, &in); 1718 error = xfs_growfs_data(mp, &in);
1722 mnt_drop_write_file(filp); 1719 mnt_drop_write_file(filp);
1723 return -error; 1720 return error;
1724 } 1721 }
1725 1722
1726 case XFS_IOC_FSGROWFSLOG: { 1723 case XFS_IOC_FSGROWFSLOG: {
1727 xfs_growfs_log_t in; 1724 xfs_growfs_log_t in;
1728 1725
1729 if (copy_from_user(&in, arg, sizeof(in))) 1726 if (copy_from_user(&in, arg, sizeof(in)))
1730 return -XFS_ERROR(EFAULT); 1727 return -EFAULT;
1731 1728
1732 error = mnt_want_write_file(filp); 1729 error = mnt_want_write_file(filp);
1733 if (error) 1730 if (error)
1734 return error; 1731 return error;
1735 error = xfs_growfs_log(mp, &in); 1732 error = xfs_growfs_log(mp, &in);
1736 mnt_drop_write_file(filp); 1733 mnt_drop_write_file(filp);
1737 return -error; 1734 return error;
1738 } 1735 }
1739 1736
1740 case XFS_IOC_FSGROWFSRT: { 1737 case XFS_IOC_FSGROWFSRT: {
1741 xfs_growfs_rt_t in; 1738 xfs_growfs_rt_t in;
1742 1739
1743 if (copy_from_user(&in, arg, sizeof(in))) 1740 if (copy_from_user(&in, arg, sizeof(in)))
1744 return -XFS_ERROR(EFAULT); 1741 return -EFAULT;
1745 1742
1746 error = mnt_want_write_file(filp); 1743 error = mnt_want_write_file(filp);
1747 if (error) 1744 if (error)
1748 return error; 1745 return error;
1749 error = xfs_growfs_rt(mp, &in); 1746 error = xfs_growfs_rt(mp, &in);
1750 mnt_drop_write_file(filp); 1747 mnt_drop_write_file(filp);
1751 return -error; 1748 return error;
1752 } 1749 }
1753 1750
1754 case XFS_IOC_GOINGDOWN: { 1751 case XFS_IOC_GOINGDOWN: {
@@ -1758,10 +1755,9 @@ xfs_file_ioctl(
1758 return -EPERM; 1755 return -EPERM;
1759 1756
1760 if (get_user(in, (__uint32_t __user *)arg)) 1757 if (get_user(in, (__uint32_t __user *)arg))
1761 return -XFS_ERROR(EFAULT); 1758 return -EFAULT;
1762 1759
1763 error = xfs_fs_goingdown(mp, in); 1760 return xfs_fs_goingdown(mp, in);
1764 return -error;
1765 } 1761 }
1766 1762
1767 case XFS_IOC_ERROR_INJECTION: { 1763 case XFS_IOC_ERROR_INJECTION: {
@@ -1771,18 +1767,16 @@ xfs_file_ioctl(
1771 return -EPERM; 1767 return -EPERM;
1772 1768
1773 if (copy_from_user(&in, arg, sizeof(in))) 1769 if (copy_from_user(&in, arg, sizeof(in)))
1774 return -XFS_ERROR(EFAULT); 1770 return -EFAULT;
1775 1771
1776 error = xfs_errortag_add(in.errtag, mp); 1772 return xfs_errortag_add(in.errtag, mp);
1777 return -error;
1778 } 1773 }
1779 1774
1780 case XFS_IOC_ERROR_CLEARALL: 1775 case XFS_IOC_ERROR_CLEARALL:
1781 if (!capable(CAP_SYS_ADMIN)) 1776 if (!capable(CAP_SYS_ADMIN))
1782 return -EPERM; 1777 return -EPERM;
1783 1778
1784 error = xfs_errortag_clearall(mp, 1); 1779 return xfs_errortag_clearall(mp, 1);
1785 return -error;
1786 1780
1787 case XFS_IOC_FREE_EOFBLOCKS: { 1781 case XFS_IOC_FREE_EOFBLOCKS: {
1788 struct xfs_fs_eofblocks eofb; 1782 struct xfs_fs_eofblocks eofb;
@@ -1792,16 +1786,16 @@ xfs_file_ioctl(
1792 return -EPERM; 1786 return -EPERM;
1793 1787
1794 if (mp->m_flags & XFS_MOUNT_RDONLY) 1788 if (mp->m_flags & XFS_MOUNT_RDONLY)
1795 return -XFS_ERROR(EROFS); 1789 return -EROFS;
1796 1790
1797 if (copy_from_user(&eofb, arg, sizeof(eofb))) 1791 if (copy_from_user(&eofb, arg, sizeof(eofb)))
1798 return -XFS_ERROR(EFAULT); 1792 return -EFAULT;
1799 1793
1800 error = xfs_fs_eofblocks_from_user(&eofb, &keofb); 1794 error = xfs_fs_eofblocks_from_user(&eofb, &keofb);
1801 if (error) 1795 if (error)
1802 return -error; 1796 return error;
1803 1797
1804 return -xfs_icache_free_eofblocks(mp, &keofb); 1798 return xfs_icache_free_eofblocks(mp, &keofb);
1805 } 1799 }
1806 1800
1807 default: 1801 default: