vfs - start making the VFS
This commit is contained in:
parent
8b75d8d5e6
commit
6a77b066e8
8 changed files with 128 additions and 63 deletions
37
kernel/src/fs/vfs.h
Normal file
37
kernel/src/fs/vfs.h
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
struct vnode;
|
||||||
|
|
||||||
|
#define VN_FILE 1
|
||||||
|
#define VN_DIR 2
|
||||||
|
|
||||||
|
typedef uint32_t vnode_type_t;
|
||||||
|
|
||||||
|
typedef struct vnode_ops {
|
||||||
|
int (*read)(struct vnode* vn, void* buf, size_t size);
|
||||||
|
} vnode_ops_t;
|
||||||
|
|
||||||
|
typedef struct vnode {
|
||||||
|
char name[256];
|
||||||
|
vnode_type_t type;
|
||||||
|
struct vnode* parent;
|
||||||
|
struct vnode* child;
|
||||||
|
struct vnode* next;
|
||||||
|
|
||||||
|
struct vnode_ops* ops;
|
||||||
|
void* internal;
|
||||||
|
} vnode_t;
|
||||||
|
|
||||||
|
typedef struct fs {
|
||||||
|
char name[32];
|
||||||
|
int (*mount)(struct vnode** root);
|
||||||
|
} fs_t;
|
||||||
|
|
||||||
|
void vfs_init(void);
|
||||||
|
int vfs_mount(char *path, fs_t* fs);
|
||||||
|
int vfs_unmount(char *path);
|
||||||
|
int vfs_open(const char* path, vnode_t** result);
|
||||||
|
int vfs_read(vnode_t* vn, void* buf, size_t size);
|
|
@ -1,4 +1,5 @@
|
||||||
#include <lib/string.h>
|
#include <lib/string.h>
|
||||||
|
#include <mm/liballoc/liballoc.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
int strlen(const char *str) {
|
int strlen(const char *str) {
|
||||||
|
@ -16,14 +17,14 @@ int strcmp(const char *s1, const char *s2) {
|
||||||
return *s1 - *s2;
|
return *s1 - *s2;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *strcpy(char *dest, const char *src)
|
char *strcpy(char *dest, const char *src) {
|
||||||
{
|
if (dest == NULL || src == NULL)
|
||||||
if (dest == NULL || src == NULL)
|
return NULL;
|
||||||
return NULL;
|
|
||||||
|
char *temp = dest;
|
||||||
char *temp = dest;
|
while ((*dest++ = *src++) != '\0')
|
||||||
while((*dest++ = *src++) != '\0');
|
;
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *strchr(const char *s, int c) {
|
char *strchr(const char *s, int c) {
|
||||||
|
@ -35,23 +36,36 @@ char *strchr(const char *s, int c) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char *strrchr(const char *s, int c) {
|
char *strrchr(const char *s, int c) {
|
||||||
const char *p = NULL;
|
const char *p = NULL;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (*s == (char)c)
|
if (*s == (char)c)
|
||||||
p = s;
|
p = s;
|
||||||
if (*s++ == '\0')
|
if (*s++ == '\0')
|
||||||
return (char *)p;
|
return (char *)p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int oct2bin(unsigned char *str, int size) {
|
int oct2bin(unsigned char *str, int size) {
|
||||||
int n = 0;
|
int n = 0;
|
||||||
unsigned char *c = str;
|
unsigned char *c = str;
|
||||||
while (size-- > 0) {
|
while (size-- > 0) {
|
||||||
n *= 8;
|
n *= 8;
|
||||||
n += *c - '0';
|
n += *c - '0';
|
||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *strdup(const char *str) {
|
||||||
|
if (str == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
int len = strlen(str);
|
||||||
|
char *dup = (char *)malloc(len + 1);
|
||||||
|
if (dup == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
strcpy(dup, str);
|
||||||
|
return dup;
|
||||||
}
|
}
|
|
@ -5,4 +5,5 @@ int strcmp(const char *s1, const char *s2);
|
||||||
char *strchr(const char *s, int c);
|
char *strchr(const char *s, int c);
|
||||||
char *strcpy(char *dest, const char *src);
|
char *strcpy(char *dest, const char *src);
|
||||||
char *strrchr(const char *s, int c);
|
char *strrchr(const char *s, int c);
|
||||||
int oct2bin(unsigned char *str, int size);
|
int oct2bin(unsigned char *str, int size);
|
||||||
|
char *strdup(const char *str);
|
|
@ -18,11 +18,13 @@
|
||||||
#include <sys/arch/x86_64/fpu.h>
|
#include <sys/arch/x86_64/fpu.h>
|
||||||
#include <sys/arch/x86_64/gdt.h>
|
#include <sys/arch/x86_64/gdt.h>
|
||||||
#include <sys/arch/x86_64/idt.h>
|
#include <sys/arch/x86_64/idt.h>
|
||||||
#include <sys/error_handling/panic.h>
|
#include <sys/errhnd/panic.h>
|
||||||
#include <sys/gfx/flanterm/backends/fb.h>
|
#include <sys/gfx/flanterm/backends/fb.h>
|
||||||
#include <sys/gfx/flanterm/flanterm.h>
|
#include <sys/gfx/flanterm/flanterm.h>
|
||||||
#include <sys/log.h>
|
#include <sys/log.h>
|
||||||
#include <sys/printf.h>
|
#include <sys/printf.h>
|
||||||
|
#include <fs/vfs.h>
|
||||||
|
#include <fs/hellofs.h>
|
||||||
|
|
||||||
__attribute__((
|
__attribute__((
|
||||||
used, section(".limine_requests"))) static volatile LIMINE_BASE_REVISION(3);
|
used, section(".limine_requests"))) static volatile LIMINE_BASE_REVISION(3);
|
||||||
|
@ -84,12 +86,22 @@ void kmain(void) {
|
||||||
while (1)
|
while (1)
|
||||||
asm("hlt");
|
asm("hlt");
|
||||||
}
|
}
|
||||||
|
|
||||||
syscall_init();
|
syscall_init();
|
||||||
pit_init(1000);
|
pit_init(1000);
|
||||||
sched_init();
|
sched_init();
|
||||||
|
|
||||||
|
vfs_init();
|
||||||
|
if (hellofs_init() < 0) {
|
||||||
|
log("kernel - Failed to initialize HelloFS\n");
|
||||||
|
} else {
|
||||||
|
log("kernel - HelloFS initialized successfully\n");
|
||||||
|
}
|
||||||
|
|
||||||
panic("No working initialization program found. (This is normal due to Soaplin's current state, so please do not report this as a bug)");
|
|
||||||
|
|
||||||
|
panic("No working initialization program found. (This is normal due to "
|
||||||
|
"Soaplin's current state, so please do not report this as a bug)");
|
||||||
|
|
||||||
log("kernel - Soaplin initialized sucessfully.\n");
|
log("kernel - Soaplin initialized sucessfully.\n");
|
||||||
|
|
||||||
|
|
|
@ -4,38 +4,40 @@
|
||||||
char bcd;
|
char bcd;
|
||||||
|
|
||||||
unsigned char read_register(unsigned char reg) {
|
unsigned char read_register(unsigned char reg) {
|
||||||
__asm__ volatile("cli");
|
__asm__ volatile("cli");
|
||||||
outb(RTC_COMMAND, reg);
|
outb(RTC_COMMAND, reg);
|
||||||
return inb(RTC_DATA);
|
return inb(RTC_DATA);
|
||||||
__asm__ volatile("sti");
|
__asm__ volatile("sti");
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_register(unsigned char reg, unsigned char value) {
|
void write_register(unsigned char reg, unsigned char value) {
|
||||||
__asm__ volatile("cli");
|
__asm__ volatile("cli");
|
||||||
outb(RTC_COMMAND, reg);
|
outb(RTC_COMMAND, reg);
|
||||||
outb(RTC_DATA, value);
|
outb(RTC_DATA, value);
|
||||||
__asm__ volatile("sti");
|
__asm__ volatile("sti");
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char bcd2bin(unsigned char in_bcd) {
|
unsigned char bcd2bin(unsigned char in_bcd) {
|
||||||
return (bcd) ? ((in_bcd >> 4) * 10) + (in_bcd & 0x0F) : in_bcd;
|
return (bcd) ? ((in_bcd >> 4) * 10) + (in_bcd & 0x0F) : in_bcd;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rtc_init() {
|
int rtc_init() {
|
||||||
__asm__ volatile("cli");
|
__asm__ volatile("cli");
|
||||||
unsigned char status;
|
unsigned char status;
|
||||||
status = read_register(RTC_STATUS);
|
status = read_register(RTC_STATUS);
|
||||||
status |= 0x02; // 24 hour clock
|
status |= 0x02; // 24 hour clock
|
||||||
status |= 0x10; // update ended interrupts
|
status |= 0x10; // update ended interrupts
|
||||||
status &= ~0x20; // no alarm interrupts
|
status &= ~0x20; // no alarm interrupts
|
||||||
status &= ~0x40; // no periodic interrupt
|
status &= ~0x40; // no periodic interrupt
|
||||||
bcd = !(status & 0x04); // check if data type is BCD
|
bcd = !(status & 0x04); // check if data type is BCD
|
||||||
write_register(RTC_STATUS, status);
|
write_register(RTC_STATUS, status);
|
||||||
|
|
||||||
outb(0x70, 0x8B); // select register B, and disable NMI
|
outb(0x70, 0x8B); // select register B, and disable NMI
|
||||||
char prev=inb(0x71); // read the current value of register B
|
char prev = inb(0x71); // read the current value of register B
|
||||||
outb(0x70, 0x8B); // set the index again (a read will reset the index to register D)
|
outb(0x70,
|
||||||
outb(0x71, prev | 0x40); // write the previous value ORed with 0x40. This turns on bit 6 of register B
|
0x8B); // set the index again (a read will reset the index to register D)
|
||||||
__asm__ volatile("sti");
|
outb(0x71, prev | 0x40); // write the previous value ORed with 0x40. This
|
||||||
return 0;
|
// turns on bit 6 of register B
|
||||||
|
__asm__ volatile("sti");
|
||||||
|
return 0;
|
||||||
}
|
}
|
20
kernel/src/sys/arch/x86_64/rtc.h
Executable file → Normal file
20
kernel/src/sys/arch/x86_64/rtc.h
Executable file → Normal file
|
@ -1,17 +1,17 @@
|
||||||
#ifndef __TIME_H
|
#ifndef __TIME_H
|
||||||
#define __TIME_H
|
#define __TIME_H
|
||||||
|
|
||||||
#define RTC_COMMAND 0x70
|
#define RTC_COMMAND 0x70
|
||||||
#define RTC_DATA 0x71
|
#define RTC_DATA 0x71
|
||||||
#define RTC_STATUS 0x0B
|
#define RTC_STATUS 0x0B
|
||||||
|
|
||||||
#define RTC_SECONDS 0x00
|
#define RTC_SECONDS 0x00
|
||||||
#define RTC_MINUTES 0x02
|
#define RTC_MINUTES 0x02
|
||||||
#define RTC_HOURS 0x04
|
#define RTC_HOURS 0x04
|
||||||
#define RTC_DAY_OF_WEEK 0x06
|
#define RTC_DAY_OF_WEEK 0x06
|
||||||
#define RTC_DAY 0x07
|
#define RTC_DAY 0x07
|
||||||
#define RTC_MONTH 0x08
|
#define RTC_MONTH 0x08
|
||||||
#define RTC_YEAR 0x09
|
#define RTC_YEAR 0x09
|
||||||
|
|
||||||
int rtc_init();
|
int rtc_init();
|
||||||
|
|
||||||
|
|
|
@ -65,10 +65,9 @@ void __panic_display_ascii_art() {
|
||||||
"halt the PC.\n");
|
"halt the PC.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void panic(char *msg) {
|
void panic(char *msg) {
|
||||||
__panic_display_ascii_art();
|
__panic_display_ascii_art();
|
||||||
|
|
||||||
log("\n");
|
log("\n");
|
||||||
log("%s\n", msg);
|
log("%s\n", msg);
|
||||||
log("\n");
|
log("\n");
|
Loading…
Add table
Add a link
Reference in a new issue