Commit 749f6629 authored by Hirofumi Ogawa's avatar Hirofumi Ogawa Committed by Linus Torvalds

[PATCH] fat_cluster_flush() fixes (2/11)

This adds a forgotten check of MS_RDONLY flag to fat_put_super(), and
adds sanity check of ->free_clusters and ->prev_free to fat_cluster_flush().
parent ed676760
...@@ -159,7 +159,9 @@ void fat_put_super(struct super_block *sb) ...@@ -159,7 +159,9 @@ void fat_put_super(struct super_block *sb)
{ {
struct msdos_sb_info *sbi = MSDOS_SB(sb); struct msdos_sb_info *sbi = MSDOS_SB(sb);
if (!(sb->s_flags & MS_RDONLY))
fat_clusters_flush(sb); fat_clusters_flush(sb);
if (sbi->nls_disk) { if (sbi->nls_disk) {
unload_nls(sbi->nls_disk); unload_nls(sbi->nls_disk);
sbi->nls_disk = NULL; sbi->nls_disk = NULL;
......
...@@ -50,15 +50,14 @@ void unlock_fat(struct super_block *sb) ...@@ -50,15 +50,14 @@ void unlock_fat(struct super_block *sb)
/* XXX: Need to write one per FSINFO block. Currently only writes 1 */ /* XXX: Need to write one per FSINFO block. Currently only writes 1 */
void fat_clusters_flush(struct super_block *sb) void fat_clusters_flush(struct super_block *sb)
{ {
struct msdos_sb_info *sbi = MSDOS_SB(sb);
struct buffer_head *bh; struct buffer_head *bh;
struct fat_boot_fsinfo *fsinfo; struct fat_boot_fsinfo *fsinfo;
if (MSDOS_SB(sb)->fat_bits != 32) if (sbi->fat_bits != 32)
return;
if (MSDOS_SB(sb)->free_clusters == -1)
return; return;
bh = sb_bread(sb, MSDOS_SB(sb)->fsinfo_sector); bh = sb_bread(sb, sbi->fsinfo_sector);
if (bh == NULL) { if (bh == NULL) {
printk(KERN_ERR "FAT bread failed in fat_clusters_flush\n"); printk(KERN_ERR "FAT bread failed in fat_clusters_flush\n");
return; return;
...@@ -71,10 +70,12 @@ void fat_clusters_flush(struct super_block *sb) ...@@ -71,10 +70,12 @@ void fat_clusters_flush(struct super_block *sb)
" Found signature1 0x%08x signature2 0x%08x" " Found signature1 0x%08x signature2 0x%08x"
" (sector = %lu)\n", " (sector = %lu)\n",
CF_LE_L(fsinfo->signature1), CF_LE_L(fsinfo->signature2), CF_LE_L(fsinfo->signature1), CF_LE_L(fsinfo->signature2),
MSDOS_SB(sb)->fsinfo_sector); sbi->fsinfo_sector);
} else { } else {
fsinfo->free_clusters = CF_LE_L(MSDOS_SB(sb)->free_clusters); if (sbi->free_clusters != -1)
fsinfo->next_cluster = CF_LE_L(MSDOS_SB(sb)->prev_free); fsinfo->free_clusters = CF_LE_L(sbi->free_clusters);
if (sbi->prev_free)
fsinfo->next_cluster = CF_LE_L(sbi->prev_free);
mark_buffer_dirty(bh); mark_buffer_dirty(bh);
} }
brelse(bh); brelse(bh);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment