void process_choice(int choice){
	BufferManager *bu = BufferManager::getBufferManager();
	float hr = -1;
	switch(choice){
		case 1: 
			initCache(bu);
			break;
		case 2:
			createDB(bu);
			break;
		case 3:
			openDB(bu);
			break;
		case 4:
			readDB(bu);
			break;
		case 5:
			writeDB(bu);
			break;
		case 6:
			expandDB(bu);
			break;
		case 7:
			commitDB(bu);
			break;
		case 8:
			closeDB(bu);
			break;
		case 9: 
			commitCache(bu);
			break;
		case 10:
			releaseCache(bu);
			break;
		case 11:
			dropDB(bu);
			break;
		case 12:
			cout<<endl<<"Enter Cache id: ";
			cin>>choice;
			(*bu).printHex(choice, (*bu).getPageSize());
			break;
		case 13:
			(*bu).printCacheHeaders();
			break;
		case 14:
			hr = (*bu).getHitRate();
			if(hr!=-1)
				cout<<endl<<"\tHit rate is: "<<hr*100.0<<" %"<<endl;
			else {
				cout<<endl<<"\tHit rate cannot be calculated because cache";
				cout<<" is either not initialized, or no operation";
				cout<<"	has been performed on cache yet."<<endl;
			}
			break;			
		case 15:
		//	releaseCache(bu);
			break;
	}
}
Пример #2
0
void
badEntry(afs_int32 e, afs_int32 i)
{
    int offset;
    struct kaentry entry;

    offset = i * sizeof(struct kaentry) + sizeof(struct kaheader);
    readDB(offset, &entry, sizeof(entry));

    fprintf(stderr, "Entry %d, %s, hash index %d, is bad: [", i,
	    EntryName(&entry), NameHash(&entry));
    if (e & 0x1)
	fprintf(stderr, " UserEntry");
    if (e & 0x2)
	fprintf(stderr, " FreeEntry");
    if (e & 0x4)
	fprintf(stderr, " OldkeysEntry");
    if (e & 0x8)
	fprintf(stderr, " PastEOF");
    if (!(e & 0xf))
	fprintf(stderr, " <NULL>");
    fprintf(stderr, " ] [");
    if (e & 0x10)
	fprintf(stderr, " UserChain");
    if (e & 0x20)
	fprintf(stderr, " FreeChain");
    if (e & 0x40)
	fprintf(stderr, " OldkeysChain");
    if (!(e & 0xf0))
	fprintf(stderr, " <NULL>");
    fprintf(stderr, " ]\n");
}
Пример #3
0
/// get initial db file from text cache
bool preferences::initDB(){
    bool found = false;
    char PrefIn[100];
    FILE* fp;
    string tempcache = TEMPCACHE;
    string Cache = getenv("HOME") + tempcache;
            fp = fopen(Cache.c_str(), "r");   /// open cached db location

    if(fp != NULL){
        rewind(fp);
        while(!feof(fp)){
            fscanf(fp, "%s", &PrefIn);
            found = true;

        }
    }
    else{
        return false;
    }

    if(found){   // if the db (listed in this text cache) exists
        setSQL(PrefIn);  /// set SQL location
        readDB();   // read that db
        fclose(fp);
        return true;
    }
    else{
        fclose(fp);
        return false;
    }
}
Пример #4
0
void mainmenufirst3(int t)
{
    char key;
    //Detect key UP and DOWN until ENTER is pressed
    do
    {
        key = getch();  //Get the input
        switch(key)
        {
        case 72 :
            query(--cursor3); //Select upper menu
            break;
        case 80 :
            query(++cursor3); //Select lower menu
            break;
        }

    }
    while(key!=13);
    switch(cursor3)
    {
    case 1 :
        system("cls");
        readDB("SELECT");
        system("PAUSE");
        query(cursor3);
        break;
    case 2 :
        system("cls");
        readDB("ALL");
        system("PAUSE");
        query(cursor3);
        break;
    case 3 :
        cursor3 = 1;
        mainmenu(cursor3);
    }
}
Пример #5
0
void SoftSlot::addSlot(CK_SLOT_ID newSlotID, char *newDBPath) {
  if(nextSlot == NULL_PTR) {
    nextSlot = new SoftSlot();
    slotID = newSlotID;
    dbPath = newDBPath;
    readDB();
  } else {
    // Slots may not share the same ID
    if(newSlotID == slotID) {
      FREE_PTR(newDBPath);
      return;
    }

    nextSlot->addSlot(newSlotID, newDBPath);
  }
}
Пример #6
0
QStringList DataBase::findLessonName(QString path){
    QStringList obtainedNameLesson;
    QDir findLesson(path);

    QStringList filter;
    filter << "*.lesson";

    QStringList file = findLesson.entryList(filter);

    for(int i = 0; i<file.size(); i++){
        QString nameBD = readDB(path + "/" + file.at(i));
        if(!nameBD.isEmpty())
            obtainedNameLesson << nameBD;
    }

    return obtainedNameLesson;
}
Пример #7
0
void * reader(void * v){
	int j = *((int *)v);
	while(1){
		pthread_mutex_lock(&mutex);//Lock out other readers
		rc++;
		if(rc == 1){
			pthread_mutex_lock(&db);//Lock database
		}
		pthread_mutex_unlock(&mutex);//Unlock for other readers
		readDB(j);
		pthread_mutex_lock(&mutex);//Lock out other readers
		if(writerState == 1 && rc%waitLimit == 0){//If writer ready and readers have had time
			pthread_cond_signal(&conditionWrite);//Signal writer
			pthread_cond_wait(&conditionRead,&db);//Sleep reader/toggle db mutex
			//Other readers should wait for this reader to leave critical region
		}
		pthread_mutex_unlock(&mutex);//Unlock for other readers
	}
}
Пример #8
0
static int
WorkerBee(struct cmd_syndesc *as, void *arock)
{
    afs_int32 code;
    char *dbFile;
    char *outFile;
    afs_int32 index;
    struct stat info;
    struct kaheader header;
    int nentries, i, j, count;
    int *entrys;
    struct kaentry entry;

    dbFile = as->parms[0].items->data;	/* -database */
    listuheader = (as->parms[1].items ? 1 : 0);	/* -uheader  */
    listkheader = (as->parms[2].items ? 1 : 0);	/* -kheader  */
    listentries = (as->parms[3].items ? 1 : 0);	/* -entries  */
    verbose = (as->parms[4].items ? 1 : 0);	/* -verbose  */
    outFile = (as->parms[5].items ? as->parms[5].items->data : NULL);	/* -rebuild  */

    if (outFile) {
	out = fopen(outFile, "w");
	if (!out) {
	    afs_com_err(whoami, errno, "opening output file %s", outFile);
	    exit(7);
	}
    } else
	out = 0;

    fd = open(dbFile, O_RDONLY, 0);
    if (fd < 0) {
	afs_com_err(whoami, errno, "opening database file %s", dbFile);
	exit(6);
    }
    code = fstat(fd, &info);
    if (code) {
	afs_com_err(whoami, errno, "stat'ing file %s", dbFile);
	exit(6);
    }
    if ((info.st_size - UBIK_HEADERSIZE) % UBIK_BUFFERSIZE)
	fprintf(stderr,
		"DATABASE SIZE INCONSISTENT: was %d, should be (n*%d + %d), for integral n\n",
		(int) info.st_size, UBIK_BUFFERSIZE, UBIK_HEADERSIZE);

    readUbikHeader();

    readDB(0, &header, sizeof(header));
    code = CheckHeader(&header);
    if (listkheader)
	PrintHeader(&header);

    nentries =
	(info.st_size -
	 (UBIK_HEADERSIZE + header.headerSize)) / sizeof(struct kaentry);
    entrys = calloc(nentries, sizeof(int));

    for (i = 0, index = sizeof(header); i < nentries;
	 i++, index += sizeof(struct kaentry)) {
	readDB(index, &entry, sizeof(entry));

	if (index >= header.eofPtr) {
	    entrys[i] |= 0x8;
	} else if (listentries) {
	    PrintEntry(index, &entry);
	}

	if (entry.flags & KAFNORMAL) {
	    entrys[i] |= 0x1;	/* user entry */

	    if (strlen(entry.userID.name) == 0) {
		if (verbose)
		    printf("Entry %d has zero length name\n", i);
		continue;
	    }
	    if (!DES_check_key_parity(ktc_to_cblock(&entry.key))
		|| DES_is_weak_key(ktc_to_cblock(&entry.key))) {
		fprintf(stderr, "Entry %d, %s, has bad key\n", i,
			EntryName(&entry));
		continue;
	    }

	    if (out) {
		RebuildEntry(&entry);
	    }

	} else if (entry.flags & KAFFREE) {
	    entrys[i] |= 0x2;	/* free entry */

	} else if (entry.flags & KAFOLDKEYS) {
	    entrys[i] |= 0x4;	/* old keys block */
	    /* Should check the structure of the oldkeys block? */

	} else {
	    if (index < header.eofPtr) {
		fprintf(stderr, "Entry %d is unrecognizable\n", i);
	    }
	}
    }

    /* Follow the hash chains */
    for (j = 0; j < HASHSIZE; j++) {
	for (index = header.nameHash[j]; index; index = entry.next) {
	    readDB(index, &entry, sizeof(entry));

	    /* check to see if the name is hashed correctly */
	    i = NameHash(&entry);
	    if (i != j) {
		fprintf(stderr,
			"Entry %" AFS_SIZET_FMT ", %s, found in hash chain %d (should be %d)\n",
			((index -
			  sizeof(struct kaheader)) / sizeof(struct kaentry)),
			EntryName(&entry), j, i);
	    }

	    /* Is it on another hash chain or circular hash chain */
	    i = (index - header.headerSize) / sizeof(entry);
	    if (entrys[i] & 0x10) {
		fprintf(stderr,
			"Entry %d, %s, hash index %d, was found on another hash chain\n",
			i, EntryName(&entry), j);
		if (entry.next)
		    fprintf(stderr, "Skipping rest of hash chain %d\n", j);
		else
		    fprintf(stderr, "No next entry in hash chain %d\n", j);
		code++;
		break;
	    }
	    entrys[i] |= 0x10;	/* On hash chain */
	}
    }

    /* Follow the free pointers */
    count = 0;
    for (index = header.freePtr; index; index = entry.next) {
	readDB(index, &entry, sizeof(entry));

	/* Is it on another chain or circular free chain */
	i = (index - header.headerSize) / sizeof(entry);
	if (entrys[i] & 0x20) {
	    fprintf(stderr, "Entry %d, %s, already found on free chain\n", i,
		    EntryName(&entry));
	    fprintf(stderr, "Skipping rest of free chain\n");
	    code++;
	    break;
	}
	entrys[i] |= 0x20;	/* On free chain */

	count++;
    }
    if (verbose)
	printf("Found %d free entries\n", count);

    /* Follow the oldkey blocks */
    count = 0;
    for (index = header.kvnoPtr; index; index = entry.next) {
	readDB(index, &entry, sizeof(entry));

	/* Is it on another chain or circular free chain */
	i = (index - header.headerSize) / sizeof(entry);
	if (entrys[i] & 0x40) {
	    fprintf(stderr, "Entry %d, %s, already found on olkeys chain\n",
		    i, EntryName(&entry));
	    fprintf(stderr, "Skipping rest of oldkeys chain\n");
	    code++;
	    break;
	}
	entrys[i] |= 0x40;	/* On free chain */

	count++;
    }
    if (verbose)
	printf("Found %d oldkey blocks\n", count);

    /* Now recheck all the blocks and see if they are allocated correctly
     * 0x1 --> User Entry           0x10 --> On hash chain
     * 0x2 --> Free Entry           0x20 --> On Free chain
     * 0x4 --> OldKeys Entry        0x40 --> On Oldkeys chain
     * 0x8 --> Past EOF
     */
    for (i = 0; i < nentries; i++) {
	j = entrys[i];
	if (j & 0x1) {		/* user entry */
	    if (!(j & 0x10))
		badEntry(j, i);	/* on hash chain? */
	    else if (j & 0xee)
		badEntry(j, i);	/* anything else? */
	} else if (j & 0x2) {	/* free entry */
	    if (!(j & 0x20))
		badEntry(j, i);	/* on free chain? */
	    else if (j & 0xdd)
		badEntry(j, i);	/* anything else? */
	} else if (j & 0x4) {	/* oldkeys entry */
	    if (!(j & 0x40))
		badEntry(j, i);	/* on oldkeys chain? */
	    else if (j & 0xbb)
		badEntry(j, i);	/* anything else? */
	} else if (j & 0x8) {	/* past eof */
	    if (j & 0xf7)
		badEntry(j, i);	/* anything else? */
	} else
	    badEntry(j, i);	/* anything else? */
    }

    exit(code != 0);
}