Revert to Fedora kernel-2.6.17-1.2187_FC5 patched with vs2.0.2.1; there are too many...
[linux-2.6.git] / fs / devpts / inode.c
index 004d7ac..1e5a577 100644 (file)
 #include <linux/mount.h>
 #include <linux/tty.h>
 #include <linux/devpts_fs.h>
+#include <linux/parser.h>
 #include <linux/vs_base.h>
-#include <linux/xattr.h>
 
-#define DEVPTS_SUPER_MAGIC 0x1cd1
-
-extern struct xattr_handler devpts_xattr_security_handler;
-
-static struct xattr_handler *devpts_xattr_handlers[] = {
-#ifdef CONFIG_DEVPTS_FS_SECURITY
-       &devpts_xattr_security_handler,
-#endif
-       NULL
-};
 
 static int devpts_permission(struct inode *inode, int mask, struct nameidata *nd)
 {
@@ -41,14 +31,8 @@ static int devpts_permission(struct inode *inode, int mask, struct nameidata *nd
        return ret;
 }
 
-struct inode_operations devpts_file_inode_operations = {
-#ifdef CONFIG_DEVPTS_FS_XATTR
-       .setxattr       = generic_setxattr,
-       .getxattr       = generic_getxattr,
-       .listxattr      = generic_listxattr,
-       .removexattr    = generic_removexattr,
-#endif
-       .permission     = devpts_permission,
+static struct inode_operations devpts_file_inode_operations = {
+       .permission     = devpts_permission,
 };
 
 static struct vfsmount *devpts_mnt;
@@ -62,95 +46,72 @@ static struct {
        umode_t mode;
 } config = {.mode = 0600};
 
+enum {
+       Opt_uid, Opt_gid, Opt_mode,
+       Opt_err
+};
+
+static match_table_t tokens = {
+       {Opt_uid, "uid=%u"},
+       {Opt_gid, "gid=%u"},
+       {Opt_mode, "mode=%o"},
+       {Opt_err, NULL}
+};
+
 static int devpts_remount(struct super_block *sb, int *flags, char *data)
 {
-       int setuid = 0;
-       int setgid = 0;
-       uid_t uid = 0;
-       gid_t gid = 0;
-       umode_t mode = 0600;
-       char *this_char;
-
-       this_char = NULL;
-       while ((this_char = strsep(&data, ",")) != NULL) {
-               int n;
-               char dummy;
-               if (!*this_char)
+       char *p;
+
+       config.setuid  = 0;
+       config.setgid  = 0;
+       config.uid     = 0;
+       config.gid     = 0;
+       config.mode    = 0600;
+
+       while ((p = strsep(&data, ",")) != NULL) {
+               substring_t args[MAX_OPT_ARGS];
+               int token;
+               int option;
+
+               if (!*p)
                        continue;
-               if (sscanf(this_char, "uid=%i%c", &n, &dummy) == 1) {
-                       setuid = 1;
-                       uid = n;
-               } else if (sscanf(this_char, "gid=%i%c", &n, &dummy) == 1) {
-                       setgid = 1;
-                       gid = n;
-               } else if (sscanf(this_char, "mode=%o%c", &n, &dummy) == 1)
-                       mode = n & ~S_IFMT;
-               else {
-                       printk("devpts: called with bogus options\n");
+
+               token = match_token(p, tokens, args);
+               switch (token) {
+               case Opt_uid:
+                       if (match_int(&args[0], &option))
+                               return -EINVAL;
+                       config.uid = option;
+                       config.setuid = 1;
+                       break;
+               case Opt_gid:
+                       if (match_int(&args[0], &option))
+                               return -EINVAL;
+                       config.gid = option;
+                       config.setgid = 1;
+                       break;
+               case Opt_mode:
+                       if (match_octal(&args[0], &option))
+                               return -EINVAL;
+                       config.mode = option & ~S_IFMT;
+                       break;
+               default:
+                       printk(KERN_ERR "devpts: called with bogus options\n");
                        return -EINVAL;
                }
        }
-       config.setuid  = setuid;
-       config.setgid  = setgid;
-       config.uid     = uid;
-       config.gid     = gid;
-       config.mode    = mode;
 
        return 0;
 }
 
+static int devpts_filter(struct dentry *de)
+{
+       return vx_check(de->d_inode->i_xid, VX_IDENT);
+}
+
 static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
 {
-       struct dentry *dentry = filp->f_dentry;
-       struct dentry *cursor = filp->private_data;
-       struct list_head *p, *q = &cursor->d_child;
-       ino_t ino;
-       int i = filp->f_pos;
-
-       switch (i) {
-               case 0:
-                       ino = dentry->d_inode->i_ino;
-                       if (filldir(dirent, ".", 1, i, ino, DT_DIR) < 0)
-                               break;
-                       filp->f_pos++;
-                       i++;
-                       /* fallthrough */
-               case 1:
-                       ino = parent_ino(dentry);
-                       if (filldir(dirent, "..", 2, i, ino, DT_DIR) < 0)
-                               break;
-                       filp->f_pos++;
-                       i++;
-                       /* fallthrough */
-               default:
-                       spin_lock(&dcache_lock);
-                       if (filp->f_pos == 2) {
-                               list_del(q);
-                               list_add(q, &dentry->d_subdirs);
-                       }
-                       for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
-                               struct dentry *next;
-                               next = list_entry(p, struct dentry, d_child);
-                               if (d_unhashed(next) || !next->d_inode)
-                                       continue;
-                               if (!vx_check(next->d_inode->i_xid, VX_IDENT))
-                                       continue;
-
-                               spin_unlock(&dcache_lock);
-                               if (filldir(dirent, next->d_name.name,
-                                       next->d_name.len, filp->f_pos,
-                                       next->d_inode->i_ino, DT_CHR) < 0)
-                                       return 0;
-                               spin_lock(&dcache_lock);
-                               /* next is still alive */
-                               list_del(q);
-                               list_add(q, p);
-                               p = q;
-                               filp->f_pos++;
-                       }
-                       spin_unlock(&dcache_lock);
-       }
-       return 0;
+       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
 }
 
 static struct file_operations devpts_dir_operations = {
@@ -175,7 +136,7 @@ devpts_fill_super(struct super_block *s, void *data, int silent)
        s->s_blocksize_bits = 10;
        s->s_magic = DEVPTS_SUPER_MAGIC;
        s->s_op = &devpts_sops;
-       s->s_xattr = devpts_xattr_handlers;
+       s->s_time_gran = 1;
 
        inode = new_inode(s);
        if (!inode)
@@ -223,11 +184,10 @@ static struct dentry *get_node(int num)
 {
        char s[12];
        struct dentry *root = devpts_root;
-       down(&root->d_inode->i_sem);
+       mutex_lock(&root->d_inode->i_mutex);
        return lookup_one_len(s, root, sprintf(s, "%d", num));
 }
 
-
 int devpts_pty_new(struct tty_struct *tty)
 {
        int number = tty->index;
@@ -257,7 +217,7 @@ int devpts_pty_new(struct tty_struct *tty)
        if (!IS_ERR(dentry) && !dentry->d_inode)
                d_instantiate(dentry, inode);
 
-       up(&devpts_root->d_inode->i_sem);
+       mutex_unlock(&devpts_root->d_inode->i_mutex);
 
        return 0;
 }
@@ -274,7 +234,7 @@ struct tty_struct *devpts_get_tty(int number)
                dput(dentry);
        }
 
-       up(&devpts_root->d_inode->i_sem);
+       mutex_unlock(&devpts_root->d_inode->i_mutex);
 
        return tty;
 }
@@ -292,7 +252,7 @@ void devpts_pty_kill(int number)
                }
                dput(dentry);
        }
-       up(&devpts_root->d_inode->i_sem);
+       mutex_unlock(&devpts_root->d_inode->i_mutex);
 }
 
 static int __init init_devpts_fs(void)