Ejemplo n.º 1
0
void wrapTest(void (*test)()) {
   REQUIRE_EQ(tfs_mkfs(DEFAULT_DISK_NAME, DEFAULT_DISK_SIZE), TFS_SUCCESS);
   REQUIRE_EQ(tfs_mount(DEFAULT_DISK_NAME), TFS_SUCCESS);

   test();

   REQUIRE_EQ(tfs_unmount(), TFS_SUCCESS);
}
Ejemplo n.º 2
0
/*
 * Mount FileSystem,
 * Initialize the buffer.
 */
int commence(char * database,
             Buffer * buf, 
             int nBufferBlocks, 
             int nCacheBlocks) {
   int num, exit_code = 0;

   if (access(database, F_OK) == -1) { /* fs does not exist */
      exit_code += tfs_mkfs(database, (nBufferBlocks * sizeof(Block)) + sizeof(Buffer));
   }
   /* mount the database */
   exit_code += tfs_mount(database);

   /* initialize buffer */
   buf->database = (char *)malloc(sizeof(strlen(database) * sizeof(char)));
   strcpy(buf->database, database);

   /* persistent slots */
   buf->nBufferBlocks = nBufferBlocks;
   buf->numBufferOccupied = 0;
   buf->pages = (Block *)malloc(sizeof(Block) * nBufferBlocks);
   buf->buffer_timestamp = (long *)malloc(sizeof(long) * nBufferBlocks);

   /* volatile slots */
   buf->nCacheBlocks = nCacheBlocks;
   buf->numCacheOccupied = 0;
   buf->cache = (Block *)malloc(sizeof(Block) * nCacheBlocks);
   buf->cache_timestamp = (long *)malloc(sizeof(long) * nCacheBlocks);

   /* other stuff */
   buf->pin = (char *)malloc(sizeof(char) * nBufferBlocks);
   buf->dirty = (char *)malloc(sizeof(char) * nBufferBlocks);
   
   for (num = 0; num < nBufferBlocks; num++) {
      /* set timestamp to -1, -1 means it's an empty slot */
      buf->buffer_timestamp[num] = -1;
      buf->pin[num] = 0;
      buf->dirty[num] = 0;
   }

   for (num = 0; num < nCacheBlocks; num++) {
      buf->cache_timestamp[num] = -1;
   }
   
   buf->numVolatileFiles = 0;
   buf->numPersistentFiles = 0;
   
   return exit_code;
}
Ejemplo n.º 3
0
void testFormat() {
   printf("testing tfs_mkfs\n");

   printf("non-existant file with size 0\n");
   REQUIRE_EQ(tfs_mkfs(FILE_NOT_EXISTS, 0), TFS_ESIZE);

   printf("non-existant file with size 1\n");
   REQUIRE_EQ(tfs_mkfs(FILE_NOT_EXISTS, 1), TFS_ESIZE);

   printf("non-existant file with size %d\n", DEFAULT_DISK_SIZE);
   REQUIRE_EQ(tfs_mkfs(FILE_NOT_EXISTS, DEFAULT_DISK_SIZE), TFS_SUCCESS);
   REQUIRE_EQ(access(FILE_NOT_EXISTS, R_OK | W_OK), 0);
   unlink(FILE_NOT_EXISTS);

   printf("existant file with size %d\n", DEFAULT_DISK_SIZE);
   REQUIRE_EQ(tfs_mkfs(FILE_EXISTS, DEFAULT_DISK_SIZE), TFS_SUCCESS);

   printf("existant file with size 1\n");
   REQUIRE_EQ(tfs_mkfs(FILE_EXISTS, 1), TFS_ESIZE);

   printf("existant file with size 0\n");
   REQUIRE_EQ(tfs_mkfs(FILE_EXISTS, 0), TFS_SUCCESS);
}
Ejemplo n.º 4
0
int main() {
   int status = 42, status2 = 41, status3 = 40;
   int i;
   fileDescriptor fd, fd2, fd3;
   /* the following blah was a funny thing taken from the internet */
   char *blah = "what the f**k did you just f*****g say about me, you little bitch? i'll have you know i graduated top of my class in the navy seals, and i've been involved in numerous secret raids on al-quaeda and i have over 300 confirmed kills, i am trained in gorilla warfare and i'm the top sniper in the entire us armed forces. you are nothing to me but just another target. i will wipe you the f**k out with precision the likes of which has never been sseen before on this earth, m ark my f*****g words. you think you can get away with saying that shit to me over the internet? think again, f****r. as we speak i am contacting my secret network of spies across the USA and your IP is being traced right now so you better prepfare for the storm, maggot. the storm that wipes out the pathetic little thin you call your life. you're f*****g dead, kids. i can be anywhere, antytime, and i can kill you in over seven hundred ways, and that's just with my bare hands, no tonly am i extensitively trained in unarmed combat, but i have access to the entire arsenal of the united states marine corps and i will use it to its full extend to wipe your miserable ass off the face of the continent, you little shit. if you could have known what unholy retribution your little clverer comment was about to bring down upon you, maybe you would have held your f*****g tongue,, but you couldn't";
   char *blah2 = "tiny message";
   char datByte;

   status = tfs_mkfs("asdf", DEFAULT_DISK_SIZE);
   status3 = tfs_mount("asdf");
   fd = tfs_openFile("filez");
   fd2 = tfs_openFile("filez2");
   tfs_makeRO("filez");
   status2 = tfs_writeFile(fd, blah, 1300);

   printf("after makeRO: %d\n", status2);
   
   /*fd3 = tfs_openFile("filez3");
   */
   //status2 = tfs_writeFile(fd, blah, 1300);

   tfs_makeRW("filez");
   status2 = tfs_writeFile(fd, blah, 1300);
   printf("after makeRW: %d\n", status2);
   status2 = tfs_seek(fd, 1299);
   status2 = tfs_writeByte(fd, 'g');
   printf("after writeByrte: %d\n", status2);
   /*
   time_t a = tfs_readFileInfo(fd);
   printf("THE TIME: %s\n", ctime(&a));
   */
   
   //status3 = tfs_deleteFile(fd2);
   //status2 = tfs_writeFile(fd3, blah2, sizeof("tiny message"));
   

   /*for(i = 0; i < 1300; i++) {
      tfs_readByte(fd, &datByte);
      printf("%c", datByte);
   }*/
   printf("\n");

   printf("tfs_mkfs: %d\n tfs_mount %d tfs_openfile: %d\n", status, status3, status2);

   /*
   int r = openDisk("asdf", 10240), status;
   void *a = "asdfasdf\0", *b;
//   printf("%d\n", r);
   status = writeBlock(r, 0, a);
//   printf("%d\n", status);
   b = malloc(256);
   status = readBlock(r, 0, b);
   printf("%d\n%s\n", 123234782578, (char*)b);
   
   
   free(b);
   close(r);
   */
   return 0;
}