aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/fs/marfs
diff options
context:
space:
mode:
authorMarvin Borner2020-01-20 23:12:54 +0100
committerMarvin Borner2020-01-20 23:12:54 +0100
commit391ed256d21a6ae2e2456d1809f357e6e96e15d1 (patch)
tree0fe9ffb3c59bbfeb3d8a04ab7fc6efba60d81e79 /src/kernel/fs/marfs
parentd5d1749257ff8b9aa6b5ace4b4720b484a2860f3 (diff)
Added pure awesomeness
Actually quite some days of work but ok
Diffstat (limited to 'src/kernel/fs/marfs')
-rw-r--r--src/kernel/fs/marfs/directory.c11
-rw-r--r--src/kernel/fs/marfs/new_file.c8
-rw-r--r--src/kernel/fs/marfs/read_whole_file.c8
-rw-r--r--src/kernel/fs/marfs/sectorlevel.c4
4 files changed, 16 insertions, 15 deletions
diff --git a/src/kernel/fs/marfs/directory.c b/src/kernel/fs/marfs/directory.c
index d0a1bff..dce92b1 100644
--- a/src/kernel/fs/marfs/directory.c
+++ b/src/kernel/fs/marfs/directory.c
@@ -2,6 +2,7 @@
#include <kernel/fs/ata_pio.h>
#include <kernel/lib/stdlib.h>
#include <kernel/fs/marfs/marfs.h>
+#include <kernel/memory/kheap.h>
uint32_t marfs_new_dir(uint32_t uid)
{
@@ -17,7 +18,7 @@ void marfs_add_to_dir(uint32_t lba_inode, char *filename, uint32_t lba)
uint8_t *old = marfs_allocate_and_read_whole_file(lba_inode);
// Allocate memory
- uint8_t *contents = kmalloc(inode->size + strlen(filename) + 1 + 4);
+ uint8_t *contents = (uint8_t *) kmalloc((uint32_t) (inode->size + strlen(filename) + 1 + 4));
// Copy the content
uint8_t last_was_null = 0;
@@ -26,16 +27,16 @@ void marfs_add_to_dir(uint32_t lba_inode, char *filename, uint32_t lba)
if (old[i] == 0 && last_was_null) continue;
contents[new_size++] = old[i];
- last_was_null = (old[i] == 0);
+ last_was_null = (uint8_t) (old[i] == 0);
}
kfree(old);
// Append new file
- for (size_t i = 0; i <= strlen(filename); i++) contents[new_size++] = filename[i];
- for (signed char j = 24; j > 0; j -= 8) contents[new_size++] = (lba >> j) & 0xFF;
+ for (size_t i = 0; i <= strlen(filename); i++) contents[new_size++] = (uint8_t) filename[i];
+ for (signed char j = 24; j > 0; j -= 8) contents[new_size++] = (uint8_t) ((lba >> j) & 0xFF);
// Free the blocks
- uint32_t new_size_in_blocks = new_size / 512;
+ uint32_t new_size_in_blocks = (uint32_t) (new_size / 512);
if (new_size % 512) new_size_in_blocks++;
for (uint32_t i = 0; i < new_size_in_blocks; i++)
marfs_mark_block_as_free(marfs_get_block(inode, i));
diff --git a/src/kernel/fs/marfs/new_file.c b/src/kernel/fs/marfs/new_file.c
index 4fef3b9..ab1c241 100644
--- a/src/kernel/fs/marfs/new_file.c
+++ b/src/kernel/fs/marfs/new_file.c
@@ -1,7 +1,7 @@
#include <stdint.h>
#include <kernel/fs/ata_pio.h>
-#include <kernel/lib/stdlib.h>
#include <kernel/fs/marfs/marfs.h>
+#include <kernel/memory/kheap.h>
static uint8_t last_max_level = 0;
@@ -30,17 +30,17 @@ void marfs_update_recursive(uint8_t level, uint32_t i, uint32_t rec_lba, uint32_
uint32_t contents_idx = contents[idx];
kfree(contents);
if (level != 1) {
- marfs_update_recursive(level - 1, i, contents_idx, real_lba);
+ marfs_update_recursive((uint8_t) (level - 1), i, contents_idx, real_lba);
}
last_max_level = 0;
}
uint32_t marfs_new_file(uint64_t size, uint8_t *data, uint32_t uid, uint8_t exec, uint8_t dir)
{
- struct marfs_inode *inode = (struct marfs_inode *) kcalloc(1, 512);
+ struct marfs_inode *inode = (struct marfs_inode *) kmalloc(512);
inode->size = size;
inode->creation_time = inode->last_mod_time = inode->last_access_time = 0; // TODO: POSIX time
- inode->n_blocks = size / 512;
+ inode->n_blocks = (uint32_t) (size / 512);
if (size % 512) inode->n_blocks++;
inode->uid = uid;
inode->is_app = exec;
diff --git a/src/kernel/fs/marfs/read_whole_file.c b/src/kernel/fs/marfs/read_whole_file.c
index 85f9bbb..dda5daf 100644
--- a/src/kernel/fs/marfs/read_whole_file.c
+++ b/src/kernel/fs/marfs/read_whole_file.c
@@ -1,7 +1,7 @@
#include <stdint.h>
#include <kernel/fs/ata_pio.h>
-#include <kernel/lib/stdlib.h>
#include <kernel/fs/marfs/marfs.h>
+#include <kernel/memory/kheap.h>
static uint8_t last_max_level = 0;
@@ -19,7 +19,7 @@ uint32_t marfs_get_recursive(uint8_t level, uint32_t i, uint32_t rec_lba)
kfree(contents);
uint32_t toRet;
- if (level > 1) toRet = marfs_get_recursive(level - 1, i, next_rec_lba);
+ if (level > 1) toRet = marfs_get_recursive((uint8_t) (level - 1), i, next_rec_lba);
else toRet = next_rec_lba;
last_max_level = 0;
return toRet;
@@ -48,7 +48,7 @@ void marfs_read_whole_file(uint32_t lba_inode, uint8_t *buffer)
for (uint32_t i = 0; i < size_in_blocks; i++) {
uint32_t this_block = marfs_get_block(inode, i);
uint8_t *this_block_contents = ata_read28(interface, this_block);
- uint16_t upper_bound = (i != size_in_blocks - 1) ? 512 : (inode->size % 512);
+ uint16_t upper_bound = (uint16_t) ((i != size_in_blocks - 1) ? 512 : (inode->size % 512));
for (uint16_t j = 0; j < upper_bound; j++) buffer[(i * 512) + j] = this_block_contents[j];
kfree(this_block_contents);
}
@@ -63,7 +63,7 @@ uint8_t *marfs_allocate_and_read_whole_file(uint32_t lba_inode)
uint64_t size = inode->size;
kfree(inode);
- uint8_t *buffer = kmalloc(size);
+ uint8_t *buffer = (uint8_t *) kmalloc((uint32_t) size);
marfs_read_whole_file(lba_inode, buffer);
return buffer;
}
diff --git a/src/kernel/fs/marfs/sectorlevel.c b/src/kernel/fs/marfs/sectorlevel.c
index d905315..8302054 100644
--- a/src/kernel/fs/marfs/sectorlevel.c
+++ b/src/kernel/fs/marfs/sectorlevel.c
@@ -1,7 +1,7 @@
#include <stdint.h>
-#include <kernel/lib/stdlib.h>
#include <kernel/fs/ata_pio.h>
#include <kernel/fs/marfs/marfs.h>
+#include <kernel/memory/kheap.h>
uint8_t marfs_init(struct ata_interface *_interface)
{
@@ -62,7 +62,7 @@ static uint8_t marfs_mark_block(uint32_t lba_sector, uint8_t mode)
{
lba_sector -= 2;
lba_sector -= sb_cache.s_first_chunk;
- uint16_t block_in_chunk = lba_sector % 512;
+ uint16_t block_in_chunk = (uint16_t) (lba_sector % 512);
lba_sector /= 512;
lba_sector = 2 + sb_cache.s_first_chunk + (512 * lba_sector);