Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filesystem PR #428

Open
wants to merge 16 commits into
base: loader
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ src/components/lib/ck/share
doc/dev_manual/composite_dev_manual.pdf
doc/dev_manual/resources/*.pdf
system_binaries/cos_build-*
.vscode
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[submodule "src/components/lib/ps/ps"]
path = src/components/lib/ps/ps
url = https://github.com/gwsystems/ps.git
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could first update the ps port, so we don't need to change the url here

url = https://github.com/msdx321/ps.git
[submodule "src/components/lib/ck/ck"]
path = src/components/lib/ck/ck
url = https://github.com/gwsystems/ck.git
[submodule "src/components/lib/lwext4/lwext4"]
path = src/components/lib/lwext4/lwext4
url = https://github.com/msdx321/lwext4.git
43 changes: 43 additions & 0 deletions composition_scripts/ext4_tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[system]
description = "Simplest system with both capability manager and scheduler, from unit_schedcomp.sh"

[[components]]
name = "booter"
img = "no_interface.llbooter"
implements = [{interface = "init"}, {interface = "addr"}]
deps = [{srv = "kernel", interface = "init", variant = "kernel"}]
constructor = "kernel"

[[components]]
name = "capmgr"
img = "capmgr.simple"
deps = [{srv = "booter", interface = "init"}, {srv = "booter", interface = "addr"}]
implements = [{interface = "capmgr"}, {interface = "init"}, {interface = "memmgr"}, {interface = "capmgr_create"}]
constructor = "booter"

[[components]]
name = "sched"
img = "sched.root_fprr"
deps = [{srv = "capmgr", interface = "init"}, {srv = "capmgr", interface = "capmgr"}, {srv = "capmgr", interface = "memmgr"}]
implements = [{interface = "sched"}, {interface = "init"}]
constructor = "booter"

[[components]]
name = "blockdev"
img = "blockdev.ramdisk"
deps = [{srv = "sched", interface = "init"}, {srv = "capmgr", interface = "capmgr_create"}, {srv = "capmgr", interface = "memmgr"}]
implements = [{interface = "blockdev"}]
constructor = "booter"

[[components]]
name = "filesystem"
img = "filesystem.ext4"
deps = [{srv = "sched", interface = "init"}, {srv = "capmgr", interface = "capmgr_create"}, {srv = "blockdev", interface = "blockdev"}, {srv = "capmgr", interface = "memmgr"}]
implements = [{interface = "filesystem"}]
constructor = "booter"

[[components]]
name = "ext4_tests"
img = "tests.ext4_tests"
deps = [{srv = "sched", interface = "init"}, {srv = "capmgr", interface = "capmgr_create"}, {srv = "filesystem", interface = "filesystem"}, {srv = "capmgr", interface = "memmgr"}]
constructor = "booter"
36 changes: 36 additions & 0 deletions composition_scripts/ramdisk_tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[system]
description = "Simplest system with both capability manager and scheduler, from unit_schedcomp.sh"

[[components]]
name = "booter"
img = "no_interface.llbooter"
implements = [{interface = "init"}, {interface = "addr"}]
deps = [{srv = "kernel", interface = "init", variant = "kernel"}]
constructor = "kernel"

[[components]]
name = "capmgr"
img = "capmgr.simple"
deps = [{srv = "booter", interface = "init"}, {srv = "booter", interface = "addr"}]
implements = [{interface = "capmgr"}, {interface = "init"}, {interface = "memmgr"}, {interface = "capmgr_create"}]
constructor = "booter"

[[components]]
name = "sched"
img = "sched.root_fprr"
deps = [{srv = "capmgr", interface = "init"}, {srv = "capmgr", interface = "capmgr"}, {srv = "capmgr", interface = "memmgr"}]
implements = [{interface = "sched"}, {interface = "init"}]
constructor = "booter"

[[components]]
name = "blockdev"
img = "blockdev.ramdisk"
deps = [{srv = "sched", interface = "init"}, {srv = "capmgr", interface = "capmgr_create"}, {srv = "capmgr", interface = "memmgr"}]
implements = [{interface = "blockdev"}]
constructor = "booter"

[[components]]
name = "ramdisk_tests"
img = "tests.ramdisk_tests"
deps = [{srv = "sched", interface = "init"}, {srv = "capmgr", interface = "capmgr_create"}, {srv = "blockdev", interface = "blockdev"}, {srv = "capmgr", interface = "memmgr"}]
constructor = "booter"
18 changes: 18 additions & 0 deletions src/components/implementation/blockdev/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Required variables used to drive the compilation process. It is OK
# for many of these to be empty.
#
# The set of interfaces that this component exports for use by other
# components. This is a list of the interface names.
INTERFACE_EXPORTS = blockdev
# The interfaces this component is dependent on for compilation (this
# is a list of directory names in interface/)
INTERFACE_DEPENDENCIES = memmgr
# The library dependencies this component is reliant on for
# compilation/linking (this is a list of directory names in lib/)
LIBRARY_DEPENDENCIES = component
# Note: Both the interface and library dependencies should be
# *minimal*. That is to say that removing a dependency should cause
# the build to fail. The build system does not validate this
# minimality; that's on you!

include Makefile.subdir
18 changes: 18 additions & 0 deletions src/components/implementation/blockdev/ramdisk/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Required variables used to drive the compilation process. It is OK
# for many of these to be empty.
#
# The set of interfaces that this component exports for use by other
# components. This is a list of the interface names.
INTERFACE_EXPORTS = blockdev
# The interfaces this component is dependent on for compilation (this
# is a list of directory names in interface/)
INTERFACE_DEPENDENCIES = memmgr
# The library dependencies this component is reliant on for
# compilation/linking (this is a list of directory names in lib/)
LIBRARY_DEPENDENCIES = component
# Note: Both the interface and library dependencies should be
# *minimal*. That is to say that removing a dependency should cause
# the build to fail. The build system does not validate this
# minimality; that's on you!

include Makefile.subsubdir
11 changes: 11 additions & 0 deletions src/components/implementation/blockdev/ramdisk/doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Ramdisk

### Description

This is a simple implementation of ramdisk on composite using blockdev interface.

### Usage and Assumptions

- Default blocksize is 4K
- Default total disk size is 16MiB
- Supports block read and block write only
45 changes: 45 additions & 0 deletions src/components/implementation/blockdev/ramdisk/ramdisk.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <cos_component.h>
#include <llprint.h>
#include <memmgr.h>

#define BLOCKDEV_RAMDISK_BSIZE 4096 // 4K block size
#define BLOCKDEV_RAMDISK_SIZE 16 * 1024 * 1024 // 16 MiB ramdisk size

typedef struct block {
char c[BLOCKDEV_RAMDISK_BSIZE];
} blk;

blk *ram_backend;

unsigned int
blockdev_bread(void *buf, unsigned long offset, unsigned long length)
{
memcpy(buf, &ram_backend[offset], length * BLOCKDEV_RAMDISK_BSIZE);
return 0;
}

unsigned int
blockdev_bwrite(const void *buf, unsigned long offset, unsigned long length)
{
memcpy(&ram_backend[offset], buf, length * BLOCKDEV_RAMDISK_BSIZE);
return 0;
}

void
cos_init(void)
{
ram_backend = (blk *)memmgr_heap_page_allocn(BLOCKDEV_RAMDISK_SIZE / 4096);
return;
}

void
cos_parallel_init(coreid_t cid, int init_core, int ncores)
{
return;
}

void
parallel_main(coreid_t cid)
{
return;
}
18 changes: 18 additions & 0 deletions src/components/implementation/filesystem/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Required variables used to drive the compilation process. It is OK
# for many of these to be empty.
#
# The set of interfaces that this component exports for use by other
# components. This is a list of the interface names.
INTERFACE_EXPORTS = filesystem
# The interfaces this component is dependent on for compilation (this
# is a list of directory names in interface/)
INTERFACE_DEPENDENCIES = blockdev
# The library dependencies this component is reliant on for
# compilation/linking (this is a list of directory names in lib/)
LIBRARY_DEPENDENCIES = component
# Note: Both the interface and library dependencies should be
# *minimal*. That is to say that removing a dependency should cause
# the build to fail. The build system does not validate this
# minimality; that's on you!

include Makefile.subdir
18 changes: 18 additions & 0 deletions src/components/implementation/filesystem/ext4/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Required variables used to drive the compilation process. It is OK
# for many of these to be empty.
#
# The set of interfaces that this component exports for use by other
# components. This is a list of the interface names.
INTERFACE_EXPORTS = filesystem
# The interfaces this component is dependent on for compilation (this
# is a list of directory names in interface/)
INTERFACE_DEPENDENCIES = blockdev memmgr
# The library dependencies this component is reliant on for
# compilation/linking (this is a list of directory names in lib/)
LIBRARY_DEPENDENCIES = component lwext4 posix libc ps
# Note: Both the interface and library dependencies should be
# *minimal*. That is to say that removing a dependency should cause
# the build to fail. The build system does not validate this
# minimality; that's on you!

include Makefile.subsubdir
9 changes: 9 additions & 0 deletions src/components/implementation/filesystem/ext4/doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## filesystem

### Description

An implementation of ext4 filesystem by using lwext4.

### Usage and Assumptions

See `filesystem.h`
126 changes: 126 additions & 0 deletions src/components/implementation/filesystem/ext4/ext4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#include <cos_component.h>
#include <llprint.h>
#include <ext4.h>
#include <ext4_mkfs.h>
#include <ps_ns.h>

extern struct ext4_blockdev *ext4_blockdev_get(void);
static struct ext4_blockdev *bd;

static struct ext4_fs fs;
static int fs_type = F_SET_EXT4;
static struct ext4_mkfs_info info = {
.block_size = 4096,
.journal = true,
};
static struct ext4_bcache *bc;

struct ps_ns *ns[64];

PS_NSSLAB_CREATE(fd, sizeof(struct ext4_file), 2, 9, 6);

word_t
filesystem_fopen(const char *path, const char *flags)
{
ps_desc_t fd;
ext4_file *file;
compid_t token;

token = (compid_t)cos_inv_token();

fd = -1;
file = ps_nsptr_alloc_fd(ns[token], &fd);
int ret = ext4_fopen(file, path, flags);
//printc("ret %d\n", ret);

//printc("mp %p\n", file->mp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing debug print or using printd() looks better.


return (word_t)fd;
}

int
filesystem_fclose(word_t fd)
{
compid_t token;
token = (compid_t)cos_inv_token();

return ext4_fclose(ps_nsptr_lkup_fd(ns[token], fd));
}

int
filesystem_ftruncate(word_t fd, unsigned long size)
{
compid_t token;
token = (compid_t)cos_inv_token();

return ext4_ftruncate(ps_nsptr_lkup_fd(ns[token], fd), size);
}

size_t
filesystem_fread(word_t fd, void *buf, size_t size)
{
size_t rcnt;
compid_t token;
token = (compid_t)cos_inv_token();

int ret = ext4_fread(ps_nsptr_lkup_fd(ns[token], fd), buf, size, &rcnt);
//printc("fread ret %d rcnt %d\n", ret, rcnt);

return rcnt;
}

size_t
filesystem_fwrite(word_t fd, void *buf, size_t size)
{
size_t wcnt;
compid_t token;

token = (compid_t)cos_inv_token();

//printc("fwrite writing %s\n", buf);

int ret = ext4_fwrite(ps_nsptr_lkup_fd(ns[token], fd), buf, size, &wcnt);
//printc("fwrite ret %d wcnt %d\n", ret, wcnt);

return wcnt;
}

int
filesystem_fseek(word_t fd, long offset, unsigned long origin)
{
compid_t token;
token = (compid_t)cos_inv_token();

return ext4_fseek(ps_nsptr_lkup_fd(ns[token], fd), offset, origin);
}

unsigned long
filesystem_ftell(word_t fd)
{
compid_t token;
token = (compid_t)cos_inv_token();

return ext4_ftell(ps_nsptr_lkup_fd(ns[token], fd));
}

unsigned long
filesystem_fsize(word_t fd)
{
compid_t token;
token = (compid_t)cos_inv_token();

return ext4_fsize(ps_nsptr_lkup_fd(ns[token], fd));
}

void
cos_init(void)
{
for (int i = 0; i < 64; i++) { ns[i] = ps_nsptr_create_slab_fd(); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define 64 to be a meaningful symbol should be better.


bd = ext4_blockdev_get();
// ext4_dmask_set(DEBUG_ALL);

ext4_mkfs(&fs, bd, &info, fs_type);
ext4_device_register(bd, "ext4_fs"); // Register our ramdisk as ext4_fs
ext4_mount("ext4_fs", "/", false); // Mount fs to root
}
Loading