PyObject *py_ped_unit_format(PyObject *s, PyObject *args) { PyObject *ret = NULL; char *pedret = NULL; PedDevice *out_dev = NULL; PedSector sector; if (!PyArg_ParseTuple(args, "L", §or)) { return NULL; } out_dev = _ped_Device2PedDevice(s); if (out_dev == NULL) { return NULL; } pedret = ped_unit_format(out_dev, sector); if (pedret != NULL) { ret = PyUnicode_FromString(pedret); free(pedret); } else { ret = PyUnicode_FromString(""); } return ret; }
int fat_check_resize_geometry (const PedFileSystem* fs, const PedGeometry* geom, PedSector new_cluster_sectors, FatCluster new_cluster_count) { FatSpecific* fs_info = FAT_SPECIFIC (fs); PedSector free_space; PedSector min_free_space; PedSector total_space; PedSector new_total_space; PedSector dir_space; PED_ASSERT (geom != NULL); dir_space = fs_info->total_dir_clusters * fs_info->cluster_sectors; free_space = fs_info->fat->free_cluster_count * fs_info->cluster_sectors; total_space = fs_info->fat->cluster_count * fs_info->cluster_sectors; new_total_space = new_cluster_count * new_cluster_sectors; min_free_space = total_space - new_total_space + dir_space; PED_ASSERT (new_cluster_count <= fat_max_cluster_count (FAT_TYPE_FAT32)); if (free_space < min_free_space) { char* needed = ped_unit_format (geom->dev, min_free_space); char* have = ped_unit_format (geom->dev, free_space); ped_exception_throw ( PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, _("You need %s of free disk space to shrink this " "partition to this size. Currently, only %s is " "free."), needed, have); free (needed); free (have); return 0; } return 1; }
int command_line_get_sector (const char* prompt, PedDevice* dev, PedSector* value, PedGeometry** range, char** raw_input) { char* def_str; char* input; int valid; def_str = ped_unit_format (dev, *value); input = command_line_get_word (prompt, *value ? def_str : NULL, NULL, 1); /* def_str might have rounded *value a little bit. If the user picked * the default, make sure the selected sector is identical to the * default. */ if (input && *value && !strcmp (input, def_str)) { if (range) { *range = ped_geometry_new (dev, *value, 1); free (def_str); free (input); return *range != NULL; } free (def_str); free (input); return 1; } free (def_str); if (!input) { *value = 0; if (range) *range = NULL; return 0; } valid = ped_unit_parse (input, dev, value, range); if (raw_input) *raw_input = input; else free (input); return valid; }
int main (int argc, char* argv[]) { PedDevice* device = NULL; PedDisk* disk = NULL; PedDiskType* type = NULL; PedPartition* part = NULL; int return_code = EXIT_FAILURE; if (argc != 2){ printf("wrong number of arguments\n"); return EXIT_FAILURE; } device = ped_device_get (argv[1]); printf("device:%s\n",argv[1]); if (device == NULL) goto error_exit; type = ped_disk_probe (device); if (type == NULL) goto error_destroy_device; printf("Disk Type:%s\n",type->name); disk = ped_disk_new (device); if (disk == NULL) goto error_destroy_device; do { part = ped_disk_next_partition (disk, part); if ((part != NULL) && (part->num > -1)){ printf("%d %s %s\n",part->num,ped_partition_type_get_name(part->type),ped_unit_format (device,part->geom.length)); } }while( part ); ped_disk_destroy (disk); return_code = EXIT_SUCCESS; // Fall through to clean up error_destroy_device: ped_device_destroy (device); error_exit: return return_code; }