doing iso9660 before gpt, making partition detection expandable
This commit is contained in:
		
							parent
							
								
									58b5c8ba41
								
							
						
					
					
						commit
						7c7fd36bea
					
				
					 6 changed files with 115 additions and 26 deletions
				
			
		
							
								
								
									
										25
									
								
								makefile
									
										
									
									
									
								
							
							
						
						
									
										25
									
								
								makefile
									
										
									
									
									
								
							|  | @ -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: | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -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
 | ||||
|     } | ||||
|   } | ||||
|  |  | |||
							
								
								
									
										24
									
								
								src/kernel/iso9660.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/kernel/iso9660.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -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
 | ||||
| } | ||||
							
								
								
									
										34
									
								
								src/kernel/iso9660.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/kernel/iso9660.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||
		Reference in a new issue