Пример #1
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);
	}

}
Пример #2
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;
}
Пример #3
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;
}
Пример #4
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;
}
Пример #5
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;
}
Пример #6
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;

}
Пример #7
0
int tcl_expandpath(ClientData clientData, Tcl_Interp *interp,
		   int argc,  char **argv) {
    char exp_filename[FILENAME_MAX+1];

    if (argc != 2)
	return TCL_ERROR;

    if (0 == expandpath(argv[1], exp_filename)) {
	return TCL_ERROR;
    }

    vTcl_SetResult(interp, "%s", exp_filename);
    return TCL_OK;
}
Пример #8
0
RENZYMES *get_enzyme(char *filename) {
    RENZYME  *r;
    RENZYMES *rs;
    FILE *pr;
    char line[LEN];
    char tmpp[1024];
    char tmp[1024];
    char exp_filename[FILENAME_MAX];
    int flag = 0;
    float efs;
    int current_num_entry = 0, num_entry = 0;
    char *id, *pt, *cr, *rss, *rst;
    int forward, reverse;

    expandpath(filename, exp_filename);

    if (NULL == (pr = fopen(exp_filename, "r"))){
        verror(ERR_WARN, "read r_enzyme file",
               "Unable to open r_enzyme file %s", exp_filename);
        return TCL_OK;
    }

    rs = init_renzymes();
    if(!rs) goto err;

    while (!feof(pr)) {
        fgets(line, LEN, pr);
        line[LEN-1]=0;
        strcpy(tmpp, line);
#if 0
        llen = strlen(line);
        while(llen >= 3 && line[llen - 2] == ',') {
            fgets(line, LEN, pr);
            tmpp[strlen(tmpp) - 1] = 0;
            strcat(tmpp, &line[5]);
        }
#endif
        if (!strncmp(&tmpp[0], "ID", 2)){

            strcpy(tmp, &tmpp[5]);
            tmp[strlen(tmp)- 1] = 0;
            if (num_entry > 0) {
                /*printf("name=%s   %s\n", rs->renzyme[num_entry-1]->name, tmp);*/
                if (!strcmp (rs->renzyme[num_entry-1]->name, tmp)){
                    id = NULL;
                } else id = strdup (tmp);
            } else id = strdup (tmp);
        }
        if (!strncmp(&tmpp[0], "RS", 2)){
            forward = 0;
            reverse = 0;
            strcpy(tmp, &tmpp[5]);
            tmp[strlen(tmp)- 1] = 0;
            rst = strdup (tmp);
            flag = parse_rs(tmp, &efs, &forward, &reverse, &rss);
            if( flag == 1) {
                current_num_entry++;
            }
        }
        if (!strncmp(&tmpp[0], "PT", 2)) {
            strcpy(tmp, &tmpp[5]);
            tmp[strlen(tmp)- 1] = 0;
            pt = strdup (tmp);
        }
        if (!strncmp(&tmpp[0], "CR", 2)){
            strcpy(tmp, &tmpp[5]);
            tmp[strlen(tmp)- 1] = 0;
            cr = strdup (tmp);
            /*printf("supplier_codes=%s\n",cr);*/
        }
        if((!strncmp(&tmpp[0], "//", 2)) && flag == 1 && id != NULL){

            r = init_renzyme();
            if (!r) goto err;
            r->name = id;
            r->rec_seq = rss;
            r->rec_seq_text = rst;
            r->prototype = pt;
            r->supplier_codes = cr;
            r->av_frag_size = efs;
            r->cut_pos_1 = forward;
            r->cut_pos_2 = reverse;
            efs = 0;
        if (num_entry != 0) {
            rs = realloc_renzymes (rs, num_entry);
        }
        rs->renzyme[num_entry] = r;
        num_entry++;
        rs->used = num_entry;
        }
    }
    fclose(pr);
    return rs;
 err:
    if (rs) free_renzymes (rs);
    if (r)  free_renzyme (r);
    fclose(pr);
    return NULL;
}
Пример #9
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;

}
Пример #10
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;
}