diff --git a/fat32format.cpp b/fat32format.cpp index 2ad023c..0d05d81 100644 --- a/fat32format.cpp +++ b/fat32format.cpp @@ -527,7 +527,7 @@ int format_volume(_In_z_ LPCSTR vol, _In_ const format_params* params) // Now we're commited - print some info first printf("Size : %gGB %lu sectors\n", piDrive.PartitionLength.QuadPart / (1024.f * 1024.f * 1024.f), TotalSectors); - printf("%lu Bytes Per Sector, Cluster size %lu bytes\n", BytesPerSect, SectorsPerCluster*BytesPerSect); + printf("%lu Bytes Per Sector, Cluster size %lu bytes\n", BytesPerSect, SectorsPerCluster * BytesPerSect); printf("Volume ID is %04lX:%04lX\n", pFAT32BootSect->dBS_VolID >> 16, pFAT32BootSect->dBS_VolID & 0xffff); printf("%u Reserved Sectors, %lu Sectors per FAT, %u fats\n", ReservedSectCount, FatSize, NumFATs); @@ -740,14 +740,29 @@ int main(int argc, char* argv[]) usage(); } - if (isalpha(volume_argv[0]) || strncmp(volume_argv, R"(\\.\)", 4) == 0) + if (strncmp(volume_argv, R"(\\?\Volume{)", 11) == 0) + { + char volume_guid[50]; + strcpy_s(volume_guid, volume_argv); + if (size_t pos = strlen(volume_guid) - 1; volume_guid[pos] == '\\') + { + volume_guid[pos] = '\0'; + } + format_volume(volume_guid, &p); + strcat_s(volume_guid, "\\"); + if (!SetVolumeLabelA(volume_guid, p.volume_label)) + { + die("Failed to set volume label"); + } + } + else { char volume[8] = R"(\\.\?:)"; - if (strcmp(&volume_argv[1], ":") == 0) + if (strlen(volume_argv) == 2 && isalpha(volume_argv[0]) && volume_argv[1] == ':') { volume[4] = volume_argv[0]; } - else if (strlen(volume_argv) == 6 && isalpha(volume_argv[4]) && volume_argv[5] == ':') + else if (strlen(volume_argv) == 6 && strncmp(volume_argv, R"(\\.\)", 4) == 0 && isalpha(volume_argv[4]) && volume_argv[5] == ':') { volume[4] = volume_argv[4]; } @@ -762,23 +777,4 @@ int main(int argc, char* argv[]) die("Failed to set volume label"); } } - else if (strncmp(volume_argv, R"(\\?\Volume{)", 11) == 0) - { - char volume_guid[50]; - strcpy_s(volume_guid, volume_argv); - if (size_t pos = strlen(volume_guid) - 1; volume_guid[pos] == '\\') - { - volume_guid[pos] = '\0'; - } - format_volume(volume_guid, &p); - strcat_s(volume_guid, "\\"); - if (!SetVolumeLabelA(volume_guid, p.volume_label)) - { - die("Failed to set volume label"); - } - } - else - { - usage(); - } } \ No newline at end of file