/* * ecryptfs_read_update_atime * * generic_file_read updates the atime of upper layer inode. But, it * doesn't give us a chance to update the atime of the lower layer * inode. This function is a wrapper to generic_file_read. It * updates the atime of the lower level inode if generic_file_read * returns without any errors. This is to be used only for file reads. * The function to be used for directory reads is ecryptfs_read.
*/ static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb, struct iov_iter *to)
{
ssize_t rc; conststruct path *path; struct file *file = iocb->ki_filp;
/* * ecryptfs_splice_read_update_atime * * filemap_splice_read updates the atime of upper layer inode. But, it * doesn't give us a chance to update the atime of the lower layer inode. This * function is a wrapper to generic_file_read. It updates the atime of the * lower level inode if generic_file_read returns without any errors. This is * to be used only for file reads. The function to be used for directory reads * is ecryptfs_read.
*/ static ssize_t ecryptfs_splice_read_update_atime(struct file *in, loff_t *ppos, struct pipe_inode_info *pipe,
size_t len, unsignedint flags)
{
ssize_t rc; conststruct path *path;
struct ecryptfs_getdents_callback { struct dir_context ctx; struct dir_context *caller; struct super_block *sb; int filldir_called; int entries_written;
};
/* Inspired by generic filldir in fs/readdir.c */ staticbool
ecryptfs_filldir(struct dir_context *ctx, constchar *lower_name, int lower_namelen, loff_t offset, u64 ino, unsignedint d_type)
{ struct ecryptfs_getdents_callback *buf =
container_of(ctx, struct ecryptfs_getdents_callback, ctx);
size_t name_size; char *name; int err; bool res;
buf->filldir_called++;
err = ecryptfs_decode_and_decrypt_filename(&name, &name_size,
buf->sb, lower_name,
lower_namelen); if (err) { if (err != -EINVAL) {
ecryptfs_printk(KERN_DEBUG, "%s: Error attempting to decode and decrypt filename [%s]; rc = [%d]\n",
__func__, lower_name, err); returnfalse;
}
/* Mask -EINVAL errors as these are most likely due a plaintext * filename present in the lower filesystem despite filename * encryption being enabled. One unavoidable example would be * the "lost+found" dentry in the root directory of an Ext4 * filesystem.
*/ returntrue;
}
buf->caller->pos = buf->ctx.pos;
res = dir_emit(buf->caller, name, name_size, ino, d_type);
kfree(name); if (res)
buf->entries_written++; return res;
}
/** * ecryptfs_readdir * @file: The eCryptfs directory file * @ctx: The actor to feed the entries to
*/ staticint ecryptfs_readdir(struct file *file, struct dir_context *ctx)
{ int rc; struct file *lower_file; struct inode *inode = file_inode(file); struct ecryptfs_getdents_callback buf = {
.ctx.actor = ecryptfs_filldir,
.caller = ctx,
.sb = inode->i_sb,
};
lower_file = ecryptfs_file_to_lower(file);
rc = iterate_dir(lower_file, &buf.ctx);
ctx->pos = buf.ctx.pos; if (rc >= 0 && (buf.entries_written || !buf.filldir_called))
fsstack_copy_attr_atime(inode, file_inode(lower_file)); return rc;
}
staticint ecryptfs_mmap(struct file *file, struct vm_area_struct *vma)
{ struct file *lower_file = ecryptfs_file_to_lower(file); /* * Don't allow mmap on top of file systems that don't support it * natively. If FILESYSTEM_MAX_STACK_DEPTH > 2 or ecryptfs * allows recursive mounting, this will need to be extended.
*/ if (!can_mmap_file(lower_file)) return -ENODEV; return generic_file_mmap(file, vma);
}
/** * ecryptfs_open * @inode: inode specifying file to open * @file: Structure to return filled in * * Opens the file specified by inode. * * Returns zero on success; non-zero otherwise
*/ staticint ecryptfs_open(struct inode *inode, struct file *file)
{ int rc = 0; struct ecryptfs_crypt_stat *crypt_stat = NULL; struct dentry *ecryptfs_dentry = file->f_path.dentry; /* Private value of ecryptfs_dentry allocated in
* ecryptfs_lookup() */ struct ecryptfs_file_info *file_info;
/* Released in ecryptfs_release or end of function if failure */
file_info = kmem_cache_zalloc(ecryptfs_file_info_cache, GFP_KERNEL);
ecryptfs_set_file_private(file, file_info); if (!file_info) {
ecryptfs_printk(KERN_ERR, "Error attempting to allocate memory\n");
rc = -ENOMEM; goto out;
}
crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
mutex_lock(&crypt_stat->cs_mutex); if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)) {
ecryptfs_printk(KERN_DEBUG, "Setting flags for stat...\n"); /* Policy code enabled in future release */
crypt_stat->flags |= (ECRYPTFS_POLICY_APPLIED
| ECRYPTFS_ENCRYPTED);
}
mutex_unlock(&crypt_stat->cs_mutex);
rc = ecryptfs_get_lower_file(ecryptfs_dentry, inode); if (rc) {
printk(KERN_ERR "%s: Error attempting to initialize " "the lower file for the dentry with name " "[%pd]; rc = [%d]\n", __func__,
ecryptfs_dentry, rc); goto out_free;
} if ((ecryptfs_inode_to_private(inode)->lower_file->f_flags & O_ACCMODE)
== O_RDONLY && (file->f_flags & O_ACCMODE) != O_RDONLY) {
rc = -EPERM;
printk(KERN_WARNING "%s: Lower file is RO; eCryptfs " "file must hence be opened RO\n", __func__); goto out_put;
}
ecryptfs_set_file_lower(
file, ecryptfs_inode_to_private(inode)->lower_file);
rc = read_or_initialize_metadata(ecryptfs_dentry); if (rc) goto out_put;
ecryptfs_printk(KERN_DEBUG, "inode w/ addr = [0x%p], i_ino = " "[0x%.16lx] size: [0x%.16llx]\n", inode, inode->i_ino,
(unsignedlonglong)i_size_read(inode)); goto out;
out_put:
ecryptfs_put_lower_file(inode);
out_free:
kmem_cache_free(ecryptfs_file_info_cache,
ecryptfs_file_to_private(file));
out: return rc;
}
/** * ecryptfs_dir_open * @inode: inode specifying file to open * @file: Structure to return filled in * * Opens the file specified by inode. * * Returns zero on success; non-zero otherwise
*/ staticint ecryptfs_dir_open(struct inode *inode, struct file *file)
{ struct dentry *ecryptfs_dentry = file->f_path.dentry; /* Private value of ecryptfs_dentry allocated in
* ecryptfs_lookup() */ struct ecryptfs_file_info *file_info; struct file *lower_file;
/* Released in ecryptfs_release or end of function if failure */
file_info = kmem_cache_zalloc(ecryptfs_file_info_cache, GFP_KERNEL);
ecryptfs_set_file_private(file, file_info); if (unlikely(!file_info)) {
ecryptfs_printk(KERN_ERR, "Error attempting to allocate memory\n"); return -ENOMEM;
}
lower_file = dentry_open(ecryptfs_dentry_to_lower_path(ecryptfs_dentry),
file->f_flags, current_cred()); if (IS_ERR(lower_file)) {
printk(KERN_ERR "%s: Error attempting to initialize " "the lower file for the dentry with name " "[%pd]; rc = [%ld]\n", __func__,
ecryptfs_dentry, PTR_ERR(lower_file));
kmem_cache_free(ecryptfs_file_info_cache, file_info); return PTR_ERR(lower_file);
}
ecryptfs_set_file_lower(file, lower_file); return 0;
}
switch (cmd) { case FITRIM: case FS_IOC_GETFLAGS: case FS_IOC_SETFLAGS: case FS_IOC_GETVERSION: case FS_IOC_SETVERSION:
rc = lower_file->f_op->unlocked_ioctl(lower_file, cmd, arg);
fsstack_copy_attr_all(file_inode(file), file_inode(lower_file));
switch (cmd) { case FITRIM: case FS_IOC32_GETFLAGS: case FS_IOC32_SETFLAGS: case FS_IOC32_GETVERSION: case FS_IOC32_SETVERSION:
rc = lower_file->f_op->compat_ioctl(lower_file, cmd, arg);
fsstack_copy_attr_all(file_inode(file), file_inode(lower_file));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.