Commit 4754b825 authored by Al Viro's avatar Al Viro

hostfs: get rid of file_type(), fold init_inode()

Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 39b743c6
...@@ -70,7 +70,6 @@ struct hostfs_stat { ...@@ -70,7 +70,6 @@ struct hostfs_stat {
extern int stat_file(const char *path, struct hostfs_stat *p, int fd); extern int stat_file(const char *path, struct hostfs_stat *p, int fd);
extern int access_file(char *path, int r, int w, int x); extern int access_file(char *path, int r, int w, int x);
extern int open_file(char *path, int r, int w, int append); extern int open_file(char *path, int r, int w, int append);
extern int file_type(const char *path, int *maj, int *min);
extern void *open_dir(char *path, int *err_out); extern void *open_dir(char *path, int *err_out);
extern char *read_dir(void *stream, unsigned long long *pos, extern char *read_dir(void *stream, unsigned long long *pos,
unsigned long long *ino_out, int *len_out); unsigned long long *ino_out, int *len_out);
......
...@@ -129,26 +129,6 @@ static char *inode_name(struct inode *ino, int extra) ...@@ -129,26 +129,6 @@ static char *inode_name(struct inode *ino, int extra)
return dentry_name(dentry, extra); return dentry_name(dentry, extra);
} }
static int read_name(struct inode *ino, char *name)
{
struct hostfs_stat st;
int err = stat_file(name, &st, -1);
if (err)
return err;
ino->i_ino = st.ino;
ino->i_mode = st.mode;
ino->i_nlink = st.nlink;
ino->i_uid = st.uid;
ino->i_gid = st.gid;
ino->i_atime = st.atime;
ino->i_mtime = st.mtime;
ino->i_ctime = st.ctime;
ino->i_size = st.size;
ino->i_blocks = st.blocks;
return 0;
}
static char *follow_link(char *link) static char *follow_link(char *link)
{ {
int len, n; int len, n;
...@@ -478,43 +458,51 @@ static const struct address_space_operations hostfs_aops = { ...@@ -478,43 +458,51 @@ static const struct address_space_operations hostfs_aops = {
.write_end = hostfs_write_end, .write_end = hostfs_write_end,
}; };
static void init_inode(struct inode *inode, char *path) static int read_name(struct inode *ino, char *name)
{ {
int type; dev_t rdev;
int maj, min; struct hostfs_stat st;
dev_t rdev = 0; int err = stat_file(name, &st, -1);
if (err)
return err;
type = file_type(path, &maj, &min);
/* Reencode maj and min with the kernel encoding.*/ /* Reencode maj and min with the kernel encoding.*/
rdev = MKDEV(maj, min); rdev = MKDEV(st.maj, st.min);
if (type == OS_TYPE_SYMLINK)
inode->i_op = &page_symlink_inode_operations;
else if (type == OS_TYPE_DIR)
inode->i_op = &hostfs_dir_iops;
else inode->i_op = &hostfs_iops;
if (type == OS_TYPE_DIR) inode->i_fop = &hostfs_dir_fops; switch (st.mode & S_IFMT) {
else inode->i_fop = &hostfs_file_fops; case S_IFLNK:
ino->i_op = &page_symlink_inode_operations;
if (type == OS_TYPE_SYMLINK) ino->i_mapping->a_ops = &hostfs_link_aops;
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; break;
case OS_TYPE_BLOCKDEV: case S_IFDIR:
init_special_inode(inode, S_IFBLK, rdev); ino->i_op = &hostfs_dir_iops;
ino->i_fop = &hostfs_dir_fops;
break; break;
case OS_TYPE_FIFO: case S_IFCHR:
init_special_inode(inode, S_IFIFO, 0); case S_IFBLK:
break; case S_IFIFO:
case OS_TYPE_SOCK: case S_IFSOCK:
init_special_inode(inode, S_IFSOCK, 0); init_special_inode(ino, st.mode & S_IFMT, rdev);
ino->i_op = &hostfs_iops;
break; break;
default:
ino->i_op = &hostfs_iops;
ino->i_fop = &hostfs_file_fops;
ino->i_mapping->a_ops = &hostfs_aops;
} }
ino->i_ino = st.ino;
ino->i_mode = st.mode;
ino->i_nlink = st.nlink;
ino->i_uid = st.uid;
ino->i_gid = st.gid;
ino->i_atime = st.atime;
ino->i_mtime = st.mtime;
ino->i_ctime = st.ctime;
ino->i_size = st.size;
ino->i_blocks = st.blocks;
return 0;
} }
int hostfs_create(struct inode *dir, struct dentry *dentry, int mode, int hostfs_create(struct inode *dir, struct dentry *dentry, int mode,
...@@ -539,12 +527,10 @@ int hostfs_create(struct inode *dir, struct dentry *dentry, int mode, ...@@ -539,12 +527,10 @@ int hostfs_create(struct inode *dir, struct dentry *dentry, int mode,
mode & S_IRUSR, mode & S_IWUSR, mode & S_IXUSR, mode & S_IRUSR, mode & S_IWUSR, mode & S_IXUSR,
mode & S_IRGRP, mode & S_IWGRP, mode & S_IXGRP, mode & S_IRGRP, mode & S_IWGRP, mode & S_IXGRP,
mode & S_IROTH, mode & S_IWOTH, mode & S_IXOTH); mode & S_IROTH, mode & S_IWOTH, mode & S_IXOTH);
if (fd < 0) { if (fd < 0)
error = fd; error = fd;
} else { else
error = read_name(inode, name); error = read_name(inode, name);
init_inode(inode, name);
}
kfree(name); kfree(name);
if (error) if (error)
...@@ -580,7 +566,6 @@ struct dentry *hostfs_lookup(struct inode *ino, struct dentry *dentry, ...@@ -580,7 +566,6 @@ struct dentry *hostfs_lookup(struct inode *ino, struct dentry *dentry,
goto out_put; goto out_put;
err = read_name(inode, name); err = read_name(inode, name);
init_inode(inode, name);
kfree(name); kfree(name);
if (err == -ENOENT) { if (err == -ENOENT) {
...@@ -707,7 +692,6 @@ int hostfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev) ...@@ -707,7 +692,6 @@ int hostfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
goto out_free; goto out_free;
err = read_name(inode, name); err = read_name(inode, name);
init_inode(inode, name);
if (err) if (err)
goto out_put; goto out_put;
kfree(name); kfree(name);
...@@ -922,21 +906,20 @@ static int hostfs_fill_sb_common(struct super_block *sb, void *d, int silent) ...@@ -922,21 +906,20 @@ static int hostfs_fill_sb_common(struct super_block *sb, void *d, int silent)
if (!root_inode) if (!root_inode)
goto out; goto out;
root_inode->i_op = &hostfs_dir_iops; err = read_name(root_inode, host_root_path);
root_inode->i_fop = &hostfs_dir_fops; if (err)
goto out_put;
if (file_type(host_root_path, NULL, NULL) == OS_TYPE_SYMLINK) { if (S_ISLNK(root_inode->i_mode)) {
char *name = follow_link(host_root_path); char *name = follow_link(host_root_path);
if (IS_ERR(name)) if (IS_ERR(name))
err = PTR_ERR(name); err = PTR_ERR(name);
else else
err = read_name(root_inode, name); err = read_name(root_inode, name);
kfree(name); kfree(name);
} else {
err = read_name(root_inode, host_root_path);
}
if (err) if (err)
goto out_put; goto out_put;
}
err = -ENOMEM; err = -ENOMEM;
sb->s_root = d_alloc_root(root_inode); sb->s_root = d_alloc_root(root_inode);
......
...@@ -53,36 +53,6 @@ int stat_file(const char *path, struct hostfs_stat *p, int fd) ...@@ -53,36 +53,6 @@ int stat_file(const char *path, struct hostfs_stat *p, int fd)
return 0; return 0;
} }
int file_type(const char *path, int *maj, int *min)
{
struct stat64 buf;
if (lstat64(path, &buf) < 0)
return -errno;
/*
* We cannot pass rdev as is because glibc and the kernel disagree
* about its definition.
*/
if (maj != NULL)
*maj = os_major(buf.st_rdev);
if (min != NULL)
*min = os_minor(buf.st_rdev);
if (S_ISDIR(buf.st_mode))
return OS_TYPE_DIR;
else if (S_ISLNK(buf.st_mode))
return OS_TYPE_SYMLINK;
else if (S_ISCHR(buf.st_mode))
return OS_TYPE_CHARDEV;
else if (S_ISBLK(buf.st_mode))
return OS_TYPE_BLOCKDEV;
else if (S_ISFIFO(buf.st_mode))
return OS_TYPE_FIFO;
else if (S_ISSOCK(buf.st_mode))
return OS_TYPE_SOCK;
else return OS_TYPE_FILE;
}
int access_file(char *path, int r, int w, int x) int access_file(char *path, int r, int w, int x)
{ {
int mode = 0; int mode = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment