~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to fs/ecryptfs/file.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
191
191
                                      | ECRYPTFS_ENCRYPTED);
192
192
        }
193
193
        mutex_unlock(&crypt_stat->cs_mutex);
194
 
        rc = ecryptfs_init_persistent_file(ecryptfs_dentry);
 
194
        rc = ecryptfs_get_lower_file(ecryptfs_dentry, inode);
195
195
        if (rc) {
196
196
                printk(KERN_ERR "%s: Error attempting to initialize "
197
 
                        "the persistent file for the dentry with name "
 
197
                        "the lower file for the dentry with name "
198
198
                        "[%s]; rc = [%d]\n", __func__,
199
199
                        ecryptfs_dentry->d_name.name, rc);
200
200
                goto out_free;
202
202
        if ((ecryptfs_inode_to_private(inode)->lower_file->f_flags & O_ACCMODE)
203
203
            == O_RDONLY && (file->f_flags & O_ACCMODE) != O_RDONLY) {
204
204
                rc = -EPERM;
205
 
                printk(KERN_WARNING "%s: Lower persistent file is RO; eCryptfs "
 
205
                printk(KERN_WARNING "%s: Lower file is RO; eCryptfs "
206
206
                       "file must hence be opened RO\n", __func__);
207
 
                goto out_free;
 
207
                goto out_put;
208
208
        }
209
209
        ecryptfs_set_file_lower(
210
210
                file, ecryptfs_inode_to_private(inode)->lower_file);
232
232
                                       "Plaintext passthrough mode is not "
233
233
                                       "enabled; returning -EIO\n");
234
234
                                mutex_unlock(&crypt_stat->cs_mutex);
235
 
                                goto out_free;
 
235
                                goto out_put;
236
236
                        }
237
237
                        rc = 0;
238
 
                        crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
 
238
                        crypt_stat->flags &= ~(ECRYPTFS_I_SIZE_INITIALIZED
 
239
                                               | ECRYPTFS_ENCRYPTED);
239
240
                        mutex_unlock(&crypt_stat->cs_mutex);
240
241
                        goto out;
241
242
                }
245
246
                        "[0x%.16lx] size: [0x%.16llx]\n", inode, inode->i_ino,
246
247
                        (unsigned long long)i_size_read(inode));
247
248
        goto out;
 
249
out_put:
 
250
        ecryptfs_put_lower_file(inode);
248
251
out_free:
249
252
        kmem_cache_free(ecryptfs_file_info_cache,
250
253
                        ecryptfs_file_to_private(file));
254
257
 
255
258
static int ecryptfs_flush(struct file *file, fl_owner_t td)
256
259
{
257
 
        int rc = 0;
258
 
        struct file *lower_file = NULL;
259
 
 
260
 
        lower_file = ecryptfs_file_to_lower(file);
261
 
        if (lower_file->f_op && lower_file->f_op->flush)
262
 
                rc = lower_file->f_op->flush(lower_file, td);
263
 
        return rc;
 
260
        return file->f_mode & FMODE_WRITE
 
261
               ? filemap_write_and_wait(file->f_mapping) : 0;
264
262
}
265
263
 
266
264
static int ecryptfs_release(struct inode *inode, struct file *file)
267
265
{
 
266
        ecryptfs_put_lower_file(inode);
268
267
        kmem_cache_free(ecryptfs_file_info_cache,
269
268
                        ecryptfs_file_to_private(file));
270
269
        return 0;
273
272
static int
274
273
ecryptfs_fsync(struct file *file, int datasync)
275
274
{
276
 
        return vfs_fsync(ecryptfs_file_to_lower(file), datasync);
 
275
        int rc = 0;
 
276
 
 
277
        rc = generic_file_fsync(file, datasync);
 
278
        if (rc)
 
279
                goto out;
 
280
        rc = vfs_fsync(ecryptfs_file_to_lower(file), datasync);
 
281
out:
 
282
        return rc;
277
283
}
278
284
 
279
285
static int ecryptfs_fasync(int fd, struct file *file, int flag)