summaryrefslogtreecommitdiffstats
path: root/lib/libdisk
diff options
context:
space:
mode:
authorgrehan <grehan@FreeBSD.org>2004-04-21 23:21:13 +0000
committergrehan <grehan@FreeBSD.org>2004-04-21 23:21:13 +0000
commita76af532c5dc1e784116e7571732ee16000d2fc1 (patch)
tree424d360a1d9752b9b11b6336dd2e237be1c2f8ca /lib/libdisk
parent4173466ca4ff2e1da50f5049e8e6318eb45b1d5f (diff)
downloadFreeBSD-src-a76af532c5dc1e784116e7571732ee16000d2fc1.zip
FreeBSD-src-a76af532c5dc1e784116e7571732ee16000d2fc1.tar.gz
PowerPC support.
submitted by: Suleiman Souhlal <refugee@segfaulted.com> approved by: phk, jhb
Diffstat (limited to 'lib/libdisk')
-rw-r--r--lib/libdisk/chunk.c28
-rw-r--r--lib/libdisk/create_chunk.c25
-rw-r--r--lib/libdisk/disk.c1
-rw-r--r--lib/libdisk/libdisk.h4
-rw-r--r--lib/libdisk/open_disk.c7
-rw-r--r--lib/libdisk/write_powerpc_disk.c64
6 files changed, 125 insertions, 4 deletions
diff --git a/lib/libdisk/chunk.c b/lib/libdisk/chunk.c
index 96d7338..ef63ccc 100644
--- a/lib/libdisk/chunk.c
+++ b/lib/libdisk/chunk.c
@@ -76,6 +76,15 @@ Find_Mother_Chunk(struct chunk *chunks, daddr_t offset, daddr_t end,
return c2;
}
return 0;
+#ifdef __powerpc__
+ case apple:
+ for (c1 = chunks->part; c1; c1 = c1->next) {
+ if (c1->type == type)
+ if (Chunk_Inside(c1, &ct))
+ return c1;
+ }
+ return 0;
+#endif
default:
warn("Unsupported mother type in Find_Mother_Chunk");
return 0;
@@ -150,7 +159,7 @@ Insert_Chunk(struct chunk *c2, daddr_t offset, daddr_t size, const char *name,
return __LINE__;
}
- if (type == freebsd || type == extended) {
+ if ((type == freebsd || type == extended || type == apple)) {
cs = New_Chunk();
if (cs == NULL)
return __LINE__;
@@ -303,6 +312,18 @@ Add_Chunk(struct disk *d, daddr_t offset, daddr_t size, const char *name,
return(-1);
}
break;
+ case p_ppc:
+ switch (type) {
+ case apple:
+ c1 = Find_Mother_Chunk(d->chunks, offset, end, whole);
+ break;
+ case part:
+ c1 = Find_Mother_Chunk(d->chunks, offset, end, apple);
+ break;
+ default:
+ return (-1);
+ }
+ break;
default:
return (-1);
}
@@ -439,6 +460,11 @@ Delete_Chunk2(struct disk *d, struct chunk *c, int rflags)
c1 = Find_Mother_Chunk(d->chunks, c->offset, c->end,
whole);
#endif
+#ifdef __powerpc__
+ if (c1 == NULL)
+ c1 = Find_Mother_Chunk(d->chunks, c->offset, c->end,
+ apple);
+#endif
break;
default:
c1 = Find_Mother_Chunk(d->chunks, c->offset, c->end, extended);
diff --git a/lib/libdisk/create_chunk.c b/lib/libdisk/create_chunk.c
index c65b8f3..3d498a6 100644
--- a/lib/libdisk/create_chunk.c
+++ b/lib/libdisk/create_chunk.c
@@ -134,6 +134,24 @@ Fixup_Extended_Names(struct chunk *c)
}
#endif
+#ifdef __powerpc__
+static int
+Fixup_Apple_Names(struct chunk *c)
+{
+ struct chunk *c1;
+
+ for (c1 = c->part; c1; c1 = c1->next) {
+ if (c1->type == unused)
+ continue;
+ free(c1->name);
+ c1->name = strdup(c->name);
+ if (!c1->name)
+ return (-1);
+ }
+ return 0;
+}
+#endif
+
int
Fixup_Names(struct disk *d)
{
@@ -185,6 +203,10 @@ Fixup_Names(struct disk *d)
for (c2 = c1->part; c2; c2 = c2->next) {
if (c2->type == freebsd)
Fixup_FreeBSD_Names(c2);
+#ifdef __powerpc__
+ else if (c2->type == apple)
+ Fixup_Apple_Names(c2);
+#endif
#ifndef PC98
else if (c2->type == extended)
Fixup_Extended_Names(c2);
@@ -238,7 +260,8 @@ Create_Chunk_DWIM(struct disk *d, struct chunk *parent, daddr_t size,
if (!parent)
parent = d->chunks;
- if (parent->type == freebsd && type == part && parent->part == NULL) {
+ if ((parent->type == freebsd && type == part && parent->part == NULL)
+ || (parent->type == apple && type == part && parent->part == NULL)) {
c1 = New_Chunk();
if (c1 == NULL)
return (NULL);
diff --git a/lib/libdisk/disk.c b/lib/libdisk/disk.c
index 8a60191..ca2d19e 100644
--- a/lib/libdisk/disk.c
+++ b/lib/libdisk/disk.c
@@ -69,6 +69,7 @@ chunk_name(chunk_e type)
case fat: return ("fat");
case spare: return ("spare");
case efi: return ("efi");
+ case apple: return ("apple");
default: return ("??");
}
};
diff --git a/lib/libdisk/libdisk.h b/lib/libdisk/libdisk.h
index 891007a..36866ed 100644
--- a/lib/libdisk/libdisk.h
+++ b/lib/libdisk/libdisk.h
@@ -47,7 +47,9 @@ typedef enum {
extended,
part,
spare,
- unused
+ unused,
+
+ apple
} chunk_e;
__BEGIN_DECLS
diff --git a/lib/libdisk/open_disk.c b/lib/libdisk/open_disk.c
index b3a99f8..cad9dab 100644
--- a/lib/libdisk/open_disk.c
+++ b/lib/libdisk/open_disk.c
@@ -128,6 +128,8 @@ Int_Open_Disk(const char *name, char *conftxt)
lo[0] = 0;
for (; p != NULL && *p; p = q) {
+ if (sn)
+ sn = NULL;
q = strchr(p, '\n');
if (q != NULL)
*q++ = '\0';
@@ -164,7 +166,8 @@ Int_Open_Disk(const char *name, char *conftxt)
}
b = strsep(&p, " ");
o = strtoimax(b, &r, 0);
- if (*r) {
+ /* APPLE have ty as a string */
+ if ((*r) && strcmp(t, "APPLE")) {
printf("BARF %d <%d>\n", __LINE__, *r);
exit (0);
}
@@ -258,6 +261,8 @@ Int_Open_Disk(const char *name, char *conftxt)
; /* nothing */
else if (!strcmp(t, "CCD"))
; /* nothing */
+ else if (!strcmp(t, "APPLE"))
+ i = Add_Chunk(d, off, len, n, apple, 0, 0, sn);
else {
printf("BARF %d\n", __LINE__);
exit(0);
diff --git a/lib/libdisk/write_powerpc_disk.c b/lib/libdisk/write_powerpc_disk.c
new file mode 100644
index 0000000..ec955e2
--- /dev/null
+++ b/lib/libdisk/write_powerpc_disk.c
@@ -0,0 +1,64 @@
+/*-
+ * Copyright (c) 2004 Suleiman Souhlal.
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <err.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/disklabel.h>
+#include <paths.h>
+#include "libdisk.h"
+
+int
+Write_Disk(const struct disk *d1)
+{
+ /*
+ * We don't have to write any label, so we only check that we can
+ * open the disk.
+ */
+ int fd;
+ char device[64];
+
+ strcpy(device, _PATH_DEV);
+ strcat(device, d1->name);
+
+ fd = open(device, O_RDWR);
+ if (fd < 0) {
+ close(fd);
+ return 1;
+ }
+
+ close(fd);
+ return 0;
+}
OpenPOWER on IntegriCloud