Question: im having this error message * * * System Error: Block number 8 1 2 0 is invalid * * * System Error: Block number

im having this error message *** System Error: Block number 8120 is invalid
*** System Error: Block number 1877 is invalid
We have read 0 characters from file DecOfInd.txt
We have read 0 characters from file CommonSense.txt it should be ou are provided the file DATA as the file you are accessing and that contains the files IHaveADream.txt, CommonSense.txt, DecOfInd.txt. Think of that file as the "hard drive".
The output will vary each run but at the end you should see:
We have read 8120 characters from file DecOfInd.txt
We have read 1877 characters from file CommonSense.txt #include
#include
#include
#include
#include
#include "b_io.h"
#include "fsLowSmall.h"
#define MAXFCBS 20// The maximum number of files open at one time
#define B_CHUNK_SIZE 512
typedef struct b_fcb {
fileInfo *fi;
char *buffer; // Added buffer to hold data
int buffer_position; // Added to keep track of position in buffer
} b_fcb;
b_fcb fcbArray[MAXFCBS];
int startup =0;
void b_init(){
if (startup) return;
for (int i =0; i < MAXFCBS; i++){
fcbArray[i].fi = NULL;
fcbArray[i].buffer = NULL; // Initialize buffer pointers
fcbArray[i].buffer_position =0; // Initialize buffer positions
}
startup =1;
}
b_io_fd b_getFCB(){
for (int i =0; i < MAXFCBS; i++){
if (fcbArray[i].fi == NULL){
fcbArray[i].fi =(fileInfo *)-2;
return i;
}
}
return -1; // If no free FCB found
}
b_io_fd b_open(char *filename, int flags){
if (startup ==0) b_init();
b_io_fd fd = b_getFCB();
if (fd ==-1) return -1; // No available FCB
// Get file info
fileInfo *file_info = GetFileInfo(filename);
if (file_info == NULL) return -1; // File not found
// Allocate buffer
fcbArray[fd].buffer =(char *)malloc(B_CHUNK_SIZE * sizeof(char));
if (fcbArray[fd].buffer == NULL){
free(file_info);
return -1; // Memory allocation failed
}
fcbArray[fd].fi = file_info;
fcbArray[fd].buffer_position =0; // Initialize buffer position
return fd;
}
int b_read(b_io_fd fd, char *buffer, int count){
if (startup ==0)
b_init();
if ((fd <0)||(fd >= MAXFCBS)){
return -1;
}
if (fcbArray[fd].fi == NULL){
return -1;
}
int bytes_read =0;
int bytes_to_read =0; // Define bytes_to_read variable outside the loop
while (count >0){
if (fcbArray[fd].buffer_position ==0){
bytes_to_read = B_CHUNK_SIZE < count ? B_CHUNK_SIZE : count;
// Call LBAread with appropriate parameters
int bytes_read_from_disk = LBAread(
fcbArray[fd].buffer, bytes_to_read,
fcbArray[fd]
.fi->fileSize); // Assuming fileSize contains the file size
if (bytes_read_from_disk <=0)
break;
fcbArray[fd].buffer_position = bytes_read_from_disk;
}
int bytes_to_copy = fcbArray[fd].buffer_position < count
? fcbArray[fd].buffer_position
: count;
memcpy(buffer + bytes_read, fcbArray[fd].buffer, bytes_to_copy);
bytes_read += bytes_to_copy;
count -= bytes_to_copy;
fcbArray[fd].buffer_position -= bytes_to_copy;
fcbArray[fd].buffer += bytes_to_copy;
}
return bytes_read;
}
int b_close(b_io_fd fd){
if (fd <0|| fd >= MAXFCBS || fcbArray[fd].fi == NULL) return -1;
// Free buffer memory
free(fcbArray[fd].buffer);
fcbArray[fd].buffer = NULL;
fcbArray[fd].fi = NULL;
fcbArray[fd].buffer_position =0;
return 0;
}

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!