Clean comments up, merge ext2 inode block index code
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
TODO: Rewrite thread_init, it's shit
|
||||
TODO: execve() after fork() should inherit old thread's ioctx
|
||||
@@ -4,7 +4,6 @@
|
||||
struct chrdev {
|
||||
void *dev_data;
|
||||
|
||||
// TODO: maybe something like flush()
|
||||
ssize_t (*write) (struct chrdev *chr, const void *buf, size_t pos, size_t lim);
|
||||
ssize_t (*read) (struct chrdev *chr, void *buf, size_t pos, size_t lim);
|
||||
};
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
|
||||
struct vnode;
|
||||
|
||||
// TODO: something like device name alias
|
||||
// for example, /dev/root aliased to
|
||||
// /dev/ramN or /dev/sdXN
|
||||
enum dev_class {
|
||||
DEV_CLASS_BLOCK = 1,
|
||||
DEV_CLASS_CHAR = 2,
|
||||
|
||||
@@ -45,7 +45,6 @@ void fmtsiz(char *out, size_t sz) {
|
||||
out[l++] = 0;
|
||||
}
|
||||
|
||||
// TODO: make debugc a __weak function of a character
|
||||
void debugc(int level, char c) {
|
||||
#if defined(ARCH_AMD64)
|
||||
rs232_send(RS232_COM1, c);
|
||||
|
||||
-21
@@ -16,8 +16,6 @@
|
||||
#include "sys/mm.h"
|
||||
|
||||
static void user_init_start(void) {
|
||||
// TODO: Instead of allocating and reading the whole buffer, rewrite binfmt_elf in a way
|
||||
// to use lseek and stuff
|
||||
const char *init_filename = "/init";
|
||||
struct ofile fd;
|
||||
struct stat st;
|
||||
@@ -57,21 +55,12 @@ static void user_init_start(void) {
|
||||
panic("Failed to initialize user init process: %s\n", kstrerror(res));
|
||||
}
|
||||
|
||||
//file_buffer = kmalloc(st.st_size);
|
||||
//_assert(file_buffer);
|
||||
|
||||
//if ((bread = vfs_read(kernel_ioctx, &fd, file_buffer, st.st_size)) != st.st_size) {
|
||||
// panic("Failed to read init binary\n");
|
||||
//}
|
||||
|
||||
if ((res = elf_load(user_init, kernel_ioctx, &fd)) != 0) {
|
||||
panic("Failed to load ELF binary: %s\n", kstrerror(res));
|
||||
}
|
||||
|
||||
vfs_close(kernel_ioctx, &fd);
|
||||
|
||||
//kfree(file_buffer);
|
||||
|
||||
// Setup I/O context for init task
|
||||
struct ofile *stdin, *stdout, *stderr;
|
||||
|
||||
@@ -81,7 +70,6 @@ static void user_init_start(void) {
|
||||
_assert(stdout);
|
||||
stderr = stdout;
|
||||
|
||||
// TODO: use dev_find and open its node instead
|
||||
struct vnode *stdout_device;
|
||||
if ((res = dev_find(DEV_CLASS_CHAR, "tty0", &stdout_device)) != 0) {
|
||||
panic("%s: %s\n", "tty0", kstrerror(res));
|
||||
@@ -95,7 +83,6 @@ static void user_init_start(void) {
|
||||
}
|
||||
++stdout->refcount;
|
||||
|
||||
// TODO: use STDIN_/STDOUT_/STDERR_FILENO macros
|
||||
user_init->fds[0] = stdin;
|
||||
user_init->fds[1] = stdout;
|
||||
user_init->fds[2] = stderr;
|
||||
@@ -128,14 +115,6 @@ void init_func(void *arg) {
|
||||
panic("Failed to mount root device: %s\n", kstrerror(res));
|
||||
}
|
||||
|
||||
//// Mount something else
|
||||
//if ((res = dev_find(DEV_CLASS_BLOCK, "sda1", &root_dev)) != 0) {
|
||||
// panic("sda1: %s\n", kstrerror(res));
|
||||
//}
|
||||
//if ((res = vfs_mount(kernel_ioctx, "/mnt", root_dev->dev, "ext2", NULL)) != 0) {
|
||||
// panic("Failed to mount root device: %s\n", kstrerror(res));
|
||||
//}
|
||||
|
||||
// Start user init binary
|
||||
user_init_start();
|
||||
|
||||
|
||||
@@ -94,7 +94,6 @@ static int ext2_fs_umount(struct fs *fs) {
|
||||
}
|
||||
|
||||
static struct vnode *ext2_fs_get_root(struct fs *fs) {
|
||||
// TODO: make sure get_root is only called once per filesystem
|
||||
struct ext2_extsb *sb = fs->fs_private;
|
||||
kdebug("ext2_fs_get_root()\n");
|
||||
|
||||
|
||||
+22
-27
@@ -41,39 +41,34 @@ int ext2_write_block(struct fs *ext2, uint32_t block_no, const void *buf) {
|
||||
return res;
|
||||
}
|
||||
|
||||
int ext2_write_inode_block(struct fs *ext2, struct ext2_inode *inode, uint32_t index, const void *buf) {
|
||||
static uint32_t ext2_get_inode_block(struct fs *ext2, struct ext2_inode *inode, uint32_t index) {
|
||||
if (index < 12) {
|
||||
uint32_t block_number = inode->direct_blocks[index];
|
||||
return ext2_write_block(ext2, block_number, buf);
|
||||
return inode->direct_blocks[index];
|
||||
} else {
|
||||
// TODO
|
||||
//abort();
|
||||
panic("Not implemented\n");
|
||||
struct ext2_extsb *sb = (struct ext2_extsb *) ext2->fs_private;
|
||||
char buf[1024];
|
||||
int res;
|
||||
|
||||
if (index < 12 + (sb->block_size / 4)) {
|
||||
if ((res = ext2_read_block(ext2, inode->l1_indirect_block, buf)) < 0) {
|
||||
return res;
|
||||
}
|
||||
|
||||
return ((uint32_t *) buf)[index - 12];
|
||||
} else {
|
||||
panic("Inode block index has too high indirection level\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ext2_write_inode_block(struct fs *ext2, struct ext2_inode *inode, uint32_t index, const void *buf) {
|
||||
uint32_t block_number = ext2_get_inode_block(ext2, inode, index);
|
||||
return ext2_write_block(ext2, block_number, buf);
|
||||
}
|
||||
|
||||
int ext2_read_inode_block(struct fs *ext2, struct ext2_inode *inode, uint32_t index, void *buf) {
|
||||
if (index < 12) {
|
||||
// Use direct ptrs
|
||||
uint32_t block_number = inode->direct_blocks[index];
|
||||
return ext2_read_block(ext2, block_number, buf);
|
||||
} else {
|
||||
struct ext2_extsb *sb = (struct ext2_extsb *) ext2->fs_private;
|
||||
// Use buf as indirection block buffer (I think we're allowed to do so)
|
||||
|
||||
if (index < 12 + (sb->block_size / 4)) {
|
||||
// Single indirection
|
||||
if (ext2_read_block(ext2, inode->l1_indirect_block, buf) < 0) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
uint32_t block_number = ((uint32_t *) buf)[index - 12];
|
||||
return ext2_read_block(ext2, block_number, buf);
|
||||
} else {
|
||||
// Not implemented yet
|
||||
return -EIO;
|
||||
}
|
||||
}
|
||||
uint32_t block_number = ext2_get_inode_block(ext2, inode, index);
|
||||
return ext2_read_block(ext2, block_number, buf);
|
||||
}
|
||||
|
||||
int ext2_read_inode(struct fs *ext2, struct ext2_inode *inode, uint32_t ino) {
|
||||
|
||||
@@ -280,7 +280,7 @@ static int ext2_vnode_creat(struct vnode *at, const char *name, uid_t uid, gid_t
|
||||
|
||||
ent_inode->uid = uid;
|
||||
ent_inode->gid = gid;
|
||||
// TODO: only regular files can be created this way now
|
||||
// NOTE: only regular files can be created this way now
|
||||
ent_inode->type_perm = (mode & 0x1FF) | (EXT2_TYPE_REG);
|
||||
ent_inode->disk_sector_count = 0;
|
||||
ent_inode->size_lower = 0;
|
||||
@@ -479,7 +479,6 @@ static int ext2_vnode_truncate(struct vnode *vn, size_t length) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: replace this with getdents
|
||||
static ssize_t ext2_vnode_readdir(struct ofile *fd, struct dirent *vfsdir) {
|
||||
struct vnode *vn = fd->vnode;
|
||||
struct ext2_inode *inode = (struct ext2_inode *) vn->fs_data;
|
||||
|
||||
Reference in New Issue
Block a user