在 C 中获取 Fat12 磁盘的卷标

Getting the volume label of a Fat12 disk in C

我有一个奇怪的时间试图在 C 中获取磁盘映像的卷标。我知道对于 FAT12 磁盘,这条信息位于偏移量 0x2b 或十进制的 43 处,长度为 11 个字节.无论如何,现在这是我的代码:

void main(int argc, char *argv[]) {
    ...
    FILE *fp = fopen(argv[1], "rb");
    printf("Volume Label: %s\n", seekData(fp, 43, 11));
    ...
}

unsigned char* seekData(FILE *fp, int offset, int bytes) {
    unsigned char* buff = malloc(sizeof(unsigned char)*bytes);
    fseek(fp, offset, SEEK_SET);
    fread(buff, 1, bytes, fp);
    rewind(fp);
    return buff;
}

对于我使用的任何输入文件 (.IMA),我总是以十六进制返回 20 20 20 20 20 20 20 20 20 20 20。或者当上面的代码是 运行 时只是 Volume Label:(nothing here)。我在这里错过了一些非常明显的东西吗?任何帮助将不胜感激

所以我找到了问题所在。卷标似乎不再存储在前面提到的位置,通常作为特殊文件位于根目录中。

来源:http://www.ntfs.com/fat-partition-sector.htm

"Volume Label. This field was used to store the volume label, but the volume label is now stored as special file in the root directory."