I've never learn about pascal language and my teacher had some homework about cache working and he told me write it in Pascal.
This is sample running.
Main menu
1. Open fake disk
2. Read block to file
3. Write block from file
4. Close fake disk
5. Exit
Enter your choice:1
Enter fake disk name:myfakedisk.dat
Disk has 100 blocks of 512 bytes each
1. Open fake disk
2. Read block to file
3. Write block from file
4. Close fake disk
5. Exit
Enter your choice:1
Enter fake disk name:/etc/shadow
Permission denied: cannot open '/etc/shadow'
Main menu
and i can code some code but i don't know "how to open file and count block" of it
( block is from how to create the fake disk on linux. For 13 blocks, try this:
N=13
dd if=/dev/zero of=fakedisk.dat bs=512 count=${N} )
Here is my code
program testcache(output);
uses crt;
var oldest,fs,i,n,z,bnum : integer;
map : array[1..z] of integer;
fname :string;
f : file of dat;
mode : char;{'r','w','a' --- read write append}
begin
clrscr;
fs :=-1;
writeln('Main menu');
writeln;
writeln('1. Open fake disk.');
writeln('2. Read block to file.');
writeln('3. Write block from file');
writeln('4. Close fake disk');
writeln('5. Exit');
writeln('Enter your choice: ');
readln(n);
case n of
1:writeln('Enter fake disk name: ');
readln(fname);
openf(f,fname,'r');
RESET (f);
if IORESULT <> 0 THEN
WRITELN('No such file: cannot open ',fname) ;
closef(f);
else
begin
read(f);
WRITELN('Disk has ',' blocks of ',' bytes each');
end;
2:writeln('Enter block number: ');
readln(bnum);
3:writeln('Enter block number: ');
read(bnum);
4:if
writeln('Flushing cache to fake disk...');
writeln('Fake disk closed');
5:writeln;
else
writeln('Invalid Choice');
end.
anyone please help me to complete my code T^T
thank you so much