Compare commits
4 Commits
e5ce4d42d1
...
047a057e9b
| Author | SHA1 | Date |
|---|---|---|
|
|
047a057e9b | |
|
|
f20ee8046c | |
|
|
daa915363d | |
|
|
c2f258f1bb |
|
|
@ -1,4 +1,4 @@
|
||||||
CFLAGS="-g -c -m32 -fno-pie -mno-sse -O3 -D __bits__=32 -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -Wno-incompatible-pointer-types -Wno-address-of-packed-member -Wno-discarded-qualifiers -fno-stack-protector -mno-red-zone -mno-sse -mno-sse2 -ffreestanding -nostdlib -mno-mmx"
|
CFLAGS="-g -c -m32 -fno-pie -mno-sse -O3 -D __bits__=32 -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -Wno-incompatible-pointer-types -fno-stack-protector -mno-red-zone -mno-sse -mno-sse2 -ffreestanding -nostdlib -mno-mmx"
|
||||||
LDFLAGS_i386="-Ttext 0xc0000000 --oformat binary -melf_i386"
|
LDFLAGS_i386="-Ttext 0xc0000000 --oformat binary -melf_i386"
|
||||||
|
|
||||||
cd src/kernel/
|
cd src/kernel/
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,7 @@ void pci_make_file(uint32_t class, uint8_t bus, uint8_t slot, uint8_t func){
|
||||||
file = fcreate(cpy, 0);
|
file = fcreate(cpy, 0);
|
||||||
// file->read = pci_read_file;
|
// file->read = pci_read_file;
|
||||||
// file->write = pci_write_file;
|
// file->write = pci_write_file;
|
||||||
|
if(file == 0) break;
|
||||||
file->fileops = &pci_fileops;
|
file->fileops = &pci_fileops;
|
||||||
if(tries >= 254){
|
if(tries >= 254){
|
||||||
mlog(MODULE_NAME, "Failed to make PCI file for device!\n", MLOG_PRINT);
|
mlog(MODULE_NAME, "Failed to make PCI file for device!\n", MLOG_PRINT);
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ int read_initrd(initrd_t *initrd){
|
||||||
vfile_t *tmp = fcreate(final_fname, 0);
|
vfile_t *tmp = fcreate(final_fname, 0);
|
||||||
if(!tmp){
|
if(!tmp){
|
||||||
mlog("INITRD", "Failed to read critical boot file: %s\n", MLOG_PRINT, file->filename);
|
mlog("INITRD", "Failed to read critical boot file: %s\n", MLOG_PRINT, file->filename);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
if(tmp->private){
|
if(tmp->private){
|
||||||
kfree(tmp->private);
|
kfree(tmp->private);
|
||||||
|
|
@ -48,4 +49,5 @@ int read_initrd(initrd_t *initrd){
|
||||||
// printf("%s, %d, %d\n", final_fname, filesize, fsize_pgs);
|
// printf("%s, %d, %d\n", final_fname, filesize, fsize_pgs);
|
||||||
offset += (((filesize + 511) / 512) + 1) * 512;
|
offset += (((filesize + 511) / 512) + 1) * 512;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -28,7 +28,7 @@ void sysinit(){
|
||||||
vfile_t *initrc = fopen("/boot/initrc.conf");
|
vfile_t *initrc = fopen("/boot/initrc.conf");
|
||||||
mlog("RAE", "\033[1;32mDid you remember to migrate your modules to the new API?\033[0m\n", MLOG_PRINT);
|
mlog("RAE", "\033[1;32mDid you remember to migrate your modules to the new API?\033[0m\n", MLOG_PRINT);
|
||||||
if(initrc){
|
if(initrc){
|
||||||
mlog("KERNEL", "Found initrc", MLOG_PRINT);
|
mlog("KERNEL", "Found initrc\n", MLOG_PRINT);
|
||||||
initrc_read(initrc);
|
initrc_read(initrc);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|
@ -68,6 +68,7 @@ extern void kmain(kernel_info_t *kernel_info){
|
||||||
//scheduler doesn't work if there is no PID0, and I don't know why.
|
//scheduler doesn't work if there is no PID0, and I don't know why.
|
||||||
thread_start(pid0);
|
thread_start(pid0);
|
||||||
thread_start(sysinit);
|
thread_start(sysinit);
|
||||||
|
// for(;;);
|
||||||
enable_interrupts();
|
enable_interrupts();
|
||||||
for(;;);//we actually **shouldn't** return, like, ever. That's bad.
|
for(;;);//we actually **shouldn't** return, like, ever. That's bad.
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,8 @@
|
||||||
#define KMALLOC_LINK_NEXT 2
|
#define KMALLOC_LINK_NEXT 2
|
||||||
#define KMALLOC_LINK_LAST 4
|
#define KMALLOC_LINK_LAST 4
|
||||||
|
|
||||||
|
#define PAGE_SIZE_BYTES 4096
|
||||||
|
|
||||||
typedef struct BIOS_data{
|
typedef struct BIOS_data{
|
||||||
uint16_t com_ports[4];
|
uint16_t com_ports[4];
|
||||||
uint16_t lpt_ports[3];
|
uint16_t lpt_ports[3];
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,11 @@ int is_num(char c){
|
||||||
|
|
||||||
void initrc_read(vfile_t *file){
|
void initrc_read(vfile_t *file){
|
||||||
mlog("KERNEL", "Reading initrc:\n", MLOG_PRINT);
|
mlog("KERNEL", "Reading initrc:\n", MLOG_PRINT);
|
||||||
char *ptr = file->private;
|
if(!file || !file->private){
|
||||||
if(!file || !ptr){
|
|
||||||
mlog("KERNEL", "Failed to read initrc!\n", MLOG_PRINT);
|
mlog("KERNEL", "Failed to read initrc!\n", MLOG_PRINT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
char *ptr = file->private;
|
||||||
uint32_t size = file->size;
|
uint32_t size = file->size;
|
||||||
char statement[512];
|
char statement[512];
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,8 @@ uint32_t module_api(uint32_t func, ...){
|
||||||
buffer = va_arg(vars, void *);
|
buffer = va_arg(vars, void *);
|
||||||
offset = va_arg(vars, uint32_t);
|
offset = va_arg(vars, uint32_t);
|
||||||
count = va_arg(vars, uint32_t);
|
count = va_arg(vars, uint32_t);
|
||||||
return_value = readdir(file, buffer, offset, count);
|
// return_value = readdir(file, buffer, offset, count);
|
||||||
|
return_value = 0;
|
||||||
break;
|
break;
|
||||||
case MODULE_API_MAP:
|
case MODULE_API_MAP:
|
||||||
return_value = 0;
|
return_value = 0;
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,15 @@
|
||||||
#include "../shared/string.h"
|
#include "../shared/string.h"
|
||||||
#define MODULE_NAME "KVFS"
|
#define MODULE_NAME "KVFS"
|
||||||
|
|
||||||
|
|
||||||
fileops_t ramfs_ops =
|
fileops_t ramfs_ops =
|
||||||
{
|
{
|
||||||
ramfs_create,
|
ramfs_create,
|
||||||
|
ramfs_delete,
|
||||||
|
ramfs_write,
|
||||||
|
ramfs_read,
|
||||||
|
ramfs_open,
|
||||||
|
ramfs_close,
|
||||||
|
ramfs_rfopen,
|
||||||
};
|
};
|
||||||
|
|
||||||
vfile_t root_dir = {"/", FS_FILE_IS_DIR | FS_FILE_SYSTEM, &ramfs_ops};
|
vfile_t root_dir = {"/", FS_FILE_IS_DIR | FS_FILE_SYSTEM, &ramfs_ops};
|
||||||
|
|
@ -16,10 +21,76 @@ vfile_t root_dir = {"/", FS_FILE_IS_DIR | FS_FILE_SYSTEM, &ramfs_ops};
|
||||||
void ramfs_init(){
|
void ramfs_init(){
|
||||||
mlog(MODULE_NAME, "Initializing VFS\n", MLOG_PRINT);
|
mlog(MODULE_NAME, "Initializing VFS\n", MLOG_PRINT);
|
||||||
root_dir.private = kmalloc(1);
|
root_dir.private = kmalloc(1);
|
||||||
root_dir.size = 4096;//one page is 4096 bytes
|
root_dir.size = PAGE_SIZE_BYTES;//one page is 4096 bytes
|
||||||
|
// printf("Sizeof VFILE_T: %d", sizeof(vfile_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vfile_t *search_dir(char *subname, vfile_t *directory){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//resolves the path relative to start
|
||||||
|
vfile_t *resolve_path(char *pathname, vfile_t *start){
|
||||||
|
const uint32_t MAX_TOKENS = PAGE_SIZE_BYTES/4;
|
||||||
|
|
||||||
|
if(!start){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
char *path = kmalloc(1);
|
||||||
|
strcpy(pathname, path);
|
||||||
|
|
||||||
|
char **path_tokens = kmalloc(1);
|
||||||
|
uint32_t pathname_entries = 0;
|
||||||
|
char *pathtok = path;
|
||||||
|
char *i = path;
|
||||||
|
while (*i != '\0') {
|
||||||
|
if (*i == '/') {
|
||||||
|
*i = '\0';
|
||||||
|
if (pathname_entries < MAX_TOKENS) {
|
||||||
|
path_tokens[pathname_entries++] = pathtok;
|
||||||
|
}
|
||||||
|
pathtok = i + 1;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (pathname_entries < MAX_TOKENS) {
|
||||||
|
path_tokens[pathname_entries++] = pathtok;
|
||||||
|
}
|
||||||
|
|
||||||
|
vfile_t **buffer = (vfile_t **)start->private;
|
||||||
|
printf("START\n");
|
||||||
|
vfile_t *entry = start;
|
||||||
|
for(int i = 0; i < pathname_entries - 1; i++){
|
||||||
|
printf("%s", path_tokens[i]);
|
||||||
|
|
||||||
|
}
|
||||||
|
printf("END\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
vfile_t *ramfs_create(char *path, FS_FILE_FLAGS flags){
|
vfile_t *ramfs_create(char *path, FS_FILE_FLAGS flags){
|
||||||
|
resolve_path("test/test1/test2", &root_dir);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ramfs_delete(vfile_t *file){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int ramfs_write(vfile_t *file, char *buffer, uint32_t offset, uint32_t count){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int ramfs_read(vfile_t *file, char *buffer, uint32_t offset, uint32_t count){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
vfile_t *ramfs_open(char *path){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
void ramfs_close(vfile_t *file){
|
||||||
|
file->refcount--;
|
||||||
|
if(file->refcount < 0) file->refcount = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
vfile_t *ramfs_rfopen(char *name, vfile_t *parent){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,3 +5,10 @@ void ramfs_init();
|
||||||
vfile_t *ramfs_create(char *path, FS_FILE_FLAGS flags);
|
vfile_t *ramfs_create(char *path, FS_FILE_FLAGS flags);
|
||||||
//Will never create a new reference
|
//Will never create a new reference
|
||||||
vfile_t *get_root_dir();
|
vfile_t *get_root_dir();
|
||||||
|
|
||||||
|
int ramfs_delete(vfile_t *file);
|
||||||
|
int ramfs_write(vfile_t *file, char *buffer, uint32_t offset, uint32_t count);
|
||||||
|
int ramfs_read(vfile_t *file, char *buffer, uint32_t offset, uint32_t count);
|
||||||
|
vfile_t *ramfs_open(char *path);
|
||||||
|
void ramfs_close(vfile_t *file);
|
||||||
|
vfile_t *ramfs_rfopen(char *name, vfile_t *parent);
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#define MODULE_NAME "KVFS"
|
#define MODULE_NAME "KVFS"
|
||||||
|
|
||||||
// !TODO: Modify code to become thread-safe
|
// !TODO: Modify code to become thread-safe
|
||||||
|
// 3 months later: does this count?
|
||||||
|
|
||||||
|
|
||||||
// void add_file(vfile_t *vfile, vfile_t *current_dir){
|
// void add_file(vfile_t *vfile, vfile_t *current_dir){
|
||||||
|
|
@ -13,7 +14,9 @@
|
||||||
// }
|
// }
|
||||||
|
|
||||||
vfile_t *fcreate(char *path, FS_FILE_FLAGS flags){
|
vfile_t *fcreate(char *path, FS_FILE_FLAGS flags){
|
||||||
vfcreate(get_root_dir(), path, flags);
|
// return 0;
|
||||||
|
vfile_t *returnable = vfcreate(get_root_dir(), path, flags);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
vfile_t *vfcreate(vfile_t *parent_dir, char *relpath, FS_FILE_FLAGS flags){
|
vfile_t *vfcreate(vfile_t *parent_dir, char *relpath, FS_FILE_FLAGS flags){
|
||||||
|
|
@ -44,9 +47,11 @@ vfile_t *vfcreate(vfile_t *parent_dir, char *relpath, FS_FILE_FLAGS flags){
|
||||||
else{
|
else{
|
||||||
vfile_t *new_parent = rfopen(name, parent_dir);
|
vfile_t *new_parent = rfopen(name, parent_dir);
|
||||||
if(!new_parent){
|
if(!new_parent){
|
||||||
|
// printf("No new parent found!\n");
|
||||||
kfree(name);
|
kfree(name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
// printf("Recursed\n");
|
||||||
new_file = vfcreate(new_parent, name+name_index+1, flags);
|
new_file = vfcreate(new_parent, name+name_index+1, flags);
|
||||||
fclose(new_parent);
|
fclose(new_parent);
|
||||||
}
|
}
|
||||||
|
|
@ -80,7 +85,7 @@ vfile_t *rfopen(char *name, vfile_t *dir){
|
||||||
if(!dir || !name || !dir->fileops || !dir->fileops->rfopen){
|
if(!dir || !name || !dir->fileops || !dir->fileops->rfopen){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return dir->fileops->rfopen(name);
|
return dir->fileops->rfopen(name, dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
int readdir(vfile_t* file, vfile_t* buffer, uint32_t offset, uint32_t count){
|
int readdir(vfile_t* file, vfile_t* buffer, uint32_t offset, uint32_t count){
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ typedef struct fileops{
|
||||||
struct virtual_file *(*open)(char *path);
|
struct virtual_file *(*open)(char *path);
|
||||||
void (*close)(struct virtual_file *file);
|
void (*close)(struct virtual_file *file);
|
||||||
// int (*readdir)(struct virtual_file* file, struct virtual_file *buffer, uint32_t count, uint32_t offset);
|
// int (*readdir)(struct virtual_file* file, struct virtual_file *buffer, uint32_t count, uint32_t offset);
|
||||||
struct virtual_file *(*rfopen)(char *name);
|
struct virtual_file *(*rfopen)(char *name, struct virtual_file *parent);
|
||||||
} fileops_t;
|
} fileops_t;
|
||||||
|
|
||||||
typedef struct virtual_file{
|
typedef struct virtual_file{
|
||||||
|
|
@ -32,7 +32,7 @@ typedef struct virtual_file{
|
||||||
|
|
||||||
uint32_t id;//for use in drivers
|
uint32_t id;//for use in drivers
|
||||||
void *private; //also for use in drivers
|
void *private; //also for use in drivers
|
||||||
uint32_t size;
|
uint32_t size; //should be in bytes
|
||||||
uint32_t offset; //for use in drivers
|
uint32_t offset; //for use in drivers
|
||||||
|
|
||||||
}vfile_t;
|
}vfile_t;
|
||||||
|
|
@ -46,5 +46,5 @@ int fread(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t count
|
||||||
|
|
||||||
vfile_t *vfcreate(vfile_t *parent, char *relpath, FS_FILE_FLAGS flags);
|
vfile_t *vfcreate(vfile_t *parent, char *relpath, FS_FILE_FLAGS flags);
|
||||||
vfile_t *rfopen(char *name, vfile_t *dir);
|
vfile_t *rfopen(char *name, vfile_t *dir);
|
||||||
|
vfile_t *fclose(vfile_t *);
|
||||||
vfile_t *fopen(char *path);
|
vfile_t *fopen(char *path);
|
||||||
|
|
@ -34,6 +34,8 @@ uint32_t fat32_mount(vfile_t *dev_file, char *destination, uint32_t offset){
|
||||||
}
|
}
|
||||||
puts(api, MODULE_NAME, "Valid BPB found!\n");
|
puts(api, MODULE_NAME, "Valid BPB found!\n");
|
||||||
|
|
||||||
|
// fat32_make_mount()
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue