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 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);
196 printk(KERN_ERR "Could not find valid key in user "
197 "session keyring for sig specified in mount "
198 "option: [%s]\n", global_auth_tok->sig);
199 global_auth_tok->flags |= ECRYPTFS_AUTH_TOK_INVALID;
202 global_auth_tok->flags &= ~ECRYPTFS_AUTH_TOK_INVALID;
207 static void ecryptfs_init_mount_crypt_stat(
208 struct ecryptfs_mount_crypt_stat *mount_crypt_stat)
210 memset((void *)mount_crypt_stat, 0,
211 sizeof(struct ecryptfs_mount_crypt_stat));
212 INIT_LIST_HEAD(&mount_crypt_stat->global_auth_tok_list);
213 mutex_init(&mount_crypt_stat->global_auth_tok_list_mutex);
214 mount_crypt_stat->flags |= ECRYPTFS_MOUNT_CRYPT_STAT_INITIALIZED;
218 * ecryptfs_parse_options
219 * @sb: The ecryptfs super block
220 * @options: The options pased to the kernel
222 * Parse mount options:
223 * debug=N - ecryptfs_verbosity level for debug output
224 * sig=XXX - description(signature) of the key to use
226 * Returns the dentry object of the lower-level (lower/interposed)
227 * directory; We want to mount our stackable file system on top of
228 * that lower directory.
230 * The signature of the key to use must be the description of a key
231 * already in the keyring. Mounting will fail if the key can not be
234 * Returns zero on success; non-zero on error
236 static int ecryptfs_parse_options(struct super_block *sb, char *options)
241 int cipher_name_set = 0;
242 int cipher_key_bytes;
243 int cipher_key_bytes_set = 0;
244 struct ecryptfs_mount_crypt_stat *mount_crypt_stat =
245 &ecryptfs_superblock_to_private(sb)->mount_crypt_stat;
246 substring_t args[MAX_OPT_ARGS];
250 char *cipher_name_dst;
251 char *cipher_name_src;
252 char *cipher_key_bytes_src;
259 ecryptfs_init_mount_crypt_stat(mount_crypt_stat);
260 while ((p = strsep(&options, ",")) != NULL) {
263 token = match_token(p, tokens, args);
265 case ecryptfs_opt_sig:
266 case ecryptfs_opt_ecryptfs_sig:
267 sig_src = args[0].from;
268 rc = ecryptfs_add_global_auth_tok(mount_crypt_stat,
271 printk(KERN_ERR "Error attempting to register "
272 "global sig; rc = [%d]\n", rc);
277 case ecryptfs_opt_debug:
278 case ecryptfs_opt_ecryptfs_debug:
279 debug_src = args[0].from;
281 (int)simple_strtol(debug_src, &debug_src,
283 ecryptfs_printk(KERN_DEBUG,
284 "Verbosity set to [%d]" "\n",
287 case ecryptfs_opt_cipher:
288 case ecryptfs_opt_ecryptfs_cipher:
289 cipher_name_src = args[0].from;
292 global_default_cipher_name;
293 strncpy(cipher_name_dst, cipher_name_src,
294 ECRYPTFS_MAX_CIPHER_NAME_SIZE);
295 ecryptfs_printk(KERN_DEBUG,
296 "The mount_crypt_stat "
297 "global_default_cipher_name set to: "
298 "[%s]\n", cipher_name_dst);
301 case ecryptfs_opt_ecryptfs_key_bytes:
302 cipher_key_bytes_src = args[0].from;
304 (int)simple_strtol(cipher_key_bytes_src,
305 &cipher_key_bytes_src, 0);
306 mount_crypt_stat->global_default_cipher_key_size =
308 ecryptfs_printk(KERN_DEBUG,
309 "The mount_crypt_stat "
310 "global_default_cipher_key_size "
311 "set to: [%d]\n", mount_crypt_stat->
312 global_default_cipher_key_size);
313 cipher_key_bytes_set = 1;
315 case ecryptfs_opt_passthrough:
316 mount_crypt_stat->flags |=
317 ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED;
319 case ecryptfs_opt_xattr_metadata:
320 mount_crypt_stat->flags |=
321 ECRYPTFS_XATTR_METADATA_ENABLED;
323 case ecryptfs_opt_encrypted_view:
324 mount_crypt_stat->flags |=
325 ECRYPTFS_XATTR_METADATA_ENABLED;
326 mount_crypt_stat->flags |=
327 ECRYPTFS_ENCRYPTED_VIEW_ENABLED;
329 case ecryptfs_opt_err:
331 ecryptfs_printk(KERN_WARNING,
332 "eCryptfs: unrecognized option '%s'\n",
338 ecryptfs_printk(KERN_ERR, "You must supply at least one valid "
339 "auth tok signature as a mount "
340 "parameter; see the eCryptfs README\n");
343 if (!cipher_name_set) {
344 cipher_name_len = strlen(ECRYPTFS_DEFAULT_CIPHER);
345 if (unlikely(cipher_name_len
346 >= ECRYPTFS_MAX_CIPHER_NAME_SIZE)) {
351 memcpy(mount_crypt_stat->global_default_cipher_name,
352 ECRYPTFS_DEFAULT_CIPHER, cipher_name_len);
353 mount_crypt_stat->global_default_cipher_name[cipher_name_len]
356 if (!cipher_key_bytes_set) {
357 mount_crypt_stat->global_default_cipher_key_size = 0;
359 rc = ecryptfs_add_new_key_tfm(
360 NULL, mount_crypt_stat->global_default_cipher_name,
361 mount_crypt_stat->global_default_cipher_key_size);
363 printk(KERN_ERR "Error attempting to initialize cipher with "
364 "name = [%s] and key size = [%td]; rc = [%d]\n",
365 mount_crypt_stat->global_default_cipher_name,
366 mount_crypt_stat->global_default_cipher_key_size, rc);
370 rc = ecryptfs_init_global_auth_toks(mount_crypt_stat);
372 printk(KERN_WARNING "One or more global auth toks could not "
373 "properly register; rc = [%d]\n", rc);
380 struct kmem_cache *ecryptfs_sb_info_cache;
383 * ecryptfs_fill_super
384 * @sb: The ecryptfs super block
385 * @raw_data: The options passed to mount
386 * @silent: Not used but required by function prototype
388 * Sets up what we can of the sb, rest is done in ecryptfs_read_super
390 * Returns zero on success; non-zero otherwise
393 ecryptfs_fill_super(struct super_block *sb, void *raw_data, int silent)
397 /* Released in ecryptfs_put_super() */
398 ecryptfs_set_superblock_private(sb,
399 kmem_cache_zalloc(ecryptfs_sb_info_cache,
401 if (!ecryptfs_superblock_to_private(sb)) {
402 ecryptfs_printk(KERN_WARNING, "Out of memory\n");
406 sb->s_op = &ecryptfs_sops;
407 /* Released through deactivate_super(sb) from get_sb_nodev */
408 sb->s_root = d_alloc(NULL, &(const struct qstr) {
409 .hash = 0,.name = "/",.len = 1});
411 ecryptfs_printk(KERN_ERR, "d_alloc failed\n");
415 sb->s_root->d_op = &ecryptfs_dops;
416 sb->s_root->d_sb = sb;
417 sb->s_root->d_parent = sb->s_root;
418 /* Released in d_release when dput(sb->s_root) is called */
419 /* through deactivate_super(sb) from get_sb_nodev() */
420 ecryptfs_set_dentry_private(sb->s_root,
421 kmem_cache_zalloc(ecryptfs_dentry_info_cache,
423 if (!ecryptfs_dentry_to_private(sb->s_root)) {
424 ecryptfs_printk(KERN_ERR,
425 "dentry_info_cache alloc failed\n");
431 /* Should be able to rely on deactivate_super called from
437 * ecryptfs_read_super
438 * @sb: The ecryptfs super block
439 * @dev_name: The path to mount over
441 * Read the super block of the lower filesystem, and use
442 * ecryptfs_interpose to create our initial inode and super block
445 static int ecryptfs_read_super(struct super_block *sb, const char *dev_name)
449 struct dentry *lower_root;
450 struct vfsmount *lower_mnt;
452 memset(&nd, 0, sizeof(struct nameidata));
453 rc = path_lookup(dev_name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &nd);
455 ecryptfs_printk(KERN_WARNING, "path_lookup() failed\n");
458 lower_root = nd.dentry;
460 ecryptfs_set_superblock_lower(sb, lower_root->d_sb);
461 sb->s_maxbytes = lower_root->d_sb->s_maxbytes;
462 ecryptfs_set_dentry_lower(sb->s_root, lower_root);
463 ecryptfs_set_dentry_lower_mnt(sb->s_root, lower_mnt);
464 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),
619 .cache = &ecryptfs_key_sig_cache,
620 .name = "ecryptfs_key_sig_cache",
621 .size = sizeof(struct ecryptfs_key_sig),
624 .cache = &ecryptfs_global_auth_tok_cache,
625 .name = "ecryptfs_global_auth_tok_cache",
626 .size = sizeof(struct ecryptfs_global_auth_tok),
629 .cache = &ecryptfs_key_tfm_cache,
630 .name = "ecryptfs_key_tfm_cache",
631 .size = sizeof(struct ecryptfs_key_tfm),
635 static void ecryptfs_free_kmem_caches(void)
639 for (i = 0; i < ARRAY_SIZE(ecryptfs_cache_infos); i++) {
640 struct ecryptfs_cache_info *info;
642 info = &ecryptfs_cache_infos[i];
644 kmem_cache_destroy(*(info->cache));
649 * ecryptfs_init_kmem_caches
651 * Returns zero on success; non-zero otherwise
653 static int ecryptfs_init_kmem_caches(void)
657 for (i = 0; i < ARRAY_SIZE(ecryptfs_cache_infos); i++) {
658 struct ecryptfs_cache_info *info;
660 info = &ecryptfs_cache_infos[i];
661 *(info->cache) = kmem_cache_create(info->name, info->size,
662 0, SLAB_HWCACHE_ALIGN, info->ctor);
663 if (!*(info->cache)) {
664 ecryptfs_free_kmem_caches();
665 ecryptfs_printk(KERN_WARNING, "%s: "
666 "kmem_cache_create failed\n",
674 struct ecryptfs_obj {
676 struct list_head slot_list;
680 struct ecryptfs_attribute {
681 struct attribute attr;
682 ssize_t(*show) (struct ecryptfs_obj *, char *);
683 ssize_t(*store) (struct ecryptfs_obj *, const char *, size_t);
687 ecryptfs_attr_store(struct kobject *kobj,
688 struct attribute *attr, const char *buf, size_t len)
690 struct ecryptfs_obj *obj = container_of(kobj, struct ecryptfs_obj,
692 struct ecryptfs_attribute *attribute =
693 container_of(attr, struct ecryptfs_attribute, attr);
695 return (attribute->store ? attribute->store(obj, buf, len) : 0);
699 ecryptfs_attr_show(struct kobject *kobj, struct attribute *attr, char *buf)
701 struct ecryptfs_obj *obj = container_of(kobj, struct ecryptfs_obj,
703 struct ecryptfs_attribute *attribute =
704 container_of(attr, struct ecryptfs_attribute, attr);
706 return (attribute->show ? attribute->show(obj, buf) : 0);
709 static struct sysfs_ops ecryptfs_sysfs_ops = {
710 .show = ecryptfs_attr_show,
711 .store = ecryptfs_attr_store
714 static struct kobj_type ecryptfs_ktype = {
715 .sysfs_ops = &ecryptfs_sysfs_ops
718 static decl_subsys(ecryptfs, &ecryptfs_ktype, NULL);
720 static ssize_t version_show(struct ecryptfs_obj *obj, char *buff)
722 return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK);
725 static struct ecryptfs_attribute sysfs_attr_version = __ATTR_RO(version);
727 static struct ecryptfs_version_str_map_elem {
730 } ecryptfs_version_str_map[] = {
731 {ECRYPTFS_VERSIONING_PASSPHRASE, "passphrase"},
732 {ECRYPTFS_VERSIONING_PUBKEY, "pubkey"},
733 {ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH, "plaintext passthrough"},
734 {ECRYPTFS_VERSIONING_POLICY, "policy"},
735 {ECRYPTFS_VERSIONING_XATTR, "metadata in extended attribute"},
736 {ECRYPTFS_VERSIONING_MULTKEY, "multiple keys per file"}
739 static ssize_t version_str_show(struct ecryptfs_obj *obj, char *buff)
742 int remaining = PAGE_SIZE;
743 int total_written = 0;
746 for (i = 0; i < ARRAY_SIZE(ecryptfs_version_str_map); i++) {
749 if (!(ECRYPTFS_VERSIONING_MASK
750 & ecryptfs_version_str_map[i].flag))
752 entry_size = strlen(ecryptfs_version_str_map[i].str);
753 if ((entry_size + 2) > remaining)
755 memcpy(buff, ecryptfs_version_str_map[i].str, entry_size);
756 buff[entry_size++] = '\n';
757 buff[entry_size] = '\0';
759 total_written += entry_size;
760 remaining -= entry_size;
763 return total_written;
766 static struct ecryptfs_attribute sysfs_attr_version_str = __ATTR_RO(version_str);
768 static int do_sysfs_registration(void)
772 rc = subsystem_register(&ecryptfs_subsys);
775 "Unable to register ecryptfs sysfs subsystem\n");
778 rc = sysfs_create_file(&ecryptfs_subsys.kobj,
779 &sysfs_attr_version.attr);
782 "Unable to create ecryptfs version attribute\n");
783 subsystem_unregister(&ecryptfs_subsys);
786 rc = sysfs_create_file(&ecryptfs_subsys.kobj,
787 &sysfs_attr_version_str.attr);
790 "Unable to create ecryptfs version_str attribute\n");
791 sysfs_remove_file(&ecryptfs_subsys.kobj,
792 &sysfs_attr_version.attr);
793 subsystem_unregister(&ecryptfs_subsys);
800 static void do_sysfs_unregistration(void)
802 sysfs_remove_file(&ecryptfs_subsys.kobj,
803 &sysfs_attr_version.attr);
804 sysfs_remove_file(&ecryptfs_subsys.kobj,
805 &sysfs_attr_version_str.attr);
806 subsystem_unregister(&ecryptfs_subsys);
809 static int __init ecryptfs_init(void)
813 if (ECRYPTFS_DEFAULT_EXTENT_SIZE > PAGE_CACHE_SIZE) {
815 ecryptfs_printk(KERN_ERR, "The eCryptfs extent size is "
816 "larger than the host's page size, and so "
817 "eCryptfs cannot run on this system. The "
818 "default eCryptfs extent size is [%d] bytes; "
819 "the page size is [%d] bytes.\n",
820 ECRYPTFS_DEFAULT_EXTENT_SIZE, PAGE_CACHE_SIZE);
823 rc = ecryptfs_init_kmem_caches();
826 "Failed to allocate one or more kmem_cache objects\n");
829 rc = register_filesystem(&ecryptfs_fs_type);
831 printk(KERN_ERR "Failed to register filesystem\n");
832 goto out_free_kmem_caches;
834 kobj_set_kset_s(&ecryptfs_subsys, fs_subsys);
835 rc = do_sysfs_registration();
837 printk(KERN_ERR "sysfs registration failed\n");
838 goto out_unregister_filesystem;
840 rc = ecryptfs_init_messaging(ecryptfs_transport);
842 ecryptfs_printk(KERN_ERR, "Failure occured while attempting to "
843 "initialize the eCryptfs netlink socket\n");
844 goto out_do_sysfs_unregistration;
846 rc = ecryptfs_init_crypto();
848 printk(KERN_ERR "Failure whilst attempting to init crypto; "
850 goto out_release_messaging;
853 out_release_messaging:
854 ecryptfs_release_messaging(ecryptfs_transport);
855 out_do_sysfs_unregistration:
856 do_sysfs_unregistration();
857 out_unregister_filesystem:
858 unregister_filesystem(&ecryptfs_fs_type);
859 out_free_kmem_caches:
860 ecryptfs_free_kmem_caches();
865 static void __exit ecryptfs_exit(void)
869 rc = ecryptfs_destroy_crypto();
871 printk(KERN_ERR "Failure whilst attempting to destroy crypto; "
873 ecryptfs_release_messaging(ecryptfs_transport);
874 do_sysfs_unregistration();
875 unregister_filesystem(&ecryptfs_fs_type);
876 ecryptfs_free_kmem_caches();
879 MODULE_AUTHOR("Michael A. Halcrow <mhalcrow@us.ibm.com>");
880 MODULE_DESCRIPTION("eCryptfs");
882 MODULE_LICENSE("GPL");
884 module_init(ecryptfs_init)
885 module_exit(ecryptfs_exit)