2005-04-16 15:20:36 -07:00
|
|
|
/*
|
2007-05-08 00:23:18 -07:00
|
|
|
* Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
|
2005-04-16 15:20:36 -07:00
|
|
|
* Licensed under the GPL
|
|
|
|
*
|
|
|
|
* Ported the filesystem routines to 2.5.
|
|
|
|
* 2003-02-10 Petr Baudis <pasky@ucw.cz>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/module.h>
|
2007-10-16 01:27:13 -07:00
|
|
|
#include <linux/mm.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/statfs.h>
|
|
|
|
#include "hostfs.h"
|
|
|
|
#include "init.h"
|
2007-10-16 01:27:13 -07:00
|
|
|
#include "kern.h"
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
struct hostfs_inode_info {
|
|
|
|
char *host_filename;
|
|
|
|
int fd;
|
|
|
|
int mode;
|
|
|
|
struct inode vfs_inode;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct hostfs_inode_info *HOSTFS_I(struct inode *inode)
|
|
|
|
{
|
2007-05-08 00:23:18 -07:00
|
|
|
return list_entry(inode, struct hostfs_inode_info, vfs_inode);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2006-12-08 03:37:05 -07:00
|
|
|
#define FILE_HOSTFS_I(file) HOSTFS_I((file)->f_path.dentry->d_inode)
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
int hostfs_d_delete(struct dentry *dentry)
|
|
|
|
{
|
2007-05-08 00:23:18 -07:00
|
|
|
return 1;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
struct dentry_operations hostfs_dentry_ops = {
|
|
|
|
.d_delete = hostfs_d_delete,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Changed in hostfs_args before the kernel starts running */
|
2007-03-07 21:41:08 -07:00
|
|
|
static char *root_ino = "";
|
2005-04-16 15:20:36 -07:00
|
|
|
static int append = 0;
|
|
|
|
|
|
|
|
#define HOSTFS_SUPER_MAGIC 0x00c0ffee
|
|
|
|
|
2007-02-12 01:55:39 -07:00
|
|
|
static const struct inode_operations hostfs_iops;
|
|
|
|
static const struct inode_operations hostfs_dir_iops;
|
2006-06-28 04:26:44 -07:00
|
|
|
static const struct address_space_operations hostfs_link_aops;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
#ifndef MODULE
|
|
|
|
static int __init hostfs_args(char *options, int *add)
|
|
|
|
{
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
ptr = strchr(options, ',');
|
2007-10-16 01:27:13 -07:00
|
|
|
if (ptr != NULL)
|
2005-04-16 15:20:36 -07:00
|
|
|
*ptr++ = '\0';
|
2007-10-16 01:27:13 -07:00
|
|
|
if (*options != '\0')
|
2005-04-16 15:20:36 -07:00
|
|
|
root_ino = options;
|
|
|
|
|
|
|
|
options = ptr;
|
2007-10-16 01:27:13 -07:00
|
|
|
while (options) {
|
2005-04-16 15:20:36 -07:00
|
|
|
ptr = strchr(options, ',');
|
2007-10-16 01:27:13 -07:00
|
|
|
if (ptr != NULL)
|
2005-04-16 15:20:36 -07:00
|
|
|
*ptr++ = '\0';
|
2007-10-16 01:27:13 -07:00
|
|
|
if (*options != '\0') {
|
|
|
|
if (!strcmp(options, "append"))
|
2005-04-16 15:20:36 -07:00
|
|
|
append = 1;
|
|
|
|
else printf("hostfs_args - unsupported option - %s\n",
|
|
|
|
options);
|
|
|
|
}
|
|
|
|
options = ptr;
|
|
|
|
}
|
2007-05-08 00:23:18 -07:00
|
|
|
return 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
__uml_setup("hostfs=", hostfs_args,
|
|
|
|
"hostfs=<root dir>,<flags>,...\n"
|
|
|
|
" This is used to set hostfs parameters. The root directory argument\n"
|
|
|
|
" is used to confine all hostfs mounts to within the specified directory\n"
|
|
|
|
" tree on the host. If this isn't specified, then a user inside UML can\n"
|
|
|
|
" mount anything on the host that's accessible to the user that's running\n"
|
|
|
|
" it.\n"
|
|
|
|
" The only flag currently supported is 'append', which specifies that all\n"
|
|
|
|
" files opened by hostfs will be opened in append mode.\n\n"
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static char *dentry_name(struct dentry *dentry, int extra)
|
|
|
|
{
|
|
|
|
struct dentry *parent;
|
|
|
|
char *root, *name;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
parent = dentry;
|
2007-10-16 01:27:13 -07:00
|
|
|
while (parent->d_parent != parent) {
|
2005-04-16 15:20:36 -07:00
|
|
|
len += parent->d_name.len + 1;
|
|
|
|
parent = parent->d_parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
root = HOSTFS_I(parent->d_inode)->host_filename;
|
|
|
|
len += strlen(root);
|
|
|
|
name = kmalloc(len + extra + 1, GFP_KERNEL);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (name == NULL)
|
2007-05-08 00:23:18 -07:00
|
|
|
return NULL;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
name[len] = '\0';
|
|
|
|
parent = dentry;
|
2007-10-16 01:27:13 -07:00
|
|
|
while (parent->d_parent != parent) {
|
2005-04-16 15:20:36 -07:00
|
|
|
len -= parent->d_name.len + 1;
|
|
|
|
name[len] = '/';
|
|
|
|
strncpy(&name[len + 1], parent->d_name.name,
|
|
|
|
parent->d_name.len);
|
|
|
|
parent = parent->d_parent;
|
|
|
|
}
|
|
|
|
strncpy(name, root, strlen(root));
|
2007-05-08 00:23:18 -07:00
|
|
|
return name;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *inode_name(struct inode *ino, int extra)
|
|
|
|
{
|
|
|
|
struct dentry *dentry;
|
|
|
|
|
|
|
|
dentry = list_entry(ino->i_dentry.next, struct dentry, d_alias);
|
2007-05-08 00:23:18 -07:00
|
|
|
return dentry_name(dentry, extra);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int read_name(struct inode *ino, char *name)
|
|
|
|
{
|
2007-10-16 01:27:13 -07:00
|
|
|
/*
|
|
|
|
* The non-int inode fields are copied into ints by stat_file and
|
2005-04-16 15:20:36 -07:00
|
|
|
* then copied into the inode because passing the actual pointers
|
|
|
|
* in and having them treated as int * breaks on big-endian machines
|
|
|
|
*/
|
|
|
|
int err;
|
|
|
|
int i_mode, i_nlink, i_blksize;
|
|
|
|
unsigned long long i_size;
|
|
|
|
unsigned long long i_ino;
|
|
|
|
unsigned long long i_blocks;
|
|
|
|
|
|
|
|
err = stat_file(name, &i_ino, &i_mode, &i_nlink, &ino->i_uid,
|
|
|
|
&ino->i_gid, &i_size, &ino->i_atime, &ino->i_mtime,
|
2007-05-08 00:23:16 -07:00
|
|
|
&ino->i_ctime, &i_blksize, &i_blocks, -1);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (err)
|
2007-05-08 00:23:18 -07:00
|
|
|
return err;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
ino->i_ino = i_ino;
|
|
|
|
ino->i_mode = i_mode;
|
|
|
|
ino->i_nlink = i_nlink;
|
|
|
|
ino->i_size = i_size;
|
|
|
|
ino->i_blocks = i_blocks;
|
2007-05-08 00:23:18 -07:00
|
|
|
return 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *follow_link(char *link)
|
|
|
|
{
|
|
|
|
int len, n;
|
|
|
|
char *name, *resolved, *end;
|
|
|
|
|
|
|
|
len = 64;
|
2007-10-16 01:27:13 -07:00
|
|
|
while (1) {
|
2005-04-16 15:20:36 -07:00
|
|
|
n = -ENOMEM;
|
|
|
|
name = kmalloc(len, GFP_KERNEL);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (name == NULL)
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
n = do_readlink(link, name, len);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (n < len)
|
2005-04-16 15:20:36 -07:00
|
|
|
break;
|
|
|
|
len *= 2;
|
|
|
|
kfree(name);
|
|
|
|
}
|
2007-10-16 01:27:13 -07:00
|
|
|
if (n < 0)
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out_free;
|
|
|
|
|
2007-10-16 01:27:13 -07:00
|
|
|
if (*name == '/')
|
2007-05-08 00:23:18 -07:00
|
|
|
return name;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
end = strrchr(link, '/');
|
2007-10-16 01:27:13 -07:00
|
|
|
if (end == NULL)
|
2007-05-08 00:23:18 -07:00
|
|
|
return name;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
*(end + 1) = '\0';
|
|
|
|
len = strlen(link) + strlen(name) + 1;
|
|
|
|
|
|
|
|
resolved = kmalloc(len, GFP_KERNEL);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (resolved == NULL) {
|
2005-04-16 15:20:36 -07:00
|
|
|
n = -ENOMEM;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(resolved, "%s%s", link, name);
|
|
|
|
kfree(name);
|
|
|
|
kfree(link);
|
2007-05-08 00:23:18 -07:00
|
|
|
return resolved;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
out_free:
|
|
|
|
kfree(name);
|
|
|
|
out:
|
2007-05-08 00:23:18 -07:00
|
|
|
return ERR_PTR(n);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2008-02-07 01:15:50 -07:00
|
|
|
static int hostfs_read_inode(struct inode *ino)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
int err = 0;
|
|
|
|
|
2007-10-16 01:27:13 -07:00
|
|
|
/*
|
|
|
|
* Unfortunately, we are called from iget() when we don't have a dentry
|
2005-04-16 15:20:36 -07:00
|
|
|
* allocated yet.
|
|
|
|
*/
|
2007-10-16 01:27:13 -07:00
|
|
|
if (list_empty(&ino->i_dentry))
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
name = inode_name(ino, 0);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (name == NULL)
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out;
|
|
|
|
|
2007-10-16 01:27:13 -07:00
|
|
|
if (file_type(name, NULL, NULL) == OS_TYPE_SYMLINK) {
|
2005-04-16 15:20:36 -07:00
|
|
|
name = follow_link(name);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (IS_ERR(name)) {
|
2005-04-16 15:20:36 -07:00
|
|
|
err = PTR_ERR(name);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err = read_name(ino, name);
|
|
|
|
kfree(name);
|
|
|
|
out:
|
2007-05-08 00:23:18 -07:00
|
|
|
return err;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2008-02-07 01:15:50 -07:00
|
|
|
static struct inode *hostfs_iget(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct inode *inode;
|
|
|
|
long ret;
|
|
|
|
|
|
|
|
inode = iget_locked(sb, 0);
|
|
|
|
if (!inode)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
if (inode->i_state & I_NEW) {
|
|
|
|
ret = hostfs_read_inode(inode);
|
|
|
|
if (ret < 0) {
|
|
|
|
iget_failed(inode);
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
unlock_new_inode(inode);
|
|
|
|
}
|
|
|
|
return inode;
|
|
|
|
}
|
|
|
|
|
2006-06-23 02:02:58 -07:00
|
|
|
int hostfs_statfs(struct dentry *dentry, struct kstatfs *sf)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2007-10-16 01:27:13 -07:00
|
|
|
/*
|
|
|
|
* do_statfs uses struct statfs64 internally, but the linux kernel
|
2005-04-16 15:20:36 -07:00
|
|
|
* struct statfs still has 32-bit versions for most of these fields,
|
|
|
|
* so we convert them here
|
|
|
|
*/
|
|
|
|
int err;
|
|
|
|
long long f_blocks;
|
|
|
|
long long f_bfree;
|
|
|
|
long long f_bavail;
|
|
|
|
long long f_files;
|
|
|
|
long long f_ffree;
|
|
|
|
|
2006-06-23 02:02:58 -07:00
|
|
|
err = do_statfs(HOSTFS_I(dentry->d_sb->s_root->d_inode)->host_filename,
|
2005-04-16 15:20:36 -07:00
|
|
|
&sf->f_bsize, &f_blocks, &f_bfree, &f_bavail, &f_files,
|
|
|
|
&f_ffree, &sf->f_fsid, sizeof(sf->f_fsid),
|
|
|
|
&sf->f_namelen, sf->f_spare);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (err)
|
2007-05-08 00:23:18 -07:00
|
|
|
return err;
|
2005-04-16 15:20:36 -07:00
|
|
|
sf->f_blocks = f_blocks;
|
|
|
|
sf->f_bfree = f_bfree;
|
|
|
|
sf->f_bavail = f_bavail;
|
|
|
|
sf->f_files = f_files;
|
|
|
|
sf->f_ffree = f_ffree;
|
|
|
|
sf->f_type = HOSTFS_SUPER_MAGIC;
|
2007-05-08 00:23:18 -07:00
|
|
|
return 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct inode *hostfs_alloc_inode(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct hostfs_inode_info *hi;
|
|
|
|
|
|
|
|
hi = kmalloc(sizeof(*hi), GFP_KERNEL);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (hi == NULL)
|
2007-05-08 00:23:18 -07:00
|
|
|
return NULL;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
*hi = ((struct hostfs_inode_info) { .host_filename = NULL,
|
|
|
|
.fd = -1,
|
|
|
|
.mode = 0 });
|
|
|
|
inode_init_once(&hi->vfs_inode);
|
2007-05-08 00:23:18 -07:00
|
|
|
return &hi->vfs_inode;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hostfs_delete_inode(struct inode *inode)
|
|
|
|
{
|
2005-09-09 13:01:31 -07:00
|
|
|
truncate_inode_pages(&inode->i_data, 0);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (HOSTFS_I(inode)->fd != -1) {
|
2005-04-16 15:20:36 -07:00
|
|
|
close_file(&HOSTFS_I(inode)->fd);
|
|
|
|
HOSTFS_I(inode)->fd = -1;
|
|
|
|
}
|
|
|
|
clear_inode(inode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hostfs_destroy_inode(struct inode *inode)
|
|
|
|
{
|
2005-11-07 02:01:34 -07:00
|
|
|
kfree(HOSTFS_I(inode)->host_filename);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2007-10-16 01:27:13 -07:00
|
|
|
/*
|
|
|
|
* XXX: This should not happen, probably. The check is here for
|
|
|
|
* additional safety.
|
|
|
|
*/
|
|
|
|
if (HOSTFS_I(inode)->fd != -1) {
|
2005-04-16 15:20:36 -07:00
|
|
|
close_file(&HOSTFS_I(inode)->fd);
|
|
|
|
printk(KERN_DEBUG "Closing host fd in .destroy_inode\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(HOSTFS_I(inode));
|
|
|
|
}
|
|
|
|
|
2007-02-12 01:55:41 -07:00
|
|
|
static const struct super_operations hostfs_sbops = {
|
2005-04-16 15:20:36 -07:00
|
|
|
.alloc_inode = hostfs_alloc_inode,
|
|
|
|
.drop_inode = generic_delete_inode,
|
|
|
|
.delete_inode = hostfs_delete_inode,
|
|
|
|
.destroy_inode = hostfs_destroy_inode,
|
|
|
|
.statfs = hostfs_statfs,
|
|
|
|
};
|
|
|
|
|
|
|
|
int hostfs_readdir(struct file *file, void *ent, filldir_t filldir)
|
|
|
|
{
|
|
|
|
void *dir;
|
|
|
|
char *name;
|
|
|
|
unsigned long long next, ino;
|
|
|
|
int error, len;
|
|
|
|
|
2006-12-08 03:37:05 -07:00
|
|
|
name = dentry_name(file->f_path.dentry, 0);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (name == NULL)
|
2007-05-08 00:23:18 -07:00
|
|
|
return -ENOMEM;
|
2005-04-16 15:20:36 -07:00
|
|
|
dir = open_dir(name, &error);
|
|
|
|
kfree(name);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (dir == NULL)
|
2007-05-08 00:23:18 -07:00
|
|
|
return -error;
|
2005-04-16 15:20:36 -07:00
|
|
|
next = file->f_pos;
|
2007-10-16 01:27:13 -07:00
|
|
|
while ((name = read_dir(dir, &next, &ino, &len)) != NULL) {
|
2005-04-16 15:20:36 -07:00
|
|
|
error = (*filldir)(ent, name, len, file->f_pos,
|
|
|
|
ino, DT_UNKNOWN);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (error) break;
|
2005-04-16 15:20:36 -07:00
|
|
|
file->f_pos = next;
|
|
|
|
}
|
|
|
|
close_dir(dir);
|
2007-05-08 00:23:18 -07:00
|
|
|
return 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int hostfs_file_open(struct inode *ino, struct file *file)
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
int mode = 0, r = 0, w = 0, fd;
|
|
|
|
|
|
|
|
mode = file->f_mode & (FMODE_READ | FMODE_WRITE);
|
2007-10-16 01:27:13 -07:00
|
|
|
if ((mode & HOSTFS_I(ino)->mode) == mode)
|
2007-05-08 00:23:18 -07:00
|
|
|
return 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2007-10-16 01:27:13 -07:00
|
|
|
/*
|
|
|
|
* The file may already have been opened, but with the wrong access,
|
2005-04-16 15:20:36 -07:00
|
|
|
* so this resets things and reopens the file with the new access.
|
|
|
|
*/
|
2007-10-16 01:27:13 -07:00
|
|
|
if (HOSTFS_I(ino)->fd != -1) {
|
2005-04-16 15:20:36 -07:00
|
|
|
close_file(&HOSTFS_I(ino)->fd);
|
|
|
|
HOSTFS_I(ino)->fd = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
HOSTFS_I(ino)->mode |= mode;
|
2007-10-16 01:27:13 -07:00
|
|
|
if (HOSTFS_I(ino)->mode & FMODE_READ)
|
2005-04-16 15:20:36 -07:00
|
|
|
r = 1;
|
2007-10-16 01:27:13 -07:00
|
|
|
if (HOSTFS_I(ino)->mode & FMODE_WRITE)
|
2005-04-16 15:20:36 -07:00
|
|
|
w = 1;
|
2007-10-16 01:27:13 -07:00
|
|
|
if (w)
|
2005-04-16 15:20:36 -07:00
|
|
|
r = 1;
|
|
|
|
|
2006-12-08 03:37:05 -07:00
|
|
|
name = dentry_name(file->f_path.dentry, 0);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (name == NULL)
|
2007-05-08 00:23:18 -07:00
|
|
|
return -ENOMEM;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
fd = open_file(name, r, w, append);
|
|
|
|
kfree(name);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (fd < 0)
|
2007-05-08 00:23:18 -07:00
|
|
|
return fd;
|
2005-04-16 15:20:36 -07:00
|
|
|
FILE_HOSTFS_I(file)->fd = fd;
|
|
|
|
|
2007-05-08 00:23:18 -07:00
|
|
|
return 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int hostfs_fsync(struct file *file, struct dentry *dentry, int datasync)
|
|
|
|
{
|
2005-07-28 21:16:15 -07:00
|
|
|
return fsync_file(HOSTFS_I(dentry->d_inode)->fd, datasync);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2006-03-28 02:56:42 -07:00
|
|
|
static const struct file_operations hostfs_file_fops = {
|
2005-04-16 15:20:36 -07:00
|
|
|
.llseek = generic_file_llseek,
|
2006-09-30 23:28:48 -07:00
|
|
|
.read = do_sync_read,
|
2007-06-01 02:49:19 -07:00
|
|
|
.splice_read = generic_file_splice_read,
|
2005-04-16 15:20:36 -07:00
|
|
|
.aio_read = generic_file_aio_read,
|
|
|
|
.aio_write = generic_file_aio_write,
|
2006-09-30 23:28:48 -07:00
|
|
|
.write = do_sync_write,
|
2005-04-16 15:20:36 -07:00
|
|
|
.mmap = generic_file_mmap,
|
|
|
|
.open = hostfs_file_open,
|
|
|
|
.release = NULL,
|
|
|
|
.fsync = hostfs_fsync,
|
|
|
|
};
|
|
|
|
|
2006-03-28 02:56:42 -07:00
|
|
|
static const struct file_operations hostfs_dir_fops = {
|
2005-04-16 15:20:36 -07:00
|
|
|
.llseek = generic_file_llseek,
|
|
|
|
.readdir = hostfs_readdir,
|
|
|
|
.read = generic_read_dir,
|
|
|
|
};
|
|
|
|
|
|
|
|
int hostfs_writepage(struct page *page, struct writeback_control *wbc)
|
|
|
|
{
|
|
|
|
struct address_space *mapping = page->mapping;
|
|
|
|
struct inode *inode = mapping->host;
|
|
|
|
char *buffer;
|
|
|
|
unsigned long long base;
|
|
|
|
int count = PAGE_CACHE_SIZE;
|
|
|
|
int end_index = inode->i_size >> PAGE_CACHE_SHIFT;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (page->index >= end_index)
|
|
|
|
count = inode->i_size & (PAGE_CACHE_SIZE-1);
|
|
|
|
|
|
|
|
buffer = kmap(page);
|
|
|
|
base = ((unsigned long long) page->index) << PAGE_CACHE_SHIFT;
|
|
|
|
|
|
|
|
err = write_file(HOSTFS_I(inode)->fd, &base, buffer, count);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (err != count) {
|
2005-04-16 15:20:36 -07:00
|
|
|
ClearPageUptodate(page);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (base > inode->i_size)
|
|
|
|
inode->i_size = base;
|
|
|
|
|
|
|
|
if (PageError(page))
|
|
|
|
ClearPageError(page);
|
|
|
|
err = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
kunmap(page);
|
|
|
|
|
|
|
|
unlock_page(page);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int hostfs_readpage(struct file *file, struct page *page)
|
|
|
|
{
|
|
|
|
char *buffer;
|
|
|
|
long long start;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
start = (long long) page->index << PAGE_CACHE_SHIFT;
|
|
|
|
buffer = kmap(page);
|
|
|
|
err = read_file(FILE_HOSTFS_I(file)->fd, &start, buffer,
|
|
|
|
PAGE_CACHE_SIZE);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (err < 0)
|
|
|
|
goto out;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
memset(&buffer[err], 0, PAGE_CACHE_SIZE - err);
|
|
|
|
|
|
|
|
flush_dcache_page(page);
|
|
|
|
SetPageUptodate(page);
|
|
|
|
if (PageError(page)) ClearPageError(page);
|
|
|
|
err = 0;
|
|
|
|
out:
|
|
|
|
kunmap(page);
|
|
|
|
unlock_page(page);
|
2007-05-08 00:23:18 -07:00
|
|
|
return err;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2007-10-16 01:25:17 -07:00
|
|
|
int hostfs_write_begin(struct file *file, struct address_space *mapping,
|
|
|
|
loff_t pos, unsigned len, unsigned flags,
|
|
|
|
struct page **pagep, void **fsdata)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2007-10-16 01:25:17 -07:00
|
|
|
pgoff_t index = pos >> PAGE_CACHE_SHIFT;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2007-10-16 01:25:17 -07:00
|
|
|
*pagep = __grab_cache_page(mapping, index);
|
|
|
|
if (!*pagep)
|
|
|
|
return -ENOMEM;
|
|
|
|
return 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2007-10-16 01:25:17 -07:00
|
|
|
int hostfs_write_end(struct file *file, struct address_space *mapping,
|
|
|
|
loff_t pos, unsigned len, unsigned copied,
|
|
|
|
struct page *page, void *fsdata)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
|
|
|
struct inode *inode = mapping->host;
|
2007-10-16 01:25:17 -07:00
|
|
|
void *buffer;
|
|
|
|
unsigned from = pos & (PAGE_CACHE_SIZE - 1);
|
|
|
|
int err;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
buffer = kmap(page);
|
2007-10-16 01:25:17 -07:00
|
|
|
err = write_file(FILE_HOSTFS_I(file)->fd, &pos, buffer + from, copied);
|
|
|
|
kunmap(page);
|
2005-12-29 09:39:57 -07:00
|
|
|
|
2007-10-16 01:25:17 -07:00
|
|
|
if (!PageUptodate(page) && err == PAGE_CACHE_SIZE)
|
|
|
|
SetPageUptodate(page);
|
2005-12-29 09:39:57 -07:00
|
|
|
|
2007-10-16 01:27:13 -07:00
|
|
|
/*
|
|
|
|
* If err > 0, write_file has added err to pos, so we are comparing
|
2007-10-16 01:25:17 -07:00
|
|
|
* i_size against the last byte written.
|
|
|
|
*/
|
|
|
|
if (err > 0 && (pos > inode->i_size))
|
|
|
|
inode->i_size = pos;
|
|
|
|
unlock_page(page);
|
|
|
|
page_cache_release(page);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2007-05-08 00:23:18 -07:00
|
|
|
return err;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2006-06-28 04:26:44 -07:00
|
|
|
static const struct address_space_operations hostfs_aops = {
|
2005-04-16 15:20:36 -07:00
|
|
|
.writepage = hostfs_writepage,
|
|
|
|
.readpage = hostfs_readpage,
|
2005-05-01 08:58:56 -07:00
|
|
|
.set_page_dirty = __set_page_dirty_nobuffers,
|
2007-10-16 01:25:17 -07:00
|
|
|
.write_begin = hostfs_write_begin,
|
|
|
|
.write_end = hostfs_write_end,
|
2005-04-16 15:20:36 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static int init_inode(struct inode *inode, struct dentry *dentry)
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
int type, err = -ENOMEM;
|
|
|
|
int maj, min;
|
|
|
|
dev_t rdev = 0;
|
|
|
|
|
2007-10-16 01:27:13 -07:00
|
|
|
if (dentry) {
|
2005-04-16 15:20:36 -07:00
|
|
|
name = dentry_name(dentry, 0);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (name == NULL)
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out;
|
|
|
|
type = file_type(name, &maj, &min);
|
2007-10-16 01:27:13 -07:00
|
|
|
/* Reencode maj and min with the kernel encoding.*/
|
2005-04-16 15:20:36 -07:00
|
|
|
rdev = MKDEV(maj, min);
|
|
|
|
kfree(name);
|
|
|
|
}
|
|
|
|
else type = OS_TYPE_DIR;
|
|
|
|
|
|
|
|
err = 0;
|
2007-10-16 01:27:13 -07:00
|
|
|
if (type == OS_TYPE_SYMLINK)
|
2005-04-16 15:20:36 -07:00
|
|
|
inode->i_op = &page_symlink_inode_operations;
|
2007-10-16 01:27:13 -07:00
|
|
|
else if (type == OS_TYPE_DIR)
|
2005-04-16 15:20:36 -07:00
|
|
|
inode->i_op = &hostfs_dir_iops;
|
|
|
|
else inode->i_op = &hostfs_iops;
|
|
|
|
|
2007-10-16 01:27:13 -07:00
|
|
|
if (type == OS_TYPE_DIR) inode->i_fop = &hostfs_dir_fops;
|
2005-04-16 15:20:36 -07:00
|
|
|
else inode->i_fop = &hostfs_file_fops;
|
|
|
|
|
2007-10-16 01:27:13 -07:00
|
|
|
if (type == OS_TYPE_SYMLINK)
|
2005-04-16 15:20:36 -07:00
|
|
|
inode->i_mapping->a_ops = &hostfs_link_aops;
|
|
|
|
else inode->i_mapping->a_ops = &hostfs_aops;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case OS_TYPE_CHARDEV:
|
|
|
|
init_special_inode(inode, S_IFCHR, rdev);
|
|
|
|
break;
|
|
|
|
case OS_TYPE_BLOCKDEV:
|
|
|
|
init_special_inode(inode, S_IFBLK, rdev);
|
|
|
|
break;
|
|
|
|
case OS_TYPE_FIFO:
|
|
|
|
init_special_inode(inode, S_IFIFO, 0);
|
|
|
|
break;
|
|
|
|
case OS_TYPE_SOCK:
|
|
|
|
init_special_inode(inode, S_IFSOCK, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
out:
|
2007-05-08 00:23:18 -07:00
|
|
|
return err;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int hostfs_create(struct inode *dir, struct dentry *dentry, int mode,
|
2007-10-16 01:27:13 -07:00
|
|
|
struct nameidata *nd)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
|
|
|
struct inode *inode;
|
|
|
|
char *name;
|
|
|
|
int error, fd;
|
|
|
|
|
2008-02-07 01:15:50 -07:00
|
|
|
inode = hostfs_iget(dir->i_sb);
|
|
|
|
if (IS_ERR(inode)) {
|
|
|
|
error = PTR_ERR(inode);
|
2007-10-16 01:27:13 -07:00
|
|
|
goto out;
|
2008-02-07 01:15:50 -07:00
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
error = init_inode(inode, dentry);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (error)
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out_put;
|
|
|
|
|
|
|
|
error = -ENOMEM;
|
|
|
|
name = dentry_name(dentry, 0);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (name == NULL)
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out_put;
|
|
|
|
|
|
|
|
fd = file_create(name,
|
|
|
|
mode & S_IRUSR, mode & S_IWUSR, mode & S_IXUSR,
|
|
|
|
mode & S_IRGRP, mode & S_IWGRP, mode & S_IXGRP,
|
|
|
|
mode & S_IROTH, mode & S_IWOTH, mode & S_IXOTH);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (fd < 0)
|
2005-04-16 15:20:36 -07:00
|
|
|
error = fd;
|
|
|
|
else error = read_name(inode, name);
|
|
|
|
|
|
|
|
kfree(name);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (error)
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out_put;
|
|
|
|
|
|
|
|
HOSTFS_I(inode)->fd = fd;
|
|
|
|
HOSTFS_I(inode)->mode = FMODE_READ | FMODE_WRITE;
|
|
|
|
d_instantiate(dentry, inode);
|
2007-05-08 00:23:18 -07:00
|
|
|
return 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
out_put:
|
|
|
|
iput(inode);
|
|
|
|
out:
|
2007-05-08 00:23:18 -07:00
|
|
|
return error;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
struct dentry *hostfs_lookup(struct inode *ino, struct dentry *dentry,
|
2007-05-08 00:23:18 -07:00
|
|
|
struct nameidata *nd)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
|
|
|
struct inode *inode;
|
|
|
|
char *name;
|
|
|
|
int err;
|
|
|
|
|
2008-02-07 01:15:50 -07:00
|
|
|
inode = hostfs_iget(ino->i_sb);
|
|
|
|
if (IS_ERR(inode)) {
|
|
|
|
err = PTR_ERR(inode);
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out;
|
2008-02-07 01:15:50 -07:00
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
err = init_inode(inode, dentry);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (err)
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out_put;
|
|
|
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
name = dentry_name(dentry, 0);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (name == NULL)
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out_put;
|
|
|
|
|
|
|
|
err = read_name(inode, name);
|
|
|
|
kfree(name);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (err == -ENOENT) {
|
2005-04-16 15:20:36 -07:00
|
|
|
iput(inode);
|
|
|
|
inode = NULL;
|
|
|
|
}
|
2007-10-16 01:27:13 -07:00
|
|
|
else if (err)
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out_put;
|
|
|
|
|
|
|
|
d_add(dentry, inode);
|
|
|
|
dentry->d_op = &hostfs_dentry_ops;
|
2007-05-08 00:23:18 -07:00
|
|
|
return NULL;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
out_put:
|
|
|
|
iput(inode);
|
|
|
|
out:
|
2007-05-08 00:23:18 -07:00
|
|
|
return ERR_PTR(err);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *inode_dentry_name(struct inode *ino, struct dentry *dentry)
|
|
|
|
{
|
2007-05-08 00:23:18 -07:00
|
|
|
char *file;
|
2005-04-16 15:20:36 -07:00
|
|
|
int len;
|
|
|
|
|
|
|
|
file = inode_name(ino, dentry->d_name.len + 1);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (file == NULL)
|
2007-05-08 00:23:18 -07:00
|
|
|
return NULL;
|
|
|
|
strcat(file, "/");
|
2005-04-16 15:20:36 -07:00
|
|
|
len = strlen(file);
|
2007-05-08 00:23:18 -07:00
|
|
|
strncat(file, dentry->d_name.name, dentry->d_name.len);
|
2005-04-16 15:20:36 -07:00
|
|
|
file[len + dentry->d_name.len] = '\0';
|
2007-05-08 00:23:18 -07:00
|
|
|
return file;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int hostfs_link(struct dentry *to, struct inode *ino, struct dentry *from)
|
|
|
|
{
|
2007-05-08 00:23:18 -07:00
|
|
|
char *from_name, *to_name;
|
|
|
|
int err;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2007-10-16 01:27:13 -07:00
|
|
|
if ((from_name = inode_dentry_name(ino, from)) == NULL)
|
2007-05-08 00:23:18 -07:00
|
|
|
return -ENOMEM;
|
|
|
|
to_name = dentry_name(to, 0);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (to_name == NULL) {
|
2005-04-16 15:20:36 -07:00
|
|
|
kfree(from_name);
|
2007-05-08 00:23:18 -07:00
|
|
|
return -ENOMEM;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
2007-05-08 00:23:18 -07:00
|
|
|
err = link_file(to_name, from_name);
|
|
|
|
kfree(from_name);
|
|
|
|
kfree(to_name);
|
|
|
|
return err;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int hostfs_unlink(struct inode *ino, struct dentry *dentry)
|
|
|
|
{
|
|
|
|
char *file;
|
|
|
|
int err;
|
|
|
|
|
2007-10-16 01:27:13 -07:00
|
|
|
if ((file = inode_dentry_name(ino, dentry)) == NULL)
|
2007-05-08 00:23:18 -07:00
|
|
|
return -ENOMEM;
|
2007-10-16 01:27:13 -07:00
|
|
|
if (append)
|
2007-05-08 00:23:18 -07:00
|
|
|
return -EPERM;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
err = unlink_file(file);
|
|
|
|
kfree(file);
|
2007-05-08 00:23:18 -07:00
|
|
|
return err;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int hostfs_symlink(struct inode *ino, struct dentry *dentry, const char *to)
|
|
|
|
{
|
|
|
|
char *file;
|
|
|
|
int err;
|
|
|
|
|
2007-10-16 01:27:13 -07:00
|
|
|
if ((file = inode_dentry_name(ino, dentry)) == NULL)
|
2007-05-08 00:23:18 -07:00
|
|
|
return -ENOMEM;
|
2005-04-16 15:20:36 -07:00
|
|
|
err = make_symlink(file, to);
|
|
|
|
kfree(file);
|
2007-05-08 00:23:18 -07:00
|
|
|
return err;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int hostfs_mkdir(struct inode *ino, struct dentry *dentry, int mode)
|
|
|
|
{
|
|
|
|
char *file;
|
|
|
|
int err;
|
|
|
|
|
2007-10-16 01:27:13 -07:00
|
|
|
if ((file = inode_dentry_name(ino, dentry)) == NULL)
|
2007-05-08 00:23:18 -07:00
|
|
|
return -ENOMEM;
|
2005-04-16 15:20:36 -07:00
|
|
|
err = do_mkdir(file, mode);
|
|
|
|
kfree(file);
|
2007-05-08 00:23:18 -07:00
|
|
|
return err;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int hostfs_rmdir(struct inode *ino, struct dentry *dentry)
|
|
|
|
{
|
|
|
|
char *file;
|
|
|
|
int err;
|
|
|
|
|
2007-10-16 01:27:13 -07:00
|
|
|
if ((file = inode_dentry_name(ino, dentry)) == NULL)
|
2007-05-08 00:23:18 -07:00
|
|
|
return -ENOMEM;
|
2005-04-16 15:20:36 -07:00
|
|
|
err = do_rmdir(file);
|
|
|
|
kfree(file);
|
2007-05-08 00:23:18 -07:00
|
|
|
return err;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int hostfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
|
|
|
|
{
|
|
|
|
struct inode *inode;
|
|
|
|
char *name;
|
2008-02-07 01:15:50 -07:00
|
|
|
int err;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2008-02-07 01:15:50 -07:00
|
|
|
inode = hostfs_iget(dir->i_sb);
|
|
|
|
if (IS_ERR(inode)) {
|
|
|
|
err = PTR_ERR(inode);
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out;
|
2008-02-07 01:15:50 -07:00
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
err = init_inode(inode, dentry);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (err)
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out_put;
|
|
|
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
name = dentry_name(dentry, 0);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (name == NULL)
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out_put;
|
|
|
|
|
|
|
|
init_special_inode(inode, mode, dev);
|
2007-01-29 14:19:44 -07:00
|
|
|
err = do_mknod(name, mode, MAJOR(dev), MINOR(dev));
|
2007-10-16 01:27:13 -07:00
|
|
|
if (err)
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
err = read_name(inode, name);
|
|
|
|
kfree(name);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (err)
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out_put;
|
|
|
|
|
|
|
|
d_instantiate(dentry, inode);
|
2007-05-08 00:23:18 -07:00
|
|
|
return 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
out_free:
|
|
|
|
kfree(name);
|
|
|
|
out_put:
|
|
|
|
iput(inode);
|
|
|
|
out:
|
2007-05-08 00:23:18 -07:00
|
|
|
return err;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int hostfs_rename(struct inode *from_ino, struct dentry *from,
|
|
|
|
struct inode *to_ino, struct dentry *to)
|
|
|
|
{
|
|
|
|
char *from_name, *to_name;
|
|
|
|
int err;
|
|
|
|
|
2007-10-16 01:27:13 -07:00
|
|
|
if ((from_name = inode_dentry_name(from_ino, from)) == NULL)
|
2007-05-08 00:23:18 -07:00
|
|
|
return -ENOMEM;
|
2007-10-16 01:27:13 -07:00
|
|
|
if ((to_name = inode_dentry_name(to_ino, to)) == NULL) {
|
2005-04-16 15:20:36 -07:00
|
|
|
kfree(from_name);
|
2007-05-08 00:23:18 -07:00
|
|
|
return -ENOMEM;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
err = rename_file(from_name, to_name);
|
|
|
|
kfree(from_name);
|
|
|
|
kfree(to_name);
|
2007-05-08 00:23:18 -07:00
|
|
|
return err;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int hostfs_permission(struct inode *ino, int desired, struct nameidata *nd)
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
int r = 0, w = 0, x = 0, err;
|
|
|
|
|
|
|
|
if (desired & MAY_READ) r = 1;
|
|
|
|
if (desired & MAY_WRITE) w = 1;
|
|
|
|
if (desired & MAY_EXEC) x = 1;
|
|
|
|
name = inode_name(ino, 0);
|
2007-05-08 00:23:18 -07:00
|
|
|
if (name == NULL)
|
|
|
|
return -ENOMEM;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
if (S_ISCHR(ino->i_mode) || S_ISBLK(ino->i_mode) ||
|
2007-10-16 01:27:13 -07:00
|
|
|
S_ISFIFO(ino->i_mode) || S_ISSOCK(ino->i_mode))
|
2005-04-16 15:20:36 -07:00
|
|
|
err = 0;
|
|
|
|
else
|
|
|
|
err = access_file(name, r, w, x);
|
|
|
|
kfree(name);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (!err)
|
2005-04-16 15:20:36 -07:00
|
|
|
err = generic_permission(ino, desired, NULL);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int hostfs_setattr(struct dentry *dentry, struct iattr *attr)
|
|
|
|
{
|
|
|
|
struct hostfs_iattr attrs;
|
|
|
|
char *name;
|
|
|
|
int err;
|
|
|
|
|
2007-05-08 00:23:16 -07:00
|
|
|
int fd = HOSTFS_I(dentry->d_inode)->fd;
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
err = inode_change_ok(dentry->d_inode, attr);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2007-10-16 01:27:13 -07:00
|
|
|
if (append)
|
2005-04-16 15:20:36 -07:00
|
|
|
attr->ia_valid &= ~ATTR_SIZE;
|
|
|
|
|
|
|
|
attrs.ia_valid = 0;
|
2007-10-16 01:27:13 -07:00
|
|
|
if (attr->ia_valid & ATTR_MODE) {
|
2005-04-16 15:20:36 -07:00
|
|
|
attrs.ia_valid |= HOSTFS_ATTR_MODE;
|
|
|
|
attrs.ia_mode = attr->ia_mode;
|
|
|
|
}
|
2007-10-16 01:27:13 -07:00
|
|
|
if (attr->ia_valid & ATTR_UID) {
|
2005-04-16 15:20:36 -07:00
|
|
|
attrs.ia_valid |= HOSTFS_ATTR_UID;
|
|
|
|
attrs.ia_uid = attr->ia_uid;
|
|
|
|
}
|
2007-10-16 01:27:13 -07:00
|
|
|
if (attr->ia_valid & ATTR_GID) {
|
2005-04-16 15:20:36 -07:00
|
|
|
attrs.ia_valid |= HOSTFS_ATTR_GID;
|
|
|
|
attrs.ia_gid = attr->ia_gid;
|
|
|
|
}
|
2007-10-16 01:27:13 -07:00
|
|
|
if (attr->ia_valid & ATTR_SIZE) {
|
2005-04-16 15:20:36 -07:00
|
|
|
attrs.ia_valid |= HOSTFS_ATTR_SIZE;
|
|
|
|
attrs.ia_size = attr->ia_size;
|
|
|
|
}
|
2007-10-16 01:27:13 -07:00
|
|
|
if (attr->ia_valid & ATTR_ATIME) {
|
2005-04-16 15:20:36 -07:00
|
|
|
attrs.ia_valid |= HOSTFS_ATTR_ATIME;
|
|
|
|
attrs.ia_atime = attr->ia_atime;
|
|
|
|
}
|
2007-10-16 01:27:13 -07:00
|
|
|
if (attr->ia_valid & ATTR_MTIME) {
|
2005-04-16 15:20:36 -07:00
|
|
|
attrs.ia_valid |= HOSTFS_ATTR_MTIME;
|
|
|
|
attrs.ia_mtime = attr->ia_mtime;
|
|
|
|
}
|
2007-10-16 01:27:13 -07:00
|
|
|
if (attr->ia_valid & ATTR_CTIME) {
|
2005-04-16 15:20:36 -07:00
|
|
|
attrs.ia_valid |= HOSTFS_ATTR_CTIME;
|
|
|
|
attrs.ia_ctime = attr->ia_ctime;
|
|
|
|
}
|
2007-10-16 01:27:13 -07:00
|
|
|
if (attr->ia_valid & ATTR_ATIME_SET) {
|
2005-04-16 15:20:36 -07:00
|
|
|
attrs.ia_valid |= HOSTFS_ATTR_ATIME_SET;
|
|
|
|
}
|
2007-10-16 01:27:13 -07:00
|
|
|
if (attr->ia_valid & ATTR_MTIME_SET) {
|
2005-04-16 15:20:36 -07:00
|
|
|
attrs.ia_valid |= HOSTFS_ATTR_MTIME_SET;
|
|
|
|
}
|
|
|
|
name = dentry_name(dentry, 0);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (name == NULL)
|
2007-05-08 00:23:18 -07:00
|
|
|
return -ENOMEM;
|
2007-05-08 00:23:16 -07:00
|
|
|
err = set_attr(name, &attrs, fd);
|
2005-04-16 15:20:36 -07:00
|
|
|
kfree(name);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (err)
|
2007-05-08 00:23:18 -07:00
|
|
|
return err;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2007-05-08 00:23:18 -07:00
|
|
|
return inode_setattr(dentry->d_inode, attr);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2007-02-12 01:55:39 -07:00
|
|
|
static const struct inode_operations hostfs_iops = {
|
2005-04-16 15:20:36 -07:00
|
|
|
.create = hostfs_create,
|
|
|
|
.link = hostfs_link,
|
|
|
|
.unlink = hostfs_unlink,
|
|
|
|
.symlink = hostfs_symlink,
|
|
|
|
.mkdir = hostfs_mkdir,
|
|
|
|
.rmdir = hostfs_rmdir,
|
|
|
|
.mknod = hostfs_mknod,
|
|
|
|
.rename = hostfs_rename,
|
|
|
|
.permission = hostfs_permission,
|
|
|
|
.setattr = hostfs_setattr,
|
|
|
|
};
|
|
|
|
|
2007-02-12 01:55:39 -07:00
|
|
|
static const struct inode_operations hostfs_dir_iops = {
|
2005-04-16 15:20:36 -07:00
|
|
|
.create = hostfs_create,
|
|
|
|
.lookup = hostfs_lookup,
|
|
|
|
.link = hostfs_link,
|
|
|
|
.unlink = hostfs_unlink,
|
|
|
|
.symlink = hostfs_symlink,
|
|
|
|
.mkdir = hostfs_mkdir,
|
|
|
|
.rmdir = hostfs_rmdir,
|
|
|
|
.mknod = hostfs_mknod,
|
|
|
|
.rename = hostfs_rename,
|
|
|
|
.permission = hostfs_permission,
|
|
|
|
.setattr = hostfs_setattr,
|
|
|
|
};
|
|
|
|
|
|
|
|
int hostfs_link_readpage(struct file *file, struct page *page)
|
|
|
|
{
|
|
|
|
char *buffer, *name;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
buffer = kmap(page);
|
|
|
|
name = inode_name(page->mapping->host, 0);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (name == NULL)
|
2007-05-08 00:23:18 -07:00
|
|
|
return -ENOMEM;
|
2005-04-16 15:20:36 -07:00
|
|
|
err = do_readlink(name, buffer, PAGE_CACHE_SIZE);
|
|
|
|
kfree(name);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (err == PAGE_CACHE_SIZE)
|
2005-04-16 15:20:36 -07:00
|
|
|
err = -E2BIG;
|
2007-10-16 01:27:13 -07:00
|
|
|
else if (err > 0) {
|
2005-04-16 15:20:36 -07:00
|
|
|
flush_dcache_page(page);
|
|
|
|
SetPageUptodate(page);
|
|
|
|
if (PageError(page)) ClearPageError(page);
|
|
|
|
err = 0;
|
|
|
|
}
|
|
|
|
kunmap(page);
|
|
|
|
unlock_page(page);
|
2007-05-08 00:23:18 -07:00
|
|
|
return err;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2006-06-28 04:26:44 -07:00
|
|
|
static const struct address_space_operations hostfs_link_aops = {
|
2005-04-16 15:20:36 -07:00
|
|
|
.readpage = hostfs_link_readpage,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int hostfs_fill_sb_common(struct super_block *sb, void *d, int silent)
|
|
|
|
{
|
|
|
|
struct inode *root_inode;
|
2007-03-29 01:20:33 -07:00
|
|
|
char *host_root_path, *req_root = d;
|
2005-04-16 15:20:36 -07:00
|
|
|
int err;
|
|
|
|
|
|
|
|
sb->s_blocksize = 1024;
|
|
|
|
sb->s_blocksize_bits = 10;
|
|
|
|
sb->s_magic = HOSTFS_SUPER_MAGIC;
|
|
|
|
sb->s_op = &hostfs_sbops;
|
|
|
|
|
2007-03-07 21:41:08 -07:00
|
|
|
/* NULL is printed as <NULL> by sprintf: avoid that. */
|
2007-03-29 01:20:33 -07:00
|
|
|
if (req_root == NULL)
|
|
|
|
req_root = "";
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
err = -ENOMEM;
|
2007-03-29 01:20:33 -07:00
|
|
|
host_root_path = kmalloc(strlen(root_ino) + 1
|
|
|
|
+ strlen(req_root) + 1, GFP_KERNEL);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (host_root_path == NULL)
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out;
|
|
|
|
|
2007-03-29 01:20:33 -07:00
|
|
|
sprintf(host_root_path, "%s/%s", root_ino, req_root);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2008-02-07 01:15:50 -07:00
|
|
|
root_inode = hostfs_iget(sb);
|
|
|
|
if (IS_ERR(root_inode)) {
|
|
|
|
err = PTR_ERR(root_inode);
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out_free;
|
2008-02-07 01:15:50 -07:00
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
err = init_inode(root_inode, NULL);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (err)
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out_put;
|
|
|
|
|
2007-03-29 01:20:33 -07:00
|
|
|
HOSTFS_I(root_inode)->host_filename = host_root_path;
|
2007-10-16 01:27:13 -07:00
|
|
|
/*
|
|
|
|
* Avoid that in the error path, iput(root_inode) frees again
|
|
|
|
* host_root_path through hostfs_destroy_inode!
|
|
|
|
*/
|
2007-03-29 01:20:33 -07:00
|
|
|
host_root_path = NULL;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
sb->s_root = d_alloc_root(root_inode);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (sb->s_root == NULL)
|
2005-04-16 15:20:36 -07:00
|
|
|
goto out_put;
|
|
|
|
|
2008-02-07 01:15:50 -07:00
|
|
|
err = hostfs_read_inode(root_inode);
|
2007-10-16 01:27:13 -07:00
|
|
|
if (err) {
|
2007-05-08 00:23:18 -07:00
|
|
|
/* No iput in this case because the dput does that for us */
|
|
|
|
dput(sb->s_root);
|
|
|
|
sb->s_root = NULL;
|
2007-03-07 21:41:07 -07:00
|
|
|
goto out;
|
2007-05-08 00:23:18 -07:00
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2007-05-08 00:23:18 -07:00
|
|
|
return 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2007-05-08 00:23:18 -07:00
|
|
|
out_put:
|
|
|
|
iput(root_inode);
|
|
|
|
out_free:
|
2007-03-29 01:20:33 -07:00
|
|
|
kfree(host_root_path);
|
2007-05-08 00:23:18 -07:00
|
|
|
out:
|
|
|
|
return err;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
[PATCH] VFS: Permit filesystem to override root dentry on mount
Extend the get_sb() filesystem operation to take an extra argument that
permits the VFS to pass in the target vfsmount that defines the mountpoint.
The filesystem is then required to manually set the superblock and root dentry
pointers. For most filesystems, this should be done with simple_set_mnt()
which will set the superblock pointer and then set the root dentry to the
superblock's s_root (as per the old default behaviour).
The get_sb() op now returns an integer as there's now no need to return the
superblock pointer.
This patch permits a superblock to be implicitly shared amongst several mount
points, such as can be done with NFS to avoid potential inode aliasing. In
such a case, simple_set_mnt() would not be called, and instead the mnt_root
and mnt_sb would be set directly.
The patch also makes the following changes:
(*) the get_sb_*() convenience functions in the core kernel now take a vfsmount
pointer argument and return an integer, so most filesystems have to change
very little.
(*) If one of the convenience function is not used, then get_sb() should
normally call simple_set_mnt() to instantiate the vfsmount. This will
always return 0, and so can be tail-called from get_sb().
(*) generic_shutdown_super() now calls shrink_dcache_sb() to clean up the
dcache upon superblock destruction rather than shrink_dcache_anon().
This is required because the superblock may now have multiple trees that
aren't actually bound to s_root, but that still need to be cleaned up. The
currently called functions assume that the whole tree is rooted at s_root,
and that anonymous dentries are not the roots of trees which results in
dentries being left unculled.
However, with the way NFS superblock sharing are currently set to be
implemented, these assumptions are violated: the root of the filesystem is
simply a dummy dentry and inode (the real inode for '/' may well be
inaccessible), and all the vfsmounts are rooted on anonymous[*] dentries
with child trees.
[*] Anonymous until discovered from another tree.
(*) The documentation has been adjusted, including the additional bit of
changing ext2_* into foo_* in the documentation.
[akpm@osdl.org: convert ipath_fs, do other stuff]
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Cc: Nathan Scott <nathans@sgi.com>
Cc: Roland Dreier <rolandd@cisco.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-23 02:02:57 -07:00
|
|
|
static int hostfs_read_sb(struct file_system_type *type,
|
|
|
|
int flags, const char *dev_name,
|
|
|
|
void *data, struct vfsmount *mnt)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
[PATCH] VFS: Permit filesystem to override root dentry on mount
Extend the get_sb() filesystem operation to take an extra argument that
permits the VFS to pass in the target vfsmount that defines the mountpoint.
The filesystem is then required to manually set the superblock and root dentry
pointers. For most filesystems, this should be done with simple_set_mnt()
which will set the superblock pointer and then set the root dentry to the
superblock's s_root (as per the old default behaviour).
The get_sb() op now returns an integer as there's now no need to return the
superblock pointer.
This patch permits a superblock to be implicitly shared amongst several mount
points, such as can be done with NFS to avoid potential inode aliasing. In
such a case, simple_set_mnt() would not be called, and instead the mnt_root
and mnt_sb would be set directly.
The patch also makes the following changes:
(*) the get_sb_*() convenience functions in the core kernel now take a vfsmount
pointer argument and return an integer, so most filesystems have to change
very little.
(*) If one of the convenience function is not used, then get_sb() should
normally call simple_set_mnt() to instantiate the vfsmount. This will
always return 0, and so can be tail-called from get_sb().
(*) generic_shutdown_super() now calls shrink_dcache_sb() to clean up the
dcache upon superblock destruction rather than shrink_dcache_anon().
This is required because the superblock may now have multiple trees that
aren't actually bound to s_root, but that still need to be cleaned up. The
currently called functions assume that the whole tree is rooted at s_root,
and that anonymous dentries are not the roots of trees which results in
dentries being left unculled.
However, with the way NFS superblock sharing are currently set to be
implemented, these assumptions are violated: the root of the filesystem is
simply a dummy dentry and inode (the real inode for '/' may well be
inaccessible), and all the vfsmounts are rooted on anonymous[*] dentries
with child trees.
[*] Anonymous until discovered from another tree.
(*) The documentation has been adjusted, including the additional bit of
changing ext2_* into foo_* in the documentation.
[akpm@osdl.org: convert ipath_fs, do other stuff]
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Cc: Nathan Scott <nathans@sgi.com>
Cc: Roland Dreier <rolandd@cisco.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-23 02:02:57 -07:00
|
|
|
return get_sb_nodev(type, flags, data, hostfs_fill_sb_common, mnt);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct file_system_type hostfs_type = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "hostfs",
|
|
|
|
.get_sb = hostfs_read_sb,
|
|
|
|
.kill_sb = kill_anon_super,
|
|
|
|
.fs_flags = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init init_hostfs(void)
|
|
|
|
{
|
2007-05-08 00:23:18 -07:00
|
|
|
return register_filesystem(&hostfs_type);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit exit_hostfs(void)
|
|
|
|
{
|
|
|
|
unregister_filesystem(&hostfs_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(init_hostfs)
|
|
|
|
module_exit(exit_hostfs)
|
|
|
|
MODULE_LICENSE("GPL");
|