From 905d1518564437ba765e153508653e7bc27babd6 Mon Sep 17 00:00:00 2001 From: OGAWA Hirofumi Date: Thu, 6 Nov 2008 12:53:54 -0800 Subject: [PATCH] --- yaml --- r: 118463 b: refs/heads/master c: 9183482f5d4a2de00f66641b974e7f351d41b675 h: refs/heads/master i: 118461: 4fba865135c4a21156ad303e6630a096c327cb45 118459: a311f9be965d2ca444968245ba0252dffca3eac5 118455: 2fe12a4b3cbd19aa9f8e80a959441a8867f0d4a2 118447: 130ca52fe5ac84308319757b76c1982d268ac774 118431: 5bd77fc4a4c309997d769eebc0551289b814b0da 118399: ca602c6324137aeaafeca047825fc765a6cc856a v: v3 --- [refs] | 2 +- trunk/fs/fat/fat.h | 33 +++++++++++++++++++++++++++++---- trunk/fs/fat/file.c | 7 ++++++- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/[refs] b/[refs] index a1a8d9d91212..e869462b7c81 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 9c0aa1b87bf541affef519eb4879ce7c5a5941ae +refs/heads/master: 9183482f5d4a2de00f66641b974e7f351d41b675 diff --git a/trunk/fs/fat/fat.h b/trunk/fs/fat/fat.h index 3b4753a024e3..313b645b8126 100644 --- a/trunk/fs/fat/fat.h +++ b/trunk/fs/fat/fat.h @@ -117,6 +117,25 @@ static inline struct msdos_inode_info *MSDOS_I(struct inode *inode) return container_of(inode, struct msdos_inode_info, vfs_inode); } +/* + * If ->i_mode can't hold S_IWUGO (i.e. ATTR_RO), we use ->i_attrs to + * save ATTR_RO instead of ->i_mode. + */ +static inline int fat_mode_can_hold_ro(struct inode *inode) +{ + struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb); + mode_t mask; + + if (S_ISDIR(inode->i_mode)) + mask = ~sbi->options.fs_dmask; + else + mask = ~sbi->options.fs_fmask; + + if (!(mask & S_IWUGO)) + return 0; + return 1; +} + /* Convert attribute bits and a mask to the UNIX mode. */ static inline mode_t fat_make_mode(struct msdos_sb_info *sbi, u8 attrs, mode_t mode) @@ -133,14 +152,20 @@ static inline mode_t fat_make_mode(struct msdos_sb_info *sbi, /* Return the FAT attribute byte for this inode */ static inline u8 fat_make_attrs(struct inode *inode) { - return ((inode->i_mode & S_IWUGO) ? ATTR_NONE : ATTR_RO) | - (S_ISDIR(inode->i_mode) ? ATTR_DIR : ATTR_NONE) | - MSDOS_I(inode)->i_attrs; + u8 attrs = MSDOS_I(inode)->i_attrs; + if (S_ISDIR(inode->i_mode)) + attrs |= ATTR_DIR; + if (fat_mode_can_hold_ro(inode) && !(inode->i_mode & S_IWUGO)) + attrs |= ATTR_RO; + return attrs; } static inline void fat_save_attrs(struct inode *inode, u8 attrs) { - MSDOS_I(inode)->i_attrs = attrs & ATTR_UNUSED; + if (fat_mode_can_hold_ro(inode)) + MSDOS_I(inode)->i_attrs = attrs & ATTR_UNUSED; + else + MSDOS_I(inode)->i_attrs = attrs & (ATTR_UNUSED | ATTR_RO); } static inline unsigned char fat_checksum(const __u8 *name) diff --git a/trunk/fs/fat/file.c b/trunk/fs/fat/file.c index f5a7e907a8fa..81b15c623803 100644 --- a/trunk/fs/fat/file.c +++ b/trunk/fs/fat/file.c @@ -27,7 +27,12 @@ int fat_generic_ioctl(struct inode *inode, struct file *filp, switch (cmd) { case FAT_IOCTL_GET_ATTRIBUTES: { - u32 attr = fat_make_attrs(inode); + u32 attr; + + mutex_lock(&inode->i_mutex); + attr = fat_make_attrs(inode); + mutex_unlock(&inode->i_mutex); + return put_user(attr, user_attr); } case FAT_IOCTL_SET_ATTRIBUTES: