Various critical bug fixes across many files

This commit is contained in:
notsomeidiot123 2026-02-02 02:39:49 -05:00
parent 806e011256
commit 1826eb1ad3
8 changed files with 29 additions and 15 deletions

View File

@ -4,7 +4,7 @@ LDFLAGS_i386="-Ttext 0xc0000000 --oformat binary -melf_i386"
cd src/kernel/
gcc kmain.c $CFLAGS -o ../../bin/kernel/kmain.o
for d in ./*/; do
if [[ "$d" != "./obj/" ]]; then
if [ "$d" != "./obj/" ]; then
echo "\033[1;32mCompiling files in $d\033[0m"
for f in $d*.c; do
echo -e "\033[1;36mfile: $f\033[0m"

View File

@ -23,13 +23,13 @@ void sysinit(){
pci_init();
// modules_init(boot_info, 0);
read_initrd(boot_info->initrd);
vfile_t *initrc = fopen("/boot/initrc.conf");
vfile_t *initrc = fget_file("/boot/initrc.conf");
if(initrc){
mlog("KERNEL", "Found initrc at: %x\n", MLOG_PRINT, initrc->access.data.ptr);
}
modules_init();
initrc_read(initrc);
vfile_t *disk_dir = fopen("/dev/disk");
vfile_t *disk_dir = fget_file("/dev/disk");
if(disk_dir == 0){
mlog("KERNEL", "Error: /dev/disk does not exist\n", MLOG_PRINT);
}

View File

@ -49,7 +49,7 @@ void initrc_read(vfile_t *file){
i+=j;
module_name[j] = 0;
// printf("%s\n", module_name);
vfile_t *module = fopen(module_name);
vfile_t *module = fget_file(module_name);
if(!module){
printf("Error: Could not find module in Initrc.conf: %s\n", module_name);
continue;

View File

@ -92,7 +92,7 @@ uint32_t module_api(uint32_t func, ...){
break;
case MODULE_API_OPEN:
name = va_arg(vars, char *);
return_value = (uint32_t)fopen(name);
return_value = (uint32_t)fget_file(name);
break;
case MODULE_API_MAP:
return_value = 0;

View File

@ -105,7 +105,7 @@ void exec(char *filename, char **argv){
//a new schedulable entity
}
void kill(uint32_t pid){
void *pd = processes[pid].page_dir;
uint32_t pd = (uint32_t)processes[pid].page_dir;
// uint32_t *pd_ptr = kmalloc(1);
// uint32_t *pt_ptr = kmalloc(1);
// kfree(pt_ptr);
@ -114,7 +114,7 @@ void kill(uint32_t pid){
uint32_t *pd_ptr = kmalloc_page_paddr(pd, 1);
for(uint32_t i = 0; i < 1024; i++){
// map(pt_ptr, (void *)pd_ptr[i], PT_PRESENT);
uint32_t *pt_ptr = kmalloc_page_paddr((void *)pd_ptr[i], 1);
uint32_t *pt_ptr = kmalloc_page_paddr(pd_ptr[i], 1);
for(uint32_t j = 0; j < 1024; j++){
uint32_t pt_paddr = pt_ptr[j] & ~(0xfff);
pm_free(pt_paddr);

View File

@ -260,7 +260,7 @@ vfile_t *search_dir(char *name, vfile_t dir){
return 0;
}
vfile_t *fopen(char *name){
vfile_t *fget_file(char *name){
if(name[0] == '/'){
if(strlen(name) == 1){
return &root_dir;

View File

@ -81,7 +81,7 @@ void fdelete();
int fwrite(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t count);
int fread(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t count);
vfile_t *search_dir(char *name, vfile_t dir);
vfile_t *fopen(char *name);
vfile_t *fget_file(char *name);
// void vfs_del_mount_handler(uint32_t key);
// void vfs_add_mount_handler(int (*mount_handler)(vfile_t *device, MOUNT_OPERATION op, ...), uint32_t key);
void vfs_detect_partitions(vfile_t *file);

View File

@ -139,12 +139,14 @@ uint32_t read_cluster(fat_info *info, uint32_t cluster, buffer_t buffer, size_t
//write size bytes to file from buffer. no value may be zero or null. If file is null, will write to root directory
int write_file(fat_info *info, file_t *file, buffer_t buffer, size_t size, FILE *disk){
uint32_t was_root = 0;
if(!file){
file_t root_file = {0};
root_file.start_cluster_high = info->bpb.root_dir_cluster>>16;
root_file.start_cluster_low = info->bpb.root_dir_cluster&0xffff;
was_root = 1;
file_t *root_file = malloc(sizeof(file_t));
root_file->start_cluster_low = info->bpb.root_dir_cluster&0xffff;
root_file->start_cluster_high = info->bpb.root_dir_cluster>>16;
// printf("Rootdirwrite: %d", root_file.start_cluster_high << 16 | root_file.start_cluster_low);
file = &root_file;
file = root_file;
}
uint32_t first_cluster = file->start_cluster_low | (file->start_cluster_high << 16);
uint32_t clusters = (size / (info->bpb.bytes_per_sector * info->bpb.sectors_per_cluster )) + 1;
@ -165,6 +167,10 @@ int write_file(fat_info *info, file_t *file, buffer_t buffer, size_t size, FILE
cluster = next_cluster;
}
write_cluster_value(info, -1, cluster);
if(was_root){
free(file);
}
free(new_buffer);
return size * info->bpb.bytes_per_sector * info->bpb.sectors_per_cluster;
}
@ -201,6 +207,7 @@ int create_file(char *path, fat_info *info, FILE *file, FILE *disk){
info->bpb.root_dir_entries++;
write_file(info, &root_files[index], buffer, size, disk);
write_file(info, 0, (buffer_t)root_files, (info->bpb.root_dir_entries * sizeof(file_t)), disk);
free(buffer);
}
int fat_write_back(FILE *file, fat_info *info){
@ -235,11 +242,12 @@ int detect_repair_fs(FILE *file, fat_info *info){
info->file_table[1] = -1;
info->file_table[info->bpb.root_dir_cluster] = -1;
}
free(boot_sector);
}
int main(int argc, char **argv){
char list_root_dir = 0;
char **files = malloc(512);
char **files = malloc(512*sizeof(char*));
int filec = 0;
FILE *output_file = 0;
@ -264,7 +272,9 @@ int main(int argc, char **argv){
}
verbose && printf("OF: %s\n", argv[i]);
output_file = fopen(argv[i], "r+");
if(!output_file) printf("Error opening file");
if(!output_file){
printf("Error opening file");
}
continue;
}
if(!strcmp(argv[i], "-v")){
@ -299,8 +309,12 @@ int main(int argc, char **argv){
printf(".%s\n", root[index].ext);
index++;
}
// free(root);
}
fat_write_back(output_file, &info);
verbose && printf("Finished. Exiting...\n");
fclose(output_file);
free(info.file_table);
free(files);
return 0;
}