From dbfa44db9cb2674e590c8c9d7bad2feace93fd44 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Fri, 27 Dec 2019 19:52:17 -0500 Subject: iso_9660_parse_ph --- src/kernel/files.c | 6 ++--- src/kernel/iso9660.c | 37 +++++++++++++++++++++++++++-- src/kernel/iso9660.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 102 insertions(+), 7 deletions(-) (limited to 'src/kernel') diff --git a/src/kernel/files.c b/src/kernel/files.c index 8064518..9747688 100644 --- a/src/kernel/files.c +++ b/src/kernel/files.c @@ -27,7 +27,7 @@ bool (*const parse_pts[N_PT_FORMATS])(uint8_t dn, uint8_t *buffer) = { //&mbr_parse_pt }; -bool (*const parse_phs[N_FS_FORMATS])(uint8_t dn, uint32_t sector, uint8_t *buffer) = { +bool (*const parse_phs[N_FS_FORMATS])(uint8_t dn, uint8_t pn, uint32_t sector, uint8_t *buffer) = { &iso_9660_parse_ph }; @@ -90,7 +90,7 @@ void detect_disk_parts(uint8_t drive) { update_status(dn); if (drives[dn].flags & (PRESENT | DISK_IN)) { /*ISO 9660 often comes with a dummy MBR*/ - if (iso_9660_parse_ph(dn, 0, buffer)) { + if (iso_9660_parse_ph(dn, 0, 0, buffer)) { part_info[dn].format = DIRECT; part_info[dn].n_partitions = 1; return; @@ -99,7 +99,7 @@ void detect_disk_parts(uint8_t drive) { if (parse_pts[ptt](dn, buffer)) return; for (uint8_t fst = 0; fst < N_FS_FORMATS; ++fst) - if (parse_phs[fst](dn, 0, buffer)) { + if (parse_phs[fst](dn, 0, 0, buffer)) { part_info[dn].format = DIRECT; part_info[dn].n_partitions = 1; return; diff --git a/src/kernel/iso9660.c b/src/kernel/iso9660.c index a1821e8..742b34b 100644 --- a/src/kernel/iso9660.c +++ b/src/kernel/iso9660.c @@ -18,7 +18,40 @@ OF THIS SOFTWARE. */ #include "iso9660.h" +#include "diskio.h" +#include "files.h" +#include "mem.h" -bool iso_9660_parse_ph(uint8_t dn, uint32_t sector, uint8_t *buffer) { - //TODO +bool iso_9660_parse_ph(uint8_t dn, uint8_t pn, uint32_t sector, uint8_t *buffer) { + uint32_t s = sector + 64; + do { + read_sectors(dn, s, 4, buffer); + if ((*buffer == 255) || (*(uint32_t *)&buffer[1] != 0x30304443) || + (buffer[5] != (uint8_t)'1')) + return false; + s += 4; + } while (*buffer != PRIM_VOLUME); + part_info[dn].partition_types[pn] = ISO_9660; + part_info[dn].partition_offsets[pn] = sector; + struct iso_9660_cache *cache = allocate_block(sizeof(struct iso_9660_cache), KERNEL); + struct iso_9660_primary_vd *as_vd = (struct iso_9660_primary_vd *)buffer; + part_info[dn].partition_cache[pn] = cache; + if ((cache->block_size = as_vd->block_size) & ~0x01ff) { + part_info[dn].partition_sizes[pn] = + (as_vd->block_size >> 9) * as_vd->size; + cache->path_table_sector = + (as_vd->block_size >> 9) * as_vd->path_table_block; + cache->optional_path_table_sector = + (as_vd->block_size >> 9) * as_vd->optional_path_table_block; + } + else { + part_info[dn].partition_sizes[pn] = + (as_vd->block_size * as_vd->size) >> 9; + cache->path_table_sector = + (as_vd->block_size * as_vd->path_table_block) >> 9; + cache->optional_path_table_sector = + (as_vd->block_size * as_vd->optional_path_table_block) >> 9; + } + cache->path_table_size = as_vd->path_table_size; + return true; } \ No newline at end of file diff --git a/src/kernel/iso9660.h b/src/kernel/iso9660.h index 8267d0d..271e5e0 100644 --- a/src/kernel/iso9660.h +++ b/src/kernel/iso9660.h @@ -23,12 +23,74 @@ OF THIS SOFTWARE. #ifndef ISO9660_H #define ISO9660_H -struct iso_9660_volume_descriptor_start { +enum iso_9660_vd_type { + BOOT_RECORD = 0, + PRIM_VOLUME = 1, + SUPP_VOLUME = 2, + PARTITION = 3 +}; + +struct iso_9660_timecode { + uint8_t year[4]; + uint8_t month[2]; + uint8_t day[2]; + uint8_t hour[2]; + uint8_t minute[2]; + uint8_t second[2]; + uint8_t centisecond[2]; + uint8_t tzone;//0 = -12, 100 = +13 +} __attribute__ ((__packed__)); + +struct iso_9660_directory { + uint8_t filler[34];//TODO +} __attribute__ ((__packed__)); + +struct iso_9660_primary_vd { uint8_t type; uint8_t id[5]; uint8_t version; + uint8_t spacing; + uint8_t system_id[32]; + uint8_t volume_id[32]; + uint64_t spacing2; + uint32_t size;//in blocks + uint32_t size_be; + uint64_t spacing3[4]; + uint16_t set_size; + uint16_t set_size_be; + uint16_t set_index; + uint16_t set_index_be; + uint16_t block_size; + uint16_t block_size_be; + uint32_t path_table_size; + uint32_t path_table_size_be; + uint32_t path_table_block; + uint32_t optional_path_table_block; + uint32_t path_table_block_be; + uint32_t optional_path_table_block_be; + struct iso_9660_directory root_directory; + uint8_t set_name[128]; + uint8_t publisher[128]; + uint8_t data_preparer[128]; + uint8_t application[128]; + uint8_t copyright_file[38]; + uint8_t abstract_file[36]; + uint8_t bibliography_file[37]; + struct iso_9660_timecode created; + struct iso_9660_timecode modified; + struct iso_9660_timecode expires; + struct iso_9660_timecode effective; + uint8_t directory_format_version; } __attribute__ ((__packed__)); -bool iso_9660_parse_ph(uint8_t dn, uint32_t sector, uint8_t *buffer); +struct iso_9660_cache { + uint16_t block_size; + struct iso_9660_directory root_directory; + uint32_t path_table_size; + uint32_t path_table_sector; + uint32_t optional_path_table_sector; +}; + +bool iso_9660_parse_ph(uint8_t dn, uint8_t pn, uint32_t sector, uint8_t *buffer); #endif \ No newline at end of file -- cgit v1.2.3