static PedPartition* dvh_partition_duplicate (const PedPartition* part) { PedPartition* result; DVHPartData* part_data = part->disk_specific; DVHPartData* result_data; result = _ped_partition_alloc (part->disk, part->type, part->fs_type, part->geom.start, part->geom.end); if (!result) goto error; result->num = part->num; if (!ped_partition_is_active (part)) { result->disk_specific = NULL; return result; } result_data = result->disk_specific = ped_malloc (sizeof (DVHPartData)); if (!result_data) goto error_free_part; result_data->type = part_data->type; strcpy (result_data->name, part_data->name); result_data->real_file_size = part_data->real_file_size; return result; error_free_part: _ped_partition_free (result); error: return NULL; }
static PedPartition* pc98_partition_new ( const PedDisk* disk, PedPartitionType part_type, const PedFileSystemType* fs_type, PedSector start, PedSector end) { PedPartition* part; PC98PartitionData* pc98_data; part = _ped_partition_alloc (disk, part_type, fs_type, start, end); if (!part) goto error; if (ped_partition_is_active (part)) { part->disk_specific = pc98_data = ped_malloc (sizeof (PC98PartitionData)); if (!pc98_data) goto error_free_part; pc98_data->ipl_sector = 0; pc98_data->hidden = 0; pc98_data->boot = 0; strcpy (pc98_data->name, ""); } else { part->disk_specific = NULL; } return part; error_free_part: free (part); error: return 0; }
static PedPartition* dvh_partition_new (const PedDisk* disk, PedPartitionType part_type, const PedFileSystemType* fs_type, PedSector start, PedSector end) { PedPartition* part; DVHPartData* dvh_part_data; part = _ped_partition_alloc (disk, part_type, fs_type, start, end); if (!part) goto error; if (!ped_partition_is_active (part)) { part->disk_specific = NULL; return part; } dvh_part_data = part->disk_specific = ped_malloc (sizeof (DVHPartData)); if (!dvh_part_data) goto error_free_part; dvh_part_data->type = (part_type == PED_PARTITION_EXTENDED) ? PTYPE_VOLHDR : PTYPE_RAW; strcpy (dvh_part_data->name, ""); dvh_part_data->real_file_size = part->geom.length * 512; return part; error_free_part: _ped_partition_free (part); error: return NULL; }
static PedPartition* bsd_partition_new (const PedDisk* disk, PedPartitionType part_type, const PedFileSystemType* fs_type, PedSector start, PedSector end) { PedPartition* part; BSDPartitionData* bsd_data; part = _ped_partition_alloc (disk, part_type, fs_type, start, end); if (!part) goto error; if (ped_partition_is_active (part)) { part->disk_specific = bsd_data = ped_malloc (sizeof (BSDPartitionData)); if (!bsd_data) goto error_free_part; bsd_data->type = 0; bsd_data->boot = 0; bsd_data->raid = 0; bsd_data->lvm = 0; } else { part->disk_specific = NULL; } return part; error_free_part: free (part); error: return 0; }
static void dasd_partition_destroy (PedPartition* part) { PED_ASSERT(part != NULL); if (ped_partition_is_active(part)) free(part->disk_specific); free(part); }
static PedPartition * _amiga_next_real_partition(const PedDisk *disk, PedPartition *part) { PedPartition *next; for (next = ped_disk_next_partition (disk, part); next != NULL && !ped_partition_is_active (next); next = ped_disk_next_partition (disk, next)); return next; }
static int pc98_partition_enumerate (PedPartition* part) { PED_ASSERT (part != NULL); PED_ASSERT (part->disk != NULL); /* don't re-number a partition */ if (part->num != -1) return 1; PED_ASSERT (ped_partition_is_active (part)); part->num = next_primary (part->disk); if (!part->num) { ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, _("Can't add another partition.")); return 0; } return 1; }
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; }
PartitionState do_test1(PedDevice *dev, label_type labelType) { PartitionState state; //PedGeometry geom; PedDisk *disk; PedPartition *part; PedPartition *grub_partition = 0, *boot_partition = 0, *root_partition = 0; PedDiskType *type = 0; PedFileSystemType *ext4 = ped_file_system_type_get("ext4"); bool dirty = false; PedSector start = 0, end = 0; /*if (!ped_geometry_init(&geom,dev,0,dev->length)) { qDebug() << "unable to init geom"; return; }*/ disk = ped_disk_new(dev); /*type = ped_disk_probe(dev); if (type) { qDebug() << "current partition type:" << type->name; disk = type->ops->alloc(dev); if (!type->ops->read(disk)) { qDebug() << "failed to read gpt tables"; return; } }*/ if (!disk) { qDebug() << "no tables detected"; if (labelType == label_type::gpt) { type = ped_disk_type_get("gpt"); } else if (labelType == label_type::mbr) { type = ped_disk_type_get("msdos"); } disk = ped_disk_new_fresh(dev,type); ped_disk_commit(disk); } if (disk) { for (part = ped_disk_next_partition(disk,NULL); part; part = ped_disk_next_partition(disk,part)) { if (!ped_partition_is_active(part)) continue; QString name(ped_partition_get_name(part)); qDebug() << "partition" << part->num << name; if (name == "boot") boot_partition = part; if (name == "root") root_partition = part; if (ped_partition_get_flag(part,PED_PARTITION_BIOS_GRUB)) grub_partition = part; for (int f = PED_PARTITION_FIRST_FLAG; f < PED_PARTITION_LAST_FLAG; f++) { if (ped_partition_get_flag(part,(PedPartitionFlag)f)) { QString flag_name(ped_partition_flag_get_name((PedPartitionFlag)f)); qDebug() << "flag" << flag_name << "is set"; } } } PedConstraint *constraint = ped_constraint_any(dev); if (!grub_partition) { start = (1024*1024) / dev->sector_size; end = ((1024*1024) / dev->sector_size) + start; qDebug() << "creating" << start << end; grub_partition = ped_partition_new(disk,PED_PARTITION_NORMAL,ext4,start,end); if (labelType == label_type::gpt) { ped_partition_set_name(grub_partition,"bios boot"); ped_partition_set_flag(grub_partition,PED_PARTITION_BIOS_GRUB,1); } if (!ped_disk_add_partition(disk,grub_partition,constraint)) { qDebug() << "error adding partition"; } dirty = true; } if (!boot_partition) { start = (1024*1024*2) / dev->sector_size; end = ((1024*1024*128) / dev->sector_size) + start; qDebug() << "creating" << start << end; boot_partition = ped_partition_new(disk,PED_PARTITION_NORMAL,NULL,start,end); if (labelType == label_type::gpt) { ped_partition_set_name(boot_partition,"boot"); } //ped_partition_set_flag(boot_partition,PED_PARTITION_BOOT,1); if (!ped_disk_add_partition(disk,boot_partition,constraint)) { qDebug() << "error adding partition"; } dirty = true; } if (!root_partition) { start = (1024*1024*129) / dev->sector_size; end = dev->length; qDebug() << "creating" << start << end; root_partition = ped_partition_new(disk,PED_PARTITION_NORMAL,ext4,start,end); if (labelType == label_type::gpt) { ped_partition_set_name(root_partition,"root"); //ped_partition_set_flag(root_partition,PED_PARTITION_ROOT,1); } if (!ped_disk_add_partition(disk,root_partition,constraint)) { qDebug() << "error adding partition"; } dirty = true; } ped_constraint_destroy(constraint); } if (dirty) ped_disk_commit(disk); state.boot_path = ped_partition_get_path(boot_partition); state.root_path = ped_partition_get_path(root_partition); return state; }
static PedPartition* amiga_partition_new (const PedDisk* disk, PedPartitionType part_type, const PedFileSystemType* fs_type, PedSector start, PedSector end) { PedPartition *part; PedDevice *dev; PedSector cyl; struct PartitionBlock *partition; struct RigidDiskBlock *rdb; PED_ASSERT(disk != NULL); PED_ASSERT(disk->dev != NULL); PED_ASSERT(disk->disk_specific != NULL); dev = disk->dev; cyl = (PedSector) (dev->hw_geom.sectors * dev->hw_geom.heads); rdb = RDSK(disk->disk_specific); if (!(part = _ped_partition_alloc (disk, part_type, fs_type, start, end))) return NULL; if (ped_partition_is_active (part)) { if (!(part->disk_specific = ped_malloc (disk->dev->sector_size))) { free (part); return NULL; } partition = PART(part->disk_specific); memset(partition, 0, sizeof(struct PartitionBlock)); partition->pb_ID = PED_CPU_TO_BE32(IDNAME_PARTITION); partition->pb_SummedLongs = PED_CPU_TO_BE32(64); partition->pb_HostID = rdb->rdb_HostID; partition->pb_Flags = PED_CPU_TO_BE32(0); /* TODO : use a scheme including the device name and the * partition number, if it is possible */ _amiga_set_bstr("dhx", partition->pb_DriveName, 32); partition->de_TableSize = PED_CPU_TO_BE32(19); partition->de_SizeBlock = PED_CPU_TO_BE32(128); partition->de_SecOrg = PED_CPU_TO_BE32(0); partition->de_Surfaces = PED_CPU_TO_BE32(dev->hw_geom.heads); partition->de_SectorPerBlock = PED_CPU_TO_BE32(1); partition->de_BlocksPerTrack = PED_CPU_TO_BE32(dev->hw_geom.sectors); partition->de_Reserved = PED_CPU_TO_BE32(2); partition->de_PreAlloc = PED_CPU_TO_BE32(0); partition->de_Interleave = PED_CPU_TO_BE32(0); partition->de_LowCyl = PED_CPU_TO_BE32(start/cyl); partition->de_HighCyl = PED_CPU_TO_BE32((end+1)/cyl-1); partition->de_NumBuffers = PED_CPU_TO_BE32(30); partition->de_BufMemType = PED_CPU_TO_BE32(0); partition->de_MaxTransfer = PED_CPU_TO_BE32(0x7fffffff); partition->de_Mask = PED_CPU_TO_BE32(0xffffffff); partition->de_BootPri = PED_CPU_TO_BE32(0); partition->de_DosType = PED_CPU_TO_BE32(0x4c4e5800); partition->de_Baud = PED_CPU_TO_BE32(0); partition->de_Control = PED_CPU_TO_BE32(0); partition->de_BootBlocks = PED_CPU_TO_BE32(0); } else { part->disk_specific = NULL; } return part; }