Changeset 3938375 in mainline for uspace/app/mkexfat/mkexfat.c
- Timestamp:
- 2012-02-22T19:43:46Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b0fecad
- Parents:
- 9587b37
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/mkexfat/mkexfat.c
r9587b37 r3938375 59 59 #define EBS_BACKUP_SECTOR_START 13 60 60 61 /** First sector of the VBR*/62 #define VBR_SECTOR 063 64 /** First sector if the VBRBackup */65 #define VBR_BACKUP_SECTOR 1261 /** First sector of the Main Boot Sector */ 62 #define MBS_SECTOR 0 63 64 /** First sector of the Main Boot Sector Backup */ 65 #define MBS_BACKUP_SECTOR 12 66 66 67 67 /** Size of the Main Extended Boot Region */ … … 159 159 } 160 160 161 /** Initialize the Volume Boot Recordfields.162 * 163 * @param vbr Pointer to the Volume Boot Recordstructure.161 /** Initialize the Main Boot Sector fields. 162 * 163 * @param mbs Pointer to the Main Boot Sector structure. 164 164 * @param cfg Pointer to the exFAT configuration structure. 165 165 * @return Initial checksum value. 166 166 */ 167 167 static uint32_t 168 vbr_initialize(exfat_bs_t * vbr, exfat_cfg_t *cfg)168 vbr_initialize(exfat_bs_t *mbs, exfat_cfg_t *cfg) 169 169 { 170 170 /* Fill the structure with zeroes */ 171 memset( vbr, 0, sizeof(exfat_bs_t));171 memset(mbs, 0, sizeof(exfat_bs_t)); 172 172 173 173 /* Init Jump Boot section */ 174 vbr->jump[0] = 0xEB;175 vbr->jump[1] = 0x76;176 vbr->jump[2] = 0x90;174 mbs->jump[0] = 0xEB; 175 mbs->jump[1] = 0x76; 176 mbs->jump[2] = 0x90; 177 177 178 178 /* Set the filesystem name */ 179 memcpy( vbr->oem_name, "EXFAT ", sizeof(vbr->oem_name));180 181 vbr->volume_start = host2uint64_t_le(cfg->volume_start);182 vbr->volume_count = host2uint64_t_le(cfg->volume_count);183 vbr->fat_sector_start = host2uint32_t_le(FAT_SECTOR_START);184 vbr->fat_sector_count = host2uint32_t_le(cfg->fat_sector_count);185 vbr->data_start_sector = host2uint32_t_le(cfg->data_start_sector);186 187 vbr->data_clusters = host2uint32_t_le(cfg->total_clusters -179 memcpy(mbs->oem_name, "EXFAT ", sizeof(mbs->oem_name)); 180 181 mbs->volume_start = host2uint64_t_le(cfg->volume_start); 182 mbs->volume_count = host2uint64_t_le(cfg->volume_count); 183 mbs->fat_sector_start = host2uint32_t_le(FAT_SECTOR_START); 184 mbs->fat_sector_count = host2uint32_t_le(cfg->fat_sector_count); 185 mbs->data_start_sector = host2uint32_t_le(cfg->data_start_sector); 186 187 mbs->data_clusters = host2uint32_t_le(cfg->total_clusters - 188 188 div_round_up(cfg->data_start_sector, cfg->cluster_size)); 189 189 190 vbr->rootdir_cluster = 0;191 vbr->volume_serial = 0;192 vbr->version.major = 1;193 vbr->version.minor = 0;194 vbr->volume_flags = host2uint16_t_le(0);195 vbr->bytes_per_sector = log2(cfg->sector_size);196 vbr->sec_per_cluster = log2(cfg->cluster_size / cfg->sector_size);190 mbs->rootdir_cluster = 0; 191 mbs->volume_serial = 0; 192 mbs->version.major = 1; 193 mbs->version.minor = 0; 194 mbs->volume_flags = host2uint16_t_le(0); 195 mbs->bytes_per_sector = log2(cfg->sector_size); 196 mbs->sec_per_cluster = log2(cfg->cluster_size / cfg->sector_size); 197 197 198 198 /* Maximum cluster size is 32 Mb */ 199 assert(( vbr->bytes_per_sector + vbr->sec_per_cluster) <= 25);200 201 vbr->fat_count = 1;202 vbr->drive_no = 0x80;203 vbr->allocated_percent = 0;204 vbr->signature = host2uint16_t_le(0xAA55);205 206 return vbr_checksum_start( vbr, sizeof(exfat_bs_t));199 assert((mbs->bytes_per_sector + mbs->sec_per_cluster) <= 25); 200 201 mbs->fat_count = 1; 202 mbs->drive_no = 0x80; 203 mbs->allocated_percent = 0; 204 mbs->signature = host2uint16_t_le(0xAA55); 205 206 return vbr_checksum_start(mbs, sizeof(exfat_bs_t)); 207 207 } 208 208 … … 210 210 bootsec_write(service_id_t service_id, exfat_cfg_t *cfg) 211 211 { 212 exfat_bs_t vbr;212 exfat_bs_t mbs; 213 213 uint32_t vbr_checksum; 214 214 uint32_t initial_checksum; 215 215 int rc; 216 216 217 vbr_checksum = vbr_initialize(& vbr, cfg);217 vbr_checksum = vbr_initialize(&mbs, cfg); 218 218 initial_checksum = vbr_checksum; 219 219 220 /* Write the VBR ondisk */221 rc = block_write_direct(service_id, VBR_SECTOR, 1, &vbr);220 /* Write the Main Boot Sector to disk */ 221 rc = block_write_direct(service_id, MBS_SECTOR, 1, &mbs); 222 222 if (rc != EOK) 223 223 return rc; 224 224 225 /* Write the VBR backup ondisk */226 rc = block_write_direct(service_id, VBR_BACKUP_SECTOR, 1, &vbr);225 /* Write the Main extended boot sectors to disk */ 226 rc = ebs_write(service_id, cfg, EBS_SECTOR_START, &vbr_checksum); 227 227 if (rc != EOK) 228 228 return rc; 229 229 230 rc = ebs_write(service_id, cfg, EBS_SECTOR_START, &vbr_checksum); 230 /* Write the Main Boot Sector backup to disk */ 231 rc = block_write_direct(service_id, MBS_BACKUP_SECTOR, 1, &mbs); 231 232 if (rc != EOK) 232 233 return rc; … … 235 236 vbr_checksum = initial_checksum; 236 237 238 /* Write the Main extended boot sectors backup to disk */ 237 239 return ebs_write(service_id, cfg, 238 240 EBS_BACKUP_SECTOR_START, &vbr_checksum); … … 299 301 /** Writes the FAT on disk. 300 302 * 303 * @param service_id The service id. 301 304 * @param cfg Pointer to the exfat_cfg structure. 302 305 * @return EOK on success or a negative error code.
Note:
See TracChangeset
for help on using the changeset viewer.