patch-2.3.99-pre3 linux/fs/open.c
Next file: linux/fs/openpromfs/inode.c
Previous file: linux/fs/ntfs/inode.c
Back to the patch index
Back to the overall index
- Lines: 93
- Date:
Thu Mar 23 13:11:49 2000
- Orig file:
v2.3.99-pre2/linux/fs/open.c
- Orig date:
Sun Mar 19 18:35:31 2000
diff -u --recursive --new-file v2.3.99-pre2/linux/fs/open.c linux/fs/open.c
@@ -298,7 +298,6 @@
if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */
return -EINVAL;
- lock_kernel();
old_fsuid = current->fsuid;
old_fsgid = current->fsgid;
old_cap = current->cap_effective;
@@ -311,7 +310,8 @@
cap_clear(current->cap_effective);
else
current->cap_effective = current->cap_permitted;
-
+
+ lock_kernel();
dentry = namei(filename);
res = PTR_ERR(dentry);
if (!IS_ERR(dentry)) {
@@ -321,12 +321,12 @@
res = -EROFS;
dput(dentry);
}
+ unlock_kernel();
current->fsuid = old_fsuid;
current->fsgid = old_fsgid;
current->cap_effective = old_cap;
- unlock_kernel();
return res;
}
@@ -646,25 +646,35 @@
*/
struct file *filp_open(const char * filename, int flags, int mode, struct dentry * base)
{
- struct inode * inode;
struct dentry * dentry;
- struct file * f;
int flag,error;
- error = -ENFILE;
- f = get_empty_filp();
- if (!f)
- goto out;
- f->f_flags = flag = flags;
- f->f_mode = (flag+1) & O_ACCMODE;
- if (f->f_mode)
+ flag = flags;
+ if ((flag+1) & O_ACCMODE)
flag++;
if (flag & O_TRUNC)
flag |= 2;
+
dentry = __open_namei(filename, flag, mode, base);
error = PTR_ERR(dentry);
- if (IS_ERR(dentry))
- goto cleanup_file;
+ if (!IS_ERR(dentry))
+ return dentry_open(dentry, flags);
+
+ return ERR_PTR(error);
+}
+
+struct file *dentry_open(struct dentry *dentry, int flags)
+{
+ struct file * f;
+ struct inode *inode;
+ int error;
+
+ error = -ENFILE;
+ f = get_empty_filp();
+ if (!f)
+ goto cleanup_dentry;
+ f->f_flags = flags;
+ f->f_mode = (flags+1) & O_ACCMODE;
inode = dentry->d_inode;
if (f->f_mode & FMODE_WRITE) {
error = get_write_access(inode);
@@ -692,12 +702,10 @@
cleanup_all:
if (f->f_mode & FMODE_WRITE)
put_write_access(inode);
-cleanup_dentry:
f->f_dentry = NULL;
+cleanup_dentry:
dput(dentry);
-cleanup_file:
put_filp(f);
-out:
return ERR_PTR(error);
}
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)