main.c (fac56c2df51bc29b07b3c2dcfabf32a015a0522c) main.c (332ab16f830f59e7621ae8eb2c353dc135a316f6)
1/**
2 * eCryptfs: Linux filesystem encryption layer
3 *
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>

--- 82 unchanged lines hidden (view full) ---

91 if (ecryptfs_verbosity >= 1)
92 vprintk(fmt, args);
93 } else
94 vprintk(fmt, args);
95 va_end(args);
96}
97
98/**
1/**
2 * eCryptfs: Linux filesystem encryption layer
3 *
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>

--- 82 unchanged lines hidden (view full) ---

91 if (ecryptfs_verbosity >= 1)
92 vprintk(fmt, args);
93 } else
94 vprintk(fmt, args);
95 va_end(args);
96}
97
98/**
99 * ecryptfs_init_persistent_file
99 * ecryptfs_init_lower_file
100 * @ecryptfs_dentry: Fully initialized eCryptfs dentry object, with
101 * the lower dentry and the lower mount set
102 *
103 * eCryptfs only ever keeps a single open file for every lower
104 * inode. All I/O operations to the lower inode occur through that
105 * file. When the first eCryptfs dentry that interposes with the first
106 * lower dentry for that inode is created, this function creates the
100 * @ecryptfs_dentry: Fully initialized eCryptfs dentry object, with
101 * the lower dentry and the lower mount set
102 *
103 * eCryptfs only ever keeps a single open file for every lower
104 * inode. All I/O operations to the lower inode occur through that
105 * file. When the first eCryptfs dentry that interposes with the first
106 * lower dentry for that inode is created, this function creates the
107 * persistent file struct and associates it with the eCryptfs
108 * inode. When the eCryptfs inode is destroyed, the file is closed.
107 * lower file struct and associates it with the eCryptfs
108 * inode. When all eCryptfs files associated with the inode are released, the
109 * file is closed.
109 *
110 *
110 * The persistent file will be opened with read/write permissions, if
111 * The lower file will be opened with read/write permissions, if
111 * possible. Otherwise, it is opened read-only.
112 *
112 * possible. Otherwise, it is opened read-only.
113 *
113 * This function does nothing if a lower persistent file is already
114 * This function does nothing if a lower file is already
114 * associated with the eCryptfs inode.
115 *
116 * Returns zero on success; non-zero otherwise
117 */
115 * associated with the eCryptfs inode.
116 *
117 * Returns zero on success; non-zero otherwise
118 */
118int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry)
119static int ecryptfs_init_lower_file(struct dentry *dentry,
120 struct file **lower_file)
119{
120 const struct cred *cred = current_cred();
121{
122 const struct cred *cred = current_cred();
121 struct ecryptfs_inode_info *inode_info =
122 ecryptfs_inode_to_private(ecryptfs_dentry->d_inode);
123 int rc = 0;
123 struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
124 struct vfsmount *lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry);
125 int rc;
124
126
125 if (!inode_info->lower_file) {
126 struct dentry *lower_dentry;
127 struct vfsmount *lower_mnt =
128 ecryptfs_dentry_to_lower_mnt(ecryptfs_dentry);
127 rc = ecryptfs_privileged_open(lower_file, lower_dentry, lower_mnt,
128 cred);
129 if (rc) {
130 printk(KERN_ERR "Error opening lower file "
131 "for lower_dentry [0x%p] and lower_mnt [0x%p]; "
132 "rc = [%d]\n", lower_dentry, lower_mnt, rc);
133 (*lower_file) = NULL;
134 }
135 return rc;
136}
129
137
130 lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
131 rc = ecryptfs_privileged_open(&inode_info->lower_file,
132 lower_dentry, lower_mnt, cred);
133 if (rc) {
134 printk(KERN_ERR "Error opening lower persistent file "
135 "for lower_dentry [0x%p] and lower_mnt [0x%p]; "
136 "rc = [%d]\n", lower_dentry, lower_mnt, rc);
137 inode_info->lower_file = NULL;
138 }
138int ecryptfs_get_lower_file(struct dentry *dentry)
139{
140 struct ecryptfs_inode_info *inode_info =
141 ecryptfs_inode_to_private(dentry->d_inode);
142 int count, rc = 0;
143
144 mutex_lock(&inode_info->lower_file_mutex);
145 count = atomic_inc_return(&inode_info->lower_file_count);
146 if (WARN_ON_ONCE(count < 1))
147 rc = -EINVAL;
148 else if (count == 1) {
149 rc = ecryptfs_init_lower_file(dentry,
150 &inode_info->lower_file);
151 if (rc)
152 atomic_set(&inode_info->lower_file_count, 0);
139 }
153 }
154 mutex_unlock(&inode_info->lower_file_mutex);
140 return rc;
141}
142
155 return rc;
156}
157
158void ecryptfs_put_lower_file(struct inode *inode)
159{
160 struct ecryptfs_inode_info *inode_info;
161
162 inode_info = ecryptfs_inode_to_private(inode);
163 if (atomic_dec_and_mutex_lock(&inode_info->lower_file_count,
164 &inode_info->lower_file_mutex)) {
165 fput(inode_info->lower_file);
166 inode_info->lower_file = NULL;
167 mutex_unlock(&inode_info->lower_file_mutex);
168 }
169}
170
143static struct inode *ecryptfs_get_inode(struct inode *lower_inode,
144 struct super_block *sb)
145{
146 struct inode *inode;
147 int rc = 0;
148
149 if (lower_inode->i_sb != ecryptfs_superblock_to_lower(sb)) {
150 rc = -EXDEV;

--- 744 unchanged lines hidden ---
171static struct inode *ecryptfs_get_inode(struct inode *lower_inode,
172 struct super_block *sb)
173{
174 struct inode *inode;
175 int rc = 0;
176
177 if (lower_inode->i_sb != ecryptfs_superblock_to_lower(sb)) {
178 rc = -EXDEV;

--- 744 unchanged lines hidden ---