/*
libparted - a library for manipulating disk partitions
- Copyright (C) 2000, 2002, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2002, 2004, 2007-2009 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
- the Free Software Foundation; either version 2 of the License, or
+ 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,
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, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
+#include <config.h>
#include <parted/parted.h>
#include <parted/debug.h>
#include <parted/endian.h>
+#include <stdbool.h>
#if ENABLE_NLS
# include <libintl.h>
# define _(String) (String)
#endif /* ENABLE_NLS */
+#include "misc.h"
+
/* struct's hacked from Linux source: fs/partitions/mac.h
* I believe it was originally written by Paul Mackerras (from comments in
* Quik source)
#define MAC_STATUS_BOOTABLE 8 /* partition is bootable */
-typedef struct {
+typedef struct _MacRawPartition MacRawPartition;
+typedef struct _MacRawDisk MacRawDisk;
+typedef struct _MacDeviceDriver MacDeviceDriver;
+typedef struct _MacPartitionData MacPartitionData;
+typedef struct _MacDiskData MacDiskData;
+
+struct __attribute__ ((packed)) _MacRawPartition {
uint16_t signature; /* expected to be MAC_PARTITION_MAGIC */
uint16_t res1;
uint32_t map_count; /* # blocks in partition map */
char processor[16]; /* Contains 680x0, x=0,2,3,4; or empty */
uint32_t driver_sig;
char _padding[372];
-} __attribute__ ((packed)) MacRawPartition;
+};
/* Driver descriptor structure, in block 0 */
-typedef struct {
+struct __attribute__ ((packed)) _MacRawDisk {
uint16_t signature; /* expected to be MAC_DRIVER_MAGIC */
uint16_t block_size; /* physical sector size */
uint32_t block_count; /* size of device in blocks */
uint16_t dev_id; /* reserved */
uint32_t data; /* reserved */
uint16_t driver_count; /* # of driver descriptor entries */
- uint8_t driverlist[488]; /* info about available drivers */
+ uint8_t driverlist[488];/* info about available drivers */
uint16_t padding[3]; /* pad to 512 bytes */
-} __attribute__ ((packed)) MacRawDisk;
+};
-typedef struct {
+struct __attribute__ ((packed)) _MacDeviceDriver {
uint32_t block; /* startblock in MacRawDisk->block_size units */
uint16_t size; /* size in 512 byte units */
uint16_t type; /* operating system type (MacOS = 1) */
-} __attribute__ ((packed)) MacDeviceDriver;
+};
-typedef struct {
+struct _MacPartitionData {
char volume_name[33]; /* eg: "Games" */
char system_name[33]; /* eg: "Apple_Unix_SVR2" */
char processor_name[17];
uint32_t status;
uint32_t driver_sig;
-} MacPartitionData;
+};
-typedef struct {
+struct _MacDiskData {
int ghost_size; /* sectors per "driver" block */
int part_map_entry_count; /* # entries (incl. ghost) */
int part_map_entry_num; /* partition map location */
uint16_t block_size; /* physical sector size */
uint16_t driver_count;
MacDeviceDriver driverlist[1 + 60]; /* 488 bytes */
-} MacDiskData;
+};
static PedDiskType mac_disk_type;
if (part_map_size == 0)
part_map_size = 64;
- new_part = ped_partition_new (disk, 0, NULL, 1, part_map_size - 1);
+ new_part = ped_partition_new (disk, PED_PARTITION_NORMAL, NULL,
+ 1, part_map_size - 1);
if (!new_part)
goto error;
return 0;
}
-PedDisk*
+static PedDisk*
mac_alloc (const PedDevice* dev)
{
PedDisk* disk;
memcpy (new_mac_data, old_mac_data, sizeof (MacDiskData));
return new_disk;
-error_free_new_disk:
_ped_disk_free (new_disk);
error:
return NULL;
MacDiskData* mac_disk_data = disk->disk_specific;
_ped_disk_free (disk);
- ped_free (mac_disk_data);
+ free (mac_disk_data);
}
#ifndef DISCOVER_ONLY
#endif /* !DISCOVER_ONLY */
static int
-_rawpart_cmp_type (MacRawPartition* raw_part, char* type)
+_rawpart_cmp_type (const MacRawPartition* raw_part, const char* type)
{
return strncasecmp (raw_part->type, type, 32) == 0;
}
static int
-_rawpart_cmp_name (MacRawPartition* raw_part, char* name)
+_rawpart_cmp_name (const MacRawPartition* raw_part, const char* name)
{
return strncasecmp (raw_part->name, name, 32) == 0;
}
static int
-_rawpart_is_partition_map (MacRawPartition* raw_part)
+_rawpart_is_partition_map (const MacRawPartition* raw_part)
{
return _rawpart_cmp_type (raw_part, "Apple_partition_map");
}
}
static int
-_rawpart_is_boot (MacRawPartition* raw_part)
+_rawpart_is_boot (const MacRawPartition* raw_part)
{
if (!strcasecmp(raw_part->type, "Apple_Bootstrap"))
return 1;
}
static int
-_rawpart_is_driver (MacRawPartition* raw_part)
+_rawpart_is_driver (const MacRawPartition* raw_part)
{
if (strncmp (raw_part->type, "Apple_", 6) != 0)
return 0;
}
static int
-_rawpart_has_driver (MacRawPartition* raw_part, MacDiskData* mac_disk_data)
+_rawpart_has_driver (const MacRawPartition* raw_part, MacDiskData* mac_disk_data)
{
MacDeviceDriver *driverlist;
uint16_t i, bsz;
#endif
return NULL;
}
- part = ped_partition_new (disk, 0, NULL, start, start + length - 1);
+ part = ped_partition_new (disk, PED_PARTITION_NORMAL, NULL,
+ start, start + length - 1);
if (!part)
goto error;
if (!ped_device_write (disk->dev, part_map, 1,
mac_disk_data->part_map_entry_count))
goto error_free_part_map;
- ped_free (part_map);
+ free (part_map);
return write_block_zero (disk, mac_driverdata);
error_free_part_map:
- ped_free (part_map);
+ free (part_map);
error_free_driverdata:
- ped_free (mac_driverdata);
+ free (mac_driverdata);
error:
return 0;
}
}
return part;
-error_free_mac_data:
- ped_free (mac_data);
+ free (mac_data);
error_free_part:
- ped_free (part);
+ free (part);
error:
return 0;
}
PED_ASSERT (part != NULL, return);
if (ped_partition_is_active (part))
- ped_free (part->disk_specific);
- ped_free (part);
+ free (part->disk_specific);
+ free (part);
}
static int
part->fs_type = fs_type;
- if (fs_type && !strcmp (fs_type->name, "linux-swap"))
+ if (fs_type && is_linux_swap (fs_type->name))
ped_partition_set_flag (part, PED_PARTITION_SWAP, 1);
if (mac_data->is_boot) {
static int
mac_partition_set_flag (PedPartition* part, PedPartitionFlag flag, int state)
{
- PedFileSystemType* hfs = ped_file_system_type_get ("hfs");
MacPartitionData* mac_data;
PED_ASSERT (part != NULL, return 0);
- mac_disk_data->free_part_entry_count + 1;
}
+static bool
+mac_get_max_supported_partition_count (const PedDisk* disk, int *max_n)
+{
+ *max_n = 65536;
+ return true;
+}
+
static PedDiskOps mac_disk_ops = {
probe: mac_probe,
#ifndef DISCOVER_ONLY
free: mac_free,
read: mac_read,
#ifndef DISCOVER_ONLY
- write: mac_write,
+ /* 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
alloc_metadata: mac_alloc_metadata,
get_max_primary_partition_count:
- mac_get_max_primary_partition_count
+ mac_get_max_primary_partition_count,
+ get_max_supported_partition_count:
+ mac_get_max_supported_partition_count
};
static PedDiskType mac_disk_type = {
PED_ASSERT (sizeof (MacRawPartition) == 512, return);
PED_ASSERT (sizeof (MacRawDisk) == 512, return);
- ped_register_disk_type (&mac_disk_type);
+ ped_disk_type_register (&mac_disk_type);
}
void
ped_disk_mac_done ()
{
- ped_unregister_disk_type (&mac_disk_type);
+ ped_disk_type_unregister (&mac_disk_type);
}