From: Kay Sievers Date: Sat, 6 Dec 2008 16:12:55 +0000 (+0100) Subject: blkid: hfs - use proper native UUID format X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=768cc5578cc87965b5f886246c957c92fd968015;p=util-linux blkid: hfs - use proper native UUID format Here is the md5'd UUID for hfs: $ LD_LIBRARY_PATH=libs/blkid/src/ libs/blkid/bin/blkid ../../volume_images/hfs-extended.img UUID="56a19597-a3c8-325d-9df2-f30bc6f8ac09" LABEL="I am HFS Extended" TYPE="hfsplus" $ /lib/udev/vol_id ../../volume_images/hfs-extended.img ID_FS_USAGE=filesystem ID_FS_TYPE=hfsplus ID_FS_VERSION= ID_FS_UUID=56a19597-a3c8-325d-9df2-f30bc6f8ac09 ID_FS_UUID_ENC=56a19597-a3c8-325d-9df2-f30bc6f8ac09 ID_FS_LABEL=I_am_HFS_Extended ID_FS_LABEL_ENC=I\x20am\x20HFS\x20Extended Signed-off-by: Kay Sievers --- diff --git a/libs/blkid/TODO b/libs/blkid/TODO index a1923b5d..2c804996 100644 --- a/libs/blkid/TODO +++ b/libs/blkid/TODO @@ -5,7 +5,6 @@ - add blkid -o | --format=full|value|udev - - add MD5(lib/md5.c) UUID to HFS, for more details see libvolume_id - consolidate "getsize" stuff (see getsize.c and lib/blkdev.c) - add a new flag to keep information that FS is ready to share the device with diff --git a/libs/blkid/src/Makefile.am b/libs/blkid/src/Makefile.am index 202fe4af..a9702b2d 100644 --- a/libs/blkid/src/Makefile.am +++ b/libs/blkid/src/Makefile.am @@ -9,7 +9,9 @@ lib_LIBRARIES = libblkid.a libblkid_a_SOURCES = cache.c dev.c devname.c devno.c getsize.c llseek.c \ probe.c read.c resolve.c save.c tag.c version.c verify.c \ blkid.h blkidP.h list.h probers/probers.h \ - $(top_srcdir)/lib/blkdev.c $(top_srcdir)/lib/linux_version.c + $(top_srcdir)/lib/blkdev.c \ + $(top_srcdir)/lib/linux_version.c \ + $(top_srcdir)/lib/md5.c libblkid_a_LIBADD = probers/libprobers.a libblkid_a_CFLAGS = -fPIC diff --git a/libs/blkid/src/probers/hfs.c b/libs/blkid/src/probers/hfs.c index 6224d378..aef99524 100644 --- a/libs/blkid/src/probers/hfs.c +++ b/libs/blkid/src/probers/hfs.c @@ -1,8 +1,5 @@ /* - * Copyright (C) 1999 by Andries Brouwer - * Copyright (C) 1999, 2000, 2003 by Theodore Ts'o - * Copyright (C) 2001 by Andreas Dilger - * Copyright (C) 2004 Kay Sievers + * Copyright (C) 2004-2008 Kay Sievers * Copyright (C) 2008 Karel Zak * * This file may be redistributed under the terms of the @@ -15,6 +12,7 @@ #include #include "blkidP.h" +#include "md5.h" /* HFS / HFS+ */ struct hfs_finder_info { @@ -128,10 +126,27 @@ struct hfsplus_vol_header { struct hfsplus_fork start_file; } __attribute__((packed)); +static int hfs_set_uuid(blkid_probe pr, unsigned char const *hfs_info) +{ + static unsigned char const hash_init[16] = { + 0xb3, 0xe2, 0x0f, 0x39, 0xf2, 0x92, 0x11, 0xd6, + 0x97, 0xa4, 0x00, 0x30, 0x65, 0x43, 0xec, 0xac + }; + unsigned char uuid[16]; + struct MD5Context md5c; + + MD5Init(&md5c); + MD5Update(&md5c, hash_init, 16); + MD5Update(&md5c, hfs_info, 8); + MD5Final(uuid, &md5c); + uuid[6] = 0x30 | (uuid[6] & 0x0f); + uuid[8] = 0x80 | (uuid[8] & 0x3f); + return blkid_probe_set_uuid(pr, uuid); +} + static int probe_hfs(blkid_probe pr, const struct blkid_idmag *mag) { struct hfs_mdb *hfs; - uint64_t uuid; hfs = blkid_probe_get_sb(pr, mag, struct hfs_mdb); if (!hfs) @@ -141,12 +156,7 @@ static int probe_hfs(blkid_probe pr, const struct blkid_idmag *mag) (memcmp(hfs->embed_sig, "HX", 2) == 0)) return 1; /* Not hfs, but an embedded HFS+ */ - uuid = le64_to_cpu(*((uint64_t *) hfs->finder_info.id)); - if (uuid) - blkid_probe_sprintf_uuid(pr, - hfs->finder_info.id, - sizeof(hfs->finder_info.id), - "%016" PRIX64, uuid); + hfs_set_uuid(pr, hfs->finder_info.id); blkid_probe_set_label(pr, hfs->label, hfs->label_len); return 0; @@ -174,7 +184,7 @@ static int probe_hfsplus(blkid_probe pr, const struct blkid_idmag *mag) unsigned int leaf_node_size; unsigned int leaf_block; int ext; - uint64_t leaf_off, uuid; + uint64_t leaf_off; unsigned char *buf; sbd = blkid_probe_get_sb(pr, mag, struct hfs_mdb); @@ -210,12 +220,7 @@ static int probe_hfsplus(blkid_probe pr, const struct blkid_idmag *mag) (memcmp(hfsplus->signature, "HX", 2) != 0)) return 1; - uuid = be64_to_cpu(*((unsigned long long *) hfsplus->finder_info.id)); - if (uuid) - blkid_probe_sprintf_uuid(pr, - hfsplus->finder_info.id, - sizeof(hfsplus->finder_info.id), - "%016" PRIX64, uuid); + hfs_set_uuid(pr, hfsplus->finder_info.id); blocksize = be32_to_cpu(hfsplus->blocksize); memcpy(extents, hfsplus->cat_file.extents, sizeof(extents));