aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ecryptfs
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2007-10-15 18:01:24 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2008-01-24 23:40:08 -0500
commit30a468b1c1b9911ae515ff8972ee10c50cca3021 (patch)
tree99b891f04425e418f4ae5745a32a86531bb8b245 /fs/ecryptfs
parent02ff82cac7ee7351d2649c4a3568f12e4e0fe534 (diff)
ecryptfs: clean up attribute mess
It isn't that hard to add simple kset attributes, so don't go through all the gyrations of creating your own object type and show and store functions. Just use the functions that are already present. This makes things much simpler. Note, the version_str string violates the "one value per file" rule for sysfs. I suggest changing this now (individual files per type supported is one suggested way.) Cc: Michael A. Halcrow <mahalcro@us.ibm.com> Cc: Michael C. Thompson <mcthomps@us.ibm.com> Cc: Tyler Hicks <tyhicks@ou.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'fs/ecryptfs')
-rw-r--r--fs/ecryptfs/main.c85
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
737struct ecryptfs_obj { 737static decl_subsys(ecryptfs, NULL, NULL);
738 char *name;
739 struct list_head slot_list;
740 struct kobject kobj;
741};
742
743struct 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
749static ssize_t
750ecryptfs_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
761static ssize_t
762ecryptfs_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
772static struct sysfs_ops ecryptfs_sysfs_ops = {
773 .show = ecryptfs_attr_show,
774 .store = ecryptfs_attr_store
775};
776 738
777static struct kobj_type ecryptfs_ktype = { 739static ssize_t version_show(struct kset *kset, char *buff)
778 .sysfs_ops = &ecryptfs_sysfs_ops
779};
780
781static decl_subsys(ecryptfs, &ecryptfs_ktype, NULL);
782
783static 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
788static struct ecryptfs_attribute sysfs_attr_version = __ATTR_RO(version); 744static struct subsys_attribute version_attr = __ATTR_RO(version);
789 745
790static struct ecryptfs_version_str_map_elem { 746static 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
802static ssize_t version_str_show(struct ecryptfs_obj *obj, char *buff) 758static 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
829static struct ecryptfs_attribute sysfs_attr_version_str = __ATTR_RO(version_str); 785static struct subsys_attribute version_attr_str = __ATTR_RO(version_str);
786
787static struct attribute *attributes[] = {
788 &version_attr.attr,
789 &version_attr_str.attr,
790 NULL,
791};
792
793static struct attribute_group attr_group = {
794 .attrs = attributes,
795};
830 796
831static int do_sysfs_registration(void) 797static 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 }
859out: 813out:
860 return rc; 814 return rc;
@@ -862,10 +816,7 @@ out:
862 816
863static void do_sysfs_unregistration(void) 817static 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