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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education