aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ecryptfs/main.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-01-25 11:34:42 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2008-01-25 11:35:13 -0500
commitdf8dc74e8a383eaf2d9b44b80a71ec6f0e52b42e (patch)
treebc3799a43e8b94fa84b32e37b1c124d5e4868f50 /fs/ecryptfs/main.c
parent556a169dab38b5100df6f4a45b655dddd3db94c1 (diff)
parent4a3ad20ccd8f4d2a0535cf98fa83f7b561ba59a9 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-2.6
This can be broken down into these major areas: - Documentation updates (language translations and fixes, as well as kobject and kset documenatation updates.) - major kset/kobject/ktype rework and fixes. This cleans up the kset and kobject and ktype relationship and architecture, making sense of things now, and good documenation and samples are provided for others to use. Also the attributes for kobjects are much easier to handle now. This cleaned up a LOT of code all through the kernel, making kobjects easier to use if you want to. - struct bus_type has been reworked to now handle the lifetime rules properly, as the kobject is properly dynamic. - struct driver has also been reworked, and now the lifetime issues are resolved. - the block subsystem has been converted to use struct device now, and not "raw" kobjects. This patch has been in the -mm tree for over a year now, and finally all the issues are worked out with it. Older distros now properly work with new kernels, and no userspace updates are needed at all. - nozomi driver is added. This has also been in -mm for a long time, and many people have asked for it to go in. It is now in good enough shape to do so. - lots of class_device conversions to use struct device instead. The tree is almost all cleaned up now, only SCSI and IB is the remaining code to fix up... * git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-2.6: (196 commits) Driver core: coding style fixes Kobject: fix coding style issues in kobject c files Kobject: fix coding style issues in kobject.h Driver core: fix coding style issues in device.h spi: use class iteration api scsi: use class iteration api rtc: use class iteration api power supply : use class iteration api ieee1394: use class iteration api Driver Core: add class iteration api Driver core: Cleanup get_device_parent() in device_add() and device_move() UIO: constify function pointer tables Driver Core: constify the name passed to platform_device_register_simple driver core: fix build with SYSFS=n sysfs: make SYSFS_DEPRECATED depend on SYSFS Driver core: use LIST_HEAD instead of call to INIT_LIST_HEAD in __init kobject: add sample code for how to use ksets/ktypes/kobjects kobject: add sample code for how to use kobjects in a simple manner. kobject: update the kobject/kset documentation kobject: remove old, outdated documentation. ...
Diffstat (limited to 'fs/ecryptfs/main.c')
-rw-r--r--fs/ecryptfs/main.c129
1 files changed, 19 insertions, 110 deletions
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index e5580bcb923a..0249aa4ae181 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -734,127 +734,40 @@ static int ecryptfs_init_kmem_caches(void)
734 return 0; 734 return 0;
735} 735}
736 736
737struct ecryptfs_obj { 737static struct kobject *ecryptfs_kobj;
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 738
749static ssize_t 739static ssize_t version_show(struct kobject *kobj,
750ecryptfs_attr_store(struct kobject *kobj, 740 struct kobj_attribute *attr, char *buff)
751 struct attribute *attr, const char *buf, size_t len)
752{ 741{
753 struct ecryptfs_obj *obj = container_of(kobj, struct ecryptfs_obj, 742 return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK);
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} 743}
760 744
761static ssize_t 745static struct kobj_attribute version_attr = __ATTR_RO(version);
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 746
772static struct sysfs_ops ecryptfs_sysfs_ops = { 747static struct attribute *attributes[] = {
773 .show = ecryptfs_attr_show, 748 &version_attr.attr,
774 .store = ecryptfs_attr_store 749 NULL,
775}; 750};
776 751
777static struct kobj_type ecryptfs_ktype = { 752static struct attribute_group attr_group = {
778 .sysfs_ops = &ecryptfs_sysfs_ops 753 .attrs = attributes,
779}; 754};
780 755
781static decl_subsys(ecryptfs, &ecryptfs_ktype, NULL);
782
783static ssize_t version_show(struct ecryptfs_obj *obj, char *buff)
784{
785 return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK);
786}
787
788static struct ecryptfs_attribute sysfs_attr_version = __ATTR_RO(version);
789
790static struct ecryptfs_version_str_map_elem {
791 u32 flag;
792 char *str;
793} ecryptfs_version_str_map[] = {
794 {ECRYPTFS_VERSIONING_PASSPHRASE, "passphrase"},
795 {ECRYPTFS_VERSIONING_PUBKEY, "pubkey"},
796 {ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH, "plaintext passthrough"},
797 {ECRYPTFS_VERSIONING_POLICY, "policy"},
798 {ECRYPTFS_VERSIONING_XATTR, "metadata in extended attribute"},
799 {ECRYPTFS_VERSIONING_MULTKEY, "multiple keys per file"}
800};
801
802static ssize_t version_str_show(struct ecryptfs_obj *obj, char *buff)
803{
804 int i;
805 int remaining = PAGE_SIZE;
806 int total_written = 0;
807
808 buff[0] = '\0';
809 for (i = 0; i < ARRAY_SIZE(ecryptfs_version_str_map); i++) {
810 int entry_size;
811
812 if (!(ECRYPTFS_VERSIONING_MASK
813 & ecryptfs_version_str_map[i].flag))
814 continue;
815 entry_size = strlen(ecryptfs_version_str_map[i].str);
816 if ((entry_size + 2) > remaining)
817 goto out;
818 memcpy(buff, ecryptfs_version_str_map[i].str, entry_size);
819 buff[entry_size++] = '\n';
820 buff[entry_size] = '\0';
821 buff += entry_size;
822 total_written += entry_size;
823 remaining -= entry_size;
824 }
825out:
826 return total_written;
827}
828
829static struct ecryptfs_attribute sysfs_attr_version_str = __ATTR_RO(version_str);
830
831static int do_sysfs_registration(void) 756static int do_sysfs_registration(void)
832{ 757{
833 int rc; 758 int rc;
834 759
835 rc = subsystem_register(&ecryptfs_subsys); 760 ecryptfs_kobj = kobject_create_and_add("ecryptfs", fs_kobj);
836 if (rc) { 761 if (!ecryptfs_kobj) {
837 printk(KERN_ERR 762 printk(KERN_ERR "Unable to create ecryptfs kset\n");
838 "Unable to register ecryptfs sysfs subsystem\n"); 763 rc = -ENOMEM;
839 goto out;
840 }
841 rc = sysfs_create_file(&ecryptfs_subsys.kobj,
842 &sysfs_attr_version.attr);
843 if (rc) {
844 printk(KERN_ERR
845 "Unable to create ecryptfs version attribute\n");
846 subsystem_unregister(&ecryptfs_subsys);
847 goto out; 764 goto out;
848 } 765 }
849 rc = sysfs_create_file(&ecryptfs_subsys.kobj, 766 rc = sysfs_create_group(ecryptfs_kobj, &attr_group);
850 &sysfs_attr_version_str.attr);
851 if (rc) { 767 if (rc) {
852 printk(KERN_ERR 768 printk(KERN_ERR
853 "Unable to create ecryptfs version_str attribute\n"); 769 "Unable to create ecryptfs version attributes\n");
854 sysfs_remove_file(&ecryptfs_subsys.kobj, 770 kobject_put(ecryptfs_kobj);
855 &sysfs_attr_version.attr);
856 subsystem_unregister(&ecryptfs_subsys);
857 goto out;
858 } 771 }
859out: 772out:
860 return rc; 773 return rc;
@@ -862,11 +775,8 @@ out:
862 775
863static void do_sysfs_unregistration(void) 776static void do_sysfs_unregistration(void)
864{ 777{
865 sysfs_remove_file(&ecryptfs_subsys.kobj, 778 sysfs_remove_group(ecryptfs_kobj, &attr_group);
866 &sysfs_attr_version.attr); 779 kobject_put(ecryptfs_kobj);
867 sysfs_remove_file(&ecryptfs_subsys.kobj,
868 &sysfs_attr_version_str.attr);
869 subsystem_unregister(&ecryptfs_subsys);
870} 780}
871 781
872static int __init ecryptfs_init(void) 782static int __init ecryptfs_init(void)
@@ -894,7 +804,6 @@ static int __init ecryptfs_init(void)
894 printk(KERN_ERR "Failed to register filesystem\n"); 804 printk(KERN_ERR "Failed to register filesystem\n");
895 goto out_free_kmem_caches; 805 goto out_free_kmem_caches;
896 } 806 }
897 kobj_set_kset_s(&ecryptfs_subsys, fs_subsys);
898 rc = do_sysfs_registration(); 807 rc = do_sysfs_registration();
899 if (rc) { 808 if (rc) {
900 printk(KERN_ERR "sysfs registration failed\n"); 809 printk(KERN_ERR "sysfs registration failed\n");