| 630 | } |
| 631 | |
| 632 | static int fat32_create_rootdir(disk_t *disk_car,const partition_t *partition, const unsigned int reserved, const unsigned int fat_length, const unsigned int root_cluster, const unsigned int sectors_per_cluster, const int verbose, file_info_t *rootdir_list, const unsigned int fats) |
| 633 | { |
| 634 | const uint64_t start_data=reserved+fats*fat_length; |
| 635 | const unsigned int cluster_size=disk_car->sector_size*sectors_per_cluster; |
| 636 | unsigned int current_entry=0; |
| 637 | unsigned int cluster; |
| 638 | unsigned char *buffer; |
| 639 | struct td_list_head *file_walker = NULL; |
| 640 | if(verbose>0) |
| 641 | { |
| 642 | log_trace("fat32_create_rootdir(reserved=%u,fat_length=%u,root_cluster=%u,sectors_per_cluster=%u)\n",reserved,fat_length,root_cluster,sectors_per_cluster); |
| 643 | } |
| 644 | cluster=root_cluster; |
| 645 | buffer=(unsigned char *)MALLOC(cluster_size); |
| 646 | memset(buffer,0,cluster_size); |
| 647 | td_list_for_each(file_walker, &rootdir_list->list) |
| 648 | { |
| 649 | const file_info_t *current_file=td_list_entry_const(file_walker, const file_info_t, list); |
| 650 | file2entry((struct msdos_dir_entry*)buffer+current_entry,current_file); |
| 651 | if(++current_entry==(cluster_size/sizeof(struct msdos_dir_entry))) |
| 652 | { |
| 653 | unsigned int next_cluster; |
| 654 | if((unsigned)disk_car->pwrite(disk_car, buffer, cluster_size, |
| 655 | partition->part_offset + (start_data + (uint64_t)(cluster - 2) * sectors_per_cluster) * disk_car->sector_size) != cluster_size) |
| 656 | { |
| 657 | display_message("Write error: Can't create FAT32 root cluster.\n"); |
| 658 | } |
| 659 | current_entry=0; |
| 660 | memset(buffer,0,cluster_size); |
| 661 | /* FIXME need to write fat32_get_next_free_cluster */ |
| 662 | next_cluster=cluster++; |
| 663 | if(set_next_cluster(disk_car,partition,UP_FAT32,reserved,cluster,next_cluster)) |
| 664 | { |
| 665 | display_message("Can't modify the FAT entries.\n"); |
| 666 | } |
| 667 | if(set_next_cluster(disk_car,partition,UP_FAT32,reserved+fat_length,cluster,next_cluster)) |
| 668 | { |
| 669 | display_message("Can't modify the FAT entries.\n"); |
| 670 | } |
| 671 | cluster=next_cluster; |
| 672 | } |
| 673 | } |
| 674 | if((unsigned)disk_car->pwrite(disk_car, buffer, cluster_size, partition->part_offset + (start_data + (uint64_t)(cluster - 2) * sectors_per_cluster) * disk_car->sector_size) != cluster_size) |
| 675 | { |
| 676 | display_message("Write error: Can't create FAT32 root cluster.\n"); |
| 677 | } |
| 678 | if(set_next_cluster(disk_car,partition,UP_FAT32,reserved,cluster,FAT32_EOC)) |
| 679 | { |
| 680 | display_message("Can't modify the FAT entries.\n"); |
| 681 | } |
| 682 | if(set_next_cluster(disk_car,partition,UP_FAT32,reserved+fat_length,cluster,FAT32_EOC)) |
| 683 | { |
| 684 | display_message("Can't modify the FAT entries.\n"); |
| 685 | } |
| 686 | #ifdef DEBUG |
| 687 | { |
| 688 | file_info_t dir_list; |
| 689 | TD_INIT_LIST_HEAD(&dir_list.list); |
no test coverage detected