[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH 2/3] volume_id: 128-bit UUID for hfs[+]
From:       Sven-Göran_Bergh <svengbergh-busybox () yahoo ! com>
Date:       2012-11-21 15:07:23
Message-ID: 1353510443.70572.YahooMailNeo () web121806 ! mail ! ne1 ! yahoo ! com
[Download RAW message or body]

In order to comply with util-linux and the UUID shown in
/dev/disk/by-uuid, the raw HFS[+] 64 bit id needs to be
mangles with md5 to produce a 128-bit UUID.

  volume_id: hfs[+] 128-bit UUID

  function                                             old     new   delta
  hfs_set_uuid                                           -     147    +147
  static.CSWTCH                                         20      16      -4
  volume_id_probe_hfs_hfsplus                          749     739     -10
  volume_id_set_uuid                                   321     295     -26
  .rodata                                           148932  148893     -39
  ------------------------------------------------------------------------------
  (add/remove: 1/0 grow/shrink: 0/4 up/down: 147/-79)            Total: 68 bytes

  Signed-off-by: Sven-Göran Bergh <sgb@systemasis.org>
---
 util-linux/volume_id/hfs.c                |   25 +++++++++++++++++++++++--
 util-linux/volume_id/util.c               |    6 ------
 util-linux/volume_id/volume_id_internal.h |    1 -
 3 files changed, 23 insertions(+), 9 deletions(-)

Patch attached.

["2-volume_id-hfs-128bit-uuid.patch" (application/octet-stream)]

commit 73b369b3d1c512473a6e823590e12763c8719166
Author: Sven-Göran Bergh <sgb@systemasis.org>
Date:   Tue Nov 20 19:04:51 2012 +0100

    volume_id: hfs[+] 128-bit UUID
    
    function                                             old     new   delta
    hfs_set_uuid                                           -     147    +147
    static.CSWTCH                                         20      16      -4
    volume_id_probe_hfs_hfsplus                          749     739     -10
    volume_id_set_uuid                                   321     295     -26
    .rodata                                           148932  148893     -39
    ------------------------------------------------------------------------------
    (add/remove: 1/0 grow/shrink: 0/4 up/down: 147/-79)            Total: 68 bytes
    
    Signed-off-by: Sven-Göran Bergh <sgb@systemasis.org>
---
 util-linux/volume_id/hfs.c                |   25 +++++++++++++++++++++++--
 util-linux/volume_id/util.c               |    6 ------
 util-linux/volume_id/volume_id_internal.h |    1 -
 3 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/util-linux/volume_id/hfs.c b/util-linux/volume_id/hfs.c
index dd5ec24..3d9704d 100644
--- a/util-linux/volume_id/hfs.c
+++ b/util-linux/volume_id/hfs.c
@@ -131,6 +131,27 @@ struct hfsplus_vol_header {
 #define HFS_NODE_LEAF			0xff
 #define HFSPLUS_POR_CNID		1
 
+static void FAST_FUNC hfs_set_uuid(struct volume_id *id, const uint8_t *hfs_id)
+{
+#define hfs_id_len 8
+	md5_ctx_t md5c;
+	uint8_t uuid[16];
+	unsigned i;
+
+	for (i = 0; i < hfs_id_len; i++)
+		if (hfs_id[i] != 0)
+			goto do_md5;
+	return;
+ do_md5:
+	md5_begin(&md5c);
+	md5_hash(&md5c, "\263\342\17\71\362\222\21\326\227\244\0\60\145\103\354\254", 16);
+	md5_hash(&md5c, hfs_id, hfs_id_len);
+	md5_end(&md5c, uuid);
+	uuid[6] = 0x30 | (uuid[6] & 0x0f);
+	uuid[8] = 0x80 | (uuid[8] & 0x3f);
+	volume_id_set_uuid(id, uuid, UUID_DCE);
+}
+
 int FAST_FUNC volume_id_probe_hfs_hfsplus(struct volume_id *id /*,uint64_t off*/)
 {
 	uint64_t off = 0;
@@ -193,7 +214,7 @@ int FAST_FUNC volume_id_probe_hfs_hfsplus(struct volume_id *id /*,uint64_t off*/
 		volume_id_set_label_string(id, hfs->label, hfs->label_len) ;
 	}
 
-	volume_id_set_uuid(id, hfs->finder_info.id, UUID_HFS);
+	hfs_set_uuid(id, hfs->finder_info.id);
 //	volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
 	IF_FEATURE_BLKID_TYPE(id->type = "hfs";)
 
@@ -207,7 +228,7 @@ int FAST_FUNC volume_id_probe_hfs_hfsplus(struct volume_id *id /*,uint64_t off*/
 	return -1;
 
  hfsplus:
-	volume_id_set_uuid(id, hfsplus->finder_info.id, UUID_HFS);
+	hfs_set_uuid(id, hfsplus->finder_info.id);
 
 	blocksize = be32_to_cpu(hfsplus->blocksize);
 	dbg("blocksize %u", blocksize);
diff --git a/util-linux/volume_id/util.c b/util-linux/volume_id/util.c
index 69e43dd..11ee0d5 100644
--- a/util-linux/volume_id/util.c
+++ b/util-linux/volume_id/util.c
@@ -142,7 +142,6 @@ void volume_id_set_uuid(struct volume_id *id, const uint8_t *buf, enum uuid_form
 		count = 4;
 		break;
 	case UUID_NTFS:
-	case UUID_HFS:
 		count = 8;
 		break;
 	case UUID_DCE:
@@ -173,11 +172,6 @@ set:
 			buf[7], buf[6], buf[5], buf[4],
 			buf[3], buf[2], buf[1], buf[0]);
 		break;
-	case UUID_HFS:
-		sprintf(id->uuid, "%02X%02X%02X%02X%02X%02X%02X%02X",
-			buf[0], buf[1], buf[2], buf[3],
-			buf[4], buf[5], buf[6], buf[7]);
-		break;
 	case UUID_DCE:
 		sprintf(id->uuid,
 			"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
diff --git a/util-linux/volume_id/volume_id_internal.h b/util-linux/volume_id/volume_id_internal.h
index 03dc46f..dd62df3 100644
--- a/util-linux/volume_id/volume_id_internal.h
+++ b/util-linux/volume_id/volume_id_internal.h
@@ -141,7 +141,6 @@ enum uuid_format {
 	UUID_DCE,
 	UUID_DOS,
 	UUID_NTFS,
-	UUID_HFS,
 };
 
 enum endian {


_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic