[parted-devel] [PATCH 2/2] Put the maximum sector checks in pt-tools.c
Joel Granados Moreno
jgranado at redhat.com
Mon May 18 15:37:44 UTC 2009
* libparted/labels/dos.c (msdos_partition_check) : Use new
ptt_partition_max_start_len function to test for len and start maxs.
* libparted/labels/dvh.c (msdos_partition_check) : Likewise.
* libparted/labels/pt-tools.c (ptt_partition_max_start_len) : New
function that checks for maximum partiion length and maximum
partition start sector.
* libparted/labels/pt-tools.h : Likewise.
* po/POTFILES.in : Add pt-tools.c to the translation list. There are
error messages there that need translating.
---
libparted/labels/dos.c | 20 +----------------
libparted/labels/dvh.c | 21 +-----------------
libparted/labels/pt-tools.c | 49 +++++++++++++++++++++++++++++++++++++++++++
libparted/labels/pt-tools.h | 2 +
po/POTFILES.in | 1 +
5 files changed, 54 insertions(+), 39 deletions(-)
diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
index bdb5186..16639ba 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -2225,26 +2225,8 @@ msdos_get_max_supported_partition_count(const PedDisk* disk, int *max_n)
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);
+ if (!ptt_partition_max_start_len("msdos", part))
return false;
- }
return true;
}
diff --git a/libparted/labels/dvh.c b/libparted/labels/dvh.c
index be6d52a..f757b1c 100644
--- a/libparted/labels/dvh.c
+++ b/libparted/labels/dvh.c
@@ -901,29 +901,10 @@ error:
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);
+ if (!ptt_partition_max_start_len("dvh", part))
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 = {
diff --git a/libparted/labels/pt-tools.c b/libparted/labels/pt-tools.c
index 564f611..4a3e879 100644
--- a/libparted/labels/pt-tools.c
+++ b/libparted/labels/pt-tools.c
@@ -24,6 +24,13 @@
#include "pt-tools.h"
+#if ENABLE_NLS
+# include <libintl.h>
+# define _(String) dgettext (PACKAGE, String)
+#else
+# define _(String) (String)
+#endif /* ENABLE_NLS */
+
static char zero[16 * 1024];
/* Write a single sector to DISK, filling the first BUFLEN
@@ -84,3 +91,45 @@ ptt_clear_sectors (PedDevice *dev, PedSector start, PedSector n)
return (rem == 0
? 1 : ped_device_write (dev, zero, start + n_z_sectors * i, rem));
}
+
+/* Will go through the partition types and raise an error and return
+ 0 if PART start is greater than the maximum allowed start for
+ LABEL_TYPE. Or if PART length is greater than the maximum
+ allowed lenght for LABEL_TYPE. */
+int
+ptt_partition_max_start_len (char const *label_type, const PedPartition *part)
+{
+ 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)
+ {
+ /* The starting sector length must fit in 32 bytes. */
+ if (part->geom.length > UINT32_MAX)
+ {
+ 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,
+ UINT32_MAX);
+ return 0;
+ }
+
+ /* 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"
+ " %s-partition-table-imposed maximum of %jd"),
+ part->geom.start,
+ label_type,
+ UINT32_MAX);
+ return 0;
+ }
+ }
+
+ return 1;
+}
diff --git a/libparted/labels/pt-tools.h b/libparted/labels/pt-tools.h
index d36929e..2987135 100644
--- a/libparted/labels/pt-tools.h
+++ b/libparted/labels/pt-tools.h
@@ -20,3 +20,5 @@
int ptt_write_sector (PedDisk const *disk, void const *buf, size_t buflen);
int ptt_read_sector (PedDevice const *dev, PedSector sector_num, void **buf);
int ptt_clear_sectors (PedDevice *dev, PedSector start, PedSector count);
+int ptt_partition_max_start_len (char const *label_type,
+ const PedPartition *part);
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 33f4979..eb53457 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -38,6 +38,7 @@ libparted/labels/gpt.c
libparted/labels/loop.c
libparted/labels/mac.c
libparted/labels/pc98.c
+libparted/labels/pt-tools.c
libparted/labels/rdb.c
libparted/labels/sun.c
libparted/labels/vtoc.c
--
1.6.0.6
More information about the parted-devel
mailing list