Skip to content

Commit

Permalink
src: filesystem: add core FAT16 functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
pcichowski committed Dec 12, 2022
1 parent 13924e4 commit 6cb7abe
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FILES = ./build/kernel.asm.o ./build/kernel.o ./build/idt/idt.asm.o ./build/idt/idt.o ./build/memory/memory.o ./build/io/io.asm.o ./build/memory/heap/heap.o ./build/memory/heap/kheap.o ./build/memory/pmap/pmap.o ./build/memory/pmap/pmap.asm.o ./build/disk/disk.o ./build/filesystem/pathparser.o ./build/string/string.o ./build/disk/disk_stream.o ./build/filesystem/file.o
FILES = ./build/kernel.asm.o ./build/kernel.o ./build/idt/idt.asm.o ./build/idt/idt.o ./build/memory/memory.o ./build/io/io.asm.o ./build/memory/heap/heap.o ./build/memory/heap/kheap.o ./build/memory/pmap/pmap.o ./build/memory/pmap/pmap.asm.o ./build/disk/disk.o ./build/filesystem/pathparser.o ./build/string/string.o ./build/disk/disk_stream.o ./build/filesystem/file.o ./build/filesystem/fat/fat16.o

INCLUDES = -I./src

Expand Down Expand Up @@ -58,6 +58,9 @@ all: ./bin/boot.bin ./bin/kernel.bin
./build/filesystem/file.o: ./src/filesystem/file.c
i686-elf-gcc $(INCLUDES) -I./src/filesystem $(FLAGS) -std=gnu99 -c ./src/filesystem/file.c -o ./build/filesystem/file.o

./build/filesystem/fat/fat16.o: ./src/filesystem/fat/fat16.c
i686-elf-gcc $(INCLUDES) -I./src/filesystem $(FLAGS) -std=gnu99 -c ./src/filesystem/fat/fat16.c -o ./build/filesystem/fat/fat16.o

./build/filesystem/pathparser.o: ./src/filesystem/pathparser.c
i686-elf-gcc $(INCLUDES) -I./src/filesystem $(FLAGS) -std=gnu99 -c ./src/filesystem/pathparser.c -o ./build/filesystem/pathparser.o

Expand Down
Empty file added build/filesystem/fat/.gitkeep
Empty file.
28 changes: 28 additions & 0 deletions src/filesystem/fat/fat16.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "fat16.h"
#include "status.h"
#include "string/string.h"

int fat16_resolve(struct disk *disk);
void *fat16_open(struct disk *disk, struct path_part *path, FILE_MODE mode);

struct filesystem fat16_fs = {
.resolve = fat16_resolve,
.open = fat16_open
};

struct filesystem *
fat16_init() {
strcpy(fat16_fs.name, "FAT16");
return &fat16_fs;
}

int
fat16_resolve(struct disk *disk) {
return 0;
}

void *
fat16_open(struct disk *disk, struct path_part *path, FILE_MODE mode)
{
return 0;
}
8 changes: 8 additions & 0 deletions src/filesystem/fat/fat16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef FAT16_H
#define FAT16_H

#include "file.h"

struct filesystem *fat16_init();

#endif // FAT16_H
3 changes: 2 additions & 1 deletion src/filesystem/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "memory/heap/kheap.h"
#include "status.h"
#include "kernel.h"
#include "fat/fat16.h"

struct filesystem *filesystems[MAX_FILESYSTEMS];

Expand Down Expand Up @@ -40,7 +41,7 @@ fs_insert_filesystem(struct filesystem *filesystem)
static void
fs_static_load()
{
//fs_insert_filesystem(fat16_init());
fs_insert_filesystem(fat16_init());
}

void
Expand Down
13 changes: 8 additions & 5 deletions src/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "filesystem/pathparser.h"
#include "string/string.h"
#include "disk/disk_stream.h"
#include "filesystem/file.h"

uint16_t *video_mem = 0;

Expand Down Expand Up @@ -100,12 +101,18 @@ kernel_main()
print(kernel_logo5);
print(kernel_logo6);

print("\nWelcome to silentOS v0.0.1\n");
print("\nWelcome to silentOS v0.0.2\n");

// initialize the heap
kheap_init();

// initialize fat16 filesystem
fs_init();

// search for and initialize available disks
disk_search_and_init();

// initialize the interrupt descriptor table
idt_init();

kernel_chunk = pmap_new_chunk(PMAP_IS_WRITEABLE | PMAP_IS_PRESENT | PMAP_ACCESS_FROM_ALL);
Expand All @@ -117,11 +124,7 @@ kernel_main()
enable_interrupts();


struct disk_stream *stream = diskstream_new(0);

diskstream_seek(stream, 0x201);
char c = 0;
diskstream_read(stream, &c, 1);
while (1)
{

Expand Down
13 changes: 13 additions & 0 deletions src/string/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ strnlen(const char *ptr, int max_length)
return i;
}

char *strcpy(char *dest, const char *src) {
char *tmp = dest;
while (*src != 0) {
*dest = *src;
src += 1;
dest += 1;
}

*dest = 0x00;

return tmp;
}

int
is_digit(char c)
{
Expand Down
1 change: 1 addition & 0 deletions src/string/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

int strlen(const char *ptr);
int strnlen(const char *ptr, int max_length);
char *strcpy(char *dest, const char *src);
int is_digit(char c);
int ascii_char_to_digit(char c);

Expand Down

0 comments on commit 6cb7abe

Please sign in to comment.