diff options
author | Marvin Borner | 2020-08-27 22:10:55 +0200 |
---|---|---|
committer | Marvin Borner | 2020-08-27 22:10:55 +0200 |
commit | 5565c4f1d12d9bdbabcc878541d3b81be45d4cf3 (patch) | |
tree | 89df697239af72926b3ea52170afcaf19b3e51f9 /kernel/features | |
parent | fa2d52e708b3f33008d60f5fbea3e2e954f1db6f (diff) |
Added doubly indirect pointer support
Diffstat (limited to 'kernel/features')
-rw-r--r-- | kernel/features/fs.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/kernel/features/fs.c b/kernel/features/fs.c index 7a9f209..52d1bb0 100644 --- a/kernel/features/fs.c +++ b/kernel/features/fs.c @@ -48,7 +48,7 @@ struct inode *get_inode(int i) u32 read_indirect(u32 indirect, u32 block_num) { char *data = buffer_read(indirect); - return *(u32 *)((u32)data + block_num * 4); + return *(u32 *)((u32)data + block_num * sizeof(u32)); } void *read_inode(struct inode *in) @@ -72,17 +72,24 @@ void *read_inode(struct inode *in) int blocknum; char *data; + // TODO: Support treply indirect pointers + // TODO: This can be heavily optimized by saving the indirect block lists for (int i = 0; i < num_blocks; i++) { if (i < 12) { blocknum = in->block[i]; data = buffer_read(blocknum); memcpy((u32 *)((u32)buf + i * BLOCK_SIZE), data, BLOCK_SIZE); - } else { - // TODO: Support doubly and triply pointers + } else if (i < BLOCK_COUNT + 12) { indirect = in->block[12]; blocknum = read_indirect(indirect, i - 12); data = buffer_read(blocknum); memcpy((u32 *)((u32)buf + (i - 1) * BLOCK_SIZE), data, BLOCK_SIZE); + } else { + indirect = in->block[13]; + blocknum = read_indirect(indirect, (i - (BLOCK_COUNT + 12)) / BLOCK_COUNT); + blocknum = read_indirect(blocknum, (i - (BLOCK_COUNT + 12)) % BLOCK_COUNT); + data = buffer_read(blocknum); + memcpy((u32 *)((u32)buf + (i - 1) * BLOCK_SIZE), data, BLOCK_SIZE); } /* printf("Loaded %d of %d\n", i + 1, num_blocks); */ } |