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>
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.
◆ Disk()
constructor of Disk class
Number of bytes per block
- Returns
- an instance of Disk class
Definition at line 41 of file disk.h.
◆ ~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.
◆ mount()
mount the disk
- Returns
- void function; returns nothing
Definition at line 73 of file disk.h.
◆ 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.
◆ open()
void Disk::open |
( |
const char * |
path, |
|
|
size_t |
nblocks |
|
) |
| |
opens the disk image
- Parameters
-
path | path to the disk image |
nblocks | number 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
-
blocknum | block to read from |
data | data 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.
◆ sanity_check()
void Disk::sanity_check |
( |
int |
blocknum, |
|
|
char * |
data |
|
) |
| |
|
private |
check if the block is within valid range
Number of mounts
- Parameters
-
blocknum | index of the block into the free block bitmap |
data | data 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.
◆ 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.
◆ unmount()
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
-
blocknum | block to write into |
data | data 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.
◆ Blocks
File descriptor of disk image
Definition at line 21 of file disk.h.
◆ Mounts
Number of writes performed
Definition at line 24 of file disk.h.
◆ Reads
Number of blocks in disk image
Definition at line 22 of file disk.h.
◆ Writes
Number of reads performed
Definition at line 23 of file disk.h.
The documentation for this class was generated from the following files: