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 "b_io.h"
#include "fsLowSmall.h"
#define MAXFCBS 20//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 b_fcb
{
fileInfo * fi; //holds the low level systems file info
// Add any other needed variables here to track the individual open file
} b_fcb;
//static array of file control blocks
b_fcb fcbArray[MAXFCBS];
// Indicates that the file control block array has not been initialized
int startup =0;
// Method to initialize our file system / file control blocks
// Anything else that needs one time initialization can go in this routine
void b_init ()
{
if (startup)
return; //already initialized
//init fcbArray to all free
for (int i =0; i < MAXFCBS; i++)
{
fcbArray[i].fi = NULL; //indicates a free fcbArray
}
startup =1;
}
//Method to get a free File Control Block FCB element
b_io_fd b_getFCB ()
{
for (int i =0; i < MAXFCBS; i++)
{
if (fcbArray[i].fi == NULL)
{
fcbArray[i].fi =(fileInfo *)-2; // used but not assigned
return i; //Not thread safe but okay for this project
}
}
return (-1); //all in use
}
// b_open 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.
b_io_fd b_open (char * filename, int flags)
{
if (startup ==0) b_init(); //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 b_getFCB
}
// b_read 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. i.e. End of File
int b_read (b_io_fd 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 B_CHUNK_SIZE byte chunks.
if (startup ==0) b_init(); //Initialize our system
// check that fd is between 0 and (MAXFCBS-1)
if ((fd <0)||(fd >= MAXFCBS))
{
return (-1); //invalid file descriptor
}
// and check that the specified FCB is actually in use
if (fcbArray[fd].fi == NULL)//File not open for this descriptor
{
return -1;
}
// 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
}
// b_close frees and allocated memory and places the file control block back
// into the unused pool of file control blocks.
int b_close (b_io_fd fd)
{
//*** TODO ***// Release any resources
}The b_open should return a integer file descriptor (a number that you can track the file). You may want to also allocate the 512(B_CHUNK_SIZE) 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 b_read takes a file descriptor, a buffer and the number of bytes desired. The Operation of your b_read function must only read B_CHUNK_SIZE 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 B_CHUNK_SIZE 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!