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/mount.h>
34 #include <linux/pagemap.h>
35 #include <linux/key.h>
36 #include <linux/parser.h>
37 #include <linux/fs_stack.h>
38 #include "ecryptfs_kernel.h"
41 * Module parameter that defines the ecryptfs_verbosity level.
43 int ecryptfs_verbosity
= 0;
45 module_param(ecryptfs_verbosity
, int, 0);
46 MODULE_PARM_DESC(ecryptfs_verbosity
,
47 "Initial verbosity level (0 or 1; defaults to "
48 "0, which is Quiet)");
51 * Module parameter that defines the number of message buffer elements
53 unsigned int ecryptfs_message_buf_len
= ECRYPTFS_DEFAULT_MSG_CTX_ELEMS
;
55 module_param(ecryptfs_message_buf_len
, uint
, 0);
56 MODULE_PARM_DESC(ecryptfs_message_buf_len
,
57 "Number of message buffer elements");
60 * Module parameter that defines the maximum guaranteed amount of time to wait
61 * for a response from ecryptfsd. The actual sleep time will be, more than
62 * likely, a small amount greater than this specified value, but only less if
63 * the message successfully arrives.
65 signed long ecryptfs_message_wait_timeout
= ECRYPTFS_MAX_MSG_CTX_TTL
/ HZ
;
67 module_param(ecryptfs_message_wait_timeout
, long, 0);
68 MODULE_PARM_DESC(ecryptfs_message_wait_timeout
,
69 "Maximum number of seconds that an operation will "
70 "sleep while waiting for a message response from "
74 * Module parameter that is an estimate of the maximum number of users
75 * that will be concurrently using eCryptfs. Set this to the right
76 * value to balance performance and memory use.
78 unsigned int ecryptfs_number_of_users
= ECRYPTFS_DEFAULT_NUM_USERS
;
80 module_param(ecryptfs_number_of_users
, uint
, 0);
81 MODULE_PARM_DESC(ecryptfs_number_of_users
, "An estimate of the number of "
82 "concurrent users of eCryptfs");
84 void __ecryptfs_printk(const char *fmt
, ...)
88 if (fmt
[1] == '7') { /* KERN_DEBUG */
89 if (ecryptfs_verbosity
>= 1)
97 * ecryptfs_init_persistent_file
98 * @ecryptfs_dentry: Fully initialized eCryptfs dentry object, with
99 * the lower dentry and the lower mount set
101 * eCryptfs only ever keeps a single open file for every lower
102 * inode. All I/O operations to the lower inode occur through that
103 * file. When the first eCryptfs dentry that interposes with the first
104 * lower dentry for that inode is created, this function creates the
105 * persistent file struct and associates it with the eCryptfs
106 * inode. When the eCryptfs inode is destroyed, the file is closed.
108 * The persistent file will be opened with read/write permissions, if
109 * possible. Otherwise, it is opened read-only.
111 * This function does nothing if a lower persistent file is already
112 * associated with the eCryptfs inode.
114 * Returns zero on success; non-zero otherwise
116 int ecryptfs_init_persistent_file(struct dentry
*ecryptfs_dentry
)
118 struct ecryptfs_inode_info
*inode_info
=
119 ecryptfs_inode_to_private(ecryptfs_dentry
->d_inode
);
122 mutex_lock(&inode_info
->lower_file_mutex
);
123 if (!inode_info
->lower_file
) {
124 struct dentry
*lower_dentry
;
125 struct vfsmount
*lower_mnt
=
126 ecryptfs_dentry_to_lower_mnt(ecryptfs_dentry
);
128 lower_dentry
= ecryptfs_dentry_to_lower(ecryptfs_dentry
);
129 rc
= ecryptfs_privileged_open(&inode_info
->lower_file
,
130 lower_dentry
, lower_mnt
);
131 if (rc
|| IS_ERR(inode_info
->lower_file
)) {
132 printk(KERN_ERR
"Error opening lower persistent file "
133 "for lower_dentry [0x%p] and lower_mnt [0x%p]; "
134 "rc = [%d]\n", lower_dentry
, lower_mnt
, rc
);
135 rc
= PTR_ERR(inode_info
->lower_file
);
136 inode_info
->lower_file
= NULL
;
139 mutex_unlock(&inode_info
->lower_file_mutex
);
145 * @lower_dentry: Existing dentry in the lower filesystem
146 * @dentry: ecryptfs' dentry
147 * @sb: ecryptfs's super_block
148 * @flags: flags to govern behavior of interpose procedure
150 * Interposes upper and lower dentries.
152 * Returns zero on success; non-zero otherwise
154 int ecryptfs_interpose(struct dentry
*lower_dentry
, struct dentry
*dentry
,
155 struct super_block
*sb
, u32 flags
)
157 struct inode
*lower_inode
;
161 lower_inode
= lower_dentry
->d_inode
;
162 if (lower_inode
->i_sb
!= ecryptfs_superblock_to_lower(sb
)) {
166 if (!igrab(lower_inode
)) {
170 inode
= iget5_locked(sb
, (unsigned long)lower_inode
,
171 ecryptfs_inode_test
, ecryptfs_inode_set
,
178 if (inode
->i_state
& I_NEW
)
179 unlock_new_inode(inode
);
182 if (S_ISLNK(lower_inode
->i_mode
))
183 inode
->i_op
= &ecryptfs_symlink_iops
;
184 else if (S_ISDIR(lower_inode
->i_mode
))
185 inode
->i_op
= &ecryptfs_dir_iops
;
186 if (S_ISDIR(lower_inode
->i_mode
))
187 inode
->i_fop
= &ecryptfs_dir_fops
;
188 if (special_file(lower_inode
->i_mode
))
189 init_special_inode(inode
, lower_inode
->i_mode
,
190 lower_inode
->i_rdev
);
191 dentry
->d_op
= &ecryptfs_dops
;
192 if (flags
& ECRYPTFS_INTERPOSE_FLAG_D_ADD
)
193 d_add(dentry
, inode
);
195 d_instantiate(dentry
, inode
);
196 fsstack_copy_attr_all(inode
, lower_inode
, NULL
);
197 /* This size will be overwritten for real files w/ headers and
199 fsstack_copy_inode_size(inode
, lower_inode
);
204 enum { ecryptfs_opt_sig
, ecryptfs_opt_ecryptfs_sig
,
205 ecryptfs_opt_cipher
, ecryptfs_opt_ecryptfs_cipher
,
206 ecryptfs_opt_ecryptfs_key_bytes
,
207 ecryptfs_opt_passthrough
, ecryptfs_opt_xattr_metadata
,
208 ecryptfs_opt_encrypted_view
, ecryptfs_opt_err
};
210 static const match_table_t tokens
= {
211 {ecryptfs_opt_sig
, "sig=%s"},
212 {ecryptfs_opt_ecryptfs_sig
, "ecryptfs_sig=%s"},
213 {ecryptfs_opt_cipher
, "cipher=%s"},
214 {ecryptfs_opt_ecryptfs_cipher
, "ecryptfs_cipher=%s"},
215 {ecryptfs_opt_ecryptfs_key_bytes
, "ecryptfs_key_bytes=%u"},
216 {ecryptfs_opt_passthrough
, "ecryptfs_passthrough"},
217 {ecryptfs_opt_xattr_metadata
, "ecryptfs_xattr_metadata"},
218 {ecryptfs_opt_encrypted_view
, "ecryptfs_encrypted_view"},
219 {ecryptfs_opt_err
, NULL
}
222 static int ecryptfs_init_global_auth_toks(
223 struct ecryptfs_mount_crypt_stat
*mount_crypt_stat
)
225 struct ecryptfs_global_auth_tok
*global_auth_tok
;
228 list_for_each_entry(global_auth_tok
,
229 &mount_crypt_stat
->global_auth_tok_list
,
230 mount_crypt_stat_list
) {
231 rc
= ecryptfs_keyring_auth_tok_for_sig(
232 &global_auth_tok
->global_auth_tok_key
,
233 &global_auth_tok
->global_auth_tok
,
234 global_auth_tok
->sig
);
236 printk(KERN_ERR
"Could not find valid key in user "
237 "session keyring for sig specified in mount "
238 "option: [%s]\n", global_auth_tok
->sig
);
239 global_auth_tok
->flags
|= ECRYPTFS_AUTH_TOK_INVALID
;
242 global_auth_tok
->flags
&= ~ECRYPTFS_AUTH_TOK_INVALID
;
248 static void ecryptfs_init_mount_crypt_stat(
249 struct ecryptfs_mount_crypt_stat
*mount_crypt_stat
)
251 memset((void *)mount_crypt_stat
, 0,
252 sizeof(struct ecryptfs_mount_crypt_stat
));
253 INIT_LIST_HEAD(&mount_crypt_stat
->global_auth_tok_list
);
254 mutex_init(&mount_crypt_stat
->global_auth_tok_list_mutex
);
255 mount_crypt_stat
->flags
|= ECRYPTFS_MOUNT_CRYPT_STAT_INITIALIZED
;
259 * ecryptfs_parse_options
260 * @sb: The ecryptfs super block
261 * @options: The options pased to the kernel
263 * Parse mount options:
264 * debug=N - ecryptfs_verbosity level for debug output
265 * sig=XXX - description(signature) of the key to use
267 * Returns the dentry object of the lower-level (lower/interposed)
268 * directory; We want to mount our stackable file system on top of
269 * that lower directory.
271 * The signature of the key to use must be the description of a key
272 * already in the keyring. Mounting will fail if the key can not be
275 * Returns zero on success; non-zero on error
277 static int ecryptfs_parse_options(struct super_block
*sb
, char *options
)
282 int cipher_name_set
= 0;
283 int cipher_key_bytes
;
284 int cipher_key_bytes_set
= 0;
285 struct ecryptfs_mount_crypt_stat
*mount_crypt_stat
=
286 &ecryptfs_superblock_to_private(sb
)->mount_crypt_stat
;
287 substring_t args
[MAX_OPT_ARGS
];
290 char *cipher_name_dst
;
291 char *cipher_name_src
;
292 char *cipher_key_bytes_src
;
298 ecryptfs_init_mount_crypt_stat(mount_crypt_stat
);
299 while ((p
= strsep(&options
, ",")) != NULL
) {
302 token
= match_token(p
, tokens
, args
);
304 case ecryptfs_opt_sig
:
305 case ecryptfs_opt_ecryptfs_sig
:
306 sig_src
= args
[0].from
;
307 rc
= ecryptfs_add_global_auth_tok(mount_crypt_stat
,
310 printk(KERN_ERR
"Error attempting to register "
311 "global sig; rc = [%d]\n", rc
);
316 case ecryptfs_opt_cipher
:
317 case ecryptfs_opt_ecryptfs_cipher
:
318 cipher_name_src
= args
[0].from
;
321 global_default_cipher_name
;
322 strncpy(cipher_name_dst
, cipher_name_src
,
323 ECRYPTFS_MAX_CIPHER_NAME_SIZE
);
324 ecryptfs_printk(KERN_DEBUG
,
325 "The mount_crypt_stat "
326 "global_default_cipher_name set to: "
327 "[%s]\n", cipher_name_dst
);
330 case ecryptfs_opt_ecryptfs_key_bytes
:
331 cipher_key_bytes_src
= args
[0].from
;
333 (int)simple_strtol(cipher_key_bytes_src
,
334 &cipher_key_bytes_src
, 0);
335 mount_crypt_stat
->global_default_cipher_key_size
=
337 ecryptfs_printk(KERN_DEBUG
,
338 "The mount_crypt_stat "
339 "global_default_cipher_key_size "
340 "set to: [%d]\n", mount_crypt_stat
->
341 global_default_cipher_key_size
);
342 cipher_key_bytes_set
= 1;
344 case ecryptfs_opt_passthrough
:
345 mount_crypt_stat
->flags
|=
346 ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED
;
348 case ecryptfs_opt_xattr_metadata
:
349 mount_crypt_stat
->flags
|=
350 ECRYPTFS_XATTR_METADATA_ENABLED
;
352 case ecryptfs_opt_encrypted_view
:
353 mount_crypt_stat
->flags
|=
354 ECRYPTFS_XATTR_METADATA_ENABLED
;
355 mount_crypt_stat
->flags
|=
356 ECRYPTFS_ENCRYPTED_VIEW_ENABLED
;
358 case ecryptfs_opt_err
:
360 ecryptfs_printk(KERN_WARNING
,
361 "eCryptfs: unrecognized option '%s'\n",
367 ecryptfs_printk(KERN_ERR
, "You must supply at least one valid "
368 "auth tok signature as a mount "
369 "parameter; see the eCryptfs README\n");
372 if (!cipher_name_set
) {
373 int cipher_name_len
= strlen(ECRYPTFS_DEFAULT_CIPHER
);
375 BUG_ON(cipher_name_len
>= ECRYPTFS_MAX_CIPHER_NAME_SIZE
);
377 strcpy(mount_crypt_stat
->global_default_cipher_name
,
378 ECRYPTFS_DEFAULT_CIPHER
);
380 if (!cipher_key_bytes_set
) {
381 mount_crypt_stat
->global_default_cipher_key_size
= 0;
383 mutex_lock(&key_tfm_list_mutex
);
384 if (!ecryptfs_tfm_exists(mount_crypt_stat
->global_default_cipher_name
,
386 rc
= ecryptfs_add_new_key_tfm(
387 NULL
, mount_crypt_stat
->global_default_cipher_name
,
388 mount_crypt_stat
->global_default_cipher_key_size
);
389 mutex_unlock(&key_tfm_list_mutex
);
391 printk(KERN_ERR
"Error attempting to initialize cipher with "
392 "name = [%s] and key size = [%td]; rc = [%d]\n",
393 mount_crypt_stat
->global_default_cipher_name
,
394 mount_crypt_stat
->global_default_cipher_key_size
, rc
);
398 rc
= ecryptfs_init_global_auth_toks(mount_crypt_stat
);
400 printk(KERN_WARNING
"One or more global auth toks could not "
401 "properly register; rc = [%d]\n", rc
);
407 struct kmem_cache
*ecryptfs_sb_info_cache
;
410 * ecryptfs_fill_super
411 * @sb: The ecryptfs super block
412 * @raw_data: The options passed to mount
413 * @silent: Not used but required by function prototype
415 * Sets up what we can of the sb, rest is done in ecryptfs_read_super
417 * Returns zero on success; non-zero otherwise
420 ecryptfs_fill_super(struct super_block
*sb
, void *raw_data
, int silent
)
424 /* Released in ecryptfs_put_super() */
425 ecryptfs_set_superblock_private(sb
,
426 kmem_cache_zalloc(ecryptfs_sb_info_cache
,
428 if (!ecryptfs_superblock_to_private(sb
)) {
429 ecryptfs_printk(KERN_WARNING
, "Out of memory\n");
433 sb
->s_op
= &ecryptfs_sops
;
434 /* Released through deactivate_super(sb) from get_sb_nodev */
435 sb
->s_root
= d_alloc(NULL
, &(const struct qstr
) {
436 .hash
= 0,.name
= "/",.len
= 1});
438 ecryptfs_printk(KERN_ERR
, "d_alloc failed\n");
442 sb
->s_root
->d_op
= &ecryptfs_dops
;
443 sb
->s_root
->d_sb
= sb
;
444 sb
->s_root
->d_parent
= sb
->s_root
;
445 /* Released in d_release when dput(sb->s_root) is called */
446 /* through deactivate_super(sb) from get_sb_nodev() */
447 ecryptfs_set_dentry_private(sb
->s_root
,
448 kmem_cache_zalloc(ecryptfs_dentry_info_cache
,
450 if (!ecryptfs_dentry_to_private(sb
->s_root
)) {
451 ecryptfs_printk(KERN_ERR
,
452 "dentry_info_cache alloc failed\n");
458 /* Should be able to rely on deactivate_super called from
464 * ecryptfs_read_super
465 * @sb: The ecryptfs super block
466 * @dev_name: The path to mount over
468 * Read the super block of the lower filesystem, and use
469 * ecryptfs_interpose to create our initial inode and super block
472 static int ecryptfs_read_super(struct super_block
*sb
, const char *dev_name
)
477 rc
= kern_path(dev_name
, LOOKUP_FOLLOW
| LOOKUP_DIRECTORY
, &path
);
479 ecryptfs_printk(KERN_WARNING
, "path_lookup() failed\n");
482 ecryptfs_set_superblock_lower(sb
, path
.dentry
->d_sb
);
483 sb
->s_maxbytes
= path
.dentry
->d_sb
->s_maxbytes
;
484 sb
->s_blocksize
= path
.dentry
->d_sb
->s_blocksize
;
485 ecryptfs_set_dentry_lower(sb
->s_root
, path
.dentry
);
486 ecryptfs_set_dentry_lower_mnt(sb
->s_root
, path
.mnt
);
487 rc
= ecryptfs_interpose(path
.dentry
, sb
->s_root
, sb
, 0);
502 * @dev_name: The path to mount over
503 * @raw_data: The options passed into the kernel
505 * The whole ecryptfs_get_sb process is broken into 4 functions:
506 * ecryptfs_parse_options(): handle options passed to ecryptfs, if any
507 * ecryptfs_fill_super(): used by get_sb_nodev, fills out the super_block
508 * with as much information as it can before needing
509 * the lower filesystem.
510 * ecryptfs_read_super(): this accesses the lower filesystem and uses
511 * ecryptfs_interpolate to perform most of the linking
512 * ecryptfs_interpolate(): links the lower filesystem into ecryptfs
514 static int ecryptfs_get_sb(struct file_system_type
*fs_type
, int flags
,
515 const char *dev_name
, void *raw_data
,
516 struct vfsmount
*mnt
)
519 struct super_block
*sb
;
521 rc
= get_sb_nodev(fs_type
, flags
, raw_data
, ecryptfs_fill_super
, mnt
);
523 printk(KERN_ERR
"Getting sb failed; rc = [%d]\n", rc
);
527 rc
= ecryptfs_parse_options(sb
, raw_data
);
529 printk(KERN_ERR
"Error parsing options; rc = [%d]\n", rc
);
532 rc
= ecryptfs_read_super(sb
, dev_name
);
534 printk(KERN_ERR
"Reading sb failed; rc = [%d]\n", rc
);
540 up_write(&sb
->s_umount
);
541 deactivate_super(sb
);
547 * ecryptfs_kill_block_super
548 * @sb: The ecryptfs super block
550 * Used to bring the superblock down and free the private data.
551 * Private data is free'd in ecryptfs_put_super()
553 static void ecryptfs_kill_block_super(struct super_block
*sb
)
555 generic_shutdown_super(sb
);
558 static struct file_system_type ecryptfs_fs_type
= {
559 .owner
= THIS_MODULE
,
561 .get_sb
= ecryptfs_get_sb
,
562 .kill_sb
= ecryptfs_kill_block_super
,
567 * inode_info_init_once
569 * Initializes the ecryptfs_inode_info_cache when it is created
572 inode_info_init_once(void *vptr
)
574 struct ecryptfs_inode_info
*ei
= (struct ecryptfs_inode_info
*)vptr
;
576 inode_init_once(&ei
->vfs_inode
);
579 static struct ecryptfs_cache_info
{
580 struct kmem_cache
**cache
;
583 void (*ctor
)(void *obj
);
584 } ecryptfs_cache_infos
[] = {
586 .cache
= &ecryptfs_auth_tok_list_item_cache
,
587 .name
= "ecryptfs_auth_tok_list_item",
588 .size
= sizeof(struct ecryptfs_auth_tok_list_item
),
591 .cache
= &ecryptfs_file_info_cache
,
592 .name
= "ecryptfs_file_cache",
593 .size
= sizeof(struct ecryptfs_file_info
),
596 .cache
= &ecryptfs_dentry_info_cache
,
597 .name
= "ecryptfs_dentry_info_cache",
598 .size
= sizeof(struct ecryptfs_dentry_info
),
601 .cache
= &ecryptfs_inode_info_cache
,
602 .name
= "ecryptfs_inode_cache",
603 .size
= sizeof(struct ecryptfs_inode_info
),
604 .ctor
= inode_info_init_once
,
607 .cache
= &ecryptfs_sb_info_cache
,
608 .name
= "ecryptfs_sb_cache",
609 .size
= sizeof(struct ecryptfs_sb_info
),
612 .cache
= &ecryptfs_header_cache_1
,
613 .name
= "ecryptfs_headers_1",
614 .size
= PAGE_CACHE_SIZE
,
617 .cache
= &ecryptfs_header_cache_2
,
618 .name
= "ecryptfs_headers_2",
619 .size
= PAGE_CACHE_SIZE
,
622 .cache
= &ecryptfs_xattr_cache
,
623 .name
= "ecryptfs_xattr_cache",
624 .size
= PAGE_CACHE_SIZE
,
627 .cache
= &ecryptfs_key_record_cache
,
628 .name
= "ecryptfs_key_record_cache",
629 .size
= sizeof(struct ecryptfs_key_record
),
632 .cache
= &ecryptfs_key_sig_cache
,
633 .name
= "ecryptfs_key_sig_cache",
634 .size
= sizeof(struct ecryptfs_key_sig
),
637 .cache
= &ecryptfs_global_auth_tok_cache
,
638 .name
= "ecryptfs_global_auth_tok_cache",
639 .size
= sizeof(struct ecryptfs_global_auth_tok
),
642 .cache
= &ecryptfs_key_tfm_cache
,
643 .name
= "ecryptfs_key_tfm_cache",
644 .size
= sizeof(struct ecryptfs_key_tfm
),
647 .cache
= &ecryptfs_open_req_cache
,
648 .name
= "ecryptfs_open_req_cache",
649 .size
= sizeof(struct ecryptfs_open_req
),
653 static void ecryptfs_free_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
];
662 kmem_cache_destroy(*(info
->cache
));
667 * ecryptfs_init_kmem_caches
669 * Returns zero on success; non-zero otherwise
671 static int ecryptfs_init_kmem_caches(void)
675 for (i
= 0; i
< ARRAY_SIZE(ecryptfs_cache_infos
); i
++) {
676 struct ecryptfs_cache_info
*info
;
678 info
= &ecryptfs_cache_infos
[i
];
679 *(info
->cache
) = kmem_cache_create(info
->name
, info
->size
,
680 0, SLAB_HWCACHE_ALIGN
, info
->ctor
);
681 if (!*(info
->cache
)) {
682 ecryptfs_free_kmem_caches();
683 ecryptfs_printk(KERN_WARNING
, "%s: "
684 "kmem_cache_create failed\n",
692 static struct kobject
*ecryptfs_kobj
;
694 static ssize_t
version_show(struct kobject
*kobj
,
695 struct kobj_attribute
*attr
, char *buff
)
697 return snprintf(buff
, PAGE_SIZE
, "%d\n", ECRYPTFS_VERSIONING_MASK
);
700 static struct kobj_attribute version_attr
= __ATTR_RO(version
);
702 static struct attribute
*attributes
[] = {
707 static struct attribute_group attr_group
= {
711 static int do_sysfs_registration(void)
715 ecryptfs_kobj
= kobject_create_and_add("ecryptfs", fs_kobj
);
716 if (!ecryptfs_kobj
) {
717 printk(KERN_ERR
"Unable to create ecryptfs kset\n");
721 rc
= sysfs_create_group(ecryptfs_kobj
, &attr_group
);
724 "Unable to create ecryptfs version attributes\n");
725 kobject_put(ecryptfs_kobj
);
731 static void do_sysfs_unregistration(void)
733 sysfs_remove_group(ecryptfs_kobj
, &attr_group
);
734 kobject_put(ecryptfs_kobj
);
737 static int __init
ecryptfs_init(void)
741 if (ECRYPTFS_DEFAULT_EXTENT_SIZE
> PAGE_CACHE_SIZE
) {
743 ecryptfs_printk(KERN_ERR
, "The eCryptfs extent size is "
744 "larger than the host's page size, and so "
745 "eCryptfs cannot run on this system. The "
746 "default eCryptfs extent size is [%d] bytes; "
747 "the page size is [%d] bytes.\n",
748 ECRYPTFS_DEFAULT_EXTENT_SIZE
, PAGE_CACHE_SIZE
);
751 rc
= ecryptfs_init_kmem_caches();
754 "Failed to allocate one or more kmem_cache objects\n");
757 rc
= register_filesystem(&ecryptfs_fs_type
);
759 printk(KERN_ERR
"Failed to register filesystem\n");
760 goto out_free_kmem_caches
;
762 rc
= do_sysfs_registration();
764 printk(KERN_ERR
"sysfs registration failed\n");
765 goto out_unregister_filesystem
;
767 rc
= ecryptfs_init_kthread();
769 printk(KERN_ERR
"%s: kthread initialization failed; "
770 "rc = [%d]\n", __func__
, rc
);
771 goto out_do_sysfs_unregistration
;
773 rc
= ecryptfs_init_messaging();
775 printk(KERN_ERR
"Failure occured while attempting to "
776 "initialize the communications channel to "
778 goto out_destroy_kthread
;
780 rc
= ecryptfs_init_crypto();
782 printk(KERN_ERR
"Failure whilst attempting to init crypto; "
784 goto out_release_messaging
;
786 if (ecryptfs_verbosity
> 0)
787 printk(KERN_CRIT
"eCryptfs verbosity set to %d. Secret values "
788 "will be written to the syslog!\n", ecryptfs_verbosity
);
791 out_release_messaging
:
792 ecryptfs_release_messaging();
794 ecryptfs_destroy_kthread();
795 out_do_sysfs_unregistration
:
796 do_sysfs_unregistration();
797 out_unregister_filesystem
:
798 unregister_filesystem(&ecryptfs_fs_type
);
799 out_free_kmem_caches
:
800 ecryptfs_free_kmem_caches();
805 static void __exit
ecryptfs_exit(void)
809 rc
= ecryptfs_destroy_crypto();
811 printk(KERN_ERR
"Failure whilst attempting to destroy crypto; "
813 ecryptfs_release_messaging();
814 ecryptfs_destroy_kthread();
815 do_sysfs_unregistration();
816 unregister_filesystem(&ecryptfs_fs_type
);
817 ecryptfs_free_kmem_caches();
820 MODULE_AUTHOR("Michael A. Halcrow <mhalcrow@us.ibm.com>");
821 MODULE_DESCRIPTION("eCryptfs");
823 MODULE_LICENSE("GPL");
825 module_init(ecryptfs_init
)
826 module_exit(ecryptfs_exit
)