aboutsummaryrefslogtreecommitdiff
path: root/fs/fat/cache.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2008-12-01 18:02:17 +0100
committerTakashi Iwai <tiwai@suse.de>2008-12-01 18:02:17 +0100
commit3af4182cc5be7d5505f9801ee3297373f1872446 (patch)
tree214348d40ed547a72f9612a7e5c94a01afded812 /fs/fat/cache.c
parentf5d4c67e41a262f0cdfaec1bb0fa8e5952187ef9 (diff)
parentc07f62e5f18123103459ff74e86af1518a5b8af5 (diff)
Merge branch 'upstream' into topic/asoc
Diffstat (limited to 'fs/fat/cache.c')
-rw-r--r--fs/fat/cache.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/fs/fat/cache.c b/fs/fat/cache.c
index 3222f51c41c..b4260229808 100644
--- a/fs/fat/cache.c
+++ b/fs/fat/cache.c
@@ -9,8 +9,8 @@
*/
#include <linux/fs.h>
-#include <linux/msdos_fs.h>
#include <linux/buffer_head.h>
+#include "fat.h"
/* this must be > 0. */
#define FAT_MAX_CACHE 8
@@ -293,10 +293,12 @@ static int fat_bmap_cluster(struct inode *inode, int cluster)
}
int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys,
- unsigned long *mapped_blocks)
+ unsigned long *mapped_blocks, int create)
{
struct super_block *sb = inode->i_sb;
struct msdos_sb_info *sbi = MSDOS_SB(sb);
+ const unsigned long blocksize = sb->s_blocksize;
+ const unsigned char blocksize_bits = sb->s_blocksize_bits;
sector_t last_block;
int cluster, offset;
@@ -309,10 +311,21 @@ int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys,
}
return 0;
}
- last_block = (MSDOS_I(inode)->mmu_private + (sb->s_blocksize - 1))
- >> sb->s_blocksize_bits;
- if (sector >= last_block)
- return 0;
+
+ last_block = (i_size_read(inode) + (blocksize - 1)) >> blocksize_bits;
+ if (sector >= last_block) {
+ if (!create)
+ return 0;
+
+ /*
+ * ->mmu_private can access on only allocation path.
+ * (caller must hold ->i_mutex)
+ */
+ last_block = (MSDOS_I(inode)->mmu_private + (blocksize - 1))
+ >> blocksize_bits;
+ if (sector >= last_block)
+ return 0;
+ }
cluster = sector >> (sbi->cluster_bits - sb->s_blocksize_bits);
offset = sector & (sbi->sec_per_clus - 1);