mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 14/21] fat: Cleanup FAT attribute stuff
Date: Wed, 15 Oct 2008 22:58:00 +0900	[thread overview]
Message-ID: <6b812e3e3e848f5f6e81422369.ps@mail.parknet.co.jp> (raw)
In-Reply-To: <5cfc12333e848f5f6e71322369.ps@mail.parknet.co.jp>


This adds three helpers:

fat_make_attrs() - makes FAT attributes from inode.
fat_make_mode()  - makes mode_t from FAT attributes.
fat_save_attrs() - saves FAT attributes to inode.

Then this replaces: MSDOS_MKMODE() by fat_make_mode(), fat_attr() by
fat_make_attrs(), ->i_attrs = attr & ATTR_UNUSED by fat_save_attrs().
And for root inode, those is used with ATTR_DIR instead of bogus
ATTR_NONE.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
---

 fs/fat/fat.h             |   20 +++++++++++++++++++-
 fs/fat/file.c            |   32 ++++++++++++--------------------
 fs/fat/inode.c           |   19 +++++++++----------
 include/linux/msdos_fs.h |    5 -----
 4 files changed, 40 insertions(+), 36 deletions(-)

diff -puN fs/fat/file.c~fat-attrs-cleanup fs/fat/file.c
--- linux-2.6/fs/fat/file.c~fat-attrs-cleanup	2008-08-27 19:33:26.000000000 +0900
+++ linux-2.6-hirofumi/fs/fat/file.c	2008-08-27 22:24:41.000000000 +0900
@@ -27,13 +27,7 @@ int fat_generic_ioctl(struct inode *inod
 	switch (cmd) {
 	case FAT_IOCTL_GET_ATTRIBUTES:
 	{
-		u32 attr;
-
-		if (inode->i_ino == MSDOS_ROOT_INO)
-			attr = ATTR_DIR;
-		else
-			attr = fat_attr(inode);
-
+		u32 attr = fat_make_attrs(inode);
 		return put_user(attr, user_attr);
 	}
 	case FAT_IOCTL_SET_ATTRIBUTES:
@@ -62,20 +56,16 @@ int fat_generic_ioctl(struct inode *inod
 		/* Merge in ATTR_VOLUME and ATTR_DIR */
 		attr |= (MSDOS_I(inode)->i_attrs & ATTR_VOLUME) |
 			(is_dir ? ATTR_DIR : 0);
-		oldattr = fat_attr(inode);
+		oldattr = fat_make_attrs(inode);
 
 		/* Equivalent to a chmod() */
 		ia.ia_valid = ATTR_MODE | ATTR_CTIME;
 		ia.ia_ctime = current_fs_time(inode->i_sb);
-		if (is_dir) {
-			ia.ia_mode = MSDOS_MKMODE(attr,
-				S_IRWXUGO & ~sbi->options.fs_dmask)
-				| S_IFDIR;
-		} else {
-			ia.ia_mode = MSDOS_MKMODE(attr,
-				(S_IRUGO | S_IWUGO | (inode->i_mode & S_IXUGO))
-				& ~sbi->options.fs_fmask)
-				| S_IFREG;
+		if (is_dir)
+			ia.ia_mode = fat_make_mode(sbi, attr, S_IRWXUGO);
+		else {
+			ia.ia_mode = fat_make_mode(sbi, attr,
+				S_IRUGO | S_IWUGO | (inode->i_mode & S_IXUGO));
 		}
 
 		/* The root directory has no attributes */
@@ -115,7 +105,7 @@ int fat_generic_ioctl(struct inode *inod
 				inode->i_flags &= S_IMMUTABLE;
 		}
 
-		MSDOS_I(inode)->i_attrs = attr & ATTR_UNUSED;
+		fat_save_attrs(inode, attr);
 		mark_inode_dirty(inode);
 up:
 		mnt_drop_write(filp->f_path.mnt);
@@ -274,7 +264,7 @@ static int fat_sanitize_mode(const struc
 
 	/*
 	 * Note, the basic check is already done by a caller of
-	 * (attr->ia_mode & ~MSDOS_VALID_MODE)
+	 * (attr->ia_mode & ~FAT_VALID_MODE)
 	 */
 
 	if (S_ISREG(inode->i_mode))
@@ -314,6 +304,8 @@ static int fat_allow_set_time(struct msd
 }
 
 #define TIMES_SET_FLAGS	(ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
+/* valid file mode bits */
+#define FAT_VALID_MODE	(S_IFREG | S_IFDIR | S_IRWXUGO)
 
 int fat_setattr(struct dentry *dentry, struct iattr *attr)
 {
@@ -356,7 +348,7 @@ int fat_setattr(struct dentry *dentry, s
 	    ((attr->ia_valid & ATTR_GID) &&
 	     (attr->ia_gid != sbi->options.fs_gid)) ||
 	    ((attr->ia_valid & ATTR_MODE) &&
-	     (attr->ia_mode & ~MSDOS_VALID_MODE)))
+	     (attr->ia_mode & ~FAT_VALID_MODE)))
 		error = -EPERM;
 
 	if (error) {
diff -puN fs/fat/fat.h~fat-attrs-cleanup fs/fat/fat.h
--- linux-2.6/fs/fat/fat.h~fat-attrs-cleanup	2008-08-27 19:33:26.000000000 +0900
+++ linux-2.6-hirofumi/fs/fat/fat.h	2008-08-27 22:24:41.000000000 +0900
@@ -117,14 +117,32 @@ static inline struct msdos_inode_info *M
 	return container_of(inode, struct msdos_inode_info, vfs_inode);
 }
 
+/* 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)
+{
+	if (attrs & ATTR_RO)
+		mode &= ~S_IWUGO;
+
+	if (attrs & ATTR_DIR)
+		return (mode & ~sbi->options.fs_dmask) | S_IFDIR;
+	else
+		return (mode & ~sbi->options.fs_fmask) | S_IFREG;
+}
+
 /* Return the FAT attribute byte for this inode */
-static inline u8 fat_attr(struct inode *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;
 }
 
+static inline void fat_save_attrs(struct inode *inode, u8 attrs)
+{
+	MSDOS_I(inode)->i_attrs = attrs & ATTR_UNUSED;
+}
+
 static inline unsigned char fat_checksum(const __u8 *name)
 {
 	unsigned char s = name[0];
diff -puN fs/fat/inode.c~fat-attrs-cleanup fs/fat/inode.c
--- linux-2.6/fs/fat/inode.c~fat-attrs-cleanup	2008-08-27 19:33:26.000000000 +0900
+++ linux-2.6-hirofumi/fs/fat/inode.c	2008-08-27 22:24:41.000000000 +0900
@@ -337,8 +337,7 @@ static int fat_fill_inode(struct inode *
 
 	if ((de->attr & ATTR_DIR) && !IS_FREE(de->name)) {
 		inode->i_generation &= ~1;
-		inode->i_mode = MSDOS_MKMODE(de->attr,
-			S_IRWXUGO & ~sbi->options.fs_dmask) | S_IFDIR;
+		inode->i_mode = fat_make_mode(sbi, de->attr, S_IRWXUGO);
 		inode->i_op = sbi->dir_ops;
 		inode->i_fop = &fat_dir_operations;
 
@@ -355,10 +354,9 @@ static int fat_fill_inode(struct inode *
 		inode->i_nlink = fat_subdirs(inode);
 	} else { /* not a directory */
 		inode->i_generation |= 1;
-		inode->i_mode = MSDOS_MKMODE(de->attr,
-		    ((sbi->options.showexec && !is_exec(de->name + 8))
-			? S_IRUGO|S_IWUGO : S_IRWXUGO)
-		    & ~sbi->options.fs_fmask) | S_IFREG;
+		inode->i_mode = fat_make_mode(sbi, de->attr,
+			((sbi->options.showexec && !is_exec(de->name + 8))
+			 ? S_IRUGO|S_IWUGO : S_IRWXUGO));
 		MSDOS_I(inode)->i_start = le16_to_cpu(de->start);
 		if (sbi->fat_bits == 32)
 			MSDOS_I(inode)->i_start |= (le16_to_cpu(de->starthi) << 16);
@@ -374,7 +372,8 @@ static int fat_fill_inode(struct inode *
 		if (sbi->options.sys_immutable)
 			inode->i_flags |= S_IMMUTABLE;
 	}
-	MSDOS_I(inode)->i_attrs = de->attr & ATTR_UNUSED;
+	fat_save_attrs(inode, de->attr);
+
 	inode->i_blocks = ((inode->i_size + (sbi->cluster_size - 1))
 			   & ~((loff_t)sbi->cluster_size - 1)) >> 9;
 
@@ -569,7 +568,7 @@ retry:
 		raw_entry->size = 0;
 	else
 		raw_entry->size = cpu_to_le32(inode->i_size);
-	raw_entry->attr = fat_attr(inode);
+	raw_entry->attr = fat_make_attrs(inode);
 	raw_entry->start = cpu_to_le16(MSDOS_I(inode)->i_logstart);
 	raw_entry->starthi = cpu_to_le16(MSDOS_I(inode)->i_logstart >> 16);
 	fat_time_unix2fat(sbi, &inode->i_mtime, &raw_entry->time,
@@ -1121,7 +1120,7 @@ static int fat_read_root(struct inode *i
 	inode->i_gid = sbi->options.fs_gid;
 	inode->i_version++;
 	inode->i_generation = 0;
-	inode->i_mode = (S_IRWXUGO & ~sbi->options.fs_dmask) | S_IFDIR;
+	inode->i_mode = fat_make_mode(sbi, ATTR_DIR, S_IRWXUGO);
 	inode->i_op = sbi->dir_ops;
 	inode->i_fop = &fat_dir_operations;
 	if (sbi->fat_bits == 32) {
@@ -1138,7 +1137,7 @@ static int fat_read_root(struct inode *i
 	MSDOS_I(inode)->i_logstart = 0;
 	MSDOS_I(inode)->mmu_private = inode->i_size;
 
-	MSDOS_I(inode)->i_attrs = ATTR_NONE;
+	fat_save_attrs(inode, ATTR_DIR);
 	inode->i_mtime.tv_sec = inode->i_atime.tv_sec = inode->i_ctime.tv_sec = 0;
 	inode->i_mtime.tv_nsec = inode->i_atime.tv_nsec = inode->i_ctime.tv_nsec = 0;
 	inode->i_nlink = fat_subdirs(inode)+2;
diff -puN include/linux/msdos_fs.h~fat-attrs-cleanup include/linux/msdos_fs.h
--- linux-2.6/include/linux/msdos_fs.h~fat-attrs-cleanup	2008-08-27 19:33:26.000000000 +0900
+++ linux-2.6-hirofumi/include/linux/msdos_fs.h	2008-08-27 22:24:40.000000000 +0900
@@ -46,11 +46,6 @@
 #define DELETED_FLAG	0xe5	/* marks file as deleted when in name[0] */
 #define IS_FREE(n)	(!*(n) || *(n) == DELETED_FLAG)
 
-/* valid file mode bits */
-#define MSDOS_VALID_MODE (S_IFREG | S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO)
-/* Convert attribute bits and a mask to the UNIX mode. */
-#define MSDOS_MKMODE(a, m) (m & (a & ATTR_RO ? S_IRUGO|S_IXUGO : S_IRWXUGO))
-
 #define MSDOS_NAME	11	/* maximum name length */
 #define MSDOS_LONGNAME	256	/* maximum name length */
 #define MSDOS_SLOTS	21	/* max # of slots for short and long names */
_

  reply	other threads:[~2008-10-15 14:09 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                         ` OGAWA Hirofumi [this message]
2008-10-15 13:58                           ` [PATCH 15/21] fat: Fix ATTR_RO in the case of (~umask & S_WUGO) == 0 OGAWA Hirofumi
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=6b812e3e3e848f5f6e81422369.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®