Пример #1
0
	//---------------------------------------------------------------------------------
	void MeshAndBspLoadContext::load(const DataStreamExPtr& _dataStream)
	{
		clear();
		mDataStream = _dataStream;

		Progress& progress = Progress::getSingleton();
		progress.setRange(0, 100);

		// Read version and size of entire MeshAndBsp.
		readMeshAndBspHeader();

		// Read mesh
		MshFileLoadContext::load(_dataStream);
		progress.setPosition(5);

		// Read BSP
		bool finish = false;
		while(!finish)
		{
			Chunk chunk(mDataStream);
			switch(chunk.getID())
			{
				case 0xC000: readBspInfo(chunk); break;
				case 0xC010: readPolygonIndices(chunk); break;
				case 0xC040: readBspNodes(chunk); break;
				case 0xC045: readLights(chunk); break;
				case 0xC050: readSectors(chunk); break;
				case 0xC0FF: finish = true; break;
			}
		}
		progress.setPosition(10);

		// Remove excess polygons
		countPolygonUsesInLod0();
		removePolygonsNotUsedInLod0();

		// Log statistics
		logStatistics();
	}
Пример #2
0
unsigned int FileSystem::readIndirectDataBlocks(PartitionEntry *partition,
                                                unsigned int inode,
                                                unsigned int parentInode,
                                                unsigned int blockNumber,
                                                unsigned int indirectionLevel,
                                                int passNumber,
                                                int performCheck,
                                                int fileType) {
  unsigned int i = 0;
  int retValue = -1;
  unsigned char buf[blockSize];
  unsigned int sector = getBlockSector(partition, blockNumber);
  readSectors(sector, (blockSize / SECTOR_SIZE_BYTES), buf);
  for (i = 0; i < blockSize; i += 4) {
    unsigned int block = getValueFromBytes(buf, i, 4);
    if (block != 0 && (indirectionLevel == 3 || indirectionLevel == 2)) {
      if (passNumber == 4)
        blockMap[block] = 1;
      retValue = readIndirectDataBlocks(partition, inode, parentInode, block,
                                        indirectionLevel - 1, passNumber,
                                        performCheck, fileType);
    } else if (indirectionLevel == 1 && block != 0) {
      if (fileType != 1)
        retValue = parseFilesystem(partition, block, passNumber, inode,
                                   parentInode, performCheck);
      if (passNumber == 4) {
        blockMap[block] = 1;
        continue;
      }
      if (retValue != -1 && !performCheck)
        return retValue;
    }
    if (retValue != -1 && !performCheck)
      return retValue;
  }
  return -1;
}
Пример #3
0
struct ext2_group_desc readGroupDescriptor(int fd, int sector, int offset)
{
  int rc;

  struct ext2_group_desc groupdescriptor;
  unsigned char buf[SECTOR_SZ];

  /* Read sector */
  rc = readSectors ( fd, sector, 1, buf );
  if ( rc == -1 )
  {
    perror ( "Could not read sector" );
    exit(-1);
  }

  groupdescriptor.bg_block_bitmap = buf[0 + offset] + buf[1 + offset] * 256 + buf[2 + offset] * 65536 + buf[3 + offset] * 16777216;
  groupdescriptor.bg_inode_bitmap = buf[4 + offset] + buf[5 + offset] * 256 + buf[6 + offset] * 65536 + buf[7 + offset] * 16777216;
  groupdescriptor.bg_inode_table = buf[8 + offset] + buf[9 + offset] * 256 + buf[10 + offset] * 65536 + buf[11 + offset] * 16777216;
  groupdescriptor.bg_free_blocks_count = buf[12 + offset] + buf[13 + offset] * 256;
  groupdescriptor.bg_free_inodes_count = buf[14 + offset] + buf[15 + offset] * 256;
  groupdescriptor.bg_used_dirs_count = buf[16 + offset] + buf[17 + offset] * 256;

  return groupdescriptor;
}
Пример #4
0
unsigned int FileSystem::parseFilesystem(PartitionEntry *partition,
                                         unsigned int blockNumber,
                                         unsigned int passNumber,
                                         unsigned int currentInode,
                                         unsigned int parentInode,
                                         int performCheck) {
  unsigned char buf[blockSize];
  unsigned int i = 0;
  struct ext2_dir_entry_2 *fileEntry;
  unsigned int blockSector = getBlockSector(partition, blockNumber);
  readSectors(blockSector, (blockSize / SECTOR_SIZE_BYTES), buf);
  while (i < blockSize - 1) {

    fileEntry = (struct ext2_dir_entry_2 *) (buf + i);

    if (fileEntry->inode == 0)
      return -1;

    if (currentInode == 2 && parentInode == 2
        && (strcmp(fileEntry->name, "lost+found") == 0)) {
      lostFoundInode = fileEntry->inode;
    }

    if (passNumber == 1 && performCheck == 1) {
      if (fileEntry->inode != currentInode
          && (strcmp(fileEntry->name, ".") == 0)) {
        QString tmpStr = QString("Entry '.' has inode ")
            + QString::number(fileEntry->inode) + QString(" instead of ")
            + QString::number(currentInode) + QString(".\n");
        textBrowser->append(tmpStr);
        errorQt++;
        fileEntry->inode = currentInode;
        writeSectors(blockSector, (blockSize / SECTOR_SIZE_BYTES), buf);
      }
      if (fileEntry->inode != parentInode && (!strcmp(fileEntry->name, ".."))) {
        QString tmpStr = QString("Entry '..' has inode ")
            + QString::number(fileEntry->inode) + QString(" instead of ")
            + QString::number(parentInode) + QString(".\n");
        textBrowser->append(tmpStr);
        errorQt++;
        fileEntry->inode = parentInode;
        writeSectors(blockSector, (blockSize / SECTOR_SIZE_BYTES), buf);
      }
    } else if (passNumber == 2 && performCheck == 1) {
      inodeMap[fileEntry->inode] = 1;
    } else if (passNumber == 3 && performCheck == 1) {
      inodeLinkCount[fileEntry->inode] += 1;
    } else if (passNumber == 4 && performCheck == 1) {
      blockMap[blockNumber] = 1;
    }

    if (strcmp(fileEntry->name, ".") && strcmp(fileEntry->name, "..")
        && performCheck != 0) {
      if (performCheck == 2) {
        inodeMap[fileEntry->inode] = 1;
      }
      InodeData inode = readInode(partition, fileEntry->inode);
      if ((inode.fileType & 0xF000) == EXT2_S_IFREG && passNumber == 4) {
        readDataBlocks(partition, fileEntry->inode, currentInode,
                       inode.dataBlocksPointers, passNumber, performCheck, 1);
      } else if (!(inode.fileType & EXT2_S_IFDIR) == 0) {
        readDataBlocks(partition, fileEntry->inode, currentInode,
                       inode.dataBlocksPointers, passNumber, performCheck, 2);
      }
    }
    i = i + fileEntry->rec_len;
  }
  if (fileEntry != NULL && fileEntry->rec_len > 8 + fileEntry->name_len
      && (fileEntry->rec_len - 8 - fileEntry->name_len) > 16 && !performCheck)
    return blockNumber;
  return -1;
}
Пример #5
0
uint8_t *ext2_readBlock(uint32_t block, uint8_t *buf, ext2_partition *part){
	readSectors(part->disk, ext2_blockToSector(block, part), part->sectors_per_block, buf);
	return buf;
}
Пример #6
0
/*------------------------------------------------------------------------------
* Name:  main
* Action:  Print out partition tables.
*-----------------------------------------------------------------------------*/
int main ()
{
  int           rc;                       /* Return code        */
  int           fd;                       /* Device descriptor  */           
  int           sector;   		          /* IN: sector to read */
  unsigned char buf[SECTOR_SZ];	          /* temporary buffer   */

  struct partition partitions[32];
  int count;
  int jump;
  int start = 446;
  int totalcount;

  /* Open the device */
  fd = open ( "disk", O_RDWR ); 
  if ( fd == -1 ) 
  {
    perror ( "Could not open device file" );
    exit(-1);
  }

  /* Read the sector */
  sector = atoi( "0" );
  rc = readSectors ( fd, sector, 1, buf );
  if ( rc == -1 )
  {
    perror ( "Could not read sector" );
    exit(-1);
  }

  /* Read the first 4 partitions in MBR and print them */
  for(count = 0; count < 4; count++)
  {
    jump = readPartition(1, start + count*16, buf, partitions, count, 0);
	printPartition(partitions, count);
  }

  /* Update total count of entries in array */
  totalcount = count;

  /* Traverse extended partitions, printing out entries, until we hit an empty entry */
  while (jump > 0)
  {
    /* Read the sector */
    sector = jump;
    rc = readSectors ( fd, sector, 1, buf );
    if ( rc == -1 )
    {
      perror ( "Could not read sector" );
      exit(-1);
    }

  /* Reset count and jump information */
    count = 0;
    jump = 1;

  /* Traverse sector, printing each entry, until we hit either an empty or extended entry */
    while (jump == 1)
    {
      jump = readPartition(0, start + count*16, buf, partitions, totalcount, sector);
      if (jump == 1)
      {
		printPartition(partitions, totalcount);

        count = count + 1;
        totalcount = totalcount + 1;
      }
    }
  }

  close(fd);
  return 0;
}