blob: 82f5e4846070c266b37c47c9adc931386767a712 [file] [log] [blame]
Denis Vlasenkode7684a2008-02-18 21:08:49 +00001/*
2 * volume_id - reads filesystem label and uuid
3 *
4 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include "volume_id_internal.h"
22
23#define ISO_SUPERBLOCK_OFFSET 0x8000
24#define ISO_SECTOR_SIZE 0x800
25#define ISO_VD_OFFSET (ISO_SUPERBLOCK_OFFSET + ISO_SECTOR_SIZE)
26#define ISO_VD_PRIMARY 0x1
27#define ISO_VD_SUPPLEMENTARY 0x2
28#define ISO_VD_END 0xff
29#define ISO_VD_MAX 16
30
31struct iso_volume_descriptor {
32 uint8_t vd_type;
33 uint8_t vd_id[5];
34 uint8_t vd_version;
35 uint8_t flags;
36 uint8_t system_id[32];
37 uint8_t volume_id[32];
38 uint8_t unused[8];
39 uint8_t space_size[8];
40 uint8_t escape_sequences[8];
41} __attribute__((__packed__));
42
43struct high_sierra_volume_descriptor {
44 uint8_t foo[8];
45 uint8_t type;
46 uint8_t id[4];
47 uint8_t version;
48} __attribute__((__packed__));
49
Denis Vlasenko28ea4292009-02-15 05:51:19 +000050int volume_id_probe_iso9660(struct volume_id *id /*,uint64_t off*/)
Denis Vlasenkode7684a2008-02-18 21:08:49 +000051{
Denis Vlasenko28ea4292009-02-15 05:51:19 +000052#define off ((uint64_t)0)
Denis Vlasenkode7684a2008-02-18 21:08:49 +000053 uint8_t *buf;
54 struct iso_volume_descriptor *is;
55 struct high_sierra_volume_descriptor *hs;
56
57 dbg("probing at offset 0x%llx", (unsigned long long) off);
58
59 buf = volume_id_get_buffer(id, off + ISO_SUPERBLOCK_OFFSET, 0x200);
60 if (buf == NULL)
61 return -1;
62
63 is = (struct iso_volume_descriptor *) buf;
64
65 if (memcmp(is->vd_id, "CD001", 5) == 0) {
66 int vd_offset;
67 int i;
68
69 dbg("read label from PVD");
Denis Vlasenkoc5b73722008-03-17 09:21:26 +000070// volume_id_set_label_raw(id, is->volume_id, 32);
Denis Vlasenkode7684a2008-02-18 21:08:49 +000071 volume_id_set_label_string(id, is->volume_id, 32);
72
73 dbg("looking for SVDs");
74 vd_offset = ISO_VD_OFFSET;
75 for (i = 0; i < ISO_VD_MAX; i++) {
76 uint8_t svd_label[64];
77
78 is = volume_id_get_buffer(id, off + vd_offset, 0x200);
79 if (is == NULL || is->vd_type == ISO_VD_END)
80 break;
81 if (is->vd_type != ISO_VD_SUPPLEMENTARY)
82 continue;
83
84 dbg("found SVD at offset 0x%llx", (unsigned long long) (off + vd_offset));
Denis Vlasenkoc5b73722008-03-17 09:21:26 +000085 if (memcmp(is->escape_sequences, "%/@", 3) == 0
86 || memcmp(is->escape_sequences, "%/C", 3) == 0
87 || memcmp(is->escape_sequences, "%/E", 3) == 0
88 ) {
Denis Vlasenkode7684a2008-02-18 21:08:49 +000089 dbg("Joliet extension found");
90 volume_id_set_unicode16((char *)svd_label, sizeof(svd_label), is->volume_id, BE, 32);
91 if (memcmp(id->label, svd_label, 16) == 0) {
92 dbg("SVD label is identical, use the possibly longer PVD one");
93 break;
94 }
95
Denis Vlasenkoc5b73722008-03-17 09:21:26 +000096// volume_id_set_label_raw(id, is->volume_id, 32);
Denis Vlasenkode7684a2008-02-18 21:08:49 +000097 volume_id_set_label_string(id, svd_label, 32);
Denis Vlasenkoc5b73722008-03-17 09:21:26 +000098// strcpy(id->type_version, "Joliet Extension");
Denis Vlasenkode7684a2008-02-18 21:08:49 +000099 goto found;
100 }
101 vd_offset += ISO_SECTOR_SIZE;
102 }
103 goto found;
104 }
105
106 hs = (struct high_sierra_volume_descriptor *) buf;
107
108 if (memcmp(hs->id, "CDROM", 5) == 0) {
Denis Vlasenkoc5b73722008-03-17 09:21:26 +0000109// strcpy(id->type_version, "High Sierra");
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000110 goto found;
111 }
112
113 return -1;
114
115 found:
Denis Vlasenkoc5b73722008-03-17 09:21:26 +0000116// volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
117// id->type = "iso9660";
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000118
119 return 0;
120}