From 7c7fd36bea1eac4d0fa7bd628a53fff7d2e60917 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Fri, 27 Dec 2019 18:49:11 -0500 Subject: doing iso9660 before gpt, making partition detection expandable --- src/kernel/files.c | 39 ++++++++++++++++++++++++++++++++------- src/kernel/files.h | 11 ++++++++--- src/kernel/gpt.c | 8 ++++---- src/kernel/iso9660.c | 24 ++++++++++++++++++++++++ src/kernel/iso9660.h | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 102 insertions(+), 14 deletions(-) create mode 100644 src/kernel/iso9660.c create mode 100644 src/kernel/iso9660.h (limited to 'src') diff --git a/src/kernel/files.c b/src/kernel/files.c index b8a9061..8064518 100644 --- a/src/kernel/files.c +++ b/src/kernel/files.c @@ -19,11 +19,21 @@ OF THIS SOFTWARE. #include "files.h" #include "diskio.h" -#include "gpt.h" +#include "iso9660.h" +#include "mem.h" + +bool (*const parse_pts[N_PT_FORMATS])(uint8_t dn, uint8_t *buffer) = { + //&gpt_parse_pt, + //&mbr_parse_pt +}; + +bool (*const parse_phs[N_FS_FORMATS])(uint8_t dn, uint32_t sector, uint8_t *buffer) = { + &iso_9660_parse_ph +}; uint8_t working_drive; uint8_t working_part; -uint8_t buffer[1024]; +uint8_t buffer[2048]; void set_working_drive(uint8_t name, uint8_t part) { if ((name >= (uint8_t)'a') && (name <= (uint8_t)'z') && @@ -74,13 +84,28 @@ uint32_t read_line_file(uint16_t handle, uint32_t max, void *buffer) { void detect_disk_parts(uint8_t drive) { if ((drive >= (uint8_t)'a') && (drive <= (uint8_t)'z')) { uint8_t dn = (drive & 0x1f) - 1; + for (uint8_t i = 0; i < part_info[dn].n_partitions; ++i) + if (part_info[dn].partition_cache[i]) + deallocate_block(part_info[dn].partition_cache[i]); update_status(dn); if (drives[dn].flags & (PRESENT | DISK_IN)) { - read_sectors(dn, 0, 2, buffer); - if ((*(uint32_t *)&buffer[0x200] == 0x20494645) &&//EFI - (*(uint32_t *)&buffer[0x204] == 0x54524150)) //PART - part_info[dn].format = gpt_parse_pt(dn, buffer) ? GPT : UNKNOWN; - ; + /*ISO 9660 often comes with a dummy MBR*/ + if (iso_9660_parse_ph(dn, 0, buffer)) { + part_info[dn].format = DIRECT; + part_info[dn].n_partitions = 1; + return; + } + for (uint8_t ptt = 0; ptt < N_PT_FORMATS; ++ptt) + if (parse_pts[ptt](dn, buffer)) + return; + for (uint8_t fst = 0; fst < N_FS_FORMATS; ++fst) + if (parse_phs[fst](dn, 0, buffer)) { + part_info[dn].format = DIRECT; + part_info[dn].n_partitions = 1; + return; + } + part_info[dn].format = UNKNOWN; + part_info[dn].n_partitions = 0; } else { part_info[dn].format = NOT_PRESENT; diff --git a/src/kernel/files.h b/src/kernel/files.h index f199306..0a11a71 100644 --- a/src/kernel/files.h +++ b/src/kernel/files.h @@ -30,17 +30,22 @@ struct file_info { }; enum fs_format { - ISO9660 + ISO_9660 = 0 }; +#define N_FS_FORMATS 1 + enum pt_format { NOT_PRESENT = 0, UNKNOWN = 1, DIRECT = 2, - MBR = 3, - GPT = 4 + + //GPT = 3, + //MBR = 4, }; +#define N_PT_FORMATS 0 + struct drive_parts { uint8_t format; uint8_t n_partitions; diff --git a/src/kernel/gpt.c b/src/kernel/gpt.c index 32185eb..39add3a 100644 --- a/src/kernel/gpt.c +++ b/src/kernel/gpt.c @@ -29,10 +29,10 @@ bool gpt_parse_pt(uint8_t dn, uint8_t *buffer) { uint32_t part_entry_size = head->part_size; struct gpt_entry *as_entries = (struct gpt_entry *)buffer; for (uint8_t i = 0; i < pi->n_partitions; ++i) { - if (!(i % 8)) - read_sectors(dn, 2 + i / 4, 2, buffer); - pi->partition_sizes[i] = ((as_entries[i % 8].last_sector + 1) >> 1) - (pi->partition_offsets[i] = ((as_entries[i % 8].sector) >> 1)); - switch (as_entries[i % 8].id.le) { + if (!(i % 16)) + read_sectors(dn, 2 + i / 4, 4, buffer); + pi->partition_sizes[i] = ((as_entries[i % 16].last_sector + 1) >> 1) - (pi->partition_offsets[i] = ((as_entries[i % 16].sector) >> 1)); + switch (as_entries[i % 16].id.le) { //TODO } } diff --git a/src/kernel/iso9660.c b/src/kernel/iso9660.c new file mode 100644 index 0000000..a1821e8 --- /dev/null +++ b/src/kernel/iso9660.c @@ -0,0 +1,24 @@ +/* +Copyright 2019 Benji Dial + +Permission to use, copy, modify, and/or distribute this +software for any purpose with or without fee is hereby +granted, provided that the above copyright notice and this +permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS +ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO +EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER +RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +OF THIS SOFTWARE. +*/ + +#include "iso9660.h" + +bool iso_9660_parse_ph(uint8_t dn, uint32_t sector, uint8_t *buffer) { + //TODO +} \ No newline at end of file diff --git a/src/kernel/iso9660.h b/src/kernel/iso9660.h new file mode 100644 index 0000000..8267d0d --- /dev/null +++ b/src/kernel/iso9660.h @@ -0,0 +1,34 @@ +/* +Copyright 2019 Benji Dial + +Permission to use, copy, modify, and/or distribute this +software for any purpose with or without fee is hereby +granted, provided that the above copyright notice and this +permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS +ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO +EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER +RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +OF THIS SOFTWARE. +*/ + +#include +#include + +#ifndef ISO9660_H +#define ISO9660_H + +struct iso_9660_volume_descriptor_start { + uint8_t type; + uint8_t id[5]; + uint8_t version; +} __attribute__ ((__packed__)); + +bool iso_9660_parse_ph(uint8_t dn, uint32_t sector, uint8_t *buffer); + +#endif \ No newline at end of file -- cgit v1.2.3