Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
Sven-Göran Bergh | 3b45801 | 2013-07-31 15:45:20 +0200 | [diff] [blame] | 21 | //kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_ISO9660) += iso9660.o |
| 22 | |
Sven-Göran Bergh | 15d0a86 | 2013-07-31 15:57:59 +0200 | [diff] [blame] | 23 | //config: |
| 24 | //config:config FEATURE_VOLUMEID_ISO9660 |
| 25 | //config: bool "iso9660 filesystem" |
| 26 | //config: default y |
| 27 | //config: depends on VOLUMEID |
| 28 | //config: help |
| 29 | //config: TODO |
| 30 | //config: |
| 31 | |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 32 | #include "volume_id_internal.h" |
| 33 | |
| 34 | #define ISO_SUPERBLOCK_OFFSET 0x8000 |
| 35 | #define ISO_SECTOR_SIZE 0x800 |
| 36 | #define ISO_VD_OFFSET (ISO_SUPERBLOCK_OFFSET + ISO_SECTOR_SIZE) |
| 37 | #define ISO_VD_PRIMARY 0x1 |
| 38 | #define ISO_VD_SUPPLEMENTARY 0x2 |
| 39 | #define ISO_VD_END 0xff |
| 40 | #define ISO_VD_MAX 16 |
| 41 | |
| 42 | struct iso_volume_descriptor { |
| 43 | uint8_t vd_type; |
| 44 | uint8_t vd_id[5]; |
| 45 | uint8_t vd_version; |
| 46 | uint8_t flags; |
| 47 | uint8_t system_id[32]; |
| 48 | uint8_t volume_id[32]; |
| 49 | uint8_t unused[8]; |
| 50 | uint8_t space_size[8]; |
| 51 | uint8_t escape_sequences[8]; |
Denys Vlasenko | 8dc0e19 | 2009-09-16 00:58:11 +0200 | [diff] [blame] | 52 | } PACKED; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 53 | |
| 54 | struct high_sierra_volume_descriptor { |
| 55 | uint8_t foo[8]; |
| 56 | uint8_t type; |
| 57 | uint8_t id[4]; |
| 58 | uint8_t version; |
Denys Vlasenko | 8dc0e19 | 2009-09-16 00:58:11 +0200 | [diff] [blame] | 59 | } PACKED; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 60 | |
Denys Vlasenko | 8930096 | 2009-11-01 23:07:18 +0100 | [diff] [blame] | 61 | int FAST_FUNC volume_id_probe_iso9660(struct volume_id *id /*,uint64_t off*/) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 62 | { |
Denis Vlasenko | 28ea429 | 2009-02-15 05:51:19 +0000 | [diff] [blame] | 63 | #define off ((uint64_t)0) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 64 | uint8_t *buf; |
| 65 | struct iso_volume_descriptor *is; |
| 66 | struct high_sierra_volume_descriptor *hs; |
| 67 | |
| 68 | dbg("probing at offset 0x%llx", (unsigned long long) off); |
| 69 | |
| 70 | buf = volume_id_get_buffer(id, off + ISO_SUPERBLOCK_OFFSET, 0x200); |
| 71 | if (buf == NULL) |
| 72 | return -1; |
| 73 | |
| 74 | is = (struct iso_volume_descriptor *) buf; |
| 75 | |
| 76 | if (memcmp(is->vd_id, "CD001", 5) == 0) { |
| 77 | int vd_offset; |
| 78 | int i; |
| 79 | |
| 80 | dbg("read label from PVD"); |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 81 | // volume_id_set_label_raw(id, is->volume_id, 32); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 82 | volume_id_set_label_string(id, is->volume_id, 32); |
| 83 | |
| 84 | dbg("looking for SVDs"); |
| 85 | vd_offset = ISO_VD_OFFSET; |
| 86 | for (i = 0; i < ISO_VD_MAX; i++) { |
| 87 | uint8_t svd_label[64]; |
| 88 | |
| 89 | is = volume_id_get_buffer(id, off + vd_offset, 0x200); |
| 90 | if (is == NULL || is->vd_type == ISO_VD_END) |
| 91 | break; |
| 92 | if (is->vd_type != ISO_VD_SUPPLEMENTARY) |
| 93 | continue; |
| 94 | |
| 95 | dbg("found SVD at offset 0x%llx", (unsigned long long) (off + vd_offset)); |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 96 | if (memcmp(is->escape_sequences, "%/@", 3) == 0 |
| 97 | || memcmp(is->escape_sequences, "%/C", 3) == 0 |
| 98 | || memcmp(is->escape_sequences, "%/E", 3) == 0 |
| 99 | ) { |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 100 | dbg("Joliet extension found"); |
| 101 | volume_id_set_unicode16((char *)svd_label, sizeof(svd_label), is->volume_id, BE, 32); |
| 102 | if (memcmp(id->label, svd_label, 16) == 0) { |
| 103 | dbg("SVD label is identical, use the possibly longer PVD one"); |
| 104 | break; |
| 105 | } |
| 106 | |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 107 | // volume_id_set_label_raw(id, is->volume_id, 32); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 108 | volume_id_set_label_string(id, svd_label, 32); |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 109 | // strcpy(id->type_version, "Joliet Extension"); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 110 | goto found; |
| 111 | } |
| 112 | vd_offset += ISO_SECTOR_SIZE; |
| 113 | } |
| 114 | goto found; |
| 115 | } |
| 116 | |
| 117 | hs = (struct high_sierra_volume_descriptor *) buf; |
| 118 | |
| 119 | if (memcmp(hs->id, "CDROM", 5) == 0) { |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 120 | // strcpy(id->type_version, "High Sierra"); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 121 | goto found; |
| 122 | } |
| 123 | |
| 124 | return -1; |
| 125 | |
| 126 | found: |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 127 | // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); |
Denys Vlasenko | 90615a0 | 2010-12-30 00:40:11 +0100 | [diff] [blame] | 128 | IF_FEATURE_BLKID_TYPE(id->type = "iso9660";) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 129 | |
| 130 | return 0; |
| 131 | } |