| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "shared-forward.h" |
| 5 |
#include "sparse-endian.h" |
| 6 |
|
| 7 |
/* ISO9660 is 5 blocks: |
| 8 |
* - Primary descriptor |
| 9 |
* - El torito descriptor |
| 10 |
* - Terminal descriptor |
| 11 |
* - El Torito boot catalog |
| 12 |
* - Root directory |
| 13 |
*/ |
| 14 |
#define ISO9660_BLOCK_SIZE 2048U |
| 15 |
#define ISO9660_START 16U |
| 16 |
#define ISO9660_PRIMARY_DESCRIPTOR (ISO9660_START+0U) |
| 17 |
#define ISO9660_ELTORITO_DESCRIPTOR (ISO9660_START+1U) |
| 18 |
#define ISO9660_TERMINAL_DESCRIPTOR (ISO9660_START+2U) |
| 19 |
#define ISO9660_BOOT_CATALOG (ISO9660_START+3U) |
| 20 |
#define ISO9660_ROOT_DIRECTORY (ISO9660_START+4U) |
| 21 |
#define ISO9660_SIZE 5U |
| 22 |
|
| 23 |
struct _packed_ iso9660_volume_descriptor_header { |
| 24 |
uint8_t type; |
| 25 |
char identifier[5]; |
| 26 |
uint8_t version; |
| 27 |
}; |
| 28 |
|
| 29 |
struct _packed_ iso9660_terminal_descriptor { |
| 30 |
struct iso9660_volume_descriptor_header header; |
| 31 |
uint8_t data[2041]; |
| 32 |
}; |
| 33 |
assert_cc(sizeof(struct iso9660_terminal_descriptor) == 2048); |
| 34 |
|
| 35 |
struct _packed_ iso9660_datetime { |
| 36 |
char year[4]; |
| 37 |
char month[2]; |
| 38 |
char day[2]; |
| 39 |
char hour[2]; |
| 40 |
char minute[2]; |
| 41 |
char second[2]; |
| 42 |
char deci[2]; |
| 43 |
int8_t zone; |
| 44 |
}; |
| 45 |
|
| 46 |
struct _packed_ iso9660_eltorito_descriptor { |
| 47 |
struct iso9660_volume_descriptor_header header; |
| 48 |
|
| 49 |
char boot_system_identifier[32]; |
| 50 |
uint8_t unused_1[32]; |
| 51 |
le32_t boot_catalog_sector; |
| 52 |
uint8_t unused_2[1973]; |
| 53 |
}; |
| 54 |
|
| 55 |
assert_cc(sizeof(struct iso9660_eltorito_descriptor) == 2048); |
| 56 |
|
| 57 |
struct _packed_ iso9660_dir_time { |
| 58 |
uint8_t year; |
| 59 |
uint8_t month; |
| 60 |
uint8_t day; |
| 61 |
uint8_t hour; |
| 62 |
uint8_t minute; |
| 63 |
uint8_t second; |
| 64 |
int8_t offset; |
| 65 |
}; |
| 66 |
|
| 67 |
struct _packed_ iso9660_directory_entry { |
| 68 |
uint8_t len; |
| 69 |
uint8_t xattr_len; |
| 70 |
le32_t extent_loc_little; |
| 71 |
be32_t extent_loc_big; |
| 72 |
le32_t data_len_little; |
| 73 |
be32_t data_len_big; |
| 74 |
struct iso9660_dir_time time; |
| 75 |
uint8_t flags; |
| 76 |
uint8_t unit_size; |
| 77 |
uint8_t gap_size; |
| 78 |
le16_t volume_seq_num_little; |
| 79 |
be16_t volume_seq_num_big; |
| 80 |
uint8_t ident_len; |
| 81 |
char ident[1]; /* variable */ |
| 82 |
}; |
| 83 |
|
| 84 |
struct _packed_ iso9660_primary_volume_descriptor { |
| 85 |
struct iso9660_volume_descriptor_header header; |
| 86 |
|
| 87 |
uint8_t unused_1; |
| 88 |
char system_identifier[32]; |
| 89 |
char volume_identifier[32]; |
| 90 |
uint8_t unused_2[8]; |
| 91 |
le32_t volume_space_size_little; |
| 92 |
be32_t volume_space_size_big; |
| 93 |
uint8_t unused_3[32]; |
| 94 |
|
| 95 |
le16_t volume_set_size_little; |
| 96 |
be16_t volume_set_size_big; |
| 97 |
le16_t volume_sequence_number_little; |
| 98 |
be16_t volume_sequence_number_big; |
| 99 |
le16_t logical_block_size_little; |
| 100 |
be16_t logical_block_size_big; |
| 101 |
|
| 102 |
le32_t path_table_size_little; |
| 103 |
be32_t path_table_size_big; |
| 104 |
|
| 105 |
le32_t path_table_little; |
| 106 |
le32_t opt_path_table_little; |
| 107 |
|
| 108 |
be32_t path_table_big; |
| 109 |
be32_t opt_path_table_big; |
| 110 |
|
| 111 |
struct iso9660_directory_entry root_directory_entry; |
| 112 |
|
| 113 |
char volume_set_identifier[128]; |
| 114 |
char publisher_identifier[128]; |
| 115 |
char data_preparer_identifier[128]; |
| 116 |
char application_identifier[128]; |
| 117 |
|
| 118 |
char copyright_file_identifier[37]; |
| 119 |
char abstract_file_identifier[37]; |
| 120 |
char bibliographic_file_identifier[37]; |
| 121 |
|
| 122 |
struct iso9660_datetime volume_creation_date; |
| 123 |
struct iso9660_datetime volume_modification_date; |
| 124 |
struct iso9660_datetime volume_expiration_date; |
| 125 |
struct iso9660_datetime volume_effective_date; |
| 126 |
|
| 127 |
uint8_t file_structure_version; /* 1 */ |
| 128 |
uint8_t unused_5; |
| 129 |
char application_used[512]; |
| 130 |
uint8_t reserved[653]; |
| 131 |
}; |
| 132 |
assert_cc(sizeof(struct iso9660_primary_volume_descriptor) == 2048); |
| 133 |
|
| 134 |
struct _packed_ el_torito_validation_entry { |
| 135 |
uint8_t header_indicator; |
| 136 |
uint8_t platform; |
| 137 |
uint8_t reserved[2]; |
| 138 |
char id_string[24]; |
| 139 |
le16_t checksum; |
| 140 |
uint8_t key_bytes[2]; |
| 141 |
}; |
| 142 |
|
| 143 |
struct _packed_ el_torito_initial_entry { |
| 144 |
uint8_t boot_indicator; |
| 145 |
uint8_t boot_media_type; |
| 146 |
le16_t load_segment; |
| 147 |
uint8_t system_type; |
| 148 |
uint8_t unused_1[1]; |
| 149 |
le16_t sector_count; |
| 150 |
le32_t load_rba; |
| 151 |
uint8_t unused_2[20]; |
| 152 |
}; |
| 153 |
|
| 154 |
struct _packed_ el_torito_section_header { |
| 155 |
uint8_t header_indicator; |
| 156 |
uint8_t platform; |
| 157 |
le16_t nentries; |
| 158 |
char id_string[28]; |
| 159 |
}; |
| 160 |
|
| 161 |
void iso9660_datetime_zero(struct iso9660_datetime *ret); |
| 162 |
int iso9660_datetime_from_usec(usec_t usec, bool utc, struct iso9660_datetime *ret); |
| 163 |
int iso9660_dir_datetime_from_usec(usec_t usec, bool utc, struct iso9660_dir_time *ret); |
| 164 |
int iso9660_set_string(char target[], size_t len, const char *source, bool allow_a_chars); |
| 165 |
|
| 166 |
static inline void iso9660_set_const_string(char target[], size_t len, const char *source, bool allow_a_chars) { |
| 167 |
assert_se(iso9660_set_string(target, len, source, allow_a_chars) == 0); |
| 168 |
} |
| 169 |
|
| 170 |
bool iso9660_volume_name_valid(const char *name); |
| 171 |
bool iso9660_system_name_valid(const char *name); |
| 172 |
bool iso9660_publisher_name_valid(const char *name); |