SimpleFS
A Simple File Sytem implementation including Disk and Shell Layers
|
FileSytem Class. Contains fs layer to access and store disk blocks. Used by sfssh (shell) to provide access to the end-user. More...
#include <fs.h>
Classes | |
union | Block |
Block Union Corresponds to one block of disk of size Disk::BLOCKSIZE. Can be used as a SuperBlock, Inode, Pointers block, or raw Data block. More... | |
struct | Directory |
Directory Structure. Contains a table of directory entries for storing hierarchy. Also contains fields for Size and Valid bits. Name is matched against the one in Directory entry. Also, it is allocated from end for effectively using disk space. More... | |
struct | Dirent |
Directory Entry. Contains necessary fields to locate the file and directory Consumes 64 KB per object. Used to store information about a directory. More... | |
struct | Inode |
Inode Structure Corresponds to a file stored on the disk. Contains the list of raw data blocks used to store the data. Stores the size of the file. More... | |
struct | SuperBlock |
SuperBlock structure. It is the first block in any disk. It's main function is to help validating the disk. Contains metadata of the disk. More... | |
Public Member Functions | |
bool | mount (Disk *disk) |
mounts the file system onto the disk More... | |
bool | set_password () |
Adds password to the mounted disk (fs_disk). Gives the control to change_password if disk is pasword protected. More... | |
bool | change_password () |
Changes password in the mounted disk (fs_disk). Checks the current password and gives control to set_password. More... | |
bool | remove_password () |
Removes password from the mounted disk (fs_disk). More... | |
bool | touch (char name[]) |
Creates a file with size 0. Main function is to allocate an Inode and add Dirent to the curr_dir. Error if file already exists. More... | |
bool | mkdir (char name[]) |
Creates an empty directory with the given name Adds 2 Dirent , '.' and '..' in it's table. More... | |
bool | rmdir (char name[]) |
Removes the directory with given name. Also removes all the Dirent in it's table. More... | |
bool | cd (char name[]) |
Change curr_dir to the given Directory name. More... | |
bool | ls () |
List all the curr_dir Dirent. More... | |
bool | rm (char name[]) |
Removes the given file/Directory. More... | |
bool | copyout (char name[], const char *path) |
Copies the file in curr_dir to the path provided. Prints amount of bytes copied. More... | |
bool | copyin (const char *path, char name[]) |
Copies the file with path provided to the curr_dir. Prints amount of bytes copied. Creates a newfile if file doesn't exist. Overwrites the file if already exists. More... | |
bool | ls_dir (char name[]) |
List the Directory given by the name. Called by ls to print curr_dir. Prints a table of Dirent. More... | |
void | exit () |
Unmounts the disk and resets pointer. More... | |
void | stat () |
Returns the stat of the disk. The stat contains information like number of directories, number of files, block number etc. More... | |
Static Public Member Functions | |
static void | debug (Disk *disk) |
prints the basic outline of the disk More... | |
static bool | format (Disk *disk) |
formats the entire disk More... | |
Private Member Functions | |
ssize_t | create () |
creates a new inode More... | |
bool | remove (size_t inumber) |
removes the inode More... | |
ssize_t | stat (size_t inumber) |
check size of an inode More... | |
ssize_t | read (size_t inumber, char *data, int length, size_t offset) |
read from disk More... | |
ssize_t | write (size_t inumber, char *data, int length, size_t offset) |
write to the disk More... | |
bool | load_inode (size_t inumber, Inode *node) |
loads inode corresponding to inumber into node More... | |
ssize_t | allocate_free_block () |
allocate the first free block from the disk More... | |
void | read_helper (uint32_t blocknum, int offset, int *length, char **data, char **ptr) |
reads the block from disk and changes the pointers accordingly More... | |
ssize_t | write_ret (size_t inumber, Inode *node, int ret) |
writes the node into the corresponding inode block More... | |
void | read_buffer (int offset, int *read, int length, char *data, uint32_t blocknum) |
reads from buffer and writes to a block in the disk More... | |
bool | check_allocation (Inode *node, int read, int orig_offset, uint32_t &blocknum, bool write_indirect, Block indirect) |
allocates a block if required; if no block is available in the disk; returns false More... | |
uint32_t | allocate_block () |
allocates the first free block from free block bitmap More... | |
Directory | add_dir_entry (Directory dir, uint32_t inum, uint32_t type, char name[]) |
Adds directory entry to the cached curr_dir. dir_write_back should be done by the caller. More... | |
void | write_dir_back (struct Directory dir) |
Writes the Directory back to the disk. More... | |
int | dir_lookup (Directory dir, char name[]) |
Finds a valid entry with the same name. More... | |
Directory | read_dir_from_offset (uint32_t offset) |
Reads Directory from Dirent offset in curr_dir. More... | |
Directory | rmdir_helper (Directory parent, char name[]) |
Helper function to remove directory from parent directory. More... | |
Directory | rm_helper (Directory parent, char name[]) |
Helper function to remove file/directory from parent directory. More... | |
Private Attributes | |
vector< bool > | free_blocks |
vector< int > | inode_counter |
vector< uint32_t > | dir_counter |
struct SuperBlock | MetaData |
Directory | curr_dir |
FileSytem Class. Contains fs layer to access and store disk blocks. Used by sfssh (shell) to provide access to the end-user.
union FileSystem::Block |
Block Union Corresponds to one block of disk of size Disk::BLOCKSIZE. Can be used as a SuperBlock, Inode, Pointers block, or raw Data block.
Class Members | ||
---|---|---|
char | Data[Disk::BLOCK_SIZE] |
Contains indexes of Direct Blocks. 0 if null.ck |
struct Directory | Directories[FileSystem::DIR_PER_BLOCK] |
Data block |
struct Inode | Inodes[FileSystem::INODES_PER_BLOCK] | |
uint32_t | Pointers[FileSystem::POINTERS_PER_BLOCK] |
Inode block |
struct SuperBlock | Super |
struct FileSystem::Directory |
Directory Structure. Contains a table of directory entries for storing hierarchy. Also contains fields for Size and Valid bits. Name is matched against the one in Directory entry. Also, it is allocated from end for effectively using disk space.
Class Members | ||
---|---|---|
uint32_t | inum |
Valid bit for validation |
char | Name[NAMESIZE] |
inum = block_num * DIR_PER_BLOCK + offset |
Dirent | Table[ENTRIES_PER_DIR] |
Directory Name |
uint16_t | Valid |
struct FileSystem::Dirent |
Directory Entry. Contains necessary fields to locate the file and directory Consumes 64 KB per object. Used to store information about a directory.
Class Members | ||
---|---|---|
uint32_t | inum |
valid bit to check if the entry is valid |
char | Name[NAMESIZE] |
inum for Inodes or offset for dir |
uint8_t | type | |
uint8_t | valid |
type = 1 for file, type = 0 for directory |
struct FileSystem::Inode |
Inode Structure Corresponds to a file stored on the disk. Contains the list of raw data blocks used to store the data. Stores the size of the file.
Class Members | ||
---|---|---|
uint32_t | Direct[FileSystem::POINTERS_PER_INODE] |
Size of file |
uint32_t | Indirect |
Direct pointers |
uint32_t | Size |
Whether or not inode is valid |
uint32_t | Valid |
struct FileSystem::SuperBlock |
SuperBlock structure. It is the first block in any disk. It's main function is to help validating the disk. Contains metadata of the disk.
|
private |
Adds directory entry to the cached curr_dir. dir_write_back should be done by the caller.
dir | Directory in which entry is to be added |
inum | inum of the File/Directory |
type | type = 1 for file , type = 0 for Directory |
name | Name of the file/Directory |
Definition at line 125 of file fs_layer_2.cpp.
|
private |
allocates the first free block from free block bitmap
Definition at line 566 of file fs_layer_1.cpp.
|
private |
allocate the first free block from the disk
bool FileSystem::cd | ( | char | name[] | ) |
Change curr_dir to the given Directory name.
name | Directory name to be used. |
Definition at line 441 of file fs_layer_2.cpp.
bool FileSystem::change_password | ( | ) |
Changes password in the mounted disk (fs_disk). Checks the current password and gives control to set_password.
Definition at line 57 of file fs_layer_2.cpp.
|
private |
allocates a block if required; if no block is available in the disk; returns false
node | used to set the size of inode in case allocation fails |
read | bytes read from buffer so far |
orig_offset | offset passed to write() function call |
blocknum | index of block in the free block bitmap |
write_indirect | true if the block is an indirect node |
indirect | the indirect node if required |
Definition at line 635 of file fs_layer_1.cpp.
bool FileSystem::copyin | ( | const char * | path, |
char | name[] | ||
) |
Copies the file with path provided to the curr_dir. Prints amount of bytes copied. Creates a newfile if file doesn't exist. Overwrites the file if already exists.
name | Name of the file to be copied in |
path | Path to store the file outside. |
Definition at line 526 of file fs_layer_2.cpp.
bool FileSystem::copyout | ( | char | name[], |
const char * | path | ||
) |
Copies the file in curr_dir to the path provided. Prints amount of bytes copied.
name | Name of the file to be copied out |
path | Path to store the file outside. |
Definition at line 485 of file fs_layer_2.cpp.
|
private |
creates a new inode
Definition at line 291 of file fs_layer_1.cpp.
|
static |
prints the basic outline of the disk
disk | the disk to be debugged |
iterating through the direct nodes
Definition at line 25 of file fs_layer_1.cpp.
|
private |
Finds a valid entry with the same name.
dir | Lookup directory |
name | File/Directory Name |
Definition at line 196 of file fs_layer_2.cpp.
void FileSystem::exit | ( | ) |
Unmounts the disk and resets pointer.
Definition at line 477 of file fs_layer_2.cpp.
|
static |
formats the entire disk
disk | the disk to be formatted |
Definition at line 88 of file fs_layer_1.cpp.
|
private |
loads inode corresponding to inumber into node
inumber | index into inode table |
node | pointer to inode |
Definition at line 333 of file fs_layer_1.cpp.
bool FileSystem::ls | ( | ) |
List all the curr_dir Dirent.
Definition at line 461 of file fs_layer_2.cpp.
bool FileSystem::ls_dir | ( | char | name[] | ) |
List the Directory given by the name. Called by ls to print curr_dir. Prints a table of Dirent.
name | Name of the directory to be listed |
Definition at line 216 of file fs_layer_2.cpp.
bool FileSystem::mkdir | ( | char | name[] | ) |
Creates an empty directory with the given name Adds 2 Dirent , '.' and '..' in it's table.
name | Name of the directory to be added. |
Definition at line 245 of file fs_layer_2.cpp.
bool FileSystem::mount | ( | Disk * | disk | ) |
mounts the file system onto the disk
disk | the disk to be mounted |
Definition at line 178 of file fs_layer_1.cpp.
|
private |
read from disk
inumber | index into the inode table of the corresponding inode |
data | data buffer |
length | bytes to be read from disk |
offset | start point of the read operation |
Definition at line 443 of file fs_layer_1.cpp.
|
private |
reads from buffer and writes to a block in the disk
offset | starts writing at index = offset |
read | bytes read from buffer so far |
length | bytes to be written to the disk |
data | data buffer |
blocknum | index of block in free block bitmap |
Definition at line 610 of file fs_layer_1.cpp.
|
private |
Reads Directory from Dirent offset in curr_dir.
offset | offset of curr_dir.Table which needs to be read. |
Definition at line 154 of file fs_layer_2.cpp.
|
private |
reads the block from disk and changes the pointers accordingly
blocknum | index into the free block bitmap |
offset | start reading from index = offset |
length | number of bytes to be read |
data | data buffer |
ptr | buffer to store the read data |
Definition at line 428 of file fs_layer_1.cpp.
|
private |
removes the inode
inumber | index into the inode table of the inode to be removed |
Definition at line 361 of file fs_layer_1.cpp.
bool FileSystem::remove_password | ( | ) |
Removes password from the mounted disk (fs_disk).
Definition at line 87 of file fs_layer_2.cpp.
bool FileSystem::rm | ( | char | name[] | ) |
Removes the given file/Directory.
name | Entry to be removed |
Definition at line 468 of file fs_layer_2.cpp.
|
private |
Helper function to remove file/directory from parent directory.
parent | Parent Directory which contains name |
name | File/Directory to be removed |
Definition at line 364 of file fs_layer_2.cpp.
bool FileSystem::rmdir | ( | char | name[] | ) |
Removes the directory with given name. Also removes all the Dirent in it's table.
name | Name of the Directory to be deleted |
Definition at line 397 of file fs_layer_2.cpp.
|
private |
Helper function to remove directory from parent directory.
parent | Directory from which the other directory is to be removed. |
name | Name of the directory to be removed |
Definition at line 306 of file fs_layer_2.cpp.
bool FileSystem::set_password | ( | ) |
Adds password to the mounted disk (fs_disk). Gives the control to change_password if disk is pasword protected.
Definition at line 27 of file fs_layer_2.cpp.
void FileSystem::stat | ( | ) |
Returns the stat of the disk. The stat contains information like number of directories, number of files, block number etc.
Definition at line 583 of file fs_layer_2.cpp.
|
private |
check size of an inode
inumber | index into the inode table of inode whose size is to be determined |
Definition at line 412 of file fs_layer_1.cpp.
bool FileSystem::touch | ( | char | name[] | ) |
Creates a file with size 0. Main function is to allocate an Inode and add Dirent to the curr_dir. Error if file already exists.
name | Name of the file to be added |
Definition at line 410 of file fs_layer_2.cpp.
|
private |
write to the disk
inumber | index into the inode table of the corresponding inode |
data | data buffer |
length | bytes to be written to disk |
offset | start point of the write operation |
Definition at line 658 of file fs_layer_1.cpp.
|
private |
Writes the Directory back to the disk.
dir | Valid Directory to be written back |
Definition at line 178 of file fs_layer_2.cpp.
|
private |
writes the node into the corresponding inode block
inumber | index into inode table |
node | the inode to be written back to disk |
ret | the value that is returned by the function |
Definition at line 587 of file fs_layer_1.cpp.
|
private |
|
private |
|
private |
|
private |
|
private |