Ejemplo n.º 1
0
/*
 * Finds and mounts an existing Rocks Partition, if one exists.
 * Returns 0 on success, 1 otherwise. Mounts to a well-known dir.
 */
static int
getRocksPartition()
{
	int	rc=1;
	int	major, minor, blocks;
	char	dev[32];
	char	*diskdevice;
	char	*line;
	char	*contents;

	contents = getPartitions();

	diskdevice = NULL;

	/*
	 * eat the first two lines
	 *
	 * there is a two line header on the output of
	 * /proc/partitions -- toss those lines, then do
	 * the work
	 */
	line = contents;
	line = strstr(line, "\n") + 1;

	while (1) {
		line = strstr(line, "\n");
		if (!line)
			break;
		line += 1;
		if (!strlen(line))
			continue;

		sscanf(line, "%d %d %d %32s", &major, &minor, &blocks, dev);

		if (!diskdevice || 
			strncmp(dev, diskdevice, strlen(diskdevice))) {
			/* A disk device name, like hda */
			diskdevice = dev;
			logMessage(INFO, "ROCKS:found disk device %s", dev);
			rc = bootable(diskdevice, major, minor);
			if (!rc) {
				/* Restart the parse */
				free(contents);
				return getRocksPartition();
			}
		}

		else if (!strncmp(dev, diskdevice, strlen(diskdevice))) {
			/* A disk partition name, like hda1 */
			logMessage(INFO, "ROCKS:found partition %s", dev);
			rc = mountRocksDisk(dev, major, minor);
			if (!rc)
				break;		/* Success */
		}
	}
	free(contents);
	return rc;
}
Ejemplo n.º 2
0
/*
 * Like getRocksPartition() but for USB disks.
 * Returns 0 on success, 1 otherwise. Mounts to a well-known dir.
 */
static int
getRocksUSB()
{
	int	rc=1;
	int	major, minor, blocks;
	char	dev[32];
	char	*diskdevice;
	char	*line;
	char	*contents;

	contents = getPartitions();

	diskdevice = NULL;

	/*
	 * eat the first two lines
	 *
	 * there is a two line header on the output of
	 * /proc/partitions -- toss those lines, then do
	 * the work
	 */
	line = contents;
	line = strstr(line, "\n") + 1;

	while (1) {
		line = strstr(line, "\n");
		if (!line)
			break;
		line += 1;
		if (!strlen(line))
			continue;

		sscanf(line, "%d %d %d %32s", &major, &minor, &blocks, dev);

		logMessage(INFO,
			"ROCKS:searching for USB keys on device %s", dev);
		rc = mountRocksUSB(dev, major, minor);
		if (!rc)
			break;		/* Success */
	}
	free(contents);
	return rc;
}
Ejemplo n.º 3
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;
}