linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / fs / proc / generic.c
index 18b5fb3..38c8540 100644 (file)
@@ -22,6 +22,8 @@
 #include <linux/vserver/inode.h>
 #include <asm/uaccess.h>
 
+#include "internal.h"
+
 static ssize_t proc_file_read(struct file *file, char __user *buf,
                              size_t nbytes, loff_t *ppos);
 static ssize_t proc_file_write(struct file *file, const char __user *buffer,
@@ -55,6 +57,18 @@ proc_file_read(struct file *file, char __user *buf, size_t nbytes,
        ssize_t n, count;
        char    *start;
        struct proc_dir_entry * dp;
+       unsigned long long pos;
+
+       /*
+        * Gaah, please just use "seq_file" instead. The legacy /proc
+        * interfaces cut loff_t down to off_t for reads, and ignore
+        * the offset entirely for writes..
+        */
+       pos = *ppos;
+       if (pos > MAX_NON_LFS)
+               return 0;
+       if (nbytes > MAX_NON_LFS - pos)
+               nbytes = MAX_NON_LFS - pos;
 
        dp = PDE(inode);
        if (!(page = (char*) __get_free_page(GFP_KERNEL)))
@@ -203,30 +217,17 @@ proc_file_write(struct file *file, const char __user *buffer,
 static loff_t
 proc_file_lseek(struct file *file, loff_t offset, int orig)
 {
-    lock_kernel();
-
-    switch (orig) {
-    case 0:
-       if (offset < 0)
-           goto out;
-       file->f_pos = offset;
-       unlock_kernel();
-       return(file->f_pos);
-    case 1:
-       if (offset + file->f_pos < 0)
-           goto out;
-       file->f_pos += offset;
-       unlock_kernel();
-       return(file->f_pos);
-    case 2:
-       goto out;
-    default:
-       goto out;
-    }
-
-out:
-    unlock_kernel();
-    return -EINVAL;
+       loff_t retval = -EINVAL;
+       switch (orig) {
+       case 1:
+               offset += file->f_pos;
+       /* fallthrough */
+       case 0:
+               if (offset < 0 || offset > MAX_NON_LFS)
+                       break;
+               file->f_pos = retval = offset;
+       }
+       return retval;
 }
 
 static int proc_notify_change(struct dentry *dentry, struct iattr *iattr)
@@ -250,6 +251,18 @@ out:
        return error;
 }
 
+static int proc_getattr(struct vfsmount *mnt, struct dentry *dentry,
+                       struct kstat *stat)
+{
+       struct inode *inode = dentry->d_inode;
+       struct proc_dir_entry *de = PROC_I(inode)->pde;
+       if (de && de->nlink)
+               inode->i_nlink = de->nlink;
+
+       generic_fillattr(inode, stat);
+       return 0;
+}
+
 static struct inode_operations proc_file_inode_operations = {
        .setattr        = proc_notify_change,
 };
@@ -330,10 +343,10 @@ static void release_inode_number(unsigned int inum)
        spin_unlock(&proc_inum_lock);
 }
 
-static int proc_follow_link(struct dentry *dentry, struct nameidata *nd)
+static void *proc_follow_link(struct dentry *dentry, struct nameidata *nd)
 {
        nd_set_link(nd, PDE(dentry->d_inode)->data);
-       return 0;
+       return NULL;
 }
 
 static struct inode_operations proc_link_inode_operations = {
@@ -483,6 +496,7 @@ static struct file_operations proc_dir_operations = {
  */
 static struct inode_operations proc_dir_inode_operations = {
        .lookup         = proc_lookup,
+       .getattr        = proc_getattr,
        .setattr        = proc_notify_change,
 };
 
@@ -528,7 +542,7 @@ static void proc_kill_inodes(struct proc_dir_entry *de)
         */
        file_list_lock();
        list_for_each(p, &sb->s_files) {
-               struct file * filp = list_entry(p, struct file, f_list);
+               struct file * filp = list_entry(p, struct file, f_u.fu_list);
                struct dentry * dentry = filp->f_dentry;
                struct inode * inode;
                struct file_operations *fops;
@@ -700,7 +714,7 @@ void remove_proc_entry(const char *name, struct proc_dir_entry *parent)
                        parent->nlink--;
                proc_kill_inodes(de);
                de->nlink = 0;
-               BUG_ON(de->subdir);
+               WARN_ON(de->subdir);
                if (!atomic_read(&de->count))
                        free_proc_entry(de);
                else {