bool MParted::MParted_Core::commit() { if (!ped_disk_commit_to_dev(pedDisk)) return false; bool success = ped_disk_commit_to_os(pedDisk); //Work around to try to alleviate problems caused by // bug #604298 - Failure to inform kernel of partition changes // If not successful the first time, try one more time. if (!success) { sleep(1); success = ped_disk_commit_to_os(pedDisk); } settleDevice(10); return success; }
bool LibPartedPartitionTable::commit(PedDisk* pd, quint32 timeout) { if (pd == nullptr) return false; bool rval = ped_disk_commit_to_dev(pd); if (rval) rval = ped_disk_commit_to_os(pd); if (!ExternalCommand(QStringLiteral("udevadm"), QStringList() << QStringLiteral("settle") << QStringLiteral("--timeout=") + QString::number(timeout)).run() && !ExternalCommand(QStringLiteral("udevsettle"), QStringList() << QStringLiteral("--timeout=") + QString::number(timeout)).run()) sleep(timeout); 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; }
bool PartitionTable::commit_to_os() { return ped_disk_commit_to_os( disk_ ) ? true : false ; }