diff options
author | OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> | 2008-11-06 15:53:54 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-11-06 18:41:21 -0500 |
commit | 9183482f5d4a2de00f66641b974e7f351d41b675 (patch) | |
tree | cc23af150f0aab03b29704eb461dac98b6c1f0cf | |
parent | 9c0aa1b87bf541affef519eb4879ce7c5a5941ae (diff) |
fat: Fix ATTR_RO in the case of (~umask & S_WUGO) == 0
If inode->i_mode doesn't have S_WUGO, current code assumes it means
ATTR_RO. However, if (~[ufd]mask & S_WUGO) == 0, inode->i_mode can't
hold S_WUGO. Therefore the updated directory entry will always have
ATTR_RO.
This adds fat_mode_can_hold_ro() to check it. And if inode->i_mode
can't hold, uses -i_attrs to hold ATTR_RO instead.
With this, we don't set ATTR_RO unless users change it via ioctl() if
(~[ufd]mask & S_WUGO) == 0.
And on FAT_IOCTL_GET_ATTRIBUTES path, this adds ->i_mutex to it for
not returning the partially updated attributes by FAT_IOCTL_SET_ATTRIBUTES
to userland.
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | fs/fat/fat.h | 33 | ||||
-rw-r--r-- | fs/fat/file.c | 7 |
2 files changed, 35 insertions, 5 deletions
diff --git a/fs/fat/fat.h b/fs/fat/fat.h index 3b4753a024e3..313b645b8126 100644 --- a/fs/fat/fat.h +++ b/fs/fat/fat.h | |||
@@ -117,6 +117,25 @@ static inline struct msdos_inode_info *MSDOS_I(struct inode *inode) | |||
117 | return container_of(inode, struct msdos_inode_info, vfs_inode); | 117 | return container_of(inode, struct msdos_inode_info, vfs_inode); |
118 | } | 118 | } |
119 | 119 | ||
120 | /* | ||
121 | * If ->i_mode can't hold S_IWUGO (i.e. ATTR_RO), we use ->i_attrs to | ||
122 | * save ATTR_RO instead of ->i_mode. | ||
123 | */ | ||
124 | static inline int fat_mode_can_hold_ro(struct inode *inode) | ||
125 | { | ||
126 | struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb); | ||
127 | mode_t mask; | ||
128 | |||
129 | if (S_ISDIR(inode->i_mode)) | ||
130 | mask = ~sbi->options.fs_dmask; | ||
131 | else | ||
132 | mask = ~sbi->options.fs_fmask; | ||
133 | |||
134 | if (!(mask & S_IWUGO)) | ||
135 | return 0; | ||
136 | return 1; | ||
137 | } | ||
138 | |||
120 | /* Convert attribute bits and a mask to the UNIX mode. */ | 139 | /* Convert attribute bits and a mask to the UNIX mode. */ |
121 | static inline mode_t fat_make_mode(struct msdos_sb_info *sbi, | 140 | static inline mode_t fat_make_mode(struct msdos_sb_info *sbi, |
122 | u8 attrs, mode_t mode) | 141 | u8 attrs, mode_t mode) |
@@ -133,14 +152,20 @@ static inline mode_t fat_make_mode(struct msdos_sb_info *sbi, | |||
133 | /* Return the FAT attribute byte for this inode */ | 152 | /* Return the FAT attribute byte for this inode */ |
134 | static inline u8 fat_make_attrs(struct inode *inode) | 153 | static inline u8 fat_make_attrs(struct inode *inode) |
135 | { | 154 | { |
136 | return ((inode->i_mode & S_IWUGO) ? ATTR_NONE : ATTR_RO) | | 155 | u8 attrs = MSDOS_I(inode)->i_attrs; |
137 | (S_ISDIR(inode->i_mode) ? ATTR_DIR : ATTR_NONE) | | 156 | if (S_ISDIR(inode->i_mode)) |
138 | MSDOS_I(inode)->i_attrs; | 157 | attrs |= ATTR_DIR; |
158 | if (fat_mode_can_hold_ro(inode) && !(inode->i_mode & S_IWUGO)) | ||
159 | attrs |= ATTR_RO; | ||
160 | return attrs; | ||
139 | } | 161 | } |
140 | 162 | ||
141 | static inline void fat_save_attrs(struct inode *inode, u8 attrs) | 163 | static inline void fat_save_attrs(struct inode *inode, u8 attrs) |
142 | { | 164 | { |
143 | MSDOS_I(inode)->i_attrs = attrs & ATTR_UNUSED; | 165 | if (fat_mode_can_hold_ro(inode)) |
166 | MSDOS_I(inode)->i_attrs = attrs & ATTR_UNUSED; | ||
167 | else | ||
168 | MSDOS_I(inode)->i_attrs = attrs & (ATTR_UNUSED | ATTR_RO); | ||
144 | } | 169 | } |
145 | 170 | ||
146 | static inline unsigned char fat_checksum(const __u8 *name) | 171 | static inline unsigned char fat_checksum(const __u8 *name) |
diff --git a/fs/fat/file.c b/fs/fat/file.c index f5a7e907a8fa..81b15c623803 100644 --- a/fs/fat/file.c +++ b/fs/fat/file.c | |||
@@ -27,7 +27,12 @@ int fat_generic_ioctl(struct inode *inode, struct file *filp, | |||
27 | switch (cmd) { | 27 | switch (cmd) { |
28 | case FAT_IOCTL_GET_ATTRIBUTES: | 28 | case FAT_IOCTL_GET_ATTRIBUTES: |
29 | { | 29 | { |
30 | u32 attr = fat_make_attrs(inode); | 30 | u32 attr; |
31 | |||
32 | mutex_lock(&inode->i_mutex); | ||
33 | attr = fat_make_attrs(inode); | ||
34 | mutex_unlock(&inode->i_mutex); | ||
35 | |||
31 | return put_user(attr, user_attr); | 36 | return put_user(attr, user_attr); |
32 | } | 37 | } |
33 | case FAT_IOCTL_SET_ATTRIBUTES: | 38 | case FAT_IOCTL_SET_ATTRIBUTES: |