summaryrefslogtreecommitdiff
path: root/src/kernel/fat.c
diff options
context:
space:
mode:
authorBenji Dial <benji6283@gmail.com>2021-01-24 20:02:58 -0500
committerBenji Dial <benji6283@gmail.com>2021-01-24 20:02:58 -0500
commitbd7facc4b5f53481dc85a15ba123361b2758655b (patch)
treeb0977c22757ddbd2685836075e175b9bd8b64127 /src/kernel/fat.c
parent782cfaa0e3f44f8c8089a7c6a148149bece0a515 (diff)
downloadportland-os-bd7facc4b5f53481dc85a15ba123361b2758655b.tar.gz
making fat driver refuse to open a file when its name is too long rather than kernel panicking
Diffstat (limited to 'src/kernel/fat.c')
-rw-r--r--src/kernel/fat.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/kernel/fat.c b/src/kernel/fat.c
index 362539c..befc1d8 100644
--- a/src/kernel/fat.c
+++ b/src/kernel/fat.c
@@ -174,7 +174,7 @@ static bool try_locate_entry(const uint8_t *fat_name) {
}
//puts first path component's fat name into fat_name_buffer,
-//returns rest of path
+//returns rest of path, or zero on error
static const char *split_path(const char *path, uint8_t *fat_name_buffer) {
uint8_t pi = 0, fi = 0;
while (1) {
@@ -190,9 +190,9 @@ static const char *split_path(const char *path, uint8_t *fat_name_buffer) {
++pi;
}
else
- PANIC("Bad path in FAT16 driver.");
+ return 0;
else if (((fi == 8) && (path[pi - 1] != EXT_SEP_CHAR)) || (fi == 11))
- PANIC("Bad path in FAT16 driver.");
+ return 0;
else {
fat_name_buffer[fi++] = (uint8_t)path[pi++];
}
@@ -206,15 +206,13 @@ static bool try_load_from_path(const struct drive *d, const char *path) {
cur_fdi = &infos[cur_id];
uint8_t fat_name[11];
- path = split_path(path, fat_name);
- if (!try_locate_root_entry(fat_name))
+ if (!(path = split_path(path, fat_name)) ||
+ !try_locate_root_entry(fat_name))
return false;
- while (*path) {
- path = split_path(path, fat_name);
- if (!try_locate_entry(fat_name))
+ while (*path)
+ if (!(path = split_path(path, fat_name)) ||
+ !try_locate_entry(fat_name))
return false;
- }
-
return true;
}