Basic Solution File System - BSFS
Loading...
Searching...
No Matches
browser_bsfs.c File Reference

Browser shell-like for the BSFS file system. More...

Functions

char * browser_read_line ()
 Read a single line from standard input.
char ** browser_split_line (char *line)
 Split a command line into whitespace-delimited tokens.
int browser_execute (FILE *file, superblock_t *sb, char **args)
 Dispatch a parsed command to its implementation.
void browser_loop (FILE *file, superblock_t *sb)
 Interactive read-eval-print loop (REPL) for the BSFS browser.
int main (int argc, char *argv[])
 Program entry point for the BSFS browser.

Variables

char current_path [PATH_MAX] = "/"
 Current working directory text (provided by the browser prompt)

Detailed Description

Browser shell-like for the BSFS file system.

This program allows interaction with a BSFS-formatted file through a shell-like interface. Usage: ./browser <formatted_file> It validates the file, reads the superblock, and enters a command loop.

Function Documentation

◆ browser_execute()

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

Dispatch a parsed command to its implementation.

Looks up the command name in the built-in command table and invokes the matching function. Unknown commands print a short error message.

Parameters
fileOpen filesystem image.
sbLoaded superblock.
argsTokenized argv-like vector (args[0] is the command name).
Returns
0 to exit the REPL; 1 to continue.

◆ browser_loop()

void browser_loop ( FILE * file,
superblock_t * sb )

Interactive read-eval-print loop (REPL) for the BSFS browser.

Prints a prompt, reads input, tokenizes and executes commands until exit.

Parameters
fileOpen filesystem image.
sbLoaded superblock.

◆ browser_read_line()

char * browser_read_line ( )

Read a single line from standard input.

Allocates a buffer and returns a NUL-terminated line suitable for tokenizing. The caller is responsible for freeing the returned pointer.

Returns
Newly allocated string with the input line.

◆ browser_split_line()

char ** browser_split_line ( char * line)

Split a command line into whitespace-delimited tokens.

Tokenizes the given mutable buffer in-place and returns a NULL-terminated array of pointers to the tokens. The array itself must be freed by the caller; the token strings live inside the original buffer.

Parameters
lineWritable buffer containing the input line to split.
Returns
NULL-terminated argv-like vector of token pointers.

◆ main()

int main ( int argc,
char * argv[] )

Program entry point for the BSFS browser.

Validates usage, opens the formatted image file, checks the magic number, reads the superblock and starts the interactive loop.

Parameters
argcArgument count (expects 2).
argvArgument vector: argv[1] must be the path to the image file.
Returns
EXIT_SUCCESS on normal termination; EXIT_FAILURE on error.

Variable Documentation

◆ current_path

char current_path[PATH_MAX] = "/"

Current working directory text (provided by the browser prompt)

Current browser prompt path (defined in browser_bsfs.c)