Publish VCC Plus OSS source distribution for 3.6.2 build 60
This commit is contained in:
commit
c652a5276d
1192 files changed
+272368
No files matched your search
@@ -0,0 +1,145 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// The host examines actual directory, FAT and sectors at each pause.
|
||||
#include <stdio.h>
|
||||
#include <cmoc.h>
|
||||
#include <coco.h>
|
||||
#include <decbfile.h>
|
||||
|
||||
#define CHECK(test) do { if (!(test)) { printf("FAIL LINE %u ERR %u\n", (unsigned)__LINE__, (unsigned)vcc_file_error()); return 1; } } while (0)
|
||||
static byte block[256];
|
||||
static byte ten[10];
|
||||
static DECBDrive registry;
|
||||
|
||||
static void checkpoint(const char *name, char key)
|
||||
{
|
||||
printf("%s\n", name);
|
||||
while (waitkey(0) != key) {}
|
||||
}
|
||||
|
||||
static int writeFiles(void)
|
||||
{
|
||||
unsigned i, sector;
|
||||
FILE *text, *binary, *snapshot;
|
||||
char line[20];
|
||||
byte before, after, unused;
|
||||
// A caller with an unpublished low-level FAT owns it until it is saved.
|
||||
CHECK(decb_init(®istry, 1) == DECB_OK && decb_registerDrive(0) == DECB_OK);
|
||||
CHECK(decb_getNumFreeGranules(0, &before) == DECB_OK);
|
||||
unused = decb_findFreeGranule(0);
|
||||
CHECK(unused < 68 && decb_setFATEntry(0, unused, 0xc1) == DECB_OK);
|
||||
CHECK(!fopen("BUSY.TXT", "w") && vcc_file_error() == DECB_ERR_ALREADY_EXISTS);
|
||||
CHECK(decb_setFATEntry(0, unused, 0xff) == DECB_OK && decb_writeFAT(0) == DECB_OK);
|
||||
// Interleave two writers so a stale cached directory or FAT loses a file.
|
||||
text = fopen("REPORT.TXT", "w");
|
||||
binary = fopen("LOG.BIN:0", "wb");
|
||||
CHECK(text && binary);
|
||||
CHECK(fputs("MARS RIDGE\n", text) >= 0);
|
||||
CHECK(fwrite(NULL, 0, 70, binary) == 0 && fwrite(NULL, 70, 0, binary) == 0);
|
||||
for (i = 0; i < 256; ++i) block[i] = (byte)i;
|
||||
CHECK(fwrite(block, 16, 16, binary) == 16);
|
||||
CHECK(fflush(NULL) == 0 && fflush(text) == 0);
|
||||
checkpoint("FIRST FLUSH", 'X');
|
||||
|
||||
CHECK(fclose(text) == 0);
|
||||
CHECK(fopen("log.bin", "ab") == NULL); // another writer owns the same file
|
||||
snapshot = fopen("log.bin", "rb");
|
||||
CHECK(snapshot && fread(block, 1, 256, snapshot) == 256);
|
||||
for (i = 0; i < 256; ++i) CHECK(block[i] == (byte)i);
|
||||
for (sector = 1; sector < 9; ++sector) {
|
||||
for (i = 0; i < 256; ++i) block[i] = (byte)(i + sector);
|
||||
CHECK(fwrite(block, 16, 16, binary) == 16);
|
||||
}
|
||||
CHECK(fflush(binary) == 0);
|
||||
CHECK(fgetc(snapshot) == EOF && feof(snapshot) && !ferror(snapshot));
|
||||
CHECK(fclose(snapshot) == 0 && fclose(binary) == 0);
|
||||
checkpoint("FULL GRANULE", 'Y');
|
||||
|
||||
text = fopen("REPORT.TXT", "a");
|
||||
binary = fopen("LOG.BIN", "ab");
|
||||
CHECK(text && binary);
|
||||
CHECK(fputc(0x1ff, binary) == 255 && fputc(0, binary) == 0);
|
||||
CHECK(fputs("SECOND\n", text) >= 0);
|
||||
CHECK(fclose(text) == 0 && fclose(binary) == 0);
|
||||
text = fopen("REPORT.TXT", "r");
|
||||
CHECK(text && fgets(line, sizeof(line), text) && strcmp(line, "MARS RIDGE\n") == 0);
|
||||
CHECK(fgets(line, sizeof(line), text) && strcmp(line, "SECOND\n") == 0);
|
||||
CHECK(fclose(text) == 0);
|
||||
// This file already spans 65,537 bytes; the append position must not wrap.
|
||||
binary = fopen("DISTANT.DAT", "ab");
|
||||
CHECK(binary && fputc(0xfe, binary) == 254 && fclose(binary) == 0);
|
||||
checkpoint("APPENDED", 'Z');
|
||||
|
||||
binary = fopen("LOG.BIN", "wb"); // truncation gives back an occupied granule
|
||||
CHECK(binary && fflush(binary) == 0 && fclose(binary) == 0);
|
||||
text = fopen("ABSENT.TXT", "a"); // append creates a missing file
|
||||
CHECK(text && fputs("A\n", text) >= 0 && fclose(text) == 0);
|
||||
// The library created two files and shrank the original two-granule log.
|
||||
CHECK(decb_getNumFreeGranules(0, &after) == DECB_OK && after + 1 == before);
|
||||
decb_shutdown();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fillDisk(void)
|
||||
{
|
||||
FILE *out = fopen("LAST.DAT", "wb");
|
||||
unsigned i;
|
||||
CHECK(out);
|
||||
for (i = 0; i < 10; ++i) ten[i] = (byte)('a' + i);
|
||||
// One free granule before open. Check that fwrite counts complete items
|
||||
// and exposes the full-volume error whether a sector was buffered or not.
|
||||
for (i = 0; i < 230; ++i) CHECK(fwrite(ten, 10, 1, out) == 1);
|
||||
CHECK(fflush(out) == 0);
|
||||
checkpoint("LAST FOUR BYTES", 'X');
|
||||
// Four bytes fit on disk and one 256-byte sector fits in the buffer.
|
||||
// 260 bytes accepted means 86 complete three-byte objects.
|
||||
byte tail[270];
|
||||
memset(tail, 0xf3, sizeof(tail));
|
||||
CHECK(fwrite(tail, 3, 90, out) == 86);
|
||||
CHECK(ferror(out) == DECB_ERR_OUT_OF_SPACE);
|
||||
CHECK(fclose(out) == EOF);
|
||||
CHECK(fopen("NOSPACE.DAT", "wb") == NULL && vcc_file_error() == DECB_ERR_OUT_OF_SPACE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int protectDuringFlush(void)
|
||||
{
|
||||
FILE *out = fopen("REPORT.TXT", "w");
|
||||
CHECK(out && fputs("MARS RIDGE\n", out) >= 0 && fflush(out) == 0);
|
||||
CHECK(fputs("UNSAVED\n", out) >= 0);
|
||||
checkpoint("PROTECT NOW", 'X');
|
||||
CHECK(fflush(out) == EOF && ferror(out) == DECB_ERR_IO);
|
||||
CHECK(fclose(out) == EOF && vcc_file_error() == DECB_ERR_IO);
|
||||
CHECK(!fopen("REPORT.TXT", "w") && vcc_file_error() == DECB_ERR_IO);
|
||||
CHECK(!fopen("ABSENT.TXT", "w") && vcc_file_error() == DECB_ERR_IO);
|
||||
CHECK(rename("SAFE.DAT", "SAVED.DAT") == EOF && vcc_file_error() == DECB_ERR_IO);
|
||||
CHECK(remove("SAFE.DAT") == EOF && vcc_file_error() == DECB_ERR_IO);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int result;
|
||||
cls(1);
|
||||
printf("SELECT CHECK\n");
|
||||
switch(waitkey(0)) {
|
||||
case 'B': // Disk BASIC has left an input file open on this drive.
|
||||
CHECK(!fopen("SAFE.DAT", "w") && vcc_file_error() == DECB_ERR_ALREADY_EXISTS);
|
||||
CHECK(rename("SAFE.DAT", "SAVED.DAT") == EOF && vcc_file_error() == DECB_ERR_ALREADY_EXISTS);
|
||||
CHECK(remove("SAFE.DAT") == EOF && vcc_file_error() == DECB_ERR_ALREADY_EXISTS);
|
||||
result = 0;
|
||||
break;
|
||||
case 'C': // Two directory entries name the same physical chain.
|
||||
CHECK(!fopen("SAFE.DAT", "w") && vcc_file_error() == DECB_ERR_CORRUPT_FAT);
|
||||
CHECK(!fopen("NEW.DAT", "a") && vcc_file_error() == DECB_ERR_CORRUPT_FAT);
|
||||
CHECK(rename("SAFE.DAT", "SAVED.DAT") == EOF && vcc_file_error() == DECB_ERR_CORRUPT_FAT);
|
||||
CHECK(remove("SAFE.DAT") == EOF && vcc_file_error() == DECB_ERR_CORRUPT_FAT);
|
||||
result = 0;
|
||||
break;
|
||||
case 'W': result = writeFiles(); break;
|
||||
case 'F': result = fillDisk(); break;
|
||||
case 'P': result = protectDuringFlush(); break;
|
||||
default: return 1;
|
||||
}
|
||||
if (!result) printf("WRITES PASSED\n");
|
||||
return result;
|
||||
}
|
||||
Reference in new issue
Block a user