/*
libparted - a library for manipulating disk partitions
- Copyright (C) 2000-2001, 2007-2009 Free Software Foundation, Inc.
+ Copyright (C) 2000-2001, 2007-2011 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <parted/debug.h>
#include <parted/endian.h>
+#include "pt-tools.h"
+
#if ENABLE_NLS
# include <libintl.h>
# define _(String) dgettext (PACKAGE, String)
static int
pc98_check_ipl_signature (const PC98RawTable *part_table)
{
- return !memcmp (part_table->boot_code + 4, "IPL1", 4);
-}
-
-static int
-check_partition_consistency (const PedDevice* dev,
- const PC98RawPartition* raw_part)
-{
- if (raw_part->ipl_sect >= dev->hw_geom.sectors
- || raw_part->sector >= dev->hw_geom.sectors
- || raw_part->end_sector >= dev->hw_geom.sectors
- || raw_part->ipl_head >= dev->hw_geom.heads
- || raw_part->head >= dev->hw_geom.heads
- || raw_part->end_head >= dev->hw_geom.heads
- || PED_LE16_TO_CPU(raw_part->ipl_cyl) >= dev->hw_geom.cylinders
- || PED_LE16_TO_CPU(raw_part->cyl) >= dev->hw_geom.cylinders
- || PED_LE16_TO_CPU(raw_part->end_cyl) >= dev->hw_geom.cylinders
- || PED_LE16_TO_CPU(raw_part->cyl)
- > PED_LE16_TO_CPU(raw_part->end_cyl)
-#if 0
- || !chs_to_sector(dev, PED_LE16_TO_CPU(raw_part->ipl_cyl),
- raw_part->ipl_head, raw_part->ipl_sect)
- || !chs_to_sector(dev, PED_LE16_TO_CPU(raw_part->cyl),
- raw_part->head, raw_part->sector)
- || !chs_to_sector(dev, PED_LE16_TO_CPU(raw_part->end_cyl),
- raw_part->end_head, raw_part->end_sector)
-#endif
- || PED_LE16_TO_CPU(raw_part->end_cyl)
- < PED_LE16_TO_CPU(raw_part->cyl))
+ if (memcmp (part_table->boot_code + 4, "IPL1", 4) == 0)
+ return 1;
+ else if (memcmp (part_table->boot_code + 4, "Linux 98", 8) == 0)
+ return 1;
+ else if (memcmp (part_table->boot_code + 4, "GRUB/98 ", 8) == 0)
+ return 1;
+ else
return 0;
-
- return 1;
}
static int
pc98_probe (const PedDevice *dev)
{
PC98RawTable part_table;
- int empty;
- const PC98RawPartition* p;
- PED_ASSERT (dev != NULL, return 0);
+ PED_ASSERT (dev != NULL);
if (dev->sector_size != 512)
return 0;
if (!pc98_check_magic (&part_table))
return 0;
- /* check consistency */
- empty = 1;
- for (p = part_table.partitions;
- p < part_table.partitions + MAX_PART_COUNT;
- p++)
- {
- if (p->mid == 0 && p->sid == 0)
- continue;
- empty = 0;
- if (!check_partition_consistency (dev, p))
- return 0;
- }
-
- /* check boot loader */
- if (pc98_check_ipl_signature (&part_table))
- return 1;
- else if (part_table.boot_code[0]) /* invalid boot loader */
- return 0;
-
- /* Not to mistake msdos disk map for PC-9800's empty disk map */
- if (empty)
- return 0;
-
- return 1;
-}
-
-#ifndef DISCOVER_ONLY
-static int
-pc98_clobber (PedDevice* dev)
-{
- PC98RawTable table;
-
- PED_ASSERT (dev != NULL, return 0);
- PED_ASSERT (pc98_probe (dev), return 0);
-
- if (!ped_device_read (dev, &table, 0, 1))
- return 0;
-
- memset (table.partitions, 0, sizeof (table.partitions));
- table.magic = PED_CPU_TO_LE16(0);
-
- if (pc98_check_ipl_signature (&table))
- memset (table.boot_code, 0, sizeof (table.boot_code));
-
- if (!ped_device_write (dev, (void*) &table, 0, 1))
- return 0;
- return ped_device_sync (dev);
+ /* check for boot loader signatures */
+ return pc98_check_ipl_signature (&part_table);
}
-#endif /* !DISCOVER_ONLY */
static PedDisk*
pc98_alloc (const PedDevice* dev)
{
- PED_ASSERT (dev != NULL, return 0);
+ PED_ASSERT (dev != NULL);
return _ped_disk_alloc (dev, &pc98_disk_type);
}
static void
pc98_free (PedDisk* disk)
{
- PED_ASSERT (disk != NULL, return);
+ PED_ASSERT (disk != NULL);
_ped_disk_free (disk);
}
-static PedSector
+static PedSector _GL_ATTRIBUTE_PURE
chs_to_sector (const PedDevice* dev, int c, int h, int s)
{
- PED_ASSERT (dev != NULL, return 0);
+ PED_ASSERT (dev != NULL);
return (c * dev->hw_geom.heads + h) * dev->hw_geom.sectors + s;
}
{
PedSector cyl_size;
- PED_ASSERT (dev != NULL, return);
- PED_ASSERT (c != NULL, return);
- PED_ASSERT (h != NULL, return);
- PED_ASSERT (s != NULL, return);
+ PED_ASSERT (dev != NULL);
+ PED_ASSERT (c != NULL);
+ PED_ASSERT (h != NULL);
+ PED_ASSERT (s != NULL);
cyl_size = dev->hw_geom.heads * dev->hw_geom.sectors;
*s = (sector) % cyl_size % dev->hw_geom.sectors;
}
-static PedSector
+static PedSector _GL_ATTRIBUTE_PURE
legacy_start (const PedDisk* disk, const PC98RawPartition* raw_part)
{
- PED_ASSERT (disk != NULL, return 0);
- PED_ASSERT (raw_part != NULL, return 0);
+ PED_ASSERT (disk != NULL);
+ PED_ASSERT (raw_part != NULL);
return chs_to_sector (disk->dev, PED_LE16_TO_CPU(raw_part->cyl),
raw_part->head, raw_part->sector);
}
-static PedSector
+static PedSector _GL_ATTRIBUTE_PURE
legacy_end (const PedDisk* disk, const PC98RawPartition* raw_part)
{
- PED_ASSERT (disk != NULL, return 0);
- PED_ASSERT (raw_part != NULL, return 0);
+ PED_ASSERT (disk != NULL);
+ PED_ASSERT (raw_part != NULL);
if (raw_part->end_head == 0 && raw_part->end_sector == 0) {
return chs_to_sector (disk->dev,
PC98RawTable table;
PedConstraint* constraint_any;
- PED_ASSERT (disk != NULL, return 0);
- PED_ASSERT (disk->dev != NULL, return 0);
+ PED_ASSERT (disk != NULL);
+ PED_ASSERT (disk->dev != NULL);
constraint_any = ped_constraint_any (disk->dev);
if (!part)
goto error;
pc98_data = part->disk_specific;
- PED_ASSERT (pc98_data != NULL, goto error);
+ PED_ASSERT (pc98_data != NULL);
pc98_data->system = (raw_part->mid << 8) | raw_part->sid;
pc98_data->boot = GET_BIT(raw_part->mid, 7);
static int
pc98_read (PedDisk* disk)
{
- PED_ASSERT (disk != NULL, return 0);
- PED_ASSERT (disk->dev != NULL, return 0);
+ PED_ASSERT (disk != NULL);
+ PED_ASSERT (disk->dev != NULL);
ped_disk_delete_all (disk);
return read_table (disk);
int c, h, s;
const char* name;
- PED_ASSERT (raw_part != NULL, return 0);
- PED_ASSERT (part != NULL, return 0);
- PED_ASSERT (part->disk_specific != NULL, return 0);
+ PED_ASSERT (raw_part != NULL);
+ PED_ASSERT (part != NULL);
+ PED_ASSERT (part->disk_specific != NULL);
pc98_data = part->disk_specific;
raw_part->mid = (pc98_data->system >> 8) & 0xFF;
memset (raw_part->name, ' ', sizeof(raw_part->name));
name = ped_partition_get_name (part);
- PED_ASSERT (name != NULL, return 0);
- PED_ASSERT (strlen (name) <= 16, return 0);
+ PED_ASSERT (name != NULL);
+ PED_ASSERT (strlen (name) <= 16);
if (!strlen (name) && part->fs_type)
name = part->fs_type->name;
memcpy (raw_part->name, name, strlen (name));
static int
pc98_write (const PedDisk* disk)
{
- PC98RawTable table;
PedPartition* part;
int i;
- PED_ASSERT (disk != NULL, return 0);
- PED_ASSERT (disk->dev != NULL, return 0);
+ PED_ASSERT (disk != NULL);
+ PED_ASSERT (disk->dev != NULL);
- if (!ped_device_read (disk->dev, &table, 0, 2))
+ void *s0;
+ if (!ptt_read_sectors (disk->dev, 0, 2, &s0))
return 0;
+ PC98RawTable *table = s0;
- if (!pc98_check_ipl_signature (&table)) {
- memset (table.boot_code, 0, sizeof(table.boot_code));
- memcpy (table.boot_code, MBR_BOOT_CODE, sizeof(MBR_BOOT_CODE));
+ if (!pc98_check_ipl_signature (table)) {
+ memset (table->boot_code, 0, sizeof(table->boot_code));
+ memcpy (table->boot_code, MBR_BOOT_CODE, sizeof(MBR_BOOT_CODE));
}
- memset (table.partitions, 0, sizeof (table.partitions));
- table.magic = PED_CPU_TO_LE16(PC9800_EXTFMT_MAGIC);
+ memset (table->partitions, 0, sizeof (table->partitions));
+ table->magic = PED_CPU_TO_LE16(PC9800_EXTFMT_MAGIC);
for (i = 1; i <= MAX_PART_COUNT; i++) {
part = ped_disk_get_partition (disk, i);
if (!part)
continue;
- if (!fill_raw_part (&table.partitions [i - 1], part))
+ if (!fill_raw_part (&table->partitions [i - 1], part))
return 0;
}
- if (!ped_device_write (disk->dev, (void*) &table, 0, 2))
+ int write_ok = ped_device_write (disk->dev, table, 0, 2);
+ free (s0);
+ if (!write_ok)
return 0;
return ped_device_sync (disk->dev);
}
}
return part;
- free (pc98_data);
error_free_part:
free (part);
error:
static void
pc98_partition_destroy (PedPartition* part)
{
- PED_ASSERT (part != NULL, return);
+ PED_ASSERT (part != NULL);
if (ped_partition_is_active (part))
free (part->disk_specific);
{
PC98PartitionData* pc98_data;
- PED_ASSERT (part != NULL, return 0);
- PED_ASSERT (part->disk_specific != NULL, return 0);
+ PED_ASSERT (part != NULL);
+ PED_ASSERT (part->disk_specific != NULL);
pc98_data = part->disk_specific;
}
}
-static int
+static int _GL_ATTRIBUTE_PURE
pc98_partition_get_flag (const PedPartition* part, PedPartitionFlag flag)
{
PC98PartitionData* pc98_data;
- PED_ASSERT (part != NULL, return 0);
- PED_ASSERT (part->disk_specific != NULL, return 0);
+ PED_ASSERT (part != NULL);
+ PED_ASSERT (part->disk_specific != NULL);
pc98_data = part->disk_specific;
switch (flag) {
PC98PartitionData* pc98_data;
int i;
- PED_ASSERT (part != NULL, return);
- PED_ASSERT (part->disk_specific != NULL, return);
+ PED_ASSERT (part != NULL);
+ PED_ASSERT (part->disk_specific != NULL);
pc98_data = part->disk_specific;
strncpy (pc98_data->name, name, 16);
pc98_data->name [i] = 0;
}
-static const char*
+static const char* _GL_ATTRIBUTE_PURE
pc98_partition_get_name (const PedPartition* part)
{
PC98PartitionData* pc98_data;
- PED_ASSERT (part != NULL, return NULL);
- PED_ASSERT (part->disk_specific != NULL, return NULL);
+ PED_ASSERT (part != NULL);
+ PED_ASSERT (part->disk_specific != NULL);
pc98_data = part->disk_specific;
return pc98_data->name;
}
+static PedAlignment*
+pc98_get_partition_alignment(const PedDisk *disk)
+{
+ PedSector cylinder_size =
+ disk->dev->hw_geom.sectors * disk->dev->hw_geom.heads;
+
+ return ped_alignment_new(0, cylinder_size);
+}
+
static PedConstraint*
_primary_constraint (PedDisk* disk)
{
static int
pc98_partition_align (PedPartition* part, const PedConstraint* constraint)
{
- PED_ASSERT (part != NULL, return 0);
+ PED_ASSERT (part != NULL);
if (_ped_partition_attempt_align (part, constraint,
_primary_constraint (part->disk)))
static int
pc98_partition_enumerate (PedPartition* part)
{
- PED_ASSERT (part != NULL, return 0);
- PED_ASSERT (part->disk != NULL, return 0);
+ PED_ASSERT (part != NULL);
+ PED_ASSERT (part->disk != NULL);
/* don't re-number a partition */
if (part->num != -1)
return 1;
- PED_ASSERT (ped_partition_is_active (part), return 0);
+ PED_ASSERT (ped_partition_is_active (part));
part->num = next_primary (part->disk);
if (!part->num) {
PedConstraint* constraint_any = NULL;
PedSector cyl_size;
- PED_ASSERT (disk != NULL, goto error);
- PED_ASSERT (disk->dev != NULL, goto error);
+ PED_ASSERT (disk != NULL);
+ PED_ASSERT (disk->dev != NULL);
constraint_any = ped_constraint_any (disk->dev);
return true;
}
-static bool
-pc98_partition_check (const PedPartition* part)
-{
- return true;
-}
+#include "pt-common.h"
+PT_define_limit_functions (pc98)
static PedDiskOps pc98_disk_ops = {
- probe: pc98_probe,
-#ifndef DISCOVER_ONLY
- clobber: pc98_clobber,
-#else
clobber: NULL,
-#endif
- alloc: pc98_alloc,
- duplicate: pc98_duplicate,
- free: pc98_free,
- read: pc98_read,
-#ifndef DISCOVER_ONLY
- write: pc98_write,
-#else
- write: NULL,
-#endif
+ write: NULL_IF_DISCOVER_ONLY (pc98_write),
- partition_new: pc98_partition_new,
- partition_duplicate: pc98_partition_duplicate,
- partition_destroy: pc98_partition_destroy,
- partition_set_system: pc98_partition_set_system,
- partition_set_flag: pc98_partition_set_flag,
- partition_get_flag: pc98_partition_get_flag,
- partition_is_flag_available: pc98_partition_is_flag_available,
partition_set_name: pc98_partition_set_name,
partition_get_name: pc98_partition_get_name,
- partition_align: pc98_partition_align,
- partition_enumerate: pc98_partition_enumerate,
- partition_check: pc98_partition_check,
-
- alloc_metadata: pc98_alloc_metadata,
- get_max_primary_partition_count:
- pc98_get_max_primary_partition_count,
- get_max_supported_partition_count:
- pc98_get_max_supported_partition_count
+
+ get_partition_alignment: pc98_get_partition_alignment,
+
+ PT_op_function_initializers (pc98)
};
static PedDiskType pc98_disk_type = {
void
ped_disk_pc98_init ()
{
- PED_ASSERT (sizeof (PC98RawTable) == 512 * 2, return);
+ PED_ASSERT (sizeof (PC98RawTable) == 512 * 2);
ped_disk_type_register (&pc98_disk_type);
}