Changeset 6aeab59c in mainline
- Timestamp:
- 2012-02-22T21:42:36Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 367014a
- Parents:
- b0fecad
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/mkexfat/mkexfat.c
rb0fecad r6aeab59c 81 81 unsigned long rootdir_cluster; 82 82 unsigned long total_clusters; 83 unsigned long allocated_clusters; 84 size_t bitmap_size; 83 85 size_t sector_size; 84 86 size_t cluster_size; … … 97 99 ebs_write(service_id_t service_id, exfat_cfg_t *cfg, 98 100 int base, uint32_t *chksum); 101 102 static int 103 bitmap_write(service_id_t service_id, exfat_cfg_t *cfg); 99 104 100 105 static void usage(void) … … 139 144 cfg->fat_sector_count, cfg->cluster_size / cfg->sector_size); 140 145 146 /* Compute the bitmap size */ 147 cfg->bitmap_size = n_req_clusters / 8; 148 149 cfg->allocated_clusters = div_round_up(cfg->bitmap_size, 150 cfg->cluster_size); 151 152 /* This account for the root directory */ 153 cfg->allocated_clusters++; 154 /* FIXME: add upcase table clusters to allocated_clusters */ 155 156 /* FIXME: set the real rootdir cluster */ 141 157 cfg->rootdir_cluster = 0; 142 158 … … 312 328 int rc; 313 329 314 pfat = calloc(cfg-> fat_sector_count, cfg->sector_size);330 pfat = calloc(cfg->sector_size, 1); 315 331 if (!pfat) 316 332 return ENOMEM; … … 332 348 memset(pfat, 0, 5 * sizeof(uint32_t)); 333 349 334 for (i = 1; i < cfg->fat_sector_count + 1; ++i) {350 for (i = 1; i < cfg->fat_sector_count; ++i) { 335 351 rc = block_write_direct(service_id, 336 352 FAT_SECTOR_START + i, 1, pfat); … … 341 357 error: 342 358 free(pfat); 359 return rc; 360 } 361 362 /** Initialize the allocation bitmap. 363 * 364 * @param service_id The service id. 365 * @param cfg Pointer to the exfat configuration structure. 366 * @return EOK on success or a negative error code. 367 */ 368 static int 369 bitmap_write(service_id_t service_id, exfat_cfg_t *cfg) 370 { 371 unsigned long i, sec; 372 unsigned long allocated_cls; 373 int rc = EOK; 374 375 /* Bitmap size in sectors */ 376 size_t const bss = div_round_up(cfg->bitmap_size, cfg->sector_size); 377 378 uint8_t *bitmap = malloc(cfg->sector_size); 379 if (!bitmap) 380 return ENOMEM; 381 382 allocated_cls = cfg->allocated_clusters; 383 384 for (sec = 0; sec < bss; ++sec) { 385 memset(bitmap, 0, cfg->sector_size); 386 if (allocated_cls > 0) { 387 for (i = 0; i < allocated_cls; ++i) { 388 unsigned byte_idx = i / 8; 389 unsigned bit_idx = i % 8; 390 391 if (byte_idx == cfg->sector_size) 392 break; 393 bitmap[byte_idx] |= 1 << bit_idx; 394 } 395 396 allocated_cls -= i * 8; 397 } 398 399 rc = block_write_direct(service_id, 400 cfg->data_start_sector + sec, 1, bitmap); 401 if (rc != EOK) 402 goto exit; 403 } 404 405 exit: 406 free(bitmap); 343 407 return rc; 344 408 } … … 459 523 } 460 524 525 rc = bitmap_write(service_id, &cfg); 526 if (rc != EOK) { 527 printf(NAME ": Error, failed to write the allocation" \ 528 " bitmap to disk.\n"); 529 return 2; 530 } 531 461 532 return 0; 462 533 }
Note:
See TracChangeset
for help on using the changeset viewer.