예제 #1
0
/*
  This function copies the exception handler to the proper location on the disk.
*/
int loadExHandlerToDisk(char* fileName)
{
	expandpath(fileName);
	FILE* fp = fopen(fileName, "r");
	int i,j;
	if(fp == NULL)
	{
		printf("File %s not found.\n", fileName);
		return -1;
	}

	for(i=0;i<EX_HANDLER_SIZE;i++)
	{
		j = writeFileToDisk(fp, EX_HANDLER + i, ASSEMBLY_CODE);
		if(j != 1)
			break;
	}
	if(j==1)
	{
		printf("Exception Handler exceeds one block\n");
		deleteExHandlerFromDisk();
		//emptyBlock(TEMP_BLOCK);
		//writeToDisk(TEMP_BLOCK,EX_HANDLER);
	}
	close(fp);
	return 0;
}
예제 #2
0
/*
  This function copies the interrupts to the proper location on the disk.
*/
int loadIntCode(char* fileName, int intNo)
{
	expandpath(fileName);
	FILE* fp = fopen(fileName, "r");
	int i,j;
	if(fp == NULL)
	{
		printf("File \'%s\' not found.\n", fileName);
		return -1;
	}

	for(i=0;i<INT1_SIZE;i++)
	{
		//printf ("Int block 1 - %d = %d\n",i,((intNo - 1) * INT1_SIZE)  + INT1 + i);
		j = writeFileToDisk(fp, ((intNo - 1) * INT1_SIZE)  + INT1 + i, ASSEMBLY_CODE);
		if(j != 1)
			break;
	}
	if(j==1)
	{
		printf("Interrupt Code exceeds %d block\n",INT1_SIZE);
		deleteIntCode(intNo);
		//emptyBlock(TEMP_BLOCK);
		//writeToDisk(TEMP_BLOCK,intNo + INT1 -1);
	}
	close(fp);
	return 0;
}
예제 #3
0
/*
  This function copies the timer interrupt to the proper location on the disk.
*/
int loadTimerCode(char* fileName)
{
	expandpath(fileName);
	FILE* fp = fopen(fileName, "r");
	int i,j;
	if(fp == NULL)
	{
		printf("File %s not found.\n", fileName);
		return -1;
	}

	for(i=0;i<TIMERINT_SIZE;i++)
	{
		j = writeFileToDisk(fp, TIMERINT + i, ASSEMBLY_CODE);
		if (j != 1)
			break;
	}
	if(j==1)
	{
		printf("Timer Interrupt Code exceeds %d block\n",TIMERINT_SIZE);
		deleteTimerFromDisk();
		//emptyBlock(TEMP_BLOCK);
		//writeToDisk(TEMP_BLOCK,TIMERINT);
	}
	close(fp);
	return 0;
}
예제 #4
0
/*
  This function loads the OS startup code specified by the first arguement to its appropriate location on disk.
  The code is first copied to memory copy. If this copying proceeds properly then the memory copy is committed to the disk.
*/
int loadOSCode(char* fileName){

	emptyBlock(TEMP_BLOCK);
	writeToDisk(TEMP_BLOCK,OS_STARTUP_CODE);
	expandpath(fileName);
	FILE* fp = fopen(fileName, "r");
	int i,j;
	if(fp == NULL)
	{
		printf("File \'%s\' not found.\n", fileName);
		return -1;
	}

	for(i=0;i<OS_STARTUP_CODE_SIZE;i++)
	{
		j = writeFileToDisk(fp, OS_STARTUP_CODE + i, ASSEMBLY_CODE);
		if (j != 1)
			break;
	}
	if(j==1)
	{
		printf("OS Code exceeds %d block\n",OS_STARTUP_CODE_SIZE);
		deleteOSCodeFromDisk();
		//emptyBlock(TEMP_BLOCK);
		//writeToDisk(TEMP_BLOCK,OS_STARTUP_CODE);
	}
	close(fp);
	return 0;
}
예제 #5
0
/*
  This function copies the init program to its proper location on the disk.
*/
int loadINITCode(char* fileName )
{
	FILE * fp;
	int i,j;
	expandpath(fileName);
	fp = fopen(fileName, "r");
	if(fp == NULL)
	{
		printf("File \'%s\' not found.\n", fileName);
		return -1;
	}

	for(i=0; i<NO_OF_INIT_BLOCKS; i++)
	{
		j = writeFileToDisk(fp, INIT_BASIC_BLOCK + i, ASSEMBLY_CODE);
		if(j != 1)
			break;
	}
	//j = writeFileToDisk(fp, INIT_BASIC_BLOCK, ASSEMBLY_CODE);		//writing executable file to disk

	//if(j == 1)
	//	j = writeFileToDisk(fp, INIT_BASIC_BLOCK + 1, ASSEMBLY_CODE);		//if the file is longer than one page.
	//if(j == 1)
		//writeFileToDisk(fp, INIT_BASIC_BLOCK + 2, ASSEMBLY_CODE);
	close(fp);
	return 0;

}
예제 #6
0
파일: util.cpp 프로젝트: vis15/fractions
void appendFile(constr& file, constr& text)
{
    str contents = getFileContents(file);

    contents += text;

    writeFileToDisk(file, contents);
}
예제 #7
0
QString takeScreenshot(QRect area) {
    QPixmap shot = grabEntireScreen();

    if (area.isValid())
        shot = shot.copy(area);

    PuushFile file = compressImage("ss", shot);

    if (settings.onPuushActions & Settings::SaveToDisk)
        writeFileToDisk(file);

    return upload(file);
}
예제 #8
0
/*
  This function loads a data file to the disk.
*/
int loadDataToDisk(char *name)
{
	FILE *fileToBeLoaded;
	int freeBlock[MAX_DATAFILE_SIZE_BASIC];
	int i,j,k,num_of_chars=0,num_of_blocks_reqd=0,file_size=0,num_of_words=0;
	for(i=0;i<MAX_DATAFILE_SIZE_BASIC;i++)
		freeBlock[i]=-1;
	char c='\0',*s;
	char filename[50],buf[16];
	s = strrchr(name,'\\');
	if(s!=NULL)
		strcpy(filename,s+1);
	else
		strcpy(filename,name);

	filename[15]='\0';
	addext(filename,".dat");

	expandpath(name);
	fileToBeLoaded = fopen(name, "r");
	if(fileToBeLoaded == NULL)
	{
		printf("File \'%s\' not found.!\n", name);
		return -1;
	}
	if(fileToBeLoaded == NULL)
	{
		printf("The file could not be opened!");
		return -1;
	}

	fseek(fileToBeLoaded, 0L, SEEK_END);

	num_of_chars = ftell(fileToBeLoaded);

	fseek(fileToBeLoaded,0,SEEK_SET);
	while(1)
	{
		fgets(buf,16,fileToBeLoaded);
		num_of_words++;
		if(feof(fileToBeLoaded))
			break;
	}
	num_of_blocks_reqd = (num_of_words/512) + 1;
	//printf("\n Chars = %d, Words = %d, Blocks(chars) = %d, Blocks(words) = %d",num_of_chars,num_of_words,num_of_blocks_reqd,(num_of_words/512));
	if(num_of_blocks_reqd > MAX_DATAFILE_SIZE)
	{
		printf("The size of file exceeds %d blocks",MAX_DATAFILE_SIZE);
		return -1;
	}

	fseek(fileToBeLoaded,0,SEEK_SET);

	for(i = 0; i < num_of_blocks_reqd + 1; i++)
	{
		if((freeBlock[i] = FindFreeBlock()) == -1){
				printf("not sufficient space in disk to hold a new file.\n");
				FreeUnusedBlock(freeBlock, MAX_DATAFILE_SIZE_BASIC);
				return -1;
			}
	}
	i = CheckRepeatedName(filename);
	if( i < FAT_SIZE )
	{
		printf("Disk already contains the file with this name. Try again with a different name.\n");
		FreeUnusedBlock(freeBlock, MAX_DATAFILE_SIZE_BASIC);
		return -1;
	}

	k = FindEmptyFatEntry();
	if( k == -1 )
	{
		FreeUnusedBlock(freeBlock, MAX_DATAFILE_SIZE_BASIC);
		printf("No free FAT entry found.\n");
		return -1;
	}


	for(i = DISK_FREE_LIST ;i < DISK_FREE_LIST + NO_OF_FREE_LIST_BLOCKS; i++)		//updating disk free list in disk
		writeToDisk(i, i);
	emptyBlock(TEMP_BLOCK);				//note:need to modify this

	for( i = 1 ; i < MAX_DATAFILE_SIZE_BASIC ; i++ )
	{
		storeValue(disk[TEMP_BLOCK].word[i-1],freeBlock[i]);
	}
	writeToDisk(TEMP_BLOCK,freeBlock[0]);

	for(i=0;i<num_of_blocks_reqd;i++)
	{
		j = writeFileToDisk(fileToBeLoaded, freeBlock[i+1], DATA_FILE);
		file_size++;
	}


	AddEntryToMemFat(k, filename, file_size * BLOCK_SIZE, freeBlock[0]);
	for(i = FAT; i < FAT + NO_OF_FAT_BLOCKS ; i++){
		writeToDisk(i,i);				//updating disk fat entry note:check for correctness
	}

      close(fileToBeLoaded);
      return 0;

}
예제 #9
0
/*
  This function loads the executable file corresponding to the first arguement to an appropriate location on the disk.
  This function systematically uses the above functions to do this action.
*/
int loadExecutableToDisk(char *name)
{
	FILE *fileToBeLoaded;
	int freeBlock[SIZE_EXEFILE_BASIC];
	int i,j,k,l,file_size=0,num_of_lines=0,num_of_blocks_reqd=0;
	for(i=0;i<SIZE_EXEFILE_BASIC;i++)
		freeBlock[i]=-1;
	char c='\0',*s;
	char filename[50];
	s = strrchr(name,'\\');
	if(s!=NULL)
		strcpy(filename,s+1);
	else
		strcpy(filename,name);

	filename[15]='\0';

	addext(filename,".xsm");

	expandpath(name);
	fileToBeLoaded = fopen(name, "r");
	if(fileToBeLoaded == NULL){
	    printf("File %s not found.\n", name);
	    return -1;
	  }
	if(fileToBeLoaded == NULL){
		printf("The file could not be opened");
		return -1;
	}

	while(c!=EOF)
	{
		c=fgetc(fileToBeLoaded);
		if(c=='\n')
			num_of_lines++;
	}

	num_of_blocks_reqd = (num_of_lines / (BLOCK_SIZE/2)) + 1;

	if(num_of_blocks_reqd > SIZE_EXEFILE)
	{
		printf("The size of file exceeds %d blocks",SIZE_EXEFILE);
		return -1;
	}

	fseek(fileToBeLoaded,0,SEEK_SET);

	for(i = 0; i < num_of_blocks_reqd + 1; i++)
	{
		if((freeBlock[i] = FindFreeBlock()) == -1){
				printf("Insufficient disk space!\n");
				FreeUnusedBlock(freeBlock, SIZE_EXEFILE_BASIC);
				return -1;
			}
	}
	i = CheckRepeatedName(filename);
	if( i < FAT_SIZE ){
		printf("Disk already contains the file with this name. Try again with a different name.\n");
		FreeUnusedBlock(freeBlock, SIZE_EXEFILE_BASIC);
		return -1;
	}

	k = FindEmptyFatEntry();
	if( k == -1 ){
		FreeUnusedBlock(freeBlock, SIZE_EXEFILE_BASIC);
		printf("No free FAT entry found.\n");
		return -1;
	}


	for(i = DISK_FREE_LIST ;i < DISK_FREE_LIST + NO_OF_FREE_LIST_BLOCKS; i++)		//updating disk free list in disk
		writeToDisk(i, i);
	emptyBlock(TEMP_BLOCK);				//note:need to modify this

	for( i = 1 ; i < SIZE_EXEFILE_BASIC ; i++ )
	{
		storeValue(disk[TEMP_BLOCK].word[i-1],freeBlock[i]);
	}
	writeToDisk(TEMP_BLOCK,freeBlock[0]);

	for(i=0;i<num_of_blocks_reqd;i++)
	{
		j = writeFileToDisk(fileToBeLoaded, freeBlock[i+1], ASSEMBLY_CODE);
		file_size++;
	}



	AddEntryToMemFat(k, filename, file_size * BLOCK_SIZE, freeBlock[0]);
	for(i = FAT; i < FAT + NO_OF_FAT_BLOCKS ; i++){
		writeToDisk(i,i);
	}

      close(fileToBeLoaded);
      return 0;
}