bool (*get_max_supported_partition_count) (const PedDisk* disk,
int* supported);
PedAlignment *(*get_partition_alignment)(const PedDisk *disk);
+ PedSector (*max_length) (void);
+ PedSector (*max_start_sector) (void);
};
struct _PedDiskType {
mac.c \
misc.h \
pc98.c \
+ pt-common.h \
pt-tools.c \
pt-tools.h \
rdb.c \
return 1;
}
-static bool
-aix_partition_check (const PedPartition* part)
-{
- return true;
-}
+#include "pt-common.h"
+PT_define_limit_functions (aix)
static PedDiskOps aix_disk_ops = {
- probe: aix_probe,
-#ifndef DISCOVER_ONLY
- clobber: aix_clobber,
-#else
- clobber: NULL,
-#endif
- alloc: aix_alloc,
- duplicate: aix_duplicate,
- free: aix_free,
- read: aix_read,
-#ifndef DISCOVER_ONLY
- write: aix_write,
-#else
- write: NULL,
-#endif
-
- partition_new: aix_partition_new,
- partition_duplicate: aix_partition_duplicate,
- partition_destroy: aix_partition_destroy,
- partition_set_system: aix_partition_set_system,
- partition_set_flag: aix_partition_set_flag,
- partition_get_flag: aix_partition_get_flag,
- 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,
- get_max_supported_partition_count:
- aix_get_max_supported_partition_count,
+ clobber: NULL_IF_DISCOVER_ONLY (aix_clobber),
+ write: NULL_IF_DISCOVER_ONLY (aix_write),
partition_set_name: NULL,
partition_get_name: NULL,
+
+ PT_op_function_initializers (aix)
};
static PedDiskType aix_disk_type = {
return 0;
}
-static bool
-bsd_partition_check (const PedPartition* part)
-{
- return true;
-}
+#include "pt-common.h"
+PT_define_limit_functions (bsd)
static PedDiskOps bsd_disk_ops = {
- probe: bsd_probe,
-#ifndef DISCOVER_ONLY
- clobber: bsd_clobber,
-#else
- clobber: NULL,
-#endif
- alloc: bsd_alloc,
- duplicate: bsd_duplicate,
- free: bsd_free,
- read: bsd_read,
-#ifndef DISCOVER_ONLY
- write: bsd_write,
-#else
- write: NULL,
-#endif
+ clobber: NULL_IF_DISCOVER_ONLY (bsd_clobber),
+ write: NULL_IF_DISCOVER_ONLY (bsd_write),
- partition_new: bsd_partition_new,
- partition_duplicate: bsd_partition_duplicate,
- partition_destroy: bsd_partition_destroy,
- partition_set_system: bsd_partition_set_system,
- partition_set_flag: bsd_partition_set_flag,
- partition_get_flag: bsd_partition_get_flag,
- partition_is_flag_available: bsd_partition_is_flag_available,
partition_set_name: NULL,
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:
- bsd_get_max_primary_partition_count,
- get_max_supported_partition_count:
- bsd_get_max_supported_partition_count
+
+ PT_op_function_initializers (bsd)
};
static PedDiskType bsd_disk_type = {
const PedFileSystemType* fs_type);
static int dasd_alloc_metadata (PedDisk* disk);
-static bool
-dasd_partition_check (const PedPartition *part)
-{
- return ptt_partition_max_start_len ("dasd", part);
-}
+#include "pt-common.h"
+PT_define_limit_functions (dasd)
static PedDiskOps dasd_disk_ops = {
- probe: dasd_probe,
- clobber: dasd_clobber,
- read: dasd_read,
- write: dasd_write,
-
- alloc: dasd_alloc,
- duplicate: dasd_duplicate,
- free: dasd_free,
- partition_set_system: dasd_partition_set_system,
-
- partition_new: dasd_partition_new,
- partition_duplicate: dasd_partition_duplicate,
- partition_destroy: dasd_partition_destroy,
- partition_set_flag: dasd_partition_set_flag,
- partition_get_flag: dasd_partition_get_flag,
- partition_is_flag_available: dasd_partition_is_flag_available,
+ clobber: NULL_IF_DISCOVER_ONLY (dasd_clobber),
+ write: NULL_IF_DISCOVER_ONLY (dasd_write),
+
partition_set_name: NULL,
partition_get_name: NULL,
- partition_align: dasd_partition_align,
- partition_enumerate: dasd_partition_enumerate,
- alloc_metadata: dasd_alloc_metadata,
- get_max_primary_partition_count: dasd_get_max_primary_partition_count,
- get_max_supported_partition_count: dasd_get_max_supported_partition_count,
get_partition_alignment: dasd_get_partition_alignment,
- partition_check: dasd_partition_check,
+
+ PT_op_function_initializers (dasd)
};
static PedDiskType dasd_disk_type = {
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 (!ptt_partition_max_start_len("msdos", part))
- return false;
-
- return true;
-}
+#include "pt-common.h"
+PT_define_limit_functions (msdos)
static PedDiskOps msdos_disk_ops = {
- probe: msdos_probe,
-#ifndef DISCOVER_ONLY
- clobber: msdos_clobber,
-#else
- clobber: NULL,
-#endif
- alloc: msdos_alloc,
- duplicate: msdos_duplicate,
- free: msdos_free,
- read: msdos_read,
-#ifndef DISCOVER_ONLY
- write: msdos_write,
-#else
- write: NULL,
-#endif
+ clobber: NULL_IF_DISCOVER_ONLY (msdos_clobber),
+ write: NULL_IF_DISCOVER_ONLY (msdos_write),
- partition_new: msdos_partition_new,
- partition_duplicate: msdos_partition_duplicate,
- partition_destroy: msdos_partition_destroy,
- partition_set_system: msdos_partition_set_system,
- partition_set_flag: msdos_partition_set_flag,
- partition_get_flag: msdos_partition_get_flag,
- partition_is_flag_available: msdos_partition_is_flag_available,
partition_set_name: NULL,
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:
- msdos_get_max_primary_partition_count,
- get_max_supported_partition_count:
- msdos_get_max_supported_partition_count
+
+ PT_op_function_initializers (msdos)
};
static PedDiskType msdos_disk_type = {
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 (!ptt_partition_max_start_len("dvh", part))
- return false;
-
- return true;
-}
+#include "pt-common.h"
+PT_define_limit_functions (dvh)
static PedDiskOps dvh_disk_ops = {
- probe: dvh_probe,
-#ifndef DISCOVER_ONLY
- clobber: dvh_clobber,
-#else
- clobber: NULL,
-#endif
- alloc: dvh_alloc,
- duplicate: dvh_duplicate,
- free: dvh_free,
- read: dvh_read,
-#ifndef DISCOVER_ONLY
- write: dvh_write,
-#else
- write: NULL,
-#endif
+ clobber: NULL_IF_DISCOVER_ONLY (dvh_clobber),
+ write: NULL_IF_DISCOVER_ONLY (dvh_write),
- partition_new: dvh_partition_new,
- partition_duplicate: dvh_partition_duplicate,
- partition_destroy: dvh_partition_destroy,
- partition_set_system: dvh_partition_set_system,
- partition_set_flag: dvh_partition_set_flag,
- partition_get_flag: dvh_partition_get_flag,
- partition_is_flag_available: dvh_partition_is_flag_available,
partition_set_name: dvh_partition_set_name,
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,
- get_max_supported_partition_count: dvh_get_max_supported_partition_count
+ PT_op_function_initializers (dvh)
};
static PedDiskType dvh_disk_type = {
return 0;
}
-static bool
-gpt_partition_check (const PedPartition *part)
-{
- return true;
-}
-
-#ifdef DISCOVER_ONLY
-# define NULL_IF_DISCOVER_ONLY(val) NULL
-#else
-# define NULL_IF_DISCOVER_ONLY(val) val
-#endif
+#include "pt-common.h"
+PT_define_limit_functions (gpt)
static PedDiskOps gpt_disk_ops =
{
- probe: gpt_probe,
clobber: NULL_IF_DISCOVER_ONLY (gpt_clobber),
- alloc: gpt_alloc,
- duplicate: gpt_duplicate,
- free: gpt_free,
- read: gpt_read,
write: NULL_IF_DISCOVER_ONLY (gpt_write),
- partition_new: gpt_partition_new,
- partition_duplicate: gpt_partition_duplicate,
- partition_destroy: gpt_partition_destroy,
- partition_set_system: gpt_partition_set_system,
- partition_set_flag: gpt_partition_set_flag,
- partition_get_flag: gpt_partition_get_flag,
- partition_is_flag_available: gpt_partition_is_flag_available,
+
partition_set_name: gpt_partition_set_name,
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
+
+ PT_op_function_initializers (gpt)
};
static PedDiskType gpt_disk_type =
return true;
}
-static bool
-loop_partition_check (const PedPartition* part)
-{
- return true;
-}
+#include "pt-common.h"
+PT_define_limit_functions (loop)
static PedDiskOps loop_disk_ops = {
- probe: loop_probe,
-#ifndef DISCOVER_ONLY
- clobber: loop_clobber,
-#else
- clobber: NULL,
-#endif
- alloc: loop_alloc,
- duplicate: loop_duplicate,
- free: loop_free,
- read: loop_read,
-#ifndef DISCOVER_ONLY
- write: loop_write,
-#else
- write: NULL,
-#endif
-
- partition_new: loop_partition_new,
- partition_duplicate: loop_partition_duplicate,
- partition_destroy: loop_partition_destroy,
- partition_set_system: loop_partition_set_system,
- partition_set_flag: loop_partition_set_flag,
- partition_get_flag: loop_partition_get_flag,
- partition_is_flag_available: loop_partition_is_flag_available,
+ clobber: NULL_IF_DISCOVER_ONLY (loop_clobber),
+ write: NULL_IF_DISCOVER_ONLY (loop_write),
+
partition_set_name: NULL,
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:
- loop_get_max_primary_partition_count,
- get_max_supported_partition_count:
- loop_get_max_supported_partition_count
+
+ PT_op_function_initializers (loop)
};
static PedDiskType loop_disk_type = {
return true;
}
-static bool
-mac_partition_check (const PedPartition* part)
-{
- return ptt_partition_max_start_len ("mac", part);
-}
+#include "pt-common.h"
+PT_define_limit_functions (mac)
static PedDiskOps mac_disk_ops = {
- probe: mac_probe,
-#ifndef DISCOVER_ONLY
- clobber: mac_clobber,
-#else
- clobber: NULL,
-#endif
- alloc: mac_alloc,
- duplicate: mac_duplicate,
- free: mac_free,
- read: mac_read,
-#ifndef DISCOVER_ONLY
+ clobber: NULL_IF_DISCOVER_ONLY (mac_clobber),
/* FIXME: remove this cast, once mac_write is fixed not to
modify its *DISK parameter. */
- write: (int (*) (const PedDisk*)) mac_write,
-#else
- write: NULL,
-#endif
+ write: NULL_IF_DISCOVER_ONLY ((int (*) (const PedDisk*)) mac_write),
- partition_new: mac_partition_new,
- partition_duplicate: mac_partition_duplicate,
- partition_destroy: mac_partition_destroy,
- partition_set_system: mac_partition_set_system,
- partition_set_flag: mac_partition_set_flag,
- partition_get_flag: mac_partition_get_flag,
- partition_is_flag_available: mac_partition_is_flag_available,
partition_set_name: mac_partition_set_name,
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:
- mac_get_max_primary_partition_count,
- get_max_supported_partition_count:
- mac_get_max_supported_partition_count,
+
get_partition_alignment: mac_get_partition_alignment,
+
+ PT_op_function_initializers (mac)
};
static PedDiskType mac_disk_type = {
#include <parted/debug.h>
#include <parted/endian.h>
+#include "pt-tools.h"
+
#if ENABLE_NLS
# include <libintl.h>
# define _(String) dgettext (PACKAGE, String)
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
+ clobber: NULL_IF_DISCOVER_ONLY (pc98_clobber),
+ 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 = {
--- /dev/null
+/* Factor some of the duplication out of *.c. */
+
+#ifdef DISCOVER_ONLY
+# define NULL_IF_DISCOVER_ONLY(val) NULL
+#else
+# define NULL_IF_DISCOVER_ONLY(val) val
+#endif
+
+#define PT_define_limit_functions(PT_type) \
+ \
+static bool \
+PT_type##_partition_check (const PedPartition *part) \
+{ \
+ return ptt_partition_max_start_len (#PT_type, part); \
+} \
+ \
+static PedSector \
+PT_type##_partition_max_start_sector (void) \
+{ \
+ PedSector max; \
+ int err = ptt_partition_max_start_sector (#PT_type, &max); \
+ PED_ASSERT (err == 0, return 0); \
+ return max; \
+} \
+ \
+static PedSector \
+PT_type##_partition_max_length (void) \
+{ \
+ PedSector max; \
+ int err = ptt_partition_max_length (#PT_type, &max); \
+ PED_ASSERT (err == 0, return 0); \
+ return max; \
+}
+
+#define PT_op_function_initializers(PT_type) \
+probe: PT_type##_probe, \
+alloc: PT_type##_alloc, \
+duplicate: PT_type##_duplicate, \
+free: PT_type##_free, \
+read: PT_type##_read, \
+partition_new: PT_type##_partition_new, \
+partition_duplicate: PT_type##_partition_duplicate, \
+partition_set_flag: PT_type##_partition_set_flag, \
+partition_get_flag: PT_type##_partition_get_flag, \
+partition_set_system: PT_type##_partition_set_system, \
+partition_is_flag_available: PT_type##_partition_is_flag_available, \
+partition_align: PT_type##_partition_align, \
+partition_destroy: PT_type##_partition_destroy, \
+partition_enumerate: PT_type##_partition_enumerate, \
+alloc_metadata: PT_type##_alloc_metadata, \
+get_max_primary_partition_count: PT_type##_get_max_primary_partition_count, \
+get_max_supported_partition_count:PT_type##_get_max_supported_partition_count,\
+partition_check: PT_type##_partition_check, \
+max_length: PT_type##_partition_max_length, \
+max_start_sector: PT_type##_partition_max_start_sector
gpt,UINT64_MAX,UINT64_MAX
mac,UINT32_MAX,UINT32_MAX
msdos,UINT32_MAX,UINT32_MAX
+#
+# Sun partitions are cylinder-aligned, and it looks like there are 128 sectors
+# in a cylinder. FIXME verify. Possibly compute sectors-per-cylinder, given
+# u_int16_t ntrks; /* Tracks per cylinder */
+# u_int16_t nsect; /* Sectors per track */
+sun,128ULL*UINT32_MAX,UINT32_MAX
+#
+bsd,UINT32_MAX,UINT32_MAX
+# aix,UINT32_MAX,UINT32_MAX
+loop,UINT32_MAX,UINT32_MAX
+pc98,UINT32_MAX,UINT32_MAX
+#
+# FIXME: not verified. looks like these are cylinder aligned, too
+amiga,UINT32_MAX,UINT32_MAX
#include <parted/debug.h>
#include <parted/endian.h>
+#include "pt-tools.h"
+
#ifndef MAX
# define MAX(a,b) ((a) < (b) ? (b) : (a))
#endif
return true;
}
-static bool
-amiga_partition_check (const PedPartition* part)
-{
- return true;
-}
+#include "pt-common.h"
+PT_define_limit_functions (amiga)
static PedDiskOps amiga_disk_ops = {
- probe: amiga_probe,
-#ifndef DISCOVER_ONLY
- clobber: amiga_clobber,
-#else
- clobber: NULL,
-#endif
- alloc: amiga_alloc,
- duplicate: amiga_duplicate,
- free: amiga_free,
- read: amiga_read,
-#ifndef DISCOVER_ONLY
- write: amiga_write,
-#else
- write: NULL,
-#endif
+ clobber: NULL_IF_DISCOVER_ONLY (amiga_clobber),
+ write: NULL_IF_DISCOVER_ONLY (amiga_write),
- partition_new: amiga_partition_new,
- partition_duplicate: amiga_partition_duplicate,
- partition_destroy: amiga_partition_destroy,
- partition_set_system: amiga_partition_set_system,
- partition_set_flag: amiga_partition_set_flag,
- partition_get_flag: amiga_partition_get_flag,
- partition_is_flag_available:
- amiga_partition_is_flag_available,
partition_set_name: amiga_partition_set_name,
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:
- amiga_get_max_primary_partition_count,
- get_max_supported_partition_count:
- amiga_get_max_supported_partition_count,
+
get_partition_alignment: amiga_get_partition_alignment,
+
+ PT_op_function_initializers (amiga)
};
static PedDiskType amiga_disk_type = {
return 0;
}
-static bool
-sun_partition_check (const PedPartition* part)
-{
- return true;
-}
+#include "pt-common.h"
+PT_define_limit_functions (sun)
static PedDiskOps sun_disk_ops = {
- probe: sun_probe,
-#ifndef DISCOVER_ONLY
- clobber: sun_clobber,
-#else
- clobber: NULL,
-#endif
- alloc: sun_alloc,
- duplicate: sun_duplicate,
- free: sun_free,
- read: sun_read,
-#ifndef DISCOVER_ONLY
- write: sun_write,
-#else
- write: NULL,
-#endif
+ clobber: NULL_IF_DISCOVER_ONLY (sun_clobber),
+ write: NULL_IF_DISCOVER_ONLY (sun_write),
- partition_new: sun_partition_new,
- partition_duplicate: sun_partition_duplicate,
- partition_destroy: sun_partition_destroy,
- partition_set_system: sun_partition_set_system,
- partition_set_flag: sun_partition_set_flag,
- partition_get_flag: sun_partition_get_flag,
- 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,
- get_max_supported_partition_count:
- sun_get_max_supported_partition_count,
get_partition_alignment: sun_get_partition_alignment,
partition_set_name: NULL,
partition_get_name: NULL,
+
+ PT_op_function_initializers (sun)
};
static PedDiskType sun_disk_type = {