summaryrefslogtreecommitdiff
path: root/src/kernel/files.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/files.c')
-rw-r--r--src/kernel/files.c39
1 files changed, 32 insertions, 7 deletions
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;