fs: Add case insensitive fopen() for config and system files
This commit is contained in:
parent
4702e912be
commit
27711e3c27
@ -39,10 +39,14 @@ extern symbol build_id_s3;
|
|||||||
static bool stage3_init(struct volume *part) {
|
static bool stage3_init(struct volume *part) {
|
||||||
struct file_handle *stage3;
|
struct file_handle *stage3;
|
||||||
|
|
||||||
|
bool old_cif = case_insensitive_fopen;
|
||||||
|
case_insensitive_fopen = true;
|
||||||
if ((stage3 = fopen(part, "/limine.sys")) == NULL
|
if ((stage3 = fopen(part, "/limine.sys")) == NULL
|
||||||
&& (stage3 = fopen(part, "/boot/limine.sys")) == NULL) {
|
&& (stage3 = fopen(part, "/boot/limine.sys")) == NULL) {
|
||||||
|
case_insensitive_fopen = old_cif;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
case_insensitive_fopen = old_cif;
|
||||||
|
|
||||||
stage3_found = true;
|
stage3_found = true;
|
||||||
|
|
||||||
|
@ -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++) {
|
for (size_t i = 0; i < volume_index_i; i++) {
|
||||||
struct file_handle *f;
|
struct file_handle *f;
|
||||||
|
|
||||||
|
bool old_cif = case_insensitive_fopen;
|
||||||
|
case_insensitive_fopen = true;
|
||||||
if ((f = fopen(volume_index[i], "/limine.cfg")) == NULL
|
if ((f = fopen(volume_index[i], "/limine.cfg")) == NULL
|
||||||
&& (f = fopen(volume_index[i], "/boot/limine.cfg")) == NULL
|
&& (f = fopen(volume_index[i], "/boot/limine.cfg")) == NULL
|
||||||
&& (f = fopen(volume_index[i], "/EFI/BOOT/limine.cfg")) == NULL) {
|
&& (f = fopen(volume_index[i], "/EFI/BOOT/limine.cfg")) == NULL) {
|
||||||
|
case_insensitive_fopen = old_cif;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
case_insensitive_fopen = old_cif;
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
|
@ -412,7 +412,9 @@ next:
|
|||||||
inode_read(name, i + sizeof(struct ext2_dir_entry), dir->name_len,
|
inode_read(name, i + sizeof(struct ext2_dir_entry), dir->name_len,
|
||||||
¤t_inode, fd, alloc_map);
|
¤t_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);
|
pmm_free(name, dir->name_len + 1);
|
||||||
|
|
||||||
if (test == 0) {
|
if (test == 0) {
|
||||||
|
@ -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];
|
*file = directory_entries[i+1];
|
||||||
ret = 0;
|
ret = 0;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
# include <efi.h>
|
# include <efi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern bool case_insensitive_fopen;
|
||||||
|
|
||||||
bool fs_get_guid(struct guid *guid, struct volume *part);
|
bool fs_get_guid(struct guid *guid, struct volume *part);
|
||||||
char *fs_get_label(struct volume *part);
|
char *fs_get_label(struct volume *part);
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ bool fs_get_guid(struct guid *guid, struct volume *part) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool case_insensitive_fopen = false;
|
||||||
|
|
||||||
struct file_handle *fopen(struct volume *part, const char *filename) {
|
struct file_handle *fopen(struct volume *part, const char *filename) {
|
||||||
size_t filename_new_len = strlen(filename) + 2;
|
size_t filename_new_len = strlen(filename) + 2;
|
||||||
char *filename_new = ext_mem_alloc(filename_new_len);
|
char *filename_new = ext_mem_alloc(filename_new_len);
|
||||||
|
@ -195,7 +195,7 @@ static struct iso9660_directory_entry *iso9660_find(void *buffer, uint32_t size,
|
|||||||
char entry_filename[128];
|
char entry_filename[128];
|
||||||
bool rr = load_name(entry_filename, entry);
|
bool rr = load_name(entry_filename, entry);
|
||||||
|
|
||||||
if (rr) {
|
if (rr && !case_insensitive_fopen) {
|
||||||
if (strcmp(filename, entry_filename) == 0) {
|
if (strcmp(filename, entry_filename) == 0) {
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,15 @@ static char *config_addr;
|
|||||||
int init_config_disk(struct volume *part) {
|
int init_config_disk(struct volume *part) {
|
||||||
struct file_handle *f;
|
struct file_handle *f;
|
||||||
|
|
||||||
|
bool old_cif = case_insensitive_fopen;
|
||||||
|
case_insensitive_fopen = true;
|
||||||
if ((f = fopen(part, "/limine.cfg")) == NULL
|
if ((f = fopen(part, "/limine.cfg")) == NULL
|
||||||
&& (f = fopen(part, "/boot/limine.cfg")) == NULL
|
&& (f = fopen(part, "/boot/limine.cfg")) == NULL
|
||||||
&& (f = fopen(part, "/EFI/BOOT/limine.cfg")) == NULL) {
|
&& (f = fopen(part, "/EFI/BOOT/limine.cfg")) == NULL) {
|
||||||
|
case_insensitive_fopen = old_cif;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
case_insensitive_fopen = old_cif;
|
||||||
|
|
||||||
size_t config_size = f->size + 2;
|
size_t config_size = f->size + 2;
|
||||||
config_addr = ext_mem_alloc(config_size);
|
config_addr = ext_mem_alloc(config_size);
|
||||||
|
@ -20,11 +20,13 @@ static void try(char *config, struct volume *v) {
|
|||||||
struct file_handle *image;
|
struct file_handle *image;
|
||||||
struct volume *p = volume_get_by_coord(v->is_optical, v->index, i);
|
struct volume *p = volume_get_by_coord(v->is_optical, v->index, i);
|
||||||
|
|
||||||
if ((image = fopen(p, "/EFI/BOOT/BOOTX64.EFI")) == NULL
|
bool old_cif = case_insensitive_fopen;
|
||||||
&& (image = fopen(p, "/efi/boot/bootx64.efi")) == NULL
|
case_insensitive_fopen = true;
|
||||||
&& (image = fopen(p, "/EFI/BOOT/BOOTx64.EFI")) == NULL) {
|
if ((image = fopen(p, "/EFI/BOOT/BOOTX64.EFI")) == NULL) {
|
||||||
|
case_insensitive_fopen = old_cif;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
case_insensitive_fopen = old_cif;
|
||||||
|
|
||||||
efi_chainload_file(config, image);
|
efi_chainload_file(config, image);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user