本文整理汇总了C++中ped_exception_throw函数的典型用法代码示例。如果您正苦于以下问题:C++ ped_exception_throw函数的具体用法?C++ ped_exception_throw怎么用?C++ ped_exception_throw使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ped_exception_throw函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: command_line_get_fs_type
int
command_line_get_fs_type (const char* prompt, const PedFileSystemType*(* value))
{
char* fs_type_name;
PedFileSystemType* fs_type;
fs_type_name = command_line_get_word (prompt,
*value ? (*value)->name : NULL,
fs_type_list, 1);
if (!fs_type_name) {
ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
_("Expecting a file system type."));
return 0;
}
fs_type = ped_file_system_type_get (fs_type_name);
if (!fs_type) {
ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
_("Unknown file system type \"%s\"."),
fs_type_name);
free (fs_type_name);
return 0;
}
free (fs_type_name);
*value = fs_type;
return 1;
}
示例2: hfs_file_write_sector
/* return 0 on error */
int
hfs_file_write_sector (HfsPrivateFile* file, void *buf, PedSector sector)
{
PedSector abs_sector;
if (sector >= file->sect_nb) {
ped_exception_throw (
PED_EXCEPTION_ERROR,
PED_EXCEPTION_CANCEL,
_("Trying to write HFS file with CNID %X behind EOF."),
PED_BE32_TO_CPU(file->CNID));
return 0;
}
abs_sector = hfs_file_find_sector (file, sector);
if (!abs_sector) {
ped_exception_throw (
PED_EXCEPTION_ERROR,
PED_EXCEPTION_CANCEL,
_("Could not find sector %lli of HFS file with "
"CNID %X."),
sector, PED_BE32_TO_CPU(file->CNID));
return 0;
}
return ped_geometry_write (file->fs->geom, buf, abs_sector, 1);
}
示例3: _generic_apfs_probe
static PedGeometry*
_generic_apfs_probe (PedGeometry* geom, uint32_t kind)
{
uint32_t *block;
PedSector root;
struct PartitionBlock * part;
uint32_t blocksize = 1, reserved = 2;
PED_ASSERT (geom != NULL);
PED_ASSERT (geom->dev != NULL);
if (geom->dev->sector_size != 512)
return NULL;
/* Finds the blocksize and reserved values of the partition block */
if (!(part = ped_malloc (PED_SECTOR_SIZE_DEFAULT*blocksize))) {
ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
_("%s : Failed to allocate partition block\n"), __func__);
goto error_part;
}
if (amiga_find_part(geom, part) != NULL) {
reserved = PED_BE32_TO_CPU (part->de_Reserved);
blocksize = PED_BE32_TO_CPU (part->de_SizeBlock)
* PED_BE32_TO_CPU (part->de_SectorPerBlock) / 128;
}
free (part);
/* Test boot block */
if (!(block = ped_malloc (PED_SECTOR_SIZE_DEFAULT*blocksize))) {
ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
_("%s : Failed to allocate block\n"), __func__);
goto error_block;
}
if (!ped_device_read (geom->dev, block, geom->start, blocksize)) {
ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
_("%s : Couldn't read boot block %llu\n"), __func__, geom->start);
goto error;
}
if (PED_BE32_TO_CPU (block[0]) != kind) {
goto error;
}
/* Find and test the root block */
root = geom->start+reserved*blocksize;
if (!ped_device_read (geom->dev, block, root, blocksize)) {
ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
_("%s : Couldn't read root block %llu\n"), __func__, root);
goto error;
}
if (_apfs_probe_root(block, blocksize, kind) == 1) {
free(block);
return ped_geometry_duplicate (geom);
}
error:
free (block);
error_block:
error_part:
return NULL;
}
示例4: dvh_partition_set_flag
static int
dvh_partition_set_flag (PedPartition* part, PedPartitionFlag flag, int state)
{
DVHDiskData* dvh_disk_data = part->disk->disk_specific;
switch (flag) {
case PED_PARTITION_ROOT:
if (part->type != 0 && state) {
#ifndef DISCOVER_ONLY
ped_exception_throw (
PED_EXCEPTION_ERROR,
PED_EXCEPTION_CANCEL,
_("Only primary partitions can be root "
"partitions."));
#endif
return 0;
}
dvh_disk_data->root = state ? part->num : 0;
break;
case PED_PARTITION_SWAP:
if (part->type != 0 && state) {
#ifndef DISCOVER_ONLY
ped_exception_throw (
PED_EXCEPTION_ERROR,
PED_EXCEPTION_CANCEL,
_("Only primary partitions can be swap "
"partitions."));
return 0;
#endif
}
dvh_disk_data->swap = state ? part->num : 0;
break;
case PED_PARTITION_BOOT:
if (part->type != PED_PARTITION_LOGICAL && state) {
#ifndef DISCOVER_ONLY
ped_exception_throw (
PED_EXCEPTION_ERROR,
PED_EXCEPTION_CANCEL,
_("Only logical partitions can be a boot "
"file."));
#endif
return 0;
}
dvh_disk_data->boot = state ? part->num : 0;
break;
case PED_PARTITION_LVM:
case PED_PARTITION_LBA:
case PED_PARTITION_HIDDEN:
case PED_PARTITION_RAID:
default:
return 0;
}
return 1;
}
示例5: command_line_get_part_type
int
command_line_get_part_type (const char* prompt, const PedDisk* disk,
PedPartitionType* type)
{
StrList* opts = NULL;
char* type_name;
if (_can_create_primary (disk)) {
opts = str_list_append_unique (opts, "primary");
opts = str_list_append_unique (opts, _("primary"));
}
if (_can_create_extended (disk)) {
opts = str_list_append_unique (opts, "extended");
opts = str_list_append_unique (opts, _("extended"));
}
if (_can_create_logical (disk)) {
opts = str_list_append_unique (opts, "logical");
opts = str_list_append_unique (opts, _("logical"));
}
if (!opts) {
ped_exception_throw (
PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
_("Can't create any more partitions."));
return 0;
}
type_name = command_line_get_word (prompt, NULL, opts, 1);
str_list_destroy (opts);
if (!type_name) {
ped_exception_throw (
PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
_("Expecting a partition type."));
return 0;
}
if (!strcmp (type_name, "primary")
|| !strcmp (type_name, _("primary"))) {
*type = 0;
}
if (!strcmp (type_name, "extended")
|| !strcmp (type_name, _("extended"))) {
*type = PED_PARTITION_EXTENDED;
}
if (!strcmp (type_name, "logical")
|| !strcmp (type_name, _("logical"))) {
*type = PED_PARTITION_LOGICAL;
}
free (type_name);
return 1;
}
示例6: _amiga_find_free_blocks
static int
_amiga_find_free_blocks(const PedDisk *disk, uint32_t *table,
struct LinkedBlock *block, uint32_t first, uint32_t type)
{
PedSector next;
PED_ASSERT(disk != NULL);
PED_ASSERT(disk->dev != NULL);
for (next = first; next != LINK_END; next = PED_BE32_TO_CPU(block->lk_Next)) {
if (table[next] != IDNAME_FREE) {
switch (ped_exception_throw(PED_EXCEPTION_ERROR,
PED_EXCEPTION_FIX | PED_EXCEPTION_IGNORE | PED_EXCEPTION_CANCEL,
_("%s : Loop detected at block %d."), __func__, next))
{
case PED_EXCEPTION_CANCEL :
return 0;
case PED_EXCEPTION_FIX :
/* TODO : Need to add fixing code */
case PED_EXCEPTION_IGNORE :
case PED_EXCEPTION_UNHANDLED :
default :
return 1;
}
}
if (!_amiga_read_block (disk->dev, AMIGA(block), next, NULL)) {
return 0;
}
if (PED_BE32_TO_CPU(block->lk_ID) != type) {
switch (ped_exception_throw(PED_EXCEPTION_ERROR,
PED_EXCEPTION_CANCEL,
_("%s : The %s list seems bad at block %s."),
__func__, _amiga_block_id(PED_BE32_TO_CPU(block->lk_ID)), next))
{
/* TODO : to more subtile things here */
case PED_EXCEPTION_CANCEL :
case PED_EXCEPTION_UNHANDLED :
default :
return 0;
}
}
table[next] = type;
if (PED_BE32_TO_CPU(block->lk_ID) == IDNAME_FILESYSHEADER) {
if (_amiga_find_free_blocks(disk, table, block,
PED_BE32_TO_CPU(LNK2(block)->lk2_Linked),
IDNAME_LOADSEG) == 0) return 0;
}
}
return 1;
}
示例7: ped_file_system_open
/**
* This function opens the file system stored on \p geom, if it
* can find one.
* It is often called in the following manner:
* \code
* fs = ped_file_system_open (&part.geom)
* \endcode
*
* \throws PED_EXCEPTION_ERROR if file system could not be detected
* \throws PED_EXCEPTION_ERROR if the file system is bigger than its volume
* \throws PED_EXCEPTION_NO_FEATURE if opening of a file system stored on
* \p geom is not implemented
*
* \return a PedFileSystem on success, \c NULL on failure.
*/
PedFileSystem *
ped_file_system_open (PedGeometry* geom)
{
PED_ASSERT (geom != NULL);
if (!ped_device_open (geom->dev))
goto error;
PedFileSystemType *type = ped_file_system_probe (geom);
if (!type) {
ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
_("Could not detect file system."));
goto error_close_dev;
}
open_fn_t open_f = open_fn (type->name);
if (open_f == NULL) {
ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
_("resizing %s file systems is not supported"),
type->name);
goto error_close_dev;
}
PedGeometry *probed_geom = ped_file_system_probe_specific (type, geom);
if (!probed_geom)
goto error_close_dev;
if (!ped_geometry_test_inside (geom, probed_geom)) {
if (ped_exception_throw (
PED_EXCEPTION_ERROR,
PED_EXCEPTION_IGNORE_CANCEL,
_("The file system is bigger than its volume!"))
!= PED_EXCEPTION_IGNORE)
goto error_destroy_probed_geom;
}
PedFileSystem *fs = (*open_f) (probed_geom);
if (!fs)
goto error_destroy_probed_geom;
ped_geometry_destroy (probed_geom);
fs->type = type;
return fs;
error_destroy_probed_geom:
ped_geometry_destroy (probed_geom);
error_close_dev:
ped_device_close (geom->dev);
error:
return NULL;
}
示例8: dasd_partition_align
static int
dasd_partition_align (PedPartition* part, const PedConstraint* constraint)
{
DasdDiskSpecific* disk_specific;
PED_ASSERT (part != NULL);
disk_specific = part->disk->disk_specific;
/* If formated in LDL, ignore metadata partition */
if (disk_specific->format_type == 1)
return 1;
if (_ped_partition_attempt_align(part, constraint,
_primary_constraint(part->disk)))
return 1;
#ifndef DISCOVER_ONLY
ped_exception_throw (
PED_EXCEPTION_ERROR,
PED_EXCEPTION_CANCEL,
_("Unable to satisfy all constraints on the partition."));
#endif
return 0;
}
示例9: read_next_dir_buffer
static int
read_next_dir_buffer (FatTraverseInfo* trav_info)
{
FatSpecific* fs_info = FAT_SPECIFIC (trav_info->fs);
PED_ASSERT (!trav_info->is_legacy_root_dir);
trav_info->this_buffer = trav_info->next_buffer;
if (trav_info->this_buffer < 2
|| trav_info->this_buffer >= fs_info->cluster_count + 2) {
ped_exception_throw (
PED_EXCEPTION_ERROR,
PED_EXCEPTION_CANCEL,
"Cluster %ld in directory %s is outside file system!",
(long) trav_info->this_buffer,
trav_info->dir_name);
return 0;
}
trav_info->next_buffer
= fat_table_get (fs_info->fat, trav_info->this_buffer);
return fat_read_cluster (trav_info->fs, (void *) trav_info->dir_entries,
trav_info->this_buffer);
}
示例10: ped_unit_get_size
/**
* Get the byte size of a given \p unit.
*/
long long
ped_unit_get_size (const PedDevice* dev, PedUnit unit)
{
PedSector cyl_size = dev->bios_geom.heads * dev->bios_geom.sectors;
switch (unit) {
case PED_UNIT_SECTOR: return dev->sector_size;
case PED_UNIT_BYTE: return 1;
case PED_UNIT_KILOBYTE: return PED_KILOBYTE_SIZE;
case PED_UNIT_MEGABYTE: return PED_MEGABYTE_SIZE;
case PED_UNIT_GIGABYTE: return PED_GIGABYTE_SIZE;
case PED_UNIT_TERABYTE: return PED_TERABYTE_SIZE;
case PED_UNIT_KIBIBYTE: return PED_KIBIBYTE_SIZE;
case PED_UNIT_MEBIBYTE: return PED_MEBIBYTE_SIZE;
case PED_UNIT_GIBIBYTE: return PED_GIBIBYTE_SIZE;
case PED_UNIT_TEBIBYTE: return PED_TEBIBYTE_SIZE;
case PED_UNIT_CYLINDER: return cyl_size * dev->sector_size;
case PED_UNIT_CHS: return dev->sector_size;
case PED_UNIT_PERCENT:
return dev->length * dev->sector_size / 100;
case PED_UNIT_COMPACT:
ped_exception_throw (
PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
_("Cannot get unit size for special unit "
"'COMPACT'."));
return 0;
}
/* never reached */
PED_ASSERT(0);
return 0;
}
示例11: command_line_get_part_flag
int
command_line_get_part_flag (const char* prompt, const PedPartition* part,
PedPartitionFlag* flag)
{
StrList* opts = NULL;
PedPartitionFlag walk = 0;
char* flag_name;
while ( (walk = ped_partition_flag_next (walk)) ) {
if (ped_partition_is_flag_available (part, walk)) {
const char* walk_name;
walk_name = ped_partition_flag_get_name (walk);
opts = str_list_append (opts, walk_name);
opts = str_list_append_unique (opts, _(walk_name));
}
}
if (opts == NULL)
{
ped_exception_throw (PED_EXCEPTION_ERROR,
PED_EXCEPTION_OK,
_("No flags supported"));
return 0;
}
flag_name = command_line_get_word (prompt, NULL, opts, 1);
str_list_destroy (opts);
if (flag_name) {
*flag = ped_partition_flag_get_by_name (flag_name);
free (flag_name);
return 1;
} else
return 0;
}
示例12: vtoc_error
static void
vtoc_error (enum failure why, char const *s1, char const *s2)
{
PDEBUG
char error[8192];
switch (why) {
case unable_to_open:
sprintf(error, "VTOC: %s -- %s\n%s\n",
_("opening of device failed"), s1, s2);
break;
case unable_to_seek:
sprintf(error, "VTOC: %s -- %s\n%s\n",
_("seeking on device failed"), s1, s2);
break;
case unable_to_write:
sprintf(error, "VTOC: %s -- %s\n%s\n",
_("writing to device failed"), s1, s2);
break;
case unable_to_read:
sprintf(error, "VTOC: %s -- %s\n%s\n",
_("reading from device failed"), s1, s2);
break;
default:
sprintf(error, "VTOC: %s\n", _("Fatal error"));
}
ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, error);
}
示例13: dasd_probe
static int
dasd_probe (const PedDevice *dev)
{
LinuxSpecific* arch_specific;
struct fdasd_anchor anchor;
PED_ASSERT(dev != NULL);
arch_specific = LINUX_SPECIFIC(dev);
/* add partition test here */
fdasd_initialize_anchor(&anchor);
if (fdasd_get_geometry(dev, &anchor, arch_specific->fd) == 0)
goto error_cleanup;
/* Labels are required on CDL formatted DASDs. */
if (fdasd_check_volume(&anchor, arch_specific->fd) &&
anchor.FBA_layout == 0)
goto error_cleanup;
fdasd_cleanup(&anchor);
return 1;
error_cleanup:
fdasd_cleanup(&anchor);
ped_exception_throw(PED_EXCEPTION_ERROR,PED_EXCEPTION_IGNORE_CANCEL,
"Error while probing device %s.", dev->path);
return 0;
}
示例14: ped_assert
/*
* Check an assertion.
* Do not call this directly -- use PED_ASSERT() instead.
*/
void ped_assert (const char* cond_text,
const char* file, int line, const char* function)
{
#if HAVE_BACKTRACE
/* Print backtrace stack */
void *stack[20];
char **strings, **string;
int size = backtrace(stack, 20);
strings = backtrace_symbols(stack, size);
if (strings) {
printf(_("Backtrace has %d calls on stack:\n"), size);
for (string = strings; size > 0; size--, string++)
printf(" %d: %s\n", size, *string);
free(strings);
}
#endif
/* Throw the exception */
ped_exception_throw (
PED_EXCEPTION_BUG,
PED_EXCEPTION_FATAL,
_("Assertion (%s) at %s:%d in function %s() failed."),
cond_text, file, line, function);
abort ();
}
示例15: _amiga_read_block
static struct AmigaBlock *
_amiga_read_block (const PedDevice *dev, struct AmigaBlock *blk,
PedSector block, struct AmigaIds *ids)
{
if (!ped_device_read (dev, blk, block, 1))
return NULL;
if (ids && !_amiga_id_in_list(PED_BE32_TO_CPU(blk->amiga_ID), ids))
return NULL;
if (_amiga_checksum (blk) != 0) {
switch (ped_exception_throw(PED_EXCEPTION_ERROR,
PED_EXCEPTION_FIX | PED_EXCEPTION_IGNORE | PED_EXCEPTION_CANCEL,
_("%s : Bad checksum on block %llu of type %s."),
__func__, block, _amiga_block_id(PED_BE32_TO_CPU(blk->amiga_ID))))
{
case PED_EXCEPTION_CANCEL :
return NULL;
case PED_EXCEPTION_FIX :
_amiga_calculate_checksum(AMIGA(blk));
if (!ped_device_write ((PedDevice*)dev, blk, block, 1))
return NULL;
case PED_EXCEPTION_IGNORE :
case PED_EXCEPTION_UNHANDLED :
default :
return blk;
}
}
return blk;
}