From 384f5c96ea05aba24a11172ebd6f5d427ca199fc Mon Sep 17 00:00:00 2001 From: OGAWA Hirofumi Date: Tue, 12 Apr 2011 21:08:37 +0900 Subject: [PATCH 1/6] fat: use new setup() for ->dir_ops too Signed-off-by: OGAWA Hirofumi --- fs/fat/fat.h | 3 +-- fs/fat/inode.c | 4 +--- fs/fat/namei_msdos.c | 4 ++-- fs/fat/namei_vfat.c | 4 ++-- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/fs/fat/fat.h b/fs/fat/fat.h index f50408901f7e..dc163b8d7699 100644 --- a/fs/fat/fat.h +++ b/fs/fat/fat.h @@ -319,8 +319,7 @@ extern struct inode *fat_build_inode(struct super_block *sb, struct msdos_dir_entry *de, loff_t i_pos); extern int fat_sync_inode(struct inode *inode); extern int fat_fill_super(struct super_block *sb, void *data, int silent, - const struct inode_operations *fs_dir_inode_ops, - int isvfat, void (*setup)(struct super_block *)); + int isvfat, void (*setup)(struct super_block *)); extern int fat_flush_inodes(struct super_block *sb, struct inode *i1, struct inode *i2); diff --git a/fs/fat/inode.c b/fs/fat/inode.c index 8d68690bdcf1..c27704dc485e 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c @@ -1238,8 +1238,7 @@ static int fat_read_root(struct inode *inode) /* * Read the super block of an MS-DOS FS. */ -int fat_fill_super(struct super_block *sb, void *data, int silent, - const struct inode_operations *fs_dir_inode_ops, int isvfat, +int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, void (*setup)(struct super_block *)) { struct inode *root_inode = NULL, *fat_inode = NULL; @@ -1268,7 +1267,6 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, sb->s_magic = MSDOS_SUPER_MAGIC; sb->s_op = &fat_sops; sb->s_export_op = &fat_export_ops; - sbi->dir_ops = fs_dir_inode_ops; ratelimit_state_init(&sbi->ratelimit, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST); diff --git a/fs/fat/namei_msdos.c b/fs/fat/namei_msdos.c index 711499040eb6..3b222dafd15b 100644 --- a/fs/fat/namei_msdos.c +++ b/fs/fat/namei_msdos.c @@ -659,14 +659,14 @@ static const struct inode_operations msdos_dir_inode_operations = { static void setup(struct super_block *sb) { + MSDOS_SB(sb)->dir_ops = &msdos_dir_inode_operations; sb->s_d_op = &msdos_dentry_operations; sb->s_flags |= MS_NOATIME; } static int msdos_fill_super(struct super_block *sb, void *data, int silent) { - return fat_fill_super(sb, data, silent, &msdos_dir_inode_operations, - 0, setup); + return fat_fill_super(sb, data, silent, 0, setup); } static struct dentry *msdos_mount(struct file_system_type *fs_type, diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c index adae3fb7451a..20b4ea53fdc4 100644 --- a/fs/fat/namei_vfat.c +++ b/fs/fat/namei_vfat.c @@ -1065,6 +1065,7 @@ static const struct inode_operations vfat_dir_inode_operations = { static void setup(struct super_block *sb) { + MSDOS_SB(sb)->dir_ops = &vfat_dir_inode_operations; if (MSDOS_SB(sb)->options.name_check != 's') sb->s_d_op = &vfat_ci_dentry_ops; else @@ -1073,8 +1074,7 @@ static void setup(struct super_block *sb) static int vfat_fill_super(struct super_block *sb, void *data, int silent) { - return fat_fill_super(sb, data, silent, &vfat_dir_inode_operations, - 1, setup); + return fat_fill_super(sb, data, silent, 1, setup); } static struct dentry *vfat_mount(struct file_system_type *fs_type, From 700309295551ef9217e4ae00a5b1d3030fc5438c Mon Sep 17 00:00:00 2001 From: OGAWA Hirofumi Date: Tue, 12 Apr 2011 21:08:38 +0900 Subject: [PATCH 2/6] fat: Fix possible null deref in fat_cache_add() Reported-by: Signed-off-by: OGAWA Hirofumi --- fs/fat/cache.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/fat/cache.c b/fs/fat/cache.c index ae8200f84e39..1cc7038e273d 100644 --- a/fs/fat/cache.c +++ b/fs/fat/cache.c @@ -151,6 +151,13 @@ static void fat_cache_add(struct inode *inode, struct fat_cache_id *new) spin_unlock(&MSDOS_I(inode)->cache_lru_lock); tmp = fat_cache_alloc(inode); + if (!tmp) { + spin_lock(&MSDOS_I(inode)->cache_lru_lock); + MSDOS_I(inode)->nr_caches--; + spin_unlock(&MSDOS_I(inode)->cache_lru_lock); + return; + } + spin_lock(&MSDOS_I(inode)->cache_lru_lock); cache = fat_cache_merge(inode, new); if (cache != NULL) { From 2c8a5ffb94bbb4f04aaf8a923e9098fb7a51a75a Mon Sep 17 00:00:00 2001 From: Alexey Fisher Date: Tue, 12 Apr 2011 21:08:38 +0900 Subject: [PATCH 3/6] fat: Convert fat_fs_error to use %pV - convert fat_fs_error to use %pV - be consequent and use "supor_block *sb" instead of "supor_block *s" - use devise name in each message. Signed-off-by: Alexey Fisher Signed-off-by: OGAWA Hirofumi --- fs/fat/fat.h | 10 +++++----- fs/fat/misc.c | 22 +++++++++++----------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/fs/fat/fat.h b/fs/fat/fat.h index dc163b8d7699..a768dad77907 100644 --- a/fs/fat/fat.h +++ b/fs/fat/fat.h @@ -325,12 +325,12 @@ extern int fat_flush_inodes(struct super_block *sb, struct inode *i1, struct inode *i2); /* fat/misc.c */ extern void -__fat_fs_error(struct super_block *s, int report, const char *fmt, ...) +__fat_fs_error(struct super_block *sb, int report, const char *fmt, ...) __attribute__ ((format (printf, 3, 4))) __cold; -#define fat_fs_error(s, fmt, args...) \ - __fat_fs_error(s, 1, fmt , ## args) -#define fat_fs_error_ratelimit(s, fmt, args...) \ - __fat_fs_error(s, __ratelimit(&MSDOS_SB(s)->ratelimit), fmt , ## args) +#define fat_fs_error(sb, fmt, args...) \ + __fat_fs_error(sb, 1, fmt , ## args) +#define fat_fs_error_ratelimit(sb, fmt, args...) \ + __fat_fs_error(sb, __ratelimit(&MSDOS_SB(sb)->ratelimit), fmt , ## args) extern int fat_clusters_flush(struct super_block *sb); extern int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster); extern void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec *ts, diff --git a/fs/fat/misc.c b/fs/fat/misc.c index 970e682ea754..e4f09629424e 100644 --- a/fs/fat/misc.c +++ b/fs/fat/misc.c @@ -20,26 +20,26 @@ * In case the file system is remounted read-only, it can be made writable * again by remounting it. */ -void __fat_fs_error(struct super_block *s, int report, const char *fmt, ...) +void __fat_fs_error(struct super_block *sb, int report, const char *fmt, ...) { - struct fat_mount_options *opts = &MSDOS_SB(s)->options; + struct fat_mount_options *opts = &MSDOS_SB(sb)->options; va_list args; + struct va_format vaf; if (report) { - printk(KERN_ERR "FAT: Filesystem error (dev %s)\n", s->s_id); - - printk(KERN_ERR " "); va_start(args, fmt); - vprintk(fmt, args); + vaf.fmt = fmt; + vaf.va = &args; + printk(KERN_ERR "FAT-fs (%s): error, %pV\n", sb->s_id, &vaf); va_end(args); - printk("\n"); } if (opts->errors == FAT_ERRORS_PANIC) - panic("FAT: fs panic from previous error\n"); - else if (opts->errors == FAT_ERRORS_RO && !(s->s_flags & MS_RDONLY)) { - s->s_flags |= MS_RDONLY; - printk(KERN_ERR "FAT: Filesystem has been set read-only\n"); + panic("FAT-fs (%s): fs panic from previous error\n", sb->s_id); + else if (opts->errors == FAT_ERRORS_RO && !(sb->s_flags & MS_RDONLY)) { + sb->s_flags |= MS_RDONLY; + printk(KERN_ERR "FAT-fs (%s): Filesystem has been " + "set read-only\n", sb->s_id); } } EXPORT_SYMBOL_GPL(__fat_fs_error); From 81ac21d34a91e85b029cd86e2ed5eeae8d7c3cd4 Mon Sep 17 00:00:00 2001 From: Alexey Fisher Date: Tue, 12 Apr 2011 21:08:38 +0900 Subject: [PATCH 4/6] fat: Add fat_msg() function for preformated FAT messages Add fat_msg() to replace not cosequent used printk() in fs/fat/* New message format should be as fallow: FAT-fs (sda1): some thing happened. Signed-off-by: Alexey Fisher Signed-off-by: OGAWA Hirofumi --- fs/fat/fat.h | 2 ++ fs/fat/misc.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/fs/fat/fat.h b/fs/fat/fat.h index a768dad77907..8276cc282dec 100644 --- a/fs/fat/fat.h +++ b/fs/fat/fat.h @@ -331,6 +331,8 @@ __fat_fs_error(struct super_block *sb, int report, const char *fmt, ...) __fat_fs_error(sb, 1, fmt , ## args) #define fat_fs_error_ratelimit(sb, fmt, args...) \ __fat_fs_error(sb, __ratelimit(&MSDOS_SB(sb)->ratelimit), fmt , ## args) +void fat_msg(struct super_block *sb, const char *level, const char *fmt, ...) + __attribute__ ((format (printf, 3, 4))) __cold; extern int fat_clusters_flush(struct super_block *sb); extern int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster); extern void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec *ts, diff --git a/fs/fat/misc.c b/fs/fat/misc.c index e4f09629424e..3dcabc1bd8c3 100644 --- a/fs/fat/misc.c +++ b/fs/fat/misc.c @@ -44,6 +44,22 @@ void __fat_fs_error(struct super_block *sb, int report, const char *fmt, ...) } EXPORT_SYMBOL_GPL(__fat_fs_error); +/** + * fat_msg() - print preformated FAT specific messages. Every thing what is + * not fat_fs_error() should be fat_msg(). + */ +void fat_msg(struct super_block *sb, const char *level, const char *fmt, ...) +{ + struct va_format vaf; + va_list args; + + va_start(args, fmt); + vaf.fmt = fmt; + vaf.va = &args; + printk("%sFAT-fs (%s): %pV\n", level, sb->s_id, &vaf); + va_end(args); +} + /* Flushes the number of free clusters on FAT32 */ /* XXX: Need to write one per FSINFO block. Currently only writes 1 */ int fat_clusters_flush(struct super_block *sb) From 869f58c0cdba3ae6880ab6113617e62672198773 Mon Sep 17 00:00:00 2001 From: Alexey Fisher Date: Tue, 12 Apr 2011 21:08:38 +0900 Subject: [PATCH 5/6] fat: Replace all printk with fat_msg() Replace all printk with fat_msg() Signed-off-by: Alexey Fisher Signed-off-by: OGAWA Hirofumi --- fs/fat/dir.c | 32 ++++++++++++----------- fs/fat/fatent.c | 4 +-- fs/fat/inode.c | 67 ++++++++++++++++++++++++------------------------- fs/fat/misc.c | 6 ++--- 4 files changed, 55 insertions(+), 54 deletions(-) diff --git a/fs/fat/dir.c b/fs/fat/dir.c index ee42b9e0b16a..4ad64732cbce 100644 --- a/fs/fat/dir.c +++ b/fs/fat/dir.c @@ -98,7 +98,7 @@ next: *bh = sb_bread(sb, phys); if (*bh == NULL) { - printk(KERN_ERR "FAT: Directory bread(block %llu) failed\n", + fat_msg(sb, KERN_ERR, "Directory bread(block %llu) failed", (llu)phys); /* skip this block */ *pos = (iblock + 1) << sb->s_blocksize_bits; @@ -136,9 +136,10 @@ static inline int fat_get_entry(struct inode *dir, loff_t *pos, * but ignore that right now. * Ahem... Stack smashing in ring 0 isn't fun. Fixed. */ -static int uni16_to_x8(unsigned char *ascii, const wchar_t *uni, int len, - int uni_xlate, struct nls_table *nls) +static int uni16_to_x8(struct super_block *sb, unsigned char *ascii, + const wchar_t *uni, int len, struct nls_table *nls) { + int uni_xlate = MSDOS_SB(sb)->options.unicode_xlate; const wchar_t *ip; wchar_t ec; unsigned char *op; @@ -166,23 +167,23 @@ static int uni16_to_x8(unsigned char *ascii, const wchar_t *uni, int len, } if (unlikely(*ip)) { - printk(KERN_WARNING "FAT: filename was truncated while " - "converting."); + fat_msg(sb, KERN_WARNING, "filename was truncated while " + "converting."); } *op = 0; return (op - ascii); } -static inline int fat_uni_to_x8(struct msdos_sb_info *sbi, const wchar_t *uni, +static inline int fat_uni_to_x8(struct super_block *sb, const wchar_t *uni, unsigned char *buf, int size) { + struct msdos_sb_info *sbi = MSDOS_SB(sb); if (sbi->options.utf8) return utf16s_to_utf8s(uni, FAT_MAX_UNI_CHARS, UTF16_HOST_ENDIAN, buf, size); else - return uni16_to_x8(buf, uni, size, sbi->options.unicode_xlate, - sbi->nls_io); + return uni16_to_x8(sb, buf, uni, size, sbi->nls_io); } static inline int @@ -419,7 +420,7 @@ parse_record: /* Compare shortname */ bufuname[last_u] = 0x0000; - len = fat_uni_to_x8(sbi, bufuname, bufname, sizeof(bufname)); + len = fat_uni_to_x8(sb, bufuname, bufname, sizeof(bufname)); if (fat_name_match(sbi, name, name_len, bufname, len)) goto found; @@ -428,7 +429,7 @@ parse_record: int size = PATH_MAX - FAT_MAX_UNI_SIZE; /* Compare longname */ - len = fat_uni_to_x8(sbi, unicode, longname, size); + len = fat_uni_to_x8(sb, unicode, longname, size); if (fat_name_match(sbi, name, name_len, longname, len)) goto found; } @@ -545,7 +546,7 @@ parse_record: if (nr_slots) { void *longname = unicode + FAT_MAX_UNI_CHARS; int size = PATH_MAX - FAT_MAX_UNI_SIZE; - int len = fat_uni_to_x8(sbi, unicode, longname, size); + int len = fat_uni_to_x8(sb, unicode, longname, size); fill_name = longname; fill_len = len; @@ -621,7 +622,7 @@ parse_record: if (isvfat) { bufuname[j] = 0x0000; - i = fat_uni_to_x8(sbi, bufuname, bufname, sizeof(bufname)); + i = fat_uni_to_x8(sb, bufuname, bufname, sizeof(bufname)); } if (nr_slots) { /* hack for fat_ioctl_filldir() */ @@ -979,6 +980,7 @@ static int __fat_remove_entries(struct inode *dir, loff_t pos, int nr_slots) int fat_remove_entries(struct inode *dir, struct fat_slot_info *sinfo) { + struct super_block *sb = dir->i_sb; struct msdos_dir_entry *de; struct buffer_head *bh; int err = 0, nr_slots; @@ -1013,8 +1015,8 @@ int fat_remove_entries(struct inode *dir, struct fat_slot_info *sinfo) */ err = __fat_remove_entries(dir, sinfo->slot_off, nr_slots); if (err) { - printk(KERN_WARNING - "FAT: Couldn't remove the long name slots\n"); + fat_msg(sb, KERN_WARNING, + "Couldn't remove the long name slots"); } } @@ -1265,7 +1267,7 @@ int fat_add_entries(struct inode *dir, void *slots, int nr_slots, if (sbi->fat_bits != 32) goto error; } else if (MSDOS_I(dir)->i_start == 0) { - printk(KERN_ERR "FAT: Corrupted directory (i_pos %lld)\n", + fat_msg(sb, KERN_ERR, "Corrupted directory (i_pos %lld)", MSDOS_I(dir)->i_pos); err = -EIO; goto error; diff --git a/fs/fat/fatent.c b/fs/fat/fatent.c index b47d2c9f4fa1..2e81ac0df7e2 100644 --- a/fs/fat/fatent.c +++ b/fs/fat/fatent.c @@ -95,7 +95,7 @@ static int fat12_ent_bread(struct super_block *sb, struct fat_entry *fatent, err_brelse: brelse(bhs[0]); err: - printk(KERN_ERR "FAT: FAT read failed (blocknr %llu)\n", (llu)blocknr); + fat_msg(sb, KERN_ERR, "FAT read failed (blocknr %llu)", (llu)blocknr); return -EIO; } @@ -108,7 +108,7 @@ static int fat_ent_bread(struct super_block *sb, struct fat_entry *fatent, fatent->fat_inode = MSDOS_SB(sb)->fat_inode; fatent->bhs[0] = sb_bread(sb, blocknr); if (!fatent->bhs[0]) { - printk(KERN_ERR "FAT: FAT read failed (blocknr %llu)\n", + fat_msg(sb, KERN_ERR, "FAT read failed (blocknr %llu)", (llu)blocknr); return -EIO; } diff --git a/fs/fat/inode.c b/fs/fat/inode.c index c27704dc485e..7a6c819893f2 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c @@ -619,8 +619,8 @@ retry: bh = sb_bread(sb, i_pos >> sbi->dir_per_block_bits); if (!bh) { - printk(KERN_ERR "FAT: unable to read inode block " - "for updating (i_pos %lld)\n", i_pos); + fat_msg(sb, KERN_ERR, "unable to read inode block " + "for updating (i_pos %lld)", i_pos); return -EIO; } spin_lock(&sbi->inode_hash_lock); @@ -976,8 +976,8 @@ static const match_table_t vfat_tokens = { {Opt_err, NULL} }; -static int parse_options(char *options, int is_vfat, int silent, int *debug, - struct fat_mount_options *opts) +static int parse_options(struct super_block *sb, char *options, int is_vfat, + int silent, int *debug, struct fat_mount_options *opts) { char *p; substring_t args[MAX_OPT_ARGS]; @@ -1168,15 +1168,15 @@ static int parse_options(char *options, int is_vfat, int silent, int *debug, /* obsolete mount options */ case Opt_obsolate: - printk(KERN_INFO "FAT: \"%s\" option is obsolete, " - "not supported now\n", p); + fat_msg(sb, KERN_INFO, "\"%s\" option is obsolete, " + "not supported now", p); break; /* unknown option */ default: if (!silent) { - printk(KERN_ERR - "FAT: Unrecognized mount option \"%s\" " - "or missing value\n", p); + fat_msg(sb, KERN_ERR, + "Unrecognized mount option \"%s\" " + "or missing value", p); } return -EINVAL; } @@ -1185,7 +1185,7 @@ static int parse_options(char *options, int is_vfat, int silent, int *debug, out: /* UTF-8 doesn't provide FAT semantics */ if (!strcmp(opts->iocharset, "utf8")) { - printk(KERN_ERR "FAT: utf8 is not a recommended IO charset" + fat_msg(sb, KERN_ERR, "utf8 is not a recommended IO charset" " for FAT filesystems, filesystem will be " "case sensitive!\n"); } @@ -1270,7 +1270,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, ratelimit_state_init(&sbi->ratelimit, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST); - error = parse_options(data, isvfat, silent, &debug, &sbi->options); + error = parse_options(sb, data, isvfat, silent, &debug, &sbi->options); if (error) goto out_fail; @@ -1280,20 +1280,20 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, sb_min_blocksize(sb, 512); bh = sb_bread(sb, 0); if (bh == NULL) { - printk(KERN_ERR "FAT: unable to read boot sector\n"); + fat_msg(sb, KERN_ERR, "unable to read boot sector"); goto out_fail; } b = (struct fat_boot_sector *) bh->b_data; if (!b->reserved) { if (!silent) - printk(KERN_ERR "FAT: bogus number of reserved sectors\n"); + fat_msg(sb, KERN_ERR, "bogus number of reserved sectors"); brelse(bh); goto out_invalid; } if (!b->fats) { if (!silent) - printk(KERN_ERR "FAT: bogus number of FAT structure\n"); + fat_msg(sb, KERN_ERR, "bogus number of FAT structure"); brelse(bh); goto out_invalid; } @@ -1306,7 +1306,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, media = b->media; if (!fat_valid_media(media)) { if (!silent) - printk(KERN_ERR "FAT: invalid media value (0x%02x)\n", + fat_msg(sb, KERN_ERR, "invalid media value (0x%02x)", media); brelse(bh); goto out_invalid; @@ -1316,7 +1316,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, || (logical_sector_size < 512) || (logical_sector_size > 4096)) { if (!silent) - printk(KERN_ERR "FAT: bogus logical sector size %u\n", + fat_msg(sb, KERN_ERR, "bogus logical sector size %u", logical_sector_size); brelse(bh); goto out_invalid; @@ -1324,15 +1324,15 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, sbi->sec_per_clus = b->sec_per_clus; if (!is_power_of_2(sbi->sec_per_clus)) { if (!silent) - printk(KERN_ERR "FAT: bogus sectors per cluster %u\n", + fat_msg(sb, KERN_ERR, "bogus sectors per cluster %u", sbi->sec_per_clus); brelse(bh); goto out_invalid; } if (logical_sector_size < sb->s_blocksize) { - printk(KERN_ERR "FAT: logical sector size too small for device" - " (logical sector size = %u)\n", logical_sector_size); + fat_msg(sb, KERN_ERR, "logical sector size too small for device" + " (logical sector size = %u)", logical_sector_size); brelse(bh); goto out_fail; } @@ -1340,14 +1340,14 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, brelse(bh); if (!sb_set_blocksize(sb, logical_sector_size)) { - printk(KERN_ERR "FAT: unable to set blocksize %u\n", + fat_msg(sb, KERN_ERR, "unable to set blocksize %u", logical_sector_size); goto out_fail; } bh = sb_bread(sb, 0); if (bh == NULL) { - printk(KERN_ERR "FAT: unable to read boot sector" - " (logical sector size = %lu)\n", + fat_msg(sb, KERN_ERR, "unable to read boot sector" + " (logical sector size = %lu)", sb->s_blocksize); goto out_fail; } @@ -1383,16 +1383,16 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, fsinfo_bh = sb_bread(sb, sbi->fsinfo_sector); if (fsinfo_bh == NULL) { - printk(KERN_ERR "FAT: bread failed, FSINFO block" - " (sector = %lu)\n", sbi->fsinfo_sector); + fat_msg(sb, KERN_ERR, "bread failed, FSINFO block" + " (sector = %lu)", sbi->fsinfo_sector); brelse(bh); goto out_fail; } fsinfo = (struct fat_boot_fsinfo *)fsinfo_bh->b_data; if (!IS_FSINFO(fsinfo)) { - printk(KERN_WARNING "FAT: Invalid FSINFO signature: " - "0x%08x, 0x%08x (sector = %lu)\n", + fat_msg(sb, KERN_WARNING, "Invalid FSINFO signature: " + "0x%08x, 0x%08x (sector = %lu)", le32_to_cpu(fsinfo->signature1), le32_to_cpu(fsinfo->signature2), sbi->fsinfo_sector); @@ -1413,8 +1413,8 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, sbi->dir_entries = get_unaligned_le16(&b->dir_entries); if (sbi->dir_entries & (sbi->dir_per_block - 1)) { if (!silent) - printk(KERN_ERR "FAT: bogus directroy-entries per block" - " (%u)\n", sbi->dir_entries); + fat_msg(sb, KERN_ERR, "bogus directroy-entries per block" + " (%u)", sbi->dir_entries); brelse(bh); goto out_invalid; } @@ -1436,7 +1436,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, 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", + fat_msg(sb, KERN_ERR, "count of clusters too big (%u)", total_clusters); brelse(bh); goto out_invalid; @@ -1469,7 +1469,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, sprintf(buf, "cp%d", sbi->options.codepage); sbi->nls_disk = load_nls(buf); if (!sbi->nls_disk) { - printk(KERN_ERR "FAT: codepage %s not found\n", buf); + fat_msg(sb, KERN_ERR, "codepage %s not found", buf); goto out_fail; } @@ -1477,7 +1477,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, if (sbi->options.isvfat) { sbi->nls_io = load_nls(sbi->options.iocharset); if (!sbi->nls_io) { - printk(KERN_ERR "FAT: IO charset %s not found\n", + fat_msg(sb, KERN_ERR, "IO charset %s not found", sbi->options.iocharset); goto out_fail; } @@ -1501,7 +1501,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, insert_inode_hash(root_inode); sb->s_root = d_alloc_root(root_inode); if (!sb->s_root) { - printk(KERN_ERR "FAT: get root inode failed\n"); + fat_msg(sb, KERN_ERR, "get root inode failed"); goto out_fail; } @@ -1510,8 +1510,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, out_invalid: error = -EINVAL; if (!silent) - printk(KERN_INFO "VFS: Can't find a valid FAT filesystem" - " on dev %s.\n", sb->s_id); + fat_msg(sb, KERN_INFO, "Can't find a valid FAT filesystem"); out_fail: if (fat_inode) diff --git a/fs/fat/misc.c b/fs/fat/misc.c index 3dcabc1bd8c3..6d93360ca0cc 100644 --- a/fs/fat/misc.c +++ b/fs/fat/misc.c @@ -73,15 +73,15 @@ int fat_clusters_flush(struct super_block *sb) bh = sb_bread(sb, sbi->fsinfo_sector); if (bh == NULL) { - printk(KERN_ERR "FAT: bread failed in fat_clusters_flush\n"); + fat_msg(sb, KERN_ERR, "bread failed in fat_clusters_flush"); return -EIO; } fsinfo = (struct fat_boot_fsinfo *)bh->b_data; /* Sanity check */ if (!IS_FSINFO(fsinfo)) { - printk(KERN_ERR "FAT: Invalid FSINFO signature: " - "0x%08x, 0x%08x (sector = %lu)\n", + fat_msg(sb, KERN_ERR, "Invalid FSINFO signature: " + "0x%08x, 0x%08x (sector = %lu)", le32_to_cpu(fsinfo->signature1), le32_to_cpu(fsinfo->signature2), sbi->fsinfo_sector); From f68e542f3478147986a9c8958942ec649dc06201 Mon Sep 17 00:00:00 2001 From: OGAWA Hirofumi Date: Tue, 12 Apr 2011 21:08:39 +0900 Subject: [PATCH 6/6] fat: Fix statfs->f_namelen pathconf(, _PC_NAME_MAX) is too small for long Unicode filename on fat. 255 as max filename size on fat is Unicode UTF-16 characters. it's not byte size. https://bugzilla.kernel.org/show_bug.cgi?id=16469 To fix it, this returns "len * NLS_MAX_CHARSET_SIZE" instead. Reported-by: Takumi Asaki Signed-off-by: OGAWA Hirofumi --- fs/fat/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/fat/inode.c b/fs/fat/inode.c index 7a6c819893f2..cb8d8391ac0b 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c @@ -581,7 +581,8 @@ static int fat_statfs(struct dentry *dentry, struct kstatfs *buf) buf->f_bavail = sbi->free_clusters; buf->f_fsid.val[0] = (u32)id; buf->f_fsid.val[1] = (u32)(id >> 32); - buf->f_namelen = sbi->options.isvfat ? FAT_LFN_LEN : 12; + buf->f_namelen = + (sbi->options.isvfat ? FAT_LFN_LEN : 12) * NLS_MAX_CHARSET_SIZE; return 0; }