Beispiel #1
0
/*read the file with name name[] into buffer[]*/
void readfile(char* name, char* buffer)
{
	char sector[512];
	int i,j,index,bufferindex=0;
	int sec,head,cyl;

	/*load the directory into sector*/
	readsector(sector,3,0,0);

	/*get the index of the file name*/
	index=findname(name,sector)+6;

	/*-1+6 is 5 - this means the file doesn't exist*/
	if (index==5)
		return;

	/*read each sector into buffer*/
	while(sector[index]!=0x00)
	{
		/*convert to CHS*/
		sec=mod(sector[index],0x12)+1;
		head=mod(div(sector[index],0x12),2);
		cyl=div(sector[index],0x24);
		readsector(buffer+bufferindex,sec,head,cyl);

		index++;
		/*step forward by 512 (1 sector)*/
		bufferindex=bufferindex+512;
	}

}
Beispiel #2
0
/*deleting involves two steps:
  1) turning all the file's map entries into 0 (sector is available)
  2) setting the first byte of the file name to 0 (dir entry is empty)
  note that it is unnecessary to actually wipe out the file*/
void delfile(char* name)
{
	int index;
	char dirsector[512];
	char mapsector[512];

	/*read the disk map and directory*/
	readsector(dirsector,3,0,0);
	readsector(mapsector,2,0,0);
	/*find the file in the directory*/
	index=findname(name,dirsector);
	if (index==-1)
		return;

	/*set the file name to deleted*/
	dirsector[index]=0x00;
	index=index+6;
	/*set all the file's map entries to 0*/
	while(dirsector[index]!=0x00)
		mapsector[dirsector[index++]]=0x00;
	
	/*write back the map and directory*/
	writesector(dirsector,3,0,0);
	writesector(mapsector,2,0,0);
}
Beispiel #3
0
unsigned int findFileBlockInPath(char *fileName)
{
	char * path; 
	char * directoryName;
	int tokens,directoryEntryNumber;
	unsigned int directoryBlockNumber;
	directoryBlock directory;
	int tokenPosition = 2;
	fileName = getData(fileName);
	path = (char*)mallocFS(mystrlen(fileName));
	path = getData(strcpy(fileName, path));
	 tokens= qtytoken(path, '/');
	directoryName = getData(mystrtok(path, '/', tokenPosition));
	directoryEntryNumber = 0;
	directoryBlockNumber = ROOTBLOCK;
	readsector(2, &directory);
	if (directoryName[0] == '\0')
		return directoryBlockNumber;
	while (tokenPosition <= tokens)
	{
		directoryEntryNumber = findFileInDirectory(directory, directoryName);

		if (directoryEntryNumber == -1)
		{
			return -1;
		}
		directoryBlockNumber = directory.entries[directoryEntryNumber].fileBlockStart;
		readsector(directoryBlockNumber, (char *)&directory);
		directoryName = getData(mystrtok(path, '/', tokenPosition + 1));
		tokenPosition++;
	}
	return directoryBlockNumber;
}
Beispiel #4
0
/**
 * Callback function
 */
int hxc_media_read(unsigned long sector, unsigned char *buffer)
{
	_direct_access_status_sector * dass;

	dass= (_direct_access_status_sector *)buffer;

	gui_more_busy();

	if (_isEmulator) {
		Rwabs(0, buffer, 1, sector, 0);
	} else {
		do {
			if((sector-_last_setlbabase)>=8) {
				_setlbabase(sector);
			}

			if(!readsector(0,buffer,0)) {
				error("Read error");
			}
			_last_setlbabase=L_INDIAN(dass->lba_base);

			/* gui_printf(0,0,0,"BA: %08X %08X" ,L_INDIAN(dass->lba_base),sector);*/
		} while((sector-L_INDIAN(dass->lba_base))>=8);

		if(!readsector((sector-_last_setlbabase)+1,buffer,0)) {
			//gui_printf(0, 0, 0, "fsector=%d", (sector-_last_setlbabase)+1));
			fatal("Read error");
		}
	}

	gui_less_busy();

	return 1;
}
int media_read(uint32 sector, uint8 *buffer, uint32 sector_count)
{
	int ret;
	uint32 i;
	direct_access_status_sector * dass;

	dass = (direct_access_status_sector *)buffer;

	#ifdef DEBUG
	dbg_printf("media_read sector : 0x%.8X, cnt : %d \n",sector,sector_count);
	#endif

	set_char_pos(&g_ui_ctx,g_ui_ctx.screen_txt_xsize - 1, 0);
	print_char(&g_ui_ctx, 10, INVERTED);

	for(i=0;i<sector_count;i++)
	{
		do
		{
			if((sector-last_setlbabase)>=8)
			{
				ret = setlbabase(sector);
				if( ret != ERR_NO_ERROR )
					return 0;
			}

			ret = readsector(0,buffer,0); 
			if( ret != ERR_NO_ERROR )
			{
				hxc_printf_box(&g_ui_ctx,"ERROR: Read ERROR ! fsector %d [Err %d]",(sector-last_setlbabase)+1,ret);

				return 0;
			}
			last_setlbabase = L_INDIAN(dass->lba_base);

		}while((sector-L_INDIAN(dass->lba_base))>=8);

		ret = readsector((unsigned char)((sector-last_setlbabase)+1),&buffer[i*512],0);
		if( ret != ERR_NO_ERROR )
		{
			hxc_printf_box(&g_ui_ctx,"ERROR: Read ERROR ! fsector %d [Err %d]",(sector-last_setlbabase)+1,ret);
			return 0;
		}

		sector++;

		#ifdef DEBUG
		print_hex_array(buffer,512);
		#endif
	}

	set_char_pos(&g_ui_ctx,g_ui_ctx.screen_txt_xsize - 1, 0);
	print_char(&g_ui_ctx, ' ', INVERTED);

	return 1;
}
Beispiel #6
0
/*print out the directory*/
void dodir()
{
	char dirsector[512];
	char mapsector[512];
	char name[7];
	int i,j,index,files;

	/*read the directory sector*/
	readsector(2,dirsector);

	printstring("Directory:\r\n\0");
	index=0;
	files=0;
	/*the file system allows no more than 16 files*/
	for (i=0; i<16; i++)
	{
		/*check if the file exists*/
		if (dirsector[index]!=0)
		{
			/*print hte name*/
			for (j=0; j<6; j++)
				name[j]=dirsector[index+j];
			name[6]=0;
			printstring(name);

			/*calculate the file size in sectors from the directory entry*/
			j=0;
			while(dirsector[index+j+6]!=0)
				j++;

			printstring("  \0");
			printnumber(j);
			printstring(" sectors\r\n\0");
			files++;
		}
		/*move to the next entry*/
		index=index+0x20;
	}
	printnumber(files);
	printstring(" files total (out of 16 maximum)\r\n\0");

	/*read the map sector to find out how many free sectors are left*/
	readsector(1,mapsector);
	j=0;
	for (i=0; i<256; i++)
	{
		if (mapsector[i]==0x0)
			j++;
	}

	printnumber(j);
	printstring(" sectors available\r\n\0");
}
Beispiel #7
0
unsigned int AllocateBlock()
{
	superBlock superBlock;
	unsigned int allocatedBlockNumber,newFirstBlockNumber;
	unusedBlock  allocatedBlock;
	allocatedBlockNumber= superBlock.firstFreeBlock;
	readsector(1, &superBlock);
	readsector(allocatedBlockNumber, &allocatedBlock);
	newFirstBlockNumber = allocatedBlock.nextFreeBlock;
	superBlock.firstFreeBlock = newFirstBlockNumber;
	superBlock.totalFreeBlocks--;
	writesector(1, &superBlock);
	return allocatedBlockNumber;
}
Beispiel #8
0
void rmDir(int DirBlock)
{
	directoryBlock dir;
	int dirStart, dirSize, y, z;
	readsector(DirBlock, (char*)&dir);
	if (DirBlock == 0)
	{
		return;
	}
	y = 0;
	while (y < DIRECTORYENTRYCOUNT)
	{
		if (dir.entries[y].fileType == IS_FILE)
		{
			dirStart = dir.entries[y].fileBlockStart;
			dirSize = dir.entries[y].fileBlockSize;
			z = dirStart;
			while( z < dirSize)
			{
				setFreeBlock(z);
				z++;
			}
			if (y == DIRECTORYENTRYCOUNT - 1)
				return;
		}
		else if (dir.entries[y].fileType == IS_DIRECTORY)
		{
			rmDir(dir.entries[y].fileBlockStart);
			setFreeBlock(y);
		}
		y++;
	}
}
Beispiel #9
0
void setFreeBlock(unsigned int blockNumber)
{
	superBlock spBlock;
	unusedBlock newBlock,lastFreeBlock;
	unsigned int secondToLastBlock;
	newBlock.nextFreeBlock = 0;
	readsector(1, &spBlock);
	readsector(spBlock.lastFreeBlock, (char*)&lastFreeBlock);
	lastFreeBlock.nextFreeBlock = blockNumber;
	secondToLastBlock = spBlock.lastFreeBlock;
	spBlock.lastFreeBlock = blockNumber;
	spBlock.totalFreeBlocks++;
	writesector(FsStart, (char*)&spBlock);
	writesector(secondToLastBlock, (char*)&lastFreeBlock);
	writesector(blockNumber, (char*)&newBlock);
}
Beispiel #10
0
void ls(char * filePath)
{
	unsigned int destinationDirBlockNumber; 
	int y;
	directoryBlock destinationDirectory;
	destinationDirBlockNumber = findFileBlockInPath(filePath);
	
	if (destinationDirBlockNumber == -1)
	{
		printstring("Directory does not exists");
		return;
	}
	
	readsector(destinationDirBlockNumber, &destinationDirectory);
	y = 0;
	while (y < DIRECTORYENTRYCOUNT)
	{
		if (destinationDirectory.entries[y].fileBlockStart != 0)
		{
			char *tempName = (char*)mallocFS(mystrlen(destinationDirectory.entries[y].fileName));
			tempName = getData(destinationDirectory.entries[y].fileName);
			if (destinationDirectory.entries[y].fileType == IS_DIRECTORY)
			{
				printstring("Directory: %s\n", tempName);
			}
			else if (destinationDirectory.entries[y].fileType == IS_FILE)
			{
				printstring("File: %s\n", tempName);
			}
		}
		y++;
	}
}
int test_floppy_if()
{
	int ret;
	unsigned char sector[512];
	direct_access_status_sector * dass;

	dass=(direct_access_status_sector *)sector;

	last_setlbabase = 2;
	do
	{
		ret = setlbabase( last_setlbabase );
		if( ret != ERR_NO_ERROR )
			return ret;

		ret = readsector(0,sector,1);
		if( ret != ERR_NO_ERROR )
			return ret;

		#ifdef DEBUG
		dbg_printf("test_floppy_if : %.8X = %.8X ?\n",last_setlbabase,L_INDIAN(dass->lba_base));
		#endif

		if(last_setlbabase!=L_INDIAN(dass->lba_base))
		{
			return -ERR_LBA_CHANGE_FAILURE;
		}

		last_setlbabase--;
	}while(last_setlbabase);

	return ERR_NO_ERROR;
}
Beispiel #12
0
void innerRemove(char sectorNumber, char* map)
{
	char directory[512];
	int x;
	int numBloque;
	readsector(BASEOFFSET+sectorNumber,directory);
	for (x=0;x<15;x+=0x20)
	{	
		if(directory[x] != 0)
		{
			for(numBloque = 6; numBloque<0x20;numBloque++)
			{
				if(map[directory[x+numBloque]]==0x44)
				{
					innerRemove(directory[x+numBloque],map);
					break;						
				}
				else if(map[directory[x+numBloque]]==0x46)
				{
					innerRemove(directory[x+numBloque],map);
					break;						
				}
			}
		}			
	}
	map[sectorNumber] = 0x0;
	for(x=0;x<512;x++)
	{
		directory[x] = 0x0;
	}
	writesector(BASEOFFSET+sectorNumber,directory);
	writesector(BASEOFFSET,map);
}
Beispiel #13
0
void lf(char *path, char *fileName)
{
	unsigned int z, fileBlockNumber, fileStart, fileSize;
	char *buffer;
	directoryBlock destinyBlock;
	fileBlock file; 
	unsigned int blockPathNumber = findFileBlockInPath(getData(path));
	readsector(blockPathNumber, (char*)&destinyBlock);
	fileBlockNumber = findFileInDirectory(destinyBlock, getData(fileName));
	z = 0;
	if (blockPathNumber == -1)
	{
		printstring("File %s does not exists", getData(fileName));
	}
	if (destinyBlock.entries[fileBlockNumber].fileType == IS_FILE)
	{
		fileStart = destinyBlock.entries[fileBlockNumber].fileBlockStart;
		fileSize = destinyBlock.entries[fileBlockNumber].fileBlockSize;
		while (z < fileSize)
		{
			if (z != 0)
			{
				readsector(fileStart, buffer);
				printstring(buffer);
			}
			else
			{
				readsector(fileStart, (char *)&file);
				printstring("File Name: ");
				printstring(getData(file.fileName));
				printstring(" \nFile Type: ");
				printstring("%d", file.type);
				printstring(" \nSize: ");
				printstring("%d", file.size);
				printstring(" \nAccess: ");
				printstring(getData(file.acessRights));
				printstring(" \nData: ");
				printstring(getData(file.data));
			}
			fileStart++;
			z++;
		}
	}
	else
		printstring("File %s does not exists", getData(fileName));
}
Beispiel #14
0
void Listar()
{
	char mapsector[512];
	readsector(BASEOFFSET,mapsector);
	printstring("Directory:\r\n\0");
	ImprimirLista(0x01,0,mapsector);
	
}
Beispiel #15
0
void cpyDir(int sourceBlock, int destinyBlock, char *destinyPath)
{
	directoryBlock source, destiny;
	int y, z, dirStart, dirSize, newBlockDir;
	char *dirName;
	readsector(sourceBlock, (char *)&source);
	readsector(destinyBlock, (char *)&destiny);
	if (sourceBlock == 0)
	{
		return;
	}
	y = 0;
	while (y < DIRECTORYENTRYCOUNT)
	{
		if (source.entries[y].fileType == IS_FILE)
		{
			dirStart = source.entries[y].fileBlockStart;
			dirSize = source.entries[y].fileBlockSize;
			if (y == DIRECTORYENTRYCOUNT - 1)
				return;
		}
		else
		{
			newBlockDir = mkdir(destinyPath, source.entries[y].fileName);
			dirName = source.entries[y].fileName;
			z=0;
			while (z < DIRECTORYENTRYCOUNT)
			{
				if (destiny.entries[z].fileBlockStart == 0)
				{
					destiny.entries[z].fileName[0] = '\0';
					strcpy(dirName, destiny.entries[z].fileName);
					destiny.entries[z].fileType = IS_DIRECTORY;
					destiny.entries[z].fileBlockStart = newBlockDir;
					destiny.entries[z].fileBlockSize = 1;
					break;
				}
				z++;
			}
			writesector(destinyBlock, (char *)&destiny);
			cpyDir(source.entries[y].fileBlockStart, newBlockDir, dirName);
		}
		y++;
	}
}
Beispiel #16
0
int	scandisk(char *filename)
{
	char	diskname[64];
	char	name[14];
	int	doad;
	struct	dskstruc buf0;
	char	buf[256];
	struct	tifile dsk;

	if (!fiadordoad(filename,&doad,diskname,name))
	{
		printf("Cannot access directory/disk image %s\n",filename);
		return 0;
	}

	if (doad)
	{
		printf("Scanning disk image %s...\n",diskname);

		//  Fatal errors

		if (!opendisk(diskname,&dsk))
		{
			tierror(diskname);
			return 0;
		}

SAY		printf("\nChecking volume header...\n\n");
		if (!readsector(dsk.doshandle,0,(byte *)&buf0))
		{
			tierror(diskname);
			return 0;
		}
		else
SAY			printf("Okay header.\n");

		//  Recoverable errors

		if (!validatename(buf0.name))
		{
			if (fix)
			{
			getname(buf0.name,name);
			memcpy(buf0.name,name+2,10);
			if (!writesector(dsk.doshandle,0,(byte *)&buf0))
				die(filename);
			}
		}

		//  No more useful testing for DOADs yet!!
	}
	else
		printf("Scanning directory %s...\n",filename);

	return	1;
}
Beispiel #17
0
void ImprimirLista(char sectorNumber, int depth, char* mapsector)
{
	char dirsector[512];
	char name[7];
	int i,j,index,files,x;
	char symbol [2];
	symbol[0] = 195;
	symbol[1] = 0;
	readsector(BASEOFFSET + sectorNumber,dirsector);
	index=0;
	files=0;
	for (i=0; i<16; i++)
	{
		if (dirsector[index]!=0)
		{
			for (j=0; j<6; j++)
				name[j]=dirsector[index+j];
			name[6]=0;
			for(x =0;x<depth;x++)
				printstring("\t");
			printstring(symbol);
			printstring(name);
			sectorNumber = dirsector[i*0x20+6];
			if(mapsector[sectorNumber] == 0x44)
			{	
				j=0;
				while(dirsector[index+j+6]!=0)
					j++;
				printstring("  \0");
				printstring( "D\0");
				printstring("\r\n\0");
				ImprimirLista(sectorNumber,depth+1,mapsector);
				files++;
			}
			else if(mapsector[sectorNumber] == 0x46)
			{	
				j=0;
				while(dirsector[index+j+6]!=0)
					j++;
				printstring(".txt");
				printstring("  \0");
				printstring("F\0");
				printstring("\r\n\0");
				files++;
			}
		}
		index=index+0x20;
	}
	j=0;
	for (i=0; i<256; i++)
	{
		if (mapsector[i]==0x0)
			j++;
	}
}
Beispiel #18
0
/*copy a file*/
void docopy()
{
	char sname[7];
	char dname[7];
	char line[80];
	char file[12800];
	char dirsector[512];
	int index,i;

	/*prompt for the first file name*/
	printstring("Name of the source file? \0");
	readstring(line);
	for (i=0; i<6; i++)
	{
		sname[i]=line[i];
		if (line[i]==0xd)
			break;
	}
	sname[i]=0x0;

	/*make sure it exists - find the directory entry*/
	readsector(2,dirsector);
	index=findname(sname,dirsector);
	if (index==-1)
	{
		printstring("File not found\r\n\0");
		return;
	}

	/*read the source file*/
	readfile(sname,file);

	/*prompt for the destination file name*/
	printstring("Name of the destination file? \0");
	readstring(line);
	for (i=0; i<6; i++)
	{
		dname[i]=line[i];
		if (line[i]==0xd)
			break;
	}
	dname[i]=0x0;

	/*figure out how long the source file is*/
	i=0;
	index=index+6;
	while(dirsector[index]!=0x0)
	{
		index++;
		i++;
	}

	/*write the file*/
	writefile(dname,file,i);
}
Beispiel #19
0
void cpy(char *pathSource, char *destinyPath, char *copyName)
{
	directoryBlock source, destiny;
	int sourceBlock, destinyBlock, newBlockDir, z;
	char *sourcePathName,*dirName;
	sourceBlock = findFileBlockInPath(getData(pathSource));
	destinyBlock = findFileBlockInPath(getData(destinyPath));
	if (sourceBlock == 0 || destinyBlock == 0)
	{
		return;
	}
	sourcePathName = getPathName(getData(pathSource), 2);
	readsector(sourceBlock, (char *)&source);
	readsector(destinyBlock, (char *)&destiny);
	{
		newBlockDir = mkdir(getData(destinyPath), getData(copyName));
		if (strCmp(getData(getData(destinyPath)), "/") != 1)
		{
			dirName = mistrcat(getData(destinyPath), "/");
			dirName = mistrcat(getData(dirName), getData(copyName));
			dirName = getData(dirName);
		}
		else	
			dirName = getData(getData(destinyPath));
		z = 0;
		while(z < DIRECTORYENTRYCOUNT)
		{
			if (destiny.entries[z].fileBlockStart == 0)
			{
				destiny.entries[z].fileName[0] = '\0';
				strcpy(getData(copyName), destiny.entries[z].fileName);
				destiny.entries[z].fileType = IS_DIRECTORY;
				destiny.entries[z].fileBlockStart = newBlockDir;
				destiny.entries[z].fileBlockSize = 1;
				break;
			}
			z++;
		}
		writesector(destinyBlock, (char *)&destiny);
		cpyDir(sourceBlock, newBlockDir, dirName);
	}
}
Beispiel #20
0
void initimage(void)
{
        int c,d;

        memset(buffer, 0, 256);
        /* First clear all sectors */
        for (c = 1; c <= MAX_TRACK; c++)
        {
                for (d = 0; d < sectornumtable[c]; d++)
                {
                        writesector(c,d);
                }
        }
        /* Then make BAM */
        buffer[0] = 18; /* Link to the directory */
        buffer[1] = 1;
        buffer[2] = 0x41; /* Disk format "A" */
        buffer[3] = 0;

        /* Disk name */
        for (c = 0; c < 23; c++)
        {
                if (diskname[c] == '.')
                        buffer[144+c] = 0x20;
                else
                {
                        if (diskname[c] != 0x20)
                                buffer[144+c] = diskname[c];
                        else
                                buffer[144+c] = 0xa0;
                }
        }
        for (c = 23; c < 27; c++) buffer[144+c] = 0xa0;
        writesector(18,0);

        /* Now mark all sectors free */
        for (c = 1; c <= MAX_TRACK; c++)
        {
                for (d = 0; d < sectornumtable[c]; d++)
                {
                       marksectorfree(c,d);
                }
        }
        /* All except BAM */
        marksectorused(18,0);

        /* Read first directoryblock */
        readsector(18,1);
        buffer[0] = 0;
        buffer[1] = 0xff; /* Assume it is the last */
        marksectorused(18,1);
        writesector(18,1);
}
Beispiel #21
0
int mkdir(char * filePath, char * fileName)
{
	unsigned int destinationDirBlockNumber,newDirBlockNumber;
	directoryBlock destinationDirectory,newDirectory;
	int z, y, isfile;
	if (strCmp(filePath, "/") == 1)
		destinationDirBlockNumber = ROOTBLOCK;
	else
		destinationDirBlockNumber = findFileBlockInPath(filePath);
	if (destinationDirBlockNumber == -1)
	{
		printstring("Directory does not exists");
		return -1;
	}
	
	filePath = getData(filePath);
	fileName = getData(fileName);	
	readsector(destinationDirBlockNumber, &destinationDirectory);
	isfile = IsNewFile(destinationDirectory, fileName);
	if (isfile == -1)
	{
		printstring("Directory already exist\n");
		return -1;
	}
	newDirBlockNumber = AllocateBlock();
	y  = 0;
	while(y < DIRECTORYENTRYCOUNT)
	{
		newDirectory.entries[y].fileType = IS_FILE;
		newDirectory.entries[y].fileBlockStart = 0;
		newDirectory.entries[y].fileBlockSize = 0;
		y++;
	}
	writesector(newDirBlockNumber, &newDirectory);
	z = 0;
	while (z < DIRECTORYENTRYCOUNT)
	{
		if (destinationDirectory.entries[z].fileBlockStart == 0)
		{
			strcpy(fileName, destinationDirectory.entries[z].fileName);
			destinationDirectory.entries[z].fileType = IS_DIRECTORY;
			destinationDirectory.entries[z].fileBlockStart = newDirBlockNumber;
			destinationDirectory.entries[z].fileBlockSize = 1;
			break;
		}
		z++;
	}
	writesector(destinationDirBlockNumber, &destinationDirectory);
	printstring("Directory ");
	printstring(fileName);
	printstring(" Created!\n");
	return newDirBlockNumber;
}
Beispiel #22
0
void mkf(char * path, char* fileName, char acess[], char *data)
{
	int y,isfile;
	directoryBlock destinationDirectory;
	fileBlock file;
	unsigned int newDirBlockNumber, destinationDirBlockNumber;
	
	if (strCmp(getData(path), "/") != 1)
	{
		destinationDirBlockNumber = findFileBlockInPath(getData(path));
	}
	else
	{
		destinationDirBlockNumber = ROOTBLOCK;
	}
	if (destinationDirBlockNumber == -1)
	{
		printstring("Path cannot be found, creating file failed");
		return;
	}
	readsector(destinationDirBlockNumber, (char*)&destinationDirectory);
	isfile = IsNewFile(destinationDirectory, getData(fileName));
	if (isfile == -1)
	{
		printstring("File already exist\n");
		return;
	}
	file.size = 0;
	file.type = IS_FILE;
	file.data[0] = '\0';
	strcpy(getData(fileName), file.fileName);
	strcpy(getData(acess), file.acessRights);
	strcpy(getData(data), file.data);
	newDirBlockNumber = AllocateBlock();
	wf(&file, getData(data), newDirBlockNumber);
	y = 0;
	while( y < DIRECTORYENTRYCOUNT)
	{
		if (destinationDirectory.entries[y].fileBlockStart == 0)
		{
			strcpy(destinationDirectory.entries[y].fileName, file.fileName);
			destinationDirectory.entries[y].fileType = IS_FILE;
			destinationDirectory.entries[y].fileBlockStart = newDirBlockNumber;
			destinationDirectory.entries[y].fileBlockSize = file.size;
			break;
		}
		y++;
	}
	writesector(destinationDirBlockNumber, (char*)&destinationDirectory);
	return;
}
Beispiel #23
0
int otherFor(char* direccion, char* dir)
{
	char nombre[6];
	char found = 0;
	char sectorNumber;
	char otro[6];
	int indexx;
	int n;
	int y;
	int b=0;
	int w=0;
	int z = 0;
	char token [10];
	int toks = CountTokens(direccion);
	sectorNumber = 0x01;
	for (b=0; b<10; b++)
		token[b]=0x0;
	while(w < toks)
	{
		z = getTok(direccion,token,z);
		found = 0;
		for(n=0;n<6;n++)
		{
			nombre[n] = token[n];
		}
		for (indexx=0;indexx<15;indexx++)
		{
			for(y=0;y<6;y++)
			{
				otro[y] = dir[indexx*0x20+y]; //si existe o no el directorio
			}
			if(cmp(otro,nombre,6)==1) //si encontramos el directorio
			{
				sectorNumber = dir[indexx*0x20+6];
				readsector(BASEOFFSET+sectorNumber,dir);
				w++;
				found = 1;
				break;
			}				
		}

		if(found == 1)
		{
			continue;
		}
		w++;		
	}
	return sectorNumber;
}
Beispiel #24
0
void rmf(char *path, char *fileName)
{
	unsigned int z, blockToRemove;
	int fileStart,fileSize,y;
	directoryBlock destinyBlock;
	unsigned int blockPathNumber; 
	blockPathNumber = findFileBlockInPath(getData(path));
	path = getData(path);
	if (blockPathNumber == -1)
	{
		printstring("Directory does not exist");
		return;
	}
	readsector(blockPathNumber, (char*)&destinyBlock);
	blockToRemove = findFileInDirectory(destinyBlock, getData(fileName));
	if (blockToRemove == -1)
	{
		printstring("File does not exist");
		return;
	}
	if (destinyBlock.entries[blockToRemove].fileType == IS_FILE)
	{
		fileStart = destinyBlock.entries[blockToRemove].fileBlockStart;
		fileSize = destinyBlock.entries[blockToRemove].fileBlockSize;
		while( z < fileSize)
		{
			setFreeBlock(fileStart);
			fileStart++;
			z++;
		}
		y= 0;
		while (y < sizeof(destinyBlock.entries[blockToRemove].fileName))
		{
			destinyBlock.entries[blockToRemove].fileName[y] = '\0';
			y++;
		}
		destinyBlock.entries[blockToRemove].fileBlockSize = 0;
		destinyBlock.entries[blockToRemove].fileBlockStart = 0;
		writesector(blockPathNumber, (char*)&destinyBlock);
	}
}
Beispiel #25
0
/**
 * Init the hardware
 * Display Firmware version
 * @return 0 on failure, 1 on success
 */
void _hxc_media_init()
{
	unsigned char sector[512];
	_direct_access_status_sector * dass;

	_last_setlbabase=0xFFFFF000;
	if (!readsector(0,(unsigned char*)&sector,1)) {
		fatal("Floppy Access error");
	}

	dass=(_direct_access_status_sector *)sector;
	if(strcmp(dass->DAHEADERSIGNATURE,"HxCFEDA")) {
		fatal("HxC Floppy Emulator not found");
	}

	gui_printf(0,0,SCR_YRESOL-30,"Firmware %s" ,dass->FIRMWAREVERSION);

	dass= (_direct_access_status_sector *)sector;
	_last_setlbabase=0;
	_setlbabase(_last_setlbabase);
}
Beispiel #26
0
void rm(char * path)
{
	int y, z, dirStart, dirSize,blockEntryToRemove,blockToRemove;
	directoryBlock erasedBlock;
	char *destinyBlock,*dirRm;
	destinyBlock = getPathName(path, 1);
	dirRm  = getPathName(path, 2); 
	blockToRemove = findFileBlockInPath(destinyBlock);
	readsector(blockToRemove, (char*)&erasedBlock);
	blockEntryToRemove = findFileInDirectory(erasedBlock, dirRm);
	if (blockEntryToRemove == -1)
	{
		printstring("Directory does not exist\n");
		return;
	}
	if (erasedBlock.entries[blockEntryToRemove].fileType == IS_FILE)
	{
		dirStart = erasedBlock.entries[blockEntryToRemove].fileBlockStart;
		dirSize = erasedBlock.entries[blockEntryToRemove].fileBlockSize;
		z = dirStart;
		while (z < dirSize)
		{
			setFreeBlock(z);
			z++;
		}
	}
	else if (erasedBlock.entries[blockEntryToRemove].fileType == IS_DIRECTORY)
	{
		rmDir(erasedBlock.entries[blockEntryToRemove].fileBlockStart);
		setFreeBlock(erasedBlock.entries[blockEntryToRemove].fileBlockStart);
	}
	y = 0;
	while (y < sizeof(erasedBlock.entries[blockEntryToRemove].fileName))
	{
		erasedBlock.entries[blockEntryToRemove].fileName[y] = '\0';
	}
	erasedBlock.entries[blockEntryToRemove].fileBlockSize = 0;
	erasedBlock.entries[blockEntryToRemove].fileBlockStart = 0;
	writesector(blockToRemove, (char*)&erasedBlock);
}
Beispiel #27
0
void rn(char *dirPath, char *newDirName)
{
	directoryBlock dir;
	int dirBlockPos,entryNumber, pathLenght,y;
	char *path,*previousDirName,*tempDirName;
	pathLenght = mystrlen(getData(dirPath)); 
	 path= (char*)mallocFS(pathLenght);
	path = getPathName(getData(dirPath), 1);
	previousDirName = getPathName(getData(dirPath), 2);
	dirBlockPos = findFileBlockInPath(path);
	if (dirBlockPos == -1)
	{
		printstring("Directory does not exists");
		return;
	}
	readsector(dirBlockPos, &dir);
	entryNumber = findFileInDirectory(dir, previousDirName);
	if (entryNumber == -1)
	{
		printstring("Directory does not exists");
		return;
	}
	tempDirName = (char*)mallocFS(mystrlen(getData(dirPath)));
	tempDirName = getData(dir.entries[entryNumber].fileName);
	if (strCmp(tempDirName, previousDirName) == 1)
	{
		y = 0;
		while( y < mystrlen(dir.entries[entryNumber].fileName))
		{
			dir.entries[entryNumber].fileName[y] = ' ';
			y++;
		}
		strcpy(dir.entries[entryNumber].fileName, getData(newDirName));
		dir.entries[entryNumber].fileType = IS_DIRECTORY;
		writesector(dirBlockPos, (char*)&dir);
	}
}
Beispiel #28
0
void mkdir(char* path)
{
	
	int b=0;
	int w=0;
	int z = 0;
	char token [10];
	int toks = CountTokens(path);
	int k;
	char r;
	char mapa[512];
	char dir[512];
	char nombre[6];
	char found = 0;
	char sectorNumber;
	char comparar[6];
	int x;
	int n;
	int y;
	int sectorLibre = 0;
	int entrada = 0;
	int dirindex = 0;
	int sectcount;	
	readsector(BASEOFFSET,mapa);
	readsector(BASEOFFSET +1,dir);
	sectorNumber = 0x01;
	for (b=0; b<10; b++)
		token[b]=0x0;
	while(w < toks)
	{
		z = getTok(path,token,z);
		found = 0;
		for(n=0;n<6;n++)
		{
			nombre[n] = token[n];
		}
		for (x=0;x<15;x++)
		{
			for(y=0;y<6;y++)
			{
				comparar[y] = dir[x*0x20+y]; //si existe o no el directorio
			}
			if(cmp(comparar,nombre,6)==1) //si encontramos el directorio
			{
				sectorNumber = dir[x*0x20+6];
				readsector(BASEOFFSET+sectorNumber,dir);
				w++;
				found = 1;
				break;
			}				
		}
		if(found == 1)
		{
			continue;
		}		
		for (entrada=0; entrada<256; entrada++)
			if (mapa[entrada]==0)
				break;
		if (entrada==256)
		{
			printstring("Not enough room for file\n");
			return;
		}
		mapa[entrada]=0x44;
		for (x=0;x<15;x++)
		{
			dirindex = x*0x20;
			sectorLibre = dir[dirindex]; //buscamos la primera entrada libre
			if(sectorLibre==0)
			{
				for (k=0; k<6; k++)
					dir[dirindex+k]=0x20;
				for (k=0; k<6; k++)
				{
					if(nombre[k]==0)
					break;
					dir[dirindex+k]=nombre[k];		
				}
				dir[dirindex+6] = entrada;
				break;
			}
		}
		writesector(BASEOFFSET+sectorNumber,dir);
		writesector(BASEOFFSET,mapa);
		readsector(BASEOFFSET+entrada,dir);
		sectorNumber = entrada;
		w++;
	}
}
int media_init()
{
	int ret;
	unsigned char sector[512];
	direct_access_status_sector * dass;
	int i,count;

	#ifdef DEBUG
	dbg_printf("media_init\n");
	#endif

	last_setlbabase=0xFFFFF000;
	ret = readsector(0,(unsigned char*)&sector,1);

	g_ui_ctx.firmware_type = INVALID_FIRMWARE;

	if(ret == ERR_NO_ERROR)
	{
		dass = (direct_access_status_sector *)sector;

		if(!strcmp(dass->DAHEADERSIGNATURE,HXC_FW_ID))
		{
			g_ui_ctx.firmware_type = HXC_LEGACY_FIRMWARE;
			i = 0;
			count = 0;

			if(dass->FIRMWAREVERSION[0] != 'v' && dass->FIRMWAREVERSION[0] != 'V')
			{
				g_ui_ctx.firmware_type = HXC_CLONE_FIRMWARE;
			}

			while(dass->FIRMWAREVERSION[i] && i < sizeof(dass->FIRMWAREVERSION))
			{
				if(dass->FIRMWAREVERSION[i] == '.')
					count++;

				i++;
			}

			if(count != 3)
				g_ui_ctx.firmware_type = HXC_CLONE_FIRMWARE;
		}

#ifdef CORTEX_FW_SUPPORT
		if(!strncmp(dass->DAHEADERSIGNATURE,CORTEX_FW_ID,strlen(CORTEX_FW_ID)))
		{
			g_ui_ctx.firmware_type = CORTEX_FIRMWARE;
		}
#endif

		if( g_ui_ctx.firmware_type != INVALID_FIRMWARE )
		{
			strncpy(g_ui_ctx.FIRMWAREVERSION,dass->FIRMWAREVERSION,sizeof(g_ui_ctx.FIRMWAREVERSION));
			hxc_printf(&g_ui_ctx,LEFT_ALIGNED|INVERTED,0, g_ui_ctx.screen_txt_ysize - 1,"FW %s",g_ui_ctx.FIRMWAREVERSION);

			ret = test_floppy_if();
			if( ret != ERR_NO_ERROR)
				return ret;

			dass = (direct_access_status_sector *)sector;
			last_setlbabase=0;

			ret = setlbabase(last_setlbabase);
			if( ret != ERR_NO_ERROR )
				return ret;

			#ifdef DEBUG
			dbg_printf("media_init : HxC FE Found\n");
			#endif

			return ERR_NO_ERROR;
		}

		#ifdef DEBUG
		dbg_printf("media_init : HxC FE not detected\n");
		#endif

		return -ERR_BAD_DRIVE_ID;
	}

	#ifdef DEBUG
	dbg_printf("media_init : Media access error\n");
	#endif

	return ret;
}
Beispiel #30
0
/*sectorlength tells how big this file must be in sectors*/
void writefile(char* name, char* buffer, int sectorlength)
{
	char dirsector[512];
	char mapsector[512];
	int i,j,k,index,sec,cyl,head;

	/*file sizes are limited to 25 sectors*/
	if (sectorlength>25)
		return;

	/*get directory and map*/
	readsector(dirsector,3,0,0);
	readsector(mapsector,2,0,0);

	/*find first available entry*/
	for (i=0; i<512; i=i+0x20)
	{
		if (dirsector[i]==0x00)
			break;
	}
	/*is directory full?*/
	if (i==512)
		return;

	/*copy name to directory, filling remainder with spaces*/
	for (j=0; j<6; j++)
		dirsector[i+j]=0x20;
	for (j=0; j<6; j++)
	{
		if (name[j]==0x00)
			break;
		dirsector[i+j]=name[j];
	}

	i=i+6;
	index=0;

	/*write the file*/
	for (j=0; j<sectorlength; j++)
	{
		/*find free sectors for file*/
		for (k=0; k<256; k++)
		{
			if (mapsector[k]==0)
				break;
		}
		if (k==256)
			break;
		/*set the map entry for the sector to "full"*/
		mapsector[k]=0x46;
		/*add that sector number to the file's dir entry*/
		dirsector[i]=(char)k;
		i++;
		
		/*compute CHS*/
		sec=mod(k,0x12)+1;
		head=mod(div(k,0x12),2);
		cyl=div(k,0x24);
		/*write a sector's worth to the disk*/
		writesector(buffer+index,sec,head,cyl);

		index=index+512;
		
	}
	/*set the next sector in the dir entry to 0.*/
	dirsector[i]=0;
	/*write back the map and directory*/
	writesector(mapsector,2,0,0);
	writesector(dirsector,3,0,0);
}