summaryrefslogtreecommitdiffstats
path: root/lib/libdisk
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2002-10-22 09:13:02 +0000
committerphk <phk@FreeBSD.org>2002-10-22 09:13:02 +0000
commit43441f1d037b19165e361f523d20669b6b11bc25 (patch)
tree8378d0fbd151285dc2443b78fe8c309a83a37602 /lib/libdisk
parent0cb4cfe3c6f594f0eb38c72c07c77d99b45b3f63 (diff)
downloadFreeBSD-src-43441f1d037b19165e361f523d20669b6b11bc25.zip
FreeBSD-src-43441f1d037b19165e361f523d20669b6b11bc25.tar.gz
Swing the weed-whacker around libdisk:
Constify some things. Staticize some things. Remove some unused things. Prototype some things. Don't install a gazillion man-pages links. Drop support for ON-TRACK disk-manager.
Diffstat (limited to 'lib/libdisk')
-rw-r--r--lib/libdisk/Makefile29
-rw-r--r--lib/libdisk/blocks.c3
-rw-r--r--lib/libdisk/chunk.c20
-rw-r--r--lib/libdisk/create_chunk.c210
-rw-r--r--lib/libdisk/disk.c58
-rw-r--r--lib/libdisk/disklabel.c14
-rw-r--r--lib/libdisk/libdisk.315
-rw-r--r--lib/libdisk/libdisk.h38
-rw-r--r--lib/libdisk/rules.c78
-rw-r--r--lib/libdisk/write_disk.c55
10 files changed, 73 insertions, 447 deletions
diff --git a/lib/libdisk/Makefile b/lib/libdisk/Makefile
index be4d8c7..a1d0746 100644
--- a/lib/libdisk/Makefile
+++ b/lib/libdisk/Makefile
@@ -1,7 +1,7 @@
# $FreeBSD$
LIB= disk
-SRCS= blocks.c disklabel.c chunk.c disk.c change.c \
+SRCS= blocks.c chunk.c disk.c change.c \
create_chunk.c rules.c write_disk.c
INCS= libdisk.h
@@ -14,33 +14,6 @@ NOPROFILE= yes
NOPIC= yes
MAN= libdisk.3
-MLINKS+= libdisk.3 Open_Disk.3 \
- libdisk.3 Clone_Disk.3 \
- libdisk.3 Free_Disk.3 \
- libdisk.3 Debug_Disk.3 \
- libdisk.3 Set_Bios_Geom.3 \
- libdisk.3 Delete_Chunk.3 \
- libdisk.3 Collapse_Disk.3 \
- libdisk.3 Collapse_Chunk.3 \
- libdisk.3 Create_Chunk.3 \
- libdisk.3 All_FreeBSD.3 \
- libdisk.3 CheckRules.3 \
- libdisk.3 Disk_Names.3 \
- libdisk.3 Set_Boot_Mgr.3 \
- libdisk.3 Set_Boot_Blocks.3 \
- libdisk.3 Write_Disk.3 \
- libdisk.3 Cyl_Aligned.3 \
- libdisk.3 Next_Cyl_Aligned.3 \
- libdisk.3 Prev_Cyl_Aligned.3 \
- libdisk.3 Track_Aligned.3 \
- libdisk.3 Next_Track_Aligned.3 \
- libdisk.3 Prev_Track_Aligned.3 \
- libdisk.3 Create_Chunk_DWIM.3 \
- libdisk.3 MakeDev.3 \
- libdisk.3 MakeDevDisk.3 \
- libdisk.3 ShowChunkFlags.3 \
- libdisk.3 ChunkCanBeRoot.3 \
- libdisk.3 slice_type_name.3
.include <bsd.lib.mk>
diff --git a/lib/libdisk/blocks.c b/lib/libdisk/blocks.c
index e3149d4..a630675 100644
--- a/lib/libdisk/blocks.c
+++ b/lib/libdisk/blocks.c
@@ -35,8 +35,9 @@ read_block(int fd, daddr_t block, u_long sector_size)
}
int
-write_block(int fd, daddr_t block, void *foo, u_long sector_size)
+write_block(int fd, daddr_t block, const void *foo, u_long sector_size)
{
+
if (-1 == lseek(fd, (off_t)block * sector_size, SEEK_SET))
return -1;
if (sector_size != write(fd, foo, sector_size))
diff --git a/lib/libdisk/chunk.c b/lib/libdisk/chunk.c
index fd4b0f3..8434f6b 100644
--- a/lib/libdisk/chunk.c
+++ b/lib/libdisk/chunk.c
@@ -18,12 +18,22 @@ __FBSDID("$FreeBSD$");
#include <err.h>
#include "libdisk.h"
-#define new_chunk() memset(malloc(sizeof(struct chunk)), 0, sizeof(struct chunk))
+static struct chunk *
+new_chunk(void)
+{
+ struct chunk *c;
+
+ c = malloc(sizeof *c);
+ if (c == NULL)
+ err(1, "malloc");
+ memset(c, 0, sizeof *c);
+ return (c);
+}
/* Is c2 completely inside c1 ? */
static int
-Chunk_Inside(struct chunk *c1, struct chunk *c2)
+Chunk_Inside(const struct chunk *c1, const struct chunk *c2)
{
/* if c1 ends before c2 do */
if (c1->end < c2->end)
@@ -34,7 +44,7 @@ Chunk_Inside(struct chunk *c1, struct chunk *c2)
return 1;
}
-struct chunk *
+static struct chunk *
Find_Mother_Chunk(struct chunk *chunks, u_long offset, u_long end, chunk_e type)
{
struct chunk *c1,*c2,ct;
@@ -92,7 +102,7 @@ Free_Chunk(struct chunk *c1)
}
struct chunk *
-Clone_Chunk(struct chunk *c1)
+Clone_Chunk(const struct chunk *c1)
{
struct chunk *c2;
@@ -112,7 +122,7 @@ Clone_Chunk(struct chunk *c1)
return c2;
}
-int
+static int
#ifdef PC98
Insert_Chunk(struct chunk *c2, u_long offset, u_long size, const char *name,
chunk_e type, int subtype, u_long flags, const char *sname)
diff --git a/lib/libdisk/create_chunk.c b/lib/libdisk/create_chunk.c
index 95ed72c..dbc5b58 100644
--- a/lib/libdisk/create_chunk.c
+++ b/lib/libdisk/create_chunk.c
@@ -33,38 +33,7 @@ __FBSDID("$FreeBSD$");
#include <pwd.h>
#include "libdisk.h"
-static void msgDebug(char *, ...) __printflike(1, 2);
-
-/* Clone these two from sysinstall because we need our own copies
- * due to link order problems with `crunch'. Feh!
- */
static int
-isDebug()
-{
- static int debug = 0; /* Allow debugger to tweak it */
-
- return debug;
-}
-
-/* Write something to the debugging port */
-static void
-msgDebug(char *fmt, ...)
-{
- va_list args;
- char *dbg;
- static int DebugFD = -1;
-
- if (DebugFD == -1)
- DebugFD = open(_PATH_DEV"ttyv1", O_RDWR);
- dbg = (char *)alloca(FILENAME_MAX);
- strcpy(dbg, "DEBUG: ");
- va_start(args, fmt);
- vsnprintf((char *)(dbg + strlen(dbg)), FILENAME_MAX, fmt, args);
- va_end(args);
- write(DebugFD, dbg, strlen(dbg));
-}
-
-int
Fixup_FreeBSD_Names(struct disk *d, struct chunk *c)
{
struct chunk *c1, *c3;
@@ -132,7 +101,7 @@ Fixup_FreeBSD_Names(struct disk *d, struct chunk *c)
return 0;
}
-int
+static int
Fixup_Extended_Names(struct disk *d, struct chunk *c)
{
struct chunk *c1;
@@ -155,14 +124,13 @@ int
Fixup_Names(struct disk *d)
{
struct chunk *c1, *c2;
- int i;
#ifdef __i386__
struct chunk *c3;
int j;
#endif
c1 = d->chunks;
- for(i=1,c2 = c1->part; c2 ; c2 = c2->next) {
+ for(c2 = c1->part; c2 ; c2 = c2->next) {
c2->flags &= ~CHUNK_BSD_COMPAT;
if (c2->type == unused)
continue;
@@ -247,7 +215,7 @@ Create_Chunk(struct disk *d, u_long offset, u_long size, chunk_e type, int subty
}
struct chunk *
-Create_Chunk_DWIM(struct disk *d, struct chunk *parent , u_long size, chunk_e type, int subtype, u_long flags)
+Create_Chunk_DWIM(struct disk *d, const struct chunk *parent , u_long size, chunk_e type, int subtype, u_long flags)
{
int i;
struct chunk *c1;
@@ -279,182 +247,14 @@ Create_Chunk_DWIM(struct disk *d, struct chunk *parent , u_long size, chunk_e ty
}
int
-MakeDev(struct chunk *c1, const char *path)
+MakeDevChunk(const struct chunk *c1, const char *path)
{
-#if 0
- char *p = c1->name;
- u_long cmaj, min, unit, part, slice;
- char buf[BUFSIZ], buf2[BUFSIZ];
- struct group *grp;
- struct passwd *pwd;
- struct statfs fs;
- uid_t owner;
- gid_t group;
-
- *buf2 = '\0';
- if (isDebug())
- msgDebug("MakeDev: Called with %s on path %s\n", p, path);
- if (!strcmp(p, "X"))
- return 0;
- if (statfs(path, &fs) != 0) {
-#ifdef DEBUG
- warn("statfs(%s) failed\n", path);
-#endif
- return 0;
- }
- if (strcmp(fs.f_fstypename, "devfs") == 0) {
- if (isDebug())
- msgDebug("MakeDev: No need to mknod(2) with DEVFS.\n");
- return 1;
- }
- if (!strncmp(p, "ad", 2))
- cmaj = 116, p += 2;
-#ifdef PC98
- else if (!strncmp(p, "wd", 2))
- cmaj = 3, p += 2;
-#endif
- else if (!strncmp(p, "wfd", 3))
- cmaj = 87, p += 3;
- else if (!strncmp(p, "afd", 3))
- cmaj = 118, p += 3;
- else if (!strncmp(p, "fla", 3))
- cmaj = 102, p += 3;
- else if (!strncmp(p, "idad", 4))
- cmaj = 109, p += 4;
- else if (!strncmp(p, "mlxd", 4))
- cmaj = 131, p += 4;
- else if (!strncmp(p, "amrd", 4))
- cmaj = 133, p += 4;
- else if (!strncmp(p, "twed", 4))
- cmaj = 147, p += 4;
- else if (!strncmp(p, "aacd", 4))
- cmaj = 151, p += 4;
- else if (!strncmp(p, "ar", 2)) /* ATA RAID */
- cmaj = 157, p += 2;
- else if (!strncmp(p, "da", 2)) /* CAM support */
- cmaj = 13, p += 2;
- else {
- msgDebug("MakeDev: Unknown major/minor for devtype %s\n", p);
- return 0;
- }
- if (!isdigit(*p)) {
- msgDebug("MakeDev: Invalid disk unit passed: %s\n", p);
- return 0;
- }
- unit = *p - '0';
- p++;
- if (!*p) {
- slice = 1;
- part = 2;
- goto done;
- }
- else if (isdigit(*p)) {
- unit *= 10;
- unit += (*p - '0');
- p++;
- }
-#ifndef __alpha__
- if (*p != 's') {
- msgDebug("MakeDev: `%s' is not a valid slice delimiter\n", p);
- return 0;
- }
- p++;
- if (!isdigit(*p)) {
- msgDebug("MakeDev: `%s' is an invalid slice number\n", p);
- return 0;
- }
- slice = *p - '0';
- p++;
- if (isdigit(*p)) {
- slice *= 10;
- slice += (*p - '0');
- p++;
- }
- slice = slice + 1;
-#else
- slice = 0;
-#endif
- if (!*p) {
- part = 2;
- if(c1->type == freebsd)
- sprintf(buf2, "%sc", c1->name);
- goto done;
- }
- if (*p < 'a' || *p > 'h') {
- msgDebug("MakeDev: `%s' is not a valid partition name.\n", p);
- return 0;
- }
- part = *p - 'a';
- done:
- if (isDebug())
- msgDebug("MakeDev: Unit %lu, Slice %lu, Part %lu\n", unit, slice, part);
- if (unit > 32)
- return 0;
- if (slice > 32)
- return 0;
- if ((pwd = getpwnam("root")) == NULL) {
- if (isDebug())
- msgDebug("MakeDev: Unable to lookup user \"root\", using 0.\n");
- owner = 0;
- } else {
- owner = pwd->pw_uid;
- }
- if ((grp = getgrnam("operator")) == NULL) {
- if (isDebug())
- msgDebug("MakeDev: Unable to lookup group \"operator\", using 5.\n");
- group = 5;
- } else {
- group = grp->gr_gid;
- }
- min = unit * 8 + 65536 * slice + part;
- sprintf(buf, "%s/r%s", path, c1->name);
- unlink(buf);
- if (mknod(buf, S_IFCHR|0640, makedev(cmaj,min)) == -1) {
- msgDebug("mknod of %s returned failure status!\n", buf);
- return 0;
- }
- if (chown(buf, owner, group) == -1) {
- msgDebug("chown of %s returned failure status!\n", buf);
- return 0;
- }
- if (*buf2) {
- sprintf(buf, "%s/r%s", path, buf2);
- unlink(buf);
- if (mknod(buf, S_IFCHR|0640, makedev(cmaj,min)) == -1) {
- msgDebug("mknod of %s returned failure status!\n", buf);
- return 0;
- }
- if (chown(buf, owner, group) == -1) {
- msgDebug("chown of %s returned failure status!\n", buf);
- return 0;
- }
- }
- sprintf(buf, "%s/%s", path, c1->name);
- unlink(buf);
- if (mknod(buf, S_IFCHR|0640, makedev(cmaj,min)) == -1) {
- msgDebug("mknod of %s returned failure status!\n", buf);
- return 0;
- }
- if (chown(buf, owner, group) == -1) {
- msgDebug("chown of %s returned failure status!\n", buf);
- return 0;
- }
-#endif
- return 1;
-}
-
-int
-MakeDevChunk(struct chunk *c1, const char *path)
-{
- int i;
-
- i = MakeDev(c1, path);
if (c1->next)
MakeDevChunk(c1->next, path);
if (c1->part)
MakeDevChunk(c1->part, path);
- return i;
+ return 1;
}
int
diff --git a/lib/libdisk/disk.c b/lib/libdisk/disk.c
index ddb4db7..3f83f2a 100644
--- a/lib/libdisk/disk.c
+++ b/lib/libdisk/disk.c
@@ -400,7 +400,7 @@ assignToSlice(void *arg, XMLToken t, u_int *slice, u_int64_t v)
* Callback to collect disk-related data.
*/
static int
-assignToDisk(void *arg, XMLToken t, u_int *slice, u_int64_t v)
+assignToDisk(void *arg, XMLToken t, const u_int *slice, u_int64_t v)
{
struct disklabel *dl = (struct disklabel *) arg;
@@ -471,7 +471,6 @@ Int_Open_Disk(const char *name, u_long size)
struct dos_partition *dp;
void *p;
#endif
- u_long offset = 0;
#ifdef HAVE_GEOM
char *confxml = NULL;
size_t xmlsize;
@@ -612,12 +611,6 @@ Int_Open_Disk(const char *name, u_long size)
continue;
if (!Read_Int32(&dp->dp_size))
continue;
-
- if (dp->dp_typ == DOSPTYP_ONTRACK) {
- d->flags |= DISK_ON_TRACK;
- offset = 63;
- }
-
}
free(p);
#endif
@@ -632,9 +625,9 @@ Int_Open_Disk(const char *name, u_long size)
d->bios_cyl = size / (dl.d_ntracks * dl.d_nsectors);
#ifdef PC98
- if (Add_Chunk(d, -offset, size, name, whole, 0, 0, "-"))
+ if (Add_Chunk(d, 0, size, name, whole, 0, 0, "-"))
#else
- if (Add_Chunk(d, -offset, size, name, whole, 0, 0))
+ if (Add_Chunk(d, 0, size, name, whole, 0, 0))
#endif
DPRINT(("Failed to add 'whole' chunk"));
@@ -662,7 +655,6 @@ Int_Open_Disk(const char *name, u_long size)
if (! ds.dss_slices[i].ds_size)
continue;
- ds.dss_slices[i].ds_offset -= offset;
snprintf(sname, sizeof(sname), "%ss%d", name, i - 1);
#ifdef PC98
subtype = ds.dss_slices[i].ds_type |
@@ -849,7 +841,6 @@ void
Debug_Disk(struct disk *d)
{
printf("Debug_Disk(%s)", d->name);
- printf(" flags=%lx", d->flags);
#if 0
printf(" real_geom=%lu/%lu/%lu", d->real_cyl, d->real_hd, d->real_sect);
#endif
@@ -887,49 +878,6 @@ Free_Disk(struct disk *d)
free(d);
}
-struct disk *
-Clone_Disk(struct disk *d)
-{
- struct disk *d2;
-
- d2 = (struct disk*) malloc(sizeof *d2);
- if(!d2) return NULL;
- *d2 = *d;
- d2->name = strdup(d2->name);
- d2->chunks = Clone_Chunk(d2->chunks);
-#ifdef PC98
- if(d2->bootipl) {
- d2->bootipl = malloc(d2->bootipl_size);
- memcpy(d2->bootipl, d->bootipl, d2->bootipl_size);
- }
- if(d2->bootmenu) {
- d2->bootmenu = malloc(d2->bootmenu_size);
- memcpy(d2->bootmenu, d->bootmenu, d2->bootmenu_size);
- }
-#else
- if(d2->bootmgr) {
- d2->bootmgr = malloc(d2->bootmgr_size);
- memcpy(d2->bootmgr, d->bootmgr, d2->bootmgr_size);
- }
-#endif
-#if defined(__i386__)
- if(d2->boot1) {
- d2->boot1 = malloc(512);
- memcpy(d2->boot1, d->boot1, 512);
- }
- if(d2->boot2) {
- d2->boot2 = malloc(512 * 15);
- memcpy(d2->boot2, d->boot2, 512 * 15);
- }
-#elif defined(__alpha__)
- if(d2->boot1) {
- d2->boot1 = malloc(512 * 15);
- memcpy(d2->boot1, d->boot1, 512 * 15);
- }
-#endif
- return d2;
-}
-
#if 0
void
Collapse_Disk(struct disk *d)
diff --git a/lib/libdisk/disklabel.c b/lib/libdisk/disklabel.c
index 96469ea..61bf500 100644
--- a/lib/libdisk/disklabel.c
+++ b/lib/libdisk/disklabel.c
@@ -16,17 +16,3 @@ __FBSDID("$FreeBSD$");
#include <sys/disklabel.h>
#include "libdisk.h"
-struct disklabel *
-read_disklabel(int fd, daddr_t block, u_long sector_size)
-{
- struct disklabel *dp;
-
- dp = (struct disklabel *) read_block(fd, block, sector_size);
- if (dp->d_magic != DISKMAGIC)
- return 0;
- if (dp->d_magic2 != DISKMAGIC)
- return 0;
- if (dkcksum(dp) != 0)
- return 0;
- return dp;
-}
diff --git a/lib/libdisk/libdisk.3 b/lib/libdisk/libdisk.3
index 36e35e8..9c6e39e 100644
--- a/lib/libdisk/libdisk.3
+++ b/lib/libdisk/libdisk.3
@@ -32,7 +32,6 @@
.Os
.Sh NAME
.Nm Open_Disk ,
-.Nm Clone_Disk ,
.Nm Free_Disk ,
.Nm Debug_Disk ,
.Nm Set_Bios_Geom ,
@@ -56,7 +55,6 @@
.Nm MakeDev ,
.Nm MakeDevDisk ,
.Nm ShowChunkFlags ,
-.Nm ChunkCanBeRoot ,
.Nm chunk_n ,
.Nm slice_type_name
.Nd library interface to slice and partition labels
@@ -71,8 +69,6 @@
.Fn slice_type_name "int type" "int subtype"
.Ft struct disk *
.Fn Open_Disk "const char *devname"
-.Ft struct disk *
-.Fn Clone_Disk "struct disk *disk"
.Ft void
.Fn Free_Disk "struct disk *disk"
.Ft void
@@ -119,8 +115,6 @@
.Fn MakeDevDisk "struct disk *d" "const char *path"
.Ft char *
.Fn ShowChunkFlags "struct chunk *c"
-.Ft char *
-.Fn ChunkCanBeRoot "struct chunk *c"
.Sh DESCRIPTION
.Nm Libdisk
provides an interface to the low-level disk slice and partition labels.
@@ -212,11 +206,6 @@ it.
.Fn Open_Disk
will open the named disk, and return populated tree.
.Pp
-.Fn Clone_Disk
-clones a copy of a tree. Useful for
-.Dq Undo
-functionality.
-.Pp
.Fn Free_Disk
frees a tree made with
.Fn Open_Disk
@@ -314,10 +303,6 @@ makes the device nodes for all chunks on this disk.
.Fn ShowChunkFlags
returns a string to show flags.
.Pp
-.Fn ChunkCanBeRoot
-returns NULL if chunk can be
-.Ql / .
-.Pp
Chunk name strings can be accessed directly using the external array
.Va chunk_n .
.Pp
diff --git a/lib/libdisk/libdisk.h b/lib/libdisk/libdisk.h
index 492e2f3..86f786a 100644
--- a/lib/libdisk/libdisk.h
+++ b/lib/libdisk/libdisk.h
@@ -29,8 +29,6 @@ typedef enum {
__BEGIN_DECLS
struct disk {
char *name;
- u_long flags;
-# define DISK_ON_TRACK 1
u_long bios_cyl;
u_long bios_hd;
u_long bios_sect;
@@ -119,11 +117,6 @@ Open_Disk(const char *devname);
/* Will open the named disk, and return populated tree.
*/
-struct disk *
-Clone_Disk(struct disk *disk);
-/* Clone a copy of a tree. Useful for "Undo" functionality
- */
-
void
Free_Disk(struct disk *disk);
/* Free a tree made with Open_Disk() or Clone_Disk()
@@ -183,7 +176,7 @@ All_FreeBSD(struct disk *d, int force_all);
*/
char *
-CheckRules(struct disk *);
+CheckRules(const struct disk *);
/* Return char* to warnings about broken design rules in this disklayout
*/
@@ -212,46 +205,40 @@ Set_Boot_Blocks(struct disk *d, const u_char *_boot1, const u_char *_boot2);
*/
int
-Write_Disk(struct disk *d);
+Write_Disk(const struct disk *d);
/* Write all the MBRs, disklabels, bootblocks and boot managers
*/
-int
-Cyl_Aligned(struct disk *d, u_long offset);
-/* Check if offset is aligned on a cylinder according to the
- * bios geometry
- */
-
u_long
-Next_Cyl_Aligned(struct disk *d, u_long offset);
+Next_Cyl_Aligned(const struct disk *d, u_long offset);
/* Round offset up to next cylinder according to the bios-geometry
*/
u_long
-Prev_Cyl_Aligned(struct disk *d, u_long offset);
+Prev_Cyl_Aligned(const struct disk *d, u_long offset);
/* Round offset down to previous cylinder according to the bios-
* geometry
*/
int
-Track_Aligned(struct disk *d, u_long offset);
+Track_Aligned(const struct disk *d, u_long offset);
/* Check if offset is aligned on a track according to the
* bios geometry
*/
u_long
-Next_Track_Aligned(struct disk *d, u_long offset);
+Next_Track_Aligned(const struct disk *d, u_long offset);
/* Round offset up to next track according to the bios-geometry
*/
u_long
-Prev_Track_Aligned(struct disk *d, u_long offset);
+Prev_Track_Aligned(const struct disk *d, u_long offset);
/* Check if offset is aligned on a track according to the
* bios geometry
*/
struct chunk *
-Create_Chunk_DWIM(struct disk *d, struct chunk *parent , u_long size,
+Create_Chunk_DWIM(struct disk *d, const struct chunk *parent , u_long size,
chunk_e type, int subtype, u_long flags);
/* This one creates a partition inside the given parent of the given
* size, and returns a pointer to it. The first unused chunk big
@@ -269,28 +256,25 @@ char *
ShowChunkFlags(struct chunk *c);
/* Return string to show flags. */
-char *
-ChunkCanBeRoot(struct chunk *c);
-/* Return NULL if chunk can be /, explanation otherwise */
-
/*
* Implementation details >>> DO NOT USE <<<
*/
void Debug_Chunk(struct chunk *);
void Free_Chunk(struct chunk *);
-struct chunk * Clone_Chunk(struct chunk *);
+struct chunk * Clone_Chunk(const struct chunk *);
#ifdef PC98
int Add_Chunk(struct disk *, long, u_long, const char *, chunk_e, int, u_long, const char *);
#else
int Add_Chunk(struct disk *, long, u_long, const char *, chunk_e, int, u_long);
#endif
void * read_block(int, daddr_t, u_long);
-int write_block(int, daddr_t, void *, u_long);
+int write_block(int, daddr_t, const void *, u_long);
struct disklabel * read_disklabel(int, daddr_t, u_long);
struct chunk * Find_Mother_Chunk(struct chunk *, u_long, u_long, chunk_e);
struct disk * Int_Open_Disk(const char *name, u_long size);
int Fixup_Names(struct disk *);
+int MakeDevChunk(const struct chunk *c1, const char *path);
__END_DECLS
#define dprintf printf
diff --git a/lib/libdisk/rules.c b/lib/libdisk/rules.c
index a3dcc1b..a6a2255 100644
--- a/lib/libdisk/rules.c
+++ b/lib/libdisk/rules.c
@@ -25,7 +25,7 @@ __FBSDID("$FreeBSD$");
#include "libdisk.h"
int
-Track_Aligned(struct disk *d, u_long offset)
+Track_Aligned(const struct disk *d, u_long offset)
{
if (!d->bios_sect)
return 1;
@@ -35,7 +35,7 @@ Track_Aligned(struct disk *d, u_long offset)
}
u_long
-Prev_Track_Aligned(struct disk *d, u_long offset)
+Prev_Track_Aligned(const struct disk *d, u_long offset)
{
if (!d->bios_sect)
return offset;
@@ -43,15 +43,15 @@ Prev_Track_Aligned(struct disk *d, u_long offset)
}
u_long
-Next_Track_Aligned(struct disk *d, u_long offset)
+Next_Track_Aligned(const struct disk *d, u_long offset)
{
if (!d->bios_sect)
return offset;
return Prev_Track_Aligned(d, offset + d->bios_sect-1);
}
-int
-Cyl_Aligned(struct disk *d, u_long offset)
+static int
+Cyl_Aligned(const struct disk *d, u_long offset)
{
if (!d->bios_sect || !d->bios_hd)
return 1;
@@ -61,7 +61,7 @@ Cyl_Aligned(struct disk *d, u_long offset)
}
u_long
-Prev_Cyl_Aligned(struct disk *d, u_long offset)
+Prev_Cyl_Aligned(const struct disk *d, u_long offset)
{
if (!d->bios_sect || !d->bios_hd)
return offset;
@@ -69,7 +69,7 @@ Prev_Cyl_Aligned(struct disk *d, u_long offset)
}
u_long
-Next_Cyl_Aligned(struct disk *d, u_long offset)
+Next_Cyl_Aligned(const struct disk *d, u_long offset)
{
if (!d->bios_sect || !d->bios_hd)
return offset;
@@ -81,8 +81,8 @@ Next_Cyl_Aligned(struct disk *d, u_long offset)
* Chunks of type 'whole' can have max NDOSPART children.
* Only one of them can have the "active" flag
*/
-void
-Rule_000(struct disk *d, struct chunk *c, char *msg)
+static void
+Rule_000(const struct disk *d, const struct chunk *c, char *msg)
{
#ifdef PC98
int i=0;
@@ -117,15 +117,14 @@ Rule_000(struct disk *d, struct chunk *c, char *msg)
* All children of 'whole' and 'extended' must be track-aligned.
* Exception: the end can be unaligned if it matches the end of 'whole'
*/
-void
-Rule_001(struct disk *d, struct chunk *c, char *msg)
+static void
+Rule_001(const struct disk *d, const struct chunk *c, char *msg)
{
- int i;
struct chunk *c1;
if (c->type != whole && c->type != extended)
return;
- for (i = 0, c1 = c->part; c1; c1 = c1->next) {
+ for (c1 = c->part; c1; c1 = c1->next) {
if (c1->type == unused) continue;
c1->flags |= CHUNK_ALIGN;
#ifdef PC98
@@ -154,8 +153,8 @@ Rule_001(struct disk *d, struct chunk *c, char *msg)
* Rule#2:
* Max one 'fat' as child of 'whole'
*/
-void
-Rule_002(struct disk *d, struct chunk *c, char *msg)
+static void
+Rule_002(const struct disk *d, const struct chunk *c, char *msg)
{
#ifndef PC98
int i;
@@ -179,8 +178,8 @@ Rule_002(struct disk *d, struct chunk *c, char *msg)
* Rule#3:
* Max one extended as child of 'whole'
*/
-void
-Rule_003(struct disk *d, struct chunk *c, char *msg)
+static void
+Rule_003(const struct disk *d, const struct chunk *c, char *msg)
{
#ifndef PC98
int i;
@@ -205,8 +204,8 @@ Rule_003(struct disk *d, struct chunk *c, char *msg)
* Max seven 'part' as children of 'freebsd'
* Max one CHUNK_IS_ROOT child per 'freebsd'
*/
-void
-Rule_004(struct disk *d, struct chunk *c, char *msg)
+static void
+Rule_004(const struct disk *d, const struct chunk *c, char *msg)
{
int i=0,k=0;
struct chunk *c1;
@@ -231,8 +230,8 @@ Rule_004(struct disk *d, struct chunk *c, char *msg)
}
}
-void
-Check_Chunk(struct disk *d, struct chunk *c, char *msg)
+static void
+Check_Chunk(const struct disk *d, const struct chunk *c, char *msg)
{
Rule_000(d, c, msg);
Rule_001(d, c, msg);
@@ -246,7 +245,7 @@ Check_Chunk(struct disk *d, struct chunk *c, char *msg)
}
char *
-CheckRules(struct disk *d)
+CheckRules(const struct disk *d)
{
char msg[BUFSIZ];
@@ -256,38 +255,3 @@ CheckRules(struct disk *d)
return strdup(msg);
return 0;
}
-
-char *
-ChunkCanBeRoot(struct chunk *c)
-{
- struct chunk *c1;
- struct disk *d = c->disk;
- char msg[BUFSIZ];
-
- *msg = '\0';
- for (c1 = d->chunks->part; ; ) {
- for (; c1; c1 = c1->next)
- if (c1->offset <= c->offset && c1->end >= c->end)
- break;
- if (!c1) {
- strcat(msg,
-"Internal trouble, cannot find this chunk in the chunk-tree\n");
- return strdup(msg);
- }
- if (c1->type == freebsd)
- break;
- c1 = c1->part;
- }
-
-#ifndef PC98
- if (c1->type != freebsd) {
- strcat(msg,
-"The root partition must be in a FreeBSD slice, otherwise\n");
- strcat(msg,
-"the kernel cannot be booted from it\n");
- return strdup(msg);
- }
-#endif
-
- return NULL;
-}
diff --git a/lib/libdisk/write_disk.c b/lib/libdisk/write_disk.c
index c44480c..d3ad912 100644
--- a/lib/libdisk/write_disk.c
+++ b/lib/libdisk/write_disk.c
@@ -28,22 +28,13 @@ __FBSDID("$FreeBSD$");
#include <paths.h>
#include "libdisk.h"
-#define DOSPTYP_EXTENDED 5
-#define BBSIZE 8192
-#define SBSIZE 0
#define DEF_RPM 3600
#define DEF_INTERLEAVE 1
-#ifdef PC98
-#define WHERE(offset,disk) (offset)
-#else
-#define WHERE(offset,disk) (disk->flags & DISK_ON_TRACK ? offset + 63 : offset)
-#endif
-
/* XXX: A lot of hardcoded 512s probably should be foo->sector_size;
I'm not sure which, so I leave it like it worked before. --schweikh */
-int
-Write_FreeBSD(int fd, struct disk *new, struct disk *old, struct chunk *c1)
+static int
+Write_FreeBSD(int fd, const struct disk *new, const struct disk *old, const struct chunk *c1)
{
struct disklabel *dl;
struct chunk *c2;
@@ -55,7 +46,7 @@ Write_FreeBSD(int fd, struct disk *new, struct disk *old, struct chunk *c1)
#endif
for(i = 0; i < BBSIZE/512; i++) {
- p = read_block(fd, WHERE(i + c1->offset, new), 512);
+ p = read_block(fd, i + c1->offset, 512);
memcpy(buf + 512 * i, p, 512);
free(p);
}
@@ -96,7 +87,7 @@ Write_FreeBSD(int fd, struct disk *new, struct disk *old, struct chunk *c1)
/*
* Add in defaults for superblock size, interleave, and rpms
*/
- dl->d_sbsize = SBSIZE;
+ dl->d_sbsize = 0;
dl->d_interleave = DEF_INTERLEAVE;
dl->d_rpm = DEF_RPM;
@@ -120,12 +111,6 @@ Write_FreeBSD(int fd, struct disk *new, struct disk *old, struct chunk *c1)
dl->d_interleave = 1;
#endif
-#ifndef PC98
- if(new->flags & DISK_ON_TRACK)
- for(i=0;i<MAXPARTITIONS;i++)
- if (dl->d_partitions[i].p_size)
- dl->d_partitions[i].p_offset += 63;
-#endif
dl->d_magic = DISKMAGIC;
dl->d_magic2 = DISKMAGIC;
dl->d_checksum = dkcksum(dl);
@@ -148,18 +133,12 @@ Write_FreeBSD(int fd, struct disk *new, struct disk *old, struct chunk *c1)
#endif /*__alpha__*/
for(i=0;i<BBSIZE/512;i++) {
- write_block(fd,WHERE(i + c1->offset, new), buf + 512 * i, 512);
+ write_block(fd, i + c1->offset, buf + 512 * i, 512);
}
return 0;
}
-int
-Write_Extended(int fd, struct disk *new, struct disk *old, struct chunk *c1)
-{
- return 0;
-}
-
#if defined(__i386__) && !defined(PC98)
static void
Write_Int32(u_int32_t *p, u_int32_t v)
@@ -189,7 +168,7 @@ Cfg_Boot_Mgr(u_char *mbr, int edd)
#endif
int
-Write_Disk(struct disk *d1)
+Write_Disk(const struct disk *d1)
{
int fd,i;
#ifdef __i386__
@@ -235,9 +214,9 @@ Write_Disk(struct disk *d1)
memset(s,0,sizeof s);
#ifdef PC98
- mbr = read_block(fd, WHERE(1, d1), d1->sector_size);
+ mbr = read_block(fd, 1, d1->sector_size);
#else
- mbr = read_block(fd, WHERE(0, d1), d1->sector_size);
+ mbr = read_block(fd, 0, d1->sector_size);
#endif
dp = (struct dos_partition*)(mbr + DOSPARTOFF);
memcpy(work, dp, sizeof work);
@@ -257,10 +236,6 @@ Write_Disk(struct disk *d1)
continue;
s[j]++;
#endif
-#ifndef PC98
- if (c1->type == extended)
- ret += Write_Extended(fd, d1, old, c1);
-#endif
if (c1->type == freebsd)
ret += Write_FreeBSD(fd, d1, old, c1);
@@ -370,9 +345,9 @@ Write_Disk(struct disk *d1)
#ifdef PC98
if (d1->bootipl)
- write_block(fd, WHERE(0, d1), d1->bootipl, d1->sector_size);
+ write_block(fd, 0, d1->bootipl, d1->sector_size);
- mbr = read_block(fd, WHERE(1, d1), d1->sector_size);
+ mbr = read_block(fd, 1, d1->sector_size);
memcpy(mbr + DOSPARTOFF, dp, sizeof *dp * NDOSPART);
/* XXX - for entire FreeBSD(98) */
for (c1 = d1->chunks->part; c1; c1 = c1->next)
@@ -380,13 +355,13 @@ Write_Disk(struct disk *d1)
&& (c1->offset == 0))
PC98_EntireDisk = 1;
if (PC98_EntireDisk == 0)
- write_block(fd, WHERE(1, d1), mbr, d1->sector_size);
+ write_block(fd, 1, mbr, d1->sector_size);
if (d1->bootmenu)
for (i = 0; i * d1->sector_size < d1->bootmenu_size; i++)
- write_block(fd, WHERE(2 + i, d1), &d1->bootmenu[i * d1->sector_size], d1->sector_size);
+ write_block(fd, 2 + i, &d1->bootmenu[i * d1->sector_size], d1->sector_size);
#else
- mbr = read_block(fd, WHERE(0, d1), d1->sector_size);
+ mbr = read_block(fd, 0, d1->sector_size);
if (d1->bootmgr) {
memcpy(mbr, d1->bootmgr, DOSPARTOFF);
Cfg_Boot_Mgr(mbr, need_edd);
@@ -394,10 +369,10 @@ Write_Disk(struct disk *d1)
memcpy(mbr + DOSPARTOFF, dp, sizeof *dp * NDOSPART);
mbr[512-2] = 0x55;
mbr[512-1] = 0xaa;
- write_block(fd, WHERE(0, d1), mbr, d1->sector_size);
+ write_block(fd, 0, mbr, d1->sector_size);
if (d1->bootmgr && d1->bootmgr_size > d1->sector_size)
for(i = 1; i * d1->sector_size <= d1->bootmgr_size; i++)
- write_block(fd, WHERE(i, d1), &d1->bootmgr[i * d1->sector_size], d1->sector_size);
+ write_block(fd, i, &d1->bootmgr[i * d1->sector_size], d1->sector_size);
#endif
#endif
OpenPOWER on IntegriCloud