Basic Solution File System - BSFS
Loading...
Searching...
No Matches
commands_bsfs.h File Reference

Command table and prototypes for the BSFS browser. More...

Classes

struct  Command
 Name-to-function descriptor for a browser command. More...

Functions

int bsfs_cmd_exit (FILE *file, superblock_t *sb, char **args)
 Exit the BSFS browser loop.
int bsfs_cmd_info (FILE *file, superblock_t *sb, char **args)
 Print filesystem information from the superblock.
int bsfs_cmd_help (FILE *file, superblock_t *sb, char **args)
 Display a help summary for available commands.
int cd (FILE *disk, superblock_t *sb, char **args)
 Change current working directory.
int pwd (FILE *disk, superblock_t *sb, char **args)
 Print the current working directory.
int list (FILE *disk, superblock_t *sb, char **args)
 List contents of a directory.
int mkdir (FILE *disk, superblock_t *sb, char **args)
 Create a new directory.
int rmdir (FILE *disk, superblock_t *sb, char **args)
 Remove an empty directory.
int touch (FILE *disk, superblock_t *sb, char **args)
 Create an empty regular file.
int rm (FILE *disk, superblock_t *sb, char **args)
 Remove a file (logical delete with Recovery snapshot).
int cp (FILE *disk, superblock_t *sb, char **args)
 Copy a file.
int mv (FILE *disk, superblock_t *sb, char **args)
 Move or rename a file or directory.
int cat (FILE *disk, superblock_t *sb, char **args)
 Display file contents.
int echo (FILE *disk, superblock_t *sb, char **args)
 Write text or append text to a file, or echo to screen.
int stat (FILE *disk, superblock_t *sb, char **args)
 Show inode metadata for a path.
int dd (FILE *disk, superblock_t *sb, char **args)
 Generate a file by copying blocks from /dev/zero or /dev/random.
int fill_cmd (FILE *disk, superblock_t *sb, char **args)
 Implements the fill command for the BSFS browser.
int whoami_cmd (FILE *disk, superblock_t *sb, char **args)
 Print current session uid, gid and umask.
int su (FILE *disk, superblock_t *sb, char **args)
 Switch the browser session identity (testing helper).
int umask_cmd (FILE *disk, superblock_t *sb, char **args)
 Show or set the session umask (octal).
int chmod (FILE *disk, superblock_t *sb, char **args)
 Change permission bits of a path.
int chown (FILE *disk, superblock_t *sb, char **args)
 Change file owner (uid) of a path (root only).
int chgrp (FILE *disk, superblock_t *sb, char **args)
 Change file group (gid) of a path (root only).
int recovery (FILE *disk, superblock_t *sb, char **args)
 List Recovery snapshots, optionally filtered by original name.
int restore (FILE *disk, superblock_t *sb, char **args)
 Restore a deleted file by recovery ID or original name.
int purge (FILE *disk, superblock_t *sb, char **args)
 BSFS browser command: purge Recovery snapshots to reclaim space.

Detailed Description

Command table and prototypes for the BSFS browser.

Exposes the browser command registry and individual command function signatures. Each command receives the open filesystem image, the loaded superblock, and the tokenized argv-like vector.

Function Documentation

◆ bsfs_cmd_exit()

int bsfs_cmd_exit ( FILE * file,
superblock_t * sb,
char ** args )

Exit the BSFS browser loop.

Usage: exit

Prints a farewell message and returns 0 so the main loop terminates.

Parameters
fileOpen filesystem image (unused).
sbLoaded superblock (unused).
argsTokenized arguments (unused).
Returns
0 to signal the REPL to exit.

◆ bsfs_cmd_help()

int bsfs_cmd_help ( FILE * file,
superblock_t * sb,
char ** args )

Display a help summary for available commands.

Usage: help

Prints categories and usage examples for navigation, file, directory, recovery and system commands available in the browser.

Parameters
fileOpen filesystem image (unused).
sbLoaded superblock (unused).
argsTokenized arguments (unused).
Returns
1 to continue the REPL.

◆ bsfs_cmd_info()

int bsfs_cmd_info ( FILE * file,
superblock_t * sb,
char ** args )

Print filesystem information from the superblock.

Usage: info

Dumps key fields such as magic, block size, total blocks, bitmap layout, inode and recovery roots, and the root inode number.

Parameters
fileOpen filesystem image (unused).
sbLoaded superblock.
argsTokenized arguments (unused).
Returns
1 to continue the REPL.

◆ cat()

int cat ( FILE * disk,
superblock_t * sb,
char ** args )

Display file contents.

Usage: cat <path>

Parameters
diskOpen filesystem image.
sbLoaded superblock.
argsFile path in args[1].
Returns
1 to continue the REPL.

◆ cd()

int cd ( FILE * disk,
superblock_t * sb,
char ** args )

Change current working directory.

Usage: cd <directory>

Parameters
diskOpen filesystem image.
sbLoaded superblock.
argsExpects directory path in args[1].
Returns
1 to continue the REPL.

◆ chgrp()

int chgrp ( FILE * disk,
superblock_t * sb,
char ** args )

Change file group (gid) of a path (root only).

Parses a decimal gid and updates the target's group via the API. Prints usage on invalid arguments and a concise error on failure.

Parameters
diskOpen filesystem image.
sbLoaded superblock.
argsCommand argv-like vector; expects gid in args[1], path in args[2].
Returns
1 to continue the browser loop.

◆ chmod()

int chmod ( FILE * disk,
superblock_t * sb,
char ** args )

Change permission bits of a path.

Parses the octal mode and calls the high-level API to update permission bits. Prints usage on invalid input and a concise error on failure.

Parameters
diskOpen filesystem image.
sbLoaded superblock.
argsCommand argv-like vector; expects mode in args[1], path in args[2].
Returns
1 to continue the browser loop.

◆ chown()

int chown ( FILE * disk,
superblock_t * sb,
char ** args )

Change file owner (uid) of a path (root only).

Parses a decimal uid and updates the target's owner via the API. Prints usage on invalid arguments and a concise error on failure.

Parameters
diskOpen filesystem image.
sbLoaded superblock.
argsCommand argv-like vector; expects uid in args[1], path in args[2].
Returns
1 to continue the browser loop.

◆ cp()

int cp ( FILE * disk,
superblock_t * sb,
char ** args )

Copy a file.

Usage: cp <src> <dst>

Parameters
diskOpen filesystem image.
sbLoaded superblock.
argsSource path in args[1], destination path in args[2].
Returns
1 to continue the REPL.

◆ dd()

int dd ( FILE * disk,
superblock_t * sb,
char ** args )

Generate a file by copying blocks from /dev/zero or /dev/random.

Usage: dd if=/dev/zero of=<file> bs=<size> count=<n>

Parameters
diskOpen filesystem image.
sbLoaded superblock.
argsKey-value args (if/of/bs/count) parsed by the command.
Returns
1 to continue the REPL.

◆ echo()

int echo ( FILE * disk,
superblock_t * sb,
char ** args )

Write text or append text to a file, or echo to screen.

Usage: echo "text" [> file | >> file]

Parameters
diskOpen filesystem image.
sbLoaded superblock.
argsText tokens and optional redirection operator + filename.
Returns
1 to continue the REPL.

◆ fill_cmd()

int fill_cmd ( FILE * disk,
superblock_t * sb,
char ** args )

Implements the fill command for the BSFS browser.

The fill command creates a number of files with a given size, measuring the elapsed time for the operation. Files are created sequentially using the high-level API and filled with a predictable byte pattern.

Usage: fill <count> <size> [prefix] [bs=<block>] [pattern=index|zero|random]

Parameters:

  • count : number of files to create (positive integer)
  • size : file size (supports K/M/G suffixes)
  • prefix : optional basename/path (default: "fill") used to build <prefix>_<NNN>.bin
  • bs= : optional block size for writes (default 64 KiB, supports suffixes)
  • pattern : optional fill pattern: "index" (default, byte = file id), "zero" (all zeros) or "random" (pseudo-random bytes)

◆ list()

int list ( FILE * disk,
superblock_t * sb,
char ** args )

List contents of a directory.

Usage: ls [path] or list [path]

Parameters
diskOpen filesystem image.
sbLoaded superblock.
argsOptional directory path in args[1]; defaults to ".".
Returns
1 to continue the REPL.

◆ mkdir()

int mkdir ( FILE * disk,
superblock_t * sb,
char ** args )

Create a new directory.

Usage: mkdir <directory>

Parameters
diskOpen filesystem image.
sbLoaded superblock.
argsDirectory name in args[1].
Returns
1 to continue the REPL.

◆ mv()

int mv ( FILE * disk,
superblock_t * sb,
char ** args )

Move or rename a file or directory.

Usage: mv <src> <dst>

Parameters
diskOpen filesystem image.
sbLoaded superblock.
argsSource path in args[1], destination path in args[2].
Returns
1 to continue the REPL.

◆ purge()

int purge ( FILE * disk,
superblock_t * sb,
char ** args )

BSFS browser command: purge Recovery snapshots to reclaim space.

Usage:

  • purge -> remove entries older than ~30 days
  • purge <id> -> remove a specific snapshot by Recovery ID
  • purge oldest <count> -> remove the <count> oldest snapshots
Parameters
diskOpen filesystem image.
sbLoaded superblock.
argsTokenized arguments per usage above.
Returns
Always 1 to continue the browser loop.

◆ pwd()

int pwd ( FILE * disk,
superblock_t * sb,
char ** args )

Print the current working directory.

Usage: pwd

Parameters
diskOpen filesystem image.
sbLoaded superblock.
argsUnused.
Returns
1 to continue the REPL.

◆ recovery()

int recovery ( FILE * disk,
superblock_t * sb,
char ** args )

List Recovery snapshots, optionally filtered by original name.

Usage: recovery [name]

Parameters
diskOpen filesystem image.
sbLoaded superblock.
argsOptional name filter in args[1].
Returns
1 to continue the REPL.

◆ restore()

int restore ( FILE * disk,
superblock_t * sb,
char ** args )

Restore a deleted file by recovery ID or original name.

If the first argument parses as a numeric ID, restores that snapshot. Otherwise treats it as a name and disambiguates if multiple snapshots share the same name, printing a table of candidates with deletion timestamps.

Parameters
diskOpen filesystem image.
sbLoaded superblock.
argsargv-like vector; id or name in args[1], optional dest dir in args[2].
Returns
1 to continue the browser loop.

◆ rm()

int rm ( FILE * disk,
superblock_t * sb,
char ** args )

Remove a file (logical delete with Recovery snapshot).

Unlinks the directory entry and inserts a snapshot into the Recovery tree so the file can be restored later. Prints a confirmation or a concise error message (including permission denied when applicable).

Parameters
diskOpen filesystem image.
sbLoaded superblock.
argsCommand argv-like vector; expects target path in args[1].
Returns
1 to continue the browser loop.

◆ rmdir()

int rmdir ( FILE * disk,
superblock_t * sb,
char ** args )

Remove an empty directory.

Usage: rmdir <directory>

Parameters
diskOpen filesystem image.
sbLoaded superblock.
argsDirectory name in args[1].
Returns
1 to continue the REPL.

◆ stat()

int stat ( FILE * disk,
superblock_t * sb,
char ** args )

Show inode metadata for a path.

Usage: stat <path>

Parameters
diskOpen filesystem image.
sbLoaded superblock.
argsPath in args[1].
Returns
1 to continue the REPL.

◆ su()

int su ( FILE * disk,
superblock_t * sb,
char ** args )

Switch the browser session identity (testing helper).

Changes the API session uid (and optionally gid) used for permission checks. Accepts decimal values. Intended for testing permission behavior in the browser; no OS-level identity is changed.

Parameters
diskOpen filesystem image (unused).
sbLoaded superblock (unused).
argsargv-like vector; expects uid in args[1], optional gid in args[2].
Returns
1 to continue the browser loop.

◆ touch()

int touch ( FILE * disk,
superblock_t * sb,
char ** args )

Create an empty regular file.

Usage: touch <filename>

Parameters
diskOpen filesystem image.
sbLoaded superblock.
argsTarget filename in args[1].
Returns
1 to continue the REPL.

◆ umask_cmd()

int umask_cmd ( FILE * disk,
superblock_t * sb,
char ** args )

Show or set the session umask (octal).

With no argument, prints the current umask. With a single octal argument, sets the session umask for subsequent creates. Values must be 000..777.

Parameters
diskOpen filesystem image (unused).
sbLoaded superblock (unused).
argsargv-like vector; optional octal value in args[1].
Returns
1 to continue the browser loop.

◆ whoami_cmd()

int whoami_cmd ( FILE * disk,
superblock_t * sb,
char ** args )

Print current session uid, gid and umask.

Reads the API session identity and umask and prints them in a compact form.

Parameters
diskOpen filesystem image (unused).
sbLoaded superblock (unused).
argsargv-like vector (unused).
Returns
1 to continue the browser loop.