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

Formatter utility for the BSFS filesystem image. More...

Functions

int mkfs_bsfs_format_open (FILE *disk)
 Format an already opened partition file as a BSFS filesystem.
int mkfs_bsfs_format_path (const char *path)
 Format a partition file located at path as a BSFS filesystem.
int main (int argc, char **argv)
 Program entry point for mkfs.bsfs.

Detailed Description

Formatter utility for the BSFS filesystem image.

Formats a regular file (e.g., created with dd) into a BSFS filesystem image. The on-disk layout initialized by this tool is:

  • Block 0: Superblock
  • Blocks [1 .. 1 + block_bitmap_total - 1]: Linked list of bitmap blocks
  • Blocks [data_block_start .. total_blocks - 1]: Data and B-tree regions

The formatter writes and persists the superblock, initializes the block bitmap linked list, reserves metadata blocks in the bitmap, initializes the inode B-tree (persisting its root in the superblock if created), creates a fresh directory B-tree for the filesystem root, inserts "." and ".." entries, and finally persists the root inode into the inode B-tree.

Usage: mkfs.bsfs <partition_file>

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Program entry point for mkfs.bsfs.

Usage: mkfs.bsfs <partition_file>

Parameters
argcArgument count.
argvArgument vector.
Returns
EXIT_SUCCESS on success; EXIT_FAILURE on error.

◆ mkfs_bsfs_format_open()

int mkfs_bsfs_format_open ( FILE * disk)

Format an already opened partition file as a BSFS filesystem.

This function expects the file size to be a multiple of the block size (4096 bytes). It computes the on-disk layout, writes the superblock, initializes and persists the bitmap, ensures the inode B-tree exists, creates the root directory entries ("." and ".."), and writes the root inode into the inode B-tree. On success, the file is a valid BSFS image.

Parameters
diskOpened FILE* corresponding to the partition image (opened in read/write mode).
Returns
0 on success; -1 on failure.

◆ mkfs_bsfs_format_path()

int mkfs_bsfs_format_path ( const char * path)

Format a partition file located at path as a BSFS filesystem.

Opens the target file in read/write mode and delegates to mkfs_bsfs_format_open(). The file must already exist and its size must be a multiple of 4096 bytes.

Parameters
pathPath to the pre-sized partition file.
Returns
0 on success; -1 on error (open failure or formatting failure).