[linux-cifs-client] [PATCH 2/7] [CIFS] on non-posix shares, clear write bits in mode when ATTR_READONLY is set

Jeff Layton jlayton at redhat.com
Mon May 5 19:16:23 GMT 2008


When mounting a share with posix extensions disabled, cifs_get_inode_info
turns off all the write bits in the mode for regular files if ATTR_READONLY
is set. Directories and other inode types, however, can also have
ATTR_READONLY set, but the mode gives no indication of this.

This patch makes this apply to other inode types besides regular files.

Signed-off-by: Jeff Layton <jlayton at redhat.com>
---
 fs/cifs/inode.c   |   18 ++++++++----------
 fs/cifs/readdir.c |   13 +++++++------
 2 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index d904a03..ed53b33 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -546,20 +546,18 @@ try_again_CIFSSMBQPathInfo:
 			cFYI(1, ("sfu mode 0%o", inode->i_mode));
 		} else {
 			inode->i_mode |= S_IFREG;
-			/* treat the dos attribute of read-only as read-only
-			   mode e.g. 555 */
-			if (cifsInfo->cifsAttrs & ATTR_READONLY)
-				inode->i_mode &= ~(S_IWUGO);
-			else if ((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		*/
-				inode->i_mode |= (S_IWUGO &
-						  cifs_sb->mnt_file_mode);
 		/* BB add code here -
 		   validate if device or weird share or device type? */
 		}
 
+		/* fix mode bits to match current state of ATTR_READONLY */
+		if (cifsInfo->cifsAttrs & ATTR_READONLY)
+			inode->i_mode &= ~(S_IWUGO);
+		else if (S_ISDIR(inode->i_mode))
+			inode->i_mode |= (S_IWUGO & cifs_sb->mnt_dir_mode);
+		else
+			inode->i_mode |= (S_IWUGO & cifs_sb->mnt_file_mode);
+
 		spin_lock(&inode->i_lock);
 		if (is_size_safe_to_change(cifsInfo,
 					   le64_to_cpu(pfindData->EndOfFile))) {
diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
index 34ec321..49347f3 100644
--- a/fs/cifs/readdir.c
+++ b/fs/cifs/readdir.c
@@ -222,14 +222,15 @@ static void fill_in_inode(struct inode *tmp_inode, int new_buf_type,
 	} 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_READONLY)
+		tmp_inode->i_mode &= ~(S_IWUGO);
+	else if (S_ISDIR(tmp_inode->i_mode))
+		tmp_inode->i_mode |= (S_IWUGO & cifs_sb->mnt_dir_mode);
+	else
+		tmp_inode->i_mode |= (S_IWUGO & cifs_sb->mnt_file_mode);
+
 	/* can not fill in nlink here as in qpathinfo version and Unx search */
 	if (atomic_read(&cifsInfo->inUse) == 0)
 		atomic_set(&cifsInfo->inUse, 1);
-- 
1.5.3.6



More information about the linux-cifs-client mailing list