Ejemplo n.º 1
0
Archivo: ui.c Proyecto: bcl/parted
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;
}
Ejemplo n.º 2
0
/* 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);
}
Ejemplo n.º 3
0
static int reiserfs_ops_interface_version_check(void)
{
	int min_interface_version, max_interface_version;
	int (*libreiserfs_get_max_interface_version) (void);
	int (*libreiserfs_get_min_interface_version) (void);

	INIT_SYM(libreiserfs_get_max_interface_version);
	INIT_SYM(libreiserfs_get_min_interface_version);

	if (!libreiserfs_get_min_interface_version ||
	    !libreiserfs_get_max_interface_version) {
		ped_exception_throw(
			PED_EXCEPTION_WARNING, PED_EXCEPTION_CANCEL,
			_("GNU Parted found an invalid libreiserfs library."));
		return 0;
	}

	min_interface_version = libreiserfs_get_min_interface_version();
	max_interface_version = libreiserfs_get_max_interface_version();

	if (REISERFS_API_VERSION < min_interface_version ||
	    REISERFS_API_VERSION > max_interface_version) {
		ped_exception_throw(
			PED_EXCEPTION_WARNING, PED_EXCEPTION_CANCEL,
			_("GNU Parted has detected libreiserfs interface "
			  "version mismatch.  Found %d-%d, required %d. "
			  "ReiserFS support will be disabled."),
			min_interface_version,
			max_interface_version,
			REISERFS_API_VERSION);
		return 0;
	}

	return 1;
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
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;
}
Ejemplo n.º 6
0
Archivo: ui.c Proyecto: bcl/parted
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;
}
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 8
0
/**
 * 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;
}
Ejemplo n.º 9
0
Archivo: dasd.c Proyecto: bcl/parted
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;
}
Ejemplo n.º 10
0
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);
}
Ejemplo n.º 11
0
Archivo: unit.c Proyecto: Excito/parted
/**
 * 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;
}
Ejemplo n.º 12
0
Archivo: ui.c Proyecto: bcl/parted
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;
}
Ejemplo n.º 13
0
Archivo: vtoc.c Proyecto: Excito/parted
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);
}
Ejemplo n.º 14
0
Archivo: dasd.c Proyecto: bcl/parted
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;
}
Ejemplo n.º 15
0
static HfsCPrivateCache*
hfsplus_cache_extents(PedFileSystem* fs, PedTimer* timer)
{
	HfsPPrivateFSData*	priv_data = (HfsPPrivateFSData*)
						fs->type_specific;
	HfsCPrivateCache*	ret;
	unsigned int		file_number, block_number;

	file_number = PED_BE32_TO_CPU(priv_data->vh->file_count);
	block_number = PED_BE32_TO_CPU(priv_data->vh->total_blocks);
	ret = hfsc_new_cache(block_number, file_number);
	if (!ret) return NULL;

	if (!hfsplus_cache_from_vh(ret, fs, timer) ||
	    !hfsplus_cache_from_catalog(ret, fs, timer) ||
	    !hfsplus_cache_from_extent(ret, fs, timer) ||
	    !hfsplus_cache_from_attributes(ret, fs, timer)) {
		ped_exception_throw(
			PED_EXCEPTION_ERROR,
			PED_EXCEPTION_CANCEL,
			_("Could not cache the file system in memory."));
		hfsc_delete_cache(ret);
		return NULL;
	}

	return ret;
}
Ejemplo n.º 16
0
/*
 * 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 ();
}
Ejemplo n.º 17
0
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;
}
Ejemplo n.º 18
0
static int
amiga_partition_enumerate (PedPartition* part)
{
	int i;
	PedPartition* p;

	PED_ASSERT (part != NULL);
	PED_ASSERT (part->disk != NULL);

	/* never change the partition numbers */
	if (part->num != -1)
		return 1;
	for (i = 1; i <= AMIGA_MAX_PARTITIONS; i++) {
		p = ped_disk_get_partition (part->disk, i);
		if (!p) {
			part->num = i;
			return 1;
		}
	}

	/* failed to allocate a number */
#ifndef DISCOVER_ONLY
	ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
		_("Unable to allocate a partition number."));
#endif
	return 0;
}
Ejemplo n.º 19
0
/* Reads in the boot sector (superblock), and does a minimum of sanity
 * checking.  The goals are:
 *	- to detect fat file systems, even if they are damaged [i.e. not
 * return an error / throw an exception]
 *	- to fail detection if there's not enough information for
 * fat_boot_sector_probe_type() to work (or possibly crash on a divide-by-zero)
 */
int
fat_boot_sector_read (FatBootSector** bsp, const PedGeometry *geom)
{
	PED_ASSERT (bsp != NULL);
	PED_ASSERT (geom != NULL);

	if (!ped_geometry_read_alloc (geom, (void **)bsp, 0, 1))
		return 0;
	FatBootSector *bs = *bsp;
	if (PED_LE16_TO_CPU (bs->boot_sign) != 0xAA55) {
		ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
			_("File system has an invalid signature for a FAT "
			  "file system."));
		return 0;
	}

	if (!bs->sector_size
            || PED_LE16_TO_CPU (bs->sector_size) % PED_SECTOR_SIZE_DEFAULT) {
		ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
			_("File system has an invalid sector size for a FAT "
			  "file system."));
		return 0;
	}

	if (!bs->cluster_size) {
		ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
			_("File system has an invalid cluster size for a FAT "
			  "file system."));
		return 0;
	}

	if (!bs->reserved) {
		ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
			_("File system has an invalid number of reserved "
			  "sectors for a FAT file system."));
		return 0;
	}

	if (bs->fats < 1 || bs->fats > 4) {
		ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
			_("File system has an invalid number of FATs."));
		return 0;
	}

	return 1;
}
Ejemplo n.º 20
0
Archivo: aix.c Proyecto: Excito/parted
static PedPartition*
aix_partition_duplicate (const PedPartition* part)
{
        ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
                             PED_EXCEPTION_CANCEL,
                             _("Support for duplicating partitions in AIX "
                               "disk labels is not implemented yet."));
        return NULL;
}
Ejemplo n.º 21
0
Archivo: aix.c Proyecto: Excito/parted
static int
aix_write (const PedDisk* disk)
{
        ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
                             PED_EXCEPTION_CANCEL,
                             _("Support for writing AIX disk labels is "
                               "is not implemented yet."));
	return 0;
}
Ejemplo n.º 22
0
Archivo: aix.c Proyecto: Excito/parted
static int
aix_partition_set_system (PedPartition* part, const PedFileSystemType* fs_type)
{
        ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
                             PED_EXCEPTION_CANCEL,
                             _("Support for setting system type of partitions "
                               "in AIX disk labels is not implemented yet."));
	return 0;
}
Ejemplo n.º 23
0
Archivo: aix.c Proyecto: Excito/parted
static int
aix_partition_set_flag (PedPartition* part, PedPartitionFlag flag, int state)
{
        ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
                             PED_EXCEPTION_CANCEL,
                             _("Support for setting flags "
                               "in AIX disk labels is not implemented yet."));
        return 0;
}
Ejemplo n.º 24
0
Archivo: ui.c Proyecto: bcl/parted
int
command_line_get_partition (const char* prompt, PedDisk* disk,
                            PedPartition** value)
{
        PedPartition*    part;
        int ret;

        /* Flawed logic, doesn't seem to work?!
        check = ped_disk_next_partition (disk, part);
        part  = ped_disk_next_partition (disk, check);

        if (part == NULL) {

        *value = check;
        printf (_("The (only) primary partition has "
                  "been automatically selected\n"));
        return 1;

        } else {
        */
        int num = (*value) ? (*value)->num : 0;

        ret = command_line_get_integer (prompt, &num);
        if ((!ret) || (num < 0)) {
                ped_exception_throw (PED_EXCEPTION_ERROR,
                                     PED_EXCEPTION_CANCEL,
                                     _("Expecting a partition number."));
                return 0;
        }

        part = ped_disk_get_partition (disk, num);

        if (!part) {
                ped_exception_throw (PED_EXCEPTION_ERROR,
                                     PED_EXCEPTION_CANCEL,
                                     _("Partition doesn't exist."));
            return 0;
        }

        *value = part;
        return 1;
        //}
}
Ejemplo n.º 25
0
Archivo: aix.c Proyecto: Excito/parted
static int
aix_read (PedDisk* disk)
{
	ped_disk_delete_all (disk);
        ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
                             PED_EXCEPTION_CANCEL,
                             _("Support for reading AIX disk labels is "
                               "is not implemented yet."));
        return 0;
}
Ejemplo n.º 26
0
static int exception_handler(reiserfs_exception_t *exception)
{
	int ex_type = libreiserfs_exception_type(exception);
	int ex_option = libreiserfs_exception_option(exception);
	char *ex_message = libreiserfs_exception_message(exception);

	return ped_exception_throw (extype_libreiserfs_to_parted (ex_type),
				    exopt_libreiserfs_to_parted (ex_option),
				    ex_message);
}
Ejemplo n.º 27
0
Archivo: aix.c Proyecto: Excito/parted
static PedPartition*
aix_partition_new (const PedDisk* disk, PedPartitionType part_type,
		   const PedFileSystemType* fs_type,
		   PedSector start, PedSector end)
{
        ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
                             PED_EXCEPTION_CANCEL,
                             _("Support for adding partitions to AIX disk "
                               "labels is not implemented yet."));
        return NULL;
}
Ejemplo n.º 28
0
static int
beos_open (PedDevice* dev)
{
	BEOSSpecific* arch_specific = BEOS_SPECIFIC(dev);

retry:
	arch_specific->fd = open(dev->path, O_RDWR);
	if (arch_specific->fd == -1) {
		char* rw_error_msg = strerror(errno);

		arch_specific->fd = open (dev->path, O_RDONLY);
		if (arch_specific->fd == -1) {
			if (ped_exception_throw (
					PED_EXCEPTION_ERROR,
					PED_EXCEPTION_RETRY_CANCEL,
					_("Error opening %s: %s"),
					dev->path, strerror (errno))
					!= PED_EXCEPTION_RETRY) {
						return 0;
					} else {
						goto retry;
					}
		} else {
			ped_exception_throw (
				PED_EXCEPTION_WARNING,
				PED_EXCEPTION_OK,
				_("Unable to open %s read-write (%s).  %s has "
					"been opened read-only."),
				dev->path, rw_error_msg, dev->path);
			dev->read_only = 1;
		}
	} else {
		dev->read_only = 0;
	}

	_flush_cache (dev);

	return 1;
}
Ejemplo n.º 29
0
struct AmigaIds *
_amiga_add_id (uint32_t id, struct AmigaIds *ids) {
	struct AmigaIds *newid;

	if ((newid=ped_malloc(sizeof (struct AmigaIds)))==NULL) {
		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
			_("%s : Failed to allocate id list element\n"), __func__);
		return 0;
	}
	newid->ID = id;
	newid->next = ids;
	return newid;
}
Ejemplo n.º 30
0
int
ped_realloc (void** old, size_t size)
{
	void*		mem;

	mem = (void*) realloc (*old, size);
	if (!mem) {
		ped_exception_throw (PED_EXCEPTION_FATAL, PED_EXCEPTION_CANCEL,
				     _("Out of memory."));
		return 0;
	}
	*old = mem;
	return 1;
}