/* testvfs.c - for 415.340 and 415.341 Assignment 2 Tests the virtual file system. Written by Robert Sheehan - 27/07/96 */ #include "vfs.h" #define BIG 1024*16 void main(int argc, char *argv[]) { char bigbuffer[BIG]; int i; char file3[] = "A file name that is of a medium length"; printf("Welcome to the virtual file system tester program.\n\n"); if (vfs_init() != VFSOK) { vfs_error(""); exit(1); } vfs_display(); if (vfs_create("", ORDINARY) != VFSOK) vfs_error("Creating empty file name"); if (vfs_create("First file", ORDINARY) != VFSOK) vfs_error("Creating \"First file\""); if (vfs_create("First file", ORDINARY) != VFSOK) vfs_error("Creating \"First file\" the second time"); if (vfs_open("First file", WRITE) != VFSOK) vfs_error("Opening \"First file\""); vfs_display(); if (vfs_open("First file", WRITE) != VFSOK) vfs_error("Opening \"First file\" the second time"); if (vfs_create("Second file", ORDINARY) != VFSOK) vfs_error("Creating \"Second file\""); vfs_display(); if (vfs_write("Second file", "Hello", 5) != VFSOK) vfs_error("Writing to \"Second file\" before opening"); if (vfs_write("First file", "Hello", 5) != VFSOK) vfs_error("Writing to \"First file\""); vfs_display(); if (vfs_open("Second file", WRITE) != VFSOK) vfs_error("Opening \"Second file\""); if (vfs_write("Second file", bigbuffer, BIG) != VFSOK) vfs_error("Writing oversized buffer"); vfs_display(); for (i = 1; i <= 4; i++) if (vfs_write("Second file", "A line of exactly 64 characters, --- four of these fills a block", 64) != VFSOK) vfs_error("Writing \"Second file\""); vfs_display(); if (vfs_write("Second file", "x", 1) != VFSOK) vfs_error("Adding one character to \"Second file\""); vfs_display(); if (vfs_create(file3, ORDINARY) != VFSOK) vfs_error("Creating file3"); vfs_display(); if (vfs_open(file3, WRITE) != VFSOK) vfs_error("Opening file3"); while (vfs_write(file3, "abc", 3) == VFSOK); vfs_error("Writing lots to file3"); vfs_display(); if (vfs_close("Second file") != VFSOK) vfs_error("Closing \"Second file\""); if (vfs_write("Second file", "x", 1) != VFSOK) vfs_error("Adding another character to \"Second file\""); if (vfs_close("Second file") != VFSOK) vfs_error("Closing \"Second file\" again"); if (vfs_close("First file") != VFSOK) vfs_error("Closing \"First file\""); if (vfs_close(file3) != VFSOK) vfs_error("Closing file3"); }