6 #include <linux/ctype.h>
11 #include <linux/kernel.h>
12 #include <linux/list.h>
13 #include <linux/module.h>
15 #include <linux/slab.h>
17 #include <linux/types.h>
20 #include <asm/uaccess.h>
47 #define HPPFS_SUPER_MAGIC 0xb00000ee
60 for (i = 0; i < dentry->
d_name.len; i++) {
67 static char *dentry_name(
struct dentry *dentry,
int extra)
79 else len += parent->
d_name.len + 1;
97 seg_name = parent->
d_name.name;
98 seg_len = parent->
d_name.len;
103 strncpy(&name[len + 1], seg_name, seg_len);
110 static int file_removed(
struct dentry *dentry,
const char *
file)
117 extra +=
strlen(file) + 1;
119 host_file = dentry_name(dentry, extra +
strlen(
"/remove"));
120 if (host_file ==
NULL) {
129 strcat(host_file,
"/remove");
140 static struct dentry *hppfs_lookup(
struct inode *
ino,
struct dentry *dentry,
143 struct dentry *proc_dentry, *parent;
148 deleted = file_removed(dentry,
NULL);
150 return ERR_PTR(deleted);
154 parent = HPPFS_I(ino)->proc_dentry;
159 if (IS_ERR(proc_dentry))
163 inode = get_inode(ino->
i_sb, proc_dentry);
167 d_add(dentry, inode);
178 loff_t *ppos,
int is_user)
183 read = file->
f_path.dentry->d_inode->i_fop->read;
198 static ssize_t hppfs_read_file(
int fd,
char __user *buf,
ssize_t count)
206 if (new_buf ==
NULL) {
216 "errno = %d\n", err);
235 static ssize_t hppfs_read(
struct file *file,
char __user *buf,
size_t count,
246 if (*ppos >= hppfs->
len)
251 while (off >=
sizeof(data->
contents)) {
257 if (off + count > hppfs->
len)
258 count = hppfs->
len - off;
260 *ppos += count - rem;
263 }
else if (hppfs->
host_fd != -1) {
267 "errno = %d\n", err);
270 err = hppfs_read_file(hppfs->
host_fd, buf, count);
279 else count = read_proc(hppfs->
proc_file, buf, count, ppos, 1);
284 static ssize_t hppfs_write(
struct file *file,
const char __user *buf,
285 size_t len, loff_t *ppos)
288 struct file *proc_file = data->
proc_file;
291 write = proc_file->
f_path.dentry->d_inode->i_fop->write;
292 return (*
write)(proc_file,
buf, len, ppos);
295 static int open_host_sock(
char *host_file,
int *filter_out)
300 end = &host_file[
strlen(host_file)];
329 struct file *proc_file,
330 struct file *hppfs_file,
343 INIT_LIST_HEAD(&data->
list);
349 while ((n = read_proc(proc_file, data->
contents,
364 "errno = %d\n", err);
382 INIT_LIST_HEAD(&new->list);
383 list_add(&new->list, &data->
list);
404 .contents =
NULL } );
408 static int file_mode(
int fmode)
419 static int hppfs_open(
struct inode *inode,
struct file *file)
432 host_file = dentry_name(file->
f_path.dentry,
strlen(
"/rw"));
433 if (host_file ==
NULL)
452 "errno = %d\n", host_file, -fd);
456 fd = open_host_sock(host_file, &filter);
458 data->
contents = hppfs_get_data(fd, filter,
465 "in '%s', errno = %d\n", host_file, -fd);
481 static int hppfs_dir_open(
struct inode *inode,
struct file *file)
483 const struct cred *cred = file->
f_cred;
509 static loff_t hppfs_llseek(
struct file *file, loff_t off,
int where)
512 struct file *proc_file = data->
proc_file;
513 loff_t (*llseek)(
struct file *, loff_t,
int);
516 llseek = proc_file->
f_path.dentry->d_inode->i_fop->llseek;
517 if (llseek !=
NULL) {
518 ret = (*llseek)(proc_file, off, where);
528 .llseek = hppfs_llseek,
530 .write = hppfs_write,
540 static int hppfs_filldir(
void *
d,
const char *name,
int size,
541 loff_t
offset,
u64 inode,
unsigned int type)
545 if (file_removed(dirent->
dentry, name))
555 struct file *proc_file = data->
proc_file;
560 .dentry = file->
f_path.dentry
564 readdir = proc_file->
f_path.dentry->d_inode->i_fop->readdir;
567 err = (*readdir)(proc_file, &
dirent, hppfs_filldir);
568 file->
f_pos = proc_file->f_pos;
573 static int hppfs_fsync(
struct file *file, loff_t
start, loff_t end,
581 .readdir = hppfs_readdir,
582 .open = hppfs_dir_open,
583 .fsync = hppfs_fsync,
587 static int hppfs_statfs(
struct dentry *dentry,
struct kstatfs *
sf)
598 static struct inode *hppfs_alloc_inode(
struct super_block *sb)
614 dput(HPPFS_I(ino)->proc_dentry);
618 static void hppfs_i_callback(
struct rcu_head *head)
621 kfree(HPPFS_I(inode));
624 static void hppfs_destroy_inode(
struct inode *inode)
630 .alloc_inode = hppfs_alloc_inode,
631 .destroy_inode = hppfs_destroy_inode,
633 .statfs = hppfs_statfs,
636 static int hppfs_readlink(
struct dentry *dentry,
char __user *
buffer,
639 struct dentry *proc_dentry = HPPFS_I(dentry->
d_inode)->proc_dentry;
640 return proc_dentry->
d_inode->i_op->readlink(proc_dentry, buffer,
644 static void *hppfs_follow_link(
struct dentry *dentry,
struct nameidata *nd)
646 struct dentry *proc_dentry = HPPFS_I(dentry->
d_inode)->proc_dentry;
648 return proc_dentry->
d_inode->i_op->follow_link(proc_dentry, nd);
651 static void hppfs_put_link(
struct dentry *dentry,
struct nameidata *nd,
654 struct dentry *proc_dentry = HPPFS_I(dentry->
d_inode)->proc_dentry;
656 if (proc_dentry->
d_inode->i_op->put_link)
657 proc_dentry->
d_inode->i_op->put_link(proc_dentry, nd, cookie);
661 .lookup = hppfs_lookup,
665 .readlink = hppfs_readlink,
666 .follow_link = hppfs_follow_link,
667 .put_link = hppfs_put_link,
670 static struct inode *get_inode(
struct super_block *sb,
struct dentry *dentry)
672 struct inode *proc_ino = dentry->
d_inode;
681 inode->
i_op = &hppfs_dir_iops;
682 inode->
i_fop = &hppfs_dir_fops;
684 inode->
i_op = &hppfs_link_iops;
685 inode->
i_fop = &hppfs_file_fops;
687 inode->
i_op = &hppfs_file_iops;
688 inode->
i_fop = &hppfs_file_fops;
691 HPPFS_I(inode)->proc_dentry = dentry;
707 static int hppfs_fill_super(
struct super_block *sb,
void *
d,
int silent)
709 struct inode *root_inode;
714 if (IS_ERR(proc_mnt))
720 sb->
s_op = &hppfs_sbops;
724 root_inode = get_inode(sb, dget(proc_mnt->
mnt_root));
738 int flags,
const char *dev_name,
741 return mount_nodev(type, flags, data, hppfs_fill_super);
747 .mount = hppfs_read_super,
752 static int __init init_hppfs(
void)
757 static void __exit exit_hppfs(
void)