diff options
Diffstat (limited to 'fs/fat/cache.c')
-rw-r--r-- | fs/fat/cache.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/fs/fat/cache.c b/fs/fat/cache.c index e9bed49df6b7..78d501c1fb65 100644 --- a/fs/fat/cache.c +++ b/fs/fat/cache.c | |||
@@ -225,7 +225,8 @@ static inline void cache_init(struct fat_cache_id *cid, int fclus, int dclus) | |||
225 | int fat_get_cluster(struct inode *inode, int cluster, int *fclus, int *dclus) | 225 | int fat_get_cluster(struct inode *inode, int cluster, int *fclus, int *dclus) |
226 | { | 226 | { |
227 | struct super_block *sb = inode->i_sb; | 227 | struct super_block *sb = inode->i_sb; |
228 | const int limit = sb->s_maxbytes >> MSDOS_SB(sb)->cluster_bits; | 228 | struct msdos_sb_info *sbi = MSDOS_SB(sb); |
229 | const int limit = sb->s_maxbytes >> sbi->cluster_bits; | ||
229 | struct fat_entry fatent; | 230 | struct fat_entry fatent; |
230 | struct fat_cache_id cid; | 231 | struct fat_cache_id cid; |
231 | int nr; | 232 | int nr; |
@@ -234,6 +235,12 @@ int fat_get_cluster(struct inode *inode, int cluster, int *fclus, int *dclus) | |||
234 | 235 | ||
235 | *fclus = 0; | 236 | *fclus = 0; |
236 | *dclus = MSDOS_I(inode)->i_start; | 237 | *dclus = MSDOS_I(inode)->i_start; |
238 | if (!fat_valid_entry(sbi, *dclus)) { | ||
239 | fat_fs_error_ratelimit(sb, | ||
240 | "%s: invalid start cluster (i_pos %lld, start %08x)", | ||
241 | __func__, MSDOS_I(inode)->i_pos, *dclus); | ||
242 | return -EIO; | ||
243 | } | ||
237 | if (cluster == 0) | 244 | if (cluster == 0) |
238 | return 0; | 245 | return 0; |
239 | 246 | ||
@@ -250,9 +257,8 @@ int fat_get_cluster(struct inode *inode, int cluster, int *fclus, int *dclus) | |||
250 | /* prevent the infinite loop of cluster chain */ | 257 | /* prevent the infinite loop of cluster chain */ |
251 | if (*fclus > limit) { | 258 | if (*fclus > limit) { |
252 | fat_fs_error_ratelimit(sb, | 259 | fat_fs_error_ratelimit(sb, |
253 | "%s: detected the cluster chain loop" | 260 | "%s: detected the cluster chain loop (i_pos %lld)", |
254 | " (i_pos %lld)", __func__, | 261 | __func__, MSDOS_I(inode)->i_pos); |
255 | MSDOS_I(inode)->i_pos); | ||
256 | nr = -EIO; | 262 | nr = -EIO; |
257 | goto out; | 263 | goto out; |
258 | } | 264 | } |
@@ -262,9 +268,8 @@ int fat_get_cluster(struct inode *inode, int cluster, int *fclus, int *dclus) | |||
262 | goto out; | 268 | goto out; |
263 | else if (nr == FAT_ENT_FREE) { | 269 | else if (nr == FAT_ENT_FREE) { |
264 | fat_fs_error_ratelimit(sb, | 270 | fat_fs_error_ratelimit(sb, |
265 | "%s: invalid cluster chain (i_pos %lld)", | 271 | "%s: invalid cluster chain (i_pos %lld)", |
266 | __func__, | 272 | __func__, MSDOS_I(inode)->i_pos); |
267 | MSDOS_I(inode)->i_pos); | ||
268 | nr = -EIO; | 273 | nr = -EIO; |
269 | goto out; | 274 | goto out; |
270 | } else if (nr == FAT_ENT_EOF) { | 275 | } else if (nr == FAT_ENT_EOF) { |