MP3 1.0
This is the Doxygen document for ECE391 MP3.
Loading...
Searching...
No Matches
Functions | Variables
filesystem.c File Reference

Functions for reading and accessing the MP3 file system. More...

#include "filesystem.h"
#include "pcb.h"
#include "lib.h"

Functions

int32_t readDentryByName (const uint8_t *fname, dentry_t *dentry)
 Find a directory by name. More...
 
int32_t readDentryByIndex (uint32_t index, dentry_t *dentry)
 Read a directory by its index. More...
 
int32_t readData (uint32_t inode, uint32_t offset, uint8_t *buf, uint32_t length)
 Read data pointed by inode at offset into file. More...
 
void initFileSystem (uint32_t *fsStart)
 Initializes the file system. More...
 
int readDirectory (int32_t fd, void *buf, int32_t nbytes)
 Read a directory. More...
 
int writeDirectory (int32_t fd, const void *buf, int32_t nbytes)
 Write to a directory. More...
 
int openDirectory (const uint8_t *filename)
 open a directory. More...
 
int closeDirectory (int32_t fd)
 close a directory. More...
 
void printDirName (char *fname)
 Print the directory name to the screen given the character buffer fname. More...
 
int readFile (int32_t fd, void *buf, int32_t nbytes)
 Read a file given the file descriptor index. More...
 
int writeFile (int32_t fd, const void *buf, int32_t nbytes)
 Write to a file. More...
 
int openFile (const uint8_t *filename)
 Open a file. More...
 
int closeFile (int32_t fd)
 Close a file. More...
 

Variables

int dirCounter = 0
 Counter for read directories. More...
 

Detailed Description

Functions for reading and accessing the MP3 file system.

Author
Group 8
Version
1.0
Date
2023-03-12

Function Documentation

◆ closeDirectory()

int closeDirectory ( int32_t  fd)

close a directory.

defined to match a close system call.

Parameters
filenameNever used.
Returns
0

◆ closeFile()

int closeFile ( int32_t  fd)

Close a file.

Defined to match a close system call.

Parameters
fdNever used.
Returns
0

◆ initFileSystem()

void initFileSystem ( uint32_t fsStart)

Initializes the file system.

Initialize the file system by pointing global boot block, inode block, and data block pointers to their valid locations. Does this by updating bootBlock, dataBlockSection, and inodeBlockSection in filesystem.h.

Parameters
fsStartPointer to the bootblock.

◆ openDirectory()

int openDirectory ( const uint8_t filename)

open a directory.

defined to match an open system call.

Parameters
filenameNever used.
Returns
0

◆ openFile()

int openFile ( const uint8_t filename)

Open a file.

Defined to match an open system call.

Parameters
filenameNever used.
Returns
0

◆ printDirName()

void printDirName ( char *  fname)

Print the directory name to the screen given the character buffer fname.

Parameters
fnameThe name to be printed.

◆ readData()

int32_t readData ( uint32_t  inode,
uint32_t  offset,
uint8_t buf,
uint32_t  length 
)

Read data pointed by inode at offset into file.

Parameters
inodeThe inode index that points to data we want to read from.
offsetThe offset into the pointed data from where we start reading.
bufBuffer to populate read data with when data is read without failure.
lengthThe number of bytes to read from pointed data.
Returns
Number of bytes read.
-1 on failure if inode number is invalid or data block is bad.
Note
This function returns by changing the input pointer
Parameters
buf.

◆ readDentryByIndex()

int32_t readDentryByIndex ( uint32_t  index,
dentry_t dentry 
)

Read a directory by its index.

Parameters
indexThe directory index to the directories stored in boot block.
dentryDirectory entry ptr which is populated w/ data of indexed directory if found.
Returns
0 on success.
-1 on failure if file does not exist or invalid index.
Note
This function returns by changing the input pointer
Parameters
dentry.

◆ readDentryByName()

int32_t readDentryByName ( const uint8_t fname,
dentry_t dentry 
)

Find a directory by name.

Parameters
fnameName of the directory to find.
dentryPointer to the found data directory (if found).
Returns
0 on success.
-1 on failure if file does not exist or invalid index.
Note
This function returns by changing the input pointer
Parameters
dentry.

◆ readDirectory()

int readDirectory ( int32_t  fd,
void *  buf,
int32_t  nbytes 
)

Read a directory.

Parameters
fdNever used.
bufBuffer that is populated with the name of the file.
nbytesnumber of bytes to copy.
Returns
the number of bytes placed into the buffer, including \0 if nbytes < FILE_NAME_MAX_LEN, otherwise not including \0.
-1 if failed.
Note
This function returns by changing the input pointer
Parameters
buf.

◆ readFile()

int readFile ( int32_t  fd,
void *  buf,
int32_t  nbytes 
)

Read a file given the file descriptor index.

Parameters
fdfile descriptor index for the file to be read.
bufBuffer that is populated with the data of the file.
nbytesnumber of bytes to copy.
Returns
0 if no bytes can be read.
Number of bytes read.
Note
The data read in returned in the input buffer buf.

◆ writeDirectory()

int writeDirectory ( int32_t  fd,
const void *  buf,
int32_t  nbytes 
)

Write to a directory.

defined to match a write system call.

Parameters
fdNever used.
bufNever used.
nbytesNever used.
Returns
-1
Note
This is a read only file system.

◆ writeFile()

int writeFile ( int32_t  fd,
const void *  buf,
int32_t  nbytes 
)

Write to a file.

Defined to match a write system call.

Parameters
fdNever used.
bufNever used.
nbytesNever used.
Returns
-1

Variable Documentation

◆ dirCounter

int dirCounter = 0

Counter for read directories.