diff options
author | Benji Dial <Benji3.141@gmail.com> | 2019-12-27 18:49:11 -0500 |
---|---|---|
committer | Benji Dial <Benji3.141@gmail.com> | 2019-12-27 18:49:11 -0500 |
commit | 7c7fd36bea1eac4d0fa7bd628a53fff7d2e60917 (patch) | |
tree | 9e2fb97dd631170ef6a917740016573231f7634f | |
parent | 58b5c8ba417fe99c01d9a48731b887ce434e797e (diff) | |
download | portland-os-7c7fd36bea1eac4d0fa7bd628a53fff7d2e60917.tar.gz |
doing iso9660 before gpt, making partition detection expandable
-rw-r--r-- | makefile | 25 | ||||
-rw-r--r-- | src/kernel/files.c | 39 | ||||
-rw-r--r-- | src/kernel/files.h | 11 | ||||
-rw-r--r-- | src/kernel/gpt.c | 8 | ||||
-rw-r--r-- | src/kernel/iso9660.c | 24 | ||||
-rw-r--r-- | src/kernel/iso9660.h | 34 |
6 files changed, 115 insertions, 26 deletions
@@ -11,19 +11,20 @@ files: out cp -r src/skel/* out/fs/ kernel: obj out - nasm src/kernel/keyb.asm -o obj/kkeyba.o -f elf32 - nasm src/kernel/serial.asm -o obj/kserial.o -f elf32 - nasm src/kernel/stub.asm -o obj/kstub.o -f elf32 - gcc -c src/kernel/diskio.c -o obj/kdiskio.o -ffreestanding -nostdlib -m32 - gcc -c src/kernel/files.c -o obj/kfiles.o -ffreestanding -nostdlib -m32 - gcc -c src/kernel/gpt.c -o obj/kgpt.o -ffreestanding -nostdlib -m32 - gcc -c src/kernel/keyb.c -o obj/kkeybc.o -ffreestanding -nostdlib -m32 - gcc -c src/kernel/main.c -o obj/kmain.o -ffreestanding -nostdlib -m32 - gcc -c src/kernel/mem.c -o obj/kmem.o -ffreestanding -nostdlib -m32 - gcc -c src/kernel/proc.c -o obj/kproc.o -ffreestanding -nostdlib -m32 - gcc -c src/kernel/vga.c -o obj/kvga.o -ffreestanding -nostdlib -m32 + nasm src/kernel/keyb.asm -o obj/kkeyba.o -f elf32 + nasm src/kernel/serial.asm -o obj/kserial.o -f elf32 + nasm src/kernel/stub.asm -o obj/kstub.o -f elf32 + gcc -c src/kernel/diskio.c -o obj/kdiskio.o -ffreestanding -nostdlib -m32 + gcc -c src/kernel/files.c -o obj/kfiles.o -ffreestanding -nostdlib -m32 + #gcc -c src/kernel/gpt.c -o obj/kgpt.o -ffreestanding -nostdlib -m32 + gcc -c src/kernel/iso9660.c -o obj/kiso9660.o -ffreestanding -nostdlib -m32 + gcc -c src/kernel/keyb.c -o obj/kkeybc.o -ffreestanding -nostdlib -m32 + gcc -c src/kernel/main.c -o obj/kmain.o -ffreestanding -nostdlib -m32 + gcc -c src/kernel/mem.c -o obj/kmem.o -ffreestanding -nostdlib -m32 + gcc -c src/kernel/proc.c -o obj/kproc.o -ffreestanding -nostdlib -m32 + gcc -c src/kernel/vga.c -o obj/kvga.o -ffreestanding -nostdlib -m32 ld obj/kkeyba.o obj/kserial.o obj/kstub.o obj/kdiskio.o obj/kfiles.o \ - obj/kgpt.o obj/kkeybc.o obj/kmain.o obj/kmem.o obj/kproc.o obj/kvga.o \ + obj/kiso9660.o obj/kkeybc.o obj/kmain.o obj/kmem.o obj/kproc.o obj/kvga.o \ -o out/kernel.elf -T src/kernel/link.ld -s --orphan-handling=discard -melf_i386 clean: 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 <stdint.h> +#include <stdbool.h> + +#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 |