Skip to content
Snippets Groups Projects
Commit 5e420234 authored by Byron Lathi's avatar Byron Lathi
Browse files

move filesystem code

parent a9962197
No related branches found
No related tags found
No related merge requests found
......@@ -7,10 +7,14 @@ int main()
sys_write(1, "Type filename: ", 15);
sys_read(0, path, 64);
int fd = sys_open(path);
sys_write(1, "Got fd ", 7);
char fdc = fd + '0';
sys_write(1, &fdc, 1);
sys_write(1, "\n", 1);
if (fd == -1) {
sys_write(1, "Error\n", 6);
} else {
sys_write(1, "Got fd ", 7);
char fdc = fd + '0';
sys_write(1, &fdc, 1);
sys_write(1, "\n", 1);
}
return 0;
......
#include <types.h>
#include <lib.h>
#include <Devices/Storage/atapio.h>
#include "ext2.h"
#include "atapio.h"
static superblock_t superblock;
static uint32_t ext2_base;
......@@ -155,6 +155,11 @@ uint32_t ext2_parse_path_to_inode_num(int8_t* filename)
tmpfilename++;
int8_t* end_pointer = tmpfilename;
// just a hack to return the root file node
if (!*tmpfilename) {
return 2;
}
int more_to_do = 1;
uint32_t inode = 2;
......@@ -176,7 +181,7 @@ uint32_t ext2_parse_path_to_inode_num(int8_t* filename)
//printf("\n%s\n", filename);
// this will now find the first entry in the root directory
inode = ext2_find_inode_num2(tmpfilename, inode);
if (!inode) {
......
......@@ -61,6 +61,27 @@ typedef struct block_group_descriptor {
};
} block_group_descriptor_t;
#define EXT2_FIFO 0x1000
#define EXT2_CHARDEV 0x2000
#define EXT2_DIR 0x4000
#define EXT2_BLKDEV 0x6000
#define EXT2_FILE 0x8000
#define EXT2_SYMLINK 0xA000
#define EXT2_SOCKET 0xC000
#define EXT2_OTHER_EXEC 0x001
#define EXT2_OTHER_WRITE 0x002
#define EXT2_OTHER_READ 0x004
#define EXT2_GROUP_EXEC 0x008
#define EXT2_GROUP_WRITE 0x010
#define EXT2_GROUP_READ 0x020
#define EXT2_USER_EXEC 0x040
#define EXT2_USER_WRITE 0x080
#define EXT2_USER_READ 0x100
#define EXT2_STICKY 0x200
#define EXT2_SET_GID 0x400
#define EXT2_SET_UID 0x800
typedef struct inode {
union {
uint8_t data8[128];
......
File moved
......@@ -2,7 +2,7 @@
#include <lib.h>
#include <x86_desc.h>
#include <paging.h>
#include <Devices/Storage/ext2.h>
#include <Filesystem/ext2.h>
#include <Devices/terminal.h>
#include "execute.h"
......
#include <types.h>
#include <lib.h>
#include <Filesystem/ext2.h>
#include "syscalls.h"
#include "execute.h"
......@@ -20,7 +21,20 @@ int32_t sys_write(int32_t fd, const void* buf, int32_t len)
int32_t sys_open(uint8_t* name)
{
inode_t inode;
printf("sys_open\n");
uint32_t inode_num = ext2_parse_path_to_inode_num((int8_t*)name);
if (!inode_num) {
return -1;
}
ext2_get_inode(inode_num, &inode);
printf("Inode %x type %x ", inode_num, inode.type_permissions);
if (inode.type_permissions & EXT2_DIR) {
printf("is a directory.\n");
} else if (inode.type_permissions & EXT2_FILE) {
printf("is a file.\n");
}
return -1;
}
......
......@@ -7,8 +7,8 @@
#include "Interrupts/i8259.h"
#include "Devices/keyboard.h"
#include "Devices/Storage/atapio.h"
#include "Devices/Storage/mbr.h"
#include "Devices/Storage/ext2.h"
#include "Filesystem/mbr.h"
#include "Filesystem/ext2.h"
#include "paging.h"
#include "Syscalls/syscalls.h"
......@@ -100,6 +100,14 @@ void entry(unsigned long magic, unsigned long addr) {
// we can't use mbi after paging is initialized since its not in kernel memory
uint32_t fb_addr = mbi->framebuffer_info.framebuffer_addr_low;
// copy over mmap (can't just do 1 since its a linked list)
int i;
uint8_t mmap[mbi->mmap_length];
for (i = 0; i < mbi->mmap_length; i++) {
mmap[i] = *((uint8_t*)mbi->mmap_addr + i);
}
uint32_t mmap_length = mbi->mmap_length;
init_paging();
kmap_large(fb_addr, fb_addr);
......@@ -112,6 +120,21 @@ void entry(unsigned long magic, unsigned long addr) {
//ata_info(ATA_MASTER);
//printf("hey mom look at this: %d", 1/0);
/*
memory_map_t* newmap = (memory_map_t*)mmap;
while ((uint32_t)newmap < (uint32_t)mmap + mmap_length) {
if (newmap->type == 1) {
printf("Usable memory:\n");
} else {
printf("Reserved Memory:\n");
}
printf("\tBase Addr: 0x%#x%#x\n", newmap->base_addr_high, newmap->base_addr_low);
printf("\tLength: 0x%#x%#x\n", newmap->length_high, newmap->length_low);
newmap = (memory_map_t*)((uint32_t)newmap + newmap->size + 4);
}
*/
mbr_t mbr;
ata_read_sectors(ATA_MASTER, 0, 1, mbr.data);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment