Chapter 38
Memory File System: liboskit_memfs.a

The memfs library contains an implementation of a trivial memory-based filesystem. It exports the standard OSKit filesystem interface, and depends on the underlying osenv interfaces. (See Chapter 9).

The header file <oskit/fs/memfs.h> must be included to use the memfs, and its derivative cousin, the bmodfs. When first instantiated, a memfs filesystem is empty, and may be populated using the standard file access mechanisms. A special function, oskit_memfs_file_set_contents is provided for convenience to replace the contents of a MEMFS filesystem. Clients who wish to strictly use the OSKit filesystem interface to guarantee portability to other filesystems should not use this function.

38.0.8 oskit_memfs_init: initialize MEMFS filesystem


#include <oskit/fs/memfs.h>

oskit_error_t oskit_memfs_init(oskit_osenv_t *osenv, oskit_filesystem_t **out_fs);


Initialize the MEMFS filesystem.


Returns handle to an empty MEMFS filesystem.

38.0.9 oskit_memfs_file_set_contents: replace contents of a MEMFS file


#include <oskit/fs/memfs.h>

oskit_error_t oskit_memfs_file_set_contents(oskit_file_t *file, void *data, oskit_off_t size, oskit_off_t allocsize, oskit_bool_t can_sfree, oskit_bool_t inhibit_resize);


This function changes the indicated MEMFS file to use the memory from [data - data+size-1] as its contents. File must be a regular MEMFS file and not a directory.

Allocsize indicates the total amount of memory available for the file to use when growing and must be greater than or equal to size. If an attempt is made to grow the file to a size greater than allocsize, new memory will be allocated with smemalign and the file contents copied to the new memory.

If inhibit_resize is true, attempts to change the size of the file hereafter will fail with OSKIT_EPERM.

If can_sfree is true, sfree is called on the data buffer if the file grows beyond allocsize, is truncated to zero-length or is removed.

File in the memfs filesystem whose contents are being replaced.
Pointer to memory to be used as the new file contents.
The new size of the file.
Size of writable memory available for the file.
If true, indicates that the memory pointed to by data can be released with sfree when the file grows beyond allocsize, is truncated to zero-length, or is removed.
If true, fails any attempt to change the size of the file.

Returns zero on success, an error code otherwise.

osenv_mem_alloc  8
osenv_mem_free  8
osenv_log  8
osenv_assert  8
memcpy  14.4.18
memset  14.4.18