From: nealcrook Date: Tue, 22 Nov 2016 22:09:38 +0000 (+0000) Subject: Do proper status checking on all the file operations. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=afe5f3b3a9225a0ac93b6bc5aa7e4f2bbc411564;p=FUZIX.git Do proper status checking on all the file operations. --- diff --git a/Applications/BCPL/icint.c b/Applications/BCPL/icint.c index 98833d79..0dc02c7f 100644 --- a/Applications/BCPL/icint.c +++ b/Applications/BCPL/icint.c @@ -57,7 +57,7 @@ #ifdef PAGEDMEM -#define VBLKS 64 +#define VBLKS 63 #else #define VBLKS PBLKS #endif @@ -152,6 +152,10 @@ pagein(uint16_t page) int i; int victim_block; +#if 0 + fprintf(stderr, "Pagein: page=%d, translations=%d\n",page, translations); +#endif + /* First attempt: search pmap for an unassigned block */ for (i=0; i= 0) { - // [NAC HACK 2016Nov19] check read return value, too - i = read(pfp, (unsigned char *)(M+i*BLKSIZE), 2*BLKSIZE); - } - else { - perror("Seek error replacing clean block"); + if ( (lseek(pfp, (uint16_t)(page*2*BLKSIZE), SEEK_SET) < 0) || + (2*BLKSIZE != read(pfp, (unsigned char *)(M+i*BLKSIZE), 2*BLKSIZE)) ) { + perror("replace clean"); + exit(1); } } return; @@ -199,17 +201,14 @@ pagein(uint16_t page) pagefile is pmap[victim_block]*2*BLKSIZE. It comes from the physical buffer at byte offset victim_block*2*BLKSIZE. It is 2*BLKSIZE bytes. */ - if (lseek(pfp, (uint16_t)(pmap[victim_block]*2*BLKSIZE), SEEK_SET) >= 0) { - // [NAC HACK 2016Nov19] check write return value, too - i = write(pfp, (unsigned char *)(M+victim_block*BLKSIZE), 2*BLKSIZE); - } - else { - perror("Seek error evicting dirty block"); + if ( (lseek(pfp, (uint16_t)(pmap[victim_block]*2*BLKSIZE), SEEK_SET) < 0) || + (2*BLKSIZE != write(pfp, (unsigned char *)(M+victim_block*BLKSIZE), 2*BLKSIZE)) ) { + perror("page-out dirty"); + exit(1); } pagstate[pmap[victim_block]] = PAGCLEAN; vmap[pmap[victim_block]] = -1; - pmap[victim_block] = page; vmap[page] = victim_block; if (pagstate[page] == PAGCLEAN) { @@ -218,13 +217,10 @@ pagein(uint16_t page) and it will go into the buffer at (of course) the same place as victim_block was written out from. Transfer 2*BLKSIZE bytes. */ - - if (lseek(pfp, (uint16_t)(page*2*BLKSIZE), SEEK_SET) >= 0) { - // [NAC HACK 2016Nov19] check read return value, too - i = read(pfp, (unsigned char *)(M+victim_block*BLKSIZE), 2*BLKSIZE); - } - else { - perror("Seek error replacing dirty block"); + if ( (lseek(pfp, (uint16_t)(page*2*BLKSIZE), SEEK_SET) < 0) || + (2*BLKSIZE != read(pfp, (unsigned char *)(M+victim_block*BLKSIZE), 2*BLKSIZE)) ) { + perror("replace dirty"); + exit(1); } } } @@ -598,9 +594,9 @@ int main(int argc, char *argv[]) } buf = (char *)pgvec; for (i=0; i