예제 #1
0
/*
  This function initialises the memory copy of the disk with the contents from the actual disk file.
*/
int loadFileToVirtualDisk(){
  int i;
  for(i=FREE_LIST_START_BLOCK; i<FREE_LIST_START_BLOCK + NO_OF_FREE_LIST_BLOCKS; i++)
      readFromDisk(i,i);
  for(i=FAT_START_BLOCK; i<FAT_START_BLOCK + NO_OF_FAT_BLOCKS; i++)
      readFromDisk(i,i);
}
예제 #2
0
SimpleJsonDB::SimpleJsonDB(const QString vpath, const QString path, bool createEmpty, int maxFlushDelayMillis) : db(), vpath(vpath), path(path), writeLock(), flushTimer(this), maxFlushDelay(maxFlushDelayMillis), skipDisk(false), filterVmAndDomstoreKeys(false)
{
    flushTimer.setSingleShot(true);

    // connect timer up to flush function
    if (!QObject::connect(&flushTimer, &QTimer::timeout, this, &SimpleJsonDB::flush))
    {
        qCritical("failed to connect timeout() to flush()");
    }

    // inter-thread signal so main thread can trigger the timer start
    if (!QObject::connect(this, &SimpleJsonDB::signalFlushTimer, this, &SimpleJsonDB::startFlushTimer))
    {
        qCritical("failed to connect signalFlushTimer() to startFlushTimer()");
    }

    // read in db from disk if not createEmpty
    if (createEmpty) {
        auto obj = QMPointer<QMJsonObject>(new QMJsonObject());
        db = QMPointer<QMJsonValue>(new QMJsonValue(obj));
    } else {
        readFromDisk();
    }

    qDebug() << db;
}
예제 #3
0
/*
  This function copies the contents of the disk starting from <startBlock> to <endBlock> to a unix file.
*/
void copyBlocksToFile (int startblock,int endblock,char *filename)
{
	int fd;
	fd = open(DISK_NAME, O_RDONLY, 0666);
	if(fd < 0){
	  printf("Unable to Open Disk File!\n");
	  return;
	}
	close(fd);
	int i,j;
	FILE *fp;
	expandpath(filename);
	fp = fopen(filename,"w");
	if(fp == NULL)
	{
		printf("File \'%s\' not found!\n", filename);
	}
	else
	{
		for(i = startblock; i <= endblock; i++)
		{
			emptyBlock(TEMP_BLOCK);
			readFromDisk(TEMP_BLOCK,i);
			for(j=0;j<BLOCK_SIZE;j++)
			{
				fprintf(fp,"%s\n",disk[TEMP_BLOCK].word[j]);
			}
		}
		fclose(fp);
	}

}
예제 #4
0
파일: hash.c 프로젝트: sagar13/temp
int main()
{
	int choice;
	char ans = 'y';
	char fname[SIZE];
	struct linknode *hashTable[TABLESIZE];
	initializeHashTable(hashTable);
	
	while(ans == 'y')
	{
		printf("\n1. Create file\n");
		printf("2. Delete File\n");
		printf("3. Search File\n");
		printf("4. Display Table\n");
		printf("5. Exit\n");
		printf("6. Write to disk\n");
		printf("7. Read from disk\n");
		printf("\nEnter choice: ");
		scanf("%d", &choice);
		switch(choice)
		{
			case 1:
				printf("Enter file name: ");
				scanf("%s", fname);
				insertFile(fname, hashTable);
				break;

			case 2:
				printf("Enter file name: ");
				scanf("%s", fname);
				deleteFile(fname, hashTable);
				break;

			case 3:
				printf("Enter file name: ");
				scanf("%s", fname);
				searchFile(fname, hashTable);
				break;

			case 4:
				displayTable(hashTable);
				break;

			case 5:
				exit(0);

			case 6:
				writeToDisk(hashTable);
				break;

			case 7:
				readFromDisk(hashTable);
				break;
		}
	}
	return (0);
}
예제 #5
0
파일: Ext2FS.cpp 프로젝트: keke222/Brokenos
void Ext2FS::readGroupBlock()
{
    int offset, gd_size;

    offset = (_blockSize == 1024) ? 2048 : _blockSize;

    gd_size = _groupNumber * sizeof(struct ext2_group_desc);

    _groups = (struct ext2_group_desc*)readFromDisk(offset, gd_size);
}
예제 #6
0
void wbPipeline(char* outDir, char* dir, char* first, int start)
{
  char out[1024];
  std::strcpy(out, outDir);
  std::strcat(out, "whiteboard/");
  char WBdir[1024];
  std::strcpy(WBdir, dir);
  char WBfirst[1024];
  std::strcpy(WBfirst, first);
  

  ////////////////////////////////
  /// Camera/WB Cap/Proc Buffers /
  Buffer* wbBuffer;
  wbBuffer = new Buffer;
  Buffer* lectVideoBuffer;
  lectVideoBuffer = new Buffer;
  Buffer* wbSlidesBuffer;
  wbSlidesBuffer = new Buffer;
  Buffer* wbSlidesWriteBuffer;
  wbSlidesWriteBuffer = new Buffer;
  Buffer* wbReadBuffer;
  wbReadBuffer = new Buffer;

  //////////////////////////////////////
  // WB Cap/Proc Modules
  WriteMod wbSlidesWriter(wbSlidesWriteBuffer);
  WhiteBoardFoot wbSlides(wbSlidesBuffer,wbSlidesWriteBuffer);
  WhiteBoardProcess wbproc(wbBuffer, wbSlidesBuffer);
  LocateSpeaker locateSpeaker(wbReadBuffer, wbBuffer);
  ReadMod readFromDisk(wbReadBuffer);
  
  boost::thread_group wbThreads;
  
  wbThreads.create_thread(boost::bind(&WriteMod::WriteSlides, &wbSlidesWriter, out, "whiteboard", start));
  wbThreads.create_thread(boost::bind(&WhiteBoardFoot::run, &wbSlides));
  wbThreads.create_thread(boost::bind(&WhiteBoardProcess::run, &wbproc, 1));
  wbThreads.create_thread(boost::bind(&LocateSpeaker::run, &locateSpeaker));
  wbThreads.create_thread(boost::bind(&ReadMod::ReadFromPatternFlipExtCrop, &readFromDisk, WBdir,WBfirst,400,1400,3600,1000));
  
  wbThreads.join_all();
  
  delete wbSlidesBuffer;
  delete wbBuffer;
  delete lectVideoBuffer;
  delete wbReadBuffer;
  
}
예제 #7
0
파일: Ext2FS.cpp 프로젝트: keke222/Brokenos
struct ext2_inode* Ext2FS::readInode(int num)
{
	int gr_num, index, offset;

    //struct ext2_inode *inode = (struct ext2_inode*)kmalloc(sizeof(struct ext2_inode));
    struct ext2_inode *inode;

    gr_num = (num - 1) / _sb->inodes_per_group;

    index = (num - 1) % _sb->inodes_per_group;

    offset = _groups[gr_num].inode_table * _blockSize + index * _sb->inode_size;

    inode = (ext2_inode*)readFromDisk(offset, _sb->inode_size);

	return inode;
}
예제 #8
0
/*
  This function returns the basic block entry(pass by pointer) corresponding to the address specified by the second arguement.
  Third argument specifies the type of file (assembly code or data file)
  NOTE: locationOfFat - relative word address of the name field in the fat.
*/
int getDataBlocks(int *basicBlockAddr, int locationOfFat)
{

	int i,a;
	basicBlockAddr[0] = getValue(disk[FAT + locationOfFat / BLOCK_SIZE].word[locationOfFat % BLOCK_SIZE + FATENTRY_BASICBLOCK]);
	emptyBlock(TEMP_BLOCK);
	//printf("Basic Block = %d\n",basicBlockAddr[0]);
	readFromDisk(TEMP_BLOCK,basicBlockAddr[0]);

	i = 0;
	a = getValue(disk[TEMP_BLOCK].word[i]);
	while ((a > 0) && i < MAX_DATAFILE_SIZE)
	{
		//printf("%d %d\t",i+1,a);
		basicBlockAddr[i+1] = a;
		i++;
		a = getValue(disk[TEMP_BLOCK].word[i]);
	}

	return 0;
}
예제 #9
0
/*
  This function displays the content of the files stored in the disk.
*/
void displayFileContents(char *name)
{
	int fd;
	fd = open(DISK_NAME, O_RDONLY, 0666);
	if(fd < 0){
	  printf("Unable to Open Disk File!\n");
	  return;
	}

	close(fd);
	int i,j,k,l,flag=0,locationOfFat;
	int blk[512];

	for(i=0;i<511;i++)
		blk[i] = 0;

	locationOfFat = CheckRepeatedName(name);
	if(locationOfFat >= FAT_SIZE){
		printf("File \'%s\' not found!\n",name);
		return;
	}


	getDataBlocks(blk,locationOfFat);

	k = 1;
	while (blk[k] > 0)
	{
		emptyBlock(TEMP_BLOCK);
		readFromDisk(TEMP_BLOCK,blk[k]);
		for(l=0;l<BLOCK_SIZE;l++)
		{
			if(strcmp(disk[TEMP_BLOCK].word[l],"\0")!=0)
				printf("%s   \n",disk[TEMP_BLOCK].word[l]);
		}
		//printf("next block\n");
		emptyBlock(TEMP_BLOCK);
		k++;
	}
}
예제 #10
0
PmuXML readPmuXml(const char * const path)
{
    PmuXML pmuXml {{},{}};
    {
        const char *xml;
        unsigned int len;
        getDefaultXml(&xml, &len);
        parse(pmuXml, xml);
    }

    if (path != NULL) {
        // Parse user defined items second as they will show up first in the linked list
        char *xml = readFromDisk(path);
        if (xml == NULL) {
            logg.logError("Unable to open additional pmus XML %s", path);
            handleException();
        }
        parse(pmuXml, xml);
        free(xml);
    }
    return pmuXml;
}
예제 #11
0
파일: utility.c 프로젝트: lenywv/xsm
int performLoadStore(int X, int flagX, int Y, int flagY, int instruction) {
	if (mode == USER_MODE) {
		raiseException(newException(EX_ILLINSTR, "Call to Privileged Instruction in USER mode", 0));		
		return 0;
	}
	Exception e = isSafeState2();
	if (e.code != EX_NONE) {
		raiseException(e);
		return 0;
	}
	switch (flagX) {
		case REG:
		case SP:
		case BP:
		case IP:
		case PTBR:
		case PTLR:
		case EFR:
			e = isRegisterInaccessible(X);
			if (e.code != EX_NONE) {
				raiseException(e);
				return 0;
			}
			if (getType(reg[X]) == TYPE_STR) {
				raiseException(newException(EX_ILLOPERAND, "Illegal operand", 0));
				return 0;
			} else X = getInteger(reg[X]);					
			break;
		case NUM:
			break;
		default:
			raiseException(newException(EX_ILLOPERAND, "Illegal operand", 0));
			return 0;
			break;
	}
	switch (flagY) {
		case REG:
		case SP:
		case BP:
		case IP:
		case PTBR:
		case PTLR:
		case EFR:
			e = isRegisterInaccessible(Y);
			if (e.code != EX_NONE) {
				raiseException(e);
				return 0;
			}
			if (getType(reg[Y]) == TYPE_STR) {
				raiseException(newException(EX_ILLOPERAND, "Illegal operand", 0));
				return 0;
			} else Y = getInteger(reg[Y]);					
			break;
		case NUM:
			break;
		default:
			raiseException(newException(EX_ILLOPERAND, "Illegal operand", 0));
			return 0;
			break;
	}
	if (instruction == LOAD) {			
		emptyPage(X);
		readFromDisk(X, Y);
	} else if (instruction == STORE) writeToDisk(Y, X);
	return 1;
}
예제 #12
0
bool ServerSettings::start()
{
	readFromDisk();
	setRunning(true);
	return true;
}
예제 #13
0
파일: Ext2FS.cpp 프로젝트: keke222/Brokenos
void Ext2FS::readSuperBlock()
{
    _sb = (struct ext2_super_block*)readFromDisk(1024, sizeof(struct ext2_super_block));
}
예제 #14
0
파일: Ext2FS.cpp 프로젝트: keke222/Brokenos
char* Ext2FS::readFile(struct file *file)
{
	char *mmap_base, *mmap_head, *buf;

	int *p,*pp, *ppp;
    int n;
    unsigned int size;

    struct filePrivateData *data = (struct filePrivateData*)file->privateData;

    if(!data)
        return 0;

    struct ext2_inode *inode = data->inode;

    //Screen::getScreen().printInfo("\tData inode : %p, num %u, size %u", data->inode, data->inum, inode->size);

    //buf = (char*)kmalloc(_blockSize);
    //p = (int*)kmalloc(_blockSize);
    //pp = (int*)kmalloc(_blockSize);
    //ppp = (int*)kmalloc(_blockSize);

	size = inode->size; // Taille totale du fichier
    file->size = inode->size;
	mmap_head = mmap_base = (char*)kmalloc(size);

    //Screen::getScreen().printDebug("BlockSize : %d", _blockSize);

	// Direct block number
	for(int i = 0; i < 12 && inode->block[i]; ++i)
	{
        buf = readFromDisk(inode->block[i] * _blockSize, _blockSize);

		n = ((size > _blockSize) ? _blockSize : size);

		memcpy(mmap_head, buf, n);
		mmap_head += n;
		size -= n;

        kfree(buf);
	}

	// Indirect block number
	if(inode->block[12])
	{
         p = (int*)readFromDisk(inode->block[12] * _blockSize, _blockSize);

		for(int i = 0; i < _blockSize / 4 && p[i]; ++i)
        {
            buf = readFromDisk(p[i] * _blockSize, _blockSize);

			n = ((size > _blockSize) ? _blockSize : size);

			memcpy(mmap_head, buf, n);
			mmap_head += n;
			size -= n;

            kfree(buf);
		}

        kfree(p);
	}

	// Bi-indirect block number
	if(inode->block[13])
    {
         p = (int*)readFromDisk(inode->block[13] * _blockSize, _blockSize);

		for(int i = 0; i < _blockSize / 4 && p[i]; ++i)
		{
             pp = (int*)readFromDisk(p[i] * _blockSize, _blockSize);

			for(int j = 0; j < _blockSize / 4 && pp[j]; ++j)
            {
                buf = readFromDisk(pp[j] * _blockSize, _blockSize);

				n = ((size > _blockSize) ? _blockSize : size);

				memcpy(mmap_head, buf, n);
				mmap_head += n;
				size -= n;

                kfree(buf);
			}

            kfree(pp);
		}

        kfree(p);
	}

	// Tri-indirect block number
	if(inode->block[14])
    {
         p = (int*)readFromDisk(inode->block[14] * _blockSize, _blockSize);

		for(int i = 0; i < _blockSize / 4 && p[i]; ++i)
		{
             pp = (int*)readFromDisk(p[i] * _blockSize, _blockSize);

			for(int j = 0; j < _blockSize / 4 && pp[j]; ++j)
            {
                ppp = (int*)readFromDisk(pp[j] * _blockSize, _blockSize);

				for(int k = 0; k < _blockSize / 4 && ppp[k]; ++k)
				{
                     buf = readFromDisk(ppp[k] * _blockSize, _blockSize);

					n = ((size > _blockSize) ? _blockSize : size);

					memcpy(mmap_head, buf, n);
					mmap_head += n;
					size -= n;

                    kfree(buf);
				}

                kfree(ppp);
			}

            kfree(pp);
		}

        kfree(p);
	}

	return mmap_base;
}
예제 #15
0
Service::Status ServerSettings::start()
{
  readFromDisk();
  setRunning(true);
  return Service::OK;
}
예제 #16
0
bool AlClipboard::writeToClipboard(char *pKey)
{
	logger->debug("AlClipboard::writeToClipboard:-- START\n");

	char tbuf[128];
	ZeroMemory(tbuf, sizeof(char) * 128);

	char tbuf2[128];
	ZeroMemory(tbuf2, sizeof(char) * 128);
	sprintf(tbuf, "%s/%s\0", DEFAULT_DIRECTORY_NAME, pKey);
	sprintf(tbuf2, "\t reading... '%s'\n\0", tbuf);
	logger->debug(tbuf2);
	FILE *fle = fopen(tbuf, "rt");
	if (!fle)
	{
		sprintf(tbuf2, "\t Opening file '%s' failed.\n\0", tbuf);
		logger->debug(tbuf2);
		return false;
	}
	fseek(fle, 0, SEEK_END);
	int maxSize = ftell(fle);
	fclose(fle);

	sprintf(tbuf2, "\t File size: '%i'.\n\0", maxSize);
	logger->debug(tbuf2);
	if (maxSize < 1)
	{
		sprintf(tbuf2, "\t file too small.\n\0", tbuf);
		logger->debug(tbuf2);
		return false;
	}

	char *pBuffer = NULL;
	pBuffer = new char[maxSize+1];
	ZeroMemory(pBuffer, sizeof(char) * (maxSize+1));
	if (!readFromDisk(pKey, pBuffer, maxSize))
	{
		return false;
	}

	if (!OpenClipboard(NULL))
	{
		logger->debug("\t OpenClipboard.. FAILED..\n");
		return false;
	}

	EmptyClipboard();
	HGLOBAL hClipboardData;
	hClipboardData = GlobalAlloc(GMEM_DDESHARE, maxSize+1);
	char * pchData;
	pchData = (char*)GlobalLock(hClipboardData);
	strcpy(pchData, pBuffer);
	GlobalUnlock(hClipboardData);
	SetClipboardData(CF_TEXT, hClipboardData);


	logger->debug("\t CloseClipboard()");
	CloseClipboard();
	SAFE_DEL(pBuffer);
	return true;
}