Index: include/parted/device.h =================================================================== RCS file: /mnt/devel/CVS/parted/include/parted/device.h,v retrieving revision 1.1.1.1 diff -u -u -r1.1.1.1 device.h --- include/parted/device.h 2000/11/20 16:18:15 1.1.1.1 +++ include/parted/device.h 2000/12/08 22:55:48 @@ -24,6 +24,8 @@ #ifndef PED_DEVICE_H_INCLUDED #define PED_DEVICE_H_INCLUDED +#include + #define PED_SECTOR_SIZE 512 typedef long long PedSector; @@ -72,9 +74,16 @@ extern int ped_device_begin_external_access (PedDevice* dev); extern int ped_device_end_external_access (PedDevice* dev); +/* XXX fix my offset */ +extern int ped_device_seek (const PedDevice* dev, off_t offset); + extern int ped_device_read (const PedDevice* dev, void* buffer, + size_t count); +extern int ped_device_read_sector (const PedDevice* dev, void* buffer, PedSector start, PedSector count); extern int ped_device_write (PedDevice* dev, const void* buffer, + size_t count); +extern int ped_device_write_sector (PedDevice* dev, const void* buffer, PedSector start, PedSector count); extern int ped_device_sync (PedDevice* dev); extern PedSector ped_device_check (PedDevice* dev, void* buffer, Index: include/parted/disk_bsd.h =================================================================== RCS file: disk_bsd.h diff -N disk_bsd.h --- /dev/null Thu Aug 24 05:00:32 2000 +++ disk_bsd.h Fri Dec 8 17:55:48 2000 @@ -0,0 +1,40 @@ +/* + libparted - a library for manipulating disk partitions + Copyright (C) 1998-2000 Andrew Clausen, Lennert Buytenhek and Red Hat Inc. + + Andrew Clausen + Lennert Buytenhek + Matt Wilson, Red Hat 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 + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contributor: Matt Wilson +*/ + +#ifndef PED_DISK_BSD_H_INCLUDED +#define PED_DISK_BSD_H_INCLUDED + +typedef struct { + int16_t type; +} BSDPartitionData; + +#define BSD_NAME "bsd" + +extern void ped_disk_bsd_init (); +extern void ped_disk_bsd_done (); + + +#endif /* PED_DISK_BSD_H_INCLUDED */ + Index: libparted/Makefile.am =================================================================== RCS file: /mnt/devel/CVS/parted/libparted/Makefile.am,v retrieving revision 1.1.1.1 diff -u -u -r1.1.1.1 Makefile.am --- libparted/Makefile.am 2000/11/20 16:18:15 1.1.1.1 +++ libparted/Makefile.am 2000/12/08 22:55:48 @@ -19,7 +19,8 @@ disk_dos.c \ disk_loop.c \ disk_mac.c \ - disk_pc98.c + disk_pc98.c \ + disk_bsd.c libparted_la_LIBADD = fs_ext2/libext2.la \ fs_fat/libfat.la \ Index: libparted/device.c =================================================================== RCS file: /mnt/devel/CVS/parted/libparted/device.c,v retrieving revision 1.1.1.2 diff -u -u -r1.1.1.2 device.c --- libparted/device.c 2000/11/30 17:51:11 1.1.1.2 +++ libparted/device.c 2000/12/08 22:55:48 @@ -796,29 +796,90 @@ } static int -ped_device_seek (const PedDevice* dev, PedSector sector) +ped_device_seek_sector (const PedDevice* dev, PedSector sector) { PED_ASSERT (dev != NULL, return 0); PED_ASSERT (!dev->external_mode, return 0); #if SIZEOF_OFF_T < 8 && defined(linux) if (sizeof (off_t) < 8) { - loff_t pos = sector * 512; + loff_t pos = sector * PED_SECTOR_SIZE; return ped_llseek (dev->fd, pos, SEEK_SET) == pos; } else #endif { - off_t pos = sector * 512; + off_t pos = sector * PED_SECTOR_SIZE; return lseek (dev->fd, pos, SEEK_SET) == pos; } } + +/* XXX fix me */ +int +ped_device_seek (const PedDevice* dev, off_t offset) +{ + PED_ASSERT (dev != NULL, return 0); + PED_ASSERT (!dev->external_mode, return 0); + +#if SIZEOF_OFF_T < 8 && defined(linux) + if (sizeof (off_t) < 8) { + return ped_llseek (dev->fd, offset, SEEK_SET) == offset; + } else +#endif + { + return lseek (dev->fd, offset, SEEK_SET) == offset; + } +} + int -ped_device_read (const PedDevice* dev, void* buffer, PedSector start, - PedSector count) +ped_device_read (const PedDevice* dev, void* buffer, size_t count) { int status; PedExceptionOption ex_status; + + PED_ASSERT (dev != NULL, return 0); + PED_ASSERT (!dev->external_mode, return 0); + PED_ASSERT (buffer != NULL, return 0); + + while (1) { + status = read (dev->fd, buffer, count); + if (status == count * PED_SECTOR_SIZE) break; + if (status > 0) { + count -= status; + buffer += status; + continue; + } + + ex_status = ped_exception_throw ( + PED_EXCEPTION_ERROR, + PED_EXCEPTION_RETRY_IGNORE_CANCEL, + _("%s during read on %s"), + strerror (errno), + dev->path); + + switch (ex_status) { + case PED_EXCEPTION_IGNORE: + return 1; + + case PED_EXCEPTION_RETRY: + break; + + case PED_EXCEPTION_UNHANDLED: + ped_exception_catch (); + case PED_EXCEPTION_CANCEL: + return 0; + } + } + + return 1; +} + +int +ped_device_read_sector (const PedDevice* dev, void* buffer, PedSector start, + PedSector count) +{ + int status; + PedExceptionOption ex_status; size_t read_length = count * PED_SECTOR_SIZE; PED_ASSERT (dev != NULL, return 0); @@ -826,7 +887,7 @@ PED_ASSERT (buffer != NULL, return 0); while (1) { - if (ped_device_seek (dev, start)) + if (ped_device_seek_sector (dev, start)) break; ex_status = ped_exception_throw ( @@ -922,8 +983,67 @@ } int -ped_device_write (PedDevice* dev, const void* buffer, PedSector start, - PedSector count) +ped_device_write (PedDevice* dev, const void* buffer, size_t count) +{ + int status; + PedExceptionOption ex_status; + + PED_ASSERT (dev != NULL, return 0); + PED_ASSERT (!dev->external_mode, return 0); + PED_ASSERT (buffer != NULL, return 0); + + if (dev->read_only) { + if (ped_exception_throw ( + PED_EXCEPTION_ERROR, + PED_EXCEPTION_IGNORE_CANCEL, + _("Can't write to %s, because it is opened read-only."), + dev->path) + != PED_EXCEPTION_IGNORE) + return 0; + else + return 1; + } + +#ifdef READONLY + printf ("ped_device_write_sector (\"%s\", %p, %d, %d)\n", + dev->path, buffer, (int) start, (int) count); +#else + dev->dirty = 1; + while (1) { + status = write (dev->fd, buffer, count); + if (status == count * PED_SECTOR_SIZE) break; + if (status > 0) { + count -= status; + buffer += status; + continue; + } + + ex_status = ped_exception_throw ( + PED_EXCEPTION_ERROR, + PED_EXCEPTION_RETRY_IGNORE_CANCEL, + _("%s during write on %s"), + strerror (errno), dev->path); + + switch (ex_status) { + case PED_EXCEPTION_IGNORE: + return 1; + + case PED_EXCEPTION_RETRY: + break; + + case PED_EXCEPTION_UNHANDLED: + ped_exception_catch (); + case PED_EXCEPTION_CANCEL: + return 0; + } + } +#endif + return 1; +} + +int +ped_device_write_sector (PedDevice* dev, const void* buffer, PedSector start, + PedSector count) { int status; PedExceptionOption ex_status; @@ -946,7 +1066,7 @@ } while (1) { - if (ped_device_seek (dev, start)) + if (ped_device_seek_sector (dev, start)) break; ex_status = ped_exception_throw ( @@ -969,7 +1089,7 @@ } #ifdef READONLY - printf ("ped_device_write (\"%s\", %p, %d, %d)\n", + printf ("ped_device_write_sector (\"%s\", %p, %d, %d)\n", dev->path, buffer, (int) start, (int) count); #else dev->dirty = 1; @@ -1018,7 +1138,7 @@ PED_ASSERT (!dev->external_mode, return 0); PED_ASSERT (buffer != NULL, return 0); - if (!ped_device_seek (dev, start)) + if (!ped_device_seek_sector (dev, start)) return 0; while (1) { Index: libparted/disk_bsd.c =================================================================== RCS file: disk_bsd.c diff -N disk_bsd.c --- /dev/null Thu Aug 24 05:00:32 2000 +++ disk_bsd.c Fri Dec 8 17:55:48 2000 @@ -0,0 +1,549 @@ +/* -*- Mode: c; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + + libparted - a library for manipulating disk partitions + Copyright (C) 1998-2000 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 + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contributor: Matt Wilson +*/ + +#include "config.h" + +#include + +#include +#include +#include + +#define BSD_DISKMAGIC (0x82564557UL) /* The disk magic number */ +#define BSD_MAXPARTITIONS 8 +#define BSD_FS_UNUSED 0 /* disklabel unused partition entry ID */ +#define BSD_LABEL_OFFSET 64 + +#define BSD_DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */ +#define BSD_DTYPE_MSCP 2 /* MSCP */ +#define BSD_DTYPE_DEC 3 /* other DEC (rk, rl) */ +#define BSD_DTYPE_SCSI 4 /* SCSI */ +#define BSD_DTYPE_ESDI 5 /* ESDI interface */ +#define BSD_DTYPE_ST506 6 /* ST506 etc. */ +#define BSD_DTYPE_HPIB 7 /* CS/80 on HP-IB */ +#define BSD_DTYPE_HPFL 8 /* HP Fiber-link */ +#define BSD_DTYPE_FLOPPY 10 /* floppy */ + +#define BSD_BBSIZE 8192 /* size of boot area, with label */ +#define BSD_SBSIZE 8192 /* max size of fs superblock */ + +typedef struct _BSDRawPartition BSDRawPartition; +typedef struct _BSDRawLabel BSDRawLabel; + +struct _BSDRawPartition { /* the partition table */ + u_int32_t p_size; /* number of sectors in partition */ + u_int32_t p_offset; /* starting sector */ + u_int32_t p_fsize; /* filesystem basic fragment size */ + u_int8_t p_fstype; /* filesystem type, see below */ + u_int8_t p_frag; /* filesystem fragments per block */ + u_int16_t p_cpg; /* filesystem cylinders per group */ +}; + +struct _BSDRawLabel { + u_int32_t d_magic; /* the magic number */ + int16_t d_type; /* drive type */ + int16_t d_subtype; /* controller/d_type specific */ + int8_t d_typename[16]; /* type name, e.g. "eagle" */ + int8_t d_packname[16]; /* pack identifier */ + u_int32_t d_secsize; /* # of bytes per sector */ + u_int32_t d_nsectors; /* # of data sectors per track */ + u_int32_t d_ntracks; /* # of tracks per cylinder */ + u_int32_t d_ncylinders; /* # of data cylinders per unit */ + u_int32_t d_secpercyl; /* # of data sectors per cylinder */ + u_int32_t d_secperunit; /* # of data sectors per unit */ + u_int16_t d_sparespertrack; /* # of spare sectors per track */ + u_int16_t d_sparespercyl; /* # of spare sectors per cylinder */ + u_int32_t d_acylinders; /* # of alt. cylinders per unit */ + u_int16_t d_rpm; /* rotational speed */ + u_int16_t d_interleave; /* hardware sector interleave */ + u_int16_t d_trackskew; /* sector 0 skew, per track */ + u_int16_t d_cylskew; /* sector 0 skew, per cylinder */ + u_int32_t d_headswitch; /* head switch time, usec */ + u_int32_t d_trkseek; /* track-to-track seek, usec */ + u_int32_t d_flags; /* generic flags */ +#define NDDATA 5 + u_int32_t d_drivedata[NDDATA]; /* drive-type specific information */ +#define NSPARE 5 + u_int32_t d_spare[NSPARE]; /* reserved for future use */ + u_int32_t d_magic2; /* the magic number (again) */ + u_int16_t d_checksum; /* xor of data incl. partitions */ + + /* filesystem and partition information: */ + u_int16_t d_npartitions; /* number of partitions in following */ + u_int32_t d_bbsize; /* size of boot area at sn0, bytes */ + u_int32_t d_sbsize; /* max size of fs superblock, bytes */ + BSDRawPartition d_partitions[BSD_MAXPARTITIONS]; /* actually may be more */ +}; + +static int bsd_probe (const PedDevice *dev); +static PedDisk* bsd_open (PedDevice* dev); +static PedDisk* bsd_create (PedDevice* dev); +static int bsd_clobber (PedDevice* dev); +static int bsd_close (PedDisk* disk); +static int bsd_read (PedDisk* disk); +static int bsd_write (PedDisk* disk); + +static PedPartition* bsd_partition_new ( + const PedDisk* disk, PedPartitionType part_type, + const PedFileSystemType* fs_type, PedSector start, PedSector end); +static void bsd_partition_destroy (PedPartition* part); +static int bsd_partition_set_flag ( + PedPartition* part, PedPartitionFlag flag, int state); +static int bsd_partition_get_flag ( + const PedPartition* part, PedPartitionFlag flag); +static int bsd_partition_is_flag_available ( + const PedPartition* part, + PedPartitionFlag flag); +static int bsd_partition_align (PedPartition* part, + const PedConstraint* constraint); +static int bsd_partition_enumerate (PedPartition* part); +static int bsd_partition_set_extended_system (PedPartition* part); +static int bsd_get_max_primary_partition_count (const PedDisk* disk); + +static int bsd_alloc_metadata (PedDisk* disk); + +static PedDiskOps bsd_disk_ops = { + probe: bsd_probe, + open: bsd_open, + create: bsd_create, + clobber: bsd_clobber, + close: bsd_close, + read: bsd_read, + write: bsd_write, + + partition_new: bsd_partition_new, + partition_destroy: bsd_partition_destroy, + 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_set_extended_system: bsd_partition_set_extended_system, + + alloc_metadata: bsd_alloc_metadata, + get_max_primary_partition_count: + bsd_get_max_primary_partition_count +}; + +static PedDiskType bsd_disk_type = { + next: NULL, + name: "bsd", + ops: &bsd_disk_ops, + features: 0 +}; + +void +ped_disk_bsd_init () +{ + PED_ASSERT (sizeof (BSDRawPartition) == 16, return); + PED_ASSERT (sizeof (BSDRawLabel) == 276, return); + + ped_register_disk_type (&bsd_disk_type); +} + +void +ped_disk_bsd_done () +{ + ped_unregister_disk_type (&bsd_disk_type); +} + + +/* XXX fixme: endian? */ +static unsigned short +xbsd_dkcksum (BSDRawLabel *lp) { + unsigned short *start, *end; + unsigned short sum = 0; + + lp->d_checksum = 0; + start = (u_short *)lp; + end = (u_short *)&lp->d_partitions[lp->d_npartitions]; + while (start < end) + sum ^= *start++; + return (sum); +} + +/* XXX fixme: endian? */ +static void +alpha_bootblock_checksum (char *boot) { + u_int64_t *dp, sum; + int i; + + dp = (u_int64_t *)boot; + sum = 0; + for (i = 0; i < 63; i++) + sum += dp[i]; + dp[63] = sum; +} + + +static int +bsd_probe (const PedDevice *dev) +{ + PedDiskType* disk_type; + BSDRawLabel label; + int i; + + PED_ASSERT (dev != NULL, return 0); + + if (!ped_device_open ((PedDevice*) dev)) + return 0; + if (!ped_device_seek (dev, BSD_LABEL_OFFSET)) { + ped_device_close ((PedDevice*) dev); + return 0; + } + if (!ped_device_read (dev, &label, sizeof (label))) { + ped_device_close ((PedDevice*) dev); + return 0; + } + ped_device_close ((PedDevice*) dev); + + /* check magic */ + if (PED_LE32_TO_CPU (label.d_magic) != BSD_DISKMAGIC) + return 0; + + return 1; +} + +static PedDisk* +bsd_open (PedDevice* dev) +{ + PedDisk* disk; + + PED_ASSERT (dev != NULL, return 0); + + if (!bsd_probe (dev)) + goto error; + + if (!ped_device_open ((PedDevice*) dev)) + goto error; + disk = ped_disk_alloc (dev, &bsd_disk_type); + if (!disk) + goto error; + + if (!bsd_read (disk)) + goto error_free_disk; + + return disk; + +error_free_disk: + ped_disk_free (disk); +error: + return NULL; +} + +static int +bsd_close (PedDisk* disk) +{ + PED_ASSERT (disk != NULL, return 0); + + ped_device_close (disk->dev); + ped_disk_free (disk); + return 1; +} + + +static PedDisk* +bsd_create (PedDevice* dev) +{ + BSDRawLabel label; + + PED_ASSERT (dev != NULL, return 0); + + if (!ped_device_open ((PedDevice*) dev)) + goto error; + if (!ped_device_seek (dev, BSD_LABEL_OFFSET)) + goto error_close_dev; + if (!ped_device_read (dev, &label, sizeof (label))) + goto error_close_dev; + + memset(&label, 0, sizeof(label)); + + label.d_magic = PED_CPU_TO_LE32 (BSD_DISKMAGIC); + label.d_type = PED_CPU_TO_LE16 (BSD_DTYPE_SCSI); + label.d_flags = 0; + label.d_secsize = PED_CPU_TO_LE16 (PED_SECTOR_SIZE); + label.d_nsectors = PED_CPU_TO_LE32 (dev->sectors); + label.d_ntracks = PED_CPU_TO_LE32 (dev->heads); + label.d_ncylinders = PED_CPU_TO_LE32 (dev->cylinders); + label.d_secpercyl = PED_CPU_TO_LE32 (dev->sectors * dev->heads); + label.d_secperunit = PED_CPU_TO_LE32 (dev->sectors * dev->heads * dev->cylinders); + + label.d_rpm = PED_CPU_TO_LE16 (3600); + label.d_interleave = PED_CPU_TO_LE16 (1);; + label.d_trackskew = 0; + label.d_cylskew = 0; + label.d_headswitch = 0; + label.d_trkseek = 0; + + label.d_magic2 = PED_CPU_TO_LE32 (BSD_DISKMAGIC); + label.d_bbsize = PED_CPU_TO_LE32 (BSD_BBSIZE); + label.d_sbsize = PED_CPU_TO_LE32 (BSD_SBSIZE); + + label.d_npartitions = 0; + label.d_checksum = xbsd_dkcksum (&label); + + if (!ped_device_seek (dev, BSD_LABEL_OFFSET)) + goto error_close_dev; + if (!ped_device_write (dev, (void*) &label, sizeof(label))) + goto error_close_dev; + if (!ped_device_sync (dev)) + goto error_close_dev; + ped_device_close (dev); + return bsd_open (dev); + +error_close_dev: + ped_device_close (dev); +error: + return 0; +} + +static int +bsd_clobber (PedDevice* dev) +{ + BSDRawLabel label; + + PED_ASSERT (dev != NULL, return 0); + PED_ASSERT (bsd_probe (dev), return 0); + + if (!ped_device_open ((PedDevice*) dev)) + goto error; + if (!ped_device_seek (dev, BSD_LABEL_OFFSET)) + goto error_close_dev; + if (!ped_device_read (dev, &label, sizeof(label))) + goto error_close_dev; + + label.d_magic = 0; + + if (!ped_device_seek (dev, BSD_LABEL_OFFSET)) + goto error_close_dev; + if (!ped_device_write (dev, (void*) &label, sizeof(label))) + goto error_close_dev; + if (!ped_device_sync (dev)) + goto error_close_dev; + ped_device_close (dev); + return 1; + +error_close_dev: + ped_device_close (dev); +error: + return 0; +} + +static int +bsd_read (PedDisk* disk) +{ + BSDRawLabel label; + int i, s; + PedPartition* part; + PedSector start, end; + PedConstraint* constraint_exact; + + PED_ASSERT (disk != NULL, return 0); + PED_ASSERT (disk->dev != NULL, return 0); + + ped_disk_delete_all (disk); + + if (!ped_device_seek (disk->dev, BSD_LABEL_OFFSET)) + goto error; + if (!ped_device_read (disk->dev, (void*) &label, sizeof(label))) + goto error; + + for (i = 0; i < BSD_MAXPARTITIONS; i++) { + if (!label.d_partitions[i].p_size + || !label.d_partitions[i].p_fstype) + continue; + start = PED_LE32_TO_CPU(label.d_partitions[i].p_offset); + end = PED_LE32_TO_CPU(label.d_partitions[i].p_offset) + + PED_LE32_TO_CPU(label.d_partitions[i].p_size - 1); + part = ped_partition_new (disk, PED_PARTITION_PRIMARY, NULL, + start, end); + if (!part) + goto error; + part->num = i + 1; + part->fs_type = ped_file_system_probe (&part->geom); + constraint_exact = ped_constraint_exact (part); + if (!ped_disk_add_partition (disk, part, constraint_exact)) + goto error; + ped_constraint_destroy (constraint_exact); + } + return 1; + + error: + return 0; +} + +static int +bsd_write (PedDisk* disk) +{ + BSDRawLabel label; + BSDPartitionData* bsd_data; + PedPartition* part; + int i, max_part; + char boot[512]; + + PED_ASSERT (disk != NULL, return 0); + PED_ASSERT (disk->dev != NULL, return 0); + + + if (!ped_device_seek (disk->dev, BSD_LABEL_OFFSET)) + return 0; + if (!ped_device_read (disk->dev, &label, sizeof(label))) + return 0; + + memset (label.d_partitions, 0, + sizeof (BSDRawPartition) * BSD_MAXPARTITIONS); + + for (i = 0; i < BSD_MAXPARTITIONS; i++) { + part = ped_disk_get_partition (disk, i); + if (!part) + continue; + bsd_data = part->disk_specific; + label.d_partitions[i - 1].p_fstype = bsd_data->type; + label.d_partitions[i - 1].p_offset = part->geom.start; + label.d_partitions[i - 1].p_size = part->geom.length; + max_part = i; + } + + label.d_npartitions = PED_CPU_TO_LE16 (max_part + 1); + label.d_checksum = xbsd_dkcksum (&label); + + if (!ped_device_seek (disk->dev, BSD_LABEL_OFFSET)) + return 0; + if (!ped_device_write (disk->dev, (void*) &label, sizeof (label))) + return 0; + if (!ped_device_seek (disk->dev, 0)) + return 0; + if (!ped_device_read (disk->dev, &boot, sizeof(boot))) + return 0; + alpha_bootblock_checksum(boot); + if (!ped_device_write (disk->dev, (void*) boot, sizeof(boot))) + return 0; + if (!ped_device_sync (disk->dev)) + return 0; + + return 1; +} + +static PedPartition* +bsd_partition_new (const PedDisk* disk, PedPartitionType part_type, + const PedFileSystemType* fs_type, + PedSector start, PedSector end) +{ + PedPartition* part; + BSDPartitionData* bsd_data; + + part = ped_partition_alloc (disk, part_type, fs_type, start, end); + if (!part) + goto error; + + if (ped_partition_is_active (part)) { + part->disk_specific + = bsd_data = ped_malloc (sizeof (BSDPartitionData)); + if (!bsd_data) + goto error_free_part; + bsd_data->type = 0; + + if (fs_type && !ped_partition_set_system (part, fs_type)) + goto error_free_bsd_data; + } else { + part->disk_specific = NULL; + } + return part; + +error_free_bsd_data: + ped_free (bsd_data); +error_free_part: + ped_free (part); +error: + return 0; +} + + +static void +bsd_partition_destroy (PedPartition* part) +{ + PED_ASSERT (part != NULL, return); + + if (ped_partition_is_active (part)) + ped_free (part->disk_specific); + ped_free (part); +} + + +static int +bsd_partition_set_flag (PedPartition* part, PedPartitionFlag flag, int state) +{ + /* no flags for bsd */ + return 0; +} + + +static int +bsd_partition_get_flag (const PedPartition* part, PedPartitionFlag flag) +{ + /* no flags for bsd */ + return 0; +} + +static int +bsd_partition_is_flag_available (const PedPartition* part, + PedPartitionFlag flag) +{ + /* no flags for bsd */ + return 0; +} + + +static int +bsd_get_max_primary_partition_count (const PedDisk* disk) +{ + return BSD_MAXPARTITIONS; +} + +static int +bsd_partition_set_extended_system (PedPartition* part) +{ + return 1; +} + +static int +bsd_partition_align (PedPartition* part, const PedConstraint* constraint) +{ + /* no alignment problems */ + return 1; +} + +static int +bsd_partition_enumerate (PedPartition* part) +{ + /* never change the partition numbers */ + return 1; +} + +static int +bsd_alloc_metadata (PedDisk* disk) +{ + /* no metadata per partition */ + return 1; +} Index: libparted/disk_dos.c =================================================================== RCS file: /mnt/devel/CVS/parted/libparted/disk_dos.c,v retrieving revision 1.1.1.2 diff -u -u -r1.1.1.2 disk_dos.c --- libparted/disk_dos.c 2000/11/30 17:51:11 1.1.1.2 +++ libparted/disk_dos.c 2000/12/08 22:55:48 @@ -216,7 +216,7 @@ if (!ped_device_open ((PedDevice*) dev)) return 0; - if (!ped_device_read (dev, &part_table, 0, 1)) { + if (!ped_device_read_sector (dev, &part_table, 0, 1)) { ped_device_close ((PedDevice*) dev); return 0; } @@ -309,7 +309,7 @@ if (!ped_device_open ((PedDevice*) dev)) goto error; - if (!ped_device_read (dev, &table, 0, 1)) + if (!ped_device_read_sector (dev, &table, 0, 1)) goto error_close_dev; if (!table.boot_code[0]) @@ -318,7 +318,7 @@ memset (table.partitions, 0, sizeof (DosRawPartition) * 4); table.magic = PED_CPU_TO_LE16 (MSDOS_MAGIC); - if (!ped_device_write (dev, (void*) &table, 0, 1)) + if (!ped_device_write_sector (dev, (void*) &table, 0, 1)) goto error_close_dev; if (!ped_device_sync (dev)) goto error_close_dev; @@ -351,12 +351,12 @@ if (!ped_device_open ((PedDevice*) dev)) goto error; - if (!ped_device_read (dev, &table, 0, 1)) + if (!ped_device_read_sector (dev, &table, 0, 1)) goto error_close_dev; table.magic = 0; - if (!ped_device_write (dev, (void*) &table, 0, 1)) + if (!ped_device_write_sector (dev, (void*) &table, 0, 1)) goto error_close_dev; if (!ped_device_sync (dev)) goto error_close_dev; @@ -758,7 +758,7 @@ PED_ASSERT (disk != NULL, return 0); PED_ASSERT (disk->dev != NULL, return 0); - if (!ped_device_read (disk->dev, (void*) &table, sector, 1)) + if (!ped_device_read_sector (disk->dev, (void*) &table, sector, 1)) goto error; /* weird: empty extended partitions are filled with 0xf6 by PM */ @@ -951,7 +951,7 @@ return 0; } - return ped_device_write (disk->dev, (void*) &table, sector, 1); + return ped_device_write_sector (disk->dev, (void*) &table, sector, 1); } static int @@ -964,7 +964,7 @@ memset (&table, 0, sizeof (DosRawTable)); table.magic = PED_CPU_TO_LE16 (MSDOS_MAGIC); - return ped_device_write (disk->dev, (void*) &table, sector, 1); + return ped_device_write_sector (disk->dev, (void*) &table, sector, 1); } /* Find the first logical partition, and write the partition table for it. @@ -995,7 +995,7 @@ PED_ASSERT (disk != NULL, return 0); PED_ASSERT (disk->dev != NULL, return 0); - ped_device_read (disk->dev, &table, 0, 1); + ped_device_read_sector (disk->dev, &table, 0, 1); if (!table.boot_code[0]) query_write_boot_code (disk->dev, &table); @@ -1017,7 +1017,7 @@ } } - if (!ped_device_write (disk->dev, (void*) &table, 0, 1)) + if (!ped_device_write_sector (disk->dev, (void*) &table, 0, 1)) return 0; if (!ped_device_sync (disk->dev)) return 0; Index: libparted/disk_loop.c =================================================================== RCS file: /mnt/devel/CVS/parted/libparted/disk_loop.c,v retrieving revision 1.1.1.2 diff -u -u -r1.1.1.2 disk_loop.c --- libparted/disk_loop.c 2000/11/30 17:51:11 1.1.1.2 +++ libparted/disk_loop.c 2000/12/08 22:55:48 @@ -161,7 +161,7 @@ memset (buf, 0, 512); strcpy (buf, LOOP_SIGNATURE); - if (!ped_device_write (dev, buf, 0, 1)) + if (!ped_device_write_sector (dev, buf, 0, 1)) goto error_close_dev; ped_device_close (dev); @@ -187,7 +187,7 @@ goto error; while (loop_probe (dev)) { - if (!ped_device_write (dev, buf, i++, 1)) + if (!ped_device_write_sector (dev, buf, i++, 1)) goto error_close_dev; } @@ -222,7 +222,7 @@ PED_ASSERT (disk != NULL, return 0); ped_disk_delete_all (disk); - if (!ped_device_read (disk->dev, buf, 0, 1)) + if (!ped_device_read_sector (disk->dev, buf, 0, 1)) goto error; if (!strncmp (buf, LOOP_SIGNATURE, strlen (LOOP_SIGNATURE))) return 1; @@ -265,7 +265,7 @@ memset (buf, 0, 512); strcpy (buf, LOOP_SIGNATURE); - return ped_device_write (disk->dev, buf, 0, 1); + return ped_device_write_sector (disk->dev, buf, 0, 1); } static PedPartition* Index: libparted/disk_mac.c =================================================================== RCS file: /mnt/devel/CVS/parted/libparted/disk_mac.c,v retrieving revision 1.1.1.2 diff -u -u -r1.1.1.2 disk_mac.c --- libparted/disk_mac.c 2000/11/30 17:51:11 1.1.1.2 +++ libparted/disk_mac.c 2000/12/08 22:55:48 @@ -222,7 +222,7 @@ if (!ped_device_open ((PedDevice*) dev)) goto error; - if (!ped_device_read ((PedDevice*) dev, &buf, 0, 1)) + if (!ped_device_read_sector ((PedDevice*) dev, &buf, 0, 1)) goto error_close_dev; ped_device_close ((PedDevice*) dev); return _check_signature (&buf); @@ -381,7 +381,7 @@ if (!ped_device_open (dev)) goto error; - if (!ped_device_write (dev, buf, 0, 1)) + if (!ped_device_write_sector (dev, buf, 0, 1)) goto error_close_dev; ped_device_close (dev); return 1; @@ -672,7 +672,7 @@ int i; for (i = 1; i < 64; i *= 2) { - if (!ped_device_read (disk->dev, &raw_part, i, 1)) + if (!ped_device_read_sector (disk->dev, &raw_part, i, 1)) return 0; if (_rawpart_check_signature (&raw_part) && !_rawpart_is_void (&raw_part)) { @@ -707,7 +707,7 @@ mac_disk_data = disk->disk_specific; mac_disk_data->part_map_entry_num = 0; /* 0 == none */ - if (!ped_device_read (disk->dev, &raw_disk, 0, 1)) + if (!ped_device_read_sector (disk->dev, &raw_disk, 0, 1)) goto error; if (!_check_signature (&raw_disk)) goto error; @@ -722,7 +722,7 @@ goto error; for (num=1; num==1 || num <= last_part_entry_num; num++) { - if (!ped_device_read (disk->dev, &raw_part, + if (!ped_device_read_sector (disk->dev, &raw_part, num * ghost_size, 1)) goto error_delete_all; @@ -945,7 +945,7 @@ raw_disk.block_count = PED_CPU_TO_BE32 (dev->length / (dev->sector_size / 512)); - return ped_device_write (dev, &raw_disk, 0, 1); + return ped_device_write_sector (dev, &raw_disk, 0, 1); } static int @@ -1002,7 +1002,7 @@ _generate_empty_part (disk, num, part_map); /* write to disk */ - if (!ped_device_write (dev, part_map, 1, + if (!ped_device_write_sector (dev, part_map, 1, mac_disk_data->part_map_entry_count)) goto error_free_part_map; ped_free (part_map); Index: libparted/disk_pc98.c =================================================================== RCS file: /mnt/devel/CVS/parted/libparted/disk_pc98.c,v retrieving revision 1.1.1.2 diff -u -u -r1.1.1.2 disk_pc98.c --- libparted/disk_pc98.c 2000/11/30 17:51:11 1.1.1.2 +++ libparted/disk_pc98.c 2000/12/08 22:55:48 @@ -249,7 +249,7 @@ if (!ped_device_open ((PedDevice*) dev)) return 0; - if (!ped_device_read (dev, &part_table, 0, 2)) { + if (!ped_device_read_sector (dev, &part_table, 0, 2)) { ped_device_close ((PedDevice*) dev); return 0; } @@ -321,7 +321,7 @@ if (!ped_device_open (dev)) goto error; - if (!ped_device_read (dev, &table, 0, 2)) + if (!ped_device_read_sector (dev, &table, 0, 2)) goto error_close_dev; if (!pc98_check_ipl_signature (&table)) { @@ -332,7 +332,7 @@ memset (table.partitions, 0, sizeof (table.partitions)); table.magic = PED_CPU_TO_LE16(PC9800_EXTFMT_MAGIC); - if (!ped_device_write (dev, (void*) &table, 0, 2)) + if (!ped_device_write_sector (dev, (void*) &table, 0, 2)) goto error_close_dev; if (!ped_device_sync (dev)) goto error_close_dev; @@ -365,7 +365,7 @@ if (!ped_device_open ((PedDevice*) dev)) goto error; - if (!ped_device_read (dev, &table, 0, 1)) + if (!ped_device_read_sector (dev, &table, 0, 1)) goto error_close_dev; memset (table.partitions, 0, sizeof (table.partitions)); @@ -374,7 +374,7 @@ if (pc98_check_ipl_signature (&table)) memset (table.boot_code, 0, sizeof (table.boot_code)); - if (!ped_device_write (dev, (void*) &table, 0, 1)) + if (!ped_device_write_sector (dev, (void*) &table, 0, 1)) goto error_close_dev; if (!ped_device_sync (dev)) goto error_close_dev; @@ -462,7 +462,7 @@ PED_ASSERT (disk != NULL, return 0); PED_ASSERT (disk->dev != NULL, return 0); - if (!ped_device_read (disk->dev, (void*) &table, 0, 2)) + if (!ped_device_read_sector (disk->dev, (void*) &table, 0, 2)) goto error; if (!pc98_check_magic(&table)) { @@ -625,7 +625,7 @@ PED_ASSERT (disk != NULL, return 0); PED_ASSERT (disk->dev != NULL, return 0); - ped_device_read (disk->dev, &table, 0, 2); + ped_device_read_sector (disk->dev, &table, 0, 2); if (!pc98_check_ipl_signature (&table)) { memset (table.boot_code, 0, sizeof(table.boot_code)); @@ -644,7 +644,7 @@ return 0; } - if (!ped_device_write (disk->dev, (void*) &table, 0, 2)) + if (!ped_device_write_sector (disk->dev, (void*) &table, 0, 2)) return 0; if (!ped_device_sync (disk->dev)) return 0; Index: libparted/geom.c =================================================================== RCS file: /mnt/devel/CVS/parted/libparted/geom.c,v retrieving revision 1.1.1.2 diff -u -u -r1.1.1.2 geom.c --- libparted/geom.c 2000/11/30 17:51:11 1.1.1.2 +++ libparted/geom.c 2000/12/08 22:55:48 @@ -204,7 +204,7 @@ return exception_status == PED_EXCEPTION_IGNORE; } - if (!ped_device_read (geom->disk->dev, buffer, real_start, count)) + if (!ped_device_read_sector (geom->disk->dev, buffer, real_start, count)) return 0; return 1; } @@ -239,7 +239,7 @@ return exception_status == PED_EXCEPTION_IGNORE; } - if (!ped_device_write (geom->disk->dev, buffer, real_start, count)) + if (!ped_device_write_sector (geom->disk->dev, buffer, real_start, count)) return 0; return 1; } Index: libparted/libparted.c =================================================================== RCS file: /mnt/devel/CVS/parted/libparted/libparted.c,v retrieving revision 1.1.1.2 diff -u -u -r1.1.1.2 libparted.c --- libparted/libparted.c 2000/11/30 17:51:11 1.1.1.2 +++ libparted/libparted.c 2000/12/08 22:55:48 @@ -63,6 +63,7 @@ ped_disk_msdos_init (); ped_disk_pc98_init (); ped_disk_mac_init (); + ped_disk_bsd_init (); } static void @@ -97,6 +98,7 @@ ped_disk_pc98_done (); ped_disk_loop_done (); ped_disk_mac_done (); + ped_disk_bsd_done (); } static void Index: libparted/fs_ext2/interface.c =================================================================== RCS file: /mnt/devel/CVS/parted/libparted/fs_ext2/interface.c,v retrieving revision 1.1.1.2 diff -u -u -r1.1.1.2 interface.c --- libparted/fs_ext2/interface.c 2000/11/30 17:51:11 1.1.1.2 +++ libparted/fs_ext2/interface.c 2000/12/08 22:55:48 @@ -30,6 +30,7 @@ #include #include #include +#include #include "ext2.h" #include "parted_io.h" @@ -334,6 +335,12 @@ else strcpy (mac_data->system_name, "Apple_UNIX_SVR2"); mac_data->status = 0x33; + return 1; + } + + if (strcmp (disk_type->name, BSD_NAME) == 0) { + BSDPartitionData* bsd_data = part->disk_specific; + bsd_data->type = 0x8; return 1; } Index: libparted/fs_linux_swap/linux_swap.c =================================================================== RCS file: /mnt/devel/CVS/parted/libparted/fs_linux_swap/linux_swap.c,v retrieving revision 1.1.1.1 diff -u -u -r1.1.1.1 linux_swap.c --- libparted/fs_linux_swap/linux_swap.c 2000/11/20 16:18:15 1.1.1.1 +++ libparted/fs_linux_swap/linux_swap.c 2000/12/08 22:55:48 @@ -31,6 +31,7 @@ #include #include #include +#include #include #if ENABLE_NLS @@ -562,6 +563,12 @@ return 0; } mac_data->status = 0x33; + return 1; + } + + if (strcmp (disk_type->name, BSD_NAME) == 0) { + BSDPartitionData* bsd_data = part->disk_specific; + bsd_data->type = 0x1; return 1; }