- uint32_t clusters_max = (volume_size >> sector_bits >> spc_bits);
- uint32_t fat_sectors = DIV_ROUND_UP(clusters_max * 4, 1 << sector_bits);
- uint32_t allocated_clusters;
-
- memset(&sb, 0, sizeof(struct exfat_super_block));
- sb.jump[0] = 0xeb;
- sb.jump[1] = 0x76;
- sb.jump[2] = 0x90;
- memcpy(sb.oem_name, "EXFAT ", sizeof(sb.oem_name));
- sb.sector_start = cpu_to_le64(first_sector);
- sb.sector_count = cpu_to_le64(volume_size >> sector_bits);
- sb.fat_sector_start = cpu_to_le32(128); /* FIXME */
- sb.fat_sector_count = cpu_to_le32(ROUND_UP(
- le32_to_cpu(sb.fat_sector_start) + fat_sectors, 1 << spc_bits) -
- le32_to_cpu(sb.fat_sector_start));
- /* cluster_sector_start will be set later */
- sb.cluster_count = cpu_to_le32(clusters_max -
- ((le32_to_cpu(sb.fat_sector_start) +
- le32_to_cpu(sb.fat_sector_count)) >> spc_bits));
- /* rootdir_cluster will be set later */
- sb.volume_serial = cpu_to_le32(volume_serial);
- sb.version.major = 1;
- sb.version.minor = 0;
- sb.volume_state = cpu_to_le16(0);
- sb.sector_bits = sector_bits;
- sb.spc_bits = spc_bits;
- sb.fat_count = 1;
- sb.drive_no = 0x80;
- sb.allocated_percent = 0;
- sb.boot_signature = cpu_to_le16(0xaa55);
-
- allocated_clusters =
- DIV_ROUND_UP(cbm_size(), CLUSTER_SIZE(sb)) +
- DIV_ROUND_UP(uct_size(), CLUSTER_SIZE(sb)) +
- DIV_ROUND_UP(rootdir_size(), CLUSTER_SIZE(sb));
- if (clusters_max < ((le32_to_cpu(sb.fat_sector_start) +
- le32_to_cpu(sb.fat_sector_count)) >> spc_bits) +
- allocated_clusters)
- {
- exfat_error("too small volume (%"PRIu64" bytes)", volume_size);
- return 1;
- }
- exfat_print_info(&sb, le32_to_cpu(sb.cluster_count) -
- allocated_clusters);
- return 0;