summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Granados Moreno <jgranado@redhat.com>2009-05-18 17:37:43 +0200
committerJim Meyering <meyering@redhat.com>2009-07-24 15:04:43 +0200
commitf387fee8be8f6d5cba90555462e5ec0b88400c38 (patch)
tree4f45f8b4edb445a072dac4e84ccfafe963fb758c
parenta60bdc0795df2191106ac8078230428d234755c1 (diff)
downloadparted-f387fee8be8f6d5cba90555462e5ec0b88400c38.tar.gz
put partition-table-specific logic in the corresponding files
* include/parted/disk.h (struct _PedDiskOps) [partition_check]: New member function. * libparted/disk.c (_check_partition): Replace open-coded tests with use of the new ->partition_check(). (_partition_max_start, _partition_max_len): Remove functions. * libparted/labels/dvh.c (dvh_partition_check): New function. * libparted/labels/dos.c (dos_partition_check): Likewise. * libparted/labels/aix.c (aix_partition_check): New stub. * libparted/labels/bsd.c (bsd_partition_check): Likewise. * libparted/labels/gpt.c (gpt_partition_check): Likewise. * libparted/labels/loop.c (loop_partition_check): Likewise. * libparted/labels/mac.c (mac_partition_check): Likewise. * libparted/labels/pc98.c (pc98_partition_check): Likewise. * libparted/labels/rdb.c (rdb_partition_check): Likewise. * libparted/labels/sun.c (sun_partition_check): Likewise.
-rw-r--r--include/parted/disk.h1
-rw-r--r--libparted/disk.c64
-rw-r--r--libparted/labels/aix.c7
-rw-r--r--libparted/labels/bsd.c7
-rw-r--r--libparted/labels/dos.c34
-rw-r--r--libparted/labels/dvh.c35
-rw-r--r--libparted/labels/gpt.c7
-rw-r--r--libparted/labels/loop.c7
-rw-r--r--libparted/labels/mac.c7
-rw-r--r--libparted/labels/pc98.c7
-rw-r--r--libparted/labels/rdb.c8
-rw-r--r--libparted/labels/sun.c7
12 files changed, 128 insertions, 63 deletions
diff --git a/include/parted/disk.h b/include/parted/disk.h
index 691f413..beec922 100644
--- a/include/parted/disk.h
+++ b/include/parted/disk.h
@@ -207,6 +207,7 @@ struct _PedDiskOps {
int (*partition_align) (PedPartition* part,
const PedConstraint* constraint);
int (*partition_enumerate) (PedPartition* part);
+ bool (*partition_check) (const PedPartition* part);
/* other */
int (*alloc_metadata) (PedDisk* disk);
diff --git a/libparted/disk.c b/libparted/disk.c
index 4dae762..ab8514a 100644
--- a/libparted/disk.c
+++ b/libparted/disk.c
@@ -1700,31 +1700,6 @@ _check_extended_partition (PedDisk* disk, PedPartition* part)
return 1;
}
-static PedSector
-_partition_max_start (char const *label_type)
-{
- /* List partition table names (a la disk->type->name) for which
- the partition length, in sectors, must fit in 32 bytes. */
- static char const *const max_32[] = {"msdos", "dvh"};
- unsigned int i;
-
- for (i = 0; i < sizeof max_32 / sizeof *max_32; i++)
- if (strcmp (label_type, max_32[i]) == 0)
- return UINT32_MAX;
-
- return TYPE_MAXIMUM (PedSector);
-}
-
-static PedSector
-_partition_max_len (char const *label_type)
-{
- /* NOTE: for now, they happen to be the same, so don't
- duplicate needlessly. Of course, if there's some format
- with different length and starting sector limits, then
- these functions will diverge. */
- return _partition_max_start (label_type);
-}
-
static int
_check_partition (PedDisk* disk, PedPartition* part)
{
@@ -1765,44 +1740,9 @@ _check_partition (PedDisk* disk, PedPartition* part)
return 0;
}
- if (!(part->type & PED_PARTITION_METADATA)) {
- char const *label_type = disk->type->name;
- /* Enforce some restrictions inherent in the DOS
- partition table format. Without these, one would be able
- to create a 2TB partition (or larger), and it would work,
- but only until the next reboot. This was insidious: the
- too-large partition would work initially, because with
- Linux-2.4.x and newer we set the partition start sector
- and length (in sectors) accurately and directly via the
- BLKPG ioctl. However, only the last 32 bits of each
- number would be written to the partition table, and the
- next time the system would read/use those corrupted numbers
- it would usually complain about an invalid partition.
- The same applies to the starting sector number. */
-
- if (part->geom.length > _partition_max_len (label_type)) {
- ped_exception_throw (
- PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
- _("partition length of %jd sectors exceeds the "
- "%s-partition-table-imposed maximum of %jd"),
- part->geom.length,
- label_type,
- _partition_max_len (label_type));
+ if (!(part->type & PED_PARTITION_METADATA))
+ if (!disk->type->ops->partition_check(part))
return 0;
- }
-
- /* The starting sector number must fit in 32 bytes. */
- if (part->geom.start > _partition_max_start (label_type)) {
- ped_exception_throw (
- PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
- _("starting sector number, %jd exceeds the"
- " %s-partition-table-imposed maximum of %jd"),
- part->geom.start,
- label_type,
- _partition_max_start (label_type));
- return 0;
- }
- }
return 1;
}
diff --git a/libparted/labels/aix.c b/libparted/labels/aix.c
index eb2a14b..1a0fcf9 100644
--- a/libparted/labels/aix.c
+++ b/libparted/labels/aix.c
@@ -235,6 +235,12 @@ aix_alloc_metadata (PedDisk* disk)
return 1;
}
+static bool
+aix_partition_check (const PedPartition* part)
+{
+ return true;
+}
+
static PedDiskOps aix_disk_ops = {
probe: aix_probe,
#ifndef DISCOVER_ONLY
@@ -261,6 +267,7 @@ static PedDiskOps aix_disk_ops = {
partition_is_flag_available: aix_partition_is_flag_available,
partition_align: aix_partition_align,
partition_enumerate: aix_partition_enumerate,
+ partition_check: aix_partition_check,
alloc_metadata: aix_alloc_metadata,
get_max_primary_partition_count:
aix_get_max_primary_partition_count,
diff --git a/libparted/labels/bsd.c b/libparted/labels/bsd.c
index 99e63e0..5390d42 100644
--- a/libparted/labels/bsd.c
+++ b/libparted/labels/bsd.c
@@ -640,6 +640,12 @@ error:
return 0;
}
+static bool
+bsd_partition_check (const PedPartition* part)
+{
+ return true;
+}
+
static PedDiskOps bsd_disk_ops = {
probe: bsd_probe,
#ifndef DISCOVER_ONLY
@@ -668,6 +674,7 @@ static PedDiskOps bsd_disk_ops = {
partition_get_name: NULL,
partition_align: bsd_partition_align,
partition_enumerate: bsd_partition_enumerate,
+ partition_check: bsd_partition_check,
alloc_metadata: bsd_alloc_metadata,
get_max_primary_partition_count:
diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
index a0fdcac..a94d84e 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -2270,6 +2270,39 @@ msdos_get_max_supported_partition_count(const PedDisk* disk, int *max_n)
return true;
}
+/*
+ * Enforce some restrictions inherent in the DOS partition table format.
+ * 1. Partition size must be smaller than 2^32 (unsigned int) sectors.
+ * If sector size is 512 bytes, this results in 2T aprox.
+ * 2. Partition starting sector number must be smaller than 2^32.
+ */
+static bool
+msdos_partition_check (const PedPartition* part)
+{
+ if (part->geom.length > UINT32_MAX) {
+ ped_exception_throw (
+ PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("partition length of %jd sectors exceeds the "
+ "msdos-partition-table-imposed maximum of %jd"),
+ part->geom.length,
+ UINT32_MAX);
+ return false;
+ }
+
+ /* The starting sector number must fit in 32 bytes. */
+ if (part->geom.start > UINT32_MAX) {
+ ped_exception_throw (
+ PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("starting sector number, %jd exceeds the"
+ " msdos-partition-table-imposed maximum of %jd"),
+ part->geom.start,
+ UINT32_MAX);
+ return false;
+ }
+
+ return true;
+}
+
static PedDiskOps msdos_disk_ops = {
probe: msdos_probe,
#ifndef DISCOVER_ONLY
@@ -2298,6 +2331,7 @@ static PedDiskOps msdos_disk_ops = {
partition_get_name: NULL,
partition_align: msdos_partition_align,
partition_enumerate: msdos_partition_enumerate,
+ partition_check: msdos_partition_check,
alloc_metadata: msdos_alloc_metadata,
get_max_primary_partition_count:
diff --git a/libparted/labels/dvh.c b/libparted/labels/dvh.c
index 3167c3f..b57fe03 100644
--- a/libparted/labels/dvh.c
+++ b/libparted/labels/dvh.c
@@ -892,6 +892,40 @@ error:
return 0;
}
+/*
+ * Enforce some restrictions inherent in the dvh partition table format.
+ * 1. Partition size must be smaller than 2^32 (unsigned int) sectors.
+ * If sector size is 512 bytes, this results in 2T aprox.
+ * 2. Partition starting sector number must be smaller than 2^32.
+ */
+static bool
+dvh_partition_check (const PedPartition* part)
+{
+ if (part->geom.length > UINT32_MAX) {
+ ped_exception_throw (
+ PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("partition length of %jd sectors exceeds the "
+ "dhv-partition-table-imposed maximum of %jd"),
+ part->geom.length,
+ UINT32_MAX);
+ return false;
+ }
+
+ /* The starting sector number must fit in 32 bytes. */
+ if (part->geom.start > UINT32_MAX) {
+ ped_exception_throw (
+ PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("starting sector number, %jd exceeds the"
+ " dhv-partition-table-imposed maximum of %jd"),
+ part->geom.start,
+ UINT32_MAX);
+ return false;
+ }
+
+ return true;
+
+}
+
static PedDiskOps dvh_disk_ops = {
probe: dvh_probe,
#ifndef DISCOVER_ONLY
@@ -920,6 +954,7 @@ static PedDiskOps dvh_disk_ops = {
partition_get_name: dvh_partition_get_name,
partition_align: dvh_partition_align,
partition_enumerate: dvh_partition_enumerate,
+ partition_check: dvh_partition_check,
alloc_metadata: dvh_alloc_metadata,
get_max_primary_partition_count: dvh_get_max_primary_partition_count,
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 2cfcddb..516d48e 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -1586,6 +1586,12 @@ gpt_partition_align (PedPartition* part, const PedConstraint* constraint)
return 0;
}
+static bool
+gpt_partition_check (const PedPartition* part)
+{
+ return true;
+}
+
static PedDiskOps gpt_disk_ops = {
probe: gpt_probe,
#ifndef DISCOVER_ONLY
@@ -1613,6 +1619,7 @@ static PedDiskOps gpt_disk_ops = {
partition_get_name: gpt_partition_get_name,
partition_align: gpt_partition_align,
partition_enumerate: gpt_partition_enumerate,
+ partition_check: gpt_partition_check,
alloc_metadata: gpt_alloc_metadata,
get_max_primary_partition_count: gpt_get_max_primary_partition_count,
get_max_supported_partition_count: gpt_get_max_supported_partition_count
diff --git a/libparted/labels/loop.c b/libparted/labels/loop.c
index 44b73f0..74a2c27 100644
--- a/libparted/labels/loop.c
+++ b/libparted/labels/loop.c
@@ -303,6 +303,12 @@ loop_get_max_supported_partition_count (const PedDisk* disk, int *max_n)
return true;
}
+static bool
+loop_partition_check (const PedPartition* part)
+{
+ return true;
+}
+
static PedDiskOps loop_disk_ops = {
probe: loop_probe,
#ifndef DISCOVER_ONLY
@@ -331,6 +337,7 @@ static PedDiskOps loop_disk_ops = {
partition_get_name: NULL,
partition_align: loop_partition_align,
partition_enumerate: loop_partition_enumerate,
+ partition_check: loop_partition_check,
alloc_metadata: loop_alloc_metadata,
get_max_primary_partition_count:
diff --git a/libparted/labels/mac.c b/libparted/labels/mac.c
index bdbb2cc..15b2fd8 100644
--- a/libparted/labels/mac.c
+++ b/libparted/labels/mac.c
@@ -1621,6 +1621,12 @@ mac_get_max_supported_partition_count (const PedDisk* disk, int *max_n)
return true;
}
+static bool
+mac_partition_check (const PedPartition* part)
+{
+ return true;
+}
+
static PedDiskOps mac_disk_ops = {
probe: mac_probe,
#ifndef DISCOVER_ONLY
@@ -1651,6 +1657,7 @@ static PedDiskOps mac_disk_ops = {
partition_get_name: mac_partition_get_name,
partition_align: mac_partition_align,
partition_enumerate: mac_partition_enumerate,
+ partition_check: mac_partition_check,
alloc_metadata: mac_alloc_metadata,
get_max_primary_partition_count:
diff --git a/libparted/labels/pc98.c b/libparted/labels/pc98.c
index f392bea..70986d6 100644
--- a/libparted/labels/pc98.c
+++ b/libparted/labels/pc98.c
@@ -839,6 +839,12 @@ pc98_get_max_supported_partition_count (const PedDisk* disk, int *max_n)
return true;
}
+static bool
+pc98_partition_check (const PedPartition* part)
+{
+ return true;
+}
+
static PedDiskOps pc98_disk_ops = {
probe: pc98_probe,
#ifndef DISCOVER_ONLY
@@ -867,6 +873,7 @@ static PedDiskOps pc98_disk_ops = {
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:
diff --git a/libparted/labels/rdb.c b/libparted/labels/rdb.c
index 8c77c6e..55cb738 100644
--- a/libparted/labels/rdb.c
+++ b/libparted/labels/rdb.c
@@ -1135,6 +1135,12 @@ amiga_get_max_supported_partition_count (const PedDisk* disk, int *max_n)
return true;
}
+static bool
+amiga_partition_check (const PedPartition* part)
+{
+ return true;
+}
+
static PedDiskOps amiga_disk_ops = {
probe: amiga_probe,
#ifndef DISCOVER_ONLY
@@ -1164,7 +1170,7 @@ static PedDiskOps amiga_disk_ops = {
partition_get_name: amiga_partition_get_name,
partition_align: amiga_partition_align,
partition_enumerate: amiga_partition_enumerate,
-
+ partition_check: amiga_partition_check,
alloc_metadata: amiga_alloc_metadata,
get_max_primary_partition_count:
diff --git a/libparted/labels/sun.c b/libparted/labels/sun.c
index 41580a4..88b71a9 100644
--- a/libparted/labels/sun.c
+++ b/libparted/labels/sun.c
@@ -836,6 +836,12 @@ error:
return 0;
}
+static bool
+sun_partition_check (const PedPartition* part)
+{
+ return true;
+}
+
static PedDiskOps sun_disk_ops = {
probe: sun_probe,
#ifndef DISCOVER_ONLY
@@ -862,6 +868,7 @@ static PedDiskOps sun_disk_ops = {
partition_is_flag_available: sun_partition_is_flag_available,
partition_align: sun_partition_align,
partition_enumerate: sun_partition_enumerate,
+ partition_check: sun_partition_check,
alloc_metadata: sun_alloc_metadata,
get_max_primary_partition_count:
sun_get_max_primary_partition_count,