lkml.org 
[lkml]   [1999]   [May]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] Minor cleanup/fix in quota_on().
	quota_on() contains almost verbatim copy of filp_open(), except
that it returns EMFILE instead of ENFILE (wrong, since EMFILE is about
per-process limit and it's not the case here) and calls open_namei() with
slightly wrong arguments (as the result read permissions are not checked).
I replaced the cruft with call of filp_open(). Could you apply the
following patch?
TIA,
Al
--- fs/dquot.c Mon Mar 8 17:00:11 1999
+++ fs/dquot.c.new Sun May 2 09:35:08 1999
@@ -1268,11 +1268,11 @@

int quota_on(kdev_t dev, short type, char *path)
{
- struct file *filp = NULL;
- struct dentry *dentry;
+ struct file *f;
struct vfsmount *vfsmnt;
struct inode *inode;
struct dquot *dquot;
+ struct quota_mount_options *mnt_dquot;
char *tmp;
int error;

@@ -1281,69 +1281,48 @@
return -ENODEV;

if (is_enabled(vfsmnt, type))
- return(-EBUSY);
+ return -EBUSY;
+ mnt_dquot = &vfsmnt->mnt_dquot;

tmp = getname(path);
error = PTR_ERR(tmp);
if (IS_ERR(tmp))
return error;

- dentry = open_namei(tmp, O_RDWR, 0600);
+ f = filp_open(tmp, O_RDWR, 0600);
putname(tmp);
+ if (IS_ERR(f))
+ return PTR_ERR(f);

- error = PTR_ERR(dentry);
- if (IS_ERR(dentry))
- return error;
- inode = dentry->d_inode;
-
- if (!S_ISREG(inode->i_mode)) {
- dput(dentry);
- return -EACCES;
- }
-
- if (inode->i_size == 0 || (inode->i_size % sizeof(struct dqblk)) != 0) {
- dput(dentry);
- return(-EINVAL);
- }
-
- filp = get_empty_filp();
- if (filp != (struct file *)NULL) {
- filp->f_mode = (O_RDWR + 1) & O_ACCMODE;
- filp->f_flags = O_RDWR;
- filp->f_dentry = dentry;
- filp->f_pos = 0;
- filp->f_reada = 0;
- filp->f_op = inode->i_op->default_file_ops;
- if (filp->f_op->read || filp->f_op->write) {
- error = get_write_access(inode);
- if (!error) {
- if (filp->f_op && filp->f_op->open)
- error = filp->f_op->open(inode, filp);
- if (!error) {
- set_enable_flags(vfsmnt, type);
- vfsmnt->mnt_dquot.files[type] = filp;
-
- dquot = dqget(dev, 0, type);
- vfsmnt->mnt_dquot.inode_expire[type] = (dquot) ? dquot->dq_itime : MAX_IQ_TIME;
- vfsmnt->mnt_dquot.block_expire[type] = (dquot) ? dquot->dq_btime : MAX_DQ_TIME;
- dqput(dquot);
-
- vfsmnt->mnt_sb->dq_op = &dquot_operations;
- add_dquot_ref(dev, type);
-
- return(0);
- }
- put_write_access(inode);
- }
- } else
- error = -EIO;
- put_filp(filp);
- } else
- error = -EMFILE;
-
- dput(dentry);
-
- return(error);
+ /* sanity checks */
+ error = -EIO;
+ if (!f->f_op->read && !f->f_op->write)
+ goto cleanup;
+ inode = f->f_dentry->d_inode;
+ error = -EACCES;
+ if (!S_ISREG(inode->i_mode))
+ goto cleanup;
+ error = -EINVAL;
+ if (inode->i_size == 0 || (inode->i_size % sizeof(struct dqblk)) != 0)
+ goto cleanup;
+
+ /* OK, there we go */
+ set_enable_flags(vfsmnt, type);
+ mnt_dquot->files[type] = f;
+
+ dquot = dqget(dev, 0, type);
+ mnt_dquot->inode_expire[type] = (dquot) ? dquot->dq_itime : MAX_IQ_TIME;
+ mnt_dquot->block_expire[type] = (dquot) ? dquot->dq_btime : MAX_DQ_TIME;
+ dqput(dquot);
+
+ vfsmnt->mnt_sb->dq_op = &dquot_operations;
+ add_dquot_ref(dev, type);
+
+ return(0);
+
+cleanup:
+ fput(f);
+ return error;
}

/*

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:51    [W:0.111 / U:0.884 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site