[34] | 1 | /* |
---|
| 2 | * ISO 9660 filesystem backend for GRUB (GRand Unified Bootloader) |
---|
| 3 | * including Rock Ridge Extensions support |
---|
| 4 | * |
---|
| 5 | * Copyright (C) 1998, 1999 Kousuke Takai <tak@kmc.kyoto-u.ac.jp> |
---|
| 6 | * |
---|
| 7 | * This program is free software; you can redistribute it and/or modify |
---|
| 8 | * it under the terms of the GNU General Public License as published by |
---|
| 9 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 10 | * (at your option) any later version. |
---|
| 11 | * |
---|
| 12 | * This program is distributed in the hope that it will be useful, |
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | * GNU General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License |
---|
| 18 | * along with this program; if not, write to the Free Software |
---|
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 20 | */ |
---|
| 21 | /* |
---|
| 22 | * References: |
---|
| 23 | * linux/fs/isofs/rock.[ch] |
---|
| 24 | * mkisofs-1.11.1/diag/isoinfo.c |
---|
| 25 | * mkisofs-1.11.1/iso9660.h |
---|
| 26 | * (all are written by Eric Youngdale) |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #ifndef _ISO9660_H_ |
---|
| 30 | #define _ISO9660_H_ |
---|
| 31 | |
---|
| 32 | #define ISO_SECTOR_BITS (11) |
---|
| 33 | #define ISO_SECTOR_SIZE (1<<ISO_SECTOR_BITS) |
---|
| 34 | |
---|
| 35 | #define ISO_REGULAR 1 /* regular file */ |
---|
| 36 | #define ISO_DIRECTORY 2 /* directory */ |
---|
| 37 | #define ISO_OTHER 0 /* other file (with Rock Ridge) */ |
---|
| 38 | |
---|
| 39 | #define RR_FLAG_PX 0x01 /* have POSIX file attributes */ |
---|
| 40 | #define RR_FLAG_PN 0x02 /* POSIX devices */ |
---|
| 41 | #define RR_FLAG_SL 0x04 /* Symbolic link */ |
---|
| 42 | #define RR_FLAG_NM 0x08 /* have alternate file name */ |
---|
| 43 | #define RR_FLAG_CL 0x10 /* Child link */ |
---|
| 44 | #define RR_FLAG_PL 0x20 /* Parent link */ |
---|
| 45 | #define RR_FLAG_RE 0x40 /* Relocation directory */ |
---|
| 46 | #define RR_FLAG_TF 0x80 /* Timestamps */ |
---|
| 47 | |
---|
| 48 | /* POSIX file attributes for Rock Ridge extensions */ |
---|
| 49 | #define POSIX_S_IFMT 0xF000 |
---|
| 50 | #define POSIX_S_IFREG 0x8000 |
---|
| 51 | #define POSIX_S_IFDIR 0x4000 |
---|
| 52 | |
---|
| 53 | /* volume descriptor types */ |
---|
| 54 | #define ISO_VD_PRIMARY 1 |
---|
| 55 | #define ISO_VD_END 255 |
---|
| 56 | |
---|
| 57 | #define ISO_STANDARD_ID "CD001" |
---|
| 58 | |
---|
| 59 | #ifndef ASM_FILE |
---|
| 60 | |
---|
| 61 | #ifndef __sun |
---|
| 62 | #ifndef __BIT_TYPES_DEFINED__ |
---|
| 63 | typedef int int8_t __attribute__((mode(QI))); |
---|
| 64 | typedef unsigned int u_int8_t __attribute__((mode(QI))); |
---|
| 65 | typedef int int16_t __attribute__((mode(HI))); |
---|
| 66 | typedef unsigned int u_int16_t __attribute__((mode(HI))); |
---|
| 67 | typedef int int32_t __attribute__((mode(SI))); |
---|
| 68 | typedef unsigned int u_int32_t __attribute__((mode(SI))); |
---|
| 69 | #endif |
---|
| 70 | #else |
---|
| 71 | #ifndef GRUB_UTIL |
---|
| 72 | typedef char int8_t; |
---|
| 73 | typedef short int16_t; |
---|
| 74 | typedef int int32_t; |
---|
| 75 | #endif /* ! GRUB_UTIL */ |
---|
| 76 | typedef unsigned char u_int8_t; |
---|
| 77 | typedef unsigned short u_int16_t; |
---|
| 78 | typedef unsigned int u_int32_t; |
---|
| 79 | #endif /* __sun */ |
---|
| 80 | |
---|
| 81 | typedef union { |
---|
| 82 | u_int8_t l,b; |
---|
| 83 | } iso_8bit_t; |
---|
| 84 | |
---|
| 85 | struct __iso_16bit { |
---|
| 86 | u_int16_t l, b; |
---|
| 87 | } __attribute__ ((packed)); |
---|
| 88 | typedef struct __iso_16bit iso_16bit_t; |
---|
| 89 | |
---|
| 90 | struct __iso_32bit { |
---|
| 91 | u_int32_t l, b; |
---|
| 92 | } __attribute__ ((packed)); |
---|
| 93 | typedef struct __iso_32bit iso_32bit_t; |
---|
| 94 | |
---|
| 95 | typedef u_int8_t iso_date_t[7]; |
---|
| 96 | |
---|
| 97 | struct iso_directory_record { |
---|
| 98 | iso_8bit_t length; |
---|
| 99 | iso_8bit_t ext_attr_length; |
---|
| 100 | iso_32bit_t extent; |
---|
| 101 | iso_32bit_t size; |
---|
| 102 | iso_date_t date; |
---|
| 103 | iso_8bit_t flags; |
---|
| 104 | iso_8bit_t file_unit_size; |
---|
| 105 | iso_8bit_t interleave; |
---|
| 106 | iso_16bit_t volume_seq_number; |
---|
| 107 | iso_8bit_t name_len; |
---|
| 108 | u_int8_t name[1]; |
---|
| 109 | } __attribute__ ((packed)); |
---|
| 110 | |
---|
| 111 | struct iso_primary_descriptor { |
---|
| 112 | iso_8bit_t type; |
---|
| 113 | u_int8_t id[5]; |
---|
| 114 | iso_8bit_t version; |
---|
| 115 | u_int8_t _unused1[1]; |
---|
| 116 | u_int8_t system_id[32]; |
---|
| 117 | u_int8_t volume_id[32]; |
---|
| 118 | u_int8_t _unused2[8]; |
---|
| 119 | iso_32bit_t volume_space_size; |
---|
| 120 | u_int8_t _unused3[32]; |
---|
| 121 | iso_16bit_t volume_set_size; |
---|
| 122 | iso_16bit_t volume_seq_number; |
---|
| 123 | iso_16bit_t logical_block_size; |
---|
| 124 | iso_32bit_t path_table_size; |
---|
| 125 | u_int8_t type_l_path_table[4]; |
---|
| 126 | u_int8_t opt_type_l_path_table[4]; |
---|
| 127 | u_int8_t type_m_path_table[4]; |
---|
| 128 | u_int8_t opt_type_m_path_table[4]; |
---|
| 129 | struct iso_directory_record root_directory_record; |
---|
| 130 | u_int8_t volume_set_id[128]; |
---|
| 131 | u_int8_t publisher_id[128]; |
---|
| 132 | u_int8_t preparer_id[128]; |
---|
| 133 | u_int8_t application_id[128]; |
---|
| 134 | u_int8_t copyright_file_id[37]; |
---|
| 135 | u_int8_t abstract_file_id[37]; |
---|
| 136 | u_int8_t bibliographic_file_id[37]; |
---|
| 137 | u_int8_t creation_date[17]; |
---|
| 138 | u_int8_t modification_date[17]; |
---|
| 139 | u_int8_t expiration_date[17]; |
---|
| 140 | u_int8_t effective_date[17]; |
---|
| 141 | iso_8bit_t file_structure_version; |
---|
| 142 | u_int8_t _unused4[1]; |
---|
| 143 | u_int8_t application_data[512]; |
---|
| 144 | u_int8_t _unused5[653]; |
---|
| 145 | } __attribute__ ((packed)); |
---|
| 146 | |
---|
| 147 | struct rock_ridge { |
---|
| 148 | u_int16_t signature; |
---|
| 149 | u_int8_t len; |
---|
| 150 | u_int8_t version; |
---|
| 151 | union { |
---|
| 152 | struct SP { |
---|
| 153 | u_int16_t magic; |
---|
| 154 | u_int8_t skip; |
---|
| 155 | } sp; |
---|
| 156 | struct CE { |
---|
| 157 | iso_32bit_t extent; |
---|
| 158 | iso_32bit_t offset; |
---|
| 159 | iso_32bit_t size; |
---|
| 160 | } ce; |
---|
| 161 | struct ER { |
---|
| 162 | u_int8_t len_id; |
---|
| 163 | u_int8_t len_des; |
---|
| 164 | u_int8_t len_src; |
---|
| 165 | u_int8_t ext_ver; |
---|
| 166 | u_int8_t data[0]; |
---|
| 167 | } er; |
---|
| 168 | struct RR { |
---|
| 169 | iso_8bit_t flags; |
---|
| 170 | } rr; |
---|
| 171 | struct PX { |
---|
| 172 | iso_32bit_t mode; |
---|
| 173 | iso_32bit_t nlink; |
---|
| 174 | iso_32bit_t uid; |
---|
| 175 | iso_32bit_t gid; |
---|
| 176 | } px; |
---|
| 177 | struct PN { |
---|
| 178 | iso_32bit_t dev_high; |
---|
| 179 | iso_32bit_t dev_low; |
---|
| 180 | } pn; |
---|
| 181 | struct SL { |
---|
| 182 | iso_8bit_t flags; |
---|
| 183 | struct SL_component { |
---|
| 184 | iso_8bit_t flags; |
---|
| 185 | u_int8_t len; |
---|
| 186 | u_int8_t text[0]; |
---|
| 187 | } link; |
---|
| 188 | } sl; |
---|
| 189 | struct NM { |
---|
| 190 | iso_8bit_t flags; |
---|
| 191 | u_int8_t name[0]; |
---|
| 192 | } nm; |
---|
| 193 | struct CL { |
---|
| 194 | iso_32bit_t location; |
---|
| 195 | } cl; |
---|
| 196 | struct PL { |
---|
| 197 | iso_32bit_t location; |
---|
| 198 | } pl; |
---|
| 199 | struct TF { |
---|
| 200 | iso_8bit_t flags; |
---|
| 201 | iso_date_t times[0]; |
---|
| 202 | } tf; |
---|
| 203 | } u; |
---|
| 204 | } __attribute__ ((packed)); |
---|
| 205 | |
---|
| 206 | typedef union RR_ptr { |
---|
| 207 | struct rock_ridge *rr; |
---|
| 208 | char *ptr; |
---|
| 209 | int i; |
---|
| 210 | } RR_ptr_t; |
---|
| 211 | |
---|
| 212 | #define RRMAGIC(c1, c2) ((c1)|(c2) << 8) |
---|
| 213 | |
---|
| 214 | #define CHECK2(ptr, c1, c2) \ |
---|
| 215 | (*(unsigned short *)(ptr) == (((c1) | (c2) << 8) & 0xFFFF)) |
---|
| 216 | |
---|
| 217 | #endif /* !ASM_FILE */ |
---|
| 218 | |
---|
| 219 | #endif /* _ISO9660_H_ */ |
---|