bool LibPartedPartitionTable::resizeFileSystem(Report& report, const Partition& partition, qint64 newLength) { bool rval = false; #if defined LIBPARTED_FS_RESIZE_LIBRARY_SUPPORT if (PedGeometry* originalGeometry = ped_geometry_new(pedDevice(), partition.fileSystem().firstSector(), partition.fileSystem().length())) { if (PedFileSystem* pedFileSystem = ped_file_system_open(originalGeometry)) { if (PedGeometry* resizedGeometry = ped_geometry_new(pedDevice(), partition.fileSystem().firstSector(), newLength)) { PedTimer* pedTimer = ped_timer_new(pedTimerHandler, nullptr); rval = ped_file_system_resize(pedFileSystem, resizedGeometry, pedTimer); ped_timer_destroy(pedTimer); if (!rval) report.line() << xi18nc("@info:progress", "Could not resize file system on partition <filename>%1</filename>.", partition.deviceNode()); ped_geometry_destroy(resizedGeometry); } else report.line() << xi18nc("@info:progress", "Could not get geometry for resized partition <filename>%1</filename> while trying to resize the file system.", partition.deviceNode()); ped_file_system_close(pedFileSystem); } else report.line() << xi18nc("@info:progress", "Could not open partition <filename>%1</filename> while trying to resize the file system.", partition.deviceNode()); ped_geometry_destroy(originalGeometry); } else report.line() << xi18nc("@info:progress", "Could not read geometry for partition <filename>%1</filename> while trying to resize the file system.", partition.deviceNode()); #else Q_UNUSED(report); Q_UNUSED(partition); Q_UNUSED(newLength); #endif return rval; }
/** * Creates the boot- and the linux partition and formats the linux * partition with an ext2 filesystem * */ int create_partitions(const char* dev, unsigned long bootsector_size) { PedDisk* disk; PedDevice* device; PedPartition* boot_part; PedPartition* linux_part; PedFileSystemType* fs_type; PedTimer* timer; // get device from string e.g. "/dev/sdd" device = ped_device_get(dev); if(device == NULL) { return 0; } // create new partition table disk = ped_disk_new_fresh(device, ped_disk_type_get("msdos")); if(disk == NULL) { ped_device_destroy(device); return 0; } // get file system type (ext2) fs_type = ped_file_system_type_get(FILE_SYSTEM); // create partitions boot_part = ped_partition_new(disk, PED_PARTITION_NORMAL, fs_type, 0, bootsector_size / device->sector_size); linux_part = ped_partition_new(disk, PED_PARTITION_NORMAL, fs_type, bootsector_size / device->sector_size, device->length - 1); // add partitions to partition table PedConstraint* constraint = ped_constraint_any(device); ped_disk_add_partition(disk, linux_part, constraint); ped_disk_add_partition(disk, boot_part, constraint); ped_constraint_destroy(constraint); // create timer timer = ped_timer_new(create_ext2_timer, NULL); // create filesystem ped_file_system_create(&linux_part->geom, fs_type, timer); // commit to hardware ped_disk_commit_to_dev(disk); ped_disk_commit_to_os(disk); return 1; }
/** * \brief Creates a new nested timer. * * This function creates a "nested" timer that describes the progress * of a subtask. \p parent is the parent timer, and \p nested_frac is * the estimated proportion (between 0 and 1) of the time that will be * spent doing the nested timer's operation. The timer should only be * constructed immediately prior to starting the nested operation. * (It will be inaccurate, otherwise). * Updates to the progress of the subtask are propagated * back through to the parent task's timer. * * \return nested timer */ PedTimer* ped_timer_new_nested (PedTimer* parent, float nest_frac) { NestedContext* context; if (!parent) return NULL; PED_ASSERT (nest_frac >= 0.0f); PED_ASSERT (nest_frac <= 1.0f); context = (NestedContext*) ped_malloc (sizeof (NestedContext)); if (!context) return NULL; context->parent = parent; context->nest_frac = nest_frac; context->start_frac = parent->frac; return ped_timer_new (_nest_handler, context); }
PartedTimer::PartedTimer():QObject() { _timer=ped_timer_new(_qt_parted_timer_handler, (void*)this); }