file.c (9a64e8e0ace51b309fdcff4b4754b3649250382a) | file.c (e3ccaa9761200952cc269b1f4b7d7bb77a5e071b) |
---|---|
1/** 2 * eCryptfs: Linux filesystem encryption layer 3 * 4 * Copyright (C) 1997-2004 Erez Zadok 5 * Copyright (C) 2001-2004 Stony Brook University 6 * Copyright (C) 2004-2007 International Business Machines Corp. 7 * Author(s): Michael A. Halcrow <mhalcrow@us.ibm.com> 8 * Michael C. Thompson <mcthomps@us.ibm.com> --- 147 unchanged lines hidden (view full) --- 156 if (!rc) 157 vma->vm_ops = &ecryptfs_file_vm_ops; 158 159 return rc; 160} 161 162struct kmem_cache *ecryptfs_file_info_cache; 163 | 1/** 2 * eCryptfs: Linux filesystem encryption layer 3 * 4 * Copyright (C) 1997-2004 Erez Zadok 5 * Copyright (C) 2001-2004 Stony Brook University 6 * Copyright (C) 2004-2007 International Business Machines Corp. 7 * Author(s): Michael A. Halcrow <mhalcrow@us.ibm.com> 8 * Michael C. Thompson <mcthomps@us.ibm.com> --- 147 unchanged lines hidden (view full) --- 156 if (!rc) 157 vma->vm_ops = &ecryptfs_file_vm_ops; 158 159 return rc; 160} 161 162struct kmem_cache *ecryptfs_file_info_cache; 163 |
164static int read_or_initialize_metadata(struct dentry *dentry) 165{ 166 struct inode *inode = dentry->d_inode; 167 struct ecryptfs_mount_crypt_stat *mount_crypt_stat; 168 struct ecryptfs_crypt_stat *crypt_stat; 169 int rc; 170 171 crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat; 172 mount_crypt_stat = &ecryptfs_superblock_to_private( 173 inode->i_sb)->mount_crypt_stat; 174 mutex_lock(&crypt_stat->cs_mutex); 175 176 if (crypt_stat->flags & ECRYPTFS_POLICY_APPLIED && 177 crypt_stat->flags & ECRYPTFS_KEY_VALID) { 178 rc = 0; 179 goto out; 180 } 181 182 rc = ecryptfs_read_metadata(dentry); 183 if (!rc) 184 goto out; 185 186 if (mount_crypt_stat->flags & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED) { 187 crypt_stat->flags &= ~(ECRYPTFS_I_SIZE_INITIALIZED 188 | ECRYPTFS_ENCRYPTED); 189 rc = 0; 190 goto out; 191 } 192 193 if (!(mount_crypt_stat->flags & ECRYPTFS_XATTR_METADATA_ENABLED) && 194 !i_size_read(ecryptfs_inode_to_lower(inode))) { 195 rc = ecryptfs_initialize_file(dentry, inode); 196 if (!rc) 197 goto out; 198 } 199 200 rc = -EIO; 201out: 202 mutex_unlock(&crypt_stat->cs_mutex); 203 return rc; 204} 205 |
|
164/** 165 * ecryptfs_open 166 * @inode: inode speciying file to open 167 * @file: Structure to return filled in 168 * 169 * Opens the file specified by inode. 170 * 171 * Returns zero on success; non-zero otherwise --- 59 unchanged lines hidden (view full) --- 231 if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) { 232 ecryptfs_printk(KERN_DEBUG, "This is a directory\n"); 233 mutex_lock(&crypt_stat->cs_mutex); 234 crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED); 235 mutex_unlock(&crypt_stat->cs_mutex); 236 rc = 0; 237 goto out; 238 } | 206/** 207 * ecryptfs_open 208 * @inode: inode speciying file to open 209 * @file: Structure to return filled in 210 * 211 * Opens the file specified by inode. 212 * 213 * Returns zero on success; non-zero otherwise --- 59 unchanged lines hidden (view full) --- 273 if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) { 274 ecryptfs_printk(KERN_DEBUG, "This is a directory\n"); 275 mutex_lock(&crypt_stat->cs_mutex); 276 crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED); 277 mutex_unlock(&crypt_stat->cs_mutex); 278 rc = 0; 279 goto out; 280 } |
239 mutex_lock(&crypt_stat->cs_mutex); 240 if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED) 241 || !(crypt_stat->flags & ECRYPTFS_KEY_VALID)) { 242 rc = ecryptfs_read_metadata(ecryptfs_dentry); 243 if (rc) { 244 ecryptfs_printk(KERN_DEBUG, 245 "Valid headers not found\n"); 246 if (!(mount_crypt_stat->flags 247 & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) { 248 rc = -EIO; 249 printk(KERN_WARNING "Either the lower file " 250 "is not in a valid eCryptfs format, " 251 "or the key could not be retrieved. " 252 "Plaintext passthrough mode is not " 253 "enabled; returning -EIO\n"); 254 mutex_unlock(&crypt_stat->cs_mutex); 255 goto out_put; 256 } 257 rc = 0; 258 crypt_stat->flags &= ~(ECRYPTFS_I_SIZE_INITIALIZED 259 | ECRYPTFS_ENCRYPTED); 260 mutex_unlock(&crypt_stat->cs_mutex); 261 goto out; 262 } 263 } 264 mutex_unlock(&crypt_stat->cs_mutex); | 281 rc = read_or_initialize_metadata(ecryptfs_dentry); 282 if (rc) 283 goto out_put; |
265 ecryptfs_printk(KERN_DEBUG, "inode w/ addr = [0x%p], i_ino = " 266 "[0x%.16lx] size: [0x%.16llx]\n", inode, inode->i_ino, 267 (unsigned long long)i_size_read(inode)); 268 goto out; 269out_put: 270 ecryptfs_put_lower_file(inode); 271out_free: 272 kmem_cache_free(ecryptfs_file_info_cache, --- 107 unchanged lines hidden --- | 284 ecryptfs_printk(KERN_DEBUG, "inode w/ addr = [0x%p], i_ino = " 285 "[0x%.16lx] size: [0x%.16llx]\n", inode, inode->i_ino, 286 (unsigned long long)i_size_read(inode)); 287 goto out; 288out_put: 289 ecryptfs_put_lower_file(inode); 290out_free: 291 kmem_cache_free(ecryptfs_file_info_cache, --- 107 unchanged lines hidden --- |