PyObject *py_ped_device_get_next(PyObject *s, PyObject *args) { PyObject *in_device = NULL; PedDevice *cur = NULL, *next = NULL; _ped_Device *ret = NULL; if (!PyArg_ParseTuple(args, "|O!", &_ped_Device_Type_obj, &in_device)) { return NULL; } if (in_device) { cur = _ped_Device2PedDevice(in_device); if (!cur) { return NULL; } } next = ped_device_get_next(cur); if (next) { ret = PedDevice2_ped_Device(next); return (PyObject *) ret; } else { PyErr_SetNone(PyExc_IndexError); return NULL; } }
int main(int argc, char* argv[]) { PedDevice *device = NULL; PedDisk *disk = NULL; ped_device_probe_all (); if (argc != 2) { while ((device = ped_device_get_next (device))) { char* esp = query_esp_path_by_disk(device->path); if (esp != NULL) { g_message("[%s] ESP: %s, path: %s\n", __func__, esp, device->path); return 0; } } } else { const char* disk_path = (argv[1]); char* esp = query_esp_path_by_disk(disk_path); if (esp != NULL) { g_message("[%s] ESP: %s, at: %s\n", __func__, esp, argv[1]); return 0; } } g_message("[%s] No ESP found\n", __func__); return 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 nwipe_device_scan( nwipe_context_t*** c ) { /** * Scans the the filesystem for storage device names. * * @parameter device_names A reference to a null array pointer. * @modifies device_names Populates device_names with an array of nwipe_contect_t * @returns The number of strings in the device_names array. * */ PedDevice* dev = NULL; ped_device_probe_all(); int dcount = 0; while ((dev = ped_device_get_next (dev))) { if (check_device(c, dev, dcount)) dcount++; } /* Return the number of devices that were found. */ return dcount; } /* nwipe_device_scan */
int main (void) { PedDevice* device = NULL; ped_device_probe_all (); while ((device = ped_device_get_next(device))) puts (device->path); return 0 ; }
int detect_parts(int noswap) { PedDevice *dev = NULL; PedDisk *disk = NULL; if(parts) { g_list_free(parts); parts = NULL; } if(partschk) { g_list_free(partschk); partschk = NULL; } ped_device_free_all(); chdir("/"); ped_exception_set_handler(peh); ped_device_probe_all(); if(ped_device_get_next(NULL)==NULL) // no disk detected already handled before, no need to inform // the user about this return(1); for(dev=ped_device_get_next(NULL);dev!=NULL;dev=dev->next) { if(dev->read_only) // we don't want to partition cds ;-) continue; disk = ped_disk_new(dev); if(disk) listparts(disk, noswap); } // software raids detect_raids(); return(0); }
int main() { PedDevice *dev = NULL; PedDisk *disk = NULL; //char *dev_name = NULL; //int nb_try = 0; ped_device_probe_all(); if(ped_device_get_next(NULL)==NULL) { printf("no disk detected? :/\n"); return(1); } for(dev=ped_device_get_next(NULL);dev!=NULL;dev=dev->next) { printf("%s, %s, %dGB\n", dev->path, dev->model, dev->length/1953125); } return(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; }
/*********************************************************** * class Devices Implementation ***********************************************************/ Devices::Devices() { ped_device_probe_all(); PedDevice* ped_dev = NULL; while ( (ped_dev = ped_device_get_next(ped_dev)) ) { Device* dev = new Device(ped_dev); if (!dev->parttable()) { //delete dev; continue; } list_dev_.push_back(dev); } }
int main() { PedDevice *dev = NULL; ped_device_probe_all(); while((dev=ped_device_get_next(dev))) { printf("\n------------------------------\n"); printf("Name: %s\n", dev->path); printf("Model: %s\n", dev->model); printf("Capacity: %lld\n", dev->sector_size * dev->length); printf("Type: %d\n", dev->type); } }
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; }
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; }
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; }
void MParted::MParted_Core::scan(MParted::Devices & devices) { QMutexLocker locker(&mutex); // Clean up first devices.clear(); // Initialise QStringList devicePaths; ped_device_probe_all(); pedDevice = NULL; while ((pedDevice = ped_device_get_next(pedDevice))) { // Only add this device if we can read the first sector (which means it's a real device) char * buf = static_cast<char *>(malloc(pedDevice->sector_size)); if (buf) { // Confirming device if (ped_device_open(pedDevice)) { //Devices with sector sizes of 512 bytes and higher are supported if (ped_device_read(pedDevice, buf, 0, 1)) devicePaths.append(Utils::charToString(pedDevice->path)); ped_device_close(pedDevice) ; } free(buf); } } closeDeviceAndDisk(); // Sort list, remove duplicates and empty entries devicePaths.removeDuplicates(); devicePaths.removeAll(""); devicePaths.sort(); for (int i = 0; i < devicePaths.size(); i++) { const QString devicePath = devicePaths.at(i); // Open device and disk if (!openDeviceAndDisk(devicePath, false)) continue; // Add to list and save pointer devices.append(MParted::Device()); MParted::Device &device = devices.last(); //device info.. device.path = devicePath; device.model = Utils::charToString(pedDevice->model); device.length = pedDevice->length; device.sector_size = pedDevice->sector_size; device.heads = pedDevice->bios_geom.heads; device.sectors = pedDevice->bios_geom.sectors; device.cylinders = pedDevice->bios_geom.cylinders; device.cylsize = device.heads * device.sectors; device.removable = isDeviceRemovable(device); //make sure cylsize is at least 1 MiB if (device.cylsize < (MEBIBYTE / device.sector_size)) device.cylsize = (MEBIBYTE / device.sector_size); //normal harddisk if (pedDisk) { device.unkownPartitionTable = false; device.diskType = Utils::charToString(pedDisk->type->name); device.maxPrimaryPartitions = ped_disk_get_max_primary_partition_count(pedDisk); // Scan partitions scanDevicePartitions(device); } //harddisk without disklabel else { device.unkownPartitionTable = true; device.diskType = QObject::tr("unrecognized"); device.maxPrimaryPartitions = -1; } // Clean up closeDeviceAndDisk(); } }
void SystemPartitioner::init() { #if NONDESTRUCTIVE emit done(); return; #endif // Check # of harddisks to see if RAID0-ing them makes any sense ped_device_probe_all(); PedDevice *tmp=NULL; int disks=0; QString installsource(getenv("INSTALLSOURCE")); MSG("Install source is " + installsource); while((tmp=ped_device_get_next(tmp))) { // FIXME workaround for parted breakage // Skip CD-ROMs parted accidentally marks as harddisk QString p(tmp->path); if(!p.startsWith("/dev/sd") && (p.contains("/dev/scd") || p.contains("/dev/sr") || access(QFile::encodeName("/proc/ide/" + p.section('/', 2, 2) + "/cache"), R_OK))) continue; // It's not a good idea to install on a USB stick we're installing from... if(installsource.startsWith(p)) continue; MSG(QString("Found disk: ") + QString(tmp->path) + ":" + "/proc/ide/" + p.section('/', 2, 2) + "/" + "cache" + ":" + QString::number(access(QFile::encodeName("/proc/ide/" + p.section('/', 2, 2) + "/cache"), R_OK))); #if 0 // Check if the drive is actually there -- some empty CF // readers misidentify themselves... int fd=open(tmp->path, O_RDONLY); if(fd < 0) continue; char test; if(read(fd, &test, 1) <= 0) { close(fd); continue; } close(fd); #endif disks++; } ped_device_free_all(); // Grab all disks ped_device_probe_all(); PedFileSystemType const *ext3=ped_file_system_type_get("ext2"); // parted doesn't support ext3 creation yet, so we need this hack PedFileSystemType const *bootext3=ped_file_system_type_get("ext2"); PedFileSystemType const *swap=ped_file_system_type_get("linux-swap"); Meminfo m; unsigned long long swapsize=m.suggested_swap(); QStringList raidPartitions; PedDevice *dev=NULL; PedPartition *fspart=NULL; PedGeometry *fsgeo=NULL; setHelp(tr("Removing other OSes...")); resizeEvent(0); uint32_t bootsize=0; #ifndef NO_RAID0 if(disks>1) bootsize=32*1024*2; /* size is in 512 kB blocks --> we use 32 MB */ #endif while((dev=ped_device_get_next(dev))) { // FIXME workaround for parted breakage QString p(dev->path); if(!p.startsWith("/dev/sd") && (p.contains("/dev/scd") || p.contains("/dev/sr") || access(QFile::encodeName("/proc/ide/" + p.section('/', 2, 2) + "/cache"), R_OK))) continue; // It's not a good idea to install on a USB stick we're installing from... if(installsource.startsWith(p)) continue; //unsigned long long disksize=dev->length*dev->sector_size; PedDiskType *type=ped_disk_type_get("msdos"); PedDisk *disk=ped_disk_new_fresh(dev, type); PedGeometry *part=ped_geometry_new(dev, 0, dev->length); if(swapsize && _swap.isEmpty() && ((unsigned long long)part->length > swapsize + bootsize)) { // Split disk in swap and fs partitions PedGeometry *swapgeo=ped_geometry_new(dev, 0, swapsize); PedGeometry *bootgeo=NULL; uint32_t fssize=part->end - swapsize; uint32_t fsstart=swapsize+1; if(bootsize) { bootgeo=ped_geometry_new(dev, swapsize+1, bootsize); fssize -= bootsize; fsstart += bootsize; } fsgeo=ped_geometry_new(dev, fsstart, fssize); PedPartition *swappart=ped_partition_new(disk, (PedPartitionType)0, swap, swapgeo->start, swapgeo->end); PedPartition *bootpart=NULL; if(bootsize) bootpart=ped_partition_new(disk, (PedPartitionType)0, bootext3, bootgeo->start, bootgeo->end); fspart=ped_partition_new(disk, (PedPartitionType)0, ext3, fsgeo->start, fsgeo->end); if(bootsize) ped_partition_set_flag(fspart, PED_PARTITION_RAID, 1); ped_disk_add_partition(disk, swappart, ped_constraint_any(dev)); ped_disk_commit(disk); ped_geometry_destroy(swapgeo); setHelp(tr("Creating swap filesystem")); PedFileSystem *swapfs=ped_file_system_create(&(swappart->geom), swap, NULL /*timer->timer()*/); ped_file_system_close(swapfs); _swap = dev->path + QString::number(swappart->num); // Parted's swap creator is buggy QProcess::execute("/sbin/mkswap " + _swap); if(bootpart) { setHelp(tr("Creating boot filesystem")); ped_disk_add_partition(disk, bootpart, ped_constraint_any(dev)); ped_disk_commit(disk); PedFileSystem *bootfs=ped_file_system_create(&(bootpart->geom), bootext3, timer->timer()); ped_file_system_close(bootfs); ped_partition_set_flag(bootpart, PED_PARTITION_BOOT, 1); ped_geometry_destroy(bootgeo); QString devname=dev->path + QString::number(bootpart->num); _size.insert(devname, bootpart->geom.length); if(_rootfs == "ext3") { Ext3FS e3(devname); e3.addJournal(0); e3.setCheckInterval(0); e3.setCheckMountcount(-1); e3.setDirIndex(); } else { QProcess::execute("/sbin/mkfs." + _rootfs + " " + _mkfsopts + " " + devname); } if(!_postmkfs.isEmpty()) QProcess::execute(_postmkfs + " " + devname); _partitions.insert(devname, FileSystem("/boot", _rootfs)); } } else { // Grab the whole disk for filesystem fsgeo=ped_constraint_solve_max(ped_constraint_any(dev)); fspart=ped_partition_new(disk, (PedPartitionType)0, ext3, part->start, part->end); if(bootsize) ped_partition_set_flag(fspart, PED_PARTITION_RAID, 1); } ped_disk_add_partition(disk, fspart, ped_constraint_any(dev)); if(!bootsize) ped_partition_set_flag(fspart, PED_PARTITION_BOOT, 1); ped_disk_commit(disk); if(!bootsize) { setHelp(tr("Creating Linux filesystem")); PedFileSystem *fs=ped_file_system_create(&(fspart->geom), ext3, timer->timer()); _totalSize += fspart->geom.length; ped_file_system_close(fs); } ped_geometry_destroy(fsgeo); // Convert to ext3 and turn off checking QString devname=dev->path + QString::number(fspart->num); if(bootsize) raidPartitions.append(devname); else if(!_partitions.hasMountpoint("/")) _partitions.insert(devname, FileSystem("/", _rootfs)); else { QString mp(devname); mp.replace("/dev", "/mnt"); _partitions.insert(devname, FileSystem(mp, _rootfs)); } _size.insert(devname, fspart->geom.length); if(!bootsize) { if(_rootfs == "ext3") { Ext3FS e3(devname); e3.addJournal(0); e3.setCheckInterval(0); e3.setCheckMountcount(-1); e3.setDirIndex(); } else { QProcess::execute("/sbin/mkfs." + _rootfs + " " + _mkfsopts + " " + devname); } if(!_postmkfs.isEmpty()) QProcess::execute(_postmkfs + " " + devname); ped_disk_destroy(disk); } } if(bootsize) { setHelp(tr("Combining disks...")); // Make sure we can read the array we're building first... Modules::instance()->loadWithDeps("md"); Modules::instance()->loadWithDeps("raid0"); // Now create it FILE *f=fopen("/tmp/mdadm.conf", "w"); if(!f) QMessageBox::information(0, "debug", QString("Failed to create mdadm.conf: ") + strerror(errno)); fprintf(f, "DEVICE partitions"); fprintf(f, "ARRAY /dev/md0 name=ArkLinux devices=%s level=0 num-devices=%u\n", qPrintable(raidPartitions.join(",")), raidPartitions.count()); fprintf(f, "MAILADDR root@localhost\n"); fclose(f); QString command="/sbin/mdadm --create -e 1.2 --chunk=32 --level=0 --raid-devices=" + QString::number(raidPartitions.count()) + " --name=ArkLinux --force /dev/md0 " + raidPartitions.join(" "); QProcess::execute(command); if(_rootfs == "ext3") { QProcess::execute("/sbin/mke2fs -j /dev/md0"); Ext3FS e3("/dev/md0"); e3.setCheckInterval(0); e3.setCheckMountcount(-1); e3.setDirIndex(); } else { QProcess::execute("/sbin/mkfs." + _rootfs + " " + _mkfsopts + " /dev/md0"); } if(!_postmkfs.isEmpty()) QProcess::execute(_postmkfs + " /dev/md0"); _partitions.insert("/dev/md0", FileSystem("/", _rootfs)); _size.clear(); _size.insert("/dev/md0", _totalSize); } // We don't need a UI to take the whole system - we're done. emit done(); }
int get_all_partitions(struct partition *parts[], const int max_parts, bool ignore_fs_type, PedPartitionFlag require_flag) { struct partition *p; int part_count = 0; PedDevice *dev = NULL; PedDisk *disk; PedPartition *part; ped_device_probe_all(); while ((dev = ped_device_get_next(dev)) != NULL) { if (dev->read_only) continue; if (strstr(dev->path, "/dev/mtd") == dev->path) continue; if (!ped_disk_probe(dev)) continue; disk = ped_disk_new(dev); part = NULL; while ((part = ped_disk_next_partition(disk, part)) != NULL) { if (part->type & (PED_PARTITION_METADATA | PED_PARTITION_FREESPACE | PED_PARTITION_EXTENDED)) continue; if (part_count >= max_parts) break; #ifndef FIND_PARTS_MAIN /* allow other udebs to block partitions */ if(block_partition(ped_partition_get_path(part)) != 0) continue; #endif if (require_flag && !ped_partition_get_flag(part, require_flag)) continue; p = malloc(sizeof(*p)); p->path = ped_partition_get_path(part); if (strstr(p->path, "/dev/hd") == p->path) { static char *targets[] = { "master", "slave" }; char drive; int part; if (sscanf(p->path, "/dev/hd%c%d", &drive, &part) == 2 && drive >= 'a' && drive <= 'z') asprintf(&p->description, "IDE%d %s\\, part. %d", (drive - 'a') / 2 + 1, targets[(drive - 'a') % 2], part); else p->description = strdup(p->path); } else if (strstr(p->path, "/dev/sd") == p->path) { char drive; int host, bus, target, lun, part; int done = 0; if (sscanf(p->path, "/dev/sd%c%d", &drive, &part) == 2 && drive >= 'a' && drive <= 'z') { struct stat st; char *disk, *disk_pos, *sys_device; disk = strdup(p->path + 5); for (disk_pos = disk + strlen(disk) - 1; disk_pos > disk; --disk_pos) { if (*disk_pos >= '0' && *disk_pos <= '9') *disk_pos = 0; else break; } sys_device = malloc(strlen(disk) + 19); sprintf(sys_device, "/sys/block/%s/device", disk); /* TODO: device symlinks are allegedly slated to go * away, but it's not entirely clear what their * replacement will be yet ... */ if (lstat(sys_device, &st) == 0 && S_ISLNK(st.st_mode)) { char buf[512]; memset(buf, 0, 512); if (readlink(sys_device, buf, 511) > 0) { const char *bus_id = basename(buf); if (sscanf(bus_id, "%d:%d:%d:%d", &host, &bus, &target, &lun) == 4) { asprintf(&p->description, "SCSI%d (%d\\,%d\\,%d) part. %d", host + 1, bus, target, lun, part); done = 1; } } } } if (!done) p->description = strdup(p->path); } else p->description = strdup(p->path); p->fstype = NULL; p->fsid = NULL; p->size = 0L; p->op.filesystem = NULL; p->op.mountpoint = NULL; p->op.done = 0; test_lvm(p); test_evms(p); test_raid(p); /* FIXME: Other tests? */ get_partition_info(p, part, dev, ignore_fs_type); parts[part_count++] = p; } if (part_count >= max_parts) break; } return part_count; }
{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0} }; static int dodgy_memory_active[100]; #endif /* DEBUG */ int ped_set_architecture (const PedArchitecture* arch) { PED_ASSERT (ped_device_get_next (NULL) == NULL, return 0); ped_architecture = arch; return 1; } extern void ped_disk_aix_init (); extern void ped_disk_bsd_init (); extern void ped_disk_dvh_init (); extern void ped_disk_gpt_init (); extern void ped_disk_loop_init (); extern void ped_disk_mac_init (); extern void ped_disk_msdos_init (); extern void ped_disk_pc98_init (); extern void ped_disk_sun_init (); extern void ped_disk_amiga_init ();