diff options
Diffstat (limited to 'fs')
-rw-r--r-- | fs/gfs2/ops_file.c | 138 |
1 files changed, 36 insertions, 102 deletions
diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index ac8e1238cb6f..db4484a3efcc 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/gfs2_ondisk.h> | 21 | #include <linux/gfs2_ondisk.h> |
22 | #include <linux/ext2_fs.h> | 22 | #include <linux/ext2_fs.h> |
23 | #include <linux/crc32.h> | 23 | #include <linux/crc32.h> |
24 | #include <linux/iflags.h> | ||
24 | #include <asm/semaphore.h> | 25 | #include <asm/semaphore.h> |
25 | #include <asm/uaccess.h> | 26 | #include <asm/uaccess.h> |
26 | 27 | ||
@@ -536,110 +537,44 @@ static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir) | |||
536 | return error; | 537 | return error; |
537 | } | 538 | } |
538 | 539 | ||
539 | const struct gfs2_flag_eattr { | 540 | static const u32 iflags_to_gfs2[32] = { |
540 | u32 flag; | 541 | [iflag_Sync] = GFS2_DIF_SYNC, |
541 | u32 ext2; | 542 | [iflag_Immutable] = GFS2_DIF_IMMUTABLE, |
542 | } gfs2_flag_eattrs[] = { | 543 | [iflag_Append] = GFS2_DIF_APPENDONLY, |
543 | { | 544 | [iflag_NoAtime] = GFS2_DIF_NOATIME, |
544 | .flag = GFS2_DIF_IMMUTABLE, | 545 | [iflag_Index] = GFS2_DIF_EXHASH, |
545 | .ext2 = EXT2_IMMUTABLE_FL, | 546 | [iflag_JournalData] = GFS2_DIF_JDATA, |
546 | }, { | 547 | [iflag_DirectIO] = GFS2_DIF_DIRECTIO, |
547 | .flag = GFS2_DIF_APPENDONLY, | 548 | [iflag_InheritDirectIO] = GFS2_DIF_INHERIT_DIRECTIO, |
548 | .ext2 = EXT2_APPEND_FL, | 549 | [iflag_InheritJdata] = GFS2_DIF_INHERIT_JDATA, |
549 | }, { | ||
550 | .flag = GFS2_DIF_JDATA, | ||
551 | .ext2 = EXT2_JOURNAL_DATA_FL, | ||
552 | }, { | ||
553 | .flag = GFS2_DIF_EXHASH, | ||
554 | .ext2 = EXT2_INDEX_FL, | ||
555 | }, { | ||
556 | .flag = GFS2_DIF_EA_INDIRECT, | ||
557 | }, { | ||
558 | .flag = GFS2_DIF_DIRECTIO, | ||
559 | }, { | ||
560 | .flag = GFS2_DIF_NOATIME, | ||
561 | .ext2 = EXT2_NOATIME_FL, | ||
562 | }, { | ||
563 | .flag = GFS2_DIF_SYNC, | ||
564 | .ext2 = EXT2_SYNC_FL, | ||
565 | }, { | ||
566 | .flag = GFS2_DIF_SYSTEM, | ||
567 | }, { | ||
568 | .flag = GFS2_DIF_TRUNC_IN_PROG, | ||
569 | }, { | ||
570 | .flag = GFS2_DIF_INHERIT_JDATA, | ||
571 | }, { | ||
572 | .flag = GFS2_DIF_INHERIT_DIRECTIO, | ||
573 | }, { | ||
574 | }, | ||
575 | }; | 550 | }; |
576 | 551 | ||
577 | static const struct gfs2_flag_eattr *get_by_ext2(u32 ext2) | 552 | static const u32 gfs2_to_iflags[32] = { |
578 | { | 553 | [gfs2fl_Sync] = IFLAG_SYNC, |
579 | const struct gfs2_flag_eattr *p = gfs2_flag_eattrs; | 554 | [gfs2fl_Immutable] = IFLAG_IMMUTABLE, |
580 | for(; p->flag; p++) { | 555 | [gfs2fl_AppendOnly] = IFLAG_APPEND, |
581 | if (ext2 == p->ext2) | 556 | [gfs2fl_NoAtime] = IFLAG_NOATIME, |
582 | return p; | 557 | [gfs2fl_ExHash] = IFLAG_INDEX, |
583 | } | 558 | [gfs2fl_Jdata] = IFLAG_JOURNAL_DATA, |
584 | return NULL; | 559 | [gfs2fl_Directio] = IFLAG_DIRECTIO, |
585 | } | 560 | [gfs2fl_InheritDirectio] = IFLAG_INHERITDIRECTIO, |
586 | 561 | [gfs2fl_InheritJdata] = IFLAG_INHERITJDATA, | |
587 | static const struct gfs2_flag_eattr *get_by_gfs2(u32 gfs2) | 562 | }; |
588 | { | ||
589 | const struct gfs2_flag_eattr *p = gfs2_flag_eattrs; | ||
590 | for(; p->flag; p++) { | ||
591 | if (gfs2 == p->flag) | ||
592 | return p; | ||
593 | } | ||
594 | return NULL; | ||
595 | } | ||
596 | |||
597 | static u32 gfs2_flags_to_ext2(u32 gfs2) | ||
598 | { | ||
599 | const struct gfs2_flag_eattr *ea; | ||
600 | u32 ext2 = 0; | ||
601 | u32 mask = 1; | ||
602 | |||
603 | for(; mask != 0; mask <<=1) { | ||
604 | if (mask & gfs2) { | ||
605 | ea = get_by_gfs2(mask); | ||
606 | if (ea) | ||
607 | ext2 |= ea->ext2; | ||
608 | } | ||
609 | } | ||
610 | return ext2; | ||
611 | } | ||
612 | |||
613 | static int gfs2_flags_from_ext2(u32 *gfs2, u32 ext2) | ||
614 | { | ||
615 | const struct gfs2_flag_eattr *ea; | ||
616 | u32 mask = 1; | ||
617 | |||
618 | for(; mask != 0; mask <<= 1) { | ||
619 | if (mask & ext2) { | ||
620 | ea = get_by_ext2(mask); | ||
621 | if (ea == NULL) | ||
622 | return -EINVAL; | ||
623 | *gfs2 |= ea->flag; | ||
624 | } | ||
625 | } | ||
626 | return 0; | ||
627 | } | ||
628 | 563 | ||
629 | static int get_ext2_flags(struct inode *inode, u32 __user *ptr) | 564 | static int gfs2_get_flags(struct inode *inode, u32 __user *ptr) |
630 | { | 565 | { |
631 | struct gfs2_inode *ip = inode->u.generic_ip; | 566 | struct gfs2_inode *ip = inode->u.generic_ip; |
632 | struct gfs2_holder gh; | 567 | struct gfs2_holder gh; |
633 | int error; | 568 | int error; |
634 | u32 ext2; | 569 | u32 iflags; |
635 | 570 | ||
636 | gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh); | 571 | gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh); |
637 | error = gfs2_glock_nq_m_atime(1, &gh); | 572 | error = gfs2_glock_nq_m_atime(1, &gh); |
638 | if (error) | 573 | if (error) |
639 | return error; | 574 | return error; |
640 | 575 | ||
641 | ext2 = gfs2_flags_to_ext2(ip->i_di.di_flags); | 576 | iflags = iflags_cvt(gfs2_to_iflags, ip->i_di.di_flags); |
642 | if (put_user(ext2, ptr)) | 577 | if (put_user(iflags, ptr)) |
643 | error = -EFAULT; | 578 | error = -EFAULT; |
644 | 579 | ||
645 | gfs2_glock_dq_m(1, &gh); | 580 | gfs2_glock_dq_m(1, &gh); |
@@ -665,7 +600,7 @@ static int get_ext2_flags(struct inode *inode, u32 __user *ptr) | |||
665 | * @mask: Indicates which flags are valid | 600 | * @mask: Indicates which flags are valid |
666 | * | 601 | * |
667 | */ | 602 | */ |
668 | static int gfs2_set_flags(struct inode *inode, u32 flags, u32 mask) | 603 | static int do_gfs2_set_flags(struct inode *inode, u32 flags, u32 mask) |
669 | { | 604 | { |
670 | struct gfs2_inode *ip = inode->u.generic_ip; | 605 | struct gfs2_inode *ip = inode->u.generic_ip; |
671 | struct buffer_head *bh; | 606 | struct buffer_head *bh; |
@@ -717,24 +652,23 @@ out: | |||
717 | return error; | 652 | return error; |
718 | } | 653 | } |
719 | 654 | ||
720 | static int set_ext2_flags(struct inode *inode, u32 __user *ptr) | 655 | static int gfs2_set_flags(struct inode *inode, u32 __user *ptr) |
721 | { | 656 | { |
722 | u32 ext2, gfs2; | 657 | u32 iflags, gfsflags; |
723 | if (get_user(ext2, ptr)) | 658 | if (get_user(iflags, ptr)) |
724 | return -EFAULT; | 659 | return -EFAULT; |
725 | if (gfs2_flags_from_ext2(&gfs2, ext2)) | 660 | gfsflags = iflags_cvt(iflags_to_gfs2, iflags); |
726 | return -EINVAL; | 661 | return do_gfs2_set_flags(inode, gfsflags, ~0); |
727 | return gfs2_set_flags(inode, gfs2, ~0); | ||
728 | } | 662 | } |
729 | 663 | ||
730 | int gfs2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, | 664 | int gfs2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, |
731 | unsigned long arg) | 665 | unsigned long arg) |
732 | { | 666 | { |
733 | switch(cmd) { | 667 | switch(cmd) { |
734 | case EXT2_IOC_GETFLAGS: | 668 | case IFLAGS_GET_IOC: |
735 | return get_ext2_flags(inode, (u32 __user *)arg); | 669 | return gfs2_get_flags(inode, (u32 __user *)arg); |
736 | case EXT2_IOC_SETFLAGS: | 670 | case IFLAGS_SET_IOC: |
737 | return set_ext2_flags(inode, (u32 __user *)arg); | 671 | return gfs2_set_flags(inode, (u32 __user *)arg); |
738 | } | 672 | } |
739 | return -ENOTTY; | 673 | return -ENOTTY; |
740 | } | 674 | } |