tree: git://git.cmpxchg.org/linux-mmotm.git master head: 7393732bae530daa27567988b91d16ecfeef6c62 commit: fe3e5c4f07cde4be67152518d21429bfbb875c0c [174/212] fat: use fat_fs_error() instead of BUG_ON() in __fat_get_block() config: i386-randconfig-s0-201822-CONFIG_DEBUG_INFO_REDUCED (attached as .config) compiler: gcc-6 (Debian 6.4.0-9) 6.4.0 20171026 reproduce: git checkout fe3e5c4f07cde4be67152518d21429bfbb875c0c # save the attached .config to linux build tree make ARCH=i386 All warnings (new ones prefixed by >>): In file included from fs///fat/inode.c:24:0: fs///fat/inode.c: In function '__fat_get_block': >> fs///fat/inode.c:163:9: warning: format '%ld' expects argument of type 'long int', but argument 5 has type 'sector_t {aka long long unsigned int}' [-Wformat=] "invalid FAT chain (i_pos %lld, last_block %ld)", ^ fs///fat/fat.h:397:24: note: in definition of macro 'fat_fs_error' __fat_fs_error(sb, 1, fmt , ## args) ^~~ vim +163 fs///fat/inode.c > 24 #include "fat.h" 25 26 #ifndef CONFIG_FAT_DEFAULT_IOCHARSET 27 /* if user don't select VFAT, this is undefined. */ 28 #define CONFIG_FAT_DEFAULT_IOCHARSET "" 29 #endif 30 31 #define KB_IN_SECTORS 2 32 33 /* 34 * A deserialized copy of the on-disk structure laid out in struct 35 * fat_boot_sector. 36 */ 37 struct fat_bios_param_block { 38 u16 fat_sector_size; 39 u8 fat_sec_per_clus; 40 u16 fat_reserved; 41 u8 fat_fats; 42 u16 fat_dir_entries; 43 u16 fat_sectors; 44 u16 fat_fat_length; 45 u32 fat_total_sect; 46 47 u8 fat16_state; 48 u32 fat16_vol_id; 49 50 u32 fat32_length; 51 u32 fat32_root_cluster; 52 u16 fat32_info_sector; 53 u8 fat32_state; 54 u32 fat32_vol_id; 55 }; 56 57 static int fat_default_codepage = CONFIG_FAT_DEFAULT_CODEPAGE; 58 static char fat_default_iocharset[] = CONFIG_FAT_DEFAULT_IOCHARSET; 59 60 static struct fat_floppy_defaults { 61 unsigned nr_sectors; 62 unsigned sec_per_clus; 63 unsigned dir_entries; 64 unsigned media; 65 unsigned fat_length; 66 } floppy_defaults[] = { 67 { 68 .nr_sectors = 160 * KB_IN_SECTORS, 69 .sec_per_clus = 1, 70 .dir_entries = 64, 71 .media = 0xFE, 72 .fat_length = 1, 73 }, 74 { 75 .nr_sectors = 180 * KB_IN_SECTORS, 76 .sec_per_clus = 1, 77 .dir_entries = 64, 78 .media = 0xFC, 79 .fat_length = 2, 80 }, 81 { 82 .nr_sectors = 320 * KB_IN_SECTORS, 83 .sec_per_clus = 2, 84 .dir_entries = 112, 85 .media = 0xFF, 86 .fat_length = 1, 87 }, 88 { 89 .nr_sectors = 360 * KB_IN_SECTORS, 90 .sec_per_clus = 2, 91 .dir_entries = 112, 92 .media = 0xFD, 93 .fat_length = 2, 94 }, 95 }; 96 97 int fat_add_cluster(struct inode *inode) 98 { 99 int err, cluster; 100 101 err = fat_alloc_clusters(inode, &cluster, 1); 102 if (err) 103 return err; 104 /* FIXME: this cluster should be added after data of this 105 * cluster is writed */ 106 err = fat_chain_add(inode, cluster, 1); 107 if (err) 108 fat_free_clusters(inode, cluster); 109 return err; 110 } 111 112 static inline int __fat_get_block(struct inode *inode, sector_t iblock, 113 unsigned long *max_blocks, 114 struct buffer_head *bh_result, int create) 115 { 116 struct super_block *sb = inode->i_sb; 117 struct msdos_sb_info *sbi = MSDOS_SB(sb); 118 unsigned long mapped_blocks; 119 sector_t phys, last_block; 120 int err, offset; 121 122 err = fat_bmap(inode, iblock, &phys, &mapped_blocks, create, false); 123 if (err) 124 return err; 125 if (phys) { 126 map_bh(bh_result, sb, phys); 127 *max_blocks = min(mapped_blocks, *max_blocks); 128 return 0; 129 } 130 if (!create) 131 return 0; 132 133 if (iblock != MSDOS_I(inode)->mmu_private >> sb->s_blocksize_bits) { 134 fat_fs_error(sb, "corrupted file size (i_pos %lld, %lld)", 135 MSDOS_I(inode)->i_pos, MSDOS_I(inode)->mmu_private); 136 return -EIO; 137 } 138 139 last_block = inode->i_blocks >> (sb->s_blocksize_bits - 9); 140 offset = (unsigned long)iblock & (sbi->sec_per_clus - 1); 141 /* 142 * allocate a cluster according to the following. 143 * 1) no more available blocks 144 * 2) not part of fallocate region 145 */ 146 if (!offset && !(iblock < last_block)) { 147 /* TODO: multiple cluster allocation would be desirable. */ 148 err = fat_add_cluster(inode); 149 if (err) 150 return err; 151 } 152 /* available blocks on this cluster */ 153 mapped_blocks = sbi->sec_per_clus - offset; 154 155 *max_blocks = min(mapped_blocks, *max_blocks); 156 MSDOS_I(inode)->mmu_private += *max_blocks << sb->s_blocksize_bits; 157 158 err = fat_bmap(inode, iblock, &phys, &mapped_blocks, create, false); 159 if (err) 160 return err; 161 if (!phys) { 162 fat_fs_error(sb, > 163 "invalid FAT chain (i_pos %lld, last_block %ld)", 164 MSDOS_I(inode)->i_pos, last_block); 165 return -EIO; 166 } 167 168 BUG_ON(*max_blocks != mapped_blocks); 169 set_buffer_new(bh_result); 170 map_bh(bh_result, sb, phys); 171 172 return 0; 173 } 174 --- 0-DAY kernel test infrastructure Open Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation
Attachment:
.config.gz
Description: application/gzip