Changeset da34d61d in mainline
- Timestamp:
- 2012-02-25T14:53:21Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ff415f62
- Parents:
- 392bd67c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/mkexfat/mkexfat.c
r392bd67c rda34d61d 47 47 #include <sys/typefmt.h> 48 48 #include <bool.h> 49 #include <str.h> 49 50 #include "exfat.h" 50 51 #include "upcase.h" … … 88 89 unsigned long rootdir_cluster; 89 90 unsigned long upcase_table_cluster; 91 unsigned long bitmap_cluster; 90 92 unsigned long total_clusters; 91 93 unsigned long allocated_clusters; … … 111 113 bitmap_write(service_id_t service_id, exfat_cfg_t *cfg); 112 114 115 static uint32_t 116 upcase_table_checksum(void const *data, size_t nbytes); 117 113 118 static void usage(void) 114 119 { … … 168 173 /* Will be set later */ 169 174 cfg->rootdir_cluster = 0; 175 176 /* Bitmap always starts at the first free cluster */ 177 cfg->bitmap_cluster = FIRST_FREE_CLUSTER; 170 178 171 179 /* The first sector of the partition is zero */ … … 524 532 } 525 533 534 /** Initialize and write the root directory entries to disk. 535 * 536 * @param service_id The service id. 537 * @param cfg Pointer to the exFAT configuration structure. 538 * @return EOK on success or a negative error code. 539 */ 540 static int 541 root_dentries_write(service_id_t service_id, exfat_cfg_t *cfg) 542 { 543 exfat_dentry_t *d; 544 aoff64_t rootdir_sec; 545 int rc; 546 uint8_t *data; 547 548 data = calloc(cfg->sector_size, 1); 549 if (!data) 550 return ENOMEM; 551 552 d = (exfat_dentry_t *) data; 553 554 /* Initialize the volume label dentry */ 555 d->type = EXFAT_TYPE_VOLLABEL; 556 str_to_utf16(d->vollabel.label, 7, "HELENOS"); 557 d->vollabel.size = 7; 558 559 d++; 560 561 /* Initialize the allocation bitmap dentry */ 562 d->type = EXFAT_TYPE_BITMAP; 563 d->bitmap.flags = 0; /* First FAT */ 564 d->bitmap.firstc = host2uint32_t_le(cfg->bitmap_cluster); 565 d->bitmap.size = host2uint64_t_le(cfg->bitmap_size); 566 567 d++; 568 569 /* Initialize the upcase table dentry */ 570 d->type = EXFAT_TYPE_UCTABLE; 571 d->uctable.checksum = host2uint32_t_le(upcase_table_checksum( 572 upcase_table, sizeof(upcase_table))); 573 d->uctable.firstc = host2uint32_t_le(cfg->upcase_table_cluster); 574 d->uctable.size = host2uint64_t_le(sizeof(upcase_table)); 575 576 /* Compute the number of the sector where the rootdir resides */ 577 578 rootdir_sec = cfg->data_start_sector; 579 rootdir_sec += ((cfg->rootdir_cluster - 2) * cfg->cluster_size) / 580 cfg->sector_size; 581 582 rc = block_write_direct(service_id, rootdir_sec, 1, data); 583 584 free(data); 585 return rc; 586 } 587 526 588 /** Given a number (n), returns the result of log2(n). 527 589 * … … 655 717 656 718 /* Allocate clusters for the bitmap */ 657 rc = fat_allocate_clusters(service_id, &cfg, FIRST_FREE_CLUSTER,719 rc = fat_allocate_clusters(service_id, &cfg, cfg.bitmap_cluster, 658 720 div_round_up(cfg.bitmap_size, cfg.cluster_size)); 659 721 if (rc != EOK) { … … 662 724 } 663 725 664 next_cls = FIRST_FREE_CLUSTER+726 next_cls = cfg.bitmap_cluster + 665 727 div_round_up(cfg.bitmap_size, cfg.cluster_size); 666 728 cfg.upcase_table_cluster = next_cls; … … 699 761 } 700 762 763 rc = root_dentries_write(service_id, &cfg); 764 if (rc != EOK) { 765 printf(NAME ": Error, failed to write the root directory" \ 766 " entries to disk.\n"); 767 return 2; 768 } 769 701 770 rc = bootsec_write(service_id, &cfg); 702 771 if (rc != EOK) {
Note:
See TracChangeset
for help on using the changeset viewer.