cuuidext2superblock

how to print the s_uuid of ext2 superblock in C


I create a variable to store the value of superblock's s_uuid. But I get trouble into how to print this variable like xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx in this form. I tried to use printf in %x and %s to print my variable, but it doesn't work.

I want to know how the UUID stores in file system and how I can print it in console instead of wrong encoding.


Solution

  • The s_uuid is defined in the superblock as: u8 s_uuid[16];

    In order to print this to the console in the above format:

    uint8_t s_uuid[16] = {0xf3, 0x58, 0x6b, 0xaf, 0xb5, 0xaa, 0x49, 0xb5, 
                          0x8d, 0x6c, 0x05, 0x69, 0x28, 0x4c, 0x63, 0x9f};
    
    printf("%02x%02x%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
        s_uuid[0], s_uuid[1], s_uuid[2], s_uuid[3], s_uuid[4], s_uuid[5], s_uuid[6], s_uuid[7], 
        s_uuid[8], s_uuid[9], s_uuid[10], s_uuid[11], s_uuid[12], s_uuid[13], s_uuid[14], s_uuid[15]);