]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/cifs/readdir.c
on non-posix shares, clear write bits in mode when ATTR_READONLY is set
[linux-2.6-omap-h63xx.git] / fs / cifs / readdir.c
index df2c3c466ee15c5e9d3318aacb33cbd61393a809..83f30695488303a785d24f02870fcfff612dd7e7 100644 (file)
@@ -132,6 +132,7 @@ static void fill_in_inode(struct inode *tmp_inode, int new_buf_type,
        __u32 attr;
        __u64 allocation_size;
        __u64 end_of_file;
+       umode_t default_mode;
 
        /* save mtime and size */
        local_mtime = tmp_inode->i_mtime;
@@ -187,48 +188,54 @@ static void fill_in_inode(struct inode *tmp_inode, int new_buf_type,
        if (atomic_read(&cifsInfo->inUse) == 0) {
                tmp_inode->i_uid = cifs_sb->mnt_uid;
                tmp_inode->i_gid = cifs_sb->mnt_gid;
-               /* set default mode. will override for dirs below */
-               tmp_inode->i_mode = cifs_sb->mnt_file_mode;
-       } else {
-               /* mask off the type bits since it gets set
-               below and we do not want to get two type
-               bits set */
+       }
+
+       if (attr & ATTR_DIRECTORY)
+               default_mode = cifs_sb->mnt_dir_mode;
+       else
+               default_mode = cifs_sb->mnt_file_mode;
+
+       /* set initial permissions */
+       if ((atomic_read(&cifsInfo->inUse) == 0) ||
+           (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM) == 0)
+               tmp_inode->i_mode = default_mode;
+       else {
+               /* just reenable write bits if !ATTR_READONLY */
+               if ((tmp_inode->i_mode & S_IWUGO) == 0 &&
+                   (attr & ATTR_READONLY) == 0)
+                       tmp_inode->i_mode |= (S_IWUGO & default_mode);
+
                tmp_inode->i_mode &= ~S_IFMT;
        }
 
-       if (attr & ATTR_DIRECTORY) {
-               *pobject_type = DT_DIR;
-               /* override default perms since we do not lock dirs */
-               if (atomic_read(&cifsInfo->inUse) == 0)
-                       tmp_inode->i_mode = cifs_sb->mnt_dir_mode;
-               tmp_inode->i_mode |= S_IFDIR;
-       } else if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) &&
-                  (attr & ATTR_SYSTEM)) {
+       /* clear write bits if ATTR_READONLY is set */
+       if (attr & ATTR_READONLY)
+               tmp_inode->i_mode &= ~S_IWUGO;
+
+       /* set inode type */
+       if ((attr & ATTR_SYSTEM) &&
+           (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)) {
                if (end_of_file == 0)  {
-                       *pobject_type = DT_FIFO;
                        tmp_inode->i_mode |= S_IFIFO;
+                       *pobject_type = DT_FIFO;
                } else {
-                       /* rather than get the type here, we mark the
-                       inode as needing revalidate and get the real type
-                       (blk vs chr vs. symlink) later ie in lookup */
-                       *pobject_type = DT_REG;
+                       /*
+                        * trying to get the type can be slow, so just call
+                        * this a regular file for now, and mark for reval
+                        */
                        tmp_inode->i_mode |= S_IFREG;
+                       *pobject_type = DT_REG;
                        cifsInfo->time = 0;
                }
-/* we no longer mark these because we could not follow them */
-/*        } else if (attr & ATTR_REPARSE) {
-               *pobject_type = DT_LNK;
-               tmp_inode->i_mode |= S_IFLNK; */
        } else {
-               *pobject_type = DT_REG;
-               tmp_inode->i_mode |= S_IFREG;
-               if (attr & ATTR_READONLY)
-                       tmp_inode->i_mode &= ~(S_IWUGO);
-               else if ((tmp_inode->i_mode & S_IWUGO) == 0)
-                       /* the ATTR_READONLY flag may have been changed on   */
-                       /* server -- set any w bits allowed by mnt_file_mode */
-                       tmp_inode->i_mode |= (S_IWUGO & cifs_sb->mnt_file_mode);
-       } /* could add code here - to validate if device or weird share type? */
+               if (attr & ATTR_DIRECTORY) {
+                       tmp_inode->i_mode |= S_IFDIR;
+                       *pobject_type = DT_DIR;
+               } else {
+                       tmp_inode->i_mode |= S_IFREG;
+                       *pobject_type = DT_REG;
+               }
+       }
 
        /* can not fill in nlink here as in qpathinfo version and Unx search */
        if (atomic_read(&cifsInfo->inUse) == 0)