]> git.neil.brown.name Git - history.git/commitdiff
[PATCH] O_DIRECT open check
authorAndrew Morton <akpm@zip.com.au>
Fri, 19 Jul 2002 04:09:30 +0000 (21:09 -0700)
committerLinus Torvalds <torvalds@home.transmeta.com>
Fri, 19 Jul 2002 04:09:30 +0000 (21:09 -0700)
Updated forward-port of Aodrea's O_DIRECT open() checks.  If the user
asked for O_DIRECT and the inode has no mapping or no a_ops then fail
the open up-front.

fs/fcntl.c
fs/open.c

index 8bc8995dd172a472f1c87395a319b1a44575fecc..9d9df23dceb91280625401e3f35e808f26ba632b 100644 (file)
@@ -245,10 +245,9 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
        }
 
        if (arg & O_DIRECT) {
-               if (inode->i_mapping && inode->i_mapping->a_ops) {
-                       if (!inode->i_mapping->a_ops->direct_IO)
+               if (!inode->i_mapping || !inode->i_mapping->a_ops ||
+                       !inode->i_mapping->a_ops->direct_IO)
                                return -EINVAL;
-               }
 
                /*
                 * alloc_kiovec() can sleep and we are only serialized by
index 3742bc8a28d4048f31cbf52e273c31057dfa42b0..5ad6630562cf976cc821796b6344fe4ac0197f70 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -665,10 +665,11 @@ struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
 
        /* NB: we're sure to have correct a_ops only after f_op->open */
        if (f->f_flags & O_DIRECT) {
-               error = -EINVAL;
-               if (inode->i_mapping && inode->i_mapping->a_ops)
-                       if (!inode->i_mapping->a_ops->direct_IO)
+               if (!inode->i_mapping || !inode->i_mapping->a_ops ||
+                       !inode->i_mapping->a_ops->direct_IO) {
+                               error = -EINVAL;
                                goto cleanup_all;
+               }
        }
 
        return f;