Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / fs / hppfs / hppfs_kern.c
index ebf08cb..5e6363b 100644 (file)
@@ -1,9 +1,10 @@
-/* 
+/*
  * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
  * Licensed under the GPL
  */
 
 #include <linux/fs.h>
+#include <linux/file.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/slab.h>
@@ -24,7 +25,7 @@ struct hppfs_data {
 };
 
 struct hppfs_private {
-       struct file proc_file;
+       struct file *proc_file;
        int host_fd;
        loff_t len;
        struct hppfs_data *contents;
@@ -37,7 +38,7 @@ struct hppfs_inode_info {
 
 static inline struct hppfs_inode_info *HPPFS_I(struct inode *inode)
 {
-       return(list_entry(inode, struct hppfs_inode_info, vfs_inode));
+       return container_of(inode, struct hppfs_inode_info, vfs_inode);
 }
 
 #define HPPFS_SUPER_MAGIC 0xb00000ee
@@ -75,7 +76,7 @@ static char *dentry_name(struct dentry *dentry, int extra)
                else len += parent->d_name.len + 1;
                parent = parent->d_parent;
        }
-       
+
        root = "proc";
        len += strlen(root);
        name = kmalloc(len + extra + 1, GFP_KERNEL);
@@ -155,7 +156,7 @@ static void hppfs_read_inode(struct inode *ino)
        ino->i_blocks = proc_ino->i_blocks;
 }
 
-static struct dentry *hppfs_lookup(struct inode *ino, struct dentry *dentry, 
+static struct dentry *hppfs_lookup(struct inode *ino, struct dentry *dentry,
                                   struct nameidata *nd)
 {
        struct dentry *proc_dentry, *new, *parent;
@@ -170,34 +171,34 @@ static struct dentry *hppfs_lookup(struct inode *ino, struct dentry *dentry,
 
        err = -ENOMEM;
        parent = HPPFS_I(ino)->proc_dentry;
-       down(&parent->d_inode->i_sem);
+       mutex_lock(&parent->d_inode->i_mutex);
        proc_dentry = d_lookup(parent, &dentry->d_name);
        if(proc_dentry == NULL){
                proc_dentry = d_alloc(parent, &dentry->d_name);
                if(proc_dentry == NULL){
-                       up(&parent->d_inode->i_sem);
+                       mutex_unlock(&parent->d_inode->i_mutex);
                        goto out;
                }
-               new = (*parent->d_inode->i_op->lookup)(parent->d_inode, 
+               new = (*parent->d_inode->i_op->lookup)(parent->d_inode,
                                                       proc_dentry, NULL);
                if(new){
                        dput(proc_dentry);
                        proc_dentry = new;
                }
        }
-       up(&parent->d_inode->i_sem);
+       mutex_unlock(&parent->d_inode->i_mutex);
 
        if(IS_ERR(proc_dentry))
                return(proc_dentry);
 
        inode = iget(ino->i_sb, 0);
-       if(inode == NULL) 
+       if(inode == NULL)
                goto out_dput;
 
        err = init_inode(inode, proc_dentry);
-       if(err) 
+       if(err)
                goto out_put;
-       
+
        hppfs_read_inode(inode);
 
        d_add(dentry, inode);
@@ -215,27 +216,27 @@ static struct dentry *hppfs_lookup(struct inode *ino, struct dentry *dentry,
 static struct inode_operations hppfs_file_iops = {
 };
 
-static ssize_t read_proc(struct file *file, char *buf, ssize_t count, 
+static ssize_t read_proc(struct file *file, char __user *buf, ssize_t count,
                         loff_t *ppos, int is_user)
 {
-       ssize_t (*read)(struct file *, char *, size_t, loff_t *);
+       ssize_t (*read)(struct file *, char __user *, size_t, loff_t *);
        ssize_t n;
 
        read = file->f_dentry->d_inode->i_fop->read;
 
        if(!is_user)
                set_fs(KERNEL_DS);
-               
+
        n = (*read)(file, buf, count, &file->f_pos);
 
        if(!is_user)
                set_fs(USER_DS);
 
        if(ppos) *ppos = file->f_pos;
-       return(n);
+       return n;
 }
 
-static ssize_t hppfs_read_file(int fd, char *buf, ssize_t count)
+static ssize_t hppfs_read_file(int fd, char __user *buf, ssize_t count)
 {
        ssize_t n;
        int cur, err;
@@ -253,7 +254,7 @@ static ssize_t hppfs_read_file(int fd, char *buf, ssize_t count)
                err = os_read_file(fd, new_buf, cur);
                if(err < 0){
                        printk("hppfs_read : read failed, errno = %d\n",
-                              count);
+                              err);
                        n = err;
                        goto out_free;
                }
@@ -270,10 +271,10 @@ static ssize_t hppfs_read_file(int fd, char *buf, ssize_t count)
  out_free:
        kfree(new_buf);
  out:
-       return(n);
+       return n;
 }
 
-static ssize_t hppfs_read(struct file *file, char *buf, size_t count, 
+static ssize_t hppfs_read(struct file *file, char __user *buf, size_t count,
                          loff_t *ppos)
 {
        struct hppfs_private *hppfs = file->private_data;
@@ -307,17 +308,17 @@ static ssize_t hppfs_read(struct file *file, char *buf, size_t count,
                if(count > 0)
                        *ppos += count;
        }
-       else count = read_proc(&hppfs->proc_file, buf, count, ppos, 1);
+       else count = read_proc(hppfs->proc_file, buf, count, ppos, 1);
 
        return(count);
 }
 
-static ssize_t hppfs_write(struct file *file, const char *buf, size_t len, 
+static ssize_t hppfs_write(struct file *file, const char __user *buf, size_t len,
                           loff_t *ppos)
 {
        struct hppfs_private *data = file->private_data;
-       struct file *proc_file = &data->proc_file;
-       ssize_t (*write)(struct file *, const char *, size_t, loff_t *);
+       struct file *proc_file = data->proc_file;
+       ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *);
        int err;
 
        write = proc_file->f_dentry->d_inode->i_fop->write;
@@ -361,9 +362,9 @@ static void free_contents(struct hppfs_data *head)
        kfree(head);
 }
 
-static struct hppfs_data *hppfs_get_data(int fd, int filter, 
-                                        struct file *proc_file, 
-                                        struct file *hppfs_file, 
+static struct hppfs_data *hppfs_get_data(int fd, int filter,
+                                        struct file *proc_file,
+                                        struct file *hppfs_file,
                                         loff_t *size_out)
 {
        struct hppfs_data *data, *new, *head;
@@ -414,7 +415,7 @@ static struct hppfs_data *hppfs_get_data(int fd, int filter,
                        err = -ENOMEM;
                        goto failed_free;
                }
-       
+
                INIT_LIST_HEAD(&new->list);
                list_add(&new->list, &data->list);
                data = new;
@@ -423,7 +424,7 @@ static struct hppfs_data *hppfs_get_data(int fd, int filter,
 
  failed_free:
        free_contents(head);
- failed:               
+ failed:
        return(ERR_PTR(err));
 }
 
@@ -471,15 +472,16 @@ static int hppfs_open(struct inode *inode, struct file *file)
        proc_dentry = HPPFS_I(inode)->proc_dentry;
 
        /* XXX This isn't closed anywhere */
-       err = open_private_file(&data->proc_file, proc_dentry, 
-                               file_mode(file->f_mode));
-       if(err)
+       data->proc_file = dentry_open(dget(proc_dentry), NULL,
+                                     file_mode(file->f_mode));
+       err = PTR_ERR(data->proc_file);
+       if(IS_ERR(data->proc_file))
                goto out_free1;
 
        type = os_file_type(host_file);
        if(type == OS_TYPE_FILE){
                fd = os_open_file(host_file, of_read(OPENFLAGS()), 0);
-               if(fd >= 0) 
+               if(fd >= 0)
                        data->host_fd = fd;
                else printk("hppfs_open : failed to open '%s', errno = %d\n",
                            host_file, -fd);
@@ -489,8 +491,8 @@ static int hppfs_open(struct inode *inode, struct file *file)
        else if(type == OS_TYPE_DIR){
                fd = open_host_sock(host_file, &filter);
                if(fd > 0){
-                       data->contents = hppfs_get_data(fd, filter, 
-                                                       &data->proc_file, 
+                       data->contents = hppfs_get_data(fd, filter,
+                                                       data->proc_file,
                                                        file, &data->len);
                        if(!IS_ERR(data->contents))
                                data->host_fd = fd;
@@ -524,9 +526,10 @@ static int hppfs_dir_open(struct inode *inode, struct file *file)
                goto out;
 
        proc_dentry = HPPFS_I(inode)->proc_dentry;
-       err = open_private_file(&data->proc_file, proc_dentry, 
-                               file_mode(file->f_mode));
-       if(err)
+       data->proc_file = dentry_open(dget(proc_dentry), NULL,
+                                     file_mode(file->f_mode));
+       err = PTR_ERR(data->proc_file);
+       if(IS_ERR(data->proc_file))
                goto out_free;
 
        file->private_data = data;
@@ -541,7 +544,7 @@ static int hppfs_dir_open(struct inode *inode, struct file *file)
 static loff_t hppfs_llseek(struct file *file, loff_t off, int where)
 {
        struct hppfs_private *data = file->private_data;
-       struct file *proc_file = &data->proc_file;
+       struct file *proc_file = data->proc_file;
        loff_t (*llseek)(struct file *, loff_t, int);
        loff_t ret;
 
@@ -555,7 +558,7 @@ static loff_t hppfs_llseek(struct file *file, loff_t off, int where)
        return(default_llseek(file, off, where));
 }
 
-static struct file_operations hppfs_file_fops = {
+static const struct file_operations hppfs_file_fops = {
        .owner          = NULL,
        .llseek         = hppfs_llseek,
        .read           = hppfs_read,
@@ -569,7 +572,7 @@ struct hppfs_dirent {
        struct dentry *dentry;
 };
 
-static int hppfs_filldir(void *d, const char *name, int size, 
+static int hppfs_filldir(void *d, const char *name, int size,
                         loff_t offset, ino_t inode, unsigned int type)
 {
        struct hppfs_dirent *dirent = d;
@@ -577,14 +580,14 @@ static int hppfs_filldir(void *d, const char *name, int size,
        if(file_removed(dirent->dentry, name))
                return(0);
 
-       return((*dirent->filldir)(dirent->vfs_dirent, name, size, offset, 
+       return((*dirent->filldir)(dirent->vfs_dirent, name, size, offset,
                                  inode, type));
 }
 
 static int hppfs_readdir(struct file *file, void *ent, filldir_t filldir)
 {
        struct hppfs_private *data = file->private_data;
-       struct file *proc_file = &data->proc_file;
+       struct file *proc_file = data->proc_file;
        int (*readdir)(struct file *, void *, filldir_t);
        struct hppfs_dirent dirent = ((struct hppfs_dirent)
                                      { .vfs_dirent     = ent,
@@ -606,7 +609,7 @@ static int hppfs_fsync(struct file *file, struct dentry *dentry, int datasync)
        return(0);
 }
 
-static struct file_operations hppfs_dir_fops = {
+static const struct file_operations hppfs_dir_fops = {
        .owner          = NULL,
        .readdir        = hppfs_readdir,
        .open           = hppfs_dir_open,
@@ -629,7 +632,7 @@ static struct inode *hppfs_alloc_inode(struct super_block *sb)
        struct hppfs_inode_info *hi;
 
        hi = kmalloc(sizeof(*hi), GFP_KERNEL);
-       if(hi == NULL) 
+       if(hi == NULL)
                return(NULL);
 
        *hi = ((struct hppfs_inode_info) { .proc_dentry = NULL });
@@ -647,7 +650,7 @@ static void hppfs_destroy_inode(struct inode *inode)
        kfree(HPPFS_I(inode));
 }
 
-static struct super_operations hppfs_sbops = { 
+static struct super_operations hppfs_sbops = {
        .alloc_inode    = hppfs_alloc_inode,
        .destroy_inode  = hppfs_destroy_inode,
        .read_inode     = hppfs_read_inode,
@@ -655,44 +658,40 @@ static struct super_operations hppfs_sbops = {
        .statfs         = hppfs_statfs,
 };
 
-static int hppfs_readlink(struct dentry *dentry, char *buffer, int buflen)
+static int hppfs_readlink(struct dentry *dentry, char __user *buffer, int buflen)
 {
-       struct file proc_file;
+       struct file *proc_file;
        struct dentry *proc_dentry;
-       int (*readlink)(struct dentry *, char *, int);
-       int err, n;
+       int ret;
 
        proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry;
-       err = open_private_file(&proc_file, proc_dentry, O_RDONLY);
-       if(err) 
-               return(err);
+       proc_file = dentry_open(dget(proc_dentry), NULL, O_RDONLY);
+       if (IS_ERR(proc_file))
+               return PTR_ERR(proc_file);
 
-       readlink = proc_dentry->d_inode->i_op->readlink;
-       n = (*readlink)(proc_dentry, buffer, buflen);
+       ret = proc_dentry->d_inode->i_op->readlink(proc_dentry, buffer, buflen);
 
-       close_private_file(&proc_file);
-       
-       return(n);
+       fput(proc_file);
+
+       return ret;
 }
 
-static int hppfs_follow_link(struct dentry *dentry, struct nameidata *nd)
+static void* hppfs_follow_link(struct dentry *dentry, struct nameidata *nd)
 {
-       struct file proc_file;
+       struct file *proc_file;
        struct dentry *proc_dentry;
-       int (*follow_link)(struct dentry *, struct nameidata *);
-       int err, n;
+       void *ret;
 
        proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry;
-       err = open_private_file(&proc_file, proc_dentry, O_RDONLY);
-       if(err) 
-               return(err);
+       proc_file = dentry_open(dget(proc_dentry), NULL, O_RDONLY);
+       if (IS_ERR(proc_file))
+               return proc_file;
+
+       ret = proc_dentry->d_inode->i_op->follow_link(proc_dentry, nd);
 
-       follow_link = proc_dentry->d_inode->i_op->follow_link;
-       n = (*follow_link)(proc_dentry, nd);
+       fput(proc_file);
 
-       close_private_file(&proc_file);
-       
-       return(n);
+       return ret;
 }
 
 static struct inode_operations hppfs_dir_iops = {
@@ -733,7 +732,7 @@ static int hppfs_fill_super(struct super_block *sb, void *d, int silent)
 
        err = -ENOENT;
        procfs = get_fs_type("proc");
-       if(procfs == NULL) 
+       if(procfs == NULL)
                goto out;
 
        if(list_empty(&procfs->fs_supers))
@@ -741,7 +740,7 @@ static int hppfs_fill_super(struct super_block *sb, void *d, int silent)
 
        proc_sb = list_entry(procfs->fs_supers.next, struct super_block,
                             s_instances);
-       
+
        sb->s_blocksize = 1024;
        sb->s_blocksize_bits = 10;
        sb->s_magic = HPPFS_SUPER_MAGIC;