-/* $OpenBSD: i386_installboot.c,v 1.4 2013/12/27 15:02:49 jsing Exp $ */
+/* $OpenBSD: i386_installboot.c,v 1.5 2014/01/18 03:07:05 jsing Exp $ */
/* $NetBSD: installboot.c,v 1.5 1995/11/17 23:23:50 gwr Exp $ */
/*
#include "installboot.h"
#include "i386_installboot.h"
+char *bootldr;
+
char *blkstore;
size_t blksize;
{
stages = 2;
stage1 = "/usr/mdec/biosboot";
- stage2 = "/boot";
+ stage2 = "/usr/mdec/boot";
+
+ bootldr = "/boot";
}
void
if (dl.d_type == 0)
warnx("disklabel type unknown");
+ bootldr = fileprefix(root, bootldr);
+ if (!nowrite)
+ filecopy(stage2, bootldr);
+
/* Get bootstrap parameters to patch into proto. */
- if (getbootparams(stage2, devfd, &dl) != 0)
+ if (getbootparams(bootldr, devfd, &dl) != 0)
exit(1);
/* Write boot blocks to device. */
-.\" $OpenBSD: installboot.8,v 1.2 2014/01/18 02:47:27 jsing Exp $
+.\" $OpenBSD: installboot.8,v 1.3 2014/01/18 03:07:05 jsing Exp $
.\"
.\" Copyright (c) 2013, 2014 Joel Sing
.\"
amd64 machine, using
.Ar /usr/mdec/biosboot
as the primary bootstrap and
-.Ar /boot
+.Ar /usr/mdec/boot
as the secondary bootstrap:
.Bd -literal -offset 3n
-# cp /usr/mdec/boot /boot
-# installboot -v wd0 /usr/mdec/biosboot /boot
+# installboot -v wd0 /usr/mdec/biosboot /usr/mdec/boot
.Ed
.Sh SEE ALSO
.Xr disklabel 8
-/* $OpenBSD: installboot.h,v 1.3 2014/01/18 02:47:27 jsing Exp $ */
+/* $OpenBSD: installboot.h,v 1.4 2014/01/18 03:07:05 jsing Exp $ */
/*
* Copyright (c) 2012, 2013 Joel Sing <jsing@openbsd.org>
*
void bootstrap(int, char *, char *);
#endif
+void filecopy(const char *, const char *);
char *fileprefix(const char *, const char *);
void md_init(void);
-/* $OpenBSD: sparc64_installboot.c,v 1.3 2013/12/28 15:05:34 jsing Exp $ */
+/* $OpenBSD: sparc64_installboot.c,v 1.4 2014/01/18 03:07:05 jsing Exp $ */
/*
* Copyright (c) 2012, 2013 Joel Sing <jsing@openbsd.org>
#include "installboot.h"
+char *bootldr;
+
char *blkstore;
char *ldrstore;
size_t blksize;
{
stages = 2;
stage1 = "/usr/mdec/bootblk";
- stage2 = "/ofwboot";
+ stage2 = "/usr/mdec/ofwboot";
+
+ bootldr = "/ofwboot";
}
void
/* XXX - is this necessary? */
sync();
+ bootldr = fileprefix(root, bootldr);
+ if (!nowrite)
+ filecopy(stage2, bootldr);
+
/* Write bootblock into the superblock. */
if (lseek(devfd, DEV_BSIZE, SEEK_SET) != DEV_BSIZE)
err(1, "lseek");
-/* $OpenBSD: util.c,v 1.1 2014/01/18 02:47:27 jsing Exp $ */
+/* $OpenBSD: util.c,v 1.2 2014/01/18 03:07:05 jsing Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*/
#include <sys/param.h>
+#include <sys/stat.h>
#include <err.h>
+#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include "installboot.h"
+#define BUFSIZE 2048
+
+void
+filecopy(const char *srcfile, const char *dstfile)
+{
+ char *buf, tempfile[MAXPATHLEN];
+ struct stat sb;
+ ssize_t sz, n;
+ int sfd, dfd;
+
+ if ((buf = malloc(BUFSIZE)) == NULL)
+ err(1, "malloc");
+
+ sfd = open(srcfile, O_RDONLY);
+ if (sfd == -1)
+ err(1, "open");
+ if (fstat(sfd, &sb) == -1)
+ err(1, "fstat");
+ sz = sb.st_size;
+
+ snprintf(tempfile, sizeof(tempfile), "%s.XXXXXXXX", dstfile);
+ dfd = mkstemp(tempfile);
+ if (dfd == -1)
+ err(1, "mkstemp");
+
+ if (chown(tempfile, 0, 0) == -1)
+ err(1, "chown");
+ if (chmod(tempfile, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) == -1)
+ err(1, "chmod");
+
+ if (verbose)
+ fprintf(stderr, "Copying %s to %s\n", srcfile, tempfile);
+
+ while (sz > 0) {
+ n = MIN(sz, BUFSIZE);
+ if ((n = read(sfd, buf, n)) == -1)
+ err(1, "read");
+ sz -= n;
+ if (write(dfd, buf, n) != n)
+ err(1, "write");
+ }
+
+ close(dfd);
+ close(sfd);
+ free(buf);
+
+ if (verbose)
+ fprintf(stderr, "Renaming %s to %s\n", tempfile, dstfile);
+
+ if (rename(tempfile, dstfile) == -1)
+ err(1, "rename");
+}
+
char *
fileprefix(const char *base, const char *path)
{