Started on path resolution algorithm
- The algorithm will work once I am of better mind to deal with raw C strings - The resolution should look at each entry divided by '/'. if the entry is not there then we can quit early, however for now I am mostly concerned with getting the names of directory entries we would need to look for.
This commit is contained in:
parent
dbb147e110
commit
94a2de3847
5
Makefile
5
Makefile
@ -5,7 +5,7 @@ CC = ${HOME}/opt/cross/bin/i686-elf-gcc
|
||||
CPP = ${HOME}/opt/cross/bin/i686-elf-g++
|
||||
CFLAGS = -ffreestanding -Og -ggdb -Wall -Wextra
|
||||
|
||||
OFILES =$(BUILD_DIR)/boot.o $(BUILD_DIR)/kterm.o $(BUILD_DIR)/kernel.o $(BUILD_DIR)/memory.o $(BUILD_DIR)/paging.o $(BUILD_DIR)/VFS.o $(BUILD_DIR)/pit.o $(BUILD_DIR)/time.o $(BUILD_DIR)/keyboard.o $(BUILD_DIR)/io.o $(BUILD_DIR)/processor.o $(BUILD_DIR)/gdtc.o $(BUILD_DIR)/idt.o $(BUILD_DIR)/pic.o $(BUILD_DIR)/sv-terminal.o $(BUILD_DIR)/string.o $(BUILD_DIR)/prekernel.o $(BUILD_DIR)/KHeap.o $(BUILD_DIR)/pci.o $(BUILD_DIR)/pcidevice.o $(BUILD_DIR)/atapiDevice.o $(BUILD_DIR)/ataDevice.o $(BUILD_DIR)/rsdp.o $(BUILD_DIR)/acpi.o
|
||||
OFILES =$(BUILD_DIR)/boot.o $(BUILD_DIR)/Path.o $(BUILD_DIR)/kterm.o $(BUILD_DIR)/kernel.o $(BUILD_DIR)/memory.o $(BUILD_DIR)/paging.o $(BUILD_DIR)/VFS.o $(BUILD_DIR)/pit.o $(BUILD_DIR)/time.o $(BUILD_DIR)/keyboard.o $(BUILD_DIR)/io.o $(BUILD_DIR)/processor.o $(BUILD_DIR)/gdtc.o $(BUILD_DIR)/idt.o $(BUILD_DIR)/pic.o $(BUILD_DIR)/sv-terminal.o $(BUILD_DIR)/string.o $(BUILD_DIR)/prekernel.o $(BUILD_DIR)/KHeap.o $(BUILD_DIR)/pci.o $(BUILD_DIR)/pcidevice.o $(BUILD_DIR)/atapiDevice.o $(BUILD_DIR)/ataDevice.o $(BUILD_DIR)/rsdp.o $(BUILD_DIR)/acpi.o
|
||||
|
||||
SRC_DIR = source
|
||||
BUILD_DIR = build
|
||||
@ -133,10 +133,11 @@ $(BUILD_DIR)/KHeap.o:
|
||||
$(BUILD_DIR)/prekernel.o:
|
||||
$(CPP) -c $(SRC_DIR)/kernel/prekernel/prekernel.cpp -o $(BUILD_DIR)/prekernel.o $(CFLAGS) -fno-exceptions -fno-rtti
|
||||
|
||||
|
||||
$(BUILD_DIR)/processor.o:
|
||||
$(CPP) -c $(SRC_DIR)/kernel/i386/processor.cpp -o $(BUILD_DIR)/processor.o $(CFLAGS) -fno-exceptions -fno-rtti
|
||||
|
||||
$(BUILD_DIR)/Path.o:
|
||||
$(CPP) -c $(SRC_DIR)/kernel/vfs/Path.cpp -o $(BUILD_DIR)/Path.o $(CFLAGS) -fno-exceptions -fno-rtti
|
||||
|
||||
# Assembly -> Object files
|
||||
$(BUILD_DIR)/boot.o:
|
||||
|
@ -48,6 +48,10 @@ extern "C" void kernel ()
|
||||
|
||||
FileSystem::initialize();
|
||||
|
||||
// Testing my path resolution functions
|
||||
Path test = Path("/boot/myos.bin");
|
||||
FileSystem::ResolvePath(test);
|
||||
|
||||
|
||||
#ifdef USERMODE_RELEASE
|
||||
// Lets jump into user mode
|
||||
|
83
source/kernel/vfs/Path.cpp
Normal file
83
source/kernel/vfs/Path.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
//
|
||||
// Created by nigel on 19/02/23.
|
||||
//
|
||||
#include "Path.h"
|
||||
#include "../memory/KernelHeap.h"
|
||||
String::String(char* characters)
|
||||
: chars(characters)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
char* String::str(){
|
||||
return chars;
|
||||
}
|
||||
|
||||
unsigned int String::length ()
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while ( chars[i] != '\0'){
|
||||
i++;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
// Returns a null character if size exceeds limits
|
||||
char String::operator[] (size_t idx)
|
||||
{
|
||||
if( idx > this->length())
|
||||
return '\0';
|
||||
|
||||
return chars[idx];
|
||||
}
|
||||
|
||||
const char String::operator[](size_t idx) const {
|
||||
return (const char) chars[idx];
|
||||
}
|
||||
|
||||
StringView::StringView(String &string, unsigned int start, unsigned int end)
|
||||
: String(string), begin(start), end(end)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
char* StringView::str(){
|
||||
char* str = (char*) malloc((this->length() * sizeof(char))+1);
|
||||
|
||||
int index = 0;
|
||||
for ( int i = begin; i < end ; i++){
|
||||
str[index] = chars[i];
|
||||
index++;
|
||||
}
|
||||
chars[index+1] ='\0';
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
Path::Path(char *path)
|
||||
: path(String(path))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Path::Path(String &path)
|
||||
: path(path)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
StringView Path::getbasename()
|
||||
{
|
||||
unsigned int path_length = path.length();
|
||||
int i = path_length;
|
||||
while (path[i] != '/')
|
||||
i--;
|
||||
|
||||
return StringView(path,i +1, path_length);
|
||||
}
|
||||
|
||||
char* Path::str() {
|
||||
return path.str();
|
||||
}
|
46
source/kernel/vfs/Path.h
Normal file
46
source/kernel/vfs/Path.h
Normal file
@ -0,0 +1,46 @@
|
||||
//
|
||||
// Created by nigel on 19/02/23.
|
||||
//
|
||||
#pragma once
|
||||
#include <stddef.h>
|
||||
|
||||
class String {
|
||||
public:
|
||||
String(char* characters);
|
||||
String(String&) = default;
|
||||
unsigned int length();
|
||||
|
||||
char* str ();
|
||||
char operator[](size_t index) ;
|
||||
const char operator[](size_t idx) const;
|
||||
|
||||
protected:
|
||||
char* chars;
|
||||
|
||||
|
||||
};
|
||||
|
||||
class StringView : String {
|
||||
public:
|
||||
StringView(String& string, unsigned int start, unsigned int end );
|
||||
char* str ();
|
||||
private:
|
||||
unsigned int begin;
|
||||
unsigned int end;
|
||||
};
|
||||
|
||||
class Path{
|
||||
public:
|
||||
Path(String& path);
|
||||
Path(char* path);
|
||||
|
||||
StringView getbasename();
|
||||
|
||||
char* str();
|
||||
|
||||
private:
|
||||
String path;
|
||||
|
||||
};
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "../drivers/ata/ataDevice.h"
|
||||
#include "../partitiontable/mbr/MasterBootRecord.h"
|
||||
#include "../memory/KernelHeap.h"
|
||||
#include "../../lib/include/string.h"
|
||||
#include "Path.h"
|
||||
#include "../filesystem/FAT/DirectoryEntry.h"
|
||||
|
||||
MOUNT_INFO mountInfo;
|
||||
@ -360,4 +360,59 @@ void FileSystem::initialize()
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
char* FindNextEntryName (char* path )
|
||||
{
|
||||
int length = strlen(path);
|
||||
|
||||
char* name = path;
|
||||
int i = 0;
|
||||
|
||||
if( name[0] == '/')
|
||||
i++;
|
||||
|
||||
while ( name[i] != '/' && i <= length)
|
||||
i++;
|
||||
|
||||
char* s = (char*) malloc(i + 1 * sizeof(char));
|
||||
for ( int a = 0; a < i; a++)
|
||||
s[a] = path[a];
|
||||
|
||||
s[i + 1] = '\0';
|
||||
|
||||
return s;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FileSystem::ResolvePath(Path &path)
|
||||
{
|
||||
char* string_path = path.str();
|
||||
void* cpy = string_path;
|
||||
|
||||
bool isAbsolutePath = string_path[0] == '/';
|
||||
if(isAbsolutePath)
|
||||
{
|
||||
// strip the first slash
|
||||
string_path++;
|
||||
}
|
||||
|
||||
char* entry_name = FindNextEntryName(string_path);
|
||||
printf("Look for entry with name: %s\n", entry_name);
|
||||
int skip = strlen(entry_name);
|
||||
free(entry_name);
|
||||
|
||||
|
||||
entry_name = FindNextEntryName(string_path + skip);
|
||||
printf("Look for entry with name: %s\n", entry_name);
|
||||
skip = strlen(entry_name);
|
||||
free(entry_name);
|
||||
|
||||
|
||||
|
||||
|
||||
free(cpy);
|
||||
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include "Path.h"
|
||||
|
||||
#define FS_FILE 0
|
||||
#define FS_DIRECTORY 1
|
||||
#define FS_INVALID 2
|
||||
@ -73,4 +75,6 @@ extern PFILESYSTEM _filesystems[DEVICE_MAX];
|
||||
public:
|
||||
static void initialize();
|
||||
|
||||
static void ResolvePath(Path& path);
|
||||
|
||||
};
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
// NOTE: These should not be inline
|
||||
inline void* memset (void* ptr, int value, size_t num){
|
||||
inline void* memset (void* ptr, int value, size_t num)
|
||||
{
|
||||
for( int i = 0; i < num; i++ )
|
||||
{
|
||||
unsigned char* data = (unsigned char*)ptr+ i;
|
||||
@ -12,19 +13,19 @@ inline void* memset (void* ptr, int value, size_t num){
|
||||
|
||||
|
||||
inline int memcmp( const void* ptr1, const void* ptr2, size_t num)
|
||||
{
|
||||
const unsigned char * cs = (const unsigned char*) ptr1;
|
||||
const unsigned char * ct = (const unsigned char*) ptr2;
|
||||
{
|
||||
const unsigned char * cs = (const unsigned char*) ptr1;
|
||||
const unsigned char * ct = (const unsigned char*) ptr2;
|
||||
|
||||
|
||||
for (int i = 0 ; i < num ; i++, cs++, ct++ ){
|
||||
if( *cs < *ct){
|
||||
return -1;
|
||||
} else if( *cs > *ct){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
for (int i = 0 ; i < num ; i++, cs++, ct++ ){
|
||||
if( *cs < *ct){
|
||||
return -1;
|
||||
} else if( *cs > *ct){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user