10 #include <linux/module.h>
14 #include <linux/slab.h>
33 #define FILE_HOSTFS_I(file) HOSTFS_I((file)->f_path.dentry->d_inode)
41 .d_delete = hostfs_d_delete,
45 static char *root_ino =
"";
46 static int append = 0;
48 #define HOSTFS_SUPER_MAGIC 0x00c0ffee
59 ptr =
strchr(options,
',');
67 ptr =
strchr(options,
',');
70 if (*options !=
'\0') {
71 if (!
strcmp(options,
"append"))
73 else printf(
"hostfs_args - unsupported option - %s\n",
82 "hostfs=<root dir>,<flags>,...\n"
83 " This is used to set hostfs parameters. The root directory argument\n"
84 " is used to confine all hostfs mounts to within the specified directory\n"
85 " tree on the host. If this isn't specified, then a user inside UML can\n"
86 " mount anything on the host that's accessible to the user that's running\n"
88 " The only flag currently supported is 'append', which specifies that all\n"
89 " files opened by hostfs will be opened in append mode.\n\n"
99 root = dentry->
d_sb->s_fs_info;
106 if (len > p - name) {
110 if (p > name + len) {
111 char *
s = name + len;
112 while ((*s++ = *p++) !=
'\0')
118 static char *dentry_name(
struct dentry *dentry)
124 return __dentry_name(dentry, name);
127 static char *inode_name(
struct inode *
ino)
129 struct dentry *dentry;
136 name = dentry_name(dentry);
143 static char *follow_link(
char *
link)
175 if (resolved ==
NULL) {
180 sprintf(resolved,
"%s%s", link, name);
214 &sf->
f_bsize, &f_blocks, &f_bfree, &f_bavail, &f_files,
228 static struct inode *hostfs_alloc_inode(
struct super_block *sb)
240 static void hostfs_evict_inode(
struct inode *inode)
244 if (HOSTFS_I(inode)->
fd != -1) {
246 HOSTFS_I(inode)->fd = -1;
253 kfree(HOSTFS_I(inode));
256 static void hostfs_destroy_inode(
struct inode *inode)
261 static int hostfs_show_options(
struct seq_file *seq,
struct dentry *root)
263 const char *root_path = root->
d_sb->s_fs_info;
266 if (
strlen(root_path) > offset)
273 .alloc_inode = hostfs_alloc_inode,
274 .destroy_inode = hostfs_destroy_inode,
275 .evict_inode = hostfs_evict_inode,
277 .show_options = hostfs_show_options,
288 name = dentry_name(file->
f_path.dentry);
296 while ((name =
read_dir(dir, &next, &ino, &len, &type)) !=
NULL) {
297 error = (*filldir)(ent,
name, len, file->
f_pos,
312 int r = 0,
w = 0,
fd;
315 if ((mode & HOSTFS_I(ino)->mode) ==
mode)
318 mode |= HOSTFS_I(ino)->mode;
328 name = dentry_name(file->
f_path.dentry);
339 if ((mode & HOSTFS_I(ino)->mode) == mode) {
343 if ((mode | HOSTFS_I(ino)->mode) != mode) {
344 mode |= HOSTFS_I(ino)->mode;
349 if (HOSTFS_I(ino)->
fd == -1) {
350 HOSTFS_I(ino)->fd =
fd;
359 HOSTFS_I(ino)->mode =
mode;
367 struct inode *inode = file->
f_mapping->host;
403 struct inode *inode = mapping->
host;
405 unsigned long long base;
410 if (page->
index >= end_index)
416 err =
write_file(HOSTFS_I(inode)->
fd, &base, buffer, count);
418 ClearPageUptodate(page);
426 ClearPageError(page);
452 SetPageUptodate(page);
453 if (PageError(page)) ClearPageError(page);
462 loff_t
pos,
unsigned len,
unsigned flags,
463 struct page **pagep,
void **fsdata)
474 loff_t
pos,
unsigned len,
unsigned copied,
477 struct inode *inode = mapping->
host;
487 SetPageUptodate(page);
493 if (err > 0 && (pos > inode->
i_size))
509 static int read_name(
struct inode *ino,
char *name)
522 ino->
i_op = &hostfs_link_iops;
525 ino->
i_op = &hostfs_dir_iops;
526 ino->
i_fop = &hostfs_dir_fops;
533 ino->
i_op = &hostfs_iops;
537 ino->
i_op = &hostfs_iops;
538 ino->
i_fop = &hostfs_file_fops;
545 i_uid_write(ino,
st.uid);
546 i_gid_write(ino,
st.gid);
562 inode = hostfs_iget(dir->
i_sb);
564 error = PTR_ERR(inode);
569 name = dentry_name(dentry);
580 error = read_name(inode, name);
586 HOSTFS_I(inode)->fd =
fd;
604 inode = hostfs_iget(ino->
i_sb);
606 err = PTR_ERR(inode);
611 name = dentry_name(dentry);
615 err = read_name(inode, name);
625 d_add(dentry, inode);
636 char *from_name, *to_name;
639 if ((from_name = dentry_name(from)) ==
NULL)
641 to_name = dentry_name(to);
642 if (to_name ==
NULL) {
660 if ((file = dentry_name(dentry)) ==
NULL)
673 if ((file = dentry_name(dentry)) ==
NULL)
685 if ((file = dentry_name(dentry)) ==
NULL)
697 if ((file = dentry_name(dentry)) ==
NULL)
710 inode = hostfs_iget(dir->
i_sb);
712 err = PTR_ERR(inode);
717 name = dentry_name(dentry);
726 err = read_name(inode, name);
745 struct inode *to_ino,
struct dentry *to)
747 char *from_name, *to_name;
750 if ((from_name = dentry_name(from)) ==
NULL)
752 if ((to_name = dentry_name(to)) ==
NULL) {
765 int r = 0,
w = 0,
x = 0,
err;
773 name = inode_name(ino);
790 struct inode *inode = dentry->
d_inode;
795 int fd = HOSTFS_I(inode)->fd;
839 name = dentry_name(dentry);
848 attr->
ia_size != i_size_read(inode)) {
859 mark_inode_dirty(inode);
870 .mknod = hostfs_mknod,
884 .mknod = hostfs_mknod,
890 static void *hostfs_follow_link(
struct dentry *dentry,
struct nameidata *nd)
894 char *
path = dentry_name(dentry);
910 nd_set_link(nd, link);
914 static void hostfs_put_link(
struct dentry *dentry,
struct nameidata *nd,
void *
cookie)
916 char *s = nd_get_link(nd);
923 .follow_link = hostfs_follow_link,
924 .put_link = hostfs_put_link,
927 static int hostfs_fill_sb_common(
struct super_block *sb,
void *
d,
int silent)
929 struct inode *root_inode;
930 char *host_root_path, *req_root =
d;
936 sb->
s_op = &hostfs_sbops;
937 sb->
s_d_op = &hostfs_dentry_ops;
941 if (req_root ==
NULL)
947 if (host_root_path ==
NULL)
950 sprintf(host_root_path,
"%s/%s", root_ino, req_root);
956 err = read_name(root_inode, host_root_path);
961 char *name = follow_link(host_root_path);
965 err = read_name(root_inode, name);
985 int flags,
const char *dev_name,
988 return mount_nodev(type, flags, data, hostfs_fill_sb_common);
1000 .mount = hostfs_read_sb,
1001 .kill_sb = hostfs_kill_sb,
1005 static int __init init_hostfs(
void)
1010 static void __exit exit_hostfs(
void)