2 * eCryptfs: Linux filesystem encryption layer
4 * Copyright (C) 1997-2003 Erez Zadok
5 * Copyright (C) 2001-2003 Stony Brook University
6 * Copyright (C) 2004-2007 International Business Machines Corp.
7 * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
8 * Michael C. Thompson <mcthomps@us.ibm.com>
9 * Tyler Hicks <tyhicks@ou.edu>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of the
14 * License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 #include <linux/dcache.h>
28 #include <linux/file.h>
29 #include <linux/module.h>
30 #include <linux/namei.h>
31 #include <linux/skbuff.h>
32 #include <linux/crypto.h>
33 #include <linux/netlink.h>
34 #include <linux/mount.h>
35 #include <linux/dcache.h>
36 #include <linux/pagemap.h>
37 #include <linux/key.h>
38 #include <linux/parser.h>
39 #include <linux/fs_stack.h>
40 #include "ecryptfs_kernel.h"
43 * Module parameter that defines the ecryptfs_verbosity level.
45 int ecryptfs_verbosity = 0;
47 module_param(ecryptfs_verbosity, int, 0);
48 MODULE_PARM_DESC(ecryptfs_verbosity,
49 "Initial verbosity level (0 or 1; defaults to "
50 "0, which is Quiet)");
53 * Module parameter that defines the number of netlink message buffer
56 unsigned int ecryptfs_message_buf_len = ECRYPTFS_DEFAULT_MSG_CTX_ELEMS;
58 module_param(ecryptfs_message_buf_len, uint, 0);
59 MODULE_PARM_DESC(ecryptfs_message_buf_len,
60 "Number of message buffer elements");
63 * Module parameter that defines the maximum guaranteed amount of time to wait
64 * for a response through netlink. The actual sleep time will be, more than
65 * likely, a small amount greater than this specified value, but only less if
66 * the netlink message successfully arrives.
68 signed long ecryptfs_message_wait_timeout = ECRYPTFS_MAX_MSG_CTX_TTL / HZ;
70 module_param(ecryptfs_message_wait_timeout, long, 0);
71 MODULE_PARM_DESC(ecryptfs_message_wait_timeout,
72 "Maximum number of seconds that an operation will "
73 "sleep while waiting for a message response from "
77 * Module parameter that is an estimate of the maximum number of users
78 * that will be concurrently using eCryptfs. Set this to the right
79 * value to balance performance and memory use.
81 unsigned int ecryptfs_number_of_users = ECRYPTFS_DEFAULT_NUM_USERS;
83 module_param(ecryptfs_number_of_users, uint, 0);
84 MODULE_PARM_DESC(ecryptfs_number_of_users, "An estimate of the number of "
85 "concurrent users of eCryptfs");
87 unsigned int ecryptfs_transport = ECRYPTFS_DEFAULT_TRANSPORT;
89 void __ecryptfs_printk(const char *fmt, ...)
93 if (fmt[1] == '7') { /* KERN_DEBUG */
94 if (ecryptfs_verbosity >= 1)
103 * @lower_dentry: Existing dentry in the lower filesystem
104 * @dentry: ecryptfs' dentry
105 * @sb: ecryptfs's super_block
106 * @flag: If set to true, then d_add is called, else d_instantiate is called
108 * Interposes upper and lower dentries.
110 * Returns zero on success; non-zero otherwise
112 int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry,
113 struct super_block *sb, int flag)
115 struct inode *lower_inode;
119 lower_inode = lower_dentry->d_inode;
120 if (lower_inode->i_sb != ecryptfs_superblock_to_lower(sb)) {
124 if (!igrab(lower_inode)) {
128 inode = iget5_locked(sb, (unsigned long)lower_inode,
129 ecryptfs_inode_test, ecryptfs_inode_set,
136 if (inode->i_state & I_NEW)
137 unlock_new_inode(inode);
140 if (S_ISLNK(lower_inode->i_mode))
141 inode->i_op = &ecryptfs_symlink_iops;
142 else if (S_ISDIR(lower_inode->i_mode))
143 inode->i_op = &ecryptfs_dir_iops;
144 if (S_ISDIR(lower_inode->i_mode))
145 inode->i_fop = &ecryptfs_dir_fops;
146 if (special_file(lower_inode->i_mode))
147 init_special_inode(inode, lower_inode->i_mode,
148 lower_inode->i_rdev);
149 dentry->d_op = &ecryptfs_dops;
151 d_add(dentry, inode);
153 d_instantiate(dentry, inode);
154 fsstack_copy_attr_all(inode, lower_inode, NULL);
155 /* This size will be overwritten for real files w/ headers and
157 fsstack_copy_inode_size(inode, lower_inode);
162 enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig, ecryptfs_opt_debug,
163 ecryptfs_opt_ecryptfs_debug, ecryptfs_opt_cipher,
164 ecryptfs_opt_ecryptfs_cipher, ecryptfs_opt_ecryptfs_key_bytes,
165 ecryptfs_opt_passthrough, ecryptfs_opt_xattr_metadata,
166 ecryptfs_opt_encrypted_view, ecryptfs_opt_err };
168 static match_table_t tokens = {
169 {ecryptfs_opt_sig, "sig=%s"},
170 {ecryptfs_opt_ecryptfs_sig, "ecryptfs_sig=%s"},
171 {ecryptfs_opt_debug, "debug=%u"},
172 {ecryptfs_opt_ecryptfs_debug, "ecryptfs_debug=%u"},
173 {ecryptfs_opt_cipher, "cipher=%s"},
174 {ecryptfs_opt_ecryptfs_cipher, "ecryptfs_cipher=%s"},
175 {ecryptfs_opt_ecryptfs_key_bytes, "ecryptfs_key_bytes=%u"},
176 {ecryptfs_opt_passthrough, "ecryptfs_passthrough"},
177 {ecryptfs_opt_xattr_metadata, "ecryptfs_xattr_metadata"},
178 {ecryptfs_opt_encrypted_view, "ecryptfs_encrypted_view"},
179 {ecryptfs_opt_err, NULL}
182 static int ecryptfs_init_global_auth_toks(
183 struct ecryptfs_mount_crypt_stat *mount_crypt_stat)
185 struct ecryptfs_global_auth_tok *global_auth_tok;
188 list_for_each_entry(global_auth_tok,
189 &mount_crypt_stat->global_auth_tok_list,
190 mount_crypt_stat_list) {
191 if ((rc = ecryptfs_keyring_auth_tok_for_sig(
192 &global_auth_tok->global_auth_tok_key,
193 &global_auth_tok->global_auth_tok,
194 global_auth_tok->sig))) {
195 printk(KERN_ERR "Could not find valid key in user "
196 "session keyring for sig specified in mount "
197 "option: [%s]\n", global_auth_tok->sig);
198 global_auth_tok->flags |= ECRYPTFS_AUTH_TOK_INVALID;
201 global_auth_tok->flags &= ~ECRYPTFS_AUTH_TOK_INVALID;
206 static void ecryptfs_init_mount_crypt_stat(
207 struct ecryptfs_mount_crypt_stat *mount_crypt_stat)
209 memset((void *)mount_crypt_stat, 0,
210 sizeof(struct ecryptfs_mount_crypt_stat));
211 INIT_LIST_HEAD(&mount_crypt_stat->global_auth_tok_list);
212 mutex_init(&mount_crypt_stat->global_auth_tok_list_mutex);
213 mount_crypt_stat->flags |= ECRYPTFS_MOUNT_CRYPT_STAT_INITIALIZED;
217 * ecryptfs_parse_options
218 * @sb: The ecryptfs super block
219 * @options: The options pased to the kernel
221 * Parse mount options:
222 * debug=N - ecryptfs_verbosity level for debug output
223 * sig=XXX - description(signature) of the key to use
225 * Returns the dentry object of the lower-level (lower/interposed)
226 * directory; We want to mount our stackable file system on top of
227 * that lower directory.
229 * The signature of the key to use must be the description of a key
230 * already in the keyring. Mounting will fail if the key can not be
233 * Returns zero on success; non-zero on error
235 static int ecryptfs_parse_options(struct super_block *sb, char *options)
240 int cipher_name_set = 0;
241 int cipher_key_bytes;
242 int cipher_key_bytes_set = 0;
243 struct key *auth_tok_key = NULL;
244 struct ecryptfs_auth_tok *auth_tok = NULL;
245 struct ecryptfs_mount_crypt_stat *mount_crypt_stat =
246 &ecryptfs_superblock_to_private(sb)->mount_crypt_stat;
247 substring_t args[MAX_OPT_ARGS];
252 char *cipher_name_dst;
253 char *cipher_name_src;
254 char *cipher_key_bytes_src;
261 while ((p = strsep(&options, ",")) != NULL) {
264 token = match_token(p, tokens, args);
266 case ecryptfs_opt_sig:
267 case ecryptfs_opt_ecryptfs_sig:
268 sig_src = args[0].from;
269 rc = ecryptfs_add_global_auth_tok(mount_crypt_stat,
272 printk(KERN_ERR "Error attempting to register "
273 "global sig; rc = [%d]\n", rc);
278 case ecryptfs_opt_debug:
279 case ecryptfs_opt_ecryptfs_debug:
280 debug_src = args[0].from;
282 (int)simple_strtol(debug_src, &debug_src,
284 ecryptfs_printk(KERN_DEBUG,
285 "Verbosity set to [%d]" "\n",
288 case ecryptfs_opt_cipher:
289 case ecryptfs_opt_ecryptfs_cipher:
290 cipher_name_src = args[0].from;
293 global_default_cipher_name;
294 strncpy(cipher_name_dst, cipher_name_src,
295 ECRYPTFS_MAX_CIPHER_NAME_SIZE);
296 ecryptfs_printk(KERN_DEBUG,
297 "The mount_crypt_stat "
298 "global_default_cipher_name set to: "
299 "[%s]\n", cipher_name_dst);
302 case ecryptfs_opt_ecryptfs_key_bytes:
303 cipher_key_bytes_src = args[0].from;
305 (int)simple_strtol(cipher_key_bytes_src,
306 &cipher_key_bytes_src, 0);
307 mount_crypt_stat->global_default_cipher_key_size =
309 ecryptfs_printk(KERN_DEBUG,
310 "The mount_crypt_stat "
311 "global_default_cipher_key_size "
312 "set to: [%d]\n", mount_crypt_stat->
313 global_default_cipher_key_size);
314 cipher_key_bytes_set = 1;
316 case ecryptfs_opt_passthrough:
317 mount_crypt_stat->flags |=
318 ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED;
320 case ecryptfs_opt_xattr_metadata:
321 mount_crypt_stat->flags |=
322 ECRYPTFS_XATTR_METADATA_ENABLED;
324 case ecryptfs_opt_encrypted_view:
325 mount_crypt_stat->flags |=
326 ECRYPTFS_XATTR_METADATA_ENABLED;
327 mount_crypt_stat->flags |=
328 ECRYPTFS_ENCRYPTED_VIEW_ENABLED;
330 case ecryptfs_opt_err:
332 ecryptfs_printk(KERN_WARNING,
333 "eCryptfs: unrecognized option '%s'\n",
337 /* Do not support lack of mount-wide signature in 0.1
341 ecryptfs_printk(KERN_ERR, "You must supply a valid "
342 "passphrase auth tok signature as a mount "
343 "parameter; see the eCryptfs README\n");
346 if (!cipher_name_set) {
347 cipher_name_len = strlen(ECRYPTFS_DEFAULT_CIPHER);
348 if (unlikely(cipher_name_len
349 >= ECRYPTFS_MAX_CIPHER_NAME_SIZE)) {
354 memcpy(mount_crypt_stat->global_default_cipher_name,
355 ECRYPTFS_DEFAULT_CIPHER, cipher_name_len);
356 mount_crypt_stat->global_default_cipher_name[cipher_name_len]
359 if (!cipher_key_bytes_set) {
360 mount_crypt_stat->global_default_cipher_key_size = 0;
362 if ((rc = ecryptfs_add_new_key_tfm(
363 NULL, mount_crypt_stat->global_default_cipher_name,
364 mount_crypt_stat->global_default_cipher_key_size))) {
365 printk(KERN_ERR "Error attempting to initialize cipher with "
366 "name = [%s] and key size = [%d]; rc = [%d]\n",
367 mount_crypt_stat->global_default_cipher_name,
368 mount_crypt_stat->global_default_cipher_key_size, rc);
372 if ((rc = ecryptfs_init_global_auth_toks(mount_crypt_stat))) {
373 printk(KERN_WARNING "One or more global auth toks could not "
374 "properly register; rc = [%d]\n", rc);
381 struct kmem_cache *ecryptfs_sb_info_cache;
384 * ecryptfs_fill_super
385 * @sb: The ecryptfs super block
386 * @raw_data: The options passed to mount
387 * @silent: Not used but required by function prototype
389 * Sets up what we can of the sb, rest is done in ecryptfs_read_super
391 * Returns zero on success; non-zero otherwise
394 ecryptfs_fill_super(struct super_block *sb, void *raw_data, int silent)
398 /* Released in ecryptfs_put_super() */
399 ecryptfs_set_superblock_private(sb,
400 kmem_cache_zalloc(ecryptfs_sb_info_cache,
402 if (!ecryptfs_superblock_to_private(sb)) {
403 ecryptfs_printk(KERN_WARNING, "Out of memory\n");
407 sb->s_op = &ecryptfs_sops;
408 /* Released through deactivate_super(sb) from get_sb_nodev */
409 sb->s_root = d_alloc(NULL, &(const struct qstr) {
410 .hash = 0,.name = "/",.len = 1});
412 ecryptfs_printk(KERN_ERR, "d_alloc failed\n");
416 sb->s_root->d_op = &ecryptfs_dops;
417 sb->s_root->d_sb = sb;
418 sb->s_root->d_parent = sb->s_root;
419 /* Released in d_release when dput(sb->s_root) is called */
420 /* through deactivate_super(sb) from get_sb_nodev() */
421 ecryptfs_set_dentry_private(sb->s_root,
422 kmem_cache_zalloc(ecryptfs_dentry_info_cache,
424 if (!ecryptfs_dentry_to_private(sb->s_root)) {
425 ecryptfs_printk(KERN_ERR,
426 "dentry_info_cache alloc failed\n");
432 /* Should be able to rely on deactivate_super called from
438 * ecryptfs_read_super
439 * @sb: The ecryptfs super block
440 * @dev_name: The path to mount over
442 * Read the super block of the lower filesystem, and use
443 * ecryptfs_interpose to create our initial inode and super block
446 static int ecryptfs_read_super(struct super_block *sb, const char *dev_name)
450 struct dentry *lower_root;
451 struct vfsmount *lower_mnt;
453 memset(&nd, 0, sizeof(struct nameidata));
454 rc = path_lookup(dev_name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &nd);
456 ecryptfs_printk(KERN_WARNING, "path_lookup() failed\n");
459 lower_root = nd.dentry;
461 ecryptfs_set_superblock_lower(sb, lower_root->d_sb);
462 sb->s_maxbytes = lower_root->d_sb->s_maxbytes;
463 ecryptfs_set_dentry_lower(sb->s_root, lower_root);
464 ecryptfs_set_dentry_lower_mnt(sb->s_root, lower_mnt);
465 if ((rc = ecryptfs_interpose(lower_root, sb->s_root, sb, 0)))
479 * @dev_name: The path to mount over
480 * @raw_data: The options passed into the kernel
482 * The whole ecryptfs_get_sb process is broken into 4 functions:
483 * ecryptfs_parse_options(): handle options passed to ecryptfs, if any
484 * ecryptfs_fill_super(): used by get_sb_nodev, fills out the super_block
485 * with as much information as it can before needing
486 * the lower filesystem.
487 * ecryptfs_read_super(): this accesses the lower filesystem and uses
488 * ecryptfs_interpolate to perform most of the linking
489 * ecryptfs_interpolate(): links the lower filesystem into ecryptfs
491 static int ecryptfs_get_sb(struct file_system_type *fs_type, int flags,
492 const char *dev_name, void *raw_data,
493 struct vfsmount *mnt)
496 struct super_block *sb;
498 rc = get_sb_nodev(fs_type, flags, raw_data, ecryptfs_fill_super, mnt);
500 printk(KERN_ERR "Getting sb failed; rc = [%d]\n", rc);
504 rc = ecryptfs_parse_options(sb, raw_data);
506 printk(KERN_ERR "Error parsing options; rc = [%d]\n", rc);
509 rc = ecryptfs_read_super(sb, dev_name);
511 printk(KERN_ERR "Reading sb failed; rc = [%d]\n", rc);
517 up_write(&sb->s_umount);
518 deactivate_super(sb);
524 * ecryptfs_kill_block_super
525 * @sb: The ecryptfs super block
527 * Used to bring the superblock down and free the private data.
528 * Private data is free'd in ecryptfs_put_super()
530 static void ecryptfs_kill_block_super(struct super_block *sb)
532 generic_shutdown_super(sb);
535 static struct file_system_type ecryptfs_fs_type = {
536 .owner = THIS_MODULE,
538 .get_sb = ecryptfs_get_sb,
539 .kill_sb = ecryptfs_kill_block_super,
544 * inode_info_init_once
546 * Initializes the ecryptfs_inode_info_cache when it is created
549 inode_info_init_once(void *vptr, struct kmem_cache *cachep, unsigned long flags)
551 struct ecryptfs_inode_info *ei = (struct ecryptfs_inode_info *)vptr;
553 inode_init_once(&ei->vfs_inode);
556 static struct ecryptfs_cache_info {
557 struct kmem_cache **cache;
560 void (*ctor)(void*, struct kmem_cache *, unsigned long);
561 } ecryptfs_cache_infos[] = {
563 .cache = &ecryptfs_auth_tok_list_item_cache,
564 .name = "ecryptfs_auth_tok_list_item",
565 .size = sizeof(struct ecryptfs_auth_tok_list_item),
568 .cache = &ecryptfs_file_info_cache,
569 .name = "ecryptfs_file_cache",
570 .size = sizeof(struct ecryptfs_file_info),
573 .cache = &ecryptfs_dentry_info_cache,
574 .name = "ecryptfs_dentry_info_cache",
575 .size = sizeof(struct ecryptfs_dentry_info),
578 .cache = &ecryptfs_inode_info_cache,
579 .name = "ecryptfs_inode_cache",
580 .size = sizeof(struct ecryptfs_inode_info),
581 .ctor = inode_info_init_once,
584 .cache = &ecryptfs_sb_info_cache,
585 .name = "ecryptfs_sb_cache",
586 .size = sizeof(struct ecryptfs_sb_info),
589 .cache = &ecryptfs_header_cache_0,
590 .name = "ecryptfs_headers_0",
591 .size = PAGE_CACHE_SIZE,
594 .cache = &ecryptfs_header_cache_1,
595 .name = "ecryptfs_headers_1",
596 .size = PAGE_CACHE_SIZE,
599 .cache = &ecryptfs_header_cache_2,
600 .name = "ecryptfs_headers_2",
601 .size = PAGE_CACHE_SIZE,
604 .cache = &ecryptfs_xattr_cache,
605 .name = "ecryptfs_xattr_cache",
606 .size = PAGE_CACHE_SIZE,
609 .cache = &ecryptfs_lower_page_cache,
610 .name = "ecryptfs_lower_page_cache",
611 .size = PAGE_CACHE_SIZE,
614 .cache = &ecryptfs_key_record_cache,
615 .name = "ecryptfs_key_record_cache",
616 .size = sizeof(struct ecryptfs_key_record),
620 static void ecryptfs_free_kmem_caches(void)
624 for (i = 0; i < ARRAY_SIZE(ecryptfs_cache_infos); i++) {
625 struct ecryptfs_cache_info *info;
627 info = &ecryptfs_cache_infos[i];
629 kmem_cache_destroy(*(info->cache));
634 * ecryptfs_init_kmem_caches
636 * Returns zero on success; non-zero otherwise
638 static int ecryptfs_init_kmem_caches(void)
642 for (i = 0; i < ARRAY_SIZE(ecryptfs_cache_infos); i++) {
643 struct ecryptfs_cache_info *info;
645 info = &ecryptfs_cache_infos[i];
646 *(info->cache) = kmem_cache_create(info->name, info->size,
647 0, SLAB_HWCACHE_ALIGN, info->ctor);
648 if (!*(info->cache)) {
649 ecryptfs_free_kmem_caches();
650 ecryptfs_printk(KERN_WARNING, "%s: "
651 "kmem_cache_create failed\n",
659 struct ecryptfs_obj {
661 struct list_head slot_list;
665 struct ecryptfs_attribute {
666 struct attribute attr;
667 ssize_t(*show) (struct ecryptfs_obj *, char *);
668 ssize_t(*store) (struct ecryptfs_obj *, const char *, size_t);
672 ecryptfs_attr_store(struct kobject *kobj,
673 struct attribute *attr, const char *buf, size_t len)
675 struct ecryptfs_obj *obj = container_of(kobj, struct ecryptfs_obj,
677 struct ecryptfs_attribute *attribute =
678 container_of(attr, struct ecryptfs_attribute, attr);
680 return (attribute->store ? attribute->store(obj, buf, len) : 0);
684 ecryptfs_attr_show(struct kobject *kobj, struct attribute *attr, char *buf)
686 struct ecryptfs_obj *obj = container_of(kobj, struct ecryptfs_obj,
688 struct ecryptfs_attribute *attribute =
689 container_of(attr, struct ecryptfs_attribute, attr);
691 return (attribute->show ? attribute->show(obj, buf) : 0);
694 static struct sysfs_ops ecryptfs_sysfs_ops = {
695 .show = ecryptfs_attr_show,
696 .store = ecryptfs_attr_store
699 static struct kobj_type ecryptfs_ktype = {
700 .sysfs_ops = &ecryptfs_sysfs_ops
703 static decl_subsys(ecryptfs, &ecryptfs_ktype, NULL);
705 static ssize_t version_show(struct ecryptfs_obj *obj, char *buff)
707 return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK);
710 static struct ecryptfs_attribute sysfs_attr_version = __ATTR_RO(version);
712 static struct ecryptfs_version_str_map_elem {
715 } ecryptfs_version_str_map[] = {
716 {ECRYPTFS_VERSIONING_PASSPHRASE, "passphrase"},
717 {ECRYPTFS_VERSIONING_PUBKEY, "pubkey"},
718 {ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH, "plaintext passthrough"},
719 {ECRYPTFS_VERSIONING_POLICY, "policy"},
720 {ECRYPTFS_VERSIONING_XATTR, "metadata in extended attribute"}
723 static ssize_t version_str_show(struct ecryptfs_obj *obj, char *buff)
726 int remaining = PAGE_SIZE;
727 int total_written = 0;
730 for (i = 0; i < ARRAY_SIZE(ecryptfs_version_str_map); i++) {
733 if (!(ECRYPTFS_VERSIONING_MASK
734 & ecryptfs_version_str_map[i].flag))
736 entry_size = strlen(ecryptfs_version_str_map[i].str);
737 if ((entry_size + 2) > remaining)
739 memcpy(buff, ecryptfs_version_str_map[i].str, entry_size);
740 buff[entry_size++] = '\n';
741 buff[entry_size] = '\0';
743 total_written += entry_size;
744 remaining -= entry_size;
747 return total_written;
750 static struct ecryptfs_attribute sysfs_attr_version_str = __ATTR_RO(version_str);
752 static int do_sysfs_registration(void)
756 if ((rc = subsystem_register(&ecryptfs_subsys))) {
758 "Unable to register ecryptfs sysfs subsystem\n");
761 rc = sysfs_create_file(&ecryptfs_subsys.kobj,
762 &sysfs_attr_version.attr);
765 "Unable to create ecryptfs version attribute\n");
766 subsystem_unregister(&ecryptfs_subsys);
769 rc = sysfs_create_file(&ecryptfs_subsys.kobj,
770 &sysfs_attr_version_str.attr);
773 "Unable to create ecryptfs version_str attribute\n");
774 sysfs_remove_file(&ecryptfs_subsys.kobj,
775 &sysfs_attr_version.attr);
776 subsystem_unregister(&ecryptfs_subsys);
783 static void do_sysfs_unregistration(void)
785 sysfs_remove_file(&ecryptfs_subsys.kobj,
786 &sysfs_attr_version.attr);
787 sysfs_remove_file(&ecryptfs_subsys.kobj,
788 &sysfs_attr_version_str.attr);
789 subsystem_unregister(&ecryptfs_subsys);
792 static int __init ecryptfs_init(void)
796 if (ECRYPTFS_DEFAULT_EXTENT_SIZE > PAGE_CACHE_SIZE) {
798 ecryptfs_printk(KERN_ERR, "The eCryptfs extent size is "
799 "larger than the host's page size, and so "
800 "eCryptfs cannot run on this system. The "
801 "default eCryptfs extent size is [%d] bytes; "
802 "the page size is [%d] bytes.\n",
803 ECRYPTFS_DEFAULT_EXTENT_SIZE, PAGE_CACHE_SIZE);
806 rc = ecryptfs_init_kmem_caches();
809 "Failed to allocate one or more kmem_cache objects\n");
812 rc = register_filesystem(&ecryptfs_fs_type);
814 printk(KERN_ERR "Failed to register filesystem\n");
815 ecryptfs_free_kmem_caches();
818 kobj_set_kset_s(&ecryptfs_subsys, fs_subsys);
819 rc = do_sysfs_registration();
821 printk(KERN_ERR "sysfs registration failed\n");
822 unregister_filesystem(&ecryptfs_fs_type);
823 ecryptfs_free_kmem_caches();
826 rc = ecryptfs_init_messaging(ecryptfs_transport);
828 ecryptfs_printk(KERN_ERR, "Failure occured while attempting to "
829 "initialize the eCryptfs netlink socket\n");
830 do_sysfs_unregistration();
831 unregister_filesystem(&ecryptfs_fs_type);
832 ecryptfs_free_kmem_caches();
838 static void __exit ecryptfs_exit(void)
840 do_sysfs_unregistration();
841 ecryptfs_release_messaging(ecryptfs_transport);
842 unregister_filesystem(&ecryptfs_fs_type);
843 ecryptfs_free_kmem_caches();
846 MODULE_AUTHOR("Michael A. Halcrow <mhalcrow@us.ibm.com>");
847 MODULE_DESCRIPTION("eCryptfs");
849 MODULE_LICENSE("GPL");
851 module_init(ecryptfs_init)
852 module_exit(ecryptfs_exit)