diff options
-rw-r--r-- | fs/ecryptfs/main.c | 85 |
1 files changed, 18 insertions, 67 deletions
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c index e5580bcb923a..f9f32472c505 100644 --- a/fs/ecryptfs/main.c +++ b/fs/ecryptfs/main.c | |||
@@ -734,58 +734,14 @@ static int ecryptfs_init_kmem_caches(void) | |||
734 | return 0; | 734 | return 0; |
735 | } | 735 | } |
736 | 736 | ||
737 | struct ecryptfs_obj { | 737 | static decl_subsys(ecryptfs, NULL, NULL); |
738 | char *name; | ||
739 | struct list_head slot_list; | ||
740 | struct kobject kobj; | ||
741 | }; | ||
742 | |||
743 | struct ecryptfs_attribute { | ||
744 | struct attribute attr; | ||
745 | ssize_t(*show) (struct ecryptfs_obj *, char *); | ||
746 | ssize_t(*store) (struct ecryptfs_obj *, const char *, size_t); | ||
747 | }; | ||
748 | |||
749 | static ssize_t | ||
750 | ecryptfs_attr_store(struct kobject *kobj, | ||
751 | struct attribute *attr, const char *buf, size_t len) | ||
752 | { | ||
753 | struct ecryptfs_obj *obj = container_of(kobj, struct ecryptfs_obj, | ||
754 | kobj); | ||
755 | struct ecryptfs_attribute *attribute = | ||
756 | container_of(attr, struct ecryptfs_attribute, attr); | ||
757 | |||
758 | return (attribute->store ? attribute->store(obj, buf, len) : 0); | ||
759 | } | ||
760 | |||
761 | static ssize_t | ||
762 | ecryptfs_attr_show(struct kobject *kobj, struct attribute *attr, char *buf) | ||
763 | { | ||
764 | struct ecryptfs_obj *obj = container_of(kobj, struct ecryptfs_obj, | ||
765 | kobj); | ||
766 | struct ecryptfs_attribute *attribute = | ||
767 | container_of(attr, struct ecryptfs_attribute, attr); | ||
768 | |||
769 | return (attribute->show ? attribute->show(obj, buf) : 0); | ||
770 | } | ||
771 | |||
772 | static struct sysfs_ops ecryptfs_sysfs_ops = { | ||
773 | .show = ecryptfs_attr_show, | ||
774 | .store = ecryptfs_attr_store | ||
775 | }; | ||
776 | 738 | ||
777 | static struct kobj_type ecryptfs_ktype = { | 739 | static ssize_t version_show(struct kset *kset, char *buff) |
778 | .sysfs_ops = &ecryptfs_sysfs_ops | ||
779 | }; | ||
780 | |||
781 | static decl_subsys(ecryptfs, &ecryptfs_ktype, NULL); | ||
782 | |||
783 | static ssize_t version_show(struct ecryptfs_obj *obj, char *buff) | ||
784 | { | 740 | { |
785 | return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK); | 741 | return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK); |
786 | } | 742 | } |
787 | 743 | ||
788 | static struct ecryptfs_attribute sysfs_attr_version = __ATTR_RO(version); | 744 | static struct subsys_attribute version_attr = __ATTR_RO(version); |
789 | 745 | ||
790 | static struct ecryptfs_version_str_map_elem { | 746 | static struct ecryptfs_version_str_map_elem { |
791 | u32 flag; | 747 | u32 flag; |
@@ -799,7 +755,7 @@ static struct ecryptfs_version_str_map_elem { | |||
799 | {ECRYPTFS_VERSIONING_MULTKEY, "multiple keys per file"} | 755 | {ECRYPTFS_VERSIONING_MULTKEY, "multiple keys per file"} |
800 | }; | 756 | }; |
801 | 757 | ||
802 | static ssize_t version_str_show(struct ecryptfs_obj *obj, char *buff) | 758 | static ssize_t version_str_show(struct kset *kset, char *buff) |
803 | { | 759 | { |
804 | int i; | 760 | int i; |
805 | int remaining = PAGE_SIZE; | 761 | int remaining = PAGE_SIZE; |
@@ -826,7 +782,17 @@ out: | |||
826 | return total_written; | 782 | return total_written; |
827 | } | 783 | } |
828 | 784 | ||
829 | static struct ecryptfs_attribute sysfs_attr_version_str = __ATTR_RO(version_str); | 785 | static struct subsys_attribute version_attr_str = __ATTR_RO(version_str); |
786 | |||
787 | static struct attribute *attributes[] = { | ||
788 | &version_attr.attr, | ||
789 | &version_attr_str.attr, | ||
790 | NULL, | ||
791 | }; | ||
792 | |||
793 | static struct attribute_group attr_group = { | ||
794 | .attrs = attributes, | ||
795 | }; | ||
830 | 796 | ||
831 | static int do_sysfs_registration(void) | 797 | static int do_sysfs_registration(void) |
832 | { | 798 | { |
@@ -838,23 +804,11 @@ static int do_sysfs_registration(void) | |||
838 | "Unable to register ecryptfs sysfs subsystem\n"); | 804 | "Unable to register ecryptfs sysfs subsystem\n"); |
839 | goto out; | 805 | goto out; |
840 | } | 806 | } |
841 | rc = sysfs_create_file(&ecryptfs_subsys.kobj, | 807 | rc = sysfs_create_group(&ecryptfs_subsys.kobj, &attr_group); |
842 | &sysfs_attr_version.attr); | ||
843 | if (rc) { | 808 | if (rc) { |
844 | printk(KERN_ERR | 809 | printk(KERN_ERR |
845 | "Unable to create ecryptfs version attribute\n"); | 810 | "Unable to create ecryptfs version attributes\n"); |
846 | subsystem_unregister(&ecryptfs_subsys); | 811 | subsystem_unregister(&ecryptfs_subsys); |
847 | goto out; | ||
848 | } | ||
849 | rc = sysfs_create_file(&ecryptfs_subsys.kobj, | ||
850 | &sysfs_attr_version_str.attr); | ||
851 | if (rc) { | ||
852 | printk(KERN_ERR | ||
853 | "Unable to create ecryptfs version_str attribute\n"); | ||
854 | sysfs_remove_file(&ecryptfs_subsys.kobj, | ||
855 | &sysfs_attr_version.attr); | ||
856 | subsystem_unregister(&ecryptfs_subsys); | ||
857 | goto out; | ||
858 | } | 812 | } |
859 | out: | 813 | out: |
860 | return rc; | 814 | return rc; |
@@ -862,10 +816,7 @@ out: | |||
862 | 816 | ||
863 | static void do_sysfs_unregistration(void) | 817 | static void do_sysfs_unregistration(void) |
864 | { | 818 | { |
865 | sysfs_remove_file(&ecryptfs_subsys.kobj, | 819 | sysfs_remove_group(&ecryptfs_subsys.kobj, &attr_group); |
866 | &sysfs_attr_version.attr); | ||
867 | sysfs_remove_file(&ecryptfs_subsys.kobj, | ||
868 | &sysfs_attr_version_str.attr); | ||
869 | subsystem_unregister(&ecryptfs_subsys); | 820 | subsystem_unregister(&ecryptfs_subsys); |
870 | } | 821 | } |
871 | 822 | ||