示例#1
0
int
check_big_enough(long long required_space)
{
    PedDevice *dev = NULL;
    ped_exception_fetch_all();
    ped_device_probe_all();

    bool big_enough = false;
    for (dev = NULL; NULL != (dev = ped_device_get_next(dev));)
    {
        long long dev_size = process_device(dev);
        if (dev_size >= required_space)
        {
            big_enough = true;
            break;
        }
    }

    // We would free the devices to release allocated memory,
    // but other modules might be using partman use well,
    // and they can hold pointers to libparted structures in
    // other threads.
    //
    // So prefer to leak memory, instead.
    //
    // ped_device_free_all();

    return big_enough;
}
int
main(int argc, char *argv[])
{
	PedDevice *dev;
	ped_exception_fetch_all();
	ped_device_probe_all();
	if (argc > 1) {
		int i;
		for (i = 1; i < argc; ++i) {
			dev = ped_device_get(argv[i]);
			if (dev) {
				process_device(dev);
				ped_device_destroy(dev);
			}
		}
	} else {
		for (dev = NULL; NULL != (dev = ped_device_get_next(dev));)
			process_device(dev);
	}
	return 0;
}
示例#3
0
int
check_big_enough(long long required_space)
{
    PedDevice *dev;
    ped_exception_fetch_all();
    ped_device_probe_all();

    bool big_enough = false;
    for (dev = NULL; NULL != (dev = ped_device_get_next(dev));)
    {
        long long dev_size = process_device(dev);
        if (dev_size > required_space)
        {
            big_enough = true;
            break;
        }
    }
    ped_device_free_all();

    return big_enough;
}
示例#4
0
int
main(int argc, char *argv[])
{
	PedDevice *dev;
	// use "-l" to list all prep partitions found (not just the first one).
	int list = (argc == 2 && !strncmp(argv[1], "-l", strlen("-l")));

	ped_exception_fetch_all();
	ped_device_probe_all();
	for (dev = ped_device_get_next(NULL); dev;
	     dev = ped_device_get_next(dev)) {
		PedDisk *disk;
		PedPartition *part;

		disk = ped_disk_new(dev);
		if (!disk)
			continue;

		for (part = ped_disk_next_partition(disk, NULL); part;
		     part = ped_disk_next_partition(disk, part)) {
			if (ped_partition_is_active(part) &&
			    ped_partition_get_flag(part, PED_PARTITION_PREP)) {
				char *path;

				path = ped_partition_get_path(part);
				if (path) {
					printf("%s\n", path);
					if (!list) {
						free(path);
						return 0;
					}
				}
				free(path);
			}
		}
	}

	return 0;
}
int
main(int argc, char *argv[])
{
  PedDevice *dev;
  char *status = "readwrite";
  char *type = "disk";
  ped_exception_fetch_all();
  ped_device_probe_all();
  for (dev = NULL; NULL != (dev = ped_device_get_next(dev));) {
    if (dev->read_only)
      status = "readonly";
    if (is_cdrom(dev->path))
      type = "cdrom";
    printf("%s\t%s\t%s\t%lli\t%s\n",
	   dev->path,
	   type,
	   status,
	   dev->length * PED_SECTOR_SIZE,
	   dev->model);
  }
  return 0;
}
示例#6
0
文件: part.c 项目: GNUHurdTR/hurd
/* Return a new store in STORE which contains a remap store of partition
   PART from the contents of SOURCE; SOURCE is consumed.  */
error_t
store_part_create (struct store *source, int index, int flags,
		   struct store **store)
{
  static pthread_mutex_t parted_lock = PTHREAD_MUTEX_INITIALIZER;
  static int version_check;

  error_t err = 0;
  PedDevice *dev;
  PedDisk *disk;
  PedPartition *part;
  struct store_run run;

  if ((source->block_size < PED_SECTOR_SIZE
       && PED_SECTOR_SIZE % source->block_size != 0)
      || (source->block_size > PED_SECTOR_SIZE
	  && source->block_size % PED_SECTOR_SIZE != 0))
    return EINVAL;

  pthread_mutex_lock (&parted_lock);

  /* Since Parted provides no source-level information about
     version compatibility, we have to check at run time.  */
  if (version_check == 0)
    {
      const char *version = ped_get_version ();
      version_check = -1;
      if (version == 0)
	error (0, 0, "cannot get version of Parted library!");
      else if (strverscmp (version, NEED_PARTED_VERSION) < 0)
	error (0, 0, "Parted library version %s older than needed %s",
	       version, NEED_PARTED_VERSION);
      else
	version_check = 1;
    }
  if (version_check <= 0)
    {
      error (0, 0, "the `part' store type is not available");
      pthread_mutex_unlock (&parted_lock);
      return ENOTSUP;
    }

  ped_exception_fetch_all ();

  dev = ped_device_new_from_store (source);
  if (! dev)
    {
      ped_exception_catch ();
      err = EIO;
      goto out;
    }

  assert (ped_device_open (dev) != 0);

  disk = ped_disk_new (dev);
  if (! disk)
    {
      ped_exception_catch ();
      err = EIO;
      goto out_with_dev;
    }

  for (part = ped_disk_next_partition (disk, NULL); part;
       part = ped_disk_next_partition (disk, part))
    {
      if (part->type != PED_PARTITION_LOGICAL
	  && part->type != 0 /* PED_PARTITION_PRIMARY */)
	continue;

      assert (part->num);
      if (part->num == index)
        break;
    }

  if (! part)
    {
      err = EIO;
      goto out_with_disk;
    }

  if (source->block_size == PED_SECTOR_SIZE)
    {
      run.start = part->geom.start;
      run.length = part->geom.length;
    }
  else if (source->block_size < PED_SECTOR_SIZE)
    {
      run.start = part->geom.start * (PED_SECTOR_SIZE / source->block_size);
      run.length = part->geom.length * (PED_SECTOR_SIZE / source->block_size);
    }
  else
    /* source->block_size > PED_SECTOR_SIZE */
    {
      run.start = part->geom.start * PED_SECTOR_SIZE;
      if (run.start % source->block_size != 0)
	err = EIO;
      else
	{
	  run.start /= source->block_size;
          run.length = part->geom.length * PED_SECTOR_SIZE;
	  if (run.length % source->block_size != 0)
	    err = EIO;
	  else
	    run.length /= source->block_size;
	}
    }

out_with_disk:
  assert (ped_device_close (dev) != 0);
  ped_disk_destroy (disk);
out_with_dev:
  ped_device_destroy (dev);
out:
  ped_exception_leave_all ();
  pthread_mutex_unlock (&parted_lock);

  if (! err)
    err = store_remap (source, &run, 1, store);

  return err;
}