Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

AHDI label editor

  • Loading branch information...
commit 16ac5d3ddeb9f8472cb84645b7357bea3bbddcb3 1 parent a2bca40
leo authored
View
13 sys/arch/atari/stand/ahdilabel/Makefile
@@ -0,0 +1,13 @@
+# $NetBSD: Makefile,v 1.1.1.1 2000/08/07 09:23:41 leo Exp $
+
+PROG= ahdilabel
+SRCS= ahdilabel.c build.c check.c cksum.c magic.c openraw.c read.c write.c \
+ writedtab.c
+
+MAN= ahdilabel.8
+MANSUBDIR= /atari
+
+WARNS= 1
+
+CFLAGS += -g
+.include <bsd.prog.mk>
View
167 sys/arch/atari/stand/ahdilabel/ahdilabel.8
@@ -0,0 +1,167 @@
+.\" $NetBSD: ahdilabel.8,v 1.1.1.1 2000/08/07 09:23:41 leo Exp $
+.\"
+.\"
+.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Julian Coleman and Leo Weppelman.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+
+.Dd July 29, 2000
+.Dt AHDILABEL 8
+.Os
+.Sh NAME
+.Nm ahdilabel
+.Nd modify AHDI partitions
+.Sh SYNOPSIS
+.Nm ahdilabel
+.Ar disk
+.Sh DESCRIPTION
+.Nm ahdilabel
+allows you to modify the AHDI partition table on a disk partitioned with
+AHDI or an AHDI compatible formatter. The AHDI partition format is usually
+only present on disks shared between
+.Nx
+and some other OS. The partition identifiers are used by
+.Nx
+as a guideline to emulate a disklabel on such a disk.
+.Pp
+.Nm ahdilabel
+supports the following options:
+.Pp
+.Bl -tag -width disk
+.It Ar disk
+The name of the disk you want to edit.
+.Nm ahdilabel
+will first try to open a disk of this name. If this cannot
+be opened, it will attempt to open
+.Ar r Ns <disk> Ns Ar c .
+Finally, if this also cannot be opened, it will attempt to open
+.Ar /dev/r Ns <disk> Ns Ar c .
+.El
+.Pp
+.Nm ahdilabel
+will display information about the number of sectors, tracks
+and sectors on the disk, as well as the current AHDI partition information.
+It will then prompt for input. The input choices are:
+.Pp
+.Bl -tag -width a-p
+.It Ar a-p
+Modify a partition. You will be prompted for a partition id, root, start
+and size.
+.Nx
+recognises the following partition id's:
+.Pp
+.Bl -tag -width "GEM or BGM" -compact
+.It NBD
+Partition is reserved for
+.Nx .
+This can be either a root or an user partition. The first NBD
+partition on a disk will be mapped to
+.Nx partition
+letter
+.Em a .
+The following NBD partitions will be mapped from letter
+.Em d
+up.
+The filesystem type is ffs by default.
+.It SWP
+The first SWP partition is mapped to partition
+.Em b.
+.It GEM or BGM
+These partitions are mapped from
+.Em d
+up. The filesystem type is msdos.
+.El
+.Pp
+The root, start and size parameters can be entered using sector or
+cylinder/track/sector notation. Whole numbers of cylinders can be entered
+using the shorthand <cylinder>/. Likewise, whole numbers of tracks can be
+entered using the shorthand <cylinder>/<track>/.
+.Pp
+The sector holding the primary AHDI partition table only has space for four
+partitions. Thus, if a disk has more than four partitions, the extra
+partition information is held in auxilliary root sectors. There is one
+auxilliary root for each additional partition (and also for the fourth
+partition, if the disk has more than four partitions).
+.It Ar r
+Recalculate the root sectors. This will automatically assign auxilliary
+root sectors if the disk has more than 4 partitions. The auxilliary root
+sectors will be positioned in a default location preceeding the relevant
+partition.
+.It Ar s
+Show the current partition information.
+.It Ar u
+Toggle the unit display between sector and cylinder/track/sector notation.
+.It Ar w
+Write the AHDI partition table to the disk.
+.It Ar q
+Quit
+.El
+.Sh EXAMPLES
+.Dl ahdilabel sd0
+Edit the AHDI label for disk sd0.
+.Sh CAVEATS
+The changes made to the AHDI partitions will become active on the next
+.Em first open
+of the disk. You are advised to use
+.Nm ahdilabel
+only on a disk without any mounted or otherwise active partitions. This
+is not enforced by
+.Nm ahdilabel.
+.Pp
+Because of way
+.Nx
+interprets AHDI partition tables to create the
+.Nx
+disklabel, the
+.Nx
+partition ordering may change if partitions labelled NBD are created or
+removed.
+.Pp
+Creating an AHDI partition table on a disk that previously did not have
+one will almost certainly overwrite any existing partition information
+and/or data on that disk. This is especially the case if auxilliary root
+sectors are needed for the AHDI partition table.
+.Pp
+As soon as a disk contains at least one NBD partition, you are allowed to
+write
+.Nx
+disklabels and install bootstraps.
+.Sh SEE ALSO
+.Xr bootpref 8 ,
+.Xr disklabel 8 ,
+.Xr installboot 8
+.Sh HISTORY
+The
+.Nm ahdilabel
+command first appeared in
+.Nx 1.5 .
View
362 sys/arch/atari/stand/ahdilabel/ahdilabel.c
@@ -0,0 +1,362 @@
+/* $NetBSD: ahdilabel.c,v 1.1.1.1 2000/08/07 09:23:40 leo Exp $ */
+
+/*
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Julian Coleman.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "privahdi.h"
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <strings.h>
+
+/*
+ * I think we can safely assume a fixed blocksize - AHDI won't support
+ * something different...
+ */
+#define BLPM ((1024 * 1024) / DEV_BSIZE)
+#define UNITS_SECTORS 0
+#define UNITS_CTS 1
+
+int main (int, char*[]);
+void show_parts (struct ahdi_ptable*, int, int, int);
+void get_input (char *, int);
+char *sec_to_cts (struct ahdi_ptable*, u_int32_t, char *);
+u_int32_t read_sector (struct ahdi_ptable*,char *);
+void change_part (struct ahdi_ptable*, int, int);
+
+int
+main (argc, argv)
+ int argc;
+ char *argv[];
+{
+ struct ahdi_ptable ptable;
+ int flags, rv, key, units;
+
+ if (argc < 2) {
+ fprintf (stderr, "usage: %s raw_disk\n", argv[0]);
+ exit (EXIT_FAILURE);
+ }
+
+ flags = 0;
+ while ((rv = ahdi_readlabel(&ptable, argv[1], flags)) != 1) {
+ switch (rv) {
+ case -1:
+ fprintf (stderr,
+ "%s: %s: %s\n", argv[0], argv[1],
+ strerror (errno));
+ exit (EXIT_FAILURE);
+ break;
+ case -2:
+ fprintf (stderr,
+ "%s: disk not 512 bytes/sector\n", argv[0]);
+ exit (EXIT_FAILURE);
+ break;
+ case -3:
+ printf ("No AHDI partitions found. Continue (y/N)?");
+ if (toupper(getchar()) == 'Y') {
+ (void) fpurge(stdin);
+ flags |= FORCE_AHDI;
+ } else
+ exit (EXIT_FAILURE);
+ break;
+ case -4:
+ case -5:
+ case -6:
+ printf ("Errors reading AHDI partition table. Override (y/N)? ");
+ if (toupper(getchar()) == 'Y') {
+ (void) fpurge(stdin);
+ flags |= AHDI_IGN_EXISTS | AHDI_IGN_EXT |
+ AHDI_IGN_CKSUM | AHDI_IGN_SPU;
+ } else
+ exit (EXIT_FAILURE);
+ break;
+ case 1:
+ /* Everything is OK */
+ break;
+ default:
+ exit (EXIT_FAILURE);
+ break;
+ }
+ }
+
+ units = UNITS_SECTORS;
+ show_parts (&ptable, 0, ptable.nparts, units);
+ key = 0;
+ while (key != 'Q') {
+ (void) fpurge(stdin);
+ printf ("Change [a-p], r)ecalculate, s)how, u)nits, w)rite or q)uit ");
+ key = toupper(getchar());
+ if (key == EOF)
+ key = 'Q';
+ if (key >= 'A' && key <= 'P') {
+ change_part (&ptable, key - 'A', units);
+ }
+ if (key == 'R') {
+ if (ahdi_buildlabel (&ptable))
+ printf ("Partiton table adjusted\n");
+ }
+ if (key == 'S') {
+ show_parts (&ptable, 0, ptable.nparts, units);
+ }
+ if (key == 'U') {
+ if (units == UNITS_SECTORS)
+ units = UNITS_CTS;
+ else
+ units = UNITS_SECTORS;
+ }
+ if (key == 'W') {
+ if ((rv = ahdi_writelabel (&ptable, argv[1], 0)) < 0) {
+ if (rv == -1)
+ perror ("\0");
+ if (rv == -2)
+ printf ("Invalid number of partitions!\n");
+ if (rv == -3)
+ printf ("GEM partition should be BGM or BGM partition should be GEM!\n");
+ if (rv == -4)
+ printf ("Partition overlaps root sector or bad sector list (starts before sector 2)!\n");
+ if (rv == -5)
+ printf ("Partition extends past end of disk!\n");
+ if (rv == -6)
+ printf ("Partitions overlap!\n");
+ if (rv == -7)
+ printf ("Partition overlaps auxilliary root!\n");
+ if (rv == -8)
+ printf ("More than 4 partitions in root sector!\n");
+ if (rv == -9)
+ printf ("More than 1 partition in an auxiliary root!\n");
+ if (rv < -1 && ahdi_errp1 != -1)
+ printf ("\tpartition %c has errors.\n",
+ ahdi_errp1 + 'a');
+ if (rv < -1 && ahdi_errp2 != -1)
+ printf ("\tpartition %c has errors.\n",
+ ahdi_errp2 + 'a');
+ }
+ }
+ }
+ return (0);
+}
+
+void
+show_parts (ptable, start, finish, units)
+ struct ahdi_ptable *ptable;
+ int start, finish, units;
+{
+ int i;
+
+ printf ("Disk information :\n");
+ printf (" sectors/track: %d\n", ptable->nsectors);
+ printf (" tracks/cylinder: %d\n", ptable->ntracks);
+ printf (" sectors/cylinder: %d\n", ptable->secpercyl);
+ printf (" cylinders: %d\n", ptable->ncylinders);
+ printf (" total sectors: %d\n", ptable->secperunit);
+
+ if (units == UNITS_SECTORS) {
+ printf (" # id root start end size MBs\n");
+ for (i = start; i < finish; i++) {
+ printf (" %c %c%c%c %8u %8u %8u %8u (%4u)\n",
+ i + 'a', ptable->parts[i].id[0],
+ ptable->parts[i].id[1], ptable->parts[i].id[2],
+ ptable->parts[i].root, ptable->parts[i].start,
+ ptable->parts[i].start +
+ (ptable->parts[i].size ?
+ ptable->parts[i].size - 1 : 0),
+ ptable->parts[i].size,
+ (ptable->parts[i].size + (BLPM >> 1)) / BLPM);
+ }
+ } else {
+ u_int32_t cylinder, track, sector;
+ printf (" # id root start end size MBs\n");
+ for (i = start; i < finish; i++) {
+ printf (" %c %c%c%c ", i + 'a',
+ ptable->parts[i].id[0], ptable->parts[i].id[1],
+ ptable->parts[i].id[2]);
+ sector = ptable->parts[i].root;
+ cylinder = sector / ptable->secpercyl;
+ sector -= cylinder * ptable->secpercyl;
+ track = sector / ptable->nsectors;
+ sector -= track * ptable->nsectors;
+ printf ("%5u/%2u/%3u ", cylinder, track, sector);
+ sector = ptable->parts[i].start;
+ cylinder = sector / ptable->secpercyl;
+ sector -= cylinder * ptable->secpercyl;
+ track = sector / ptable->nsectors;
+ sector -= track * ptable->nsectors;
+ printf ("%5u/%2u/%3u ", cylinder, track, sector);
+ sector = ptable->parts[i].start +
+ (ptable->parts[i].size ?
+ ptable->parts[i].size - 1 : 0),
+ cylinder = sector / ptable->secpercyl;
+ sector -= cylinder * ptable->secpercyl;
+ track = sector / ptable->nsectors;
+ sector -= track * ptable->nsectors;
+ printf ("%5u/%2u/%3u ", cylinder, track, sector);
+ sector = ptable->parts[i].size;
+ cylinder = sector / ptable->secpercyl;
+ sector -= cylinder * ptable->secpercyl;
+ track = sector / ptable->nsectors;
+ sector -= track * ptable->nsectors;
+ printf ("%5u/%2u/%3u ", cylinder, track, sector);
+ printf ("(%4u)\n",
+ (ptable->parts[i].size + (BLPM >> 1)) / BLPM);
+ }
+ }
+}
+
+void
+get_input (buf, len)
+ char *buf;
+ int len;
+{
+ int count, key;
+
+ count = 0;
+ (void) fpurge(stdin);
+ while (count < (len - 1) && key != '\n' && key != '\r') {
+ key = getchar();
+ buf[count] = key;
+ count++;
+ }
+ buf[count] = '\0';
+}
+
+char *
+sec_to_cts (ptable, sector, cts)
+ struct ahdi_ptable *ptable;
+ u_int32_t sector;
+ char *cts;
+{
+ u_int32_t cylinder, track;
+
+ cylinder = sector / ptable->secpercyl;
+ sector -= cylinder * ptable->secpercyl;
+ track = sector / ptable->nsectors;
+ sector -= track * ptable->nsectors;
+ sprintf (cts, "%u/%u/%u", cylinder, track, sector);
+ return (cts);
+}
+
+u_int32_t
+read_sector (ptable, buf)
+ struct ahdi_ptable *ptable;
+ char *buf;
+{
+ u_int32_t sector, track, cylinder;
+
+ sector = track = cylinder = 0;
+ if ((strchr (buf, '/') != NULL) &&
+ ((sscanf (buf, "%u/%u/%u", &cylinder, &track, &sector) == 3) ||
+ (sscanf (buf, "%u/%u/", &cylinder, &track) == 2) ||
+ (sscanf (buf, "%u/", &cylinder) == 1))) {
+ if (sector > ptable->nsectors || track > ptable->ntracks ||
+ cylinder > ptable->ncylinders)
+ return (0);
+ sector += ptable->nsectors * track;
+ sector += ptable->secpercyl * cylinder;
+ return (sector);
+ }
+ if (sscanf (buf, "%u", &sector) == 1)
+ return (sector);
+ return (0);
+}
+
+void
+change_part (ptable, part, units)
+ struct ahdi_ptable *ptable;
+ int part, units;
+{
+#define BUFLEN 20
+#define CTSLEN 64
+ char buf[BUFLEN], cts[CTSLEN];
+ u_int32_t sector;
+
+ if (part > ptable->nparts) {
+ part = ptable->nparts;
+ printf ("Changing partition %c!\n", part + 'a');
+ ptable->nparts++;
+ }
+ if (part == ptable->nparts)
+ ptable->nparts++;
+ show_parts (ptable, part, part + 1, units);
+
+ printf ("id [%c%c%c] ", ptable->parts[part].id[0],
+ ptable->parts[part].id[1], ptable->parts[part].id[2]);
+ get_input (&buf[0], BUFLEN);
+ if (buf[0] != '\n' && buf[0] != '\r') {
+ ptable->parts[part].id[0] = buf[0];
+ ptable->parts[part].id[1] = buf[1];
+ ptable->parts[part].id[2] = buf[2];
+ }
+
+ printf ("root [%8u (%s)] ", ptable->parts[part].root,
+ sec_to_cts (ptable, ptable->parts[part].root, &cts[0]));
+ get_input (&buf[0], BUFLEN);
+ if (buf[0] != '\n' && buf[0] != '\r') {
+ sector = read_sector (ptable, buf);
+ ptable->parts[part].root = sector;
+ }
+
+ printf ("start [%8u (%s)] ", ptable->parts[part].start,
+ sec_to_cts (ptable, ptable->parts[part].start, &cts[0]));
+ get_input (&buf[0], BUFLEN);
+ if (buf[0] != '\n' && buf[0] != '\r') {
+ sector = read_sector (ptable, buf);
+ if (sector)
+ ptable->parts[part].start = sector;
+ }
+
+ printf ("size [%8u (%s)] ", ptable->parts[part].size,
+ sec_to_cts (ptable, ptable->parts[part].size, &cts[0]));
+ get_input (&buf[0], BUFLEN);
+ if (buf[0] != '\n' && buf[0] != '\r') {
+ sector = read_sector (ptable, buf);
+ if (sector)
+ ptable->parts[part].size = sector;
+ }
+
+/*
+ printf ("NetBSD disk letter [%c] ", ptable->parts[part].letter + 'a');
+ get_input (&buf[0], BUFLEN);
+ if (buf[0] != '\n' && buf[0] != '\r')
+ if (buf[0] == 'a' || (buf[0] >= 'd' && buf[0] <= 'p'))
+ ptable->parts[part].letter = buf[0] - 'a';
+*/
+
+ if (!ptable->parts[part].start && !ptable->parts[part].size) {
+ if (part == ptable->nparts - 1)
+ ptable->nparts--;
+ }
+}
View
92 sys/arch/atari/stand/ahdilabel/build.c
@@ -0,0 +1,92 @@
+/* $NetBSD: build.c,v 1.1.1.1 2000/08/07 09:23:40 leo Exp $ */
+
+/*
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Julian Coleman, Waldi Ravens and Leo Weppelman.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "privahdi.h"
+#include <strings.h>
+
+/*
+ * Build AHDI auxillary roots (extended partitions).
+ * Always make first 3 partitions real.
+ */
+int
+ahdi_buildlabel (ptable)
+ struct ahdi_ptable *ptable;
+{
+ int i, j;
+ struct ahdi_ptable old_table;
+
+ /* Copy original ptable */
+ bcopy (ptable, &old_table, sizeof (struct ahdi_ptable));
+
+ /*
+ * Adjust partition starts. Do this first because some
+ * partitioning tools (ICD) change the relative ordering of
+ * auxiliary roots vs. partitions.
+ */
+ for (i = 0; i < ptable->nparts; i++)
+ for (j = 0; j < ptable->nparts; j++)
+ if (ptable->parts[j].start ==
+ ptable->parts[i].root + 1) {
+ if (ptable->parts[j].start)
+ ptable->parts[j].start--;
+ if (ptable->parts[j].size)
+ ptable->parts[j].size++;
+ }
+ for (i = 0; i < ptable->nparts; i++) {
+ /* Remove auxiliary roots for first 3 (or all) partitions */
+ if (i < 3 || (i < 4 && ptable->nparts < 5)) {
+ ptable->parts[i].root = 0;
+ /* Create auxiliary roots for other partitions */
+ } else {
+ ptable->parts[i].root = ptable->parts[i].start;
+ if (ptable->parts[i].start)
+ ptable->parts[i].start++;
+ if (ptable->parts[i].size)
+ ptable->parts[i].size--;
+ }
+ }
+
+ /* Compare old and new */
+ for (i = 0; i < ptable->nparts; i++)
+ if (ptable->parts[i].root != old_table.parts[i].root ||
+ ptable->parts[i].start != old_table.parts[i].start ||
+ ptable->parts[i].size != old_table.parts[i].size)
+ return (1);
+
+ return (0);
+}
View
146 sys/arch/atari/stand/ahdilabel/check.c
@@ -0,0 +1,146 @@
+/* $NetBSD: check.c,v 1.1.1.1 2000/08/07 09:23:40 leo Exp $ */
+
+/*
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Julian Coleman, Waldi Ravens and Leo Weppelman.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "privahdi.h"
+
+/* Partitions which have errors */
+int ahdi_errp1;
+int ahdi_errp2;
+
+/*
+ * Check partitions for consistency :
+ * GEM vs BGM
+ * Start sector > 2
+ * End sector < secperunit
+ * other partition overlap
+ * auxiliary root overlap
+ * Number of partitions in root/auxiliary root
+ */
+int
+ahdi_checklabel (ptable)
+ struct ahdi_ptable *ptable;
+{
+ int i, j, rcount, acount;
+ u_int32_t i_end, j_end;
+
+ ahdi_errp1 = -1;
+ ahdi_errp2 = -1;
+
+ if (ptable->nparts < 1 || ptable->nparts > MAXPARTITIONS)
+ return (-2);
+
+ rcount = 0;
+ acount = 0;
+
+ for (i = 0; i < ptable->nparts; i++) {
+
+ /* GEM vs BGM */
+ if (ptable->parts[i].size > 32768) {
+ if (AHDI_MKPID (ptable->parts[i].id[0],
+ ptable->parts[i].id[1], ptable->parts[i].id[2])
+ == AHDI_PID_GEM) {
+ ahdi_errp1 = i;
+ return (-3);
+ }
+ } else {
+ if (AHDI_MKPID (ptable->parts[i].id[0],
+ ptable->parts[i].id[1], ptable->parts[i].id[2])
+ == AHDI_PID_BGM) {
+ ahdi_errp1 = i;
+ return (-3);
+ }
+ }
+
+ /* Need 2 free sectors at start for root and bad sector list */
+ if (ptable->parts[i].start < 2) {
+ ahdi_errp1 = i;
+ return (-4);
+ }
+
+ i_end = ptable->parts[i].start + ptable->parts[i].size - 1;
+
+ /* Check partition does not extend past end of disk */
+ if (i_end > ptable->secperunit) {
+ ahdi_errp1 = i;
+ return (-5);
+ }
+
+ for (j = i + 1; j < ptable->nparts; j++) {
+ /* Check for overlap with other partitions */
+ j_end = ptable->parts[j].start + ptable->parts[j].size
+ - 1;
+ if ((ptable->parts[j].start >= ptable->parts[i].start
+ && ptable->parts[j].start <= i_end) ||
+ (j_end >= ptable->parts[i].start &&
+ j_end <= i_end)) {
+ ahdi_errp1 = i;
+ ahdi_errp2 = j;
+ return (-6);
+ }
+ /* Check number of partitions in auxiliary root */
+ if (ptable->parts[i].root &&
+ ptable->parts[i].root == ptable->parts[j].root) {
+ ahdi_errp1 = i;
+ ahdi_errp2 = j;
+ return (-9);
+ }
+ }
+
+ for (j = i; j < ptable->nparts; j++)
+ /* Check for overlap with auxiliary root(s) */
+ if (ptable->parts[j].root >= ptable->parts[i].start &&
+ ptable->parts[j].root <= i_end) {
+ ahdi_errp1 = i;
+ return (-7);
+ }
+
+ /* Count partitions in root/auxiliary roots */
+ if (ptable->parts[i].root)
+ acount ++;
+ else
+ rcount ++;
+
+ }
+ /* Check number of partitions in root sector */
+ if (acount)
+ rcount++;
+ if (rcount > 4)
+ return (-8);
+ else
+ return (1);
+}
View
73 sys/arch/atari/stand/ahdilabel/cksum.c
@@ -0,0 +1,73 @@
+/* $NetBSD: cksum.c,v 1.1.1.1 2000/08/07 09:23:40 leo Exp $ */
+
+/*
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Julian Coleman, Waldi Ravens and Leo Weppelman.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "privahdi.h"
+
+/*
+ * Disklabel checksum.
+ */
+
+int
+dkcksum (dl)
+ struct disklabel *dl;
+{
+ u_short *start, *end, sum = 0;
+
+ start = (u_short *)dl;
+ end = (u_short *)&dl->d_partitions[dl->d_npartitions];
+ while (start < end)
+ sum ^= *start++;
+ return (sum);
+}
+
+/*
+ * AHDI root sector checksum.
+ */
+
+u_int16_t
+ahdi_cksum (buf)
+ void *buf;
+{
+ u_int16_t *p = (u_int16_t *)buf;
+ u_int16_t csum = 0;
+ int i;
+
+ for (i = 0; i < 256; i++)
+ csum += *p++;
+ return ((0x1234 - csum) & 0xffff);
+}
View
81 sys/arch/atari/stand/ahdilabel/magic.c
@@ -0,0 +1,81 @@
+/* $NetBSD: magic.c,v 1.1.1.1 2000/08/07 09:23:40 leo Exp $ */
+
+/*
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Julian Coleman, Waldi Ravens and Leo Weppelman.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "privahdi.h"
+#include <stdlib.h>
+
+/*
+ * Check label magic numbers for AHDI partitions
+ */
+int
+check_magic(fd, offset, flags)
+ int fd;
+ u_int offset;
+ int flags;
+{
+ u_char *bblk;
+ u_int nsec;
+ int rv = 1;
+
+ nsec = (BBMINSIZE + (DEV_BSIZE - 1)) / DEV_BSIZE;
+ bblk = disk_read(fd, offset, nsec);
+ if (bblk != NULL) {
+ u_int *end, *p;
+
+ end = (u_int *)&bblk[BBMINSIZE - sizeof(struct disklabel)];
+ for (p = (u_int *)bblk; p < end; ++p) {
+ struct disklabel *dl = (struct disklabel *)&p[1];
+ if (((p[0] == NBDAMAGIC && offset == 0 &&
+ !(flags & FORCE_AHDI)) ||
+ (p[0] == AHDIMAGIC && offset != 0) ||
+ (u_char *)dl - bblk == 7168) &&
+ dl->d_npartitions <= MAXPARTITIONS &&
+ dl->d_magic2 == DISKMAGIC &&
+ dl->d_magic == DISKMAGIC &&
+ dkcksum(dl) == 0) {
+ rv = -3;
+ break;
+ }
+ }
+ free(bblk);
+ }
+ else
+ rv = -1;
+
+ return (rv);
+}
View
68 sys/arch/atari/stand/ahdilabel/openraw.c
@@ -0,0 +1,68 @@
+/* $NetBSD: openraw.c,v 1.1.1.1 2000/08/07 09:23:40 leo Exp $ */
+
+/*
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Julian Coleman, Waldi Ravens and Leo Weppelman.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "privahdi.h"
+#include <fcntl.h>
+#include <paths.h>
+#include <stdio.h>
+#include <machine/disklabel.h>
+
+/*
+ * Open raw disk partition.
+ */
+int
+openraw (name, flags)
+ const char *name;
+ int flags;
+{
+ char buf[MAXPATHLEN];
+ int f;
+
+ if ((f = open (name, flags)) != -1)
+ return (f);
+
+ snprintf (buf, MAXPATHLEN, "r%s%c", name, RAW_PART + 'a');
+ if ((f = open (buf, flags)) != -1)
+ return (f);
+
+ snprintf (buf, MAXPATHLEN, "%sr%s%c", _PATH_DEV, name, RAW_PART + 'a');
+ if ((f = open (buf, flags)) != -1)
+ return (f);
+
+ return (0);
+}
View
94 sys/arch/atari/stand/ahdilabel/privahdi.h
@@ -0,0 +1,94 @@
+/* $NetBSD: privahdi.h,v 1.1.1.1 2000/08/07 09:23:41 leo Exp $ */
+
+/*
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Julian Coleman, Waldi Ravens and Leo Weppelman.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <sys/disklabel.h>
+#include <machine/ahdilabel.h>
+
+/* Flags for ahdi_readlabel() */
+#define FORCE_AHDI 0x01 /* Read AHDI label when NetBSD label exists */
+#define AHDI_IGN_EXISTS 0x02 /* Ignore partition exists flag (ICD tools) */
+#define AHDI_IGN_EXT 0x04 /* Ignore last extended parition (HDDriver) */
+#define AHDI_IGN_CKSUM 0x08 /* Ignore checksum mismatch on root sector */
+#define AHDI_IGN_SPU 0x10 /* Ignore total sectors mismatch */
+
+/* Flags for ahdi_writelabel() */
+#define AHDI_KEEP_BOOT 0x01 /* Keep boot sector */
+#define AHDI_KEEP_BSL 0x02 /* Keep bad sector list */
+#define AHDI_KEEP_NBDA 0x04 /* Keep NetBSD label */
+
+struct ptable_part {
+ u_int8_t flag; /* partition flag */
+ u_int8_t id[3]; /* id: GEM, BGM, NBD, ... */
+ u_int32_t root; /* root sector */
+ u_int32_t start; /* start sector */
+ u_int32_t size; /* size in sectors */
+ int letter; /* partition letter */
+};
+
+struct ahdi_ptable {
+ u_int32_t nsectors; /* number of sectors/track */
+ u_int32_t ntracks; /* number of tracks/cylinder */
+ u_int32_t ncylinders; /* number of cylinders */
+ u_int32_t secpercyl; /* number of sectors/cylinder */
+ u_int32_t secperunit; /* number of total sectors */
+ int nparts; /* number of partitions */
+ struct ptable_part parts[MAXPARTITIONS];
+};
+
+int ahdi_buildlabel __P((struct ahdi_ptable *));
+int ahdi_checklabel __P((struct ahdi_ptable *));
+int ahdi_readlabel __P((struct ahdi_ptable *, char *, int));
+int ahdi_writedisktab __P((struct ahdi_ptable *, char *, char *, char *));
+int ahdi_writelabel __P((struct ahdi_ptable *, char *, int));
+
+extern int ahdi_errp1, ahdi_errp2;
+
+/* Internal functions */
+u_int16_t ahdi_cksum __P((void *));
+void assign_letters __P((struct ahdi_ptable *));
+int check_magic __P((int, u_int, int));
+int dkcksum __P((struct disklabel *));
+void *disk_read __P((int, u_int, u_int));
+int disk_write __P((int, u_int, u_int, void *));
+int invalidate_netbsd_label __P((int, u_int32_t));
+int openraw __P((const char *, int));
+struct disklabel *read_dl __P((int));
+int read_rsec __P((int, struct ahdi_ptable *, u_int,
+ u_int, int));
+int write_bsl __P((int));
View
280 sys/arch/atari/stand/ahdilabel/read.c
@@ -0,0 +1,280 @@
+/* $NetBSD: read.c,v 1.1.1.1 2000/08/07 09:23:40 leo Exp $ */
+
+/*
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Julian Coleman, Waldi Ravens and Leo Weppelman.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "privahdi.h"
+#include <fcntl.h>
+#include <stdlib.h>
+#include <strings.h>
+#include <unistd.h>
+#include <sys/dkio.h>
+#include <sys/ioctl.h>
+
+/*
+ * Read AHDI partitions from disk.
+ */
+int
+ahdi_readlabel (ptable, diskname, flags)
+ struct ahdi_ptable *ptable;
+ char *diskname;
+ int flags;
+{
+ int fd, rv;
+ struct disklabel *dl;
+
+ if (!(fd = openraw (diskname, O_RDONLY)))
+ return (-1);
+
+ if ((dl = read_dl (fd)) == NULL) {
+ close (fd);
+ return (-1);
+ }
+
+ if (dl->d_secsize != AHDI_BSIZE) {
+ close (fd);
+ return (-2);
+ }
+
+ if ((rv = check_magic(fd, LABELSECTOR, flags)) < 0) {
+ close (fd);
+ return (rv);
+ }
+
+ bzero ((void *) ptable, sizeof (struct ahdi_ptable));
+
+ if ((rv = read_rsec (fd, ptable, AHDI_BBLOCK, AHDI_BBLOCK, flags))
+ < 0) {
+ close (fd);
+ return (rv);
+ }
+
+ if (dl->d_secperunit != ptable->secperunit) {
+ if (flags & AHDI_IGN_SPU)
+ ptable->secperunit = dl->d_secperunit;
+ else {
+ close (fd);
+ return (-6);
+ }
+ }
+
+ ptable->nsectors = dl->d_nsectors;
+ ptable->ntracks = dl->d_ntracks;
+ ptable->ncylinders = dl->d_ncylinders;
+ ptable->secpercyl = dl->d_secpercyl;
+
+ assign_letters (ptable);
+
+ close (fd);
+ return (1);
+}
+
+/*
+ * Read AHDI partitions from root sector/auxillary root sector.
+ */
+int
+read_rsec (fd, ptable, rsec, esec, flags)
+ int fd;
+ struct ahdi_ptable *ptable;
+ u_int rsec, esec;
+ int flags;
+{
+ struct ahdi_part *part, *end;
+ struct ahdi_root *root;
+ u_int16_t cksum, newcksum;
+ int rv;
+
+ if ((root = disk_read (fd, rsec, 1)) == NULL) {
+ return (-1);
+ }
+
+ if (rsec == AHDI_BBLOCK) {
+ end = &root->ar_parts[AHDI_MAXRPD];
+ if (root->ar_checksum) {
+ cksum = root->ar_checksum;
+ root->ar_checksum = 0;
+ newcksum = ahdi_cksum (root);
+ if ((cksum != newcksum) && !(flags & AHDI_IGN_CKSUM)) {
+ free (root);
+ return (-4);
+ }
+ }
+ ptable->secperunit=root->ar_hdsize;
+ } else
+ end = &root->ar_parts[AHDI_MAXARPD];
+ for (part = root->ar_parts; part < end; ++part) {
+#ifdef DEBUG
+ printf ("Found partitions at sector %u:\n", rsec);
+ printf (" flags : %02x\n", part->ap_flg);
+ printf (" id : %c%c%c\n", part->ap_id[0], part->ap_id[1],
+ part->ap_id[2]);
+ printf (" start : %u\n", part->ap_st);
+ printf (" size : %u\n", part->ap_size);
+#endif
+ if (!(part->ap_flg & 0x01)) {
+ if ((part->ap_id[0] || part->ap_id[1] ||
+ part->ap_id[2]) && (flags & AHDI_IGN_EXISTS))
+ part->ap_flg &= 0x01;
+ else
+ continue;
+ }
+
+ if (AHDI_MKPID (part->ap_id[0], part->ap_id[1],
+ part->ap_id[2]) == AHDI_PID_XGM) {
+ u_int offs = part->ap_st + esec;
+ if ((rv = read_rsec (fd, ptable, offs,
+ esec == AHDI_BBLOCK ? offs : esec, flags)) < 0) {
+ free (root);
+ return (rv);
+ }
+ } else {
+ /* Attempt to check for junk values */
+ if (((part->ap_st + rsec) > ptable->secperunit ||
+ (part->ap_st + rsec + part->ap_size -1) >
+ ptable->secperunit)) {
+ if (flags & AHDI_IGN_EXT) {
+ /* Fake previous partition */
+ ptable->parts[ptable->nparts].id[0] =
+ part->ap_id[0];
+ ptable->parts[ptable->nparts].id[1] =
+ part->ap_id[1];
+ ptable->parts[ptable->nparts].id[2] =
+ part->ap_id[2];
+ } else {
+ free (root);
+ return (-5);
+ }
+ }
+ ptable->parts[ptable->nparts].flag = part->ap_flg;
+ ptable->parts[ptable->nparts].id[0] = part->ap_id[0];
+ ptable->parts[ptable->nparts].id[1] = part->ap_id[1];
+ ptable->parts[ptable->nparts].id[2] = part->ap_id[2];
+ ptable->parts[ptable->nparts].root = rsec;
+ ptable->parts[ptable->nparts].start =
+ part->ap_st + rsec;
+ ptable->parts[ptable->nparts].size = part->ap_size;
+ ptable->nparts++;
+ }
+ }
+ free (root);
+ if (ptable->nparts || FORCE_AHDI)
+ return (1);
+ else
+ return (-3);
+}
+
+/*
+ * Read a sector from the disk.
+ */
+void *
+disk_read (fd, start, count)
+ int fd;
+ u_int start,
+ count;
+{
+ void *buffer;
+ off_t offset;
+ size_t size;
+
+
+ size = count * DEV_BSIZE;
+ offset = start * DEV_BSIZE;
+
+ if ((buffer = malloc (size)) == NULL)
+ return (NULL);
+
+ if (lseek (fd, offset, SEEK_SET) != offset) {
+ free (buffer);
+ return (NULL);
+ }
+ if (read (fd, buffer, size) != size) {
+ free (buffer);
+ return (NULL);
+ }
+ return (buffer);
+}
+
+/*
+ * Assign NetBSD drive letters to partitions
+ */
+void
+assign_letters (ptable)
+ struct ahdi_ptable *ptable;
+{
+ int i, have_root, pno;
+ u_int32_t pid;
+
+#define ROOT_PART 0
+
+ have_root = 0;
+ pno = 0;
+
+ for (i = 0; i < ptable->nparts; i++) {
+ while (pno == ROOT_PART || pno == SWAP_PART || pno == RAW_PART)
+ pno++;
+ pid = AHDI_MKPID (ptable->parts[i].id[0],
+ ptable->parts[i].id[1], ptable->parts[i].id[2]);
+ if (!have_root && pid == AHDI_PID_NBD) {
+ ptable->parts[i].letter = ROOT_PART;
+ have_root = 1;
+ } else if (pid == AHDI_PID_SWP)
+ ptable->parts[i].letter = SWAP_PART;
+ else {
+ ptable->parts[i].letter = pno;
+ pno++;
+ }
+ }
+}
+
+/*
+ * Read disklabel for disk.
+ */
+struct disklabel *
+read_dl (fd)
+ int fd;
+{
+ struct disklabel *dl;
+
+ if ((dl = malloc (sizeof (struct disklabel))) == NULL) {
+ return (NULL);
+ }
+
+ if (ioctl (fd, DIOCGDINFO, dl) < 0) {
+ free (dl);
+ return (NULL);
+ }
+ return (dl);
+}
View
351 sys/arch/atari/stand/ahdilabel/write.c
@@ -0,0 +1,351 @@
+/* $NetBSD: write.c,v 1.1.1.1 2000/08/07 09:23:40 leo Exp $ */
+
+/*
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Julian Coleman, Waldi Ravens and Leo Weppelman.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "privahdi.h"
+#include <fcntl.h>
+#include <stdlib.h>
+#include <strings.h>
+#include <unistd.h>
+#include <sys/dkio.h>
+#include <sys/ioctl.h>
+
+#define BSL_MAGIC 0xa5
+#define BSL_OFFSET 1
+#define BSL_SIZE 1
+
+/*
+ * Write AHDI partitions to disk
+ */
+
+int
+ahdi_writelabel (ptable, diskname, flags)
+ struct ahdi_ptable *ptable;
+ char *diskname;
+ int flags;
+{
+ int fd, i, j, k, firstxgm, keep;
+ struct ahdi_root *root;
+ u_int rsec;
+ u_int32_t xgmsec, nbdsec;
+
+ if (!(fd = openraw (diskname, O_RDWR)))
+ return (-1);
+
+ if ((i = ahdi_checklabel (ptable)) < 0) {
+ close (fd);
+ return (i);
+ }
+
+ if (flags & AHDI_KEEP_BOOT) {
+ if ((root = disk_read (fd, AHDI_BBLOCK, 1)) == NULL) {
+ return (-1);
+ }
+ bzero ((void *) root->ar_parts,
+ sizeof (struct ahdi_part) * AHDI_MAXRPD);
+ } else {
+ if ((root = malloc (sizeof (struct ahdi_root))) == NULL) {
+ close (fd);
+ return (-1);
+ }
+ bzero ((void *) root, sizeof (struct ahdi_root));
+ }
+
+ nbdsec = 0;
+#ifdef DEBUG
+ printf ("Writing root sector\n");
+#endif
+
+ /* All partitions in root sector (including first XGM) */
+ j = 0;
+ firstxgm = 0;
+ for (i = 0; i < ptable->nparts; i++) {
+ if (ptable->parts[i].root == 0) {
+#ifdef DEBUG
+ printf (" Partition %d - ", j);
+#endif
+ root->ar_parts[j].ap_flg = 0x01;
+ for (k = 0; k < 3; k++) {
+ root->ar_parts[j].ap_id[k] =
+ ptable->parts[i].id[k];
+#ifdef DEBUG
+ printf ("%c", root->ar_parts[j].ap_id[k]);
+#endif
+ }
+ root->ar_parts[j].ap_st = ptable->parts[i].start;
+ root->ar_parts[j].ap_size = ptable->parts[i].size;
+#ifdef DEBUG
+ printf ("/%u/%u\n", root->ar_parts[j].ap_st,
+ root->ar_parts[j].ap_size);
+#endif
+
+ j++;
+ } else if (!firstxgm) {
+ root->ar_parts[j].ap_flg = 0x01;
+ root->ar_parts[j].ap_id[0] = 'X';
+ root->ar_parts[j].ap_id[1] = 'G';
+ root->ar_parts[j].ap_id[2] = 'M';
+ root->ar_parts[j].ap_st = ptable->parts[i].root;
+ root->ar_parts[j].ap_size = ptable->parts[i].size + 1;
+ firstxgm = i;
+ xgmsec = ptable->parts[i].root;
+#ifdef DEBUG
+ printf (" Partition %d - XGM/%u/%u\n", j,
+ root->ar_parts[j].ap_st,
+ root->ar_parts[j].ap_size);
+#endif
+ j++;
+ }
+ /*
+ * Note first netbsd partition for invalidate_netbsd_label().
+ */
+ if (!nbdsec && AHDI_MKPID (ptable->parts[i].id[0],
+ ptable->parts[i].id[1], ptable->parts[i].id[2])
+ == AHDI_PID_NBD) {
+ nbdsec = ptable->parts[i].start;
+ }
+ }
+
+ root->ar_hdsize = ptable->secperunit;
+ if (!(flags & AHDI_KEEP_BSL)) {
+ root->ar_bslst = (u_int32_t) BSL_OFFSET;
+ root->ar_bslsize = (u_int32_t) BSL_SIZE;
+ }
+ root->ar_checksum = ahdi_cksum (root);
+
+ if (!disk_write (fd, AHDI_BBLOCK, 1, root)) {
+ free (root);
+ close (fd);
+ return (-1);
+ }
+
+ /* Auxiliary roots */
+ for (i = firstxgm; i < ptable->nparts; i++) {
+ j = 0;
+ if (ptable->parts[i].root == 0)
+ continue;
+#ifdef DEBUG
+ printf ("Writing auxiliary root at sector %u\n",
+ ptable->parts[i].root);
+#endif
+ bzero ((void *) root, sizeof (struct ahdi_root));
+ rsec = ptable->parts[i].root;
+#ifdef DEBUG
+ printf (" Partition %d - ", j);
+#endif
+ root->ar_parts[j].ap_flg = 0x01;
+ for (k = 0; k < 3; k++) {
+ root->ar_parts[j].ap_id[k] =
+ ptable->parts[i].id[k];
+#ifdef DEBUG
+ printf ("%c", root->ar_parts[j].ap_id[k]);
+#endif
+ }
+ root->ar_parts[j].ap_st = ptable->parts[i].start -
+ rsec;
+ root->ar_parts[j].ap_size = ptable->parts[i].size;
+#ifdef DEBUG
+ printf ("/%u/%u\n", root->ar_parts[j].ap_st,
+ root->ar_parts[j].ap_size);
+#endif
+ j++;
+ if (i < ptable->nparts - 1) {
+ /* Need an XGM? */
+ if (ptable->parts[i].root != ptable->parts[i+1].root &&
+ ptable->parts[i+1].root != 0) {
+ root->ar_parts[j].ap_flg = 0x01;
+ root->ar_parts[j].ap_id[0] = 'X';
+ root->ar_parts[j].ap_id[1] = 'G';
+ root->ar_parts[j].ap_id[2] = 'M';
+ root->ar_parts[j].ap_st =
+ ptable->parts[i+1].root - xgmsec;
+ root->ar_parts[j].ap_size =
+ ptable->parts[i+1].size + 1;
+#ifdef DEBUG
+ printf (" Partition %d - XGM/%u/%u\n", j,
+ root->ar_parts[j].ap_st,
+ root->ar_parts[j].ap_size);
+#endif
+ root->ar_parts[j].ap_size = 0;
+ }
+ if (ptable->parts[i].root == ptable->parts[i+1].root) {
+ /* Next partition has same auxiliary root */
+#ifdef DEBUG
+ printf (" Partition %d - ", j);
+#endif
+ root->ar_parts[j].ap_flg = 0x01;
+ for (k = 0; k < 3; k++) {
+ root->ar_parts[j].ap_id[k] =
+ ptable->parts[i+1].id[k];
+#ifdef DEBUG
+ printf ("%c", root->ar_parts[j].ap_id[k]);
+#endif
+ }
+ root->ar_parts[j].ap_st =
+ ptable->parts[i+1].start - rsec;
+ root->ar_parts[j].ap_size =
+ ptable->parts[i+1].size;
+#ifdef DEBUG
+ printf ("/%u/%u\n", root->ar_parts[j].ap_st,
+ root->ar_parts[j].ap_size);
+#endif
+ i++;
+ }
+ j++;
+ }
+
+ if (!disk_write (fd, rsec, 1, root)) {
+ close (fd);
+ free (root);
+ return (-1);
+ }
+
+ /*
+ * Note first netbsd partition for invalidate_netbsd_label().
+ */
+ if (!nbdsec && AHDI_MKPID (ptable->parts[i].id[0],
+ ptable->parts[i].id[1], ptable->parts[i].id[2])
+ == AHDI_PID_NBD) {
+ nbdsec = ptable->parts[i].start;
+ }
+ }
+
+ free (root);
+
+ if (!(flags & AHDI_KEEP_BSL) && !write_bsl (fd)) {
+ close (fd);
+ return (-1);
+ }
+
+ if (!(flags & AHDI_KEEP_NBDA) && !invalidate_netbsd_label(fd, nbdsec)) {
+ close (fd);
+ return (-1);
+ }
+
+#ifdef DEBUG
+ printf ("Forcing disk label re-read\n");
+#endif
+ keep = 0;
+ if (ioctl (fd, DIOCKLABEL, &keep) < 0) {
+ close (fd);
+ return (-1);
+ }
+
+ close (fd);
+ return (1);
+}
+
+/*
+ * Write a bad sector list (empty).
+ */
+int
+write_bsl (fd)
+ int fd;
+{
+ u_int8_t *bsl;
+
+ if ((bsl = malloc (sizeof (u_int8_t) * BSL_SIZE * DEV_BSIZE)) == NULL)
+ return (0);
+ bzero ((void *) bsl, sizeof (u_int8_t) * DEV_BSIZE);
+
+#ifdef DEBUG
+ printf ("Writing bad sector list\n");
+#endif
+ bsl[3] = BSL_MAGIC;
+ if (!disk_write (fd, (u_int) BSL_OFFSET, (u_int) BSL_SIZE, bsl)) {
+ free (bsl);
+ return (0);
+ }
+ free (bsl);
+ return (1);
+}
+
+/*
+ * Invalidate any previous AHDI/NBDA disklabel.
+ * Otherwise this make take precedence when we next open the disk.
+ */
+int
+invalidate_netbsd_label (fd, nbdsec)
+ int fd;
+ u_int32_t nbdsec;
+{
+ struct bootblock *bb;
+ u_int nsec;
+
+ nsec = (BBMINSIZE + (DEV_BSIZE - 1)) / DEV_BSIZE;
+
+ if ((bb = disk_read (fd, nbdsec, nsec)) == NULL) {
+ return (0);
+ }
+
+ if (bb->bb_magic == NBDAMAGIC || bb->bb_magic == AHDIMAGIC) {
+ bb->bb_magic = bb->bb_magic & 0xffffff00;
+ bb->bb_magic = bb->bb_magic | 0x5f;
+
+#ifdef DEBUG
+ printf ("Invalidating old NBDA/AHDI label (sector %u)\n",
+ nbdsec);
+#endif
+ if (!disk_write (fd, nbdsec, nsec, bb)) {
+ free (bb);
+ return (0);
+ }
+ }
+
+ free (bb);
+ return (1);
+}
+
+int
+disk_write (fd, start, count, buf)
+ int fd;
+ u_int start,
+ count;
+ void *buf;
+{
+ off_t offset;
+ size_t size;
+
+ size = count * DEV_BSIZE;
+ offset = start * DEV_BSIZE;
+
+ if (lseek (fd, offset, SEEK_SET) != offset)
+ return (0);
+ if (write (fd, buf, size) != size)
+ return (0);
+ return (1);
+}
View
116 sys/arch/atari/stand/ahdilabel/writedtab.c
@@ -0,0 +1,116 @@
+/* $NetBSD: writedtab.c,v 1.1.1.1 2000/08/07 09:23:40 leo Exp $ */
+
+/*
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Julian Coleman, Waldi Ravens and Leo Weppelman.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "privahdi.h"
+#include <disktab.h>
+#include <fcntl.h>
+#include <stdio.h>
+
+/*
+ * Write AHDI partitions to disk
+ */
+int
+ahdi_writedisktab (ptable, disktype, disktab, dtype)
+ struct ahdi_ptable *ptable;
+ char *disktype, *disktab, *dtype;
+{
+ FILE *fd;
+ int pid, i, j, todo;
+
+ if ((fd = fopen (strlen (disktab) ? disktab : _PATH_DISKTAB, "a"))
+ == NULL)
+ return (-1);
+
+ fprintf (fd, "%s disk|%s:\\\n",
+ strlen (dtype) ? dtype : "SCSI", disktype);
+ fprintf (fd, "\t:ty#winchester:dt=%s:ns#%u:nt#%u:nc#%u:sc#%u:su#%u",
+ strlen (dtype) ? dtype : "SCSI", ptable->nsectors,
+ ptable->ntracks, ptable->ncylinders, ptable->secpercyl,
+ ptable->secperunit);
+
+ todo = ptable->nparts;
+ j = 0;
+ while (todo) {
+ for (i = 0; i < ptable->nparts; i++) {
+ if (j == RAW_PART) {
+ fprintf (fd,
+ "\\\n\t:p%c#%u:o%c#0:t%c=unknown:",
+ RAW_PART + 'a', ptable->secperunit,
+ RAW_PART + 'a', RAW_PART + 'a');
+ break;
+ }
+ if (ptable->parts[i].letter == j) {
+ fprintf (fd, "\\\n\t:p%c#%u:o%c#%u:t%c=",
+ ptable->parts[i].letter + 'a',
+ ptable->parts[i].size,
+ ptable->parts[i].letter + 'a',
+ ptable->parts[i].start,
+ ptable->parts[i].letter + 'a');
+ pid = AHDI_MKPID (ptable->parts[i].id[0],
+ ptable->parts[i].id[1],
+ ptable->parts[i].id[2]);
+ switch (pid) {
+ case AHDI_PID_NBD:
+ fprintf (fd, "4.2BSD:");
+ break;
+ case AHDI_PID_SWP:
+ fprintf (fd, "swap:");
+ break;
+ case AHDI_PID_GEM:
+ case AHDI_PID_BGM:
+ fprintf (fd, "MSDOS:");
+ break;
+ default:
+ fprintf (fd, "unknown:" );
+ }
+ todo--;
+ break;
+ }
+ }
+ j++;
+ }
+ if (j <= RAW_PART) {
+ fprintf (fd, "\\\n\t:p%c#%u:o%c#0:t%c=unknown:",
+ RAW_PART + 'a', ptable->secperunit,
+ RAW_PART + 'a', RAW_PART + 'a');
+ }
+ fprintf (fd, "\n\n");
+
+ fclose (fd);
+ return (1);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.