2 * volume_id - reads filesystem label and uuid
4 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #include <asm/types.h>
37 #include "volume_id.h"
42 #define ISO_SUPERBLOCK_OFFSET 0x8000
43 #define ISO_SECTOR_SIZE 0x800
44 #define ISO_VD_OFFSET (ISO_SUPERBLOCK_OFFSET + ISO_SECTOR_SIZE)
45 #define ISO_VD_PRIMARY 0x1
46 #define ISO_VD_SUPPLEMENTARY 0x2
47 #define ISO_VD_END 0xff
50 struct iso_volume_descriptor {
59 __u8 escape_sequences[8];
60 } __attribute__((__packed__));
62 struct high_sierra_volume_descriptor {
67 } __attribute__((__packed__));
69 int volume_id_probe_iso9660(struct volume_id *id, __u64 off)
72 struct iso_volume_descriptor *is;
73 struct high_sierra_volume_descriptor *hs;
75 dbg("probing at offset 0x%llx", (unsigned long long) off);
77 buf = volume_id_get_buffer(id, off + ISO_SUPERBLOCK_OFFSET, 0x200);
81 is = (struct iso_volume_descriptor *) buf;
83 if (memcmp(is->vd_id, "CD001", 5) == 0) {
87 dbg("read label from PVD");
88 volume_id_set_label_raw(id, is->volume_id, 32);
89 volume_id_set_label_string(id, is->volume_id, 32);
91 dbg("looking for SVDs");
92 vd_offset = ISO_VD_OFFSET;
93 for (i = 0; i < ISO_VD_MAX; i++) {
96 is = (struct iso_volume_descriptor *) volume_id_get_buffer(id, off + vd_offset, 0x200);
97 if (is == NULL || is->vd_type == ISO_VD_END)
99 if (is->vd_type != ISO_VD_SUPPLEMENTARY)
102 dbg("found SVD at offset 0x%llx", (unsigned long long) (off + vd_offset));
103 if (memcmp(is->escape_sequences, "%/@", 3) == 0||
104 memcmp(is->escape_sequences, "%/C", 3) == 0||
105 memcmp(is->escape_sequences, "%/E", 3) == 0) {
106 dbg("Joliet extension found");
107 volume_id_set_unicode16(svd_label, sizeof(svd_label), is->volume_id, BE, 32);
108 if (memcmp(id->label, svd_label, 16) == 0) {
109 dbg("SVD label is identical, use the possibly longer PVD one");
113 volume_id_set_label_raw(id, is->volume_id, 32);
114 volume_id_set_label_string(id, svd_label, 32);
115 strcpy(id->type_version, "Joliet Extension");
118 vd_offset += ISO_SECTOR_SIZE;
123 hs = (struct high_sierra_volume_descriptor *) buf;
125 if (memcmp(hs->id, "CDROM", 5) == 0) {
126 strcpy(id->type_version, "High Sierra");
133 volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
134 id->type = "iso9660";