From 577cbb4df0f4d21d4ae0990832b467f1023f71b4 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 18 May 2010 16:09:58 +0200 Subject: [PATCH] libblkid: improbe DDF detection Signed-off-by: Karel Zak --- shlibs/blkid/src/superblocks/ddf_raid.c | 71 ++++++++++++++++++++-- tests/expected/blkid/low-probe-ddf-raid | 6 +- tests/ts/blkid/images-fs/ddf-raid.img.bz2 | Bin 535 -> 599 bytes 3 files changed, 68 insertions(+), 9 deletions(-) diff --git a/shlibs/blkid/src/superblocks/ddf_raid.c b/shlibs/blkid/src/superblocks/ddf_raid.c index a48735d2..c0ba3351 100644 --- a/shlibs/blkid/src/superblocks/ddf_raid.c +++ b/shlibs/blkid/src/superblocks/ddf_raid.c @@ -18,12 +18,57 @@ /* http://www.snia.org/standards/home */ #define DDF_GUID_LENGTH 24 #define DDF_REV_LENGTH 8 +#define DDF_MAGIC 0xDE11DE11 + struct ddf_header { - uint8_t signature[4]; + uint32_t signature; uint32_t crc; uint8_t guid[DDF_GUID_LENGTH]; - uint8_t ddf_rev[DDF_REV_LENGTH]; + char ddf_rev[8]; /* 01.02.00 */ + uint32_t seq; /* starts at '1' */ + uint32_t timestamp; + uint8_t openflag; + uint8_t foreignflag; + uint8_t enforcegroups; + uint8_t pad0; /* 0xff */ + uint8_t pad1[12]; /* 12 * 0xff */ + /* 64 bytes so far */ + uint8_t header_ext[32]; /* reserved: fill with 0xff */ + uint64_t primary_lba; + uint64_t secondary_lba; + uint8_t type; + uint8_t pad2[3]; /* 0xff */ + uint32_t workspace_len; /* sectors for vendor space - + * at least 32768(sectors) */ + uint64_t workspace_lba; + uint16_t max_pd_entries; /* one of 15, 63, 255, 1023, 4095 */ + uint16_t max_vd_entries; /* 2^(4,6,8,10,12)-1 : i.e. as above */ + uint16_t max_partitions; /* i.e. max num of configuration + record entries per disk */ + uint16_t config_record_len; /* 1 +ROUNDUP(max_primary_element_entries + *12/512) */ + uint16_t max_primary_element_entries; /* 16, 64, 256, 1024, or 4096 */ + uint8_t pad3[54]; /* 0xff */ + /* 192 bytes so far */ + uint32_t controller_section_offset; + uint32_t controller_section_length; + uint32_t phys_section_offset; + uint32_t phys_section_length; + uint32_t virt_section_offset; + uint32_t virt_section_length; + uint32_t config_section_offset; + uint32_t config_section_length; + uint32_t data_section_offset; + uint32_t data_section_length; + uint32_t bbm_section_offset; + uint32_t bbm_section_length; + uint32_t diag_space_offset; + uint32_t diag_space_length; + uint32_t vendor_offset; + uint32_t vendor_length; + /* 256 bytes so far */ + uint8_t pad4[256]; /* 0xff */ } __attribute__((packed)); static int probe_ddf(blkid_probe pr, const struct blkid_idmag *mag) @@ -32,7 +77,7 @@ static int probe_ddf(blkid_probe pr, const struct blkid_idmag *mag) int i; struct ddf_header *ddf = NULL; char version[DDF_REV_LENGTH + 1]; - uint64_t off; + uint64_t off, lba; if (pr->size < 0x30000) return -1; @@ -46,8 +91,8 @@ static int probe_ddf(blkid_probe pr, const struct blkid_idmag *mag) if (!ddf) return -1; - if (memcmp(ddf->signature, "\x11\xde\x11\xde", 4) == 0 || - memcmp(ddf->signature, "\xde\x11\xde\x11", 4) == 0) + if (ddf->signature == cpu_to_be32(DDF_MAGIC) || + ddf->signature == cpu_to_le32(DDF_MAGIC)) break; ddf = NULL; } @@ -55,6 +100,20 @@ static int probe_ddf(blkid_probe pr, const struct blkid_idmag *mag) if (!ddf) return -1; + lba = ddf->signature == cpu_to_be32(DDF_MAGIC) ? + be64_to_cpu(ddf->primary_lba) : + le64_to_cpu(ddf->primary_lba); + + if (lba > 0) { + /* check primary header */ + unsigned char *buf; + + buf = blkid_probe_get_buffer(pr, + lba << 9, sizeof(ddf->signature)); + if (!buf || memcmp(buf, &ddf->signature, 4)) + return -1; + } + blkid_probe_strncpy_uuid(pr, ddf->guid, sizeof(ddf->guid)); memcpy(version, ddf->ddf_rev, sizeof(ddf->ddf_rev)); @@ -64,7 +123,7 @@ static int probe_ddf(blkid_probe pr, const struct blkid_idmag *mag) return -1; if (blkid_probe_set_magic(pr, off, sizeof(ddf->signature), - (unsigned char *) ddf->signature)) + (unsigned char *) &ddf->signature)) return -1; return 0; } diff --git a/tests/expected/blkid/low-probe-ddf-raid b/tests/expected/blkid/low-probe-ddf-raid index 08329501..7956dcd0 100644 --- a/tests/expected/blkid/low-probe-ddf-raid +++ b/tests/expected/blkid/low-probe-ddf-raid @@ -1,5 +1,5 @@ ID_FS_TYPE=ddf_raid_member ID_FS_USAGE=raid -ID_FS_UUID=8Z_I__B_8Z_I_e_I_q_I____ -ID_FS_UUID_ENC=8Z\xb0I\x95\x10B\x028Z\xb0I\xc8e\xb0I\xb8q\xb0I\xff\xff\xff\xff -ID_FS_VERSION=02.00.00 +ID_FS_UUID=Linux-MDÞ­__ +ID_FS_UUID_ENC=Linux-MDÞ­\xbe\xef +ID_FS_VERSION=01.02.00 diff --git a/tests/ts/blkid/images-fs/ddf-raid.img.bz2 b/tests/ts/blkid/images-fs/ddf-raid.img.bz2 index c8f0c8ac527302fbedbd7367befad3b5ca234479..b09349337852a9e5f5b704b36c8d8c1481e0274a 100644 GIT binary patch literal 599 zcmV-d0;v5$T4*^jL0KkKStBJqO92rWfB*h~V1Y;@dwA6+LC`a2o?=`8P!cc}BEb-V zWkU%BfeNqzc-E*IifCvJ02u~=0002cXa8*jq55s)C|hA#Ff?{dg}XF6BcjncuZaW^nx+fH?%aB+5fMgn84ir3c2H!@b`P}XD;Prl zWm4g2s5S^NmujAG?{Cb2uoJ)}l|lh>n!Sz3icn7r2H}c{0`n^C5invcqZZHatSCke z#eX`JqMmY+x`?U@iDVHJG$19PCB*=$C|iM4P>I7nD2f6iDUvFzp#c<+BNP>qWi^xR z007VfBR}8&$OZrff;R#MKwtt8qy+#30RaG@01yZO01%J}5Q_i{lp=bjfB1rVWP!b~woFoZBkQ@YOg-2;0z>V5zK literal 535 zcmV+y0_gohT4*^jL0KkKS%(mj7XS|sfB*md{D5Bpf6#XHY%xkA>|;gHrx44^RiG>IbMjG|-JS&`60?{W7Ph@=Xs@ z2-<)&(9x!V(;=V$0iX>%LqVf@p~FBl02%{8XaE2Pnl#V`KmY?qnFcs$27m)VXbk`W z0MkaA0LTCUXwx9phVo>B*dQCg^z5R{8mTX1K$1xbSt78g#wT<-8-f{li5XDDAOR&z zcqlQkrj>0b(oLhjNmPJ<1eSYH(pLy6B4ola69FwD@oOcu$%tlSjhHqhKma7Mtb*$h z?%gCVWoD8KEt=0^*wK8iiQb{lNw-EC;~~5xFFo=AqZg!6!+djE-_did6=`XM4t3yW z4V{G|7L7|MX^6dDlPow^2zNo5b~%ipL@aXC5UzOFFrdO)9hHWus$Th4u`Elqufg4z zY8G)`Z95_JW9%=G>mk#q&9|Rx;=rTYg0rhYmry>N6qKtvt3KD zFjNptg;1E;8!Y?ff3u4=nU}SH5pD4R0Fsn1;~}Qej>Rkhk)RXLgdl*xVYQQ_&ns38 ZB(XyR7AXH&7P7y^+>uTcBq78kMZn?3=70bI -- 2.39.5