This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / fs / open.c
index 66a77f5..f6dab95 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
 #include <asm/uaccess.h>
 #include <linux/fs.h>
 #include <linux/pagemap.h>
+#include <linux/vs_base.h>
+#include <linux/vs_limit.h>
+#include <linux/vs_dlimit.h>
+#include <linux/vserver/xid.h>
+
+#include <asm/unistd.h>
 
 int vfs_statfs(struct super_block *sb, struct kstatfs *buf)
 {
@@ -38,6 +44,8 @@ int vfs_statfs(struct super_block *sb, struct kstatfs *buf)
                        if (retval == 0 && buf->f_frsize == 0)
                                buf->f_frsize = buf->f_bsize;
                }
+               if (!vx_check(0, VX_ADMIN|VX_WATCH))
+                       vx_vsi_statfs(sb, buf);
        }
        return retval;
 }
@@ -237,7 +245,7 @@ static inline long do_sys_truncate(const char __user * path, loff_t length)
                goto dput_and_out;
 
        error = -EROFS;
-       if (IS_RDONLY(inode))
+       if (IS_RDONLY(inode) || MNT_IS_RDONLY(nd.mnt))
                goto dput_and_out;
 
        error = -EPERM;
@@ -335,7 +343,7 @@ asmlinkage long sys_ftruncate64(unsigned int fd, loff_t length)
 }
 #endif
 
-#if !(defined(__alpha__) || defined(__ia64__))
+#ifdef __ARCH_WANT_SYS_UTIME
 
 /*
  * sys_utime() can be implemented in user-level using sys_utimes().
@@ -361,7 +369,7 @@ asmlinkage long sys_utime(char __user * filename, struct utimbuf __user * times)
        inode = nd.dentry->d_inode;
 
        error = -EROFS;
-       if (IS_RDONLY(inode))
+       if (IS_RDONLY(inode) || MNT_IS_RDONLY(nd.mnt))
                goto dput_and_out;
 
        /* Don't worry, the checks are done in inode_change_ok() */
@@ -418,7 +426,7 @@ long do_utimes(char __user * filename, struct timeval * times)
        inode = nd.dentry->d_inode;
 
        error = -EROFS;
-       if (IS_RDONLY(inode))
+       if (IS_RDONLY(inode) || MNT_IS_RDONLY(nd.mnt))
                goto dput_and_out;
 
        /* Don't worry, the checks are done in inode_change_ok() */
@@ -500,7 +508,8 @@ asmlinkage long sys_access(const char __user * filename, int mode)
        if (!res) {
                res = permission(nd.dentry->d_inode, mode, &nd);
                /* SuS v2 requires we report a read only fs too */
-               if(!res && (mode & S_IWOTH) && IS_RDONLY(nd.dentry->d_inode)
+               if(!res && (mode & S_IWOTH)
+                  && (IS_RDONLY(nd.dentry->d_inode) || MNT_IS_RDONLY(nd.mnt))
                   && !special_file(nd.dentry->d_inode->i_mode))
                        res = -EROFS;
                path_release(&nd);
@@ -534,6 +543,8 @@ out:
        return error;
 }
 
+EXPORT_SYMBOL_GPL(sys_chdir);
+
 asmlinkage long sys_fchdir(unsigned int fd)
 {
        struct file *file;
@@ -590,6 +601,8 @@ out:
        return error;
 }
 
+EXPORT_SYMBOL_GPL(sys_chroot);
+
 asmlinkage long sys_fchmod(unsigned int fd, mode_t mode)
 {
        struct inode * inode;
@@ -606,7 +619,7 @@ asmlinkage long sys_fchmod(unsigned int fd, mode_t mode)
        inode = dentry->d_inode;
 
        err = -EROFS;
-       if (IS_RDONLY(inode))
+       if (IS_RDONLY(inode) || (file && MNT_IS_RDONLY(file->f_vfsmnt)))
                goto out_putf;
        err = -EPERM;
        if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
@@ -638,7 +651,7 @@ asmlinkage long sys_chmod(const char __user * filename, mode_t mode)
        inode = nd.dentry->d_inode;
 
        error = -EROFS;
-       if (IS_RDONLY(inode))
+       if (IS_RDONLY(inode) || MNT_IS_RDONLY(nd.mnt))
                goto dput_and_out;
 
        error = -EPERM;
@@ -659,7 +672,8 @@ out:
        return error;
 }
 
-static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
+static int chown_common(struct dentry *dentry, struct vfsmount *mnt,
+       uid_t user, gid_t group)
 {
        struct inode * inode;
        int error;
@@ -671,19 +685,20 @@ static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
                goto out;
        }
        error = -EROFS;
-       if (IS_RDONLY(inode))
+       if (IS_RDONLY(inode) || MNT_IS_RDONLY(mnt))
                goto out;
        error = -EPERM;
        if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
                goto out;
+
        newattrs.ia_valid =  ATTR_CTIME;
        if (user != (uid_t) -1) {
                newattrs.ia_valid |= ATTR_UID;
-               newattrs.ia_uid = user;
+               newattrs.ia_uid = vx_map_uid(user);
        }
        if (group != (gid_t) -1) {
                newattrs.ia_valid |= ATTR_GID;
-               newattrs.ia_gid = group;
+               newattrs.ia_gid = vx_map_gid(group);
        }
        if (!S_ISDIR(inode->i_mode))
                newattrs.ia_valid |= ATTR_KILL_SUID|ATTR_KILL_SGID;
@@ -701,7 +716,7 @@ asmlinkage long sys_chown(const char __user * filename, uid_t user, gid_t group)
 
        error = user_path_walk(filename, &nd);
        if (!error) {
-               error = chown_common(nd.dentry, user, group);
+               error = chown_common(nd.dentry, nd.mnt, user, group);
                path_release(&nd);
        }
        return error;
@@ -714,7 +729,7 @@ asmlinkage long sys_lchown(const char __user * filename, uid_t user, gid_t group
 
        error = user_path_walk_link(filename, &nd);
        if (!error) {
-               error = chown_common(nd.dentry, user, group);
+               error = chown_common(nd.dentry, nd.mnt, user, group);
                path_release(&nd);
        }
        return error;
@@ -728,7 +743,7 @@ asmlinkage long sys_fchown(unsigned int fd, uid_t user, gid_t group)
 
        file = fget(fd);
        if (file) {
-               error = chown_common(file->f_dentry, user, group);
+               error = chown_common(file->f_dentry, file->f_vfsmnt, user, group);
                fput(file);
        }
        return error;
@@ -779,7 +794,7 @@ struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
        if (!f)
                goto cleanup_dentry;
        f->f_flags = flags;
-       f->f_mode = (flags+1) & O_ACCMODE;
+       f->f_mode = ((flags+1) & O_ACCMODE) | FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE;
        inode = dentry->d_inode;
        if (f->f_mode & FMODE_WRITE) {
                error = get_write_access(inode);
@@ -788,7 +803,6 @@ struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
        }
 
        f->f_mapping = inode->i_mapping;
-       file_ra_state_init(&f->f_ra, f->f_mapping);
        f->f_dentry = dentry;
        f->f_vfsmnt = mnt;
        f->f_pos = 0;
@@ -802,12 +816,13 @@ struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
        }
        f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
 
+       file_ra_state_init(&f->f_ra, f->f_mapping->host->i_mapping);
+
        /* NB: we're sure to have correct a_ops only after f_op->open */
        if (f->f_flags & O_DIRECT) {
-               if (!f->f_mapping || !f->f_mapping->a_ops ||
-                       !f->f_mapping->a_ops->direct_IO) {
-                               fput(f);
-                               f = ERR_PTR(-EINVAL);
+               if (!f->f_mapping->a_ops || !f->f_mapping->a_ops->direct_IO) {
+                       fput(f);
+                       f = ERR_PTR(-EINVAL);
                }
        }
 
@@ -878,6 +893,7 @@ repeat:
        FD_SET(fd, files->open_fds);
        FD_CLR(fd, files->close_on_exec);
        files->next_fd = fd + 1;
+       // vx_openfd_inc(fd);
 #if 1
        /* Sanity check */
        if (files->fd[fd] != NULL) {
@@ -899,6 +915,7 @@ static inline void __put_unused_fd(struct files_struct *files, unsigned int fd)
        __FD_CLR(fd, files->open_fds);
        if (fd < files->next_fd)
                files->next_fd = fd;
+       // vx_openfd_dec(fd);
 }
 
 void fastcall put_unused_fd(unsigned int fd)
@@ -965,7 +982,6 @@ out_error:
        fd = error;
        goto out;
 }
-EXPORT_SYMBOL_GPL(sys_open);
 
 #ifndef __alpha__
 
@@ -1068,3 +1084,15 @@ int generic_file_open(struct inode * inode, struct file * filp)
 }
 
 EXPORT_SYMBOL(generic_file_open);
+
+/*
+ * This is used by subsystems that don't want seekable
+ * file descriptors
+ */
+int nonseekable_open(struct inode *inode, struct file *filp)
+{
+       filp->f_mode &= ~(FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE);
+       return 0;
+}
+
+EXPORT_SYMBOL(nonseekable_open);