dvh.c revision 7e7bd3dccbfe8f79e25e5c1554b5bc3a9aaca321
/*
libparted - a library for manipulating disk partitions
Copyright (C) 2001, 2002, 2005, 2007 Free Software Foundation, Inc.
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include "dvh.h"
#if ENABLE_NLS
# include <libintl.h>
#else
#endif /* ENABLE_NLS */
/* Default size for volhdr part, same val as IRIX's fx uses */
#define PTYPE_VOLHDR_DFLTSZ 4096
/* Partition numbers that seem to be strongly held convention */
#define PNUM_VOLHDR 8
#define PNUM_VOLUME 10
/* Other notes of interest:
* PED_PARTITION_EXTENDED is used for volume headers
* PED_PARTITION_LOGICAL is used for bootfiles
* PED_PARTITION_NORMAL is used for all else
*/
typedef struct _DVHDiskData {
struct device_parameters dev_params;
int swap; /* part num of swap, 0=none */
int root; /* part num of root, 0=none */
int boot; /* part num of boot, 0=none */
} DVHDiskData;
typedef struct _DVHPartData {
int type;
int real_file_size; /* boot volumes only */
} DVHPartData;
static PedDiskType dvh_disk_type;
static int
{
struct volume_header vh;
return 0;
return 0;
}
#ifndef DISCOVER_ONLY
static int
{
char zeros[512];
}
#endif /* !DISCOVER_ONLY */
static PedDisk*
{
if (!disk)
goto error;
= ped_malloc (sizeof (DVHDiskData));
if (!dvh_disk_data)
goto error_free_disk;
sizeof (struct device_parameters));
dvh_disk_data->swap = 0;
dvh_disk_data->root = 0;
dvh_disk_data->boot = 0;
0, PTYPE_VOLHDR_DFLTSZ - 1);
if (!volume_part)
goto error_free_disk_specific;
return disk;
return NULL;
}
static PedDisk*
{
if (!new_disk)
goto error;
= ped_malloc (sizeof (DVHDiskData));
if (!new_dvh_disk_data)
goto error_free_new_disk;
return new_disk;
return NULL;
}
static void
{
}
/* two's complement 32-bit checksum */
static uint32_t
{
size_t i;
return sum;
}
/* try to make a reasonable volume header partition... */
static PedExceptionOption
{
switch (ped_exception_throw (
_("%s has no extended partition (volume header partition)."),
case PED_EXCEPTION_UNHANDLED:
case PED_EXCEPTION_FIX:
default:
0, PTYPE_VOLHDR_DFLTSZ - 1);
if (!part)
goto error;
if (!constraint)
goto error_destroy_part;
goto error_destroy_constraint;
break;
case PED_EXCEPTION_CANCEL:
goto error;
}
return ret;
return PED_EXCEPTION_CANCEL;
}
static PedPartition*
{
NULL,
if (!part)
return NULL;
return part;
}
static PedPartition*
{
if (!part)
return NULL;
return part;
}
/* YUCK
*
* thing isn't updated. (Probably reflects a design bug somewhere...)
* Anyway, the workaround is: flush stale flags whenever we allocate
* new partition numbers, and before we write to disk.
*/
static void
{
if (dvh_disk_data->root
dvh_disk_data->root = 0;
if (dvh_disk_data->swap
dvh_disk_data->swap = 0;
if (dvh_disk_data->boot
dvh_disk_data->boot = 0;
}
static int
{
int i;
struct volume_header vh;
#ifndef DISCOVER_ONLY
int write_back = 0;
#endif
return 0;
if (ped_exception_throw (
_("Checksum is wrong, indicating the partition "
"table is corrupt."))
return 0;
}
boot_name[BFNAMESIZE] = 0;
/* normal partitions */
for (i = 0; i < NPARTAB; i++) {
continue;
/* Skip the whole-disk partition, parted disklikes overlap */
continue;
if (!part)
goto error_delete_all;
goto error_delete_all;
}
}
if (!ped_disk_extended_partition (disk)) {
#ifdef DISCOVER_ONLY
return 1;
#else
switch (_handle_no_volume_header (disk)) {
case PED_EXCEPTION_CANCEL:
return 0;
case PED_EXCEPTION_IGNORE:
return 1;
case PED_EXCEPTION_FIX:
write_back = 1;
break;
default:
break;
}
#endif
}
/* boot partitions */
for (i = 0; i < NVDIR; i++) {
continue;
if (!part)
goto error_delete_all;
goto error_delete_all;
}
}
#ifndef DISCOVER_ONLY
if (write_back)
#endif
return 1;
return 0;
}
#ifndef DISCOVER_ONLY
static void
{
/* Assert not a bootfile */
}
static void
{
/* Assert it's a bootfile */
}
static int
{
struct volume_header vh;
int i;
if (dvh_disk_data->boot) {
}
/* Set up rudimentary device geometry */
for (i = 0; i < NPARTAB; i++) {
if (part)
}
/* whole disk partition
* This is only ever written here, and never modified
* (or even shown) as it must contain the entire disk,
* and parted does not like overlapping partitions
*/
for (i = 0; i < NVDIR; i++) {
i + 1 + NPARTAB);
if (part)
}
sizeof (struct volume_header)));
}
#endif /* !DISCOVER_ONLY */
static PedPartition*
const PedFileSystemType* fs_type,
{
if (!part)
goto error;
if (!ped_partition_is_active (part)) {
return part;
}
ped_malloc (sizeof (DVHPartData));
if (!dvh_part_data)
goto error_free_part;
: PTYPE_RAW;
return part;
return NULL;
}
static PedPartition*
{
if (!result)
goto error;
if (!ped_partition_is_active (part)) {
return result;
}
ped_malloc (sizeof (DVHPartData));
if (!result_data)
goto error_free_part;
return result;
return NULL;
}
static void
{
if (ped_partition_is_active (part)) {
}
}
static int
{
return 1;
}
/* Is this a bootfile? */
return 1;
else
return 1;
}
static int
{
switch (flag) {
case PED_PARTITION_ROOT:
#ifndef DISCOVER_ONLY
_("Only primary partitions can be root "
"partitions."));
#endif
return 0;
}
break;
case PED_PARTITION_SWAP:
#ifndef DISCOVER_ONLY
_("Only primary partitions can be swap "
"partitions."));
return 0;
#endif
}
break;
case PED_PARTITION_BOOT:
#ifndef DISCOVER_ONLY
_("Only logical partitions can be a boot "
"file."));
#endif
return 0;
}
break;
case PED_PARTITION_LVM:
case PED_PARTITION_LBA:
case PED_PARTITION_HIDDEN:
case PED_PARTITION_RAID:
default:
return 0;
}
return 1;
}
static int
{
switch (flag) {
case PED_PARTITION_ROOT:
case PED_PARTITION_SWAP:
case PED_PARTITION_BOOT:
case PED_PARTITION_LVM:
case PED_PARTITION_LBA:
case PED_PARTITION_HIDDEN:
case PED_PARTITION_RAID:
default:
return 0;
}
return 1;
}
static int
{
switch (flag) {
case PED_PARTITION_ROOT:
case PED_PARTITION_SWAP:
case PED_PARTITION_BOOT:
return 1;
case PED_PARTITION_LVM:
case PED_PARTITION_LBA:
case PED_PARTITION_HIDDEN:
case PED_PARTITION_RAID:
default:
return 0;
}
return 1;
}
static void
{
/* Bootfile */
} else {
#ifndef DISCOVER_ONLY
_("Only logical partitions (boot files) have a name."));
#endif
}
}
static const char*
{
return dvh_part_data->name;
}
/* The constraint for the volume header partition is different, because it must
* contain the first sector of the disk.
*/
static PedConstraint*
{
return NULL;
return ped_constraint_new_from_min (&min_geom);
}
static PedConstraint*
{
return NULL;
return ped_constraint_new_from_max (&max_geom);
}
static int
{
return 1;
#ifndef DISCOVER_ONLY
_("Unable to satisfy all constraints on the partition."));
#endif
return 0;
}
static int
{
int i;
/* never change the partition numbers */
return 1;
/* Bootfile */
return 1;
}
}
PED_ASSERT (0, return 0);
/* Volheader */
} else {
for (i = 1; i <= NPARTAB; i++) {
/* reserved for full volume partition */
if (i == PNUM_VOLUME + 1)
continue;
return 1;
}
}
_("Too many primary partitions"));
}
return 0;
}
static int
{
return NPARTAB;
}
static int
{
/* We don't need to "protect" the start of the disk from the volume
* header.
*/
else
if (!part)
goto error;
goto error_destroy_part;
return 1;
return 0;
}
static PedDiskOps dvh_disk_ops = {
#ifndef DISCOVER_ONLY
.clobber = dvh_clobber,
#else
#endif
#ifndef DISCOVER_ONLY
#else
#endif
};
static PedDiskType dvh_disk_type = {
.name = "dvh",
.ops = &dvh_disk_ops,
};
void
{
}
void
{
}