Question: its a C language and DO NOT use any single linux file opration on this code please #include #include #include #include #include #include b
its a C language and DO NOT use any single linux file opration on this code please #include
#include
#include
#include
#include
#include bioh
#include "fsLowSmall.h
#define MAXFCBS The maximum number of files open at one time
This structure is all the information needed to maintain an open file
It contains a pointer to a fileInfo strucutre and any other information
that you need to maintain your open file.
typedef struct bfcb
fileInfo fi; holds the low level systems file info
Add any other needed variables here to track the individual open file
bfcb;
static array of file control blocks
bfcb fcbArrayMAXFCBS;
Indicates that the file control block array has not been initialized
int startup ;
Method to initialize our file system file control blocks
Anything else that needs one time initialization can go in this routine
void binit
if startup
return; already initialized
init fcbArray to all free
for int i ; i MAXFCBS; i
fcbArrayifi NULL; indicates a free fcbArray
startup ;
Method to get a free File Control Block FCB element
biofd bgetFCB
for int i ; i MAXFCBS; i
if fcbArrayifi NULL
fcbArrayifi fileInfo ; used but not assigned
return i; Not thread safe but okay for this project
return ; all in use
bopen is called by the "user application" to open a file. This routine is
similar to the Linux open function.
You will create your own file descriptor which is just an integer index into an
array of file control blocks fcbArray that you maintain for each open file.
For this assignment the flags will be read only and can be ignored.
biofd bopen char filename, int flags
if startup binit; Initialize our system
TODO Write open function to return your file descriptor
You may want to allocate the buffer here as well
But make sure every file has its own buffer
This is where you are going to want to call GetFileInfo and bgetFCB
bread functions just like its Linux counterpart read. The user passes in
the file descriptor index into fcbArray a buffer where thay want you to
place the data, and a count of how many bytes they want from the file.
The return value is the number of bytes you have copied into their buffer.
The return value can never be greater then the requested count, but it can
be less only when you have run out of bytes to read. ie End of File
int bread biofd fd char buffer, int count
TODO
Write buffered read function to return the data and # bytes read
You must use LBAread and you must buffer the data in BCHUNKSIZE byte chunks.
if startup binit; Initialize our system
check that fd is between and MAXFCBS
if fd fd MAXFCBS
return ; invalid file descriptor
and check that the specified FCB is actually in use
if fcbArrayfdfi NULLFile not open for this descriptor
return ;
Your Read code here the only function you call to get data is LBAread.
Track which byte in the buffer you are at and which block in the file
bclose frees and allocated memory and places the file control block back
into the unused pool of file control blocks.
int bclose biofd fd
TODO Release any resources
The bopen should return a integer file descriptor a number that you can track the file You may want to also allocate the BCHUNKSIZE byte buffer you will need for read operations here. Make sure though you know how to track the buffer for each individual file. Return a negative number if there is an error. You will call GetFileInfo to find the filesize and location of the desired file. See the structure fileInfo. GetFileInfo returns a pointer to fileInfo this pointer does NOT need to be freed That structure has the starting block number all files are contiguously allocated for the file and the files actual byte length.
The bread takes a file descriptor, a buffer and the number of bytes desired. The Operation of your bread function must only read BCHUNKSIZE byte chunks at a time from LBAread into your own buffer, you will then copy the appropriate bytes from your buffer to the callers buffer do not copy one byte at a time and treat the data as binary data This means you may not even need to do a read of the actual file if your buffer already has the data needed. Or it may mean that you have some bytes in the buffer, but not enough and have to transfer what you have, read the next BCHUNKSIZE bytes, then copy the remaining needed bytes to the callers buffer.
The return value is the number of bytes you have transferred to the callers buffer. When it is positive but less
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
