Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fat: new inline functions to determine the FAT variant (32, 16 or 12)

This patch introduces 3 new inline functions - is_fat12, is_fat16 and
is_fat32, and replaces every occurrence in the code in which the FS
variant (whether this is FAT12, FAT16 or FAT32) was previously checked
using msdos_sb_info->fat_bits.

Link: http://lkml.kernel.org/r/1544990640-11604-4-git-send-email-carmeli.tamir@gmail.com
Signed-off-by: Carmeli Tamir <carmeli.tamir@gmail.com>
Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Carmeli Tamir and committed by
Linus Torvalds
306790f7 d19dc016

+39 -22
+1 -1
fs/fat/cache.c
··· 363 363 364 364 *phys = 0; 365 365 *mapped_blocks = 0; 366 - if ((sbi->fat_bits != 32) && (inode->i_ino == MSDOS_ROOT_INO)) { 366 + if (!is_fat32(sbi) && (inode->i_ino == MSDOS_ROOT_INO)) { 367 367 if (sector < (sbi->dir_entries >> sbi->dir_per_block_bits)) { 368 368 *phys = sector + sbi->dir_start; 369 369 *mapped_blocks = 1;
+2 -2
fs/fat/dir.c
··· 57 57 if ((iblock & (sbi->sec_per_clus - 1)) || sbi->sec_per_clus == 1) 58 58 return; 59 59 /* root dir of FAT12/FAT16 */ 60 - if ((sbi->fat_bits != 32) && (dir->i_ino == MSDOS_ROOT_INO)) 60 + if (!is_fat32(sbi) && (dir->i_ino == MSDOS_ROOT_INO)) 61 61 return; 62 62 63 63 bh = sb_find_get_block(sb, phys); ··· 1313 1313 } 1314 1314 } 1315 1315 if (dir->i_ino == MSDOS_ROOT_INO) { 1316 - if (sbi->fat_bits != 32) 1316 + if (!is_fat32(sbi)) 1317 1317 goto error; 1318 1318 } else if (MSDOS_I(dir)->i_start == 0) { 1319 1319 fat_msg(sb, KERN_ERR, "Corrupted directory (i_pos %lld)",
+22 -3
fs/fat/fat.h
··· 142 142 return sb->s_fs_info; 143 143 } 144 144 145 + /* 146 + * Functions that determine the variant of the FAT file system (i.e., 147 + * whether this is FAT12, FAT16 or FAT32. 148 + */ 149 + static inline bool is_fat12(const struct msdos_sb_info *sbi) 150 + { 151 + return sbi->fat_bits == 12; 152 + } 153 + 154 + static inline bool is_fat16(const struct msdos_sb_info *sbi) 155 + { 156 + return sbi->fat_bits == 16; 157 + } 158 + 159 + static inline bool is_fat32(const struct msdos_sb_info *sbi) 160 + { 161 + return sbi->fat_bits == 32; 162 + } 163 + 145 164 /* Maximum number of clusters */ 146 165 static inline u32 max_fat(struct super_block *sb) 147 166 { 148 167 struct msdos_sb_info *sbi = MSDOS_SB(sb); 149 168 150 - return sbi->fat_bits == 32 ? MAX_FAT32 : 151 - sbi->fat_bits == 16 ? MAX_FAT16 : MAX_FAT12; 169 + return is_fat32(sbi) ? MAX_FAT32 : 170 + is_fat16(sbi) ? MAX_FAT16 : MAX_FAT12; 152 171 } 153 172 154 173 static inline struct msdos_inode_info *MSDOS_I(struct inode *inode) ··· 285 266 const struct msdos_dir_entry *de) 286 267 { 287 268 int cluster = le16_to_cpu(de->start); 288 - if (sbi->fat_bits == 32) 269 + if (is_fat32(sbi)) 289 270 cluster |= (le16_to_cpu(de->starthi) << 16); 290 271 return cluster; 291 272 }
+7 -9
fs/fat/fatent.c
··· 290 290 291 291 mutex_init(&sbi->fat_lock); 292 292 293 - switch (sbi->fat_bits) { 294 - case 32: 293 + if (is_fat32(sbi)) { 295 294 sbi->fatent_shift = 2; 296 295 sbi->fatent_ops = &fat32_ops; 297 - break; 298 - case 16: 296 + } else if (is_fat16(sbi)) { 299 297 sbi->fatent_shift = 1; 300 298 sbi->fatent_ops = &fat16_ops; 301 - break; 302 - case 12: 299 + } else if (is_fat12(sbi)) { 303 300 sbi->fatent_shift = -1; 304 301 sbi->fatent_ops = &fat12_ops; 305 - break; 302 + } else { 303 + fat_fs_error(sb, "invalid FAT variant, %u bits", sbi->fat_bits); 306 304 } 307 305 } 308 306 ··· 308 310 { 309 311 struct msdos_sb_info *sbi = MSDOS_SB(sb); 310 312 311 - if (sb_rdonly(sb) || sbi->fat_bits != 32) 313 + if (sb_rdonly(sb) || !is_fat32(sbi)) 312 314 return; 313 315 314 316 __mark_inode_dirty(sbi->fsinfo_inode, I_DIRTY_SYNC); ··· 325 327 /* Is this fatent's blocks including this entry? */ 326 328 if (!fatent->nr_bhs || bhs[0]->b_blocknr != blocknr) 327 329 return 0; 328 - if (sbi->fat_bits == 12) { 330 + if (is_fat12(sbi)) { 329 331 if ((offset + 1) < sb->s_blocksize) { 330 332 /* This entry is on bhs[0]. */ 331 333 if (fatent->nr_bhs == 2) {
+6 -6
fs/fat/inode.c
··· 686 686 687 687 b = (struct fat_boot_sector *) bh->b_data; 688 688 689 - if (sbi->fat_bits == 32) { 689 + if (is_fat32(sbi)) { 690 690 if (set) 691 691 b->fat32.state |= FAT_STATE_DIRTY; 692 692 else ··· 1396 1396 inode->i_mode = fat_make_mode(sbi, ATTR_DIR, S_IRWXUGO); 1397 1397 inode->i_op = sbi->dir_ops; 1398 1398 inode->i_fop = &fat_dir_operations; 1399 - if (sbi->fat_bits == 32) { 1399 + if (is_fat32(sbi)) { 1400 1400 MSDOS_I(inode)->i_start = sbi->root_cluster; 1401 1401 error = fat_calc_dir_size(inode); 1402 1402 if (error < 0) ··· 1423 1423 struct msdos_sb_info *sbi = MSDOS_SB(sb); 1424 1424 1425 1425 /* Divide first to avoid overflow */ 1426 - if (sbi->fat_bits != 12) { 1426 + if (!is_fat12(sbi)) { 1427 1427 unsigned long ent_per_sec = sb->s_blocksize * 8 / sbi->fat_bits; 1428 1428 return ent_per_sec * sbi->fat_length; 1429 1429 } ··· 1743 1743 } 1744 1744 1745 1745 /* interpret volume ID as a little endian 32 bit integer */ 1746 - if (sbi->fat_bits == 32) 1746 + if (is_fat32(sbi)) 1747 1747 sbi->vol_id = bpb.fat32_vol_id; 1748 1748 else /* fat 16 or 12 */ 1749 1749 sbi->vol_id = bpb.fat16_vol_id; ··· 1769 1769 1770 1770 total_clusters = (total_sectors - sbi->data_start) / sbi->sec_per_clus; 1771 1771 1772 - if (sbi->fat_bits != 32) 1772 + if (!is_fat32(sbi)) 1773 1773 sbi->fat_bits = (total_clusters > MAX_FAT12) ? 16 : 12; 1774 1774 1775 1775 /* some OSes set FAT_STATE_DIRTY and clean it on unmount. */ 1776 - if (sbi->fat_bits == 32) 1776 + if (is_fat32(sbi)) 1777 1777 sbi->dirty = bpb.fat32_state & FAT_STATE_DIRTY; 1778 1778 else /* fat 16 or 12 */ 1779 1779 sbi->dirty = bpb.fat16_state & FAT_STATE_DIRTY;
+1 -1
fs/fat/misc.c
··· 64 64 struct buffer_head *bh; 65 65 struct fat_boot_fsinfo *fsinfo; 66 66 67 - if (sbi->fat_bits != 32) 67 + if (!is_fat32(sbi)) 68 68 return 0; 69 69 70 70 bh = sb_bread(sb, sbi->fsinfo_sector);