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

SYNOPSIS

#include <oskit/fs/memfs.h>

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

DESCRIPTION

Initialize the MEMFS filesystem.

RETURNS

Returns handle to an empty MEMFS filesystem.

38.0.9 oskit_memfs_file_set_contents: replace contents of a MEMFS file

SYNOPSIS

#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);

DESCRIPTION

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.

PARAMETERS
file:
File in the memfs filesystem whose contents are being replaced.
data:
Pointer to memory to be used as the new file contents.
size:
The new size of the file.
allocsize:
Size of writable memory available for the file.
can_sfree:
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.
inhibit_resize:
If true, fails any attempt to change the size of the file.
RETURNS

Returns zero on success, an error code otherwise.

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