From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, hirofumi@mail.parknet.co.jp
Subject: [PATCH 15/21] fat: Fix ATTR_RO in the case of (~umask & S_WUGO) == 0
Date: Wed, 15 Oct 2008 22:58:00 +0900 [thread overview]
Message-ID: <cd30496c3e848f5f6e81522369.ps@mail.parknet.co.jp> (raw)
In-Reply-To: <6b812e3e3e848f5f6e81422369.ps@mail.parknet.co.jp>
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>
---
fs/fat/fat.h | 33 +++++++++++++++++++++++++++++----
fs/fat/file.c | 7 ++++++-
2 files changed, 35 insertions(+), 5 deletions(-)
diff -puN fs/fat/fat.h~fat-attrs-fixes fs/fat/fat.h
--- linux-2.6/fs/fat/fat.h~fat-attrs-fixes 2008-10-13 01:49:49.000000000 +0900
+++ linux-2.6-hirofumi/fs/fat/fat.h 2008-10-13 01:49:49.000000000 +0900
@@ -117,6 +117,25 @@ static inline struct msdos_inode_info *M
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(struc
/* 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 -puN fs/fat/file.c~fat-attrs-fixes fs/fat/file.c
--- linux-2.6/fs/fat/file.c~fat-attrs-fixes 2008-10-13 01:49:49.000000000 +0900
+++ linux-2.6-hirofumi/fs/fat/file.c 2008-10-13 01:49:49.000000000 +0900
@@ -27,7 +27,12 @@ int fat_generic_ioctl(struct inode *inod
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:
_
next prev parent reply other threads:[~2008-10-15 14:06 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-15 13:57 [PATCH 01/21] fat: document additional vfat mount options OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 02/21] fat: move fs/vfat/* and fs/msdos/* to fs/fat OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 03/21] fat: split include/msdos_fs.h OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 04/21] fat: Fix and cleanup timestamp conversion OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 05/21] fat: use generic_file_llseek() for directory OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 06/21] fat: cleanup fat_parse_long() error handling OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 07/21] fat: improve fat_hash() OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 08/21] fat: Fix fat_ent_update_ptr() for FAT12 OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 09/21] fat: use fat_detach() in fat_clear_inode() OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 10/21] vfat: Fix vfat_find() error path in vfat_lookup() OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 11/21] fat: Fix/Cleanup dcache handling for vfat OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 12/21] fat: Kill d_invalidate() in vfat_lookup() OGAWA Hirofumi
2008-10-15 13:57 ` [PATCH 13/21] fat: Cleanup msdos_lookup() OGAWA Hirofumi
2008-10-15 13:58 ` [PATCH 14/21] fat: Cleanup FAT attribute stuff OGAWA Hirofumi
2008-10-15 13:58 ` OGAWA Hirofumi [this message]
2008-10-15 13:58 ` [PATCH 16/21] fat: Fix ATTR_RO for directory OGAWA Hirofumi
2008-10-15 13:58 ` [PATCH 17/21] fat: Fix _fat_bmap() race OGAWA Hirofumi
2008-10-15 13:58 ` [PATCH 18/21] fat: Add printf attribute to fat_fs_panic() OGAWA Hirofumi
2008-10-15 13:58 ` [PATCH 19/21] fat: mmu_private race fix OGAWA Hirofumi
2008-10-15 13:58 ` [PATCH 20/21] fat: ->i_pos " OGAWA Hirofumi
2008-10-15 13:58 ` [PATCH 21/21] fat: i_blocks warning fix OGAWA Hirofumi
2009-03-17 23:33 ` [PATCH 02/21] fat: move fs/vfat/* and fs/msdos/* to fs/fat Pozsar Balazs
2008-10-15 22:07 ` [PATCH 01/21] fat: document additional vfat mount options Andrew Morton
2008-10-15 23:04 ` OGAWA Hirofumi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cd30496c3e848f5f6e81522369.ps@mail.parknet.co.jp \
--to=hirofumi@mail.parknet.co.jp \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®