This commit is contained in:
mrg 1998-06-20 13:05:48 +00:00
parent 077ba12357
commit d1b0d1b602
15 changed files with 763 additions and 590 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: factor.c,v 1.8 1998/02/20 07:43:52 phil Exp $ */
/* $NetBSD: factor.c,v 1.9 1998/06/20 13:05:48 mrg Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -38,8 +38,12 @@
/* Prototypes for strict prototyping. */
static void build_primes (long max);
void factor (long val, long *fact_list, int fact_size, int *num_fact);
#include <sys/cdefs.h>
#include <stdio.h>
static void build_primes __P((long max));
void factor __P((long val, long *fact_list, int fact_size, int *num_fact));
/*
* primes - prime table, built to include up to 46345 because
@ -52,7 +56,9 @@ void factor (long val, long *fact_list, int fact_size, int *num_fact);
long primes[4800];
int num_primes = 2;
static void build_primes (long max)
static void
build_primes(max)
long max;
{
long pc;
int j;
@ -68,7 +74,7 @@ static void build_primes (long max)
for (pc = primes[num_primes-1]; pc < 46345 && pc*pc <= max; pc+=2) {
j = 0;
rem = 1;
while (j<num_primes && primes[j]*primes[j] <= pc) {
while (j < num_primes && primes[j] * primes[j] <= pc) {
if ((rem = pc % primes[j]) == 0)
break;
j++;
@ -82,7 +88,12 @@ static void build_primes (long max)
The last number may not be a prime factor is the list is not
long enough. */
void factor (long val, long *fact_list, int fact_size, int *num_fact)
void
factor(val, fact_list, fact_size, num_fact)
long val;
long *fact_list;
int fact_size;
int *num_fact;
{
int i;
@ -97,7 +108,7 @@ void factor (long val, long *fact_list, int fact_size, int *num_fact)
/* Put factors in array. */
while (*num_fact < fact_size-1 && i < num_primes &&
val % primes[i] == 0) {
val % primes[i] == 0) {
fact_list[(*num_fact)++] = primes[i];
val /= primes[i];
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: fdisk.c,v 1.7 1998/02/27 21:30:09 phil Exp $ */
/* $NetBSD: fdisk.c,v 1.8 1998/06/20 13:05:48 mrg Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -39,6 +39,7 @@
/* fdisk.c -- routines to deal with /sbin/fdisk ... */
#include <stdio.h>
#include "defs.h"
#include "md.h"
#include "txtwalk.h"
@ -72,36 +73,37 @@ struct lookfor fdiskbuf[] = {
int numfdiskbuf = sizeof(fdiskbuf) / sizeof(struct lookfor);
/*
* Fetch current MBR from disk into core by parsing /sbin/fdisk output.
*/
void get_fdisk_info (void)
void
get_fdisk_info()
{
char *textbuf;
int textsize;
int t1, t2;
/* Get Fdisk information */
textsize = collect (T_OUTPUT, &textbuf,
"/sbin/fdisk -S /dev/r%sd 2>/dev/null", diskdev);
textsize = collect(T_OUTPUT, &textbuf,
"/sbin/fdisk -S /dev/r%sd 2>/dev/null", diskdev);
if (textsize < 0) {
endwin();
(void) fprintf (stderr, "Could not run fdisk.");
(void)fprintf(stderr, "Could not run fdisk.");
exit (1);
}
walk (textbuf, textsize, fdiskbuf, numfdiskbuf);
free (textbuf);
/* A common failure of fdisk is to get the number of cylinders
wrong and the number of sectors and heads right. This makes
a disk look very big. In this case, we can just recompute
the number of cylinders and things should work just fine.
Also, fdisk may correctly indentify the settings to include
a cylinder total > 1024, because translation mode is not used.
Check for it. */
walk(textbuf, textsize, fdiskbuf, numfdiskbuf);
free(textbuf);
/*
* A common failure of fdisk is to get the number of cylinders
* wrong and the number of sectors and heads right. This makes
* a disk look very big. In this case, we can just recompute
* the number of cylinders and things should work just fine.
* Also, fdisk may correctly indentify the settings to include
* a cylinder total > 1024, because translation mode is not used.
* Check for it.
*/
/* XXX should warn user about this, and maybe ask! */
if (bcyl > 1024 && disk->geom[1] == bhead && disk->geom[2] == bsec)
bcyl = 1024;
else if (bcyl > 1024 && bsec < 64) {
@ -119,24 +121,25 @@ void get_fdisk_info (void)
* Write incore MBR geometry and partition info to disk
* using /sbin/fdisk.
*/
void set_fdisk_info (void)
void
set_fdisk_info()
{
int i;
if (bstuffset)
run_prog ("/sbin/fdisk -i -f -b %d/%d/%d /dev/r%sd",
run_prog("/sbin/fdisk -i -f -b %d/%d/%d /dev/r%sd",
bcyl, bhead, bsec, diskdev);
for (i=0; i<4; i++)
for (i = 0; i < 4; i++)
if (part[i][SET])
run_prog("/sbin/fdisk -u -f -%d -b %d/%d/%d "
"-s %d/%d/%d /dev/r%sd",
i, bcyl, bhead, bsec,
part[i][ID], part[i][START],
part[i][SIZE], diskdev);
"-s %d/%d/%d /dev/r%sd",
i, bcyl, bhead, bsec,
part[i][ID], part[i][START],
part[i][SIZE], diskdev);
if (activepart >= 0)
run_prog ("/sbin/fdisk -a -%d -f /dev/r%s",
activepart, diskdev);
run_prog("/sbin/fdisk -a -%d -f /dev/r%s",
activepart, diskdev);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: geom.c,v 1.1 1997/10/15 04:35:40 phil Exp $ */
/* $NetBSD: geom.c,v 1.2 1998/06/20 13:05:48 mrg Exp $ */
/*
* Copyright (c) 1995, 1997 Jason R. Thorpe.
@ -41,11 +41,13 @@
#include <unistd.h>
#include <util.h>
/* Visible functions */
int get_geom __P((char *, struct disklabel *));
int get_geom (char *disk, struct disklabel *l)
int
get_geom(disk, l)
char *disk;
struct disklabel *l;
{
char diskpath[MAXPATHLEN];
int fd;
@ -56,9 +58,9 @@ int get_geom (char *disk, struct disklabel *l)
return 0;
if (ioctl(fd, DIOCGDEFLABEL, (char *)l) < 0) {
(void) close(fd);
(void)close(fd);
return 0;
}
(void) close(fd);
(void)close(fd);
return 1;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: install.c,v 1.11 1998/05/15 15:12:30 fvdl Exp $ */
/* $NetBSD: install.c,v 1.12 1998/06/20 13:05:48 mrg Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -46,65 +46,66 @@
/* Do the system install. */
void do_install(void)
void
do_install()
{
doingwhat = msg_string (MSG_install);
doingwhat = msg_string(MSG_install);
msg_display (MSG_installusure);
process_menu (MENU_noyes);
msg_display(MSG_installusure);
process_menu(MENU_noyes);
if (!yesno)
return;
get_ramsize();
if (find_disks () < 0)
if (find_disks() < 0)
return;
/* if we need the user to mount root, ask them to. */
if (must_mount_root()) {
msg_display(MSG_pleasemountroot, diskdev, diskdev, diskdev);
process_menu (MENU_ok);
process_menu(MENU_ok);
return;
}
if (!md_get_info ()) {
msg_display (MSG_abort);
if (!md_get_info()) {
msg_display(MSG_abort);
return;
}
if (md_make_bsd_partitions () == 0) {
if (md_make_bsd_partitions() == 0) {
msg_display(MSG_abort);
return;
}
/* Last chance ... do you really want to do this? */
msg_display (MSG_lastchance);
process_menu (MENU_noyes);
msg_display(MSG_lastchance);
process_menu(MENU_noyes);
if (!yesno)
return;
/* Leave curses so program output looks good. */
endwin ();
endwin();
md_pre_disklabel ();
md_pre_disklabel();
write_disklabel ();
write_disklabel();
md_post_disklabel ();
md_post_disklabel();
make_filesystems ();
make_filesystems();
md_copy_filesystem ();
md_copy_filesystem();
make_fstab();
md_post_newfs ();
md_post_newfs();
/* Done to here. */
printf("%s", msg_string(MSG_disksetupdone));
getchar();
puts (CL); /* just to make sure */
puts(CL); /* just to make sure */
wrefresh(stdscr);
/* Unpack the distribution. */

View File

@ -1,4 +1,4 @@
/* $NetBSD: label.c,v 1.4 1997/12/18 11:54:11 fvdl Exp $ */
/* $NetBSD: label.c,v 1.5 1998/06/20 13:05:49 mrg Exp $ */
/*
* Copyright 1997 Jonathan Stone
@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: label.c,v 1.4 1997/12/18 11:54:11 fvdl Exp $");
__RCSID("$NetBSD: label.c,v 1.5 1998/06/20 13:05:49 mrg Exp $");
#endif
#include <sys/types.h>
@ -68,7 +68,11 @@ void translate_partinfo __P((partinfo *lp, struct partition *pp));
* for overlapping partitions.
*/
static int
boringpart(partinfo *lp, int i, int rawpart, int bsdpart)
boringpart(lp, i, rawpart, bsdpart)
partinfo *lp;
int i;
int rawpart;
int bsdpart;
{
if (i == rawpart || i == bsdpart ||
@ -86,8 +90,13 @@ boringpart(partinfo *lp, int i, int rawpart, int bsdpart)
* overlapping partitions if any are found.
*/
int
checklabel(partinfo *lp, int nparts, int rawpart, int bsdpart,
int *ovly1, int *ovly2)
checklabel(lp, nparts, rawpart, bsdpart, ovly1, ovly2)
partinfo *lp;
int nparts;
int rawpart;
int bsdpart;
int *ovly1;
int *ovly2;
{
int i;
int j;
@ -96,7 +105,7 @@ checklabel(partinfo *lp, int nparts, int rawpart, int bsdpart,
*ovly2 = -1;
for (i = 0; i < nparts - 1; i ++ ) {
int *ip = lp[i];
int *ip = lp[i];
int istart, istop;
/* skip unused or reserved partitions */
@ -126,12 +135,12 @@ checklabel(partinfo *lp, int nparts, int rawpart, int bsdpart,
(jstart <= istart && istart < jstop)) {
*ovly1 = i;
*ovly2 = j;
return(1);
return (1);
}
}
}
return(0);
return (0);
}
@ -141,13 +150,17 @@ checklabel(partinfo *lp, int nparts, int rawpart, int bsdpart,
* Ask the user if they want to edit the parittion or give up.
*/
int
edit_and_check_label(partinfo *lp, int nparts, int rawpart, int bsdpart)
edit_and_check_label(lp, nparts, rawpart, bsdpart)
partinfo *lp;
int nparts;
int rawpart;
int bsdpart;
{
while (1) {
int i, j;
/* first give the user the option to edit the label... */
process_menu (MENU_fspartok);
process_menu(MENU_fspartok);
/* User thinks the label is OK. check for overlaps.*/
if (checklabel(lp, nparts, rawpart, bsdpart, &i, &j) == 0) {
@ -168,7 +181,9 @@ edit_and_check_label(partinfo *lp, int nparts, int rawpart, int bsdpart)
}
void emptylabel(partinfo *lp)
void
emptylabel(lp)
partinfo *lp;
{
register int i, maxpart;
@ -184,39 +199,41 @@ void emptylabel(partinfo *lp)
}
int
savenewlabel(partinfo *lp, int nparts)
savenewlabel(lp, nparts)
partinfo *lp;
int nparts;
{
FILE *f;
int i;
#ifdef DEBUG
f = fopen ("/tmp/disktab", "a");
f = fopen("/tmp/disktab", "a");
#else
f = fopen ("/etc/disktab", "a");
f = fopen("/etc/disktab", "a");
#endif
if (f == NULL) {
endwin();
(void) fprintf (stderr, "Could not open /etc/disktab");
(void)fprintf(stderr, "Could not open /etc/disktab");
exit (1);
}
(void)fprintf (f, "%s|NetBSD installation generated:\\\n", bsddiskname);
(void)fprintf (f, "\t:dt=%s:ty=winchester:\\\n", disktype);
(void)fprintf (f, "\t:nc#%d:nt#%d:ns#%d:\\\n", dlcyl, dlhead, dlsec);
(void)fprintf (f, "\t:sc#%d:su#%d:\\\n", dlhead*dlsec, dlsize);
(void)fprintf (f, "\t:se#%d:%s\\\n", sectorsize, doessf);
for (i=0; i < nparts; i++) {
(void)fprintf (f, "\t:p%c#%d:o%c#%d:t%c=%s:",
'a'+i, bsdlabel[i][D_SIZE],
'a'+i, bsdlabel[i][D_OFFSET],
'a'+i, fstype[bsdlabel[i][D_FSTYPE]]);
(void)fprintf(f, "%s|NetBSD installation generated:\\\n", bsddiskname);
(void)fprintf(f, "\t:dt=%s:ty=winchester:\\\n", disktype);
(void)fprintf(f, "\t:nc#%d:nt#%d:ns#%d:\\\n", dlcyl, dlhead, dlsec);
(void)fprintf(f, "\t:sc#%d:su#%d:\\\n", dlhead*dlsec, dlsize);
(void)fprintf(f, "\t:se#%d:%s\\\n", sectorsize, doessf);
for (i = 0; i < nparts; i++) {
(void)fprintf(f, "\t:p%c#%d:o%c#%d:t%c=%s:",
'a'+i, bsdlabel[i][D_SIZE],
'a'+i, bsdlabel[i][D_OFFSET],
'a'+i, fstype[bsdlabel[i][D_FSTYPE]]);
if (bsdlabel[i][D_FSTYPE] == T_42BSD)
(void)fprintf (f, "b%c#%d:f%c#%d",
'a'+i, bsdlabel[i][D_BSIZE],
'a'+i, bsdlabel[i][D_FSIZE]);
if (i < 7)
(void)fprintf (f, "\\\n");
(void)fprintf(f, "\\\n");
else
(void)fprintf (f, "\n");
(void)fprintf(f, "\n");
}
fclose (f);
@ -225,8 +242,11 @@ savenewlabel(partinfo *lp, int nparts)
void
translate_partinfo(partinfo *lp, struct partition *pp)
translate_partinfo(lp, pp)
partinfo *lp;
struct partition *pp;
{
switch (pp->p_fstype) {
case FS_UNUSED: /* XXX */
@ -260,7 +280,10 @@ translate_partinfo(partinfo *lp, struct partition *pp)
/*
* Read a label from disk into a sysist label structure.
*/
int incorelabel(const char *dkname, partinfo *lp)
int
incorelabel(dkname, lp)
const char *dkname;
partinfo *lp;
{
struct disklabel lab;
int fd;
@ -277,7 +300,8 @@ int incorelabel(const char *dkname, partinfo *lp)
close(fd);
maxpart = getmaxpartitions();
if (maxpart > 16) maxpart = 16;
if (maxpart > 16)
maxpart = 16;
/* XXX set globals used by MD code to compute disk size? */

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.8 1997/12/05 13:38:59 simonb Exp $ */
/* $NetBSD: main.c,v 1.9 1998/06/20 13:05:49 mrg Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -49,31 +49,34 @@
#include "msg_defs.h"
#include "menu_defs.h"
int main(int argc, char **argv);
static void usage(void);
static void inthandler(int);
static void cleanup(void);
int main __P((int argc, char **argv));
static void usage __P((void));
static void inthandler __P((int));
static void cleanup __P((void));
static int exit_cleanly = 0; /* Did we finish nicely? */
int main(int argc, char **argv)
int
main(argc, argv)
int argc;
char **argv;
{
WINDOW *win;
int ch;
/* Check for TERM ... */
if (!getenv("TERM")) {
(void)fprintf (stderr,
(void)fprintf(stderr,
"sysinst: environment varible TERM not set.\n");
exit(1);
}
/* argv processing */
while ((ch = getopt(argc, argv, "r:")) != -1)
while ((ch = getopt(argc, argv, "r:")) != -1)
switch(ch) {
case 'r':
/* Release name other than compiled in release. */
strncpy (rel, optarg, SSTRSIZE);
strncpy(rel, optarg, SSTRSIZE);
break;
case '?':
default:
@ -82,15 +85,15 @@ int main(int argc, char **argv)
/* initialize message window */
win = newwin(22,78,1,1);
win = newwin(22, 78, 1, 1); /* XXX BOGUS XXX */
msg_window(win);
/* Watch for SIGINT and clean up */
(void) signal(SIGINT, inthandler);
(void) atexit(cleanup);
(void)signal(SIGINT, inthandler);
(void)atexit(cleanup);
/* Menu processing */
process_menu (MENU_netbsd);
process_menu(MENU_netbsd);
exit_cleanly = 1;
exit(0);
@ -98,10 +101,12 @@ int main(int argc, char **argv)
/* toplevel menu handler ... */
void toplevel(void)
void
toplevel()
{
/* Display banner message in (english, francais, deutche..) */
msg_display (MSG_hello);
msg_display(MSG_hello);
/*
* Undo any stateful side-effects of previous menu choices.
@ -116,24 +121,28 @@ void toplevel(void)
/* The usage ... */
static void
usage(void)
usage()
{
(void)fprintf (stderr, msg_string(MSG_usage));
(void)fprintf(stderr, msg_string(MSG_usage));
exit(1);
}
/* ARGSUSED */
static void
inthandler(int notused)
inthandler(notused)
int notused;
{
/* atexit() wants a void function, so inthandler() just calls cleanup */
cleanup();
exit(1);
}
static void
cleanup(void)
cleanup()
{
endwin();
unwind_mounts();
run_prog("/sbin/umount /mnt2 2>/dev/null");

View File

@ -1,4 +1,4 @@
/* $NetBSD: mbr.c,v 1.6 1998/02/24 05:36:03 jonathan Exp $ */
/* $NetBSD: mbr.c,v 1.7 1998/06/20 13:05:49 mrg Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -59,8 +59,8 @@ struct part_id {
{7, "NTFS"},
{131, "Linux native"},
{131, "Linux swap"},
{165, "NetBSD/FreeBSD/386bsd"},
{169, "new NetBSD"},
{165, "old NetBSD/FreeBSD/386BSD"},
{169, "NetBSD"},
{-1, "Unknown"},
};
@ -88,43 +88,45 @@ struct part_id {
int dosptyp_nbsd = DOSPTYP_OURS;
/* prototypes */
int otherpart(int id);
int ourpart(int id);
int otherpart __P((int id));
int ourpart __P((int id));
int edit_mbr __P((void));
/*
* First, geometry stuff...
*/
int check_geom (void)
int
check_geom()
{
return bcyl <= 1024 && bsec < 64 && bcyl > 0 && bhead > 0 && bsec > 0;
}
/*
* get C/H/S geometry from user via menu interface and
* store in globals.
*/
void set_fdisk_geom (void)
void
set_fdisk_geom()
{
char res[80];
msg_display_add(MSG_setbiosgeom);
disp_cur_geom();
msg_printf_add ("\n");
msg_prompt_add (MSG_cylinders, NULL, res, 80);
msg_printf_add("\n");
msg_prompt_add(MSG_cylinders, NULL, res, 80);
bcyl = atoi(res);
msg_prompt_add (MSG_heads, NULL, res, 80);
msg_prompt_add(MSG_heads, NULL, res, 80);
bhead = atoi(res);
msg_prompt_add (MSG_sectors, NULL, res, 80);
msg_prompt_add(MSG_sectors, NULL, res, 80);
bsec = atoi(res);
bstuffset = 1;
}
void disp_cur_geom (void)
void
disp_cur_geom()
{
msg_display_add(MSG_realgeom, dlcyl, dlhead, dlsec);
msg_display_add(MSG_biosgeom, bcyl, bhead, bsec);
}
@ -134,27 +136,32 @@ void disp_cur_geom (void)
* Then, the partition stuff...
*/
int
otherpart(int id)
otherpart(id)
int id;
{
return (id != 0 && id != DOSPTYP_386BSD && id != DOSPTYP_NETBSD);
}
int
ourpart(int id)
ourpart(id)
int id;
{
return (id != 0 && (id == DOSPTYP_386BSD || id == DOSPTYP_NETBSD));
}
/*
* Let user change incore Master Boot Record partitions via menu.
*/
int edit_mbr()
int
edit_mbr()
{
int i, j;
/* Ask full/part */
msg_display (MSG_fullpart, diskdev);
process_menu (MENU_fullpart);
msg_display(MSG_fullpart, diskdev);
process_menu(MENU_fullpart);
/* DOS fdisk label checking and value setting. */
if (usefull) {
@ -166,13 +173,13 @@ int edit_mbr()
for (i = 0; i < 4; i++) {
otherparts += otherpart(part[0][ID]);
/* check for dualboot *bsd too */
ourparts += ourpart(part[0][ID]);
ourparts += ourpart(part[0][ID]);
}
/* Ask if we really want to blow away non-NetBSD stuff */
if (otherparts != 0 || ourparts > 1) {
msg_display (MSG_ovrwrite);
process_menu (MENU_noyes);
msg_display(MSG_ovrwrite);
process_menu(MENU_noyes);
if (!yesno) {
endwin();
return 0;
@ -206,7 +213,7 @@ int edit_mbr()
ask_sizemult();
bsdpart = freebsdpart = -1;
activepart = -1;
for (i=0; i<4; i++)
for (i = 0; i<4; i++)
if (part[i][FLAG] != 0)
activepart = i;
do {
@ -218,7 +225,7 @@ int edit_mbr()
overlap = 0;
yesno = 0;
for (i=0; i<4; i++) {
/* Count 386bsd/FreeBSD/NetBSD partitions */
/* Count 386bsd/FreeBSD/NetBSD(old) partitions */
if (part[i][ID] == DOSPTYP_386BSD) {
freebsdpart = i;
numfreebsd++;
@ -242,20 +249,20 @@ int edit_mbr()
/* Check for overlap or multiple native partitions */
if (overlap || numbsd != 1) {
msg_display (MSG_reeditpart);
process_menu (MENU_yesno);
msg_display(MSG_reeditpart);
process_menu(MENU_yesno);
}
} while (yesno && (numbsd != 1 || overlap));
if (numbsd == 0) {
msg_display (MSG_nobsdpart);
process_menu (MENU_ok);
msg_display(MSG_nobsdpart);
process_menu(MENU_ok);
return 0;
}
if (numbsd > 1) {
msg_display (MSG_multbsdpart, bsdpart);
process_menu (MENU_ok);
msg_display(MSG_multbsdpart, bsdpart);
process_menu(MENU_ok);
}
ptstart = part[bsdpart][START];
@ -279,8 +286,12 @@ int edit_mbr()
return 1;
}
int partsoverlap(int i, int j)
int
partsoverlap(i, j)
int i;
int j;
{
if (part[i][SIZE] == 0 || part[j][SIZE] == 0)
return 0;
@ -292,10 +303,12 @@ int partsoverlap(int i, int j)
part[i][START] < part[j][START] + part[j][SIZE])
||
(part[i][START] == part[j][START]);
}
void disp_cur_part(int sel, int disp)
void
disp_cur_part(sel, disp)
int sel;
int disp;
{
int i, j, start, stop, rsize, rend;
@ -303,11 +316,12 @@ void disp_cur_part(int sel, int disp)
start = 0, stop = 4;
else
start = disp, stop = disp+1;
msg_display_add (MSG_part_head, multname, multname, multname);
for (i=start; i<stop; i++) {
if (sel == i) msg_standout();
msg_display_add(MSG_part_head, multname, multname, multname);
for (i = start; i < stop; i++) {
if (sel == i)
msg_standout();
if (part[i][SIZE] == 0 && part[i][START] == 0)
msg_printf_add ("%d %36s ", i, "");
msg_printf_add("%d %36s ", i, "");
else {
rsize = part[i][SIZE] / sizemult;
if (part[i][SIZE] % sizemult)
@ -316,8 +330,7 @@ void disp_cur_part(int sel, int disp)
if ((part[i][SIZE] + part[i][SIZE]) % sizemult)
rend++;
msg_printf_add("%d %12d%12d%12d ", i,
part[i][START] / sizemult,
rsize, rend);
part[i][START] / sizemult, rsize, rend);
}
for (j = 0; part_ids[j].id != -1 &&
part_ids[j].id != part[i][ID]; j++);

View File

@ -1,4 +1,4 @@
/* $NetBSD: mbr.h,v 1.1 1998/02/24 05:36:03 jonathan Exp $ */
/* $NetBSD: mbr.h,v 1.2 1998/06/20 13:05:49 mrg Exp $ */
/*
* Copyright 1997, 1988 Piermont Information Systems Inc.
@ -57,13 +57,13 @@ EXTERN int usefull; /* on install, clobber entire disk */
/* from mbr.c */
void set_fdisk_geom (void); /* edit incore BIOS geometry */
void disp_cur_geom (void);
int check_geom (void); /* primitive geometry sanity-check */
void set_fdisk_geom __P((void)); /* edit incore BIOS geometry */
void disp_cur_geom __P((void));
int check_geom __P((void)); /* primitive geometry sanity-check */
int edit_mbr __P((void));
int partsoverlap (int, int); /* primive partition sanity-check */
int partsoverlap __P((int, int)); /* primive partition sanity-check */
/* from fdisk.c */
void get_fdisk_info (void); /* read from disk into core */
void set_fdisk_info (void); /* write incore info into disk */
void get_fdisk_info __P((void)); /* read from disk into core */
void set_fdisk_info __P((void)); /* write incore info into disk */

View File

@ -1,4 +1,4 @@
/* $NetBSD: net.c,v 1.29 1998/02/09 07:34:16 thorpej Exp $ */
/* $NetBSD: net.c,v 1.30 1998/06/20 13:05:50 mrg Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -55,7 +55,11 @@ int network_up = 0;
/* Get the list of network interfaces. */
static void get_ifconfig_info (void)
static void get_ifconfig_info __P((void));
static void get_ifinterface_info __P((void));
static void
get_ifconfig_info()
{
char *textbuf;
int textsize;
@ -63,27 +67,26 @@ static void get_ifconfig_info (void)
/* Get ifconfig information */
textsize = collect (T_OUTPUT, &textbuf,
"/sbin/ifconfig -l 2>/dev/null");
textsize = collect(T_OUTPUT, &textbuf, "/sbin/ifconfig -l 2>/dev/null");
if (textsize < 0) {
endwin();
(void) fprintf (stderr, "Could not run ifconfig.");
exit (1);
(void)fprintf(stderr, "Could not run ifconfig.");
exit(1);
}
(void) strtok(textbuf,"\n");
strncpy (net_devices, textbuf, textsize<STRSIZE ? textsize : STRSIZE);
(void)strtok(textbuf,"\n");
strncpy(net_devices, textbuf, textsize<STRSIZE ? textsize : STRSIZE);
net_devices[STRSIZE] = 0;
free (textbuf);
free(textbuf);
/* Remove lo0 and anything after ... */
t = strstr (net_devices, "lo0");
t = strstr(net_devices, "lo0");
if (t != NULL)
*t = 0;
}
/* Fill in defaults network values for the selected interface */
static void get_ifinterface_info(void)
static void
get_ifinterface_info()
{
char *textbuf;
int textsize;
@ -92,7 +95,7 @@ static void get_ifinterface_info(void)
/* First look to see if the selected interface is already configured. */
textsize = collect(T_OUTPUT, &textbuf, "/sbin/ifconfig %s 2>/dev/null",
net_dev);
net_dev);
if (textsize >= 0) {
(void)strtok(textbuf, " \t\n"); /* ignore interface name */
while ((t = strtok(NULL, " \t\n")) != NULL) {
@ -100,13 +103,11 @@ static void get_ifinterface_info(void)
t = strtok(NULL, " \t\n");
if (strcmp(t, "0.0.0.0") != 0)
strcpy(net_ip, t);
}
else if (strcmp(t, "netmask") == 0) {
} else if (strcmp(t, "netmask") == 0) {
t = strtok(NULL, " \t\n");
if (strcmp(t, "0x0") != 0)
strcpy(net_mask, t);
}
else if (strcmp(t, "media:") == 0) {
} else if (strcmp(t, "media:") == 0) {
t = strtok(NULL, " \t\n");
if (strcmp(t, "none") != 0 &&
strcmp(t, "manual") != 0)
@ -120,10 +121,12 @@ static void get_ifinterface_info(void)
strncpy(net_host, hostname, sizeof(net_host));
}
/* Get the information to configure the network, configure it and
make sure both the gateway and the name server are up. */
int config_network (void)
/*
* Get the information to configure the network, configure it and
* make sure both the gateway and the name server are up.
*/
int
config_network()
{ char *tp;
char defname[255];
int octet0;
@ -133,29 +136,28 @@ int config_network (void)
time_t now;
if (network_up)
return 1;
return (1);
network_up = 1;
net_devices[0] = '\0';
get_ifconfig_info ();
get_ifconfig_info();
if (strlen(net_devices) == 0) {
/* No network interfaces found! */
msg_display (MSG_nonet);
process_menu (MENU_ok);
return -1;
msg_display(MSG_nonet);
process_menu(MENU_ok);
return (-1);
}
strncpy (defname, net_devices, 255);
strncpy(defname, net_devices, 255);
tp = defname;
strsep(&tp, " ");
msg_prompt (MSG_asknetdev, defname, net_dev, 255, net_devices);
msg_prompt(MSG_asknetdev, defname, net_dev, 255, net_devices);
tp = net_dev;
strsep(&tp, " ");
net_dev[strlen(net_dev)+1] = 0;
net_dev[strlen(net_dev)] = ' ';
while ((strlen(net_dev) != 4 && strlen(net_dev) != 5) ||
strstr(net_devices, net_dev) == NULL) {
msg_prompt (MSG_badnet, defname, net_dev, 10,
net_devices);
strstr(net_devices, net_dev) == NULL) {
msg_prompt(MSG_badnet, defname, net_dev, 10, net_devices);
tp = net_dev;
strsep(&tp, " ");
net_dev[strlen(net_dev)+1] = 0;
@ -163,54 +165,53 @@ int config_network (void)
}
/* Remove that space we added. */
net_dev[strlen(net_dev)-1] = 0;
net_dev[strlen(net_dev) - 1] = 0;
/* Preload any defaults we can find */
get_ifinterface_info ();
get_ifinterface_info();
pass = strlen(net_mask) == 0 ? 0 : 1;
needmedia = strlen(net_media) == 0 ? 0 : 1;
/* Get other net information */
msg_display (MSG_netinfo);
msg_display(MSG_netinfo);
do {
msg_prompt_add (MSG_net_domain, net_domain, net_domain,
STRSIZE);
msg_prompt_add (MSG_net_host, net_host, net_host, STRSIZE);
msg_prompt_add (MSG_net_ip, net_ip, net_ip, STRSIZE);
msg_prompt_add(MSG_net_domain, net_domain, net_domain, STRSIZE);
msg_prompt_add(MSG_net_host, net_host, net_host, STRSIZE);
msg_prompt_add(MSG_net_ip, net_ip, net_ip, STRSIZE);
octet0 = atoi(net_ip);
if (!pass) {
if (0 <= octet0 && octet0 <= 127)
strcpy (net_mask, "0xff000000");
strcpy(net_mask, "0xff000000");
else if (127 <= octet0 && octet0 <= 191)
strcpy (net_mask, "0xffff0000");
strcpy(net_mask, "0xffff0000");
else if (192 <= octet0 && octet0 <= 223)
strcpy (net_mask, "0xffff0000");
strcpy(net_mask, "0xffff0000");
}
msg_prompt_add (MSG_net_mask, net_mask, net_mask, STRSIZE);
msg_prompt_add (MSG_net_defroute, net_defroute, net_defroute,
msg_prompt_add(MSG_net_mask, net_mask, net_mask, STRSIZE);
msg_prompt_add(MSG_net_defroute, net_defroute, net_defroute,
STRSIZE);
msg_prompt_add (MSG_net_namesrv, net_namesvr, net_namesvr,
msg_prompt_add(MSG_net_namesrv, net_namesvr, net_namesvr,
STRSIZE);
if (needmedia)
msg_prompt_add(MSG_net_media, net_media, net_media,
STRSIZE);
msg_display (MSG_netok, net_domain, net_host, net_ip, net_mask,
msg_display(MSG_netok, net_domain, net_host, net_ip, net_mask,
*net_namesvr == '\0' ? "<none>" : net_namesvr,
*net_defroute == '\0' ? "<none>" : net_defroute,
*net_media == '\0' ? "<default>" : net_media);
process_menu (MENU_yesno);
process_menu(MENU_yesno);
if (!yesno)
msg_display (MSG_netagain);
msg_display(MSG_netagain);
pass++;
} while (!yesno);
/* Create /etc/resolv.conf if a nameserver was given */
if (strcmp(net_namesvr, "") != 0) {
#ifdef DEBUG
f = fopen ("/tmp/resolv.conf", "w");
f = fopen("/tmp/resolv.conf", "w");
#else
f = fopen ("/etc/resolv.conf", "w");
f = fopen("/etc/resolv.conf", "w");
#endif
if (f == NULL) {
endwin();
@ -219,15 +220,15 @@ int config_network (void)
}
time(&now);
/* NB: ctime() returns a string ending in '\n' */
(void)fprintf (f, ";\n; BIND data file\n; %s %s;\n",
"Created by NetBSD sysinst on", ctime(&now));
(void)fprintf(f, ";\n; BIND data file\n; %s %s;\n",
"Created by NetBSD sysinst on", ctime(&now));
(void)fprintf (f,
"nameserver %s\nlookup file bind\nsearch %s\n",
net_namesvr, net_domain);
fclose (f);
"nameserver %s\nlookup file bind\nsearch %s\n",
net_namesvr, net_domain);
fclose(f);
}
run_prog ("/sbin/ifconfig lo0 127.0.0.1");
run_prog("/sbin/ifconfig lo0 127.0.0.1");
if (*net_media != '\0')
run_prog("/sbin/ifconfig %s inet %s netmask %s media %s",
net_dev, net_ip, net_mask, net_media);
@ -236,50 +237,49 @@ int config_network (void)
net_ip, net_mask);
/* Set host name */
if (strcmp(net_host, "") != 0) {
if (strcmp(net_host, "") != 0)
sethostname(net_host, strlen(net_host));
}
/* Set a default route if one was given */
if (strcmp(net_defroute, "") != 0) {
run_prog ("/sbin/route -f > /dev/null 2> /dev/null");
run_prog ("/sbin/route add default %s > /dev/null 2> /dev/null",
run_prog("/sbin/route -f > /dev/null 2> /dev/null");
run_prog("/sbin/route -n add default %s > /dev/null 2> /dev/null",
net_defroute);
}
if (strcmp(net_namesvr, "") != 0 && network_up)
network_up = !run_prog ("/sbin/ping -c 2 %s > /dev/null",
network_up = !run_prog("/sbin/ping -c 2 %s > /dev/null",
net_namesvr);
if (strcmp(net_defroute, "") != 0 && network_up)
network_up = !run_prog ("/sbin/ping -c 2 %s > /dev/null",
network_up = !run_prog("/sbin/ping -c 2 %s > /dev/null",
net_defroute);
return network_up;
}
int
get_via_ftp (void)
get_via_ftp()
{
distinfo *list;
char filename[SSTRSIZE];
int ret;
while (!config_network ()) {
msg_display (MSG_netnotup);
process_menu (MENU_yesno);
while (!config_network()) {
msg_display(MSG_netnotup);
process_menu(MENU_yesno);
if (!yesno)
return 0;
}
cd_dist_dir ("ftp");
cd_dist_dir("ftp");
/* Fill in final values for ftp_dir. */
strncat (ftp_dir, rel, STRSIZE-strlen(ftp_dir));
strcat (ftp_dir, "/");
strncat (ftp_dir, machine, STRSIZE-strlen(ftp_dir));
strncat (ftp_dir, ftp_prefix, STRSIZE-strlen(ftp_dir));
process_menu (MENU_ftpsource);
strncat(ftp_dir, rel, STRSIZE - strlen(ftp_dir));
strcat(ftp_dir, "/");
strncat(ftp_dir, machine, STRSIZE - strlen(ftp_dir));
strncat(ftp_dir, ftp_prefix, STRSIZE - strlen(ftp_dir));
process_menu(MENU_ftpsource);
list = dist_list;
endwin();
@ -288,25 +288,24 @@ get_via_ftp (void)
list++;
continue;
}
snprintf (filename, SSTRSIZE, "%s%s", list->name, dist_postfix);
(void)snprintf(filename, SSTRSIZE, "%s%s", list->name,
dist_postfix);
if (strcmp ("ftp", ftp_user) == 0)
ret = run_prog("/usr/bin/ftp -a 'ftp://%s/%s/%s'",
ftp_host, ftp_dir,
filename);
ftp_host, ftp_dir, filename);
else
ret = run_prog("/usr/bin/ftp 'ftp://%s:%s@%s/%s/%s'",
ftp_user, ftp_pass, ftp_host, ftp_dir,
filename);
ftp_user, ftp_pass, ftp_host, ftp_dir, filename);
if (ret) {
/* Error getting the file. Bad host name ... ? */
msg_display (MSG_ftperror_cont);
msg_display(MSG_ftperror_cont);
getchar();
puts (CL);
wrefresh (stdscr);
msg_display (MSG_ftperror);
process_menu (MENU_yesno);
puts(CL);
wrefresh(stdscr);
msg_display(MSG_ftperror);
process_menu(MENU_yesno);
if (yesno)
process_menu (MENU_ftpsource);
process_menu(MENU_ftpsource);
else
return 0;
endwin();
@ -314,36 +313,38 @@ get_via_ftp (void)
list++;
}
puts (CL); /* Just to make sure. */
wrefresh (stdscr);
puts(CL); /* Just to make sure. */
wrefresh(stdscr);
#ifndef DEBUG
chdir("/"); /* back to current real root */
#endif
return 1;
return (1);
}
int
get_via_nfs(void)
get_via_nfs()
{
while (!config_network ()) {
msg_display (MSG_netnotup);
process_menu (MENU_yesno);
while (!config_network()) {
msg_display(MSG_netnotup);
process_menu(MENU_yesno);
if (!yesno)
return 0;
return (0);
}
/* Get server and filepath */
process_menu (MENU_nfssource);
process_menu(MENU_nfssource);
again:
run_prog("/sbin/umount /mnt2 2> /dev/null");
run_prog("/sbin/umount /mnt2 2> /dev/null");
/* Mount it */
if (run_prog("/sbin/mount -r -o -i,-r=1024 -t nfs %s:%s /mnt2", nfs_host, nfs_dir)) {
msg_display (MSG_nfsbadmount, nfs_host, nfs_dir);
process_menu (MENU_nfsbadmount);
if (run_prog("/sbin/mount -r -o -i,-r=1024 -t nfs %s:%s /mnt2",
nfs_host, nfs_dir)) {
msg_display(MSG_nfsbadmount, nfs_host, nfs_dir);
process_menu(MENU_nfsbadmount);
if (!yesno)
return 0;
return (0);
if (!ignorerror)
goto again;
}
@ -359,7 +360,7 @@ again:
}
/* return location, don't clean... */
strcpy (ext_dir, "/mnt2");
strcpy(ext_dir, "/mnt2");
clean_dist_dir = 0;
mnt2_mounted = 1;
return 1;
@ -370,6 +371,8 @@ again:
* config files in the target disk. Be careful not to lose any
* information we don't immediately add back, in case the install
* target is the currently-active root.
*
* XXXX rc.conf support is needed here!
*/
void
mnt_net_config(void)
@ -379,14 +382,14 @@ mnt_net_config(void)
FILE *f;
if (network_up) {
msg_prompt (MSG_mntnetconfig, ans, ans, 5);
msg_prompt(MSG_mntnetconfig, ans, ans, 5);
if (*ans == 'y') {
/* Write hostname to /etc/myname */
f = target_fopen("/etc/myname", "w");
if (f != 0) {
fprintf(f, "%s\n", net_host);
fclose(f);
(void)fprintf(f, "%s\n", net_host);
(void)fclose(f);
}
/* If not running in target, copy resolv.conf there. */
@ -399,15 +402,14 @@ mnt_net_config(void)
*/
f = target_fopen("/etc/hosts", "a");
if (f != 0) {
fprintf(f, msg_string(MSG_etc_hosts),
net_ip, net_host, net_domain,
net_host);
fclose(f);
(void)fprintf(f, msg_string(MSG_etc_hosts),
net_ip, net_host, net_domain, net_host);
(void)fclose(f);
}
/* Write IPaddr and netmask to /etc/ifconfig.if[0-9] */
snprintf (ifconfig_fn, STRSIZE,
"/etc/ifconfig.%s", net_dev);
snprintf(ifconfig_fn, STRSIZE, "/etc/ifconfig.%s",
net_dev);
f = target_fopen(ifconfig_fn, "w");
if (f != 0) {
if (*net_media != '\0')

View File

@ -1,4 +1,4 @@
/* $NetBSD: run.c,v 1.4 1997/11/03 02:38:50 jonathan Exp $ */
/* $NetBSD: run.c,v 1.5 1998/06/20 13:05:50 mrg Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -56,14 +56,14 @@
/*
* local prototypes
*/
int do_system(const char *cmdstr);
char* va_prog_cmdstr(char *cmd, va_list ap);
int do_system __P((const char *cmdstr));
char* va_prog_cmdstr __P((char *cmd, va_list ap));
#define BUFSIZE 4096
int
collect (int kind, char **buffer, const char *name, ...)
collect(int kind, char **buffer, const char *name, ...)
{
size_t nbytes; /* Number of bytes in buffer. */
size_t fbytes; /* Number of bytes in file. */
@ -73,34 +73,31 @@ collect (int kind, char **buffer, const char *name, ...)
char fileorcmd [STRSIZE];
va_list ap;
va_start (ap, name);
vsnprintf (fileorcmd, STRSIZE, name, ap);
va_end (ap);
va_start(ap, name);
vsnprintf(fileorcmd, STRSIZE, name, ap);
va_end(ap);
if (kind == T_FILE) {
/* Get the file information. */
if (stat (fileorcmd, &st)) {
if (stat(fileorcmd, &st)) {
*buffer = NULL;
return -1;
}
fbytes = (size_t)st.st_size;
/* Open the file. */
f = fopen (fileorcmd, "r");
f = fopen(fileorcmd, "r");
if (f == NULL) {
*buffer = NULL;
return -1;
}
} else {
/* Open the program. */
f = popen (fileorcmd, "r");
f = popen(fileorcmd, "r");
if (f == NULL) {
*buffer = NULL;
return -1;
}
fbytes = BUFSIZE;
}
@ -108,7 +105,7 @@ collect (int kind, char **buffer, const char *name, ...)
fbytes = BUFSIZE;
/* Allocate the buffer size. */
*buffer = (char *) malloc (fbytes + 1);
*buffer = (char *)malloc(fbytes + 1);
if (!*buffer)
return -1;
@ -131,15 +128,19 @@ collect (int kind, char **buffer, const char *name, ...)
/*
* system(3), but with a debug wrapper.
*/
int do_system(const char *execstr)
int
do_system(execstr)
const char *execstr;
{
register int ret;
/* The following may be more than one function call. Can't just
"return Xsystem (command);" */
/*
* The following may be more than one function call. Can't just
* "return Xsystem (command);"
*/
ret = Xsystem (execstr);
return ret;
ret = Xsystem(execstr);
return (ret);
}
@ -147,26 +148,30 @@ int do_system(const char *execstr)
* build command tring for do_system() from anonymous args.
* XXX return result is in a static buffer.
*/
char* va_prog_cmdstr(char *cmd, va_list ap)
char *
va_prog_cmdstr(char *cmd, va_list ap)
{
static char command [STRSIZE];
static char command[STRSIZE];
bzero(command, STRSIZE);
(void) vsnprintf (command, STRSIZE, cmd, ap);
return command;
(void)vsnprintf(command, STRSIZE, cmd, ap);
return (command);
}
/* run a program. The caller handles any and all errors. */
int run_prog (char *cmd, ...)
/*
* run a program. The caller handles any and all errors.
*/
int
run_prog (char *cmd, ...)
{
va_list ap;
int ret;
va_start (ap, cmd);
va_start(ap, cmd);
ret = do_system(va_prog_cmdstr(cmd, ap));
va_end(ap);
return ret;
return (ret);
}
/*
@ -177,23 +182,23 @@ int run_prog (char *cmd, ...)
* Use stderr/stdin since we want the user to see any messages
* from the command before we go back into curses.
*/
int run_prog_or_continue (char *cmd, ...)
int
run_prog_or_continue(char *cmd, ...)
{
va_list ap;
int ret;
const char *execstr;
va_start (ap, cmd);
va_start(ap, cmd);
execstr = va_prog_cmdstr(cmd, ap);
ret = do_system(execstr);
va_end (ap);
va_end(ap);
/* Warn copiously about any errors. */
if (ret) {
/* XXX use messages instead */
printf(msg_string(MSG_anonprogfailed), execstr, strerror(ret));
fgetc(stdin);
/* XXX use messages instead */
printf(msg_string(MSG_anonprogfailed), execstr, strerror(ret));
fgetc(stdin);
}
return ret;
}
@ -208,13 +213,13 @@ void run_prog_or_die (char *cmd, ...)
int ret;
const char *execstr;
va_start (ap, cmd);
va_start(ap, cmd);
execstr = va_prog_cmdstr(cmd, ap);
ret = do_system(execstr);
if (ret) {
printf(msg_string(MSG_progdie), execstr, strerror(ret));
exit(ret);
printf(msg_string(MSG_progdie), execstr, strerror(ret));
exit(ret);
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: target.c,v 1.15 1998/02/20 02:33:51 jonathan Exp $ */
/* $NetBSD: target.c,v 1.16 1998/06/20 13:05:50 mrg Exp $ */
/*
* Copyright 1997 Jonathan Stone
@ -37,10 +37,9 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: target.c,v 1.15 1998/02/20 02:33:51 jonathan Exp $");
__RCSID("$NetBSD: target.c,v 1.16 1998/06/20 13:05:50 mrg Exp $");
#endif
/*
* target.c -- path-prefixing routines to access the target installation
* filesystems. Makes the install tools more ndependent of whether
@ -66,7 +65,6 @@ __RCSID("$NetBSD: target.c,v 1.15 1998/02/20 02:33:51 jonathan Exp $");
#include "msg_defs.h"
#include "menu_defs.h"
/*
* local prototypes
*/
@ -85,7 +83,6 @@ int target_test_file __P((const char *path)); /* deprecated */
void backtowin(void);
void unwind_mounts __P((void));
int mount_with_unwind(const char *fstype, const char *from, const char *on);
@ -96,8 +93,7 @@ struct unwind_mount {
};
/* Unwind-mount stack */
struct unwind_mount *unwind_mountlist = NULL;
struct unwind_mount *unwind_mountlist = NULL;
/*
* Debugging options
@ -105,18 +101,15 @@ struct unwind_mount {
/*#define DEBUG_ROOT*/ /* turn on what-is-root? debugging. */
/*#define DEBUG_UNWIND*/ /* turn on unwind-target-mount debugging. */
/*
* debugging helper. curses...
*/
void backtowin(void)
void
backtowin()
{
fflush(stdout); /* curses does not leave stdout linebuffered. */
getchar(); /* wait for user to press return */
wrefresh(stdscr);
}
@ -125,8 +118,8 @@ void backtowin(void)
* On NetBSD-1.3_ALPHA, this just returns the name of a
* device (e.g., "sd0"), not a specific partition -- like "sd0a",
* or "sd0b" for root-in-swap.
*/
static const char*
*/
static const char *
get_rootdev()
{
int mib[2];
@ -152,9 +145,10 @@ get_rootdev()
* e.g., target is "sd0" and root is "le0" (nfs).
*/
int
target_on_current_disk(void)
target_on_current_disk()
{
int same;
same = (strcmp(diskdev, get_rootdev()) == 0);
return (same);
}
@ -168,14 +162,15 @@ target_on_current_disk(void)
*
* check to see if they're
*/
int must_mount_root(void)
int
must_mount_root()
{
int result;
#if defined(DEBUG) || defined(DEBUG_ROOT)
endwin();
printf("must_mount_root\n");
backtowin();
endwin();
printf("must_mount_root\n");
backtowin();
#endif
/* if they're on different devices, we're OK. */
@ -183,21 +178,20 @@ int must_mount_root(void)
#if defined(DEBUG) || defined(DEBUG_ROOT)
endwin();
printf("must_mount_root: %s and %s, no?\n",
diskdev, get_rootdev());
diskdev, get_rootdev());
fflush(stdout);
backtowin();
#endif
return (0);
}
/* If they're on the same device, and root not mounted, yell. */
result = (strcmp(mounted_rootpart(), "root_device") == 0);
#if defined(DEBUG) || defined(DEBUG_ROOT)
endwin();
printf("must_mount_root %s and root_device gives %d\n",
mounted_rootpart(), result);
mounted_rootpart(), result);
fflush(stdout);
backtowin();
#endif
@ -212,12 +206,12 @@ int must_mount_root(void)
* install/upgrade.
* FIXME -- disklabel-editing code assumes that partition 'a' is always root.
*/
int target_already_root()
int
target_already_root()
{
register int result;
char diskdevroot[STRSIZE];
/* if they're on different devices, we're OK. */
if (target_on_current_disk() == 0)
return (0);
@ -231,7 +225,7 @@ int target_already_root()
/* append 'a' to the partitionless target disk device name. */
snprintf(diskdevroot, STRSIZE, "%s%c", diskdev, 'a');
result = is_active_rootpart(diskdevroot);
return(result);
return (result);
}
@ -244,8 +238,8 @@ int target_already_root()
*
* Don't cache the answer in case the user suspnnds and remounts.
*/
static const char*
mounted_rootpart(void)
static const char *
mounted_rootpart()
{
struct statfs statfsbuf;
int result;
@ -256,7 +250,7 @@ mounted_rootpart(void)
if (result < 0) {
endwin();
fprintf(stderr, "Help! statfs() can't find root: %s\n",
strerror(errno));
strerror(errno));
fflush(stderr);
exit(errno);
return(0);
@ -264,7 +258,7 @@ mounted_rootpart(void)
#if defined(DEBUG)
endwin();
printf("mounted_rootpart: got %s on %s\n",
statfsbuf.f_mntonname, statfsbuf.f_mntfromname);
statfsbuf.f_mntonname, statfsbuf.f_mntfromname);
fflush(stdout);
backtowin();
#endif
@ -273,16 +267,16 @@ mounted_rootpart(void)
* Check for unmounted root. We can't tell which partition
*/
strncpy(statrootstr, statfsbuf.f_mntfromname, STRSIZE);
return(statrootstr);
return (statrootstr);
}
/*
* Is this device partition (e.g., "sd0a") mounted as root?
* Note difference from target_on_current_disk()!
*/
int
is_active_rootpart(const char *devpart)
is_active_rootpart(devpart)
const char *devpart;
{
const char *root = 0;
int result;
@ -299,20 +293,17 @@ is_active_rootpart(const char *devpart)
result = (strcmp(devdirdevpart, root) == 0);
#if defined(DEBUG) || defined(DEBUG_ROOT)
endwin();
printf("is_active_rootpart: activeroot = %s, query=%s, mung=%s, answer=%d\n",
root, devpart, devdirdevpart, result);
root, devpart, devdirdevpart, result);
fflush(stdout);
backtowin();
#endif
return(result);
return (result);
}
/*
* Pathname prefixing glue to support installation either
* from in-ramdisk miniroots or on-disk diskimages.
@ -321,17 +312,16 @@ is_active_rootpart(const char *devpart)
* otherwise we are installing to the currently-active root and
* no prefix is needed.
*/
const char* target_prefix(void)
const char *
target_prefix()
{
/*
* XXX fetch sysctl variable for current root, and compare
* to the devicename of the instllal target disk.
* to the devicename of the install target disk.
*/
return(target_already_root() ? "" : "/mnt");
}
/*
* concatenate two pathnames.
* XXX returns either input args or result in a static buffer.
@ -339,8 +329,10 @@ const char* target_prefix(void)
* next call to a target-prefixing function, or to modify the inputs..
* Used only internally so this is probably safe.
*/
static const char*
concat_paths(const char* prefix, const char *suffix)
static const char*
concat_paths(prefix, suffix)
const char* prefix;
const char *suffix;
{
static char realpath[STRSIZE];
@ -357,11 +349,9 @@ concat_paths(const char* prefix, const char *suffix)
snprintf(realpath, STRSIZE, "%s%s", prefix, suffix);
else
snprintf(realpath, STRSIZE, "%s/%s", prefix, suffix);
return realpath;
return (realpath);
}
/*
* Do target prefix expansion on a pathname.
* XXX uses concat_paths and so returns result in a static buffer.
@ -371,38 +361,42 @@ concat_paths(const char* prefix, const char *suffix)
*
* Not static so other functions can generate target related file names.
*/
const char*
target_expand(const char *tgtpath)
const char *
target_expand(tgtpath)
const char *tgtpath;
{
return concat_paths(target_prefix(), tgtpath);
}
/* Make a directory, with a prefix like "/mnt" or possibly just "". */
static void
make_prefixed_dir(const char *prefix, const char *path)
make_prefixed_dir(prefix, path)
const char *prefix;
const char *path;
{
run_prog_or_continue("/bin/mkdir -p %s", concat_paths(prefix, path));
}
/* Make a directory with a pathname relative to the insatllation target. */
void
make_target_dir(const char *path)
make_target_dir(path)
const char *path;
{
make_prefixed_dir(target_prefix(), path);
}
/* Make a directory with a pathname in the currently-mounted root. */
/* Make a directory with a pathname in the currently-mounted root. */
void
make_ramdisk_dir(const char *path)
make_ramdisk_dir(path)
const char *path;
{
make_prefixed_dir(path, "");
}
/*
*
* Append |string| to the filename |path|, where |path| is
@ -412,8 +406,11 @@ make_ramdisk_dir(const char *path)
* would set the default hostname at the next reboot of the installed-on disk.
*/
void
append_to_target_file(const char *path, const char *string)
append_to_target_file(path, string)
const char *path;
const char *string;
{
run_prog_or_die("echo %s >> %s", string, target_expand(path));
}
@ -421,7 +418,9 @@ append_to_target_file(const char *path, const char *string)
* As append_to_target_file, but with ftrunc semantics.
*/
void
echo_to_target_file(const char *path, const char *string)
echo_to_target_file(path, string)
const char *path;
const char *string;
{
trunc_target_file(path);
append_to_target_file(path, string);
@ -444,12 +443,17 @@ sprintf_to_target_file(const char *path, const char *format, ...)
void
trunc_target_file(const char *path)
trunc_target_file(path)
const char *path;
{
run_prog_or_die("cat < /dev/null > %s", target_expand(path));
}
static int do_target_chdir(const char *dir, int must_succeed)
static int
do_target_chdir(dir, must_succeed)
const char *dir;
int must_succeed;
{
const char *tgt_dir;
int error;
@ -459,9 +463,9 @@ static int do_target_chdir(const char *dir, int must_succeed)
#ifndef DEBUG
/* chdir returns -1 on error and sets errno. */
if (chdir(tgt_dir) < 0) {
if (chdir(tgt_dir) < 0)
error = errno;
}
if (error && must_succeed) {
endwin();
fprintf(stderr, msg_string(MSG_realdir),
@ -475,13 +479,19 @@ static int do_target_chdir(const char *dir, int must_succeed)
#endif
}
void target_chdir_or_die(const char *dir)
void
target_chdir_or_die(dir)
const char *dir;
{
(void) do_target_chdir(dir, 1);
}
int target_chdir(const char *dir)
int
target_chdir(dir)
const char *dir;
{
return(do_target_chdir(dir, 0));
}
@ -490,9 +500,13 @@ int target_chdir(const char *dir)
* where the destination pathname is relative to the target root.
* Does not check for copy-to-self when target is current root.
*/
void cp_to_target(const char *srcpath, const char *tgt_path)
void
cp_to_target(srcpath, tgt_path)
const char *srcpath;
const char *tgt_path;
{
const char *realpath = target_expand(tgt_path);
run_prog ("/bin/cp %s %s", srcpath, realpath);
}
@ -501,16 +515,22 @@ void cp_to_target(const char *srcpath, const char *tgt_path)
* in the target system. Pathname must be an absolute pathname.
* If we're running in the target, do nothing.
*/
void dup_file_into_target(const char *filename)
void
dup_file_into_target(filename)
const char *filename;
{
if (!target_already_root()) {
if (!target_already_root())
cp_to_target(filename, filename);
}
}
/* Do a mv where both pathnames are within the target filesystem. */
void mv_within_target_or_die(const char *frompath, const char *topath)
/*
* Do a mv where both pathnames are within the target filesystem.
*/
void mv_within_target_or_die(frompath, topath)
const char *frompath;
const char *topath;
{
char realfrom[STRSIZE];
char realto[STRSIZE];
@ -522,7 +542,9 @@ void mv_within_target_or_die(const char *frompath, const char *topath)
}
/* Do a cp where both pathnames are within the target filesystem. */
int cp_within_target(const char *frompath, const char *topath)
int cp_within_target(frompath, topath)
const char *frompath;
const char *topath;
{
char realfrom[STRSIZE];
char realto[STRSIZE];
@ -534,8 +556,12 @@ int cp_within_target(const char *frompath, const char *topath)
}
/* fopen a pathname in the target. */
FILE* target_fopen (const char *filename, const char *type)
FILE *
target_fopen(filename, type)
const char *filename;
const char *type;
{
return fopen(target_expand(filename), type);
}
@ -544,7 +570,10 @@ FILE* target_fopen (const char *filename, const char *type)
* unwind after completing or aborting a mount.
*/
int
mount_with_unwind(const char *fstype, const char *from, const char *on)
mount_with_unwind(fstype, from, on)
const char *fstype;
const char *from;
const char *on;
{
int error;
struct unwind_mount * m;
@ -601,14 +630,15 @@ unwind_mounts()
unwind_in_progress = 0;
}
/*
* Do a mount onto a moutpoint in the install target.
* NB: does not prefix mount-from, which probably breaks nullfs mounts.
*/
int target_mount(const char *fstype, const char *from, const char *on)
int
target_mount(fstype, from, on)
const char *fstype;
const char *from;
const char *on;
{
int error;
const char *realmount = target_expand(on);
@ -619,10 +649,13 @@ int target_mount(const char *fstype, const char *from, const char *on)
return (error);
}
int target_collect_file(int kind, char **buffer, char *name)
int
target_collect_file(kind, buffer, name)
int kind;
char **buffer;
char *name;
{
register const char *realname =target_expand(name);
const char *realname =target_expand(name);
#ifdef DEBUG
printf("collect real name %s\n", realname);
@ -634,19 +667,20 @@ int target_collect_file(int kind, char **buffer, char *name)
* Verify a pathname already exists in the target root filesystem,
* by running test "testflag" on the expanded target pathname.
*/
int target_test(const char *test, const char *path)
int
target_test(test, path)
const char *test;
const char *path;
{
const char *realpath = target_expand(path);
register int result;
result = run_prog ("test %s %s", test, realpath);
result = run_prog("test %s %s", test, realpath);
#if defined(DEBUG)
printf("target_test(%s %s) returning %d\n",
test, realpath, result);
printf("target_test(%s %s) returning %d\n", test, realpath, result);
#endif
return result;
return (result);
}
/*
@ -654,8 +688,11 @@ int target_test(const char *test, const char *path)
* filesystem. Do not create the directory if it doesn't exist.
* Assumes that sysinst has already mounted the target root.
*/
int target_test_dir(const char *path)
int
target_test_dir(path)
const char *path;
{
return target_test("-d", path);
}
@ -664,18 +701,24 @@ int target_test_dir(const char *path)
* filesystem. Do not create the directory if it doesn't exist.
* Assumes that sysinst has already mounted the target root.
*/
int target_test_file(const char *path)
int
target_test_file(path)
const char *path;
{
return target_test("-f", path);
}
int target_file_exists_p(const char *path)
int target_file_exists_p(path)
const char *path;
{
return (target_test_file(path) == 0);
}
int target_dir_exists_p(const char *path)
int target_dir_exists_p(path)
const char *path;
{
return (target_test_dir(path) == 0);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: txtwalk.c,v 1.1.1.1 1997/09/26 23:02:54 phil Exp $ */
/* $NetBSD: txtwalk.c,v 1.2 1998/06/20 13:05:51 mrg Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -56,17 +56,22 @@
/* prototypes */
static void process (struct lookfor, char *);
static void match (char *, struct lookfor *, int);
static int finddata (struct lookfor, char *, struct data *, int *);
static char *strndup (char *, int);
static void process __P((struct lookfor, char *));
static void match __P((char *, struct lookfor *, int));
static int finddata __P((struct lookfor, char *, struct data *, int *));
static char *strndup __P((char *, int));
/* Walk the buffer, call match for each line. */
/*
* Walk the buffer, call match for each line.
*/
void
walk (char *buffer, size_t size, struct lookfor *these, int numthese)
walk(buffer, size, these, numthese)
char *buffer;
size_t size;
struct lookfor *these;
int numthese;
{
int i=0;
int i = 0;
int len;
int line = 1;
@ -92,13 +97,15 @@ walk (char *buffer, size_t size, struct lookfor *these, int numthese)
}
}
/* Match the current line with a string of interest.
/*
* Match the current line with a string of interest.
* For each match in these, process the match.
*/
static void
match (char *line, struct lookfor *these, int numthese)
match(line, these, numthese)
char *line;
struct lookfor *these;
int numthese;
{
int linelen; /* Line length */
int patlen; /* Pattern length */
@ -110,32 +117,35 @@ match (char *line, struct lookfor *these, int numthese)
patlen = strlen(these[which].head);
if (linelen < patlen)
continue;
if (strncmp (these[which].head, line, patlen) == 0)
process (these[which], line);
if (strncmp(these[which].head, line, patlen) == 0)
process(these[which], line);
}
}
/* process the matched line. */
static void
process (struct lookfor this, char *line)
process(this, line)
struct lookfor this;
char *line;
{
struct data found[MAXDATA];
int numfound = 0;
char *p;
int i, j;
if (finddata(this, line, found, &numfound)) {
#ifdef DEBUG
printf ("process: \"%s\"\n", line);
for (i=0; i<numfound; i++) {
printf("process: \"%s\"\n", line);
for (i = 0; i < numfound; i++) {
printf ("\t%d: ", i);
switch (found[i].what) {
case INT: printf ("%d\n", found[i].u.i_val);
break;
case STR: printf ("'%s'\n", found[i].u.s_val);
break;
case INT:
printf ("%d\n", found[i].u.i_val);
break;
case STR:
printf ("'%s'\n", found[i].u.s_val);
break;
}
}
#endif
@ -144,8 +154,10 @@ process (struct lookfor this, char *line)
case 'a':
p = this.todo;
j = 0;
while (*p && *p != '$') p++;
if (*p) p++;
while (*p && *p != '$')
p++;
if (*p)
p++;
while (*p && isdigit(*p)) {
i = atoi(p);
switch (found[i].what) {
@ -158,27 +170,35 @@ process (struct lookfor this, char *line)
found[i].u.s_val);
break;
}
while (isdigit(*p)) p++;
while (*p && *p != '$') p++;
if (*p) p++;
while (isdigit(*p))
p++;
while (*p && *p != '$')
p++;
if (*p)
p++;
j++;
}
break;
case 'c':
(*this.func) (found, numfound);
(*this.func)(found, numfound);
break;
}
}
}
/* find the expected data. Return 1 if successful, return 0 if not.
/*
* find the expected data. Return 1 if successful, return 0 if not.
* Successful means running into the end of the expect string before
* running out of line data or encountering other bad data.
*
* Side Effect -- sets numfound and found.
*/
static int
finddata (struct lookfor this, char *line, struct data *found, int *numfound )
finddata(this, line, found, numfound )
struct lookfor this;
char *line;
struct data *found;
int *numfound;
{
char *fmt = this.fmt;
int len;
@ -208,22 +228,22 @@ finddata (struct lookfor this, char *line, struct data *found, int *numfound )
line++;
break;
case 'd':
if (!isdigit (*line))
if (!isdigit(*line))
return 0;
found[*numfound].what = INT;
found[(*numfound)++].u.i_val = atoi(line);
while (*line && isdigit (*line))
while (*line && isdigit(*line))
line++;
break;
case 's':
len = 0;
while (line[len] && !isspace(line[len])
&& line[len] != fmt[1])
&& line[len] != fmt[1])
len++;
found[*numfound].what = STR;
found[*numfound].u.s_val = strndup(line, len);
if (found[(*numfound)++].u.s_val == NULL) {
(void) fprintf (stderr,
(void)fprintf(stderr,
"msgwalk: strndup: out of vm.\n");
exit(1);
}
@ -234,7 +254,8 @@ finddata (struct lookfor this, char *line, struct data *found, int *numfound )
}
} else if (*fmt == ' ') {
while (*line && isspace(*line)) line++;
while (*line && isspace(*line))
line++;
} else if (*line == *fmt) {
line++;
} else {
@ -248,20 +269,23 @@ finddata (struct lookfor this, char *line, struct data *found, int *numfound )
return 1;
}
/* Utility routines....
/*
* Utility routines....
*/
static char
*strndup (char *str, int len)
static char *
strndup(str, len)
char *str;
int len;
{
int alen;
char *val;
alen = strlen(str);
alen = len < alen ? len+1 : alen+1;
val = (char *) malloc(alen);
alen = len < alen ? len + 1 : alen + 1;
val = (char *)malloc(alen);
if (!val)
return NULL;
strncpy (val, str, alen-1);
strncpy(val, str, alen-1);
return val;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: txtwalk.h,v 1.1.1.1 1997/09/26 23:02:54 phil Exp $ */
/* $NetBSD: txtwalk.h,v 1.2 1998/06/20 13:05:51 mrg Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -55,7 +55,7 @@ struct lookfor {
char *fmt; /* Expected format. */
char *todo; /* What to do ... */
void *var; /* Possible var */
void (*func) (struct data *list, int num); /* function to call */
void (*func) __P((struct data *list, int num)); /* function to call */
};
/* Format string for the expected string:
@ -77,7 +77,7 @@ struct lookfor {
/* prototypes */
void walk (char *, size_t, struct lookfor *, int);
void walk __P((char *, size_t, struct lookfor *, int));
/* Maximum number of matched data elements per line! */

View File

@ -1,4 +1,4 @@
/* $NetBSD: upgrade.c,v 1.14 1998/02/20 00:37:17 jonathan Exp $ */
/* $NetBSD: upgrade.c,v 1.15 1998/06/20 13:05:51 mrg Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -52,25 +52,29 @@ void check_prereqs __P((void));
int save_etc __P((void));
int merge_etc __P((void));
/* Do the system upgrade. */
void do_upgrade(void)
/*
* Do the system upgrade.
*/
void
do_upgrade()
{
doingwhat = msg_string (MSG_upgrade);
msg_display (MSG_upgradeusure);
process_menu (MENU_noyes);
doingwhat = msg_string(MSG_upgrade);
msg_display(MSG_upgradeusure);
process_menu(MENU_noyes);
if (!yesno)
return;
get_ramsize ();
get_ramsize();
if (find_disks () < 0)
if (find_disks() < 0)
return;
/* if we need the user to mount root, ask them to. */
if (must_mount_root()) {
msg_display(MSG_pleasemountroot, diskdev, diskdev, diskdev);
process_menu (MENU_ok);
process_menu(MENU_ok);
return;
}
@ -87,12 +91,12 @@ void do_upgrade(void)
/* Do any md updating of the file systems ... e.g. bootblocks,
copy file systems ... */
if (!md_update ())
if (!md_update())
return;
/* Done with disks. Ready to get and unpack tarballs. */
msg_display(MSG_disksetupdone);
process_menu (MENU_ok);
process_menu(MENU_ok);
get_and_unpack_sets(MSG_upgrcomplete, MSG_abortupgr);
@ -109,12 +113,13 @@ void do_upgrade(void)
* back files we might want during the installation -- in case
* we are upgrading the target root.
*/
int save_etc(void)
int
save_etc()
{
if (target_dir_exists_p("/etc.old")) {
msg_display(MSG_etc_oldexists);
process_menu (MENU_ok);
process_menu(MENU_ok);
return EEXIST;
}
@ -123,7 +128,7 @@ int save_etc(void)
#endif
/* Move target /etc to /etc.old. Abort on error. */
mv_within_target_or_die ("/etc", "/etc.old");
mv_within_target_or_die("/etc", "/etc.old");
/* now make an /etc that should let the user reboot. */
make_target_dir("/etc");
@ -159,49 +164,49 @@ int save_etc(void)
return 0;
}
/*
* Merge back saved target /etc files after unpacking the new
* sets has completed.
*/
int merge_etc(void)
int
merge_etc()
{
/* just move back fstab, so we can boot cleanly. */
cp_within_target("/etc.old/fstab", "/etc/");
return 0;
}
/*
* Unpacks sets, clobbering existintg contents.
*/
void
do_reinstall_sets(void)
do_reinstall_sets()
{
unwind_mounts();
msg_display (MSG_reinstallusure);
process_menu (MENU_noyes);
msg_display(MSG_reinstallusure);
process_menu(MENU_noyes);
if (!yesno)
return;
if (find_disks () < 0)
if (find_disks() < 0)
return;
/* if we need the user to mount root, ask them to. */
if (must_mount_root()) {
msg_display(MSG_pleasemountroot, diskdev, diskdev, diskdev);
process_menu (MENU_ok);
process_menu(MENU_ok);
return;
}
if (!fsck_disks())
return;
fflush(stdout); puts(CL); wrefresh(stdscr);
fflush(stdout);
puts(CL);
wrefresh(stdscr);
/* Unpack the distribution. */
get_and_unpack_sets(MSG_unpackcomplete, MSG_abortunpack);

View File

@ -1,4 +1,4 @@
/* $NetBSD: util.c,v 1.28 1998/05/15 15:12:30 fvdl Exp $ */
/* $NetBSD: util.c,v 1.29 1998/06/20 13:05:51 mrg Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -54,7 +54,7 @@
/*
* local prototypes
*/
struct tarstats{
struct tarstats {
int nselected;
int nfound;
int nnotfound;
@ -67,22 +67,32 @@ int extract_dist __P((void));
int distribution_sets_exist_p __P((const char *path));
static int check_for __P((const char *type, const char *pathname));
int dir_exists_p(const char *path)
/*
* XXX these are WAY bogus!
*/
int
dir_exists_p(path)
const char *path;
{
register int result;
result = (run_prog("test -d %s", path) == 0);
return (result);
}
int file_exists_p(const char *path)
int
file_exists_p(path)
const char *path;
{
register int result;
result = (run_prog("test -f %s", path) == 0);
return (result);
}
int distribution_sets_exist_p (const char *path)
int
distribution_sets_exist_p(path)
const char *path;
{
char buf[STRSIZE];
int result;
@ -98,9 +108,10 @@ int distribution_sets_exist_p (const char *path)
}
void get_ramsize(void)
void
get_ramsize()
{
long len=sizeof(long);
long len = sizeof(long);
int mib[2] = {CTL_HW, HW_PHYSMEM};
sysctl(mib, 2, (void *)&ramsize, (size_t *)&len, NULL, 0);
@ -109,40 +120,45 @@ void get_ramsize(void)
rammb = (ramsize + MEG - 1) / MEG;
}
static int asked = 0;
void ask_sizemult (void)
void
ask_sizemult()
{
if (!asked) {
msg_display (MSG_sizechoice, dlcylsize);
process_menu (MENU_sizechoice);
msg_display(MSG_sizechoice, dlcylsize);
process_menu(MENU_sizechoice);
}
asked = 1;
}
void reask_sizemult (void)
void
reask_sizemult()
{
asked = 0;
ask_sizemult ();
ask_sizemult();
}
/* Returns 1 for "y" or "Y" and "n" otherwise. CR => default. */
/*
* Returns 1 for "y" or "Y" and "n" otherwise. CR => default.
*/
int
ask_ynquestion (char *quest, char def, ...)
ask_ynquestion(char *quest, char def, ...)
{
char line[STRSIZE];
va_list ap;
char c;
va_start(ap, def);
vsnprintf (line, STRSIZE, quest, ap);
vsnprintf(line, STRSIZE, quest, ap);
va_end(ap);
if (def)
printf ("%s [%c]: ", line, def);
printf("%s [%c]: ", line, def);
else
printf ("%s: ", line);
printf("%s: ", line);
c = getchar();
if (c == '\n')
return def == 'y';
@ -152,27 +168,31 @@ ask_ynquestion (char *quest, char def, ...)
return c == 'y' || c == 'Y';
}
void run_makedev (void)
void
run_makedev()
{
char *owd;
msg_display (MSG_makedev);
msg_display(MSG_makedev);
sleep (1);
owd = getcwd (NULL,0);
owd = getcwd(NULL,0);
/* make /dev, in case the user didn't extract it. */
make_target_dir("/dev");
target_chdir_or_die("/dev");
run_prog ("/bin/sh MAKEDEV all");
run_prog("/bin/sh MAKEDEV all");
chdir(owd);
free(owd);
}
/* Load files from floppy. Requires a /mnt2 directory for mounting them. */
int get_via_floppy (void)
/*
* Load files from floppy. Requires a /mnt2 directory for mounting them.
*/
int
get_via_floppy()
{
char distname[STRSIZE];
char fddev[STRSIZE] = "/dev/fd0a";
@ -184,47 +204,45 @@ int get_via_floppy (void)
int first;
struct stat sb;
cd_dist_dir("unloading from floppy");
cd_dist_dir ("unloading from floppy");
msg_prompt_add (MSG_fddev, fddev, fddev, STRSIZE);
msg_prompt_add(MSG_fddev, fddev, fddev, STRSIZE);
list = dist_list;
while (list->name) {
strcpy (post, ".aa");
snprintf (distname, STRSIZE, "%s%s", list->name, dist_postfix);
strcpy(post, ".aa");
snprintf(distname, STRSIZE, "%s%s", list->name, dist_postfix);
while (list->getit && strcmp(&post[1],list->fdlast) <= 0) {
snprintf (fname, STRSIZE, "%s%s", list->name, post);
snprintf (fullname, STRSIZE, "/mnt2/%s", fname);
snprintf(fname, STRSIZE, "%s%s", list->name, post);
snprintf(fullname, STRSIZE, "/mnt2/%s", fname);
first = 1;
while (!mounted || stat(fullname, &sb)) {
if (mounted)
run_prog ("/sbin/umount /mnt2 "
"2>/dev/null");
run_prog("/sbin/umount /mnt2 2>/dev/null");
if (first)
msg_display (MSG_fdmount, fname);
msg_display(MSG_fdmount, fname);
else
msg_display (MSG_fdnotfound, fname);
process_menu (MENU_fdok);
msg_display(MSG_fdnotfound, fname);
process_menu(MENU_fdok);
if (!yesno)
return 0;
while (run_prog("/sbin/mount -r -t %s %s /mnt2",
fdtype, fddev)) {
msg_display (MSG_fdremount, fname);
process_menu (MENU_fdremount);
fdtype, fddev)) {
msg_display(MSG_fdremount, fname);
process_menu(MENU_fdremount);
if (!yesno)
return 0;
}
mounted = 1;
first = 0;
}
run_prog ("/bin/cat %s >> %s", fullname, distname);
run_prog("/bin/cat %s >> %s", fullname, distname);
if (post[2] < 'z')
post[2]++;
else
post[2]='a', post[1]++;
post[2] = 'a', post[1]++;
}
run_prog ("/sbin/umount /mnt2 2>/dev/null");
run_prog("/sbin/umount /mnt2 2>/dev/null");
mounted = 0;
list++;
}
@ -234,31 +252,34 @@ int get_via_floppy (void)
return 1;
}
/* Get from a CDROM distribution. */
/*
* Get from a CDROM distribution.
*/
int
get_via_cdrom(void)
get_via_cdrom()
{
char tmpdir[STRSIZE];
/* Fill in final default path, similar to ftp path
because we expect the CDROM structure to be the
same as the ftp site. */
strncat (cdrom_dir, rel, STRSIZE-strlen(cdrom_dir));
strcat (cdrom_dir, "/");
strncat (cdrom_dir, machine, STRSIZE-strlen(cdrom_dir));
strncat (cdrom_dir, ftp_prefix, STRSIZE-strlen(cdrom_dir));
/*
* Fill in final default path, similar to ftp path
* because we expect the CDROM structure to be the
* same as the ftp site.
*/
strncat(cdrom_dir, rel, STRSIZE - strlen(cdrom_dir));
strcat(cdrom_dir, "/");
strncat(cdrom_dir, machine, STRSIZE - strlen(cdrom_dir));
strncat(cdrom_dir, ftp_prefix, STRSIZE - strlen(cdrom_dir));
/* Get CD-rom device name and path within CD-rom */
process_menu (MENU_cdromsource);
process_menu(MENU_cdromsource);
again:
run_prog("/sbin/umount /mnt2 2> /dev/null");
/* Mount it */
if (run_prog ("/sbin/mount -rt cd9660 /dev/%sa /mnt2", cdrom_dev)) {
if (run_prog("/sbin/mount -rt cd9660 /dev/%sa /mnt2", cdrom_dev)) {
msg_display(MSG_badsetdir, cdrom_dev);
process_menu (MENU_cdrombadmount);
process_menu(MENU_cdrombadmount);
if (!yesno)
return 0;
if (!ignorerror)
@ -270,14 +291,13 @@ again:
/* Verify distribution files exist. */
if (distribution_sets_exist_p(tmpdir) == 0) {
msg_display(MSG_badsetdir, tmpdir);
process_menu (MENU_cdrombadmount);
process_menu(MENU_cdrombadmount);
if (!yesno)
return (0);
if (!ignorerror)
goto again;
}
/* return location, don't clean... */
strncpy(ext_dir, tmpdir, STRSIZE);
clean_dist_dir = 0;
@ -290,7 +310,8 @@ again:
* Get from a pathname inside an unmounted local filesystem
* (e.g., where sets were preloaded onto a local DOS partition)
*/
int get_via_localfs(void)
int
get_via_localfs()
{
char tmpdir[STRSIZE];
@ -298,19 +319,18 @@ int get_via_localfs(void)
process_menu (MENU_localfssource);
again:
run_prog("/sbin/umount /mnt2 2> /dev/null");
/* Mount it */
if (run_prog ("/sbin/mount -rt %s /dev/%s /mnt2", localfs_fs,
if (run_prog("/sbin/mount -rt %s /dev/%s /mnt2", localfs_fs,
localfs_dev)) {
msg_display (MSG_localfsbadmount, localfs_dir, localfs_dev);
process_menu (MENU_localfsbadmount);
msg_display(MSG_localfsbadmount, localfs_dir, localfs_dev);
process_menu(MENU_localfsbadmount);
if (!yesno)
return 0;
if (!ignorerror)
goto again;
goto again;
}
snprintf(tmpdir, STRSIZE, "%s/%s", "/mnt2", localfs_dir);
@ -318,7 +338,7 @@ again:
/* Verify distribution files exist. */
if (distribution_sets_exist_p(tmpdir) == 0) {
msg_display(MSG_badsetdir, tmpdir);
process_menu (MENU_localfsbadmount);
process_menu(MENU_localfsbadmount);
if (!yesno)
return 0;
if (!ignorerror)
@ -332,23 +352,22 @@ again:
return 1;
}
/* Get from an already-mounted pathname. */
/*
* Get from an already-mounted pathname.
*/
int get_via_localdir(void)
{
/* Get device, filesystem, and filepath */
process_menu (MENU_localdirsource);
process_menu(MENU_localdirsource);
again:
/* Complain if not a directory */
if (dir_exists_p(localfs_dir) == 0) {
msg_display (MSG_badlocalsetdir, localfs_dir);
process_menu (MENU_localdirbad);
msg_display(MSG_badlocalsetdir, localfs_dir);
process_menu(MENU_localdirbad);
if (!yesno)
return (0);
if (!ignorerror)
@ -358,28 +377,29 @@ again:
/* Verify distribution files exist. */
if (distribution_sets_exist_p(localfs_dir) == 0) {
msg_display(MSG_badsetdir, localfs_dir);
process_menu (MENU_localdirbad);
process_menu(MENU_localdirbad);
if (!yesno)
return (0);
if (!ignorerror)
goto again;
}
/* return location, don't clean... */
strncpy (ext_dir, localfs_dir, STRSIZE);
strncpy(ext_dir, localfs_dir, STRSIZE);
clean_dist_dir = 0;
mnt2_mounted = 0;
return 1;
}
void cd_dist_dir (char *forwhat)
void
cd_dist_dir(forwhat)
char *forwhat;
{
char *cwd;
/* ask user for the mountpoint. */
msg_prompt (MSG_distdir, dist_dir, dist_dir, STRSIZE, forwhat);
msg_prompt(MSG_distdir, dist_dir, dist_dir, STRSIZE, forwhat);
/* make sure the directory exists. */
make_target_dir(dist_dir);
@ -388,48 +408,54 @@ void cd_dist_dir (char *forwhat)
target_chdir_or_die(dist_dir);
/* Set ext_dir for absolute path. */
cwd = getcwd (NULL,0);
strncpy (ext_dir, cwd, STRSIZE);
cwd = getcwd(NULL,0);
strncpy(ext_dir, cwd, STRSIZE);
free (cwd);
}
/* Support for custom distribution fetches / unpacks. */
void toggle_getit (int num)
/*
* Support for custom distribution fetches / unpacks.
*/
void
toggle_getit(num)
int num;
{
dist_list[num].getit ^= 1;
}
void show_cur_distsets (void)
void
show_cur_distsets()
{
distinfo *list;
msg_display (MSG_cur_distsets);
msg_display(MSG_cur_distsets);
list = dist_list;
while (list->name) {
msg_printf_add ("%s%s\n", list->desc, list->getit ?
msg_string(MSG_yes) : msg_string(MSG_no));
msg_printf_add("%s%s\n", list->desc,
list->getit ? msg_string(MSG_yes) : msg_string(MSG_no));
list++;
}
}
/* Do we want a verbose extract? */
static int verbose = -1;
void
ask_verbose_dist (void)
ask_verbose_dist()
{
if (verbose < 0) {
msg_display (MSG_verboseextract);
process_menu (MENU_noyes);
msg_display(MSG_verboseextract);
process_menu(MENU_noyes);
verbose = yesno;
}
}
void
extract_file (char *path)
extract_file(path)
char *path;
{
char *owd;
int tarexit;
@ -448,32 +474,36 @@ extract_file (char *path)
target_chdir_or_die("/");
/* now extract set files files into "./". */
(void)printf (msg_string(MSG_extracting), path);
tarexit = run_prog ("/usr/bin/tar --unlink -xpz%s -f %s",
verbose ? "v":"", path);
(void)printf(msg_string(MSG_extracting), path);
#ifdef __sparc__ /* XXX make all ports use pax! XXX */
tarexit = run_prog("pax -zr%spe -f %s", verbose ? "v" : "", path);
#else
tarexit = run_prog("/usr/bin/tar -xpz%s -f %s", verbose ? "v":"", path);
#endif
/* Check tarexit for errors and give warning. */
if (tarexit) {
tarstats.nerror++;
ask_ynquestion (msg_string(MSG_tarerror), 0, path);
ask_ynquestion(msg_string(MSG_tarerror), 0, path);
sleep(3);
} else {
tarstats.nsuccess++;
sleep(1);
}
chdir (owd);
free (owd);
chdir(owd);
free(owd);
}
/* Extract_dist **REQUIRES** an absolute path in ext_dir. Any code
/*
* Extract_dist **REQUIRES** an absolute path in ext_dir. Any code
* that sets up dist_dir for use by extract_dist needs to put in the
* full path name to the directory.
*/
int
extract_dist (void)
extract_dist()
{
char distname[STRSIZE];
char fname[STRSIZE];
@ -487,11 +517,11 @@ extract_dist (void)
while (list->name) {
if (list->getit) {
tarstats.nselected++;
(void)snprintf (distname, STRSIZE, "%s%s", list->name,
dist_postfix);
(void)snprintf (fname, STRSIZE, "%s/%s", ext_dir,
distname);
extract_file (fname);
(void)snprintf(distname, STRSIZE, "%s%s", list->name,
dist_postfix);
(void)snprintf(fname, STRSIZE, "%s/%s", ext_dir,
distname);
extract_file(fname);
}
list++;
}
@ -500,36 +530,39 @@ extract_dist (void)
wrefresh(stdscr);
if (tarstats.nerror == 0 && tarstats.nsuccess == tarstats.nselected) {
msg_display (MSG_endtarok);
process_menu (MENU_ok);
msg_display(MSG_endtarok);
process_menu(MENU_ok);
return 0;
} else {
/* We encountered errors. Let the user know. */
msg_display(MSG_endtar,
tarstats.nselected, tarstats.nnotfound,
tarstats.nfound, tarstats.nsuccess, tarstats.nerror);
process_menu (MENU_ok);
process_menu(MENU_ok);
return 1;
}
}
/*
* Get and unpack the distribution.
* show success_msg if installation completes. Otherwise,,
* sHow failure_msg and wait for the user to ack it before continuing.
* Get and unpack the distribution.
* show success_msg if installation completes. Otherwise,,
* show failure_msg and wait for the user to ack it before continuing.
* success_msg and failure_msg must both be 0-adic messages.
*/
void get_and_unpack_sets(int success_msg, int failure_msg)
void
get_and_unpack_sets(success_msg, failure_msg)
int success_msg;
int failure_msg;
{
/* Ensure mountpoint for distribution files exists in current root. */
(void) mkdir("/mnt2", S_IRWXU| S_IRGRP|S_IXGRP | S_IXOTH|S_IXOTH);
/* Find out which files to "get" if we get files. */
process_menu (MENU_distset);
process_menu(MENU_distset);
/* Get the distribution files */
process_menu (MENU_distmedium);
process_menu(MENU_distmedium);
if (nodist)
return;
@ -537,37 +570,36 @@ void get_and_unpack_sets(int success_msg, int failure_msg)
if (got_dist) {
/* ask user whether to do normal or verbose extraction */
ask_verbose_dist ();
ask_verbose_dist();
/* Extract the distribution, abort on errors. */
if (extract_dist ()) {
if (extract_dist()) {
goto bad;
}
/* Configure the system */
run_makedev ();
run_makedev();
/* Other configuration. */
mnt_net_config();
/* Clean up dist dir (use absolute path name) */
if (clean_dist_dir)
run_prog ("/bin/rm -rf %s", ext_dir);
run_prog("/bin/rm -rf %s", ext_dir);
/* Mounted dist dir? */
if (mnt2_mounted)
run_prog ("/sbin/umount /mnt2");
run_prog("/sbin/umount /mnt2");
/* Install/Upgrade complete ... reboot or exit to script */
msg_display (success_msg);
process_menu (MENU_ok);
/* Install/Upgrade complete ... reboot or exit to script */
msg_display(success_msg);
process_menu(MENU_ok);
return;
}
bad:
msg_display (failure_msg);
process_menu (MENU_ok);
msg_display(failure_msg);
process_menu(MENU_ok);
}
@ -578,8 +610,6 @@ bad:
* Uses a table of files we expect to find after a base install/upgrade.
*/
/* test flag and pathname to check for after unpacking. */
struct check_table { const char *testarg; const char *path;} checks[] = {
{ "-f", "/netbsd" },
@ -606,11 +636,13 @@ struct check_table { const char *testarg; const char *path;} checks[] = {
};
/*
* Check target for a single file.
*/
static int check_for(const char *type, const char *pathname)
static int
check_for(type, pathname)
const char *type;
const char *pathname;
{
int found;
@ -627,7 +659,6 @@ static int check_for(const char *type, const char *pathname)
int
sanity_check()
{
int target_ok = 1;
struct check_table *p;