X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=extras%2Fvolume_id%2Fvolume_id%2Fiso9660.c;h=8811ffbc03e9e0a0acd6c11ac200fccc4ab6b9bb;hb=b5d88a0cfe49ca34db713b42ea031857395debc4;hp=ffccf609dc50e5f80604f1774773faf8d93853c1;hpb=e4d4a557e53c3fbcf14bd1bb29686fd884905b53;p=elogind.git diff --git a/extras/volume_id/volume_id/iso9660.c b/extras/volume_id/volume_id/iso9660.c index ffccf609d..8811ffbc0 100644 --- a/extras/volume_id/volume_id/iso9660.c +++ b/extras/volume_id/volume_id/iso9660.c @@ -32,7 +32,6 @@ #include #include #include -#include #include "volume_id.h" #include "logging.h" @@ -47,68 +46,86 @@ #define ISO_VD_END 0xff #define ISO_VD_MAX 16 -union iso_super_block { - struct iso_header { - __u8 type; - __u8 id[5]; - __u8 version; - __u8 unused1; - __u8 system_id[32]; - __u8 volume_id[32]; - } __attribute__((__packed__)) iso; - struct hs_header { - __u8 foo[8]; - __u8 type; - __u8 id[4]; - __u8 version; - } __attribute__((__packed__)) hs; +struct iso_volume_descriptor { + uint8_t vd_type; + uint8_t vd_id[5]; + uint8_t vd_version; + uint8_t flags; + uint8_t system_id[32]; + uint8_t volume_id[32]; + uint8_t unused[8]; + uint8_t space_size[8]; + uint8_t escape_sequences[8]; } __attribute__((__packed__)); -int volume_id_probe_iso9660(struct volume_id *id, __u64 off) +struct high_sierra_volume_descriptor { + uint8_t foo[8]; + uint8_t type; + uint8_t id[4]; + uint8_t version; +} __attribute__((__packed__)); + +int volume_id_probe_iso9660(struct volume_id *id, uint64_t off) { - union iso_super_block *is; + uint8_t *buf; + struct iso_volume_descriptor *is; + struct high_sierra_volume_descriptor *hs; - dbg("probing at offset %llu", off); + dbg("probing at offset 0x%llx", (unsigned long long) off); - is = (union iso_super_block *) volume_id_get_buffer(id, off + ISO_SUPERBLOCK_OFFSET, 0x200); - if (is == NULL) + buf = volume_id_get_buffer(id, off + ISO_SUPERBLOCK_OFFSET, 0x200); + if (buf == NULL) return -1; - if (memcmp(is->iso.id, "CD001", 5) == 0) { - char root_label[VOLUME_ID_LABEL_SIZE+1]; + is = (struct iso_volume_descriptor *) buf; + + if (memcmp(is->vd_id, "CD001", 5) == 0) { int vd_offset; int i; - int found_svd; - memset(root_label, 0, sizeof(root_label)); - strncpy(root_label, is->iso.volume_id, sizeof(root_label)-1); + dbg("read label from PVD"); + volume_id_set_label_raw(id, is->volume_id, 32); + volume_id_set_label_string(id, is->volume_id, 32); - found_svd = 0; + dbg("looking for SVDs"); vd_offset = ISO_VD_OFFSET; for (i = 0; i < ISO_VD_MAX; i++) { - is = (union iso_super_block *) volume_id_get_buffer(id, off + vd_offset, 0x200); - if (is == NULL || is->iso.type == ISO_VD_END) - break; - if (is->iso.type == ISO_VD_SUPPLEMENTARY) { - dbg("found ISO supplementary VD at offset 0x%llx", off + vd_offset); - volume_id_set_label_raw(id, is->iso.volume_id, 32); - volume_id_set_label_unicode16(id, is->iso.volume_id, BE, 32); - found_svd = 1; + uint8_t svd_label[64]; + + is = (struct iso_volume_descriptor *) volume_id_get_buffer(id, off + vd_offset, 0x200); + if (is == NULL || is->vd_type == ISO_VD_END) break; + if (is->vd_type != ISO_VD_SUPPLEMENTARY) + continue; + + dbg("found SVD at offset 0x%llx", (unsigned long long) (off + vd_offset)); + if (memcmp(is->escape_sequences, "%/@", 3) == 0|| + memcmp(is->escape_sequences, "%/C", 3) == 0|| + memcmp(is->escape_sequences, "%/E", 3) == 0) { + dbg("Joliet extension found"); + volume_id_set_unicode16((char *)svd_label, sizeof(svd_label), is->volume_id, BE, 32); + if (memcmp(id->label, svd_label, 16) == 0) { + dbg("SVD label is identical, use the possibly longer PVD one"); + break; + } + + volume_id_set_label_raw(id, is->volume_id, 32); + volume_id_set_label_string(id, svd_label, 32); + strcpy(id->type_version, "Joliet Extension"); + goto found; } vd_offset += ISO_SECTOR_SIZE; } - - if (!found_svd || - (found_svd && !memcmp(root_label, id->label, 16))) - { - volume_id_set_label_raw(id, root_label, 32); - volume_id_set_label_string(id, root_label, 32); - } goto found; } - if (memcmp(is->hs.id, "CDROM", 5) == 0) + + hs = (struct high_sierra_volume_descriptor *) buf; + + if (memcmp(hs->id, "CDROM", 5) == 0) { + strcpy(id->type_version, "High Sierra"); goto found; + } + return -1; found: