From: kn Date: Sat, 3 Sep 2022 15:46:20 +0000 (+0000) Subject: Fix passing explicit stage files X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=d5142bb915074fc23db8c54d652b6bfa1e3c19bc;p=openbsd Fix passing explicit stage files Every platform ought to set `stages', `stage1' and optionally `stage2' in md_init(), otherwise passing explicit files results won't work as `stages' is zero-initialised and no default path is set: # installboot -nv wd0 ./ofwboot usage: installboot [-nv] [-r root] disk [stage1] installboot [-nv] -p disk This is correct synopsis and ought to work, but macppc_installboot.c (others, too) has an empty md_init(). Set stage bits to fix this: # ./obj/installboot -nv wd0 ./ofwboot Using / as root would install bootstrap on /dev/rwd0c using first-stage ./ofwboot would copy ./ofwboot to /tmp/installboot.Ymmm6QU8OJ/ofwboot Using `stage1' leads to a bit more cleanup since early MI installboot.c handles `-r', i.e. write_filesystem() no longer has needs to do the fileprefix() dance itself. This makes regress/usr.sbin/installboot pass on macppc (while being lucky or carrying miod's fix for the kernel disklabel race manifesting on vnd). OK gkoehler --- diff --git a/usr.sbin/installboot/macppc_installboot.c b/usr.sbin/installboot/macppc_installboot.c index b14bc276f23..0eb3af5d4f8 100644 --- a/usr.sbin/installboot/macppc_installboot.c +++ b/usr.sbin/installboot/macppc_installboot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: macppc_installboot.c,v 1.5 2022/08/31 20:52:15 krw Exp $ */ +/* $OpenBSD: macppc_installboot.c,v 1.6 2022/09/03 15:46:20 kn Exp $ */ /* * Copyright (c) 2011 Joel Sing @@ -60,6 +60,8 @@ static int findmbrfat(int, struct disklabel *); void md_init(void) { + stages = 1; + stage1 = "/usr/mdec/ofwboot"; } void @@ -161,12 +163,9 @@ write_filesystem(struct disklabel *dl, char part) struct msdosfs_args args; char cmd[60]; char dst[PATH_MAX]; - char *src; - size_t mntlen, pathlen, srclen; + size_t mntlen, pathlen; int rslt; - src = NULL; - /* Create directory for temporary mount point. */ strlcpy(dst, "/tmp/installboot.XXXXXXXXXX", sizeof(dst)); if (mkdtemp(dst) == NULL) @@ -224,17 +223,11 @@ write_filesystem(struct disklabel *dl, char part) warn("unable to build /ofwboot path"); goto umount; } - src = fileprefix(root, "/usr/mdec/ofwboot"); - if (src == NULL) { - rslt = -1; - goto umount; - } - srclen = strlen(src); if (verbose) fprintf(stderr, "%s %s to %s\n", - (nowrite ? "would copy" : "copying"), src, dst); + (nowrite ? "would copy" : "copying"), stage1, dst); if (!nowrite) { - rslt = filecopy(src, dst); + rslt = filecopy(stage1, dst); if (rslt == -1) goto umount; } @@ -252,8 +245,6 @@ rmdir: if (rmdir(dst) == -1) err(1, "rmdir('%s') failed", dst); - free(src); - if (rslt == -1) exit(1); }