cfatdiskimage

Getting the volume label of a Fat12 disk in C


I'm having an odd time trying to get the volume label of a disk image in C. I understand that for FAT12 disks this piece of information is located at offset 0x2b or 43 in decimal and is 11 bytes in length. Anyway here is my code right now:

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;
}

For any input file I use (.IMA) I keep getting back 20 20 20 20 20 20 20 20 20 20 20 in hex. Or just Volume Label:(nothing here) when the above code is run. Am I missing something super obvious here? Any help would be appreciated


Solution

  • So I have found the problem. It seems volume label isn't stored at the previously mentioned location anymore and is usually located in the root directory as a special file.

    Source: 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."