fs: Add case insensitive fopen() for config and system files

This commit is contained in:
mintsuki 2022-09-01 14:02:53 +02:00
parent 4702e912be
commit 27711e3c27
9 changed files with 28 additions and 6 deletions

View File

@ -39,10 +39,14 @@ extern symbol build_id_s3;
static bool stage3_init(struct volume *part) {
struct file_handle *stage3;
bool old_cif = case_insensitive_fopen;
case_insensitive_fopen = true;
if ((stage3 = fopen(part, "/limine.sys")) == NULL
&& (stage3 = fopen(part, "/boot/limine.sys")) == NULL) {
case_insensitive_fopen = old_cif;
return false;
}
case_insensitive_fopen = old_cif;
stage3_found = true;

View File

@ -73,11 +73,15 @@ noreturn void uefi_entry(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
for (size_t i = 0; i < volume_index_i; i++) {
struct file_handle *f;
bool old_cif = case_insensitive_fopen;
case_insensitive_fopen = true;
if ((f = fopen(volume_index[i], "/limine.cfg")) == NULL
&& (f = fopen(volume_index[i], "/boot/limine.cfg")) == NULL
&& (f = fopen(volume_index[i], "/EFI/BOOT/limine.cfg")) == NULL) {
case_insensitive_fopen = old_cif;
continue;
}
case_insensitive_fopen = old_cif;
fclose(f);

View File

@ -412,7 +412,9 @@ next:
inode_read(name, i + sizeof(struct ext2_dir_entry), dir->name_len,
&current_inode, fd, alloc_map);
int test = strcmp(token, name);
int (*strcmpfn)(const char *, const char *) = case_insensitive_fopen ? strcasecmp : strcmp;
int test = strcmpfn(token, name);
pmm_free(name, dir->name_len + 1);
if (test == 0) {

View File

@ -384,7 +384,9 @@ static int fat32_open_in(struct fat32_context* context, struct fat32_directory_e
}
}
if (!strcmp(current_lfn, name)) {
int (*strcmpfn)(const char *, const char *) = case_insensitive_fopen ? strcasecmp : strcmp;
if (strcmpfn(current_lfn, name) == 0) {
*file = directory_entries[i+1];
ret = 0;
goto out;

View File

@ -9,6 +9,8 @@
# include <efi.h>
#endif
extern bool case_insensitive_fopen;
bool fs_get_guid(struct guid *guid, struct volume *part);
char *fs_get_label(struct volume *part);

View File

@ -32,6 +32,8 @@ bool fs_get_guid(struct guid *guid, struct volume *part) {
return false;
}
bool case_insensitive_fopen = false;
struct file_handle *fopen(struct volume *part, const char *filename) {
size_t filename_new_len = strlen(filename) + 2;
char *filename_new = ext_mem_alloc(filename_new_len);

View File

@ -195,7 +195,7 @@ static struct iso9660_directory_entry *iso9660_find(void *buffer, uint32_t size,
char entry_filename[128];
bool rr = load_name(entry_filename, entry);
if (rr) {
if (rr && !case_insensitive_fopen) {
if (strcmp(filename, entry_filename) == 0) {
return buffer;
}

View File

@ -21,11 +21,15 @@ static char *config_addr;
int init_config_disk(struct volume *part) {
struct file_handle *f;
bool old_cif = case_insensitive_fopen;
case_insensitive_fopen = true;
if ((f = fopen(part, "/limine.cfg")) == NULL
&& (f = fopen(part, "/boot/limine.cfg")) == NULL
&& (f = fopen(part, "/EFI/BOOT/limine.cfg")) == NULL) {
case_insensitive_fopen = old_cif;
return -1;
}
case_insensitive_fopen = old_cif;
size_t config_size = f->size + 2;
config_addr = ext_mem_alloc(config_size);

View File

@ -20,11 +20,13 @@ static void try(char *config, struct volume *v) {
struct file_handle *image;
struct volume *p = volume_get_by_coord(v->is_optical, v->index, i);
if ((image = fopen(p, "/EFI/BOOT/BOOTX64.EFI")) == NULL
&& (image = fopen(p, "/efi/boot/bootx64.efi")) == NULL
&& (image = fopen(p, "/EFI/BOOT/BOOTx64.EFI")) == NULL) {
bool old_cif = case_insensitive_fopen;
case_insensitive_fopen = true;
if ((image = fopen(p, "/EFI/BOOT/BOOTX64.EFI")) == NULL) {
case_insensitive_fopen = old_cif;
continue;
}
case_insensitive_fopen = old_cif;
efi_chainload_file(config, image);
}