aboutsummaryrefslogtreecommitdiffstats
path: root/fs/fat
diff options
context:
space:
mode:
authorOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>2008-04-28 05:16:27 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-04-28 11:58:47 -0400
commit606e423e43bac0c2f7b85b682eb1ddd2a634586e (patch)
tree86e7bc56e7e70cf1403aec7fd58d854490b1478f /fs/fat
parent1ae43f826b6cb951fc5b0f9c92372a8d5b63c7f9 (diff)
fat: Update free_clusters even if it is untrusted
Currently, free_clusters is not updated until it is trusted, because Windows doesn't update it correctly. But if user is using FAT driver of Linux, it updates free_clusters correctly. Instead, this updates it even if it's untrusted, so if free_clustes is correct, now keep correct value. Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/fat')
-rw-r--r--fs/fat/fatent.c7
-rw-r--r--fs/fat/inode.c7
2 files changed, 9 insertions, 5 deletions
diff --git a/fs/fat/fatent.c b/fs/fat/fatent.c
index 5fb366992b73..c7c8ab2209e1 100644
--- a/fs/fat/fatent.c
+++ b/fs/fat/fatent.c
@@ -450,7 +450,8 @@ int fat_alloc_clusters(struct inode *inode, int *cluster, int nr_cluster)
450 BUG_ON(nr_cluster > (MAX_BUF_PER_PAGE / 2)); /* fixed limit */ 450 BUG_ON(nr_cluster > (MAX_BUF_PER_PAGE / 2)); /* fixed limit */
451 451
452 lock_fat(sbi); 452 lock_fat(sbi);
453 if (sbi->free_clusters != -1 && sbi->free_clusters < nr_cluster) { 453 if (sbi->free_clusters != -1 && sbi->free_clus_valid &&
454 sbi->free_clusters < nr_cluster) {
454 unlock_fat(sbi); 455 unlock_fat(sbi);
455 return -ENOSPC; 456 return -ENOSPC;
456 } 457 }
@@ -504,6 +505,7 @@ int fat_alloc_clusters(struct inode *inode, int *cluster, int nr_cluster)
504 505
505 /* Couldn't allocate the free entries */ 506 /* Couldn't allocate the free entries */
506 sbi->free_clusters = 0; 507 sbi->free_clusters = 0;
508 sbi->free_clus_valid = 1;
507 sb->s_dirt = 1; 509 sb->s_dirt = 1;
508 err = -ENOSPC; 510 err = -ENOSPC;
509 511
@@ -615,7 +617,7 @@ int fat_count_free_clusters(struct super_block *sb)
615 int err = 0, free; 617 int err = 0, free;
616 618
617 lock_fat(sbi); 619 lock_fat(sbi);
618 if (sbi->free_clusters != -1) 620 if (sbi->free_clusters != -1 && sbi->free_clus_valid)
619 goto out; 621 goto out;
620 622
621 reada_blocks = FAT_READA_SIZE >> sb->s_blocksize_bits; 623 reada_blocks = FAT_READA_SIZE >> sb->s_blocksize_bits;
@@ -643,6 +645,7 @@ int fat_count_free_clusters(struct super_block *sb)
643 } while (fat_ent_next(sbi, &fatent)); 645 } while (fat_ent_next(sbi, &fatent));
644 } 646 }
645 sbi->free_clusters = free; 647 sbi->free_clusters = free;
648 sbi->free_clus_valid = 1;
646 sb->s_dirt = 1; 649 sb->s_dirt = 1;
647 fatent_brelse(&fatent); 650 fatent_brelse(&fatent);
648out: 651out:
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index 886f6095a378..1604a8a5c01f 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -537,7 +537,7 @@ static int fat_statfs(struct dentry *dentry, struct kstatfs *buf)
537 struct msdos_sb_info *sbi = MSDOS_SB(dentry->d_sb); 537 struct msdos_sb_info *sbi = MSDOS_SB(dentry->d_sb);
538 538
539 /* If the count of free cluster is still unknown, counts it here. */ 539 /* If the count of free cluster is still unknown, counts it here. */
540 if (sbi->free_clusters == -1) { 540 if (sbi->free_clusters == -1 || !sbi->free_clus_valid) {
541 int err = fat_count_free_clusters(dentry->d_sb); 541 int err = fat_count_free_clusters(dentry->d_sb);
542 if (err) 542 if (err)
543 return err; 543 return err;
@@ -1274,6 +1274,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
1274 sbi->fat_length = le16_to_cpu(b->fat_length); 1274 sbi->fat_length = le16_to_cpu(b->fat_length);
1275 sbi->root_cluster = 0; 1275 sbi->root_cluster = 0;
1276 sbi->free_clusters = -1; /* Don't know yet */ 1276 sbi->free_clusters = -1; /* Don't know yet */
1277 sbi->free_clus_valid = 0;
1277 sbi->prev_free = FAT_START_ENT; 1278 sbi->prev_free = FAT_START_ENT;
1278 1279
1279 if (!sbi->fat_length && b->fat32_length) { 1280 if (!sbi->fat_length && b->fat32_length) {
@@ -1309,8 +1310,8 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
1309 sbi->fsinfo_sector); 1310 sbi->fsinfo_sector);
1310 } else { 1311 } else {
1311 if (sbi->options.usefree) 1312 if (sbi->options.usefree)
1312 sbi->free_clusters = 1313 sbi->free_clus_valid = 1;
1313 le32_to_cpu(fsinfo->free_clusters); 1314 sbi->free_clusters = le32_to_cpu(fsinfo->free_clusters);
1314 sbi->prev_free = le32_to_cpu(fsinfo->next_cluster); 1315 sbi->prev_free = le32_to_cpu(fsinfo->next_cluster);
1315 } 1316 }
1316 1317