Пример #1
0
/* Can read single and multi-sector files */
int readFile(char* fname, char* buffer, int* size) {
  char dirBuffer[512];
  int bufferIndex = 0;
  int foundIndex;
  int index = 0;
  *size = 0;

  /* Load directory sector */
  readSector(dirBuffer,2);
  
  while (index < 16) {
    if (strcmp(fname, &dirBuffer[bufferIndex])) {
      foundIndex = bufferIndex + 6;
      while (dirBuffer[foundIndex] != 0x0) {
        readSector(buffer, dirBuffer[foundIndex]);
        buffer = buffer + 512;
        *size = *size + 512;
        ++foundIndex;
      }
  
      return 1; 
    }
    ++index;
    bufferIndex = bufferIndex + 32;
  }

  error(0);
  return 0;
}
Пример #2
0
void readFile(char* file_name, char* buffer) {
	int i = 0;
	char dir_buffer[512];
	readSector(dir_buffer, 2);
	while (i < 16) {
		if (dir_buffer[(i * 32)] != 0x0) {
			int j = 0;
			while (j < 6) {
				if (dir_buffer[(i * 32) + j] == file_name[j]) ++j;
				else break;
			}
			if (j == 6) {
				int buffer_addr = 0;
				while (j < 32) {
					int sector = dir_buffer[(i * 32) + j];
					if (sector == 0x0) break;
					
					readSector(buffer + buffer_addr, sector);
					
					buffer_addr += 512;
					++j;
				}
			}
		}
		++i;
	}
}
Пример #3
0
void deleteFile(char * name){
    char dir[512];
    char map[512];
    char index = 0;
    int i = 6;
    int sector;

    char tmp;

    readSector(dir, 2);
    readSector(map, 1);

    index = findFile(dir, name);
    if(index == 17){
        printString("File not found!\n\0");
        return;
    }
    dir[index*32] = 0x0;

    while(dir[(index*32) + i] != 0x0){
        sector = dir[(index*32)+i];
        map[sector] = 0x0;
        i++;
    }
    writeSector(dir, 2);
    writeSector(map, 1);
}
Пример #4
0
void deleteFile(char* name){
  char directory[SECTORSIZE], map[SECTORSIZE];
  int entry, matched;
  int sector, curSector;

  readSector(directory, DIRECTORYSECTOR);
  readSector(map, MAPSECTOR);

  for(entry=0; entry<MAXFILEENTRY; entry++){
    matched = matchNames(name, directory+entry*FILEENTRYLENGTH, NAMELENGTH);
    if(matched == 1){
      break;
    }
  }
  if(matched == 0){
    return;
  }

  directory[entry*FILEENTRYLENGTH] = FILLERSECTOR;

  for(sector=0; sector<FILESECTORLENGTH; sector++){
    curSector = *(directory+entry*FILEENTRYLENGTH+NAMELENGTH+sector);
    if(curSector != FILLERSECTOR){
      map[curSector] = FILLERSECTOR;
    }else{
      break;
    }
  }

  writeSector(directory, DIRECTORYSECTOR);
  writeSector(map, MAPSECTOR);

  return;
}
void readfile(char* s,char* result){
	char directory[512] ;
	int j = 0;
	 int k = 0;
	 int p=0;
    readSector(directory,2);

    while(j<16){
    	p = 0;
    	k=j*32;
         while(p<6){
         	if(s[p]!=directory[k+p])
         		break ;
         	
         	  	
         	p++;	          
         }
         j++;
         while(p>=6){
         	 if(directory[k+p]==0)
         	return;
           readSector(result,directory[k+p]);
            result+=512;
         if(p==31)
         	return;
         p++;
         }
         
    	}
    	
    }
Пример #6
0
//deleteFile method
int deleteFile(char *fname){
    char dirBuffer[512];
    char diskmap[512];
    struct directory *dir;
    int i = 0;
    int j = 0;
    dir = dirBuffer;
    readSector(dirBuffer,2);
    readSector(diskmap,1);
    for (i; i < 16; i++) {
        if(compare(fname,dir->entries[i].name) == 1){
            for( j = 0; j < 26 ; j++){
                if(dir->entries[i].sectors[j]!=0){
                    diskmap[ dir->entries[i].sectors[j] ] = 0;
                }
            }
            
            dir->entries[i].sectors[0] = 0x00;
            dir->entries[i].name[0] = 0x00;
            
            writeSector(diskmap,1);
            writeSector(dirBuffer,2);
            return 1;
        }
        
    }
    return -1;
}
Пример #7
0
int readFile(char *filename, char *buffer){
	int file = 0;
	int i=6;
	int sectors[26];
	int address=0;

	readSector(buffer,2);

	file = searchFileInDirectory(buffer,filename);
	if(file<0){
		cleanBuffer(buffer);
		return -1; //File was not found
	}

	file*=32; //set the rigth file offset
	for(i=0;i<26;i++){
		sectors[i]=buffer[file+i+6]; //pass each sector number to sectors array
	}

	cleanBuffer(buffer);

	for(i=0;i<26;i++){
		if(sectors[i]==0) //check if it is the last sector 
			break; 
		readSector(buffer+address,sectors[i]); //read the sector at sectors[i]
		address+=512; //create more space for the next sector to be read
	}

	return file;
}
	void MifarePlusSL3Commands::readSectors(int start_sector, int stop_sector, void* buf, size_t buflen, boost::shared_ptr<AccessInfo> aiToUse)
	{
		int i;
		size_t test_buflen = 0;
		size_t toReadLen = 0;

		if (aiToUse)
		{
			boost::shared_ptr<MifarePlusAccessInfo> mAiToUse = boost::dynamic_pointer_cast<MifarePlusAccessInfo>(aiToUse);
			EXCEPTION_ASSERT(mAiToUse, std::invalid_argument, "aiToUse must be a MifarePlusAccessInfo.");

			for (i = start_sector; i < stop_sector; ++i)
			{
				test_buflen += getNbBlocks(i) * MIFARE_PLUS_BLOCK_SIZE;
			}
			if (test_buflen + MIFARE_PLUS_BLOCK_SIZE > buflen)
				throw EXCEPTION(std::invalid_argument, "Bad buffer parameter. The buffer must fit the sectors size.");

			test_buflen = 0;
			for (i = start_sector; i <= stop_sector && test_buflen < buflen; ++i)
			{
				toReadLen = getNbBlocks(i) * MIFARE_PLUS_BLOCK_SIZE;
				if (toReadLen + test_buflen > buflen)
					toReadLen = buflen - test_buflen;
				if (mAiToUse->keyA && !mAiToUse->keyA->isEmpty())
					readSector(i, 0, reinterpret_cast<char*>(buf) + test_buflen, toReadLen, mAiToUse->keyA, KT_KEY_AES_A);
				else if (mAiToUse->keyB && !mAiToUse->keyB->isEmpty())
					readSector(i, 0, reinterpret_cast<char*>(buf) + test_buflen, toReadLen, mAiToUse->keyB, KT_KEY_AES_B);
				else
					throw EXCEPTION(std::invalid_argument, "You must set the writing key using the MifarePlusAccessInfo ");
				test_buflen += getNbBlocks(i) * MIFARE_PLUS_BLOCK_SIZE;
			}
		}
	}
Пример #9
0
deleteFile(char* name) {
	char map[512];
	char dir[512];
	int i;
	int j;
	int sector;

	readSector(map, 1);
	readSector(dir, 2);

	for(i=0; i<512; i=i+0x20) {
		for (j=0; j<6; j++) {
			if(dir[i+j] != name[j])
				goto continue_outer_loop;
		}
		dir[i] = 0x00;
		j = i+6;
		while (dir[j] != 0x00) {
			sector = dir[j++];
			map[sector+1] = 0x00;
		}
		continue_outer_loop:;
	}
	writeSector(map, 1);
	writeSector(dir, 2);
}
Пример #10
0
/* deletes a file, and frees sectors */
void deleteFile(char* name) {
 
  char mapDir[512]; 
  char diskDir[512];
  char* diskPtr = diskDir;
  int i = 0;
  readSector(mapDir,1);
  readSector(diskDir,2);


  while (i < 16) {
    if(strcmp(name, diskPtr)) {
      *diskPtr = 0x0;
      diskPtr = diskPtr + 6;
      while (*diskPtr != 0x0) {
        mapDir[*diskPtr] = 0x0;
        diskPtr++;
      }
      writeSector(mapDir,1);
      writeSector(diskDir,2);
      return;
    } 
    ++i;
    diskPtr = diskPtr + 32;
  }
 
  error(0); 
  return;
}
Пример #11
0
int main() {
	char buf[CHUNK];
	char* bootloaderSecondStageName = "BOOT2.SYS;1";
	readSector(buf, 0x10); //0x10 sector Primary Volume Descriptor, 0x11 Boot Record
#if IS_DEBUG == 1
	printInt8((char*)buf);
	printString(((char*)buf) + 1, 5);
#endif
	int rootDirExtendLBA = *((int32_t*)(buf + 156 + 2));
	int rootDirExtendSize = *((int32_t*)(buf + 156 + 10));
	PRINTF("rootDirExtendLBA=%d rootDirExtendSize=%d\n", rootDirExtendLBA, rootDirExtendSize);
	
//-------------- EXTEND of ROOT dir ----------------------------
	readSector(buf, rootDirExtendLBA);
#if IS_DEBUG == 1
	printInt8(buf);
#endif
	int i = 0;
	int locationOfExtendLBA;
	int sizeOfExtendLBA;
	while (i <  rootDirExtendSize) {
		int dirRecordLength = buf[i];
		if (dirRecordLength ==0 ) break;
		PRINTF("-------------------------------------------------------------------------------\n");
		PRINTF("dirRecordLength=%d\n", dirRecordLength);
		int fileNameLength = buf[i + 32];
#if IS_DEBUG == 1
		printString(buf + i + 33, fileNameLength);
#endif
		locationOfExtendLBA = *((int32_t*)(buf + i + 2));
		sizeOfExtendLBA = *((int32_t*)(buf + i + 10));
		PRINTF("locationOfExtendLBA=%d sizeOfExtendLBA=%d\n", locationOfExtendLBA, sizeOfExtendLBA);
		if (strcmp(bootloaderSecondStageName, buf + i + 33)) {
			break;
		}
		i += dirRecordLength;
	}

	FILE *f = fopen("BOOT2.SYS", "wb");
	if (f == NULL)
	{
		PRINTF("Error opening file!\n");
		exit(1);
	}

	i = 0;
	while (i < sizeOfExtendLBA) {
		readSector(buf, i);
		if (sizeOfExtendLBA - i < CHUNK) {
			fwrite (buf , sizeof(char), sizeOfExtendLBA - i, f);
		} else {
			fwrite (buf , sizeof(char), sizeof(buf), f);
		}
		i += CHUNK;	
	}
	fclose(f);
	
}
Пример #12
0
writeFile(char* name, char* buffer, int secNum) {
	char map[512];
	char dir[512];
	int i;
	int j;
	int k;
	int z;
	int remBytes;
	char data[512];

	readSector(map, 1);
	readSector(dir, 2);

	for(i=0; i<512; i=i+0x20) {
		if (dir[i] != 0x00) {
			goto continue_outer_loop;
		}
		j = 0;
		k = i;
		while (name[j] != '\0') {
			dir[i++] = name[j++];
		}
		z = i-k;
		if (z > 0) {
			while (z < 6) {
				dir[i++] = 0x00;
				z++;
			}
		}
		k = 0;
		z = 0;
		while (k < secNum) {
			while(z<512) {
				if (map[z] == 0x00) {
					map[z] = 0xff;
					break;
				}
				z++;
			}
			dir[i++] = z;
			for (j=0; j<512; j++) {
				data[j] = buffer[j+k*512];
			}
			writeSector(data, z);
			k++;
		}
		remBytes = 26-secNum;
		for(j=0; j<remBytes; j++) {
			dir[i++] = 0x00;
		}
		break;

		continue_outer_loop:;
	}
	writeSector(map, 1);
	writeSector(dir, 2);
}
Пример #13
0
void writeFile(char * name, char * buffer, int numberOfSectors){
    char dir[512];
    char map[512];
    char tmpSect[512];
    int dirNum = 0;
    int i = 0;
    int sectNum = 0;
    int k = 0;
    int iBuf = 0;
    readSector(dir, 2);
    readSector(map, 1);

    dirNum = findFreeDir(dir);

    if(dirNum >= 16){
        return;
    }
    // Writing the name in directory
    while(name[i] != 0x0){
        dir[dirNum*32+i] = name[i];
        i++;
    }

    // Writing data and map
    for(i = 0; i <= numberOfSectors; i++){
        // Locating free sector
        while(map[sectNum] != 0x0){
            sectNum++;
        }
        if(i >= 16){
            deleteFile(name);
            return;
        }
        printString(name); 
        // Writing to map and directory
        map[sectNum] = 0xFF;
        writeSector(map, 0);
        dir[dirNum*32+6+i] = sectNum;

        // Writing the sector
        for(k = 0; k < 512; k++){
            tmpSect[k] = buffer[iBuf];
            iBuf++;
        }
        writeSector(tmpSect, sectNum);
    }

    // Filling the rest of the dir entry with 0x00
    while(i<16){
        dir[dirNum*32+6+i] = 0x0;
        i++;
    }

    writeSector(map, 1);
    writeSector(dir, 2);
}
Пример #14
0
 void readFile (char* a , char* buffer){
  
   char line[512];
   int i = 0;
   int fileNameCounter=0;
   int fileNumber = 0;
 
   int  sectorNumber = 0;
   readSector(line,2);
    
    
  
 
   for(i =0 ; i<512 ; i++ ){

   	if(fileNameCounter == 6 ){
   	//printString("heree1");
   		 if(i < (fileNumber+1)*32){
   		 	       
             if(line[i] != 0x0){
               
             	readSector(buffer+(512*sectorNumber),line[i]);
             	sectorNumber++;
             }else{
             	  
             	break;
             }
   		 }else{
   		 	break;
   		 }
   	}

     if(fileNameCounter < 6){
          
            if(line[i] == a[fileNameCounter] || !a[fileNameCounter]){
               
         		fileNameCounter++;
            //printString("here2");
          }else{
          
          	  fileNumber++;
            i = (fileNumber*32) -1;
            fileNameCounter = 0;

          }
        

         
     }

   }
   
  
}
Пример #15
0
void readFile(char* fileName, char* buffer, int* size) {
    char directory[512];
    int i, j;
    int sectorCount = 0;

    readSector(directory, 2);

    for(i = 0; i < 512; i += 32) {
        // Iterate through every file name in the directory

        if(directory[i] == 0x0) {
            // Skip this iteration since there is no file
            continue;
        }

        // Check if the file names match
        for(j = 0; j < 6; j += 1) {
            if(fileName[j] == '\0') {
                // End of fileName is reached; file found
                j = 6;
                break;
            } else if(directory[i + j] != fileName[j]) {
                // Names do not match
                break;
            }
        }

        if(j == 6) {
            // File names match
            break;
        }
    }

    if(i == 512) {
        // File not found
        error(0);
    } else {
        // Filename is at i'th index of directory sector
        j += i;
        for(j; j < i + 32; j += 1) {
            // Read sector numbers of the file
            if(directory[j] == 0) {
                break;
            }

            readSector(buffer, directory[j]);
            buffer += 512;
            sectorCount += 1;
        }

        *size = sectorCount;
    }
}
Пример #16
0
	unsigned int MifareCommands::getSectorFromMAD(long aid, boost::shared_ptr<MifareKey> madKeyA)
	{
		unsigned int sector = static_cast<unsigned int>(-1);
		MifareAccessInfo::SectorAccessBits sab;
		
		if (!madKeyA->isEmpty())
		{
			getMifareChip()->getMifareProfile()->setKey(0, KT_KEY_A, madKeyA);
		}

		unsigned char madbuf[32];
		memset(madbuf, 0x00, sizeof(madbuf));

		if (!readSector(0, 1, madbuf, sizeof(madbuf), sab))
		{
			THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Can't read the MAD.");
		}
		
		unsigned char madcrc = calculateMADCrc(madbuf, sizeof(madbuf));
		if (madcrc != madbuf[0])
		{
			THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Bad MAD CRC.");
		}
		
		sector = findReferencedSector(aid, madbuf, sizeof(madbuf));

		if ((sector == static_cast<unsigned int>(-1)) && getChip()->getCardType() == "Mifare4K")
		{
			unsigned char madbuf2[48];
			memset(madbuf2, 0x00, sizeof(madbuf2));

			if (readSector(16, 0, madbuf2, sizeof(madbuf2), sab) != sizeof(madbuf2))
			{
				THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Can't read the MAD2.");
			}

			unsigned char mad2crc = calculateMADCrc(madbuf2, sizeof(madbuf2));
			if (mad2crc != madbuf2[0])
			{
				THROW_EXCEPTION_WITH_LOG(LibLogicalAccessException, "Bad MAD2 CRC.");
			}

			sector = findReferencedSector(aid, madbuf2, sizeof(madbuf2));

			if (sector != static_cast<unsigned int>(-1))
			{
				sector += 16;
			}
		}

		return sector;
	}
Пример #17
0
void readFile(char* name, char* file){
  	int i=0;
  	int j=0;
  	int k=0;
  	int test=1;
  	char directory[512];
  	char fileName[6];
  	char* base = name;
  	int fileAddress = 0;
  	readSector(directory,2);
  	for(i=0;i<512;i++){
  		for(j=0;j<6;j++){
  			if(directory[i+j] != name[j]){
  					test = 0;
  					break;
  			}

  		}

  		if(test == 0){
  			//printString("3w\0");
  			i = i+31;
        test =1;

  		}

  		else{

  			i+=6;
  			break;
  		}
  	}

  	if(test == 1){
  		  		for(k=0;k<26;k++){
  			if(directory[i] != 0x00){
  				readSector(fileAddress+file,directory[i]);
  				fileAddress = fileAddress+512;
          i++;

  			}
  			else{
  				break;
  			}
  			}
  		
  	}
  	
  }
Пример #18
0
void writeFile(char* filename, char* contents, int numSectors){
  char directory[SECTORSIZE], map[SECTORSIZE];
  int entry, q, filenameEnd;
  int sector, sectorCount, currentChar;
  int remnants;

  readSector(directory, DIRECTORYSECTOR);
  readSector(map, MAPSECTOR);

  /*Find empty directory*/
  for(entry=0; entry<MAXFILEENTRY; entry++){
    if(directory[entry*FILEENTRYLENGTH] == FILLERSECTOR){
      break;
    }
  }

  /*Write filename to directory*/
  filenameEnd = 0;
  for(q=0; q<NAMELENGTH; q++){
    if(filename[q] == '\0' || filename[q] == '\r' || filenameEnd){
      filenameEnd = 1;
      directory[entry*FILEENTRYLENGTH+q] = FILLERSECTOR;
    }else{
      directory[entry*FILEENTRYLENGTH+q] = filename[q];
    }
  }

  /*Find and fill free sectors*/
  sectorCount = 0;
  for(sector=DIRECTORYSECTOR+1; sector<SECTORSIZE && sectorCount<numSectors; sector++){
    if(map[sector] != FILLERSECTOR){
      map[sector] = FILLERSECTOR;
      directory[entry*FILEENTRYLENGTH+NAMELENGTH+sectorCount] = sector;
      writeSector(contents+sectorCount*SECTORSIZE, sector);
      sectorCount++;
    }
  }

  /*Zero remnants of entry*/
  for(remnants=NAMELENGTH+sectorCount+1; remnants<FILEENTRYLENGTH; remnants++){
    directory[entry*FILEENTRYLENGTH+remnants] = FILLERSECTOR;
  }

  writeSector(directory, DIRECTORYSECTOR);
  writeSector(map, MAPSECTOR);

  return;
}
Пример #19
0
void handleInterrupt21(int ax, int bx, int cx, int dx){
    switch(ax){
        case 0:
            printString((char*) bx);
            break;
        case 1:
            readString((char*) bx);
            break;
        case 2:
            readSector((char*) bx, cx);
            break;
        case 3:
            readFile((char*) bx,(char *) cx);
            break;
        case 4:
            executeProgram((char*) bx, cx);
            break;
        case 5:
            terminate();
            break;
        case 6:
            writeSector((char*) bx, cx);
            break;
        case 7:
            deleteFile((char*) bx);
            break;
        case 8:
            writeFile((char *) bx, (char*) cx, dx);
            break;
        case 9:
            listFile((char *) bx);
            break;
    }
}
Пример #20
0
void scanDirectory(int dirID, File* fileInfo, int* fileNum) {
  int entry, flag;
  char directoryBuffer[SECTOR_SIZE];
  readSector(directoryBuffer, dirID);
  /* interrupt(0x21, 2, directoryBuffer, 2, 0); */
  for (entry = 0; entry < 16; entry++) {
    char filename[7];
    char number[50];
    int pointer;
    int j;
    pointer = entry * 32;
    if (directoryBuffer[pointer] == 0x00) {
      continue;
    }
    flag = 0;
    for (j = 0; j < 6; j++) {
      if (directoryBuffer[pointer + j] == 0) {
        flag = 1;
      }
      if (!flag) {
        filename[j] = directoryBuffer[pointer + j];
      } else {
        filename[j] = '\0';
        break;
      }
    }
  }
}
Пример #21
0
void getExt2Superblock(int disk, int sect, ext2_superblock *sp){
	readSector(disk, sect+2, (char *)sp);
	if(sp->version_major < 1){ //If major version is less than 1, then use defaults for stuff
		sp->first_inode = 11;
		sp->inode_size = 128;
	}
}
Пример #22
0
int isoRead(void *buffer, u32 lba, int offset, u32 size)
{
	u32 remaining;
	u32 pos, copied;
	u32 re;
	int ret;

	remaining = size;
	pos = isoLBA2Pos(lba, offset);
	copied = 0;

	while(remaining > 0) {
		ret = readSector(isoPos2LBA(pos), g_sector_buffer);

		if (ret < 0) {
			break;
		}

		re = MIN(isoPos2RestSize(pos), remaining);
		memcpy(buffer+copied, g_sector_buffer+isoPos2OffsetInSector(pos), re);
		remaining -= re;
		pos += re;
		copied += re;
	}

	return copied;
}
Пример #23
0
void handleInterrupt21 (int AX, int BX, int CX, int DX){
	if (AX == 0){
	    printString(BX);
	}
	else if (AX ==1){
	    readString(BX);
	}
	else if(AX == 2){
	    readSector(BX,30);
	}
	else if (AX == 3){
		readFile(BX, CX);
	}
	else if(AX == 4){
		executeProgram(BX,CX);
	}
	else if(AX == 5){
		terminate();
	}
	else if(AX == 6){
		clear();
	}
	else{
	    printString("La interrupcion no existe!\0");
	}
}
Пример #24
0
void readFile(char* array, char* buffer){
	char temp [512];

	int i = 0;
	char* origin = *buffer;
	interrupt(0x21, 2, temp, 2, 0);
	while(i<512){
		char c [7];
		int j =0;
		while (j<6){
			c[j] = temp[i+j];
			j++;
		}
		c[6] = '\0';
		if(equals(array , c)==1){
			while(j<32){
				int x = temp[i+j];
				if(x != 0){
					readSector(buffer , x);
					buffer = buffer +512;
				}
				else break;
				j++;
			}
			break;
		}
		i = i+32;
	}
	*buffer = *origin;
}
Пример #25
0
Cache::Item* FsDevice::read(const Cache::ItemIdentity& ident)
{
  debug(FS_DEVICE, "read - CALL (ident addr=%x)\n", &ident);

  const SectorCacheIdent* sector_ident = static_cast<const SectorCacheIdent*>(&ident);

  // invalid / not usable ident-object
  if(sector_ident == NULL)
  {
    debug(FS_DEVICE, "read - ERROR invalid argument.\n");
    return NULL;
  }

  sector_addr_t sector = sector_ident->getSectorNumber();
  sector_len_t block_size = sector_ident->getSectorSize();

  debug(FS_DEVICE, "read - reading from sector=%x (BlockSize=%d)\n", sector, block_size);

  // reading the Sector from the FsDevice
  char* data = new char[block_size];
  if(!readSector(sector, data, block_size))
  {
    // I/O read-error
    return NULL;
  }

  return new SectorCacheItem( data );
}
Пример #26
0
void handleInterrupt21(int ax, int bx, int cx, int dx) {
    switch(ax) {
        case 0:
            printString(bx);
            break;
        case 1:
            readString(bx);
            break;
        case 2:
            readSector(bx, cx);
            break;
        case 3:
            readFile(bx, cx, dx);
            break;
        case 4:
            runProgram(bx, cx);
            break;
        case 5:
            stop();
            break;
        case 12:
            clearScreen(bx, cx);
            break;
        case 13:
            writeInt(bx);
            break;
        case 14:
            readInt(bx);
            break;
        case 15:
            error(bx);
            break;
    }
}
Пример #27
0
void handleInterrupt21(int ax, int bx, int cx, int dx){
	switch(ax){
		case 0: printString(bx); break;
		case 1: readString(bx); break;
		case 2: readSector(bx,cx); break;
		default: printString("error"); break;
	}
}
Пример #28
0
phStatus_t forceReadSector(uint8_t sector_id, uint8_t ** keys, uint16_t nbKeys, uint8_t * data) {
  uint8_t bSak[1];
  uint8_t bUid[10];
  uint8_t bNbCards;
  uint8_t bLength;
  uint16_t i;
  PH_CHECK_SUCCESS_FCT(status, search_card(bUid, &bLength, bSak, &bNbCards));
  for (i = 0; i < nbKeys; i++) {
    if (readSector(sector_id, keys[i], PHAL_MFC_KEYA, bUid, data) == PH_ERR_SUCCESS)
      return PH_ERR_SUCCESS;
    PH_CHECK_SUCCESS_FCT(status, search_card(bUid, &bLength, bSak, &bNbCards));
    if (readSector(sector_id, keys[i], PHAL_MFC_KEYB, bUid, data) == PH_ERR_SUCCESS)
      return PH_ERR_SUCCESS;
    PH_CHECK_SUCCESS_FCT(status, search_card(bUid, &bLength, bSak, &bNbCards));
  }
  return PH_ERR_AUTH_ERROR;
}
Пример #29
0
	void deleteFile(char* c)
	{
		char map[512];
		char dir[512];
		int i = 0;
		char* base = c;
		int flag = 1;
		readSector(map , 1);
		readSector(dir , 2);
		
		while(i < 512)
		{
			int j = i;
			c = base;
			flag = 1;
			while(*c != 0x0)
			{
				if(*c != dir[j])
				{
					flag = 0;
					break;
				}
				j++;
				c++;
			}

			if(flag == 1)
				break;	

			i+=32;		
		}

		dir[i] = 0x00;
		i+=6;

		while(dir[i] != 0x00)
		{
			map[dir[i]] = 0x00;
			i++;
		}
      
		writeSector(map , 1);
		writeSector(dir , 2);


	}
Пример #30
0
dword Archive::write( Handle * pHandle, const void * pBuffer, dword nBytes )
{
	if (! m_Open || !pHandle || !pBuffer || m_Access == READ )
		return 0;

	dword nBytesWritten = 0;
	while( nBytesWritten < nBytes )
	{
		dword remain = ARCHIVE_SECTOR_SIZE - pHandle->offset;	// number of bytes remaing in buffer
		dword write = nBytes > remain ? remain : nBytes;			// number of bytes to copy from this sector

		// copy the bytes
		memcpy( pHandle->buffer + pHandle->offset, pBuffer, write );
		pHandle->modified = true;

		// advance the pointers
		pHandle->offset += write;
		pHandle->position += write;

		if ( pHandle->position > pHandle->size )
			pHandle->size = pHandle->position;

		nBytesWritten += write;
		pBuffer = ((byte *)pBuffer) + write;

		// do we need to load the next sector
		if ( remain == write )
		{
			lock();

			// was the last sector modified
			if ( pHandle->modified )
			{
				writeSector( pHandle );
				pHandle->modified = false;
			}

			dword sector = pHandle->sector;
			dword nextSector = m_SectorMap[ sector ];
			ASSERT( nextSector != SECTOR_FREE );

			if ( nextSector == SECTOR_LAST )
			{
				nextSector = allocateSector();
				m_SectorMap[ sector ] = nextSector;
			}

			pHandle->sector = nextSector;
			pHandle->offset = 0;

			readSector( pHandle );
			
			unlock();
		}
	}

	return nBytesWritten;
}