Skip to contentSkip to conversation

FAT: kill fatfs_syms.c

PATCH In review OGAWA Hirofumi 4 participants 20 messages Jan 17, 2005 – Jan 18, 2005 VFAT/FAT/msdos filesystem

lore
Share & tools
lore

OGAWA Hirofumi

author maintainer
#0 lore raw

PATCH 1/13 FAT: kill fatfs_syms.c

Hi,

Since 1~13 patches is including the "Lindent" cleanup, size is bit big. However these are trivial changes.

Please apply.

Signature · 237 lines
OGAWA Hirofumi <[email protected]>



The patch below removes fatfs_syms.c

All EXPORT_SYMBOL's are moved to the files where the actual functions 
are.

Signed-off-by: Adrian Bunk <[email protected]>
Signed-off-by: OGAWA Hirofumi <[email protected]>
---

 fs/fat/Makefile     |    2 +-
 fs/fat/dir.c        |   11 +++++++++++
 fs/fat/inode.c      |   34 ++++++++++++++++++++++++++++++++++
 fs/fat/misc.c       |    4 ++++
 fs/fat/fatfs_syms.c |   48 ------------------------------------------------
 5 files changed, 50 insertions(+), 49 deletions(-)

diff -puN fs/fat/Makefile~fat_export-cleanup fs/fat/Makefile
--- linux-2.6.10/fs/fat/Makefile~fat_export-cleanup	2005-01-08 09:07:36.000000000 +0900
+++ linux-2.6.10-hirofumi/fs/fat/Makefile	2005-01-08 09:07:37.000000000 +0900
@@ -4,4 +4,4 @@
 
 obj-$(CONFIG_FAT_FS) += fat.o
 
-fat-objs := cache.o dir.o file.o inode.o misc.o fatfs_syms.o
+fat-objs := cache.o dir.o file.o inode.o misc.o
diff -puN fs/fat/dir.c~fat_export-cleanup fs/fat/dir.c
--- linux-2.6.10/fs/fat/dir.c~fat_export-cleanup	2005-01-08 09:07:37.000000000 +0900
+++ linux-2.6.10-hirofumi/fs/fat/dir.c	2005-01-08 09:07:37.000000000 +0900
@@ -13,6 +13,7 @@
  *  Short name translation 1999, 2001 by Wolfram Pienkoss <[email protected]>
  */
 
+#include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/time.h>
 #include <linux/msdos_fs.h>
@@ -335,6 +336,8 @@ struct fat_ioctl_filldir_callback {
 	int short_len;
 };
 
+EXPORT_SYMBOL(fat_search_long);
+
 static int fat_readdirx(struct inode *inode, struct file *filp, void *dirent,
 			filldir_t filldir, int short_only, int both)
 {
@@ -732,6 +735,8 @@ int fat_add_entries(struct inode *dir,in
 	return offset;
 }
 
+EXPORT_SYMBOL(fat_add_entries);
+
 int fat_new_dir(struct inode *dir, struct inode *parent, int is_vfat)
 {
 	struct buffer_head *bh;
@@ -767,6 +772,8 @@ int fat_new_dir(struct inode *dir, struc
 	return 0;
 }
 
+EXPORT_SYMBOL(fat_new_dir);
+
 static int fat_get_short_entry(struct inode *dir, loff_t *pos,
 			       struct buffer_head **bh,
 			       struct msdos_dir_entry **de, loff_t *i_pos)
@@ -800,6 +807,8 @@ int fat_dir_empty(struct inode *dir)
 	return result;
 }
 
+EXPORT_SYMBOL(fat_dir_empty);
+
 /*
  * fat_subdirs counts the number of sub-directories of dir. It can be run
  * on directories being created.
@@ -839,3 +848,5 @@ int fat_scan(struct inode *dir, const un
 	}
 	return -ENOENT;
 }
+
+EXPORT_SYMBOL(fat_scan);
diff -L fs/fat/fatfs_syms.c -puN fs/fat/fatfs_syms.c~fat_export-cleanup /dev/null
--- linux-2.6.10/fs/fat/fatfs_syms.c
+++ /dev/null	2004-09-13 22:36:32.000000000 +0900
@@ -1,48 +0,0 @@
-/*
- * linux/fs/fat/fatfs_syms.c
- *
- * Exported kernel symbols for the low-level FAT-based fs support.
- *
- */
-
-#include <linux/module.h>
-#include <linux/init.h>
-
-#include <linux/mm.h>
-#include <linux/msdos_fs.h>
-
-EXPORT_SYMBOL(fat_new_dir);
-EXPORT_SYMBOL(fat_date_unix2dos);
-EXPORT_SYMBOL(fat__get_entry);
-EXPORT_SYMBOL(fat_notify_change);
-EXPORT_SYMBOL(fat_attach);
-EXPORT_SYMBOL(fat_detach);
-EXPORT_SYMBOL(fat_build_inode);
-EXPORT_SYMBOL(fat_fill_super);
-EXPORT_SYMBOL(fat_search_long);
-EXPORT_SYMBOL(fat_scan);
-EXPORT_SYMBOL(fat_add_entries);
-EXPORT_SYMBOL(fat_dir_empty);
-
-int __init fat_cache_init(void);
-void __exit fat_cache_destroy(void);
-int __init fat_init_inodecache(void);
-void __exit fat_destroy_inodecache(void);
-static int __init init_fat_fs(void)
-{
-	int ret;
-
-	ret = fat_cache_init();
-	if (ret < 0)
-		return ret;
-	return fat_init_inodecache();
-}
-
-static void __exit exit_fat_fs(void)
-{
-	fat_cache_destroy();
-	fat_destroy_inodecache();
-}
-
-module_init(init_fat_fs)
-module_exit(exit_fat_fs)
diff -puN fs/fat/inode.c~fat_export-cleanup fs/fat/inode.c
--- linux-2.6.10/fs/fat/inode.c~fat_export-cleanup	2005-01-08 09:07:37.000000000 +0900
+++ linux-2.6.10-hirofumi/fs/fat/inode.c	2005-01-08 09:07:37.000000000 +0900
@@ -11,6 +11,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/init.h>
 #include <linux/time.h>
 #include <linux/slab.h>
 #include <linux/smp_lock.h>
@@ -87,6 +88,8 @@ void fat_attach(struct inode *inode, lof
 	spin_unlock(&sbi->inode_hash_lock);
 }
 
+EXPORT_SYMBOL(fat_attach);
+
 void fat_detach(struct inode *inode)
 {
 	struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
@@ -96,6 +99,8 @@ void fat_detach(struct inode *inode)
 	spin_unlock(&sbi->inode_hash_lock);
 }
 
+EXPORT_SYMBOL(fat_detach);
+
 struct inode *fat_iget(struct super_block *sb, loff_t i_pos)
 {
 	struct msdos_sb_info *sbi = MSDOS_SB(sb);
@@ -145,6 +150,8 @@ out:
 	return inode;
 }
 
+EXPORT_SYMBOL(fat_build_inode);
+
 static void fat_delete_inode(struct inode *inode)
 {
 	if (!is_bad_inode(inode)) {
@@ -1070,6 +1077,8 @@ out_fail:
 	return error;
 }
 
+EXPORT_SYMBOL(fat_fill_super);
+
 static int fat_statfs(struct super_block *sb, struct kstatfs *buf)
 {
 	int free, nr, ret;
@@ -1328,4 +1337,29 @@ out:
 	unlock_kernel();
 	return error;
 }
+
+EXPORT_SYMBOL(fat_notify_change);
+
+int __init fat_cache_init(void);
+void __exit fat_cache_destroy(void);
+
+static int __init init_fat_fs(void)
+{
+	int ret;
+
+	ret = fat_cache_init();
+	if (ret < 0)
+		return ret;
+	return fat_init_inodecache();
+}
+
+static void __exit exit_fat_fs(void)
+{
+	fat_cache_destroy();
+	fat_destroy_inodecache();
+}
+
+module_init(init_fat_fs)
+module_exit(exit_fat_fs)
+
 MODULE_LICENSE("GPL");
diff -puN fs/fat/misc.c~fat_export-cleanup fs/fat/misc.c
--- linux-2.6.10/fs/fat/misc.c~fat_export-cleanup	2005-01-08 09:07:37.000000000 +0900
+++ linux-2.6.10-hirofumi/fs/fat/misc.c	2005-01-08 09:07:37.000000000 +0900
@@ -6,6 +6,7 @@
  *		 and date_dos2unix for date==0 by Igor Zhbanov([email protected])
  */
 
+#include <linux/module.h>
 #include <linux/fs.h>
 #include <linux/msdos_fs.h>
 #include <linux/buffer_head.h>
@@ -272,6 +273,7 @@ void fat_date_unix2dos(int unix_date,__l
 	*date = cpu_to_le16(nl_day-day_n[month-1]+1+(month << 5)+(year << 9));
 }
 
+EXPORT_SYMBOL(fat_date_unix2dos);
 
 /* Returns the inode number of the directory entry at offset pos. If bh is
    non-NULL, it is brelse'd before. Pos is incremented. The buffer header is
@@ -320,3 +322,5 @@ next:
 
 	return 0;
 }
+
+EXPORT_SYMBOL(fat__get_entry);
_
author maintainer
#1 lore raw

PATCH 2/13 FAT: merge msdos_fs_{i,sb}.h into msdos_fs.h

We don't have the union in "struct inode" and "struct super_block", so we doesn't need xxx_fs_i.h and xxx_fs_sb.h anymore.

From Christoph Hellwig <[email protected]>

---

 include/linux/msdos_fs.h    |   80 ++++++++++++++++++++++++++++++++++++++++++--
 include/linux/msdos_fs_i.h  |   29 ---------------
 include/linux/msdos_fs_sb.h |   60 ---------------------------------
 3 files changed, 78 insertions(+), 91 deletions(-)
include/linux/msdos_fs.h renamed from include/linux/msdos_fs.h~fat_remove_headers +78 -2
diff -puN include/linux/msdos_fs.h~fat_remove_headers include/linux/msdos_fs.h
@@ -189,8 +189,84 @@ struct vfat_slot_info {
 #include <linux/buffer_head.h>
 #include <linux/string.h>
 #include <linux/nls.h>
-#include <linux/msdos_fs_i.h>
-#include <linux/msdos_fs_sb.h>
+#include <linux/fs.h>
+
+struct fat_mount_options {
+	uid_t fs_uid;
+	gid_t fs_gid;
+	unsigned short fs_fmask;
+	unsigned short fs_dmask;
+	unsigned short codepage;  /* Codepage for shortname conversions */
+	char *iocharset;          /* Charset used for filename input/display */
+	unsigned short shortname; /* flags for shortname display/create rule */
+	unsigned char name_check; /* r = relaxed, n = normal, s = strict */
+	unsigned quiet:1,         /* set = fake successful chmods and chowns */
+		 showexec:1,      /* set = only set x bit for com/exe/bat */
+		 sys_immutable:1, /* set = system files are immutable */
+		 dotsOK:1,        /* set = hidden and system files are named '.filename' */
+		 isvfat:1,        /* 0=no vfat long filename support, 1=vfat support */
+		 utf8:1,	  /* Use of UTF8 character set (Default) */
+		 unicode_xlate:1, /* create escape sequences for unhandled Unicode */
+		 numtail:1,       /* Does first alias have a numeric '~1' type tail? */
+		 atari:1,         /* Use Atari GEMDOS variation of MS-DOS fs */
+		 nocase:1;	  /* Does this need case conversion? 0=need case conversion*/
+};
+
+#define FAT_HASH_BITS	8
+#define FAT_HASH_SIZE	(1UL << FAT_HASH_BITS)
+#define FAT_HASH_MASK	(FAT_HASH_SIZE-1)
+
+/*
+ * MS-DOS file system in-core superblock data
+ */
+struct msdos_sb_info {
+	unsigned short sec_per_clus; /* sectors/cluster */
+	unsigned short cluster_bits; /* log2(cluster_size) */
+	unsigned int cluster_size;   /* cluster size */
+	unsigned char fats,fat_bits; /* number of FATs, FAT bits (12 or 16) */
+	unsigned short fat_start;
+	unsigned long fat_length;    /* FAT start & length (sec.) */
+	unsigned long dir_start;
+	unsigned short dir_entries;  /* root dir start & entries */
+	unsigned long data_start;    /* first data sector */
+	unsigned long clusters;      /* number of clusters */
+	unsigned long root_cluster;  /* first cluster of the root directory */
+	unsigned long fsinfo_sector; /* sector number of FAT32 fsinfo */
+	struct semaphore fat_lock;
+	int prev_free;               /* previously allocated cluster number */
+	int free_clusters;           /* -1 if undefined */
+	struct fat_mount_options options;
+	struct nls_table *nls_disk;  /* Codepage used on disk */
+	struct nls_table *nls_io;    /* Charset used for input and display */
+	void *dir_ops;		     /* Opaque; default directory operations */
+	int dir_per_block;	     /* dir entries per block */
+	int dir_per_block_bits;	     /* log2(dir_per_block) */
+
+	spinlock_t inode_hash_lock;
+	struct hlist_head inode_hashtable[FAT_HASH_SIZE];
+};
+
+#define FAT_CACHE_VALID	0	/* special case for valid cache */
+
+/*
+ * MS-DOS file system inode data in memory
+ */
+struct msdos_inode_info {
+	spinlock_t cache_lru_lock;
+	struct list_head cache_lru;
+	int nr_caches;
+	/* for avoiding the race between fat_free() and fat_get_cluster() */
+	unsigned int cache_valid_id;
+
+	loff_t mmu_private;
+	int i_start;	/* first cluster or 0 */
+	int i_logstart;	/* logical first cluster */
+	int i_attrs;	/* unused attribute bits */
+	int i_ctime_ms;	/* unused change time in milliseconds */
+	loff_t i_pos;	/* on-disk position of directory entry or 0 */
+	struct hlist_node i_fat_hash;	/* hash by i_location */
+	struct inode vfs_inode;
+};
 
 static inline struct msdos_sb_info *MSDOS_SB(struct super_block *sb)
 {
include/linux/msdos_fs_i.h deleted +0 -29
diff -L include/linux/msdos_fs_i.h -puN include/linux/msdos_fs_i.h~fat_remove_headers /dev/null
@@ -1,29 +0,0 @@
-#ifndef _MSDOS_FS_I
-#define _MSDOS_FS_I
-
-#include <linux/fs.h>
-
-/*
- * MS-DOS file system inode data in memory
- */
-
-#define FAT_CACHE_VALID	0	/* special case for valid cache */
-
-struct msdos_inode_info {
-	spinlock_t cache_lru_lock;
-	struct list_head cache_lru;
-	int nr_caches;
-	/* for avoiding the race between fat_free() and fat_get_cluster() */
-	unsigned int cache_valid_id;
-
-	loff_t mmu_private;
-	int i_start;	/* first cluster or 0 */
-	int i_logstart;	/* logical first cluster */
-	int i_attrs;	/* unused attribute bits */
-	int i_ctime_ms;	/* unused change time in milliseconds */
-	loff_t i_pos;	/* on-disk position of directory entry or 0 */
-	struct hlist_node i_fat_hash;	/* hash by i_location */
-	struct inode vfs_inode;
-};
-
-#endif
include/linux/msdos_fs_sb.h deleted +0 -60

60 lines not on this page · raw message

_

author maintainer
#2 lore raw

PATCH 3/13 FAT: IS_BADCHAR/IS_REPLACECHR/IS_SKIPCHAR cleanup

From Rene Scharfe <[email protected]>

---

 fs/vfat/namei.c |   49 +++++++++++++++++++++----------------------------
 1 files changed, 21 insertions(+), 28 deletions(-)
fs/vfat/namei.c renamed from fs/vfat/namei.c~fat_check-chars-cleanup +21 -28
diff -puN fs/vfat/namei.c~fat_check-chars-cleanup fs/vfat/namei.c
@@ -158,33 +158,26 @@ static int vfat_cmp(struct dentry *dentr
 
 /* Characters that are undesirable in an MS-DOS file name */
 
-static wchar_t bad_chars[] = {
-	/*  `*'     `?'     `<'    `>'      `|'     `"'     `:'     `/' */
-	0x002A, 0x003F, 0x003C, 0x003E, 0x007C, 0x0022, 0x003A, 0x002F,
-	/*  `\' */
-	0x005C, 0,
-};
-#define IS_BADCHAR(uni)	(vfat_unistrchr(bad_chars, (uni)) != NULL)
-
-static wchar_t replace_chars[] = {
-	/*  `['     `]'    `;'     `,'     `+'      `=' */
-	0x005B, 0x005D, 0x003B, 0x002C, 0x002B, 0x003D, 0,
-};
-#define IS_REPLACECHAR(uni)	(vfat_unistrchr(replace_chars, (uni)) != NULL)
+static inline wchar_t vfat_bad_char(wchar_t w)
+{
+	return (w < 0x0020)
+	    || (w == 0x002A) /* * */	|| (w == 0x003F) /* ? */
+	    || (w == 0x003C) /* < */	|| (w == 0x003E) /* > */
+	    || (w == 0x007C) /* | */	|| (w == 0x0022) /* " */
+	    || (w == 0x003A) /* : */	|| (w == 0x002F) /* / */
+	    || (w == 0x005C);/* \ */
+}
 
-static wchar_t skip_chars[] = {
-	/*  `.'     ` ' */
-	0x002E, 0x0020, 0,
-};
-#define IS_SKIPCHAR(uni) \
-	((wchar_t)(uni) == skip_chars[0] || (wchar_t)(uni) == skip_chars[1])
+static inline wchar_t vfat_replace_char(wchar_t w)
+{
+	return (w == 0x005B) /* [ */	|| (w == 0x005D) /* ] */
+	    || (w == 0x003B) /* ; */	|| (w == 0x002C) /* , */
+	    || (w == 0x002B) /* + */	|| (w == 0x003D);/* = */
+}
 
-static inline wchar_t *vfat_unistrchr(const wchar_t *s, const wchar_t c)
+static wchar_t vfat_skip_char(wchar_t w)
 {
-	for(; *s != c; ++s)
-		if (*s == 0)
-			return NULL;
-	return (wchar_t *) s;
+	return (w == 0x002E) /* . */	|| (w == 0x0020);/* <space> */
 }
 
 static inline int vfat_is_used_badchars(const wchar_t *s, int len)
@@ -192,7 +185,7 @@ static inline int vfat_is_used_badchars(
 	int i;
 	
 	for (i = 0; i < len; i++)
-		if (s[i] < 0x0020 || IS_BADCHAR(s[i]))
+		if (vfat_bad_char(s[i]))
 			return -EINVAL;
 	return 0;
 }
@@ -291,11 +284,11 @@ static inline int to_shortname_char(stru
 {
 	int len;
 
-	if (IS_SKIPCHAR(*src)) {
+	if (vfat_skip_char(*src)) {
 		info->valid = 0;
 		return 0;
 	}
-	if (IS_REPLACECHAR(*src)) {
+	if (vfat_replace_char(*src)) {
 		info->valid = 0;
 		buf[0] = '_';
 		return 1;
@@ -375,7 +368,7 @@ static int vfat_create_shortname(struct 
 		 */
 		name_start = &uname[0];
 		while (name_start < ext_start) {
-			if (!IS_SKIPCHAR(*name_start))
+			if (!vfat_skip_char(*name_start))
 				break;
 			name_start++;
 		}

_

author maintainer
#3 lore raw

PATCH 4/13 FAT: Return better error codes from vfat_valid_longname()

Fix error code.

From Rene Scharfe <[email protected]>

---

 fs/vfat/namei.c |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)
fs/vfat/namei.c renamed from fs/vfat/namei.c~fat_nametoolong +9 -8
diff -puN fs/vfat/namei.c~fat_nametoolong fs/vfat/namei.c
@@ -192,10 +192,10 @@ static inline int vfat_is_used_badchars(
 
 static int vfat_valid_longname(const unsigned char *name, unsigned int len)
 {
-	if (len && name[len-1] == ' ')
-		return 0;
+	if (name[len - 1] == ' ')
+		return -EINVAL;
 	if (len >= 256)
-		return 0;
+		return -ENAMETOOLONG;
 
 	/* MS-DOS "device special files" */
 	if (len == 3 || (len > 3 && name[3] == '.')) {	/* basename == 3 */
@@ -203,18 +203,18 @@ static int vfat_valid_longname(const uns
 		    !strnicmp(name, "con", 3) ||
 		    !strnicmp(name, "nul", 3) ||
 		    !strnicmp(name, "prn", 3))
-			return 0;
+			return -EINVAL;
 	}
 	if (len == 4 || (len > 4 && name[4] == '.')) {	/* basename == 4 */
 		/* "com1", "com2", ... */
 		if ('1' <= name[3] && name[3] <= '9') {
 			if (!strnicmp(name, "com", 3) ||
 			    !strnicmp(name, "lpt", 3))
-				return 0;
+				return -EINVAL;
 		}
 	}
 
-	return 1;
+	return 0;
 }
 
 static int vfat_find_form(struct inode *dir, unsigned char *name)
@@ -617,8 +617,9 @@ static int vfat_build_slots(struct inode
 	loff_t offset;
 
 	*slots = 0;
-	if (!vfat_valid_longname(name, len))
-		return -EINVAL;
+	res = vfat_valid_longname(name, len);
+	if (res)
+		return res;
 
 	if(!(page = __get_free_page(GFP_KERNEL)))
 		return -ENOMEM;

_

author maintainer
#4 lore raw

PATCH 5/13 FAT: Manually inline shortname_info_to_lcase()

This patch inlines shortname_info_to_lcase() by hand. At least my compiler (gcc 3.3.4 from Debian) doesn't go all the way, so the compiled text size is decreased by this patch. And IMHO the code gets more readable, too.

The terms (base->valid && ext->valid), (ext->lower || ext->upper) and (base->lower || base->upper) are trivially found to be true at the single callsite of shortname_info_to_lcase(). The relevant lines are included in this patch file.

From [email protected]

---

 fs/vfat/namei.c |   26 ++++++--------------------
 1 files changed, 6 insertions(+), 20 deletions(-)
fs/vfat/namei.c renamed from fs/vfat/namei.c~fat_lcase-cleanup +6 -20
diff -puN fs/vfat/namei.c~fat_lcase-cleanup fs/vfat/namei.c
@@ -262,22 +262,6 @@ struct shortname_info {
 	(x)->valid = 1;				\
 } while (0)
 
-static inline unsigned char
-shortname_info_to_lcase(struct shortname_info *base,
-			struct shortname_info *ext)
-{
-	unsigned char lcase = 0;
-
-	if (base->valid && ext->valid) {
-		if (!base->upper && base->lower && (ext->lower || ext->upper))
-			lcase |= CASE_LOWER_BASE;
-		if (!ext->upper && ext->lower && (base->lower || base->upper))
-			lcase |= CASE_LOWER_EXT;
-	}
-
-	return lcase;
-}
-
 static inline int to_shortname_char(struct nls_table *nls,
 				    unsigned char *buf, int buf_size, wchar_t *src,
 				    struct shortname_info *info)
@@ -455,10 +439,12 @@ static int vfat_create_shortname(struct 
 		if (opt_shortname & VFAT_SFN_CREATE_WIN95) {
 			return (base_info.upper && ext_info.upper);
 		} else if (opt_shortname & VFAT_SFN_CREATE_WINNT) {
-			if ((base_info.upper || base_info.lower)
-			    && (ext_info.upper || ext_info.lower)) {
-				*lcase = shortname_info_to_lcase(&base_info,
-								 &ext_info);
+			if ((base_info.upper || base_info.lower) &&
+			    (ext_info.upper || ext_info.lower)) {
+				if (!base_info.upper && base_info.lower)
+					*lcase |= CASE_LOWER_BASE;
+				if (!ext_info.upper && ext_info.lower)
+					*lcase |= CASE_LOWER_EXT;
 				return 1;
 			}
 			return 0;

_

author maintainer
#5 lore raw

PATCH 6/13 FAT: use vprintk instead of snprintf with static buffer

---

 fs/fat/misc.c |   22 +++++++++-------------
 1 files changed, 9 insertions(+), 13 deletions(-)
fs/fat/misc.c renamed from fs/fat/misc.c~fat_sprintf-to-vprintk +9 -13
diff -puN fs/fat/misc.c~fat_sprintf-to-vprintk fs/fat/misc.c
@@ -15,26 +15,22 @@
  * fat_fs_panic reports a severe file system problem and sets the file system
  * read-only. The file system can be made writable again by remounting it.
  */
-
-static char panic_msg[512];
-
 void fat_fs_panic(struct super_block *s, const char *fmt, ...)
 {
-	int not_ro;
 	va_list args;
 
-	va_start (args, fmt);
-	vsnprintf (panic_msg, sizeof(panic_msg), fmt, args);
-	va_end (args);
+	printk(KERN_ERR "FAT: Filesystem panic (dev %s)\n", s->s_id);
 
-	not_ro = !(s->s_flags & MS_RDONLY);
-	if (not_ro)
-		s->s_flags |= MS_RDONLY;
+	printk(KERN_ERR "    ");
+	va_start(args, fmt);
+	vprintk(fmt, args);
+	va_end(args);
+	printk("\n");
 
-	printk(KERN_ERR "FAT: Filesystem panic (dev %s)\n"
-	       "    %s\n", s->s_id, panic_msg);
-	if (not_ro)
+	if (!(s->s_flags & MS_RDONLY)) {
+		s->s_flags |= MS_RDONLY;
 		printk(KERN_ERR "    File system has been set read-only\n");
+	}
 }
 
 void lock_fat(struct super_block *sb)

_

author maintainer
#6 lore raw

PATCH 7/13 FAT: kill unnecessary kmap()

---

 fs/fat/inode.c |   22 +++++++---------------
 1 files changed, 7 insertions(+), 15 deletions(-)
fs/fat/inode.c renamed from fs/fat/inode.c~fat_kill-unnecessary_kmap +7 -15
diff -puN fs/fat/inode.c~fat_kill-unnecessary_kmap fs/fat/inode.c
@@ -1137,30 +1137,22 @@ static int
 fat_prepare_write(struct file *file, struct page *page,
 			unsigned from, unsigned to)
 {
-	kmap(page);
 	return cont_prepare_write(page,from,to,fat_get_block,
 		&MSDOS_I(page->mapping->host)->mmu_private);
 }
 
-static int
-fat_commit_write(struct file *file, struct page *page,
-			unsigned from, unsigned to)
-{
-	kunmap(page);
-	return generic_commit_write(file, page, from, to);
-}
-
 static sector_t _fat_bmap(struct address_space *mapping, sector_t block)
 {
 	return generic_block_bmap(mapping,block,fat_get_block);
 }
+
 static struct address_space_operations fat_aops = {
-	.readpage = fat_readpage,
-	.writepage = fat_writepage,
-	.sync_page = block_sync_page,
-	.prepare_write = fat_prepare_write,
-	.commit_write = fat_commit_write,
-	.bmap = _fat_bmap
+	.readpage	= fat_readpage,
+	.writepage	= fat_writepage,
+	.sync_page	= block_sync_page,
+	.prepare_write	= fat_prepare_write,
+	.commit_write	= generic_commit_write,
+	.bmap		= _fat_bmap
 };
 
 /* doesn't deal with root inode */

_

author maintainer
#7 lore raw

PATCH 8/13 FAT: fs/fat/cache.c: make __fat_access static

The patch below makes a needlessly global function static.

---

 fs/fat/cache.c           |    2 +-
 include/linux/msdos_fs.h |    1 -
 2 files changed, 1 insertion(+), 2 deletions(-)
fs/fat/cache.c renamed from fs/fat/cache.c~fat__fat_access +1 -1
diff -puN fs/fat/cache.c~fat__fat_access fs/fat/cache.c
@@ -203,7 +203,7 @@ void fat_cache_inval_inode(struct inode 
 	spin_unlock(&MSDOS_I(inode)->cache_lru_lock);
 }
 
-int __fat_access(struct super_block *sb, int nr, int new_value)
+static int __fat_access(struct super_block *sb, int nr, int new_value)
 {
 	struct msdos_sb_info *sbi = MSDOS_SB(sb);
 	struct buffer_head *bh, *bh2, *c_bh, *c_bh2;
include/linux/msdos_fs.h renamed from include/linux/msdos_fs.h~fat__fat_access +0 -1
diff -puN include/linux/msdos_fs.h~fat__fat_access include/linux/msdos_fs.h
@@ -306,7 +306,6 @@ static inline void fatwchar_to16(__u8 *d
 
 /* fat/cache.c */
 extern int fat_access(struct super_block *sb, int nr, int new_value);
-extern int __fat_access(struct super_block *sb, int nr, int new_value);
 extern int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys);
 extern void fat_cache_inval_inode(struct inode *inode);
 extern int fat_get_cluster(struct inode *inode, int cluster,

_

author maintainer
#8 lore raw

PATCH 9/13 FAT: Lindent fs/msdos/namei.c

---

 fs/msdos/namei.c |  179 ++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 105 insertions(+), 74 deletions(-)
fs/msdos/namei.c renamed from fs/msdos/namei.c~fat_lindent-msdos +105 -74
diff -puN fs/msdos/namei.c~fat_lindent-msdos fs/msdos/namei.c
@@ -12,25 +12,28 @@
 #include <linux/msdos_fs.h>
 #include <linux/smp_lock.h>
 
-
 /* MS-DOS "device special files" */
 static const unsigned char *reserved_names[] = {
-	"CON     ","PRN     ","NUL     ","AUX     ",
-	"LPT1    ","LPT2    ","LPT3    ","LPT4    ",
-	"COM1    ","COM2    ","COM3    ","COM4    ",
+	"CON     ", "PRN     ", "NUL     ", "AUX     ",
+	"LPT1    ", "LPT2    ", "LPT3    ", "LPT4    ",
+	"COM1    ", "COM2    ", "COM3    ", "COM4    ",
 	NULL
 };
 
 /* Characters that are undesirable in an MS-DOS file name */
 static unsigned char bad_chars[] = "*?<>|\"";
 static unsigned char bad_if_strict_pc[] = "+=,; ";
-static unsigned char bad_if_strict_atari[] = " "; /* GEMDOS is less restrictive */
-#define	bad_if_strict(opts) ((opts)->atari ? bad_if_strict_atari : bad_if_strict_pc)
+/* GEMDOS is less restrictive */
+static unsigned char bad_if_strict_atari[] = " ";
+
+#define bad_if_strict(opts) \
+	((opts)->atari ? bad_if_strict_atari : bad_if_strict_pc)
 
 /***** Formats an MS-DOS file name. Rejects invalid names. */
 static int msdos_format_name(const unsigned char *name, int len,
-	unsigned char *res, struct fat_mount_options *opts)
-	/* name is the proposed name, len is its length, res is
+			     unsigned char *res, struct fat_mount_options *opts)
+	/*
+	 * name is the proposed name, len is its length, res is
 	 * the resulting name, opts->name_check is either (r)elaxed,
 	 * (n)ormal or (s)trict, opts->dotsOK allows dots at the
 	 * beginning of name (for hidden files)
@@ -41,52 +44,66 @@ static int msdos_format_name(const unsig
 	unsigned char c;
 	int space;
 
-	if (name[0] == '.') {  /* dotfile because . and .. already done */
+	if (name[0] == '.') {	/* dotfile because . and .. already done */
 		if (opts->dotsOK) {
 			/* Get rid of dot - test for it elsewhere */
-			name++; len--;
-		}
-		else if (!opts->atari) return -EINVAL;
+			name++;
+			len--;
+		} else if (!opts->atari)
+			return -EINVAL;
 	}
-	/* disallow names that _really_ start with a dot for MS-DOS, GEMDOS does
-	 * not care */
+	/*
+	 * disallow names that _really_ start with a dot for MS-DOS,
+	 * GEMDOS does not care
+	 */
 	space = !opts->atari;
 	c = 0;
-	for (walk = res; len && walk-res < 8; walk++) {
-	    	c = *name++;
+	for (walk = res; len && walk - res < 8; walk++) {
+		c = *name++;
 		len--;
-		if (opts->name_check != 'r' && strchr(bad_chars,c))
+		if (opts->name_check != 'r' && strchr(bad_chars, c))
 			return -EINVAL;
-		if (opts->name_check == 's' && strchr(bad_if_strict(opts),c))
+		if (opts->name_check == 's' && strchr(bad_if_strict(opts), c))
 			return -EINVAL;
-  		if (c >= 'A' && c <= 'Z' && opts->name_check == 's')
+		if (c >= 'A' && c <= 'Z' && opts->name_check == 's')
 			return -EINVAL;
-		if (c < ' ' || c == ':' || c == '\\') return -EINVAL;
-/*  0xE5 is legal as a first character, but we must substitute 0x05     */
-/*  because 0xE5 marks deleted files.  Yes, DOS really does this.       */
-/*  It seems that Microsoft hacked DOS to support non-US characters     */
-/*  after the 0xE5 character was already in use to mark deleted files.  */
-		if((res==walk) && (c==0xE5)) c=0x05;
-		if (c == '.') break;
+		if (c < ' ' || c == ':' || c == '\\')
+			return -EINVAL;
+	/*
+	 * 0xE5 is legal as a first character, but we must substitute
+	 * 0x05 because 0xE5 marks deleted files.  Yes, DOS really
+	 * does this.
+	 * It seems that Microsoft hacked DOS to support non-US
+	 * characters after the 0xE5 character was already in use to
+	 * mark deleted files.
+	 */
+		if ((res == walk) && (c == 0xE5))
+			c = 0x05;
+		if (c == '.')
+			break;
 		space = (c == ' ');
-		*walk = (!opts->nocase && c >= 'a' && c <= 'z') ? c-32 : c;
+		*walk = (!opts->nocase && c >= 'a' && c <= 'z') ? c - 32 : c;
 	}
-	if (space) return -EINVAL;
+	if (space)
+		return -EINVAL;
 	if (opts->name_check == 's' && len && c != '.') {
 		c = *name++;
 		len--;
-		if (c != '.') return -EINVAL;
+		if (c != '.')
+			return -EINVAL;
 	}
-	while (c != '.' && len--) c = *name++;
+	while (c != '.' && len--)
+		c = *name++;
 	if (c == '.') {
-		while (walk-res < 8) *walk++ = ' ';
-		while (len > 0 && walk-res < MSDOS_NAME) {
+		while (walk - res < 8)
+			*walk++ = ' ';
+		while (len > 0 && walk - res < MSDOS_NAME) {
 			c = *name++;
 			len--;
-			if (opts->name_check != 'r' && strchr(bad_chars,c))
+			if (opts->name_check != 'r' && strchr(bad_chars, c))
 				return -EINVAL;
 			if (opts->name_check == 's' &&
-			    strchr(bad_if_strict(opts),c))
+			    strchr(bad_if_strict(opts), c))
 				return -EINVAL;
 			if (c < ' ' || c == ':' || c == '\\')
 				return -EINVAL;
@@ -98,16 +115,23 @@ static int msdos_format_name(const unsig
 			if (c >= 'A' && c <= 'Z' && opts->name_check == 's')
 				return -EINVAL;
 			space = c == ' ';
-			*walk++ = (!opts->nocase && c >= 'a' && c <= 'z') ? c-32 : c;
+			if (!opts->nocase && c >= 'a' && c <= 'z')
+				*walk++ = c - 32;
+			else
+				*walk++ = c;
 		}
-		if (space) return -EINVAL;
-		if (opts->name_check == 's' && len) return -EINVAL;
+		if (space)
+			return -EINVAL;
+		if (opts->name_check == 's' && len)
+			return -EINVAL;
 	}
-	while (walk-res < MSDOS_NAME) *walk++ = ' ';
+	while (walk - res < MSDOS_NAME)
+		*walk++ = ' ';
 	if (!opts->atari)
 		/* GEMDOS is less stupid and has no reserved names */
 		for (reserved = reserved_names; *reserved; reserved++)
-			if (!strncmp(res,*reserved,8)) return -EINVAL;
+			if (!strncmp(res, *reserved, 8))
+				return -EINVAL;
 	return 0;
 }
 
@@ -121,12 +145,13 @@ static int msdos_find(struct inode *dir,
 	int res;
 
 	dotsOK = MSDOS_SB(dir->i_sb)->options.dotsOK;
-	res = msdos_format_name(name,len, msdos_name,&MSDOS_SB(dir->i_sb)->options);
+	res = msdos_format_name(name, len, msdos_name,
+				&MSDOS_SB(dir->i_sb)->options);
 	if (res < 0)
 		return -ENOENT;
 	res = fat_scan(dir, msdos_name, bh, de, i_pos);
 	if (!res && dotsOK) {
-		if (name[0]=='.') {
+		if (name[0] == '.') {
 			if (!((*de)->attr & ATTR_HIDDEN))
 				res = -ENOENT;
 		} else {
@@ -145,10 +170,10 @@ static int msdos_find(struct inode *dir,
  */
 static int msdos_hash(struct dentry *dentry, struct qstr *qstr)
 {
-	struct fat_mount_options *options = & (MSDOS_SB(dentry->d_sb)->options);
+	struct fat_mount_options *options = &MSDOS_SB(dentry->d_sb)->options;
 	unsigned char msdos_name[MSDOS_NAME];
 	int error;
-	
+
 	error = msdos_format_name(qstr->name, qstr->len, msdos_name, options);
 	if (!error)
 		qstr->hash = full_name_hash(msdos_name, MSDOS_NAME);
@@ -161,7 +186,7 @@ static int msdos_hash(struct dentry *den
  */
 static int msdos_cmp(struct dentry *dentry, struct qstr *a, struct qstr *b)
 {
-	struct fat_mount_options *options = & (MSDOS_SB(dentry->d_sb)->options);
+	struct fat_mount_options *options = &MSDOS_SB(dentry->d_sb)->options;
 	unsigned char a_msdos_name[MSDOS_NAME], b_msdos_name[MSDOS_NAME];
 	int error;
 
@@ -182,7 +207,6 @@ old_compare:
 	goto out;
 }
 
-
 static struct dentry_operations msdos_dentry_operations = {
 	.d_hash		= msdos_hash,
 	.d_compare	= msdos_cmp,
@@ -194,7 +218,7 @@ static struct dentry_operations msdos_de
 
 /***** Get inode using directory and name */
 static struct dentry *msdos_lookup(struct inode *dir, struct dentry *dentry,
-		struct nameidata *nd)
+				   struct nameidata *nd)
 {
 	struct super_block *sb = dir->i_sb;
 	struct inode *inode = NULL;
@@ -202,7 +226,7 @@ static struct dentry *msdos_lookup(struc
 	struct buffer_head *bh = NULL;
 	loff_t i_pos;
 	int res;
-	
+
 	dentry->d_op = &msdos_dentry_operations;
 
 	lock_kernel();
@@ -260,7 +284,7 @@ static int msdos_add_entry(struct inode 
 
 /***** Create a file */
 static int msdos_create(struct inode *dir, struct dentry *dentry, int mode,
-		struct nameidata *nd)
+			struct nameidata *nd)
 {
 	struct super_block *sb = dir->i_sb;
 	struct buffer_head *bh;
@@ -271,19 +295,19 @@ static int msdos_create(struct inode *di
 	unsigned char msdos_name[MSDOS_NAME];
 
 	lock_kernel();
-	res = msdos_format_name(dentry->d_name.name,dentry->d_name.len,
+	res = msdos_format_name(dentry->d_name.name, dentry->d_name.len,
 				msdos_name, &MSDOS_SB(sb)->options);
 	if (res < 0) {
 		unlock_kernel();
 		return res;
 	}
-	is_hid = (dentry->d_name.name[0]=='.') && (msdos_name[0]!='.');
+	is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.');
 	/* Have to do it due to foo vs. .foo conflicts */
 	if (fat_scan(dir, msdos_name, &bh, &de, &i_pos) >= 0) {
 		brelse(bh);
 		unlock_kernel();
 		return -EINVAL;
- 	}
+	}
 	inode = NULL;
 	res = msdos_add_entry(dir, msdos_name, &bh, &de, &i_pos, 0, is_hid);
 	if (res) {
@@ -349,18 +373,18 @@ static int msdos_mkdir(struct inode *dir
 	struct buffer_head *bh;
 	struct msdos_dir_entry *de;
 	struct inode *inode;
-	int res,is_hid;
+	int res, is_hid;
 	unsigned char msdos_name[MSDOS_NAME];
 	loff_t i_pos;
 
 	lock_kernel();
-	res = msdos_format_name(dentry->d_name.name,dentry->d_name.len,
+	res = msdos_format_name(dentry->d_name.name, dentry->d_name.len,
 				msdos_name, &MSDOS_SB(sb)->options);
 	if (res < 0) {
 		unlock_kernel();
 		return res;
 	}
-	is_hid = (dentry->d_name.name[0]=='.') && (msdos_name[0]!='.');
+	is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.');
 	/* foo vs .foo situation */
 	if (fat_scan(dir, msdos_name, &bh, &de, &i_pos) >= 0)
 		goto out_exist;
@@ -376,7 +400,7 @@ static int msdos_mkdir(struct inode *dir
 	res = 0;
 
 	dir->i_nlink++;
-	inode->i_nlink = 2; /* no need to mark them dirty */
+	inode->i_nlink = 2;	/* no need to mark them dirty */
 
 	res = fat_new_dir(inode, dir, 0);
 	if (res)
@@ -440,14 +464,16 @@ unlink_done:
 }
 
 static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
-    struct dentry *old_dentry,
-    struct inode *new_dir, unsigned char *new_name, struct dentry *new_dentry,
-    struct buffer_head *old_bh,
-    struct msdos_dir_entry *old_de, loff_t old_i_pos, int is_hid)
-{
-	struct buffer_head *new_bh=NULL,*dotdot_bh=NULL;
-	struct msdos_dir_entry *new_de,*dotdot_de;
-	struct inode *old_inode,*new_inode;
+			   struct dentry *old_dentry,
+			   struct inode *new_dir, unsigned char *new_name,
+			   struct dentry *new_dentry,
+			   struct buffer_head *old_bh,
+			   struct msdos_dir_entry *old_de, loff_t old_i_pos,
+			   int is_hid)
+{
+	struct buffer_head *new_bh = NULL, *dotdot_bh = NULL;
+	struct msdos_dir_entry *new_de, *dotdot_de;
+	struct inode *old_inode, *new_inode;
 	loff_t new_i_pos, dotdot_i_pos;
 	int error;
 	int is_dir;
@@ -456,8 +482,8 @@ static int do_msdos_rename(struct inode 
 	new_inode = new_dentry->d_inode;
 	is_dir = S_ISDIR(old_inode->i_mode);
 
-	if (fat_scan(new_dir, new_name, &new_bh, &new_de, &new_i_pos) >= 0
-	    && !new_inode)
+	if (fat_scan(new_dir, new_name, &new_bh, &new_de, &new_i_pos) >= 0 &&
+	    !new_inode)
 		goto degenerate_case;
 	if (is_dir) {
 		if (new_inode) {
@@ -502,7 +528,8 @@ static int do_msdos_rename(struct inode 
 	}
 	if (dotdot_bh) {
 		dotdot_de->start = cpu_to_le16(MSDOS_I(new_dir)->i_logstart);
-		dotdot_de->starthi = cpu_to_le16((MSDOS_I(new_dir)->i_logstart) >> 16);
+		dotdot_de->starthi =
+			cpu_to_le16((MSDOS_I(new_dir)->i_logstart) >> 16);
 		mark_buffer_dirty(dotdot_bh);
 		old_dir->i_nlink--;
 		mark_inode_dirty(old_dir);
@@ -522,7 +549,7 @@ out:
 
 degenerate_case:
 	error = -EINVAL;
-	if (new_de!=old_de)
+	if (new_de != old_de)
 		goto out;
 	if (is_hid)
 		MSDOS_I(old_inode)->i_attrs |= ATTR_HIDDEN;
@@ -537,7 +564,7 @@ degenerate_case:
 
 /***** Rename, a wrapper for rename_same_dir & rename_diff_dir */
 static int msdos_rename(struct inode *old_dir, struct dentry *old_dentry,
-		struct inode *new_dir, struct dentry *new_dentry)
+			struct inode *new_dir, struct dentry *new_dentry)
 {
 	struct buffer_head *old_bh;
 	struct msdos_dir_entry *old_de;
@@ -547,18 +574,21 @@ static int msdos_rename(struct inode *ol
 
 	lock_kernel();
 	error = msdos_format_name(old_dentry->d_name.name,
-				  old_dentry->d_name.len,old_msdos_name,
+				  old_dentry->d_name.len, old_msdos_name,
 				  &MSDOS_SB(old_dir->i_sb)->options);
 	if (error < 0)
 		goto rename_done;
 	error = msdos_format_name(new_dentry->d_name.name,
-				  new_dentry->d_name.len,new_msdos_name,
+				  new_dentry->d_name.len, new_msdos_name,
 				  &MSDOS_SB(new_dir->i_sb)->options);
 	if (error < 0)
 		goto rename_done;
 
-	is_hid  = (new_dentry->d_name.name[0]=='.') && (new_msdos_name[0]!='.');
-	old_hid = (old_dentry->d_name.name[0]=='.') && (old_msdos_name[0]!='.');
+	is_hid =
+	     (new_dentry->d_name.name[0] == '.') && (new_msdos_name[0] != '.');
+	old_hid =
+	     (old_dentry->d_name.name[0] == '.') && (old_msdos_name[0] != '.');
+
 	error = fat_scan(old_dir, old_msdos_name, &old_bh, &old_de, &old_i_pos);
 	if (error < 0)
 		goto rename_done;
@@ -583,7 +613,7 @@ static struct inode_operations msdos_dir
 	.setattr	= fat_notify_change,
 };
 
-static int msdos_fill_super(struct super_block *sb,void *data, int silent)
+static int msdos_fill_super(struct super_block *sb, void *data, int silent)
 {
 	int res;
 
@@ -596,7 +626,8 @@ static int msdos_fill_super(struct super
 }
 
 static struct super_block *msdos_get_sb(struct file_system_type *fs_type,
-	int flags, const char *dev_name, void *data)
+					int flags, const char *dev_name,
+					void *data)
 {
 	return get_sb_bdev(fs_type, flags, dev_name, data, msdos_fill_super);
 }

_

author maintainer
#9 lore raw

PATCH 10/13 FAT: Lindent fs/vfat/namei.c

---

 fs/vfat/namei.c |  225 ++++++++++++++++++++++++++++----------------------------
 1 files changed, 113 insertions(+), 112 deletions(-)
fs/vfat/namei.c renamed from fs/vfat/namei.c~fat_lindent-vfat +113 -112
diff -puN fs/vfat/namei.c~fat_lindent-vfat fs/vfat/namei.c
@@ -12,7 +12,7 @@
  *  Short name translation 1999, 2001 by Wolfram Pienkoss <[email protected]>
  *
  *  Support Multibyte character and cleanup by
- *  				OGAWA Hirofumi <[email protected]>
+ *				OGAWA Hirofumi <[email protected]>
  */
 
 #include <linux/module.h>
@@ -25,33 +25,6 @@
 #include <linux/buffer_head.h>
 #include <linux/namei.h>
 
-static int vfat_hashi(struct dentry *parent, struct qstr *qstr);
-static int vfat_hash(struct dentry *parent, struct qstr *qstr);
-static int vfat_cmpi(struct dentry *dentry, struct qstr *a, struct qstr *b);
-static int vfat_cmp(struct dentry *dentry, struct qstr *a, struct qstr *b);
-static int vfat_revalidate(struct dentry *dentry, struct nameidata *nd);
-
-static struct dentry_operations vfat_dentry_ops[4] = {
-	{
-		.d_hash		= vfat_hashi,
-		.d_compare	= vfat_cmpi,
-	},
-	{
-		.d_revalidate	= vfat_revalidate,
-		.d_hash		= vfat_hashi,
-		.d_compare	= vfat_cmpi,
-	},
-	{
-		.d_hash		= vfat_hash,
-		.d_compare	= vfat_cmp,
-	},
-	{
-		.d_revalidate	= vfat_revalidate,
-		.d_hash		= vfat_hash,
-		.d_compare	= vfat_cmp,
-	}
-};
-
 static int vfat_revalidate(struct dentry *dentry, struct nameidata *nd)
 {
 	int ret = 1;
@@ -78,9 +51,8 @@ static unsigned int vfat_striptail_len(s
 {
 	unsigned int len = qstr->len;
 
-	while (len && qstr->name[len-1] == '.')
+	while (len && qstr->name[len - 1] == '.')
 		len--;
-
 	return len;
 }
 
@@ -93,7 +65,6 @@ static unsigned int vfat_striptail_len(s
 static int vfat_hash(struct dentry *dentry, struct qstr *qstr)
 {
 	qstr->hash = full_name_hash(qstr->name, vfat_striptail_len(qstr));
-
 	return 0;
 }
 
@@ -156,6 +127,27 @@ static int vfat_cmp(struct dentry *dentr
 	return 1;
 }
 
+static struct dentry_operations vfat_dentry_ops[4] = {
+	{
+		.d_hash		= vfat_hashi,
+		.d_compare	= vfat_cmpi,
+	},
+	{
+		.d_revalidate	= vfat_revalidate,
+		.d_hash		= vfat_hashi,
+		.d_compare	= vfat_cmpi,
+	},
+	{
+		.d_hash		= vfat_hash,
+		.d_compare	= vfat_cmp,
+	},
+	{
+		.d_revalidate	= vfat_revalidate,
+		.d_hash		= vfat_hash,
+		.d_compare	= vfat_cmp,
+	}
+};
+
 /* Characters that are undesirable in an MS-DOS file name */
 
 static inline wchar_t vfat_bad_char(wchar_t w)
@@ -183,7 +175,7 @@ static wchar_t vfat_skip_char(wchar_t w)
 static inline int vfat_is_used_badchars(const wchar_t *s, int len)
 {
 	int i;
-	
+
 	for (i = 0; i < len; i++)
 		if (vfat_bad_char(s[i]))
 			return -EINVAL;
@@ -231,7 +223,7 @@ static int vfat_find_form(struct inode *
 	return 0;
 }
 
-/* 
+/*
  * 1) Valid characters for the 8.3 format alias are any combination of
  * letters, uppercase alphabets, digits, any of the
  * following special characters:
@@ -241,11 +233,11 @@ static int vfat_find_form(struct inode *
  * WinNT's Extension:
  * File name and extension name is contain uppercase/lowercase
  * only. And it is expressed by CASE_LOWER_BASE and CASE_LOWER_EXT.
- *     
+ *
  * 2) File name is 8.3 format, but it contain the uppercase and
  * lowercase char, muliti bytes char, etc. In this case numtail is not
  * added, but Longfilename is stored.
- * 
+ *
  * 3) When the one except for the above, or the following special
  * character are contained:
  *        .   [ ] ; , + =
@@ -263,8 +255,8 @@ struct shortname_info {
 } while (0)
 
 static inline int to_shortname_char(struct nls_table *nls,
-				    unsigned char *buf, int buf_size, wchar_t *src,
-				    struct shortname_info *info)
+				    unsigned char *buf, int buf_size,
+				    wchar_t *src, struct shortname_info *info)
 {
 	int len;
 
@@ -277,7 +269,7 @@ static inline int to_shortname_char(stru
 		buf[0] = '_';
 		return 1;
 	}
-	
+
 	len = nls->uni2char(*src, buf, buf_size);
 	if (len <= 0) {
 		info->valid = 0;
@@ -302,7 +294,7 @@ static inline int to_shortname_char(stru
 		info->lower = 0;
 		info->upper = 0;
 	}
-	
+
 	return len;
 }
 
@@ -332,7 +324,7 @@ static int vfat_create_shortname(struct 
 	/* Now, we need to create a shortname from the long name */
 	ext_start = end = &uname[ulen];
 	while (--ext_start >= uname) {
-		if (*ext_start == 0x002E) { /* is `.' */
+		if (*ext_start == 0x002E) {	/* is `.' */
 			if (ext_start == end - 1) {
 				sz = ulen;
 				ext_start = NULL;
@@ -361,7 +353,7 @@ static int vfat_create_shortname(struct 
 			ext_start++;
 		} else {
 			sz = ulen;
-			ext_start=NULL;
+			ext_start = NULL;
 		}
 	}
 
@@ -377,7 +369,7 @@ static int vfat_create_shortname(struct 
 			numtail2_baselen = baselen;
 		if (baselen < 6 && (baselen + chl) > 6)
 			numtail_baselen = baselen;
-		for (chi = 0; chi < chl; chi++){
+		for (chi = 0; chi < chl; chi++) {
 			*p++ = charbuf[chi];
 			baselen++;
 			if (baselen >= 8)
@@ -452,7 +444,7 @@ static int vfat_create_shortname(struct 
 			BUG();
 		}
 	}
-	
+
 	if (MSDOS_SB(dir->i_sb)->options.numtail == 0)
 		if (vfat_find_form(dir, name_res) < 0)
 			return 0;
@@ -465,25 +457,25 @@ static int vfat_create_shortname(struct 
 	 * values for part of the base.
 	 */
 
-	if (baselen>6) {
+	if (baselen > 6) {
 		baselen = numtail_baselen;
 		name_res[7] = ' ';
 	}
 	name_res[baselen] = '~';
 	for (i = 1; i < 10; i++) {
-		name_res[baselen+1] = i + '0';
+		name_res[baselen + 1] = i + '0';
 		if (vfat_find_form(dir, name_res) < 0)
 			return 0;
 	}
 
 	i = jiffies & 0xffff;
 	sz = (jiffies >> 16) & 0x7;
-	if (baselen>2) {
+	if (baselen > 2) {
 		baselen = numtail2_baselen;
 		name_res[7] = ' ';
 	}
-	name_res[baselen+4] = '~';
-	name_res[baselen+5] = '1' + sz;
+	name_res[baselen + 4] = '~';
+	name_res[baselen + 5] = '1' + sz;
 	while (1) {
 		sprintf(buf, "%04X", i);
 		memcpy(&name_res[baselen], buf, 4);
@@ -516,13 +508,14 @@ xlate_to_uni(const unsigned char *name, 
 		 * We stripped '.'s before and set len appropriately,
 		 * but utf8_mbstowcs doesn't care about len
 		 */
-		*outlen -= (name_len-len);
+		*outlen -= (name_len - len);
 
 		op = &outname[*outlen * sizeof(wchar_t)];
 	} else {
 		if (nls) {
 			for (i = 0, ip = name, op = outname, *outlen = 0;
-			     i < len && *outlen <= 260; *outlen += 1)
+			     i < len && *outlen <= 260;
+			     *outlen += 1)
 			{
 				if (escape && (*ip == ':')) {
 					if (i > len - 5)
@@ -550,7 +543,7 @@ xlate_to_uni(const unsigned char *name, 
 					ip += 5;
 					i += 5;
 				} else {
-					if ((charlen = nls->char2uni(ip, len-i, (wchar_t *)op)) < 0)
+					if ((charlen = nls->char2uni(ip, len - i, (wchar_t *)op)) < 0)
 						return -EINVAL;
 					ip += charlen;
 					i += charlen;
@@ -559,7 +552,8 @@ xlate_to_uni(const unsigned char *name, 
 			}
 		} else {
 			for (i = 0, ip = name, op = outname, *outlen = 0;
-			     i < len && *outlen <= 260; i++, *outlen += 1)
+			     i < len && *outlen <= 260;
+			     i++, *outlen += 1)
 			{
 				*op++ = *ip++;
 				*op++ = 0;
@@ -607,7 +601,8 @@ static int vfat_build_slots(struct inode
 	if (res)
 		return res;
 
-	if(!(page = __get_free_page(GFP_KERNEL)))
+	page = __get_free_page(GFP_KERNEL);
+	if (!page)
 		return -ENOMEM;
 
 	uname = (wchar_t *)page;
@@ -632,9 +627,8 @@ static int vfat_build_slots(struct inode
 
 	/* build the entry of long file name */
 	*slots = usize / 13;
-	for (cksum = i = 0; i < 11; i++) {
+	for (cksum = i = 0; i < 11; i++)
 		cksum = (((cksum&1)<<7)|((cksum&0xfe)>>1)) + msdos_name[i];
-	}
 
 	for (ps = ds, slot = *slots; slot > 0; slot--, ps++) {
 		ps->id = slot;
@@ -648,7 +642,7 @@ static int vfat_build_slots(struct inode
 		fatwchar_to16(ps->name11_12, uname + offset + 11, 2);
 	}
 	ds[0].id |= 0x40;
-	de = (struct msdos_dir_entry *) ps;
+	de = (struct msdos_dir_entry *)ps;
 
 shortname:
 	/* build the entry of 8.3 alias name */
@@ -668,7 +662,7 @@ out_free:
 	return res;
 }
 
-static int vfat_add_entry(struct inode *dir,struct qstr* qname,
+static int vfat_add_entry(struct inode *dir, struct qstr *qname,
 			  int is_dir, struct vfat_slot_info *sinfo_out,
 			  struct buffer_head **bh, struct msdos_dir_entry **de)
 {
@@ -684,8 +678,7 @@ static int vfat_add_entry(struct inode *
 	if (len == 0)
 		return -ENOENT;
 
-	dir_slots =
-	       kmalloc(sizeof(struct msdos_dir_slot) * MSDOS_SLOTS, GFP_KERNEL);
+	dir_slots = kmalloc(sizeof(*dir_slots) * MSDOS_SLOTS, GFP_KERNEL);
 	if (dir_slots == NULL)
 		return -ENOMEM;
 
@@ -695,7 +688,8 @@ static int vfat_add_entry(struct inode *
 		goto cleanup;
 
 	/* build the empty directory entry of number of slots */
-	offset = fat_add_entries(dir, slots, &dummy_bh, &dummy_de, &dummy_i_pos);
+	offset =
+	    fat_add_entries(dir, slots, &dummy_bh, &dummy_de, &dummy_i_pos);
 	if (offset < 0) {
 		res = offset;
 		goto cleanup;
@@ -735,9 +729,9 @@ cleanup:
 	return res;
 }
 
-static int vfat_find(struct inode *dir,struct qstr* qname,
-	struct vfat_slot_info *sinfo, struct buffer_head **last_bh,
-	struct msdos_dir_entry **last_de)
+static int vfat_find(struct inode *dir, struct qstr *qname,
+		     struct vfat_slot_info *sinfo, struct buffer_head **last_bh,
+		     struct msdos_dir_entry **last_de)
 {
 	struct super_block *sb = dir->i_sb;
 	loff_t offset;
@@ -751,17 +745,17 @@ static int vfat_find(struct inode *dir,s
 	res = fat_search_long(dir, qname->name, len,
 			      (MSDOS_SB(sb)->options.name_check != 's'),
 			      &offset, &sinfo->longname_offset);
-	if (res>0) {
-		sinfo->long_slots = res-1;
-		if (fat_get_entry(dir,&offset,last_bh,last_de,&sinfo->i_pos)>=0)
+	if (res > 0) {
+		sinfo->long_slots = res - 1;
+		if (fat_get_entry(dir, &offset, last_bh, last_de, &sinfo->i_pos) >= 0)
 			return 0;
 		res = -EIO;
-	} 
+	}
 	return res ? res : -ENOENT;
 }
 
 static struct dentry *vfat_lookup(struct inode *dir, struct dentry *dentry,
-		struct nameidata *nd)
+				  struct nameidata *nd)
 {
 	int res;
 	struct vfat_slot_info sinfo;
@@ -770,13 +764,13 @@ static struct dentry *vfat_lookup(struct
 	struct buffer_head *bh = NULL;
 	struct msdos_dir_entry *de;
 	int table;
-	
+
 	lock_kernel();
 	table = (MSDOS_SB(dir->i_sb)->options.name_check == 's') ? 2 : 0;
 	dentry->d_op = &vfat_dentry_ops[table];
 
 	inode = NULL;
-	res = vfat_find(dir,&dentry->d_name,&sinfo,&bh,&de);
+	res = vfat_find(dir, &dentry->d_name, &sinfo, &bh, &de);
 	if (res < 0) {
 		table++;
 		goto error;
@@ -789,14 +783,14 @@ static struct dentry *vfat_lookup(struct
 	}
 	alias = d_find_alias(inode);
 	if (alias) {
-		if (d_invalidate(alias)==0)
+		if (d_invalidate(alias) == 0)
 			dput(alias);
 		else {
 			iput(inode);
 			unlock_kernel();
 			return alias;
 		}
-		
+
 	}
 error:
 	unlock_kernel();
@@ -810,8 +804,8 @@ error:
 	return dentry;
 }
 
-static int vfat_create(struct inode *dir, struct dentry* dentry, int mode,
-		struct nameidata *nd)
+static int vfat_create(struct inode *dir, struct dentry *dentry, int mode,
+		       struct nameidata *nd)
 {
 	struct super_block *sb = dir->i_sb;
 	struct inode *inode = NULL;
@@ -834,14 +828,15 @@ static int vfat_create(struct inode *dir
 	inode->i_version++;
 	dir->i_version++;
 	dentry->d_time = dentry->d_parent->d_inode->i_version;
-	d_instantiate(dentry,inode);
+	d_instantiate(dentry, inode);
 out:
 	unlock_kernel();
 	return res;
 }
 
-static void vfat_remove_entry(struct inode *dir,struct vfat_slot_info *sinfo,
-     struct buffer_head *bh, struct msdos_dir_entry *de)
+static void vfat_remove_entry(struct inode *dir, struct vfat_slot_info *sinfo,
+			      struct buffer_head *bh,
+			      struct msdos_dir_entry *de)
 {
 	loff_t offset, i_pos;
 	int i;
@@ -853,7 +848,8 @@ static void vfat_remove_entry(struct ino
 	de->name[0] = DELETED_FLAG;
 	mark_buffer_dirty(bh);
 	/* remove the longname */
-	offset = sinfo->longname_offset; de = NULL;
+	offset = sinfo->longname_offset;
+	de = NULL;
 	for (i = sinfo->long_slots; i > 0; --i) {
 		if (fat_get_entry(dir, &offset, &bh, &de, &i_pos) < 0)
 			continue;
@@ -864,28 +860,30 @@ static void vfat_remove_entry(struct ino
 	brelse(bh);
 }
 
-static int vfat_rmdir(struct inode *dir, struct dentry* dentry)
+static int vfat_rmdir(struct inode *dir, struct dentry *dentry)
 {
-	int res;
+	struct inode *inode = dentry->d_inode;
 	struct vfat_slot_info sinfo;
 	struct buffer_head *bh = NULL;
 	struct msdos_dir_entry *de;
+	int res;
 
 	lock_kernel();
-	res = fat_dir_empty(dentry->d_inode);
+	res = fat_dir_empty(inode);
 	if (res)
 		goto out;
 
-	res = vfat_find(dir,&dentry->d_name,&sinfo, &bh, &de);
+	res = vfat_find(dir, &dentry->d_name, &sinfo, &bh, &de);
 	if (res < 0)
 		goto out;
+
 	res = 0;
-	dentry->d_inode->i_nlink = 0;
-	dentry->d_inode->i_mtime = dentry->d_inode->i_atime = CURRENT_TIME_SEC;
-	fat_detach(dentry->d_inode);
-	mark_inode_dirty(dentry->d_inode);
+	inode->i_nlink = 0;
+	inode->i_mtime = inode->i_atime = CURRENT_TIME_SEC;
+	fat_detach(inode);
+	mark_inode_dirty(inode);
 	/* releases bh */
-	vfat_remove_entry(dir,&sinfo,bh,de);
+	vfat_remove_entry(dir, &sinfo, bh, de);
 	dir->i_nlink--;
 out:
 	unlock_kernel();
@@ -894,28 +892,29 @@ out:
 
 static int vfat_unlink(struct inode *dir, struct dentry *dentry)
 {
-	int res;
+	struct inode *inode = dentry->d_inode;
 	struct vfat_slot_info sinfo;
 	struct buffer_head *bh = NULL;
 	struct msdos_dir_entry *de;
+	int res;
 
 	lock_kernel();
-	res = vfat_find(dir,&dentry->d_name,&sinfo,&bh,&de);
+	res = vfat_find(dir, &dentry->d_name, &sinfo, &bh, &de);
 	if (res < 0)
 		goto out;
-	dentry->d_inode->i_nlink = 0;
-	dentry->d_inode->i_mtime = dentry->d_inode->i_atime = CURRENT_TIME_SEC;
-	fat_detach(dentry->d_inode);
-	mark_inode_dirty(dentry->d_inode);
+	inode->i_nlink = 0;
+	inode->i_mtime = inode->i_atime = CURRENT_TIME_SEC;
+	fat_detach(inode);
+	mark_inode_dirty(inode);
 	/* releases bh */
-	vfat_remove_entry(dir,&sinfo,bh,de);
+	vfat_remove_entry(dir, &sinfo, bh, de);
 out:
 	unlock_kernel();
 
 	return res;
 }
 
-static int vfat_mkdir(struct inode *dir,struct dentry* dentry,int mode)
+static int vfat_mkdir(struct inode *dir, struct dentry *dentry, int mode)
 {
 	struct super_block *sb = dir->i_sb;
 	struct inode *inode = NULL;
@@ -936,12 +935,12 @@ static int vfat_mkdir(struct inode *dir,
 	inode->i_version++;
 	dir->i_version++;
 	dir->i_nlink++;
-	inode->i_nlink = 2; /* no need to mark them dirty */
+	inode->i_nlink = 2;	/* no need to mark them dirty */
 	res = fat_new_dir(inode, dir, 1);
 	if (res < 0)
 		goto mkdir_failed;
 	dentry->d_time = dentry->d_parent->d_inode->i_version;
-	d_instantiate(dentry,inode);
+	d_instantiate(dentry, inode);
 out_brelse:
 	brelse(bh);
 out:
@@ -954,27 +953,28 @@ mkdir_failed:
 	fat_detach(inode);
 	mark_inode_dirty(inode);
 	/* releases bh */
-	vfat_remove_entry(dir,&sinfo,bh,de);
+	vfat_remove_entry(dir, &sinfo, bh, de);
 	iput(inode);
 	dir->i_nlink--;
 	goto out;
 }
- 
+
 static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,
-		struct inode *new_dir, struct dentry *new_dentry)
+		       struct inode *new_dir, struct dentry *new_dentry)
 {
-	struct buffer_head *old_bh,*new_bh,*dotdot_bh;
-	struct msdos_dir_entry *old_de,*new_de,*dotdot_de;
+	struct buffer_head *old_bh, *new_bh, *dotdot_bh;
+	struct msdos_dir_entry *old_de, *new_de, *dotdot_de;
 	loff_t dotdot_i_pos;
 	struct inode *old_inode, *new_inode;
 	int res, is_dir;
-	struct vfat_slot_info old_sinfo,sinfo;
+	struct vfat_slot_info old_sinfo, sinfo;
 
 	old_bh = new_bh = dotdot_bh = NULL;
 	old_inode = old_dentry->d_inode;
 	new_inode = new_dentry->d_inode;
 	lock_kernel();
-	res = vfat_find(old_dir,&old_dentry->d_name,&old_sinfo,&old_bh,&old_de);
+	res = vfat_find(old_dir, &old_dentry->d_name, &old_sinfo, &old_bh,
+			&old_de);
 	if (res < 0)
 		goto rename_done;
 
@@ -989,7 +989,7 @@ static int vfat_rename(struct inode *old
 	}
 
 	if (new_dentry->d_inode) {
-		res = vfat_find(new_dir,&new_dentry->d_name,&sinfo,&new_bh,
+		res = vfat_find(new_dir, &new_dentry->d_name, &sinfo, &new_bh,
 				&new_de);
 		if (res < 0 || MSDOS_I(new_inode)->i_pos != sinfo.i_pos) {
 			/* WTF??? Cry and fail. */
@@ -1004,16 +1004,17 @@ static int vfat_rename(struct inode *old
 		}
 		fat_detach(new_inode);
 	} else {
-		res = vfat_add_entry(new_dir,&new_dentry->d_name,is_dir,&sinfo,
-					&new_bh,&new_de);
-		if (res < 0) goto rename_done;
+		res = vfat_add_entry(new_dir, &new_dentry->d_name, is_dir,
+				     &sinfo, &new_bh, &new_de);
+		if (res < 0)
+			goto rename_done;
 	}
 
 	new_dir->i_version++;
 
 	/* releases old_bh */
-	vfat_remove_entry(old_dir,&old_sinfo,old_bh,old_de);
-	old_bh=NULL;
+	vfat_remove_entry(old_dir, &old_sinfo, old_bh, old_de);
+	old_bh = NULL;
 	fat_detach(old_inode);
 	fat_attach(old_inode, sinfo.i_pos);
 	mark_inode_dirty(old_inode);
@@ -1046,7 +1047,6 @@ rename_done:
 	brelse(new_bh);
 	unlock_kernel();
 	return res;
-
 }
 
 static struct inode_operations vfat_dir_inode_operations = {
@@ -1076,7 +1076,8 @@ static int vfat_fill_super(struct super_
 }
 
 static struct super_block *vfat_get_sb(struct file_system_type *fs_type,
-	int flags, const char *dev_name, void *data)
+				       int flags, const char *dev_name,
+				       void *data)
 {
 	return get_sb_bdev(fs_type, flags, dev_name, data, vfat_fill_super);
 }

_

author maintainer
#10 lore raw

PATCH 11/13 FAT: fs/fat/* cleanup

This patch is just cleanup (whitespace, and place of functions is changed). No changes of logic.

---

 fs/fat/cache.c           |   68 ---
 fs/fat/dir.c             |  252 ++++++-----
 fs/fat/file.c            |  168 +++++--
 fs/fat/inode.c           | 1035 +++++++++++++++++++++++------------------------
 fs/fat/misc.c            |   94 +---
 include/linux/msdos_fs.h |  113 ++---
 6 files changed, 846 insertions(+), 884 deletions(-)
fs/fat/cache.c renamed from fs/fat/cache.c~fat_cleanup +3 -65
diff -puN fs/fat/cache.c~fat_cleanup fs/fat/cache.c
@@ -296,7 +296,7 @@ static int __fat_access(struct super_blo
 	return next;
 }
 
-/* 
+/*
  * Returns the this'th FAT entry, -1 if it is an end-of-file entry. If
  * new_value is != -1, that FAT entry is replaced by it.
  */
@@ -343,7 +343,7 @@ int fat_get_cluster(struct inode *inode,
 	int nr;
 
 	BUG_ON(MSDOS_I(inode)->i_start == 0);
-	
+
 	*fclus = 0;
 	*dclus = MSDOS_I(inode)->i_start;
 	if (cluster == 0)
@@ -368,7 +368,7 @@ int fat_get_cluster(struct inode *inode,
 
 		nr = fat_access(sb, *dclus, -1);
 		if (nr < 0)
- 			return nr;
+			return nr;
 		else if (nr == FAT_ENT_FREE) {
 			fat_fs_panic(sb, "%s: invalid cluster chain"
 				     " (i_pos %lld)", __FUNCTION__,
@@ -437,65 +437,3 @@ int fat_bmap(struct inode *inode, sector
 	}
 	return 0;
 }
-
-/* Free all clusters after the skip'th cluster. */
-int fat_free(struct inode *inode, int skip)
-{
-	struct super_block *sb = inode->i_sb;
-	int nr, ret, fclus, dclus;
-
-	if (MSDOS_I(inode)->i_start == 0)
-		return 0;
-
-	if (skip) {
-		ret = fat_get_cluster(inode, skip - 1, &fclus, &dclus);
-		if (ret < 0)
-			return ret;
-		else if (ret == FAT_ENT_EOF)
-			return 0;
-
-		nr = fat_access(sb, dclus, -1);
-		if (nr == FAT_ENT_EOF)
-			return 0;
-		else if (nr > 0) {
-			/*
-			 * write a new EOF, and get the remaining cluster
-			 * chain for freeing.
-			 */
-			nr = fat_access(sb, dclus, FAT_ENT_EOF);
-		}
-		if (nr < 0)
-			return nr;
-
-		fat_cache_inval_inode(inode);
-	} else {
-		fat_cache_inval_inode(inode);
-
-		nr = MSDOS_I(inode)->i_start;
-		MSDOS_I(inode)->i_start = 0;
-		MSDOS_I(inode)->i_logstart = 0;
-		mark_inode_dirty(inode);
-	}
-
-	lock_fat(sb);
-	do {
-		nr = fat_access(sb, nr, FAT_ENT_FREE);
-		if (nr < 0)
-			goto error;
-		else if (nr == FAT_ENT_FREE) {
-			fat_fs_panic(sb, "%s: deleting beyond EOF (i_pos %lld)",
-				     __FUNCTION__, MSDOS_I(inode)->i_pos);
-			nr = -EIO;
-			goto error;
-		}
-		if (MSDOS_SB(sb)->free_clusters != -1)
-			MSDOS_SB(sb)->free_clusters++;
-		inode->i_blocks -= MSDOS_SB(sb)->cluster_size >> 9;
-	} while (nr != FAT_ENT_EOF);
-	fat_clusters_flush(sb);
-	nr = 0;
-error:
-	unlock_fat(sb);
-
-	return nr;
-}
fs/fat/dir.c renamed from fs/fat/dir.c~fat_cleanup +137 -115

331 lines not on this page · raw message

fs/fat/file.c renamed from fs/fat/file.c~fat_cleanup +120 -48

206 lines not on this page · raw message

fs/fat/inode.c renamed from fs/fat/inode.c~fat_cleanup +509 -526

1,094 lines not on this page · raw message

fs/fat/misc.c renamed from fs/fat/misc.c~fat_cleanup +26 -68

151 lines not on this page · raw message

include/linux/msdos_fs.h renamed from include/linux/msdos_fs.h~fat_cleanup +51 -62

212 lines not on this page · raw message

_

author maintainer
#11 lore raw

PATCH 12/13 FAT: reserved clusters cleanup

- Replaces the "number of reserved clusters" by FAT_START_ENT.

- The ->clusters is total number of clusters. Instead of it, use the maximum cluster number (->max_cluster).

By this change, removes the some "->clusters + 2" calculation.

- Adds inline function for cluster to block number conversion. And replaces the open-coding for it.

---

 fs/fat/cache.c           |    8 +++-----
 fs/fat/dir.c             |    2 +-
 fs/fat/inode.c           |   25 +++++++++++++------------
 fs/fat/misc.c            |   27 ++++++++++++++-------------
 include/linux/msdos_fs.h |   11 ++++++++++-
 5 files changed, 41 insertions(+), 32 deletions(-)
fs/fat/cache.c renamed from fs/fat/cache.c~fat_max-clusters-cleanup +3 -5
diff -puN fs/fat/cache.c~fat_max-clusters-cleanup fs/fat/cache.c
@@ -305,7 +305,7 @@ int fat_access(struct super_block *sb, i
 	int next;
 
 	next = -EIO;
-	if (nr < 2 || MSDOS_SB(sb)->clusters + 2 <= nr) {
+	if (nr < FAT_START_ENT || MSDOS_SB(sb)->max_cluster <= nr) {
 		fat_fs_panic(sb, "invalid access to FAT (entry 0x%08x)", nr);
 		goto out;
 	}
@@ -431,9 +431,7 @@ int fat_bmap(struct inode *inode, sector
 	cluster = fat_bmap_cluster(inode, cluster);
 	if (cluster < 0)
 		return cluster;
-	else if (cluster) {
-		*phys = ((sector_t)cluster - 2) * sbi->sec_per_clus
-			+ sbi->data_start + offset;
-	}
+	else if (cluster)
+		*phys = fat_clus_to_blknr(sbi, cluster) + offset;
 	return 0;
 }
fs/fat/dir.c renamed from fs/fat/dir.c~fat_max-clusters-cleanup +1 -1
diff -puN fs/fat/dir.c~fat_max-clusters-cleanup fs/fat/dir.c
@@ -767,7 +767,7 @@ static struct buffer_head *fat_extend_di
 	if (nr < 0)
 		return ERR_PTR(nr);
 
-	sector = ((sector_t)nr - 2) * sec_per_clus + MSDOS_SB(sb)->data_start;
+	sector = fat_clus_to_blknr(MSDOS_SB(sb), nr);
 	last_sector = sector + sec_per_clus;
 	for ( ; sector < last_sector; sector++) {
 		if ((bh = sb_getblk(sb, sector))) {
fs/fat/inode.c renamed from fs/fat/inode.c~fat_max-clusters-cleanup +13 -12
diff -puN fs/fat/inode.c~fat_max-clusters-cleanup fs/fat/inode.c
@@ -419,17 +419,18 @@ static int fat_remount(struct super_bloc
 
 static int fat_statfs(struct super_block *sb, struct kstatfs *buf)
 {
+	struct msdos_sb_info *sbi = MSDOS_SB(sb);
 	int free, nr, ret;
 
-	if (MSDOS_SB(sb)->free_clusters != -1)
-		free = MSDOS_SB(sb)->free_clusters;
+	if (sbi->free_clusters != -1)
+		free = sbi->free_clusters;
 	else {
 		lock_fat(sb);
-		if (MSDOS_SB(sb)->free_clusters != -1)
-			free = MSDOS_SB(sb)->free_clusters;
+		if (sbi->free_clusters != -1)
+			free = sbi->free_clusters;
 		else {
 			free = 0;
-			for (nr = 2; nr < MSDOS_SB(sb)->clusters + 2; nr++) {
+			for (nr = FAT_START_ENT; nr < sbi->max_cluster; nr++) {
 				ret = fat_access(sb, nr, -1);
 				if (ret < 0) {
 					unlock_fat(sb);
@@ -437,17 +438,17 @@ static int fat_statfs(struct super_block
 				} else if (ret == FAT_ENT_FREE)
 					free++;
 			}
-			MSDOS_SB(sb)->free_clusters = free;
+			sbi->free_clusters = free;
 		}
 		unlock_fat(sb);
 	}
 
 	buf->f_type = sb->s_magic;
-	buf->f_bsize = MSDOS_SB(sb)->cluster_size;
-	buf->f_blocks = MSDOS_SB(sb)->clusters;
+	buf->f_bsize = sbi->cluster_size;
+	buf->f_blocks = sbi->max_cluster - FAT_START_ENT;
 	buf->f_bfree = free;
 	buf->f_bavail = free;
-	buf->f_namelen = MSDOS_SB(sb)->options.isvfat ? 260 : 12;
+	buf->f_namelen = sbi->options.isvfat ? 260 : 12;
 
 	return 0;
 }
@@ -1232,7 +1233,7 @@ int fat_fill_super(struct super_block *s
 
 	/* check that FAT table does not overflow */
 	fat_clusters = sbi->fat_length * sb->s_blocksize * 8 / sbi->fat_bits;
-	total_clusters = min(total_clusters, fat_clusters - 2);
+	total_clusters = min(total_clusters, fat_clusters - FAT_START_ENT);
 	if (total_clusters > MAX_FAT(sb)) {
 		if (!silent)
 			printk(KERN_ERR "FAT: count of clusters too big (%u)\n",
@@ -1241,9 +1242,9 @@ int fat_fill_super(struct super_block *s
 		goto out_invalid;
 	}
 
-	sbi->clusters = total_clusters;
+	sbi->max_cluster = total_clusters + FAT_START_ENT;
 	/* check the free_clusters, it's not necessarily correct */
-	if (sbi->free_clusters != -1 && sbi->free_clusters > sbi->clusters)
+	if (sbi->free_clusters != -1 && sbi->free_clusters > total_clusters)
 		sbi->free_clusters = -1;
 
 	brelse(bh);
fs/fat/misc.c renamed from fs/fat/misc.c~fat_max-clusters-cleanup +14 -13
diff -puN fs/fat/misc.c~fat_max-clusters-cleanup fs/fat/misc.c
@@ -86,8 +86,9 @@ void fat_clusters_flush(struct super_blo
 int fat_add_cluster(struct inode *inode)
 {
 	struct super_block *sb = inode->i_sb;
+	struct msdos_sb_info *sbi = MSDOS_SB(sb);
 	int ret, count, limit, new_dclus, new_fclus, last;
-	int cluster_bits = MSDOS_SB(sb)->cluster_bits;
+	int cluster_bits = sbi->cluster_bits;
 
 	/*
 	 * We must locate the last cluster of the file to add this new
@@ -110,17 +111,17 @@ int fat_add_cluster(struct inode *inode)
 	/* find free FAT entry */
 	lock_fat(sb);
 
-	if (MSDOS_SB(sb)->free_clusters == 0) {
+	if (sbi->free_clusters == 0) {
 		unlock_fat(sb);
 		return -ENOSPC;
 	}
 
-	limit = MSDOS_SB(sb)->clusters + 2;
-	new_dclus = MSDOS_SB(sb)->prev_free + 1;
-	for (count = 0; count < MSDOS_SB(sb)->clusters; count++, new_dclus++) {
+	limit = sbi->max_cluster;
+	new_dclus = sbi->prev_free + 1;
+	for (count = FAT_START_ENT; count < limit; count++, new_dclus++) {
 		new_dclus = new_dclus % limit;
-		if (new_dclus < 2)
-			new_dclus = 2;
+		if (new_dclus < FAT_START_ENT)
+			new_dclus = FAT_START_ENT;
 
 		ret = fat_access(sb, new_dclus, -1);
 		if (ret < 0) {
@@ -129,8 +130,8 @@ int fat_add_cluster(struct inode *inode)
 		} else if (ret == FAT_ENT_FREE)
 			break;
 	}
-	if (count >= MSDOS_SB(sb)->clusters) {
-		MSDOS_SB(sb)->free_clusters = 0;
+	if (count >= limit) {
+		sbi->free_clusters = 0;
 		unlock_fat(sb);
 		return -ENOSPC;
 	}
@@ -141,9 +142,9 @@ int fat_add_cluster(struct inode *inode)
 		return ret;
 	}
 
-	MSDOS_SB(sb)->prev_free = new_dclus;
-	if (MSDOS_SB(sb)->free_clusters != -1)
-		MSDOS_SB(sb)->free_clusters--;
+	sbi->prev_free = new_dclus;
+	if (sbi->free_clusters != -1)
+		sbi->free_clusters--;
 	fat_clusters_flush(sb);
 
 	unlock_fat(sb);
@@ -164,7 +165,7 @@ int fat_add_cluster(struct inode *inode)
 			new_fclus, inode->i_blocks >> (cluster_bits - 9));
 		fat_cache_inval_inode(inode);
 	}
-	inode->i_blocks += MSDOS_SB(sb)->cluster_size >> 9;
+	inode->i_blocks += sbi->cluster_size >> 9;
 
 	return new_dclus;
 }
include/linux/msdos_fs.h renamed from include/linux/msdos_fs.h~fat_max-clusters-cleanup +10 -1
diff -puN include/linux/msdos_fs.h~fat_max-clusters-cleanup include/linux/msdos_fs.h
@@ -64,6 +64,9 @@
 #define FAT_FIRST_ENT(s, x)	((MSDOS_SB(s)->fat_bits == 32 ? 0x0FFFFF00 : \
 	MSDOS_SB(s)->fat_bits == 16 ? 0xFF00 : 0xF00) | (x))
 
+/* start of data cluster's entry (number of reserved clusters) */
+#define FAT_START_ENT	2
+
 /* maximum number of clusters */
 #define MAX_FAT12	0xFF4
 #define MAX_FAT16	0xFFF4
@@ -221,7 +224,7 @@ struct msdos_sb_info {
 	unsigned long dir_start;
 	unsigned short dir_entries;  /* root dir start & entries */
 	unsigned long data_start;    /* first data sector */
-	unsigned long clusters;      /* number of clusters */
+	unsigned long max_cluster;   /* maximum cluster number */
 	unsigned long root_cluster;  /* first cluster of the root directory */
 	unsigned long fsinfo_sector; /* sector number of FAT32 fsinfo */
 	struct semaphore fat_lock;
@@ -270,6 +273,12 @@ static inline struct msdos_inode_info *M
 	return container_of(inode, struct msdos_inode_info, vfs_inode);
 }
 
+static inline sector_t fat_clus_to_blknr(struct msdos_sb_info *sbi, int clus)
+{
+	return ((sector_t)clus - FAT_START_ENT) * sbi->sec_per_clus
+		+ sbi->data_start;
+}
+
 static inline void fat16_towchar(wchar_t *dst, const __u8 *src, size_t len)
 {
 #ifdef __BIG_ENDIAN

_

author maintainer
#12 lore raw

PATCH 13/13 FAT: show current nls config even if it's default.

Default config may be setted by distributer. By this change, certainly the user can know current NLS using by FAT.

---

 fs/fat/inode.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
fs/fat/inode.c renamed from fs/fat/inode.c~fat_show-default +2 -3
diff -puN fs/fat/inode.c~fat_show-default fs/fat/inode.c
@@ -690,11 +690,10 @@ static int fat_show_options(struct seq_f
 		seq_printf(m, ",gid=%u", opts->fs_gid);
 	seq_printf(m, ",fmask=%04o", opts->fs_fmask);
 	seq_printf(m, ",dmask=%04o", opts->fs_dmask);
-	if (sbi->nls_disk && opts->codepage != fat_default_codepage)
+	if (sbi->nls_disk)
 		seq_printf(m, ",codepage=%s", sbi->nls_disk->charset);
 	if (isvfat) {
-		if (sbi->nls_io &&
-		    strcmp(opts->iocharset, fat_default_iocharset))
+		if (sbi->nls_io)
 			seq_printf(m, ",iocharset=%s", sbi->nls_io->charset);
 
 		switch (opts->shortname) {

_

#13 lore raw

Re: [PATCH 10/13] FAT: Lindent fs/vfat/namei.c

In reply to OGAWA Hirofumi

fs/vfat/namei.c line 14

Quoted 7 lines · OGAWA Hirofumi

diff -puN fs/vfat/namei.c~fat_lindent-vfat fs/vfat/namei.c

fs/vfat/namei.c renamed from fs/vfat/namei.c~fat_lindent-vfat +0 -0
@@ -12,7 +12,7 @@
  *  Short name translation 1999, 2001 by Wolfram Pienkoss <[email protected]>
  *
  *  Support Multibyte character and cleanup by

^^^ Shouldn't that be 'characters'?

Yup, that was it.. sorry if I'm nitpicking :-P

Sytse

author maintainer
#14 lore raw

Re: [PATCH 10/13] FAT: Lindent fs/vfat/namei.c

Quoted 2 lines · Sytse Wielinga
Quoted 1 line

* Support Multibyte character and cleanup by

^^^ Shouldn't that be 'characters'?

Thanks.

Please apply the following incremental patch.

Signature · 25 lines
OGAWA Hirofumi <[email protected]>



[PATCH 15] FAT: Fix typo in comment

Signed-off-by: OGAWA Hirofumi <[email protected]>
---

 fs/vfat/namei.c |    2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)

diff -puN fs/vfat/namei.c~fat_fix-typo fs/vfat/namei.c
--- linux-2.6.11-rc1/fs/vfat/namei.c~fat_fix-typo	2005-01-18 09:57:16.000000000 +0900
+++ linux-2.6.11-rc1-hirofumi/fs/vfat/namei.c	2005-01-18 09:57:16.000000000 +0900
@@ -11,7 +11,7 @@
  *
  *  Short name translation 1999, 2001 by Wolfram Pienkoss <[email protected]>
  *
- *  Support Multibyte character and cleanup by
+ *  Support Multibyte characters and cleanup by
  *				OGAWA Hirofumi <[email protected]>
  */
 
_
#15 lore raw

Re: [PATCH 4/13] FAT: Return better error codes from vfat_valid_longname()

In reply to OGAWA Hirofumi

fs/vfat/namei.c static inline int vfat_is_used_badchars( · line 196

Quoted 6 lines · OGAWA Hirofumi

static int vfat_valid_longname(const unsigned char *name, unsigned int len) {

fs/vfat/namei.c renamed from fs/vfat/namei.c~fat_nametoolong +2 -2
-	if (len && name[len-1] == ' ')
-		return 0;
+	if (name[len - 1] == ' ')
+		return -EINVAL;

Sorry for the stupid question, but is len guaranteed to be always greater than zero?

Otherwise, I think that the test with len would be warranted. And, if that is the case, wouldn't it be better to have it explicitly say if (len > 0...)?

Just curious. And sorry again for the stupid question. But as Knuth says, "premature optimization is the root of all evil".

Perhaps I'm way too much into proving invariants of algorithms. :-)

Thanks for your work, Rogério.

Signature · 3 lines
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  Rogério Brito - [email protected] - http://www.ime.usp.br/~rbrito
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
author maintainer
#16 lore raw

Re: [PATCH 4/13] FAT: Return better error codes from vfat_valid_longname()

Quoted 10 lines · Rogério Brito

fs/vfat/namei.c static inline int vfat_is_used_badchars( · line 196

Quoted 6 lines · OGAWA Hirofumi

static int vfat_valid_longname(const unsigned char *name, unsigned int len) {

fs/vfat/namei.c renamed from fs/vfat/namei.c~fat_nametoolong +2 -2
-	if (len && name[len-1] == ' ')
-		return 0;
+	if (name[len - 1] == ' ')
+		return -EINVAL;

Sorry for the stupid question, but is len guaranteed to be always greater than zero?

Yes. That "len" was already checked in vfat_add_entry().

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#17 lore raw

Re: [PATCH 4/13] FAT: Return better error codes from vfat_valid_longname()

Quoted 5 lines · OGAWA Hirofumi
Quoted 2 lines · Rogério Brito

Sorry for the stupid question, but is len guaranteed to be always greater than zero?

Yes. That "len" was already checked in vfat_add_entry().

Sorry for the stupid question then.

Thanks.

Signature · 3 lines
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  Rogério Brito - [email protected] - http://www.ime.usp.br/~rbrito
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#18 lore raw

Re: [PATCH 3/13] FAT: IS_BADCHAR/IS_REPLACECHR/IS_SKIPCHAR cleanup

In reply to OGAWA Hirofumi

fs/vfat/namei.c static int vfat_cmp(struct dentry *dentr · line 169

Quoted 9 lines · OGAWA Hirofumi
fs/vfat/namei.c renamed from fs/vfat/namei.c~fat_check-chars-cleanup +9 -0
+static inline wchar_t vfat_bad_char(wchar_t w)
+{
+	return (w < 0x0020)
+	    || (w == 0x002A) /* * */	|| (w == 0x003F) /* ? */
+	    || (w == 0x003C) /* < */	|| (w == 0x003E) /* > */
+	    || (w == 0x007C) /* | */	|| (w == 0x0022) /* " */
+	    || (w == 0x003A) /* : */	|| (w == 0x002F) /* / */
+	    || (w == 0x005C);/* \ */
+}

Ugh... What's wrong with comparison to '*', '<', etc.? All values are below 0x80, so signedness of char doesn't matter and when they get promoted to int, they will give you the values you want...

fs/vfat/namei.c static int vfat_cmp(struct dentry *dentr · line 176

Quoted 6 lines
fs/vfat/namei.c renamed from fs/vfat/namei.c~fat_check-chars-cleanup +6 -0
+static inline wchar_t vfat_replace_char(wchar_t w)
+{
+	return (w == 0x005B) /* [ */	|| (w == 0x005D) /* ] */
+	    || (w == 0x003B) /* ; */	|| (w == 0x002C) /* , */
+	    || (w == 0x002B) /* + */	|| (w == 0x003D);/* = */
+}

Ditto.

author maintainer
#19 lore raw

Re: [PATCH 3/13] FAT: IS_BADCHAR/IS_REPLACECHR/IS_SKIPCHAR cleanup

Quoted 3 lines · Al Viro

Ugh... What's wrong with comparison to '*', '<', etc.? All values are below 0x80, so signedness of char doesn't matter and when they get promoted to int, they will give you the values you want...

Indeed. Thanks.

Please apply the following incremental patch.

Signature · 46 lines
OGAWA Hirofumi <[email protected]>



[PATCH 14] FAT: Further IS_BADCHAR/IS_REPLACECHR/IS_SKIPCHAR cleanup

Signed-off-by: OGAWA Hirofumi <[email protected]>
---

 fs/vfat/namei.c |   15 ++++++---------
 1 files changed, 6 insertions(+), 9 deletions(-)

diff -puN fs/vfat/namei.c~fat_check-chars-cleanup2 fs/vfat/namei.c
--- linux-2.6.11-rc1/fs/vfat/namei.c~fat_check-chars-cleanup2	2005-01-18 09:50:45.000000000 +0900
+++ linux-2.6.11-rc1-hirofumi/fs/vfat/namei.c	2005-01-18 09:56:08.000000000 +0900
@@ -153,23 +153,20 @@ static struct dentry_operations vfat_den
 static inline wchar_t vfat_bad_char(wchar_t w)
 {
 	return (w < 0x0020)
-	    || (w == 0x002A) /* * */	|| (w == 0x003F) /* ? */
-	    || (w == 0x003C) /* < */	|| (w == 0x003E) /* > */
-	    || (w == 0x007C) /* | */	|| (w == 0x0022) /* " */
-	    || (w == 0x003A) /* : */	|| (w == 0x002F) /* / */
-	    || (w == 0x005C);/* \ */
+	    || (w == '*') || (w == '?') || (w == '<') || (w == '>')
+	    || (w == '|') || (w == '"') || (w == ':') || (w == '/')
+	    || (w == '\\');
 }
 
 static inline wchar_t vfat_replace_char(wchar_t w)
 {
-	return (w == 0x005B) /* [ */	|| (w == 0x005D) /* ] */
-	    || (w == 0x003B) /* ; */	|| (w == 0x002C) /* , */
-	    || (w == 0x002B) /* + */	|| (w == 0x003D);/* = */
+	return (w == '[') || (w == ']') || (w == ';') || (w == ',')
+	    || (w == '+') || (w == '=');
 }
 
 static wchar_t vfat_skip_char(wchar_t w)
 {
-	return (w == 0x002E) /* . */	|| (w == 0x0020);/* <space> */
+	return (w == '.') || (w == ' ');
 }
 
 static inline int vfat_is_used_badchars(const wchar_t *s, int len)
_