PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
Filesystem.

Filesystem interface. More...

Collaboration diagram for Filesystem.:

Detailed Description

Filesystem interface.

The filesystem interface represents a filesystem type, e.g. fat32, tmpfs, devfs, etc. Each filesystem is exposed in a directory within the fs sysfs directory named after the filesystem.

The directory itself can be used to mount instances of that filesystem type.

Within each filesystem directory are readable files representing each mounted instance of that filesystem type, named after the superblock ID, containing the following information:

id: %llu
block_size: %llu
max_file_size: %llu
static char * id
Definition dwm.c:20

Where the id is the superblock ID, block_size is the block size of the superblock, and max_file_size is the maximum size of a file on this superblock.

See also
System Filesystem

Data Structures

struct  filesystem_t
 Filesystem structure, represents a filesystem type, e.g. fat32, tmpfs, devfs, etc. More...
 

Macros

#define OPTIONS_FOR_EACH(options, key, value)
 Helper macro for iterating over options passed to a filesystem mount operation.
 

Functions

void filesystem_expose (void)
 Exposes the sysfs fs directory.
 
uint64_t filesystem_register (filesystem_t *fs)
 Registers a filesystem.
 
void filesystem_unregister (filesystem_t *fs)
 Unregisters a filesystem.
 
filesystem_tfilesystem_get_by_name (const char *name)
 Gets a filesystem by name.
 
filesystem_tfilesystem_get_by_path (const char *path, process_t *process)
 Gets a filesystem by path.
 
bool options_next (const char **iter, char *buffer, size_t size, char **key, char **value)
 Helper function for iterating over options passed to a filesystem mount operation.
 

Macro Definition Documentation

◆ OPTIONS_FOR_EACH

#define OPTIONS_FOR_EACH (   options,
  key,
  value 
)
Value:
for (struct { \
const char* iter; \
char buf[256]; \
} _state = {(options), {0}}; \
options_next(&_state.iter, _state.buf, sizeof(_state.buf), &(key), &(value));)

Helper macro for iterating over options passed to a filesystem mount operation.

Each helper option is specified as key=value pairs, with multiple options separated by commas.

Parameters
optionsThe options string.
keyThe key variable.
valueThe value variable.

Definition at line 140 of file filesystem.h.

Function Documentation

◆ filesystem_expose()

void filesystem_expose ( void  )

Exposes the sysfs fs directory.

s

Must be called before filesystem_get_by_path() can be used.

Definition at line 215 of file filesystem.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ filesystem_register()

uint64_t filesystem_register ( filesystem_t fs)

Registers a filesystem.

Parameters
fsThe filesystem to register.
Returns
On success, 0. On failure, ERR and errno is set to:
  • EINVAL: Invalid parameters.
  • Other values from map_insert().

Definition at line 233 of file filesystem.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ filesystem_unregister()

void filesystem_unregister ( filesystem_t fs)

Unregisters a filesystem.

Parameters
fsThe filesystem to unregister, or NULL for no-op.

Definition at line 259 of file filesystem.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ filesystem_get_by_name()

filesystem_t * filesystem_get_by_name ( const char *  name)

Gets a filesystem by name.

Parameters
nameThe name of the filesystem.
Returns
On success, the filesystem. On failure, returns NULL.

Definition at line 276 of file filesystem.c.

Here is the call graph for this function:

◆ filesystem_get_by_path()

filesystem_t * filesystem_get_by_path ( const char *  path,
process_t process 
)

Gets a filesystem by path.

The path should point to a directory in the fs sysfs directory.

Parameters
pathThe path to check.
processThe process whose namespace to use.
Returns
On success, the filesystem. On failure, returns NULL and errno is set to:
  • ENOENT: The path does not exist.
  • ENOMEM: Out of memory.
  • EINVAL: The path is not a directory in the fs sysfs directory.

Definition at line 284 of file filesystem.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ options_next()

bool options_next ( const char **  iter,
char *  buffer,
size_t  size,
char **  key,
char **  value 
)

Helper function for iterating over options passed to a filesystem mount operation.

Each helper option is specified as key=value pairs, with multiple options separated by commas.

Parameters
iterPointer to the current iterator position. Updated on each call.
bufferBuffer to store the current option.
sizeSize of the buffer.
keyPointer to store the key of the current option.
valuePointer to store the value of the current option.
Returns
1 if an option was found, 0 if no more options are available.

Definition at line 327 of file filesystem.c.

Here is the call graph for this function: