I'm trying to code a file system in BCPL. Everything is working properly except for my read and write functions. I believe the issue traces back to the disc_writech and disc_readch functions. Can you help me fix this. I included most of the relevant functions so you don't need to sort through a ton of code
I'm trying to code a file system in BCPL. Everything is working properly except for my read and write functions. I believe the issue traces back to the disc_writech and disc_readch functions. Can you help me fix this. I included most of the relevant functions so you don't need to sort through a ton of code
import "io"
//import "heap"
manifest
{
iosb_ichar = 9;
iosb_ochar = 10;
iosb_close = 0;
iosb_unit = 11;
iosb_buffer = 1;
iosb_pos = 2;
iosb_size = 3;
iosb_header = 4;
iosb_cre_date = 5;
iosb_headerBlock = 6;
iosb_currentBlock = 8;
iosb_length = 12;
sizeof_iosb = 13;
iosb_blockpointers = 14;
sb.rootdir = 0;
sb.firstfree = 1 }
let superblock = vec(128);
let rootdir = vec(128);
let find.free.block() be
{ let b = superblock ! sb.firstfree;
out("find a free block\n");
superblock ! sb.firstfree +:= 1;
resultis b }
let write_block(bn, mem) be
{ let r = devctl(DC_DISC_WRITE, 1, bn, 1, mem);
if r < 1 then
out("Error %d on trying to write block %d\n", r, bn) }
let disc_writech(iosb, ch) be
{
if iosb ! iosb_pos = iosb ! sizeof_iosb then
{
let r = write_block(iosb ! iosb_blockpointers ! iosb_currentBlock, iosb ! iosb_buffer);
iosb ! iosb_currentBlock +:= 1;
iosb ! sizeof_iosb +:= 512;
iosb ! iosb_blockpointers ! iosb_currentBlock := find.free.block();
if r < 0 then
{
out("code %d from disk write\n", r);
finish
}
iosb ! iosb_pos +:= 0
}
byte (iosb ! iosb_pos) of (iosb ! iosb_buffer) := ch;
iosb ! iosb_pos +:= 1 }
let disc_readch(iosb) be
{
let ch;
if iosb ! iosb_pos = 512 then
{
let r = read_block(iosb ! iosb_blockpointers ! iosb_currentBlock, iosb ! iosb_buffer);
if r < 0 then
{
out("code %d from disk read\n", r);
finish
}
//iosb ! iosb_blockpointers ! iosb_currentBlock := find.free.block();
}
ch := byte(iosb ! iosb_pos) of (iosb ! iosb_buffer);
iosb ! iosb_pos +:= 1;
resultis ch;
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps