diff --git a/Makefile b/Makefile index bf446589..58d56f58 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ include Makefile.inc DIRS = core -.PHONY: all clean install core run +.PHONY: all clean install core run curses all: kernel @@ -17,6 +17,9 @@ install: kernel run: bootdisk.img qemu -fda bootdisk.img +curses: bootdisk.img + qemu -curses -fda bootdisk.img + kernel: start.o link.ld main.o core ${LD} -T link.ld -o kernel *.o core/*.o core/fs/*.o diff --git a/Makefile.inc b/Makefile.inc index 4abc1818..b075a67c 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -1,5 +1,5 @@ CC = gcc LD = ld -m elf_i386 -CFLAGS = -Wall -Wextra -pedantic -m32 -O0 -std=c99 -finline-functions -nostdinc -ffreestanding +CFLAGS = -Wall -Wextra -pedantic -m32 -O0 -std=c99 -finline-functions -fno-stack-protector -nostdinc -ffreestanding NASM = nasm -f elf diff --git a/core/fs/ext2_initrd.c b/core/fs/ext2_initrd.c index c5bb2488..3071acdd 100644 --- a/core/fs/ext2_initrd.c +++ b/core/fs/ext2_initrd.c @@ -29,7 +29,17 @@ read_initrd( uint32_t size, uint8_t *buffer ) { - return 0; + ext2_inodetable_t * inode = ext2_get_inode(node->inode); + uint32_t end; + if (offset + size > inode->size) { + end = inode->size; + } else { + end = offset + size; + } + uint32_t size_to_read = end - offset; + // TODO: proper block reading, read files larger than one block + memcpy(buffer, ext2_get_block(inode->block[0]) + offset, size_to_read); + return size_to_read; } uint32_t @@ -130,7 +140,7 @@ finddir_initrd( return NULL; } fs_node_t * outnode = malloc(sizeof(fs_node_t)); - initrd_node_from_file(direntry->inode, direntry, outnode); + initrd_node_from_file(ext2_get_inode(direntry->inode), direntry, outnode); return outnode; } @@ -204,22 +214,22 @@ initrd_node_from_dirent( /* File Flags */ fnode->flags = 0; if (inode->mode & EXT2_S_IFREG) { - fnode->flags &= FS_FILE; + fnode->flags |= FS_FILE; } if (inode->mode & EXT2_S_IFDIR) { - fnode->flags &= FS_DIRECTORY; + fnode->flags |= FS_DIRECTORY; } if (inode->mode & EXT2_S_IFBLK) { - fnode->flags &= FS_BLOCKDEVICE; + fnode->flags |= FS_BLOCKDEVICE; } if (inode->mode & EXT2_S_IFCHR) { - fnode->flags &= FS_CHARDEVICE; + fnode->flags |= FS_CHARDEVICE; } if (inode->mode & EXT2_S_IFIFO) { - fnode->flags &= FS_PIPE; + fnode->flags |= FS_PIPE; } if (inode->mode & EXT2_S_IFLNK) { - fnode->flags &= FS_SYMLINK; + fnode->flags |= FS_SYMLINK; } fnode->read = read_initrd; fnode->write = write_initrd; diff --git a/core/vfs.c b/core/vfs.c index 751a2991..e3cd5660 100644 --- a/core/vfs.c +++ b/core/vfs.c @@ -84,8 +84,10 @@ kopen( free((void *)path); return NULL; } else if (depth == path_depth - 1) { + open_fs(node_ptr, 1, 0); return node_ptr; } + path_offset += strlen(path_offset) + 1; } free((void *)path); return NULL; diff --git a/initrd b/initrd index b6a94d54..2322b42a 100644 Binary files a/initrd and b/initrd differ diff --git a/main.c b/main.c index 17b282cd..21cec76b 100644 --- a/main.c +++ b/main.c @@ -93,11 +93,19 @@ main(struct multiboot *mboot_ptr) { uint32_t module_end = *(uint32_t*)(mboot_ptr->mods_addr+4); initrd_mount(module_start, module_end); - fs_node_t * test_file = kopen("/hello.txt", NULL); + kprintf("Opening /etc/kernel/hello.txt... "); + fs_node_t * test_file = kopen("/etc/kernel/hello.txt", NULL); if (!test_file) { - kprintf("Couldn't find /hello.txt\n"); + kprintf("Couldn't find hello.txt\n"); } - kprintf("Found %s at inode %d\n", test_file->name, test_file->inode); + kprintf("Found at inode %d\n", test_file->name, test_file->inode); + char buffer[256]; + uint32_t bytes_read; + bytes_read = read_fs(test_file, 0, 255, &buffer); + kprintf("Read %d bytes from file:\n", bytes_read); + kprintf("%s\n", buffer); + kprintf("| end file\n"); + close_fs(test_file); #if 0 ext2_superblock_t * superblock = (ext2_superblock_t *)(module_start + 1024);