diff options
author | Marvin Borner | 2020-07-25 00:12:57 +0200 |
---|---|---|
committer | Marvin Borner | 2020-07-25 00:12:57 +0200 |
commit | 16c5b566d04e6cbf63f871bd569d4636a9e90d62 (patch) | |
tree | 3cc851f5608b33f7c0f690ef319e4aa5e6c2ebda | |
parent | e83d78eb48eaaeca83bb21a9da4f98904eed4671 (diff) |
Added fs wrapper
-rw-r--r-- | src/features/fs.c | 16 | ||||
-rw-r--r-- | src/inc/fs.h | 4 | ||||
-rw-r--r-- | src/lib/print.c | 1 | ||||
-rw-r--r-- | src/main.c | 2 |
4 files changed, 15 insertions, 8 deletions
diff --git a/src/features/fs.c b/src/features/fs.c index d505e31..c8136a8 100644 --- a/src/features/fs.c +++ b/src/features/fs.c @@ -48,7 +48,7 @@ u32 read_indirect(u32 indirect, u32 block_num) return *(u32 *)((u32)data + block_num * 4); } -void *read_file(struct inode *in) +void *read_inode(struct inode *in) { //assert(in); if (!in) @@ -78,17 +78,22 @@ void *read_file(struct inode *in) if (i < 12) { blocknum = in->block[i]; data = buffer_read(blocknum); - memcpy((u32 *)((u32)buf + i * BLOCK_SIZE), data, BLOCK_SIZE); + memcpy((u8 *)((u32)buf + i * BLOCK_SIZE), data, BLOCK_SIZE); } else { blocknum = read_indirect(indirect, i - 12); data = buffer_read(blocknum); - memcpy((u32 *)((u32)buf + (i - 1) * BLOCK_SIZE), data, BLOCK_SIZE); + memcpy((u8 *)((u32)buf + (i - 1) * BLOCK_SIZE), data, BLOCK_SIZE); } } return buf; } +void *read_file(const char *name, int dir_inode) +{ + return read_inode(get_inode(find_inode(name, dir_inode))); +} + int find_inode(const char *name, int dir_inode) { if (!dir_inode) @@ -101,7 +106,7 @@ int find_inode(const char *name, int dir_inode) for (u32 q = 0; q < i->blocks / 2; q++) { char *data = buffer_read(i->block[q]); - memcpy((u32 *)((u32)buf + (q * BLOCK_SIZE)), data, BLOCK_SIZE); + memcpy((u32 *)((u32)buf + q * BLOCK_SIZE), data, BLOCK_SIZE); } struct dirent *d = (struct dirent *)buf; @@ -110,7 +115,6 @@ int find_inode(const char *name, int dir_inode) do { // Calculate the 4byte aligned size of each entry sum += d->total_len; - //printf("%2d %10s\t%2d %3d\n", (int)d->inode, d->name, d->name_len, d->rec_len); if (strncmp((void *)d->name, name, d->name_len) == 0) { free(buf); return d->inode_num; @@ -130,7 +134,7 @@ void ls_root() for (u32 q = 0; q < i->blocks / 2; q++) { char *data = buffer_read(i->block[q]); - memcpy((u32 *)((u32)buf + (q * BLOCK_SIZE)), data, BLOCK_SIZE); + memcpy((u32 *)((u32)buf + q * BLOCK_SIZE), data, BLOCK_SIZE); } struct dirent *d = (struct dirent *)buf; diff --git a/src/inc/fs.h b/src/inc/fs.h index 222939b..b521ca6 100644 --- a/src/inc/fs.h +++ b/src/inc/fs.h @@ -73,6 +73,7 @@ struct inode { u32 fragment_addr; u8 os_specific_val2[12]; }; + #define INODE_SIZE (sizeof(struct inode)) struct dirent { @@ -93,7 +94,8 @@ struct file { int find_inode(const char *name, int dir_inode); struct inode *get_inode(int i); -void *read_file(struct inode *in); +void *read_inode(struct inode *in); +void *read_file(const char *name, int dir_inode); void ls_root(); // DEMO ;) #endif diff --git a/src/lib/print.c b/src/lib/print.c index 9379f68..b9cddfa 100644 --- a/src/lib/print.c +++ b/src/lib/print.c @@ -84,6 +84,7 @@ int vprintf(const char *format, va_list ap) return len; } +// TODO: Fix printf for *very* large strings (serial works) int printf(const char *format, ...) { va_list ap; @@ -28,7 +28,7 @@ void main(struct mem_info *mem_info, struct vid_info *vid_info) printf("hello\n"); ls_root(); - read_file(get_inode(find_inode("font24.bdf", 2))); + printf("%s", read_file("test.txt", 2)); while (1) { }; |