Exemplo n.º 1
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);
}
Exemplo n.º 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);
}
Exemplo n.º 3
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);
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
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);
}
Exemplo n.º 6
0
void Format()
{
	int i =0;
	char arreglo [512];
	for(i=0; i<512;i++)
	{
		arreglo[i]=0;
	}
	for(i=0; i<512;i++)
	{
		writesector(0X40+i,arreglo); 
	}
	arreglo[0] = 'M';
	arreglo[1] = 'D';
	writesector(0X40,arreglo);
	printstring("Format Done!");
}
Exemplo n.º 7
0
void
flushsector(int c)
{
    int		i;

    for (i = (bufptr - buf); i < SECTORSIZE; i++) writechar(c);
    writesector(buf);
    bufptr = buf;
}
Exemplo n.º 8
0
void
writechar(int c)
{
    if ((bufptr - buf) == SECTORSIZE) {
	writesector(buf);
	bufptr = buf;
    }
    *bufptr++ = c;
}
Exemplo n.º 9
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;
}
Exemplo n.º 10
0
void wf(fileBlock *file, char Data[], int blockStart)
{
	int module,blocksToWrite,pos,y,z,x;
	char buffer[512];
	blocksToWrite = mystrlen(Data) / BlockSize;
	module = mod(blocksToWrite, BlockSize);
	pos = 481;
	if (module != 0)
	{
		blocksToWrite = blocksToWrite + 1;
	}
	if (blocksToWrite == 0)
	{
		blocksToWrite = 1;
	}
	file->size = blocksToWrite;
	y = 0;
	while (y < blocksToWrite)
	{
		if (y!=0)
		{
			z = pos;
			while (z < pos + 512)
			{
				buffer[x] = Data[z];
				z++;
				x++;
			}
			writesector(blockStart, buffer);
			blockStart++;
			pos = pos + 512;
		}
		else
		{
			writesector(blockStart, (char *)&file);
			blockStart++;
		}
		y++;
	}
}
Exemplo n.º 11
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;
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
0
void entradaM(int sect, char* map, char * dir, int dirindex, char* content, int x)
{
	int entradaMapa;
	for (entradaMapa=0; entradaMapa<256; entradaMapa++)
		{
			if (map[entradaMapa]==0)
				break;
		}	
		if (entradaMapa==256)
		{
			printstring("Not enough room for file\n");
			return;
		}
		map[entradaMapa]=0x46;
		dir[dirindex+6+x] = entradaMapa;
		writesector(BASEOFFSET+entradaMapa,content+(x*512));
}
Exemplo n.º 14
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++;
	}
}
Exemplo n.º 15
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);
	}
}
Exemplo n.º 16
0
int media_write(uint32 sector, uint8 *buffer, uint32 sector_count)
{
	int ret;
	uint32 i;

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

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

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

		ret = writesector((unsigned char)((sector-last_setlbabase)+1),buffer);
		if( ret != ERR_NO_ERROR )
		{
			hxc_printf_box(&g_ui_ctx,"ERROR: Write sector ERROR !");
			return 0;
		}

		sector++;
	}

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

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

	return 1;
}
Exemplo n.º 17
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);
	}
}
Exemplo n.º 18
0
/**
 * Callback function
 */
int hxc_media_write(unsigned long sector, unsigned char *buffer)
{
	gui_more_busy();

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

		if(!writesector((sector-_last_setlbabase)+1,buffer)) {
			fatal("Write sector error");
		}
	}

	gui_less_busy();

	return 1;
}
Exemplo n.º 19
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);
}
Exemplo n.º 20
0
int setlbabase(unsigned long lba)
{
	int ret;
	unsigned char sector[512];
	direct_access_cmd_sector * dacs;

	#ifdef DEBUG
	dbg_printf("setlbabase : 0x%.8X\n",lba);
	#endif

	dacs=(direct_access_cmd_sector  *)sector;

	memset(&sector,0,512);

#ifdef CORTEX_FW_SUPPORT
	if(g_ui_ctx.firmware_type == CORTEX_FIRMWARE)
	{
		strcpy(dacs->DAHEADERSIGNATURE,CORTEX_FW_ID);
	}
	else
	{
		strcpy(dacs->DAHEADERSIGNATURE,HXC_FW_ID);
	}
#else
	strcpy(dacs->DAHEADERSIGNATURE,HXC_FW_ID);
#endif

	dacs->cmd_code=1;
	dacs->parameter_0 = (unsigned char)((lba>>0)&0xFF);
	dacs->parameter_1 = (unsigned char)((lba>>8)&0xFF);
	dacs->parameter_2 = (unsigned char)((lba>>16)&0xFF);
	dacs->parameter_3 = (unsigned char)((lba>>24)&0xFF);
	dacs->parameter_4 = 0xA5;

	ret = writesector( 0,(unsigned char *)&sector);

	return ret;
}
Exemplo n.º 21
0
void _setlbabase(unsigned long lba)
{
	unsigned char sector[512];
	int ret;
	_direct_access_cmd_sector * dacs;

	dacs=(_direct_access_cmd_sector  *)sector;

	memsetword(&sector, 0, 512/2);

	sprintf(dacs->DAHEADERSIGNATURE,"HxCFEDA");
	dacs->cmd_code=1;
	dacs->parameter_0=(lba>>0)&0xFF;
	dacs->parameter_1=(lba>>8)&0xFF;
	dacs->parameter_2=(lba>>16)&0xFF;
	dacs->parameter_3=(lba>>24)&0xFF;
	dacs->parameter_4=0xA5;

	ret=writesector( 0,(unsigned char *)&sector);
	if(!ret) {
		fatal("Write CTRL error");
	}
}
Exemplo n.º 22
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);
	}
}
Exemplo n.º 23
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);
}
Exemplo n.º 24
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++;
	}
}
Exemplo n.º 25
0
void Remove(char* path)
{
	int i;
	char r;
	char map[512];
	char dir[512];
	char nombre[6];
	char found = 0;
	char sectorNumber;
	char prevSectorNumber;
	char comparar[6];
	int x;
	int n;
	int y;
	int sectorLibre = 0;
	int entradaMapa = 0;
	int dirindex = 0;
	int sectcount;
	int b=0;
	int w=0;
	int z = 0;
	char token [10];
	int toks = CountTokens(path);//cantidad de subdirectorios
	readsector(BASEOFFSET,map);
	readsector(BASEOFFSET +1,dir);	
	sectorNumber = 0x01;
	prevSectorNumber = 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]; //copiando el nombre del directorio
			}
			if(cmp(comparar,nombre,6)==1) //si encontramos el directorio
			{
				prevSectorNumber = sectorNumber;
				sectorNumber = dir[x*0x20+6];
				readsector(BASEOFFSET+sectorNumber,dir);
				found = 1;
				break;
			}
		}
		w++;
	}
	if(found == 1)
	{
		readsector(BASEOFFSET + prevSectorNumber,dir);
		for(y=0;y<7;y++)
		{
			dir[x*0x20+y] = 0;
		}
		writesector(BASEOFFSET + prevSectorNumber,dir);
	
	}else
	{
		printstring("Directorio no Encontrando");
	}	
}
Exemplo n.º 26
0
void guardarArchivo(char* direccion, char* content, int size)
{

	int i;
	char r;
	int sect;
	char map[512];
	char dir[512];
	char nombre[6];
	char found = 0;
	char sectorNumber;
	char otro[6];
	int indexx;
	int n;
	int y;
	int sectorLibre = 0;
	int entradaMapa = 0;
	int dirindex = 0;
	int sectcount;
	int b=0;
	int w=0;
	int z = 0;
	char token [10];
	int toks = CountTokens(direccion);
	readsector(BASEOFFSET,map);
	readsector(BASEOFFSET +1,dir);	
	//sectorNumber = otherFor(direccion, dir);
	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++;		
	}//busca que es el ultimo token no me acuerdo que hace
	for (indexx=0;indexx<15;indexx++)
	{
		dirindex = indexx*0x20;
		sectorLibre = dir[dirindex]; //buscamos la primera entrada libre
		if(sectorLibre==0)
		{
			for (i=0; i<6; i++)
				dir[dirindex+i]=0x20;
			for (i=0; i<6; i++)
			{
				if(nombre[i]==0)
				break;
				dir[dirindex+i]=nombre[i];		
			}
			break;
		}
	}	
	sect = (div(size,512)+1);
	for(indexx=0;indexx<sect;indexx++)
	{
		printnumber(dirindex);
		entradaM(sect,map,dir,dirindex,content,indexx);
	}
	writesector(BASEOFFSET+sectorNumber,dir);
	writesector(BASEOFFSET,map);
	return;
}
Exemplo n.º 27
0
int writefile(char *dosname, char *c64name)
{
        int strack1, strack2;
        int track, sector;
        int lasttrack, lastsector;
        int blocks = 0;
        int c, d;
        FILE *src;

        /* Open the dos file */
        src = fopen(dosname, "rb");
        if (!src) return 0;

        /*
         * Search for free sector, starting from as close to the directory
         * as possible
         */
        strack1 = 1;
        if (interleave > 10)
        {
                for (;;)
                {
                  startsector = 0;
                  starttrack = strack1;
                  for (c = 0; c < sectornumtable[starttrack]; c++)
                  {
                          if (querysector(starttrack, startsector)) goto FIRSTFOUND;
                          startsector--;
                          if (startsector < 0) startsector = sectornumtable[starttrack]-1;
                  }
                  strack1++;
                  if (strack1 == 18) strack1++;
                  if (strack1 > MAX_TRACK) break;
                }
        }
        else
        {
                for (;;)
                {
                  startsector = 0;
                  starttrack = strack1;
                  for (c = 0; c < sectornumtable[starttrack]; c++)
                  {
                          if (querysector(starttrack, startsector)) goto FIRSTFOUND;
                          startsector++;
                          if (startsector >= sectornumtable[starttrack]) startsector = 0;
                  }
                  strack1++;
                  if (strack1 == 18) strack1++;
                  if (strack1 > MAX_TRACK) break;
                }
        }
        /* No free sector found */
        printf("Disk full\n");
        fclose(src);
        return 255;

        FIRSTFOUND:
        track = starttrack;
        sector = startsector;
        lasttrack = -1;
        lastsector = -1;

        for (;;)
        {
                int bytesread;

                memset(buffer, 0, 256);
                bytesread = fread(&buffer[2], 1, 254, src);
                if (bytesread == 0)
                {
                        if (lasttrack > 0)
                        {
                                lastblocksize = 254;
                                readsector(lasttrack, lastsector);
                                buffer[0] = 0;
                                buffer[1] = 255; /* File ends just on the block
                                                  * boundary
                                                  */
                                writesector(lasttrack, lastsector);
                        }
                        else
                        {
                                /* Zero sized file, but we still mark one block
                                 * used
                                 */
                                marksectorused(track, sector);
                                blocks++;
                        }
                        break;
                }
                else
                {
                        if (bytesread == 254)
                        {
                                /* Full block */
                                writesector(track, sector);
                                marksectorused(track, sector);
                                blocks++;
                        }
                        else
                        {
                                /* Less than full block, file ends */
                                lastblocksize = bytesread;
                                buffer[0] = 0;
                                buffer[1] = bytesread+1;
                                writesector(track, sector);
                                marksectorused(track, sector);
                                blocks++;
                                break;
                        }
                }
                lasttrack = track;
                lastsector = sector;

                /* Now search next free sector */
                /* Preferably on the same track */
                sector += interleave;
                if (sector >= sectornumtable[track]) sector %= sectornumtable[track];
                if (querysector(track, sector)) goto FOUND;
                if (interleave > 10)
                {
                        for (c = 0; c < sectornumtable[track]; c++)
                        {
                                sector--;
                                if (sector < 0) sector = sectornumtable[track]-1;
                                if (querysector(track, sector)) goto FOUND;
                        }
                }
                else
                {
                        for (c = 0; c < sectornumtable[track]; c++)
                        {
                                sector++;
                                if (sector >= sectornumtable[track]) sector = 0;
                                if (querysector(track, sector)) goto FOUND;
                        }
                }

                /* No free blocks on same track */
                for (; track <= MAX_TRACK; track++)
                {
                        if (track == 18) track++;
                        for (sector = 0; sector < sectornumtable[track]; sector++)
                        {
                                if (querysector(track, sector)) goto FOUND;
                        }
                }
                /* Give up */
                printf("Disk full\n");
                fclose(src);
                return 255;

                FOUND:
                /* Make link to this track */
                readsector(lasttrack, lastsector);
                buffer[0] = track;
                buffer[1] = sector;
                writesector(lasttrack, lastsector);

                /* Then go back to read more of the file */
        }
        /* File ready, now we must make directory entry */
        fclose(src);

        track = 18;
        sector = 1;

        for (;;)
        {
                NEXTDIRBLOCK:
                readsector(track, sector);
                /* Room in this directory block? */
                for (c = 2; c < 256; c += 32)
                {
                        if (!buffer[c])
                        {
                                /* File name */
                                for (d = 0; d < 16; d++)
                                {
                                        unsigned char ch;

                                        if (d < strlen(c64name)) ch = c64name[d];
                                        else ch = 0xa0;
                                        if (ch == '_') ch = 0x20;
                                        /* Special filename to cut the directory listing */
                                        if ((c64name[0] == 20) && (ch != 20)) ch = 0x00;
                                        buffer[c+d+3] = ch;
                                }
                                /* File location */
                                buffer[c] = 0x82; /* PRG */
                                buffer[c+1] = starttrack;
                                buffer[c+2] = startsector;
                                /* File size */
                                buffer[c+28] = blocks;
                                buffer[c+29] = blocks / 256;
                                writesector(track, sector);
                                return 1; /* OK! */
                        }
                }
                /* More directoryblocks? */
                if (buffer[0])
                {
                        track = buffer[0];
                        sector = buffer[1];
                        goto NEXTDIRBLOCK;
                }

                /* Room for new directoryblock? */
                if (sector == sectornumtable[track]-1) return 0;
                buffer[0] = track;
                buffer[1] = sector+1;
                writesector(track, sector);
                sector++;
                readsector(track, sector);
                buffer[0] = 0;
                buffer[1] = 0xff;       /* Assume new block is the last */
                marksectorused(track, sector);
                writesector(track, sector);
        }
}