【问题标题】:how to print the s_uuid of ext2 superblock in C如何在 C 中打印 ext2 超级块的 s_uuid
【发布时间】:2018-02-15 11:08:35
【问题描述】:

我创建了一个变量来存储超级块的 s_uuid 的值。但是我遇到了如何以这种形式打印这个变量,如 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 的问题。我尝试在 %x 和 %s 中使用 printf 来打印我的变量,但它不起作用。

我想知道 UUID 如何存储在文件系统中,以及如何在控制台中打印它而不是错误编码。

【问题讨论】:

  • 显示代码和你的尝试..

标签: c uuid ext2 superblock


【解决方案1】:

s_uuid 在超级块中定义为: u8 s_uuid[16];

为了以上述格式将其打印到控制台:

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]);

【讨论】:

  • 谢谢。我搜索了很长时间,但没有得到有用的信息。您介意与我分享文档的链接吗?非常感谢。
猜你喜欢
  • 2013-03-09
  • 2016-07-12
  • 2015-03-16
  • 2016-08-14
  • 2021-03-27
  • 2011-12-23
  • 1970-01-01
  • 2019-07-07
  • 2011-11-27
相关资源
最近更新 更多