SimpleFS
A Simple File Sytem implementation including Disk and Shell Layers
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Disk Class Reference

Disk class Implements Disk abstraction that enables emulation of a disk image. Used by file system to access and make changes to the disk. More...

#include <disk.h>

Public Member Functions

 Disk ()
 constructor of Disk class More...
 
 ~Disk ()
 destructor of Disk class More...
 
void open (const char *path, size_t nblocks)
 opens the disk image More...
 
size_t size () const
 check size of disk More...
 
bool mounted () const
 check if the disk has been mounted More...
 
void mount ()
 mount the disk More...
 
void unmount ()
 unmount the disk More...
 
void read (int blocknum, char *data)
 read from disk More...
 
void write (int blocknum, char *data)
 write to disk More...
 

Private Member Functions

void sanity_check (int blocknum, char *data)
 check if the block is within valid range More...
 

Private Attributes

size_t Blocks
 
size_t Reads
 
size_t Writes
 
size_t Mounts
 

Detailed Description

Disk class Implements Disk abstraction that enables emulation of a disk image. Used by file system to access and make changes to the disk.

Definition at line 18 of file disk.h.

Constructor & Destructor Documentation

◆ Disk()

Disk::Disk ( )
inline

constructor of Disk class

Number of bytes per block

Returns
an instance of Disk class

Definition at line 41 of file disk.h.

◆ ~Disk()

Disk::~Disk ( )

destructor of Disk class

Returns
returns nothing; deletes the Disk object
Implementation details
  • Check if FileDescriptor is set
  • If set, print the required information and close.

Definition at line 46 of file disk.cpp.

Member Function Documentation

◆ mount()

void Disk::mount ( )
inline

mount the disk

Returns
void function; returns nothing

Definition at line 73 of file disk.h.

Here is the caller graph for this function:

◆ mounted()

bool Disk::mounted ( ) const
inline

check if the disk has been mounted

Returns
true if the disk has been mounted; false otherwise

Definition at line 67 of file disk.h.

Here is the caller graph for this function:

◆ open()

void Disk::open ( const char *  path,
size_t  nblocks 
)

opens the disk image

Parameters
pathpath to the disk image
nblocksnumber of blocks in the disk image
Returns
void function; returns nothing. throws runtime_error exception on error.
Implementation details
  • Open Filedescriptor
  • Check if FileDescriptor is valid
  • Allocated blocks
  • Initialize the disk

Definition at line 18 of file disk.cpp.

◆ read()

void Disk::read ( int  blocknum,
char *  data 
)

read from disk

Parameters
blocknumblock to read from
datadata buffer to write into
Implementation details
  • sanity_check blocknum and data
  • reposition read/write file offset and check validity
  • read the FileDescriptor for BLOCK_SIZE
  • Increment reads

Definition at line 86 of file disk.cpp.

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

◆ sanity_check()

void Disk::sanity_check ( int  blocknum,
char *  data 
)
private

check if the block is within valid range

Number of mounts

Parameters
blocknumindex of the block into the free block bitmap
datadata buffer
Returns
void function; returns nothing. throws invalid_argument on error
Implementation details
  • reason for exit.
  • Check if block num is valid or not.
  • Check if data pointer is valid

Definition at line 61 of file disk.cpp.

Here is the caller graph for this function:

◆ size()

size_t Disk::size ( ) const
inline

check size of disk

Returns
size of disk in terms of blocks

Definition at line 61 of file disk.h.

Here is the caller graph for this function:

◆ unmount()

void Disk::unmount ( )
inline

unmount the disk

Returns
void function; returns nothing

Definition at line 79 of file disk.h.

◆ write()

void Disk::write ( int  blocknum,
char *  data 
)

write to disk

Parameters
blocknumblock to write into
datadata buffer to read from
Implementation details
  • sanity_check blocknum and data
  • reposition read/write file offset and check validity
  • write the BLOCK_SIZE data to the FileDescriptor
  • increment writes

Definition at line 112 of file disk.cpp.

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

Member Data Documentation

◆ Blocks

size_t Disk::Blocks
private

File descriptor of disk image

Definition at line 21 of file disk.h.

◆ Mounts

size_t Disk::Mounts
private

Number of writes performed

Definition at line 24 of file disk.h.

◆ Reads

size_t Disk::Reads
private

Number of blocks in disk image

Definition at line 22 of file disk.h.

◆ Writes

size_t Disk::Writes
private

Number of reads performed

Definition at line 23 of file disk.h.


The documentation for this class was generated from the following files: