void Collective::initialize(void)
{ _nSpecies = nX = lparameters.groupSize();
  finished = false;
  checkAllocation();
  fill(_alive.begin(), _alive.end(), true);
  currentProposal = BitString::wildType(
    lparameters.nBlocks(), lparameters.nBits() / lparameters.nBlocks());
}
 virtual void 
 run (Arg arg)
   {
     if (0 < arg.size()) NUM_CLUSTERS = lexical_cast<uint> (arg[0]);
     if (1 < arg.size()) NUM_OBJECTS  = lexical_cast<uint> (arg[1]);
     if (2 < arg.size()) NUM_FAMILIES = lexical_cast<uint> (arg[2]);
     
     simpleUsage();
     checkAllocation();
     checkErrorHandling();
   }
Exemplo n.º 3
0
int checkIndirect(int fd, int level, int location, struct ext2_group_desc *gds, int p_start, int blocks_per_group, int inodes_per_group)
{
  int count;
  int offset;
  int sector_count;

  int pointer;
  int rc;
  int sector;

  unsigned char buf[SECTOR_SZ];

  for (sector_count = 0; sector_count < 2; sector_count++)
  {
    count = 0;
    offset = 0;

    sector = location + sector_count;
    rc = readSectors ( fd, sector, 1, buf );
    if ( rc == -1 )
    {
      perror ( "Could not read sector" );
      exit(-1);
    }

    pointer = buf[0 + offset] + buf[1 + offset] * 256 + buf[2 + offset] * 65536 + buf[3 + offset] * 16777216;

    while ((pointer != 0) && (count < 128))
    {
      if (level == 1)
      { rc = checkAllocation(fd, 0, pointer, gds, p_start, blocks_per_group, inodes_per_group); }
      if (level == 2)
      { rc = checkIndirect(fd, 1, pointer, gds, p_start, blocks_per_group, inodes_per_group); }
      if (level == 3)
      { rc = checkIndirect(fd, 2, pointer, gds, p_start, blocks_per_group, inodes_per_group); }

      if (rc == 0) 
      { return 0; }
    
      count = count + 1;
      offset = count * 4;
      pointer = buf[0 + offset] + buf[1 + offset] * 256 + buf[2 + offset] * 65536 + buf[3 + offset] * 16777216;
    }
  }

  return 1;
}
Exemplo n.º 4
0
int checkBlockAllocation(int fd, int *blocks, struct ext2_group_desc *gds, int p_start, int blocks_per_group, int inodes_per_group)
{
  int count = 0;
  int totalcount = 0;
  int location;

  while ((blocks[count] != 0) && (count < 15))
  {
    count = count + 1;
    totalcount = totalcount + 1;
  }

  for (count = 0; count < totalcount; count++)
  {
    if (checkAllocation(fd, 0, blocks[count], gds, p_start, blocks_per_group, inodes_per_group) == 0) 
    { return 0; }
  }

  if (totalcount > 12)
  {
    location = blocks[12] * 2 + p_start;
    return checkIndirect(fd, 1, location, gds, p_start, blocks_per_group, inodes_per_group);
  }

  if (totalcount > 13)
  {
    location = blocks[13] * 2 + p_start;
    return checkIndirect(fd, 2, location, gds, p_start, blocks_per_group, inodes_per_group);
  }

  if (totalcount > 14)
  {
    location = blocks[14] * 2 + p_start;
    return checkIndirect(fd, 3, location, gds, p_start, blocks_per_group, inodes_per_group);
  }

  return 1;
}
Exemplo n.º 5
0
int main ()
{
  int           rc;                       /* Return code        */
  int           fd;                       /* Device descriptor  */           
  int           sector;                   /* IN: sector to read */

  struct partition partitions[16];
  struct ext2_group_desc groupdescriptors[32];
  struct ext2_inode inode;
  struct ext2_super_block superblock;

  int block_size;
  int dir_in_location;
  int partition_start;
  int start = 446;

  int inode_num;
  int dir_count;
  int gd_count;
  int partition_count;

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

  /* Read the partitions */
  partition_count = getPartitions(fd, partitions);
  partition_start = partitions[0].start_sect;

  /* Read the Superblock */
  superblock = readSuperBlock(fd, partition_start);
  if (superblock.s_magic == EXT2_SUPER_MAGIC)
  { printf("\nSuperblock Magic Number: %x (Correct)", superblock.s_magic); }
  else
  { printf("\nSuperblock Magic Number: %x (Incorrect)", superblock.s_magic); }

  block_size = pow(2, superblock.s_log_block_size) * 1024;
  printf("\nBlock Size: %d\n", block_size);

  /* Read the group descriptors */
  gd_count = getGroupDescriptors(fd, partition_start, groupdescriptors);

  /* Read the root inode */
  inode_num = 2;
  inode = getInode(fd, inode_num, groupdescriptors, partition_start, superblock.s_inodes_per_group);
  printf("\nRoot Inode File Mode: ");
  printFileMode(inode.i_mode);

  /* See if root inode is allocated */
  if (checkAllocation(fd, 1, inode_num, groupdescriptors, partition_start, superblock.s_blocks_per_group, superblock.s_inodes_per_group) == 1) 
  { printf("\nInode Allocated\n"); }
  else 
  { printf("\nInode Not Allocated\n"); }

  /* Read the data for root inode */
  printf("\nRoot Inode Directory Data...");
  dir_in_location = partition_start + (inode.i_block[0] * 2);
  dir_count = printDirs(fd, dir_in_location);

  /* Read the oz inode */
  inode_num = 28;
  inode = getInode(fd, inode_num, groupdescriptors, partition_start, superblock.s_inodes_per_group);
  
  /* Read the data for oz inode */
  printf("\n\nOz Directory Data...");
  dir_in_location = partition_start + (inode.i_block[0] * 2);
  dir_count = printDirs(fd, dir_in_location);

  /* Read the ohmy.txt inode */
  inode_num = 4021;
  inode = getInode(fd, inode_num, groupdescriptors, partition_start, superblock.s_inodes_per_group);
  printf("\n\nohmy.txt Inode Data Blocks: %d", inode.i_blocks);

  /* See if ohmy.txt's blocks are allocated */
  if (checkBlockAllocation(fd, inode.i_block, groupdescriptors, partition_start, superblock.s_blocks_per_group, superblock.s_inodes_per_group) == 1) 
  { printf("\nAll Blocks Allocated"); }
  else 
  { printf("\nNot All Blocks Allocated"); }

  /* Read the glinda inode */
  inode_num = 30;
  inode = getInode(fd, inode_num, groupdescriptors, partition_start, superblock.s_inodes_per_group);
  printf("\n\nglinda Inode File Mode: ");
  printFileMode(inode.i_mode);

  printf("\nglinda Link: ");
  printFastSymbolic(fd, inode_num, inode.i_size, groupdescriptors, partition_start, superblock.s_inodes_per_group);

  close(fd);
  return 0;
}