blob: c771b01f5524d62a3cefffe20a52a11ab897d859 [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 */
Sven-Göran Bergh15d0a862013-07-31 15:57:59 +020020//config:config FEATURE_VOLUMEID_ISO9660
21//config: bool "iso9660 filesystem"
22//config: default y
23//config: depends on VOLUMEID
Sven-Göran Bergh15d0a862013-07-31 15:57:59 +020024
Denys Vlasenko0c4dbd42017-09-18 16:28:43 +020025//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_ISO9660) += iso9660.o
26
Denis Vlasenkode7684a2008-02-18 21:08:49 +000027#include "volume_id_internal.h"
28
29#define ISO_SUPERBLOCK_OFFSET 0x8000
30#define ISO_SECTOR_SIZE 0x800
31#define ISO_VD_OFFSET (ISO_SUPERBLOCK_OFFSET + ISO_SECTOR_SIZE)
32#define ISO_VD_PRIMARY 0x1
33#define ISO_VD_SUPPLEMENTARY 0x2
34#define ISO_VD_END 0xff
35#define ISO_VD_MAX 16
36
37struct iso_volume_descriptor {
38 uint8_t vd_type;
39 uint8_t vd_id[5];
40 uint8_t vd_version;
41 uint8_t flags;
42 uint8_t system_id[32];
43 uint8_t volume_id[32];
44 uint8_t unused[8];
45 uint8_t space_size[8];
46 uint8_t escape_sequences[8];
Denys Vlasenko8dc0e192009-09-16 00:58:11 +020047} PACKED;
Denis Vlasenkode7684a2008-02-18 21:08:49 +000048
49struct high_sierra_volume_descriptor {
50 uint8_t foo[8];
51 uint8_t type;
52 uint8_t id[4];
53 uint8_t version;
Denys Vlasenko8dc0e192009-09-16 00:58:11 +020054} PACKED;
Denis Vlasenkode7684a2008-02-18 21:08:49 +000055
Denys Vlasenko89300962009-11-01 23:07:18 +010056int FAST_FUNC volume_id_probe_iso9660(struct volume_id *id /*,uint64_t off*/)
Denis Vlasenkode7684a2008-02-18 21:08:49 +000057{
Denis Vlasenko28ea4292009-02-15 05:51:19 +000058#define off ((uint64_t)0)
Denis Vlasenkode7684a2008-02-18 21:08:49 +000059 uint8_t *buf;
60 struct iso_volume_descriptor *is;
61 struct high_sierra_volume_descriptor *hs;
62
63 dbg("probing at offset 0x%llx", (unsigned long long) off);
64
65 buf = volume_id_get_buffer(id, off + ISO_SUPERBLOCK_OFFSET, 0x200);
66 if (buf == NULL)
67 return -1;
68
69 is = (struct iso_volume_descriptor *) buf;
70
71 if (memcmp(is->vd_id, "CD001", 5) == 0) {
72 int vd_offset;
73 int i;
74
75 dbg("read label from PVD");
Denis Vlasenkoc5b73722008-03-17 09:21:26 +000076// volume_id_set_label_raw(id, is->volume_id, 32);
Denis Vlasenkode7684a2008-02-18 21:08:49 +000077 volume_id_set_label_string(id, is->volume_id, 32);
78
79 dbg("looking for SVDs");
80 vd_offset = ISO_VD_OFFSET;
81 for (i = 0; i < ISO_VD_MAX; i++) {
82 uint8_t svd_label[64];
83
84 is = volume_id_get_buffer(id, off + vd_offset, 0x200);
85 if (is == NULL || is->vd_type == ISO_VD_END)
86 break;
87 if (is->vd_type != ISO_VD_SUPPLEMENTARY)
88 continue;
89
90 dbg("found SVD at offset 0x%llx", (unsigned long long) (off + vd_offset));
Denis Vlasenkoc5b73722008-03-17 09:21:26 +000091 if (memcmp(is->escape_sequences, "%/@", 3) == 0
92 || memcmp(is->escape_sequences, "%/C", 3) == 0
93 || memcmp(is->escape_sequences, "%/E", 3) == 0
94 ) {
Denis Vlasenkode7684a2008-02-18 21:08:49 +000095 dbg("Joliet extension found");
96 volume_id_set_unicode16((char *)svd_label, sizeof(svd_label), is->volume_id, BE, 32);
97 if (memcmp(id->label, svd_label, 16) == 0) {
98 dbg("SVD label is identical, use the possibly longer PVD one");
99 break;
100 }
101
Denis Vlasenkoc5b73722008-03-17 09:21:26 +0000102// volume_id_set_label_raw(id, is->volume_id, 32);
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000103 volume_id_set_label_string(id, svd_label, 32);
Denis Vlasenkoc5b73722008-03-17 09:21:26 +0000104// strcpy(id->type_version, "Joliet Extension");
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000105 goto found;
106 }
107 vd_offset += ISO_SECTOR_SIZE;
108 }
109 goto found;
110 }
111
112 hs = (struct high_sierra_volume_descriptor *) buf;
113
114 if (memcmp(hs->id, "CDROM", 5) == 0) {
Denis Vlasenkoc5b73722008-03-17 09:21:26 +0000115// strcpy(id->type_version, "High Sierra");
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000116 goto found;
117 }
118
119 return -1;
120
121 found:
Denis Vlasenkoc5b73722008-03-17 09:21:26 +0000122// volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
Denys Vlasenko90615a02010-12-30 00:40:11 +0100123 IF_FEATURE_BLKID_TYPE(id->type = "iso9660";)
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000124
125 return 0;
126}