Handle the 'custom' case in a sane fashion (do not create zero length

partitions under any circumstances, allow no swap, do not *overwrite* /usr
when listing additional partitions, and try to abstract at least most of the
magic numbers to #defines at the top.
Also sync up as much as possible to make this easier in future.
Still need to attack the other arch's md.c files.
This commit is contained in:
abs 1999-08-10 15:54:55 +00:00
parent 0536609b97
commit 1e7a66ebab
4 changed files with 565 additions and 400 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: md.c,v 1.34 1999/08/07 15:56:31 simonb Exp $ */
/* $NetBSD: md.c,v 1.35 1999/08/10 15:54:55 abs Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -25,18 +25,19 @@
* THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* md.c -- pmax machine specific routines */
/* This file is in close sync with sparc, vax, and x68k md.c */
#include <sys/types.h>
#include <sys/ioctl.h>
@ -59,41 +60,52 @@ void get_labelname(void)
{
/* Disk name */
msg_prompt (MSG_packname, "mydisk", bsddiskname, DISKNAME_SIZE);
msg_prompt(MSG_packname, "mydisk", bsddiskname, DISKNAME_SIZE);
}
/*
* Symbolic names for disk partitions.
*/
#define PART_ROOT A
#define PART_RAW C
#define PART_USR D
#define PART_ROOT A
#define PART_SWAP B
#define PART_RAW C
#define PART_USR D /* Can be after PART_FIRST_FREE */
#define PART_FIRST_FREE E
#define PART_LAST H
#define DEFSWAPRAM 32 /* Assume at least this RAM for swap calc */
#define DEFROOTSIZE 32 /* Default root size */
#define STDNEEDMB 140 /* Min space for non X install */
int
md_get_info (void)
md_get_info(void)
{
struct disklabel disklabel;
int fd;
char devname[100];
snprintf (devname, 100, "/dev/r%sc", diskdev);
snprintf(devname, 100, "/dev/r%sc", diskdev);
fd = open (devname, O_RDONLY, 0);
fd = open(devname, O_RDONLY, 0);
if (fd < 0) {
if (logging)
(void)fprintf(log, "Can't open %s\n", devname);
endwin();
fprintf (stderr, "Can't open %s\n", devname);
fprintf(stderr, "Can't open %s\n", devname);
exit(1);
}
if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
if (logging)
(void)fprintf(log, "Can't read disklabel on %s.\n",
devname);
endwin();
fprintf (stderr, "Can't read disklabel on %s.\n", devname);
fprintf(stderr, "Can't read disklabel on %s.\n", devname);
close(fd);
exit(1);
}
close(fd);
dlcyl = disklabel.d_ncylinders;
dlhead = disklabel.d_ntracks;
dlsec = disklabel.d_nsectors;
@ -102,7 +114,7 @@ md_get_info (void)
/*
* Compute whole disk size. Take max of (dlcyl*dlhead*dlsec)
* and secperunit, just in case the disk is already labelled.
* and secperunit, just in case the disk is already labelled.
* (If our new label's RAW_PART size ends up smaller than the
* in-core RAW_PART size value, updating the label will fail.)
*/
@ -111,25 +123,25 @@ md_get_info (void)
dlsize = disklabel.d_secperunit;
/* Compute minimum NetBSD partition sizes (in sectors). */
minfsdmb = (80 + 4*rammb) * (MEG / sectorsize);
minfsdmb = STDNEEDMB * (MEG / sectorsize);
return 1;
}
/*
* hook called before editing new disklabel.
/*
* hook called before writing new disklabel.
*/
int md_pre_disklabel (void)
int
md_pre_disklabel(void)
{
return 0;
}
/*
* hook called after writing disklabel to new target disk.
/*
* hook called after writing disklabel to new target disk.
*/
int md_post_disklabel (void)
int
md_post_disklabel(void)
{
return 0;
}
@ -143,49 +155,58 @@ int md_post_disklabel (void)
*
* On pmax, we take this opportuinty to update the bootblocks.
*/
int md_post_newfs (void)
int
md_post_newfs(void)
{
/* XXX boot blocks ... */
if (target_already_root()) {
/* /usr is empty and we must already have bootblocks?*/
return 0;
}
printf (msg_string(MSG_dobootblks), diskdev);
printf(msg_string(MSG_dobootblks), diskdev);
run_prog(0, 1, NULL, "/sbin/disklabel -B %s /dev/r%sc",
"-b /usr/mdec/rzboot -s /usr/mdec/bootrz", diskdev);
return 0;
}
/*
* some ports use this to copy the MD filesystem, we do not.
*/
int
md_copy_filesystem(void)
{
return 0;
}
/*
* md back-end code for menu-driven BSD disklabel editor.
* md back-end code for menu-driven BSD disklabel editor.
*/
int md_make_bsd_partitions (void)
int
md_make_bsd_partitions(void)
{
FILE *f;
int i;
int part; /* next available partition */
int i, part;
int remain;
char isize[20];
int maxpart = getmaxpartitions();
/*
* Initialize global variables that track space used on this disk.
* Initialize global variables that track space used on this disk.
* Standard 4.3BSD 8-partition labels always cover whole disk.
*/
ptstart = 0;
ptsize = dlsize;
fsdsize = dlsize; /* actually means `whole disk' */
fsptsize = dlsize; /* netbsd partition -- same as above */
ptsize = dlsize - ptstart;
fsdsize = dlsize; /* actually means `whole disk' */
fsptsize = dlsize - ptstart; /* netbsd partition -- same as above */
fsdmb = fsdsize / MEG;
/* Ask for layout type -- standard or special */
msg_display (MSG_layout,
(1.0*fsptsize*sectorsize)/MEG,
(1.0*minfsdmb*sectorsize)/MEG,
(1.0*minfsdmb*sectorsize)/MEG+rammb+XNEEDMB);
process_menu (MENU_layout);
msg_display(MSG_layout,
(1.0*fsptsize*sectorsize)/MEG,
(1.0*minfsdmb*sectorsize)/MEG,
(1.0*minfsdmb*sectorsize)/MEG+rammb+XNEEDMB);
process_menu(MENU_layout);
if (layoutkind == 3) {
ask_sizemult();
@ -198,21 +219,21 @@ int md_make_bsd_partitions (void)
/* Build standard partitions */
emptylabel(bsdlabel);
/* Partitions C is predefined (whole disk). */
/* Partitions C is predefined (whole disk). */
bsdlabel[C].pi_fstype = FS_UNUSED;
bsdlabel[C].pi_offset = 0;
bsdlabel[C].pi_size = dlsize;
/* Standard fstypes */
bsdlabel[A].pi_fstype = FS_BSDFFS;
bsdlabel[B].pi_fstype = FS_SWAP;
bsdlabel[B].pi_fstype = FS_UNUSED;
/* Conventionally, C is whole disk. */
bsdlabel[D].pi_fstype = FS_UNUSED; /* fill out below */
bsdlabel[E].pi_fstype = FS_UNUSED;
bsdlabel[F].pi_fstype = FS_UNUSED;
bsdlabel[G].pi_fstype = FS_UNUSED;
bsdlabel[H].pi_fstype = FS_UNUSED;
part = D;
switch (layoutkind) {
case 1: /* standard: a root, b swap, c "unused", d /usr */
@ -220,22 +241,23 @@ int md_make_bsd_partitions (void)
partstart = ptstart;
/* Root */
/* By convention, NetBSD/pmax uses a 32Mbyte root */
partsize= NUMSEC(32, MEG/sectorsize, dlcylsize);
bsdlabel[A].pi_offset = partstart;
bsdlabel[A].pi_size = partsize;
bsdlabel[A].pi_bsize = 8192;
bsdlabel[A].pi_fsize = 1024;
strcpy (fsmount[A], "/");
partsize = NUMSEC(DEFROOTSIZE, MEG/sectorsize, dlcylsize);
bsdlabel[PART_ROOT].pi_offset = partstart;
bsdlabel[PART_ROOT].pi_size = partsize;
bsdlabel[PART_ROOT].pi_bsize = 8192;
bsdlabel[PART_ROOT].pi_fsize = 1024;
strcpy(fsmount[PART_ROOT], "/");
partstart += partsize;
/* swap */
i = NUMSEC(layoutkind * 2 * (rammb < 32 ? 32 : rammb),
i = NUMSEC(layoutkind * 2 *
(rammb < DEFSWAPRAM ? DEFSWAPRAM : rammb),
MEG/sectorsize, dlcylsize) + partstart;
partsize = NUMSEC (i/(MEG/sectorsize)+1, MEG/sectorsize,
partsize = NUMSEC(i/(MEG/sectorsize)+1, MEG/sectorsize,
dlcylsize) - partstart;
bsdlabel[B].pi_offset = partstart;
bsdlabel[B].pi_size = partsize;
bsdlabel[PART_SWAP].pi_fstype = FS_SWAP;
bsdlabel[PART_SWAP].pi_offset = partstart;
bsdlabel[PART_SWAP].pi_size = partsize;
partstart += partsize;
/* /usr */
@ -245,9 +267,8 @@ int md_make_bsd_partitions (void)
bsdlabel[PART_USR].pi_size = partsize;
bsdlabel[PART_USR].pi_bsize = 8192;
bsdlabel[PART_USR].pi_fsize = 1024;
strcpy (fsmount[PART_USR], "/usr");
strcpy(fsmount[PART_USR], "/usr");
part = E;
break;
case 3: /* custom: ask user for all sizes */
@ -255,64 +276,83 @@ int md_make_bsd_partitions (void)
/* root */
partstart = ptstart;
remain = fsdsize - partstart;
/* By convention, NetBSD/pmax uses a 32Mbyte root */
partsize= NUMSEC(32, MEG/sectorsize, dlcylsize);
snprintf (isize, 20, "%d", partsize/sizemult);
msg_prompt (MSG_askfsroot, isize, isize, 20,
partsize = NUMSEC(DEFROOTSIZE, MEG/sectorsize, dlcylsize);
snprintf(isize, 20, "%d", partsize/sizemult);
msg_prompt(MSG_askfsroot, isize, isize, 20,
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
bsdlabel[A].pi_offset = partstart;
bsdlabel[A].pi_size = partsize;
bsdlabel[A].pi_bsize = 8192;
bsdlabel[A].pi_fsize = 1024;
strcpy (fsmount[A], "/");
/* If less than a 'unit' left, also use it */
if (remain - partsize < sizemult)
partsize = remain;
bsdlabel[PART_ROOT].pi_offset = partstart;
bsdlabel[PART_ROOT].pi_size = partsize;
bsdlabel[PART_ROOT].pi_bsize = 8192;
bsdlabel[PART_ROOT].pi_fsize = 1024;
strcpy(fsmount[PART_ROOT], "/");
partstart += partsize;
/* swap */
remain = fsdsize - partstart;
i = NUMSEC(layoutkind * 2 * (rammb < 32 ? 32 : rammb),
MEG/sectorsize, dlcylsize) + partstart;
partsize = NUMSEC (i/(MEG/sectorsize)+1, MEG/sectorsize,
dlcylsize) - partstart;
snprintf (isize, 20, "%d", partsize/sizemult);
msg_prompt_add (MSG_askfsswap, isize, isize, 20,
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
bsdlabel[B].pi_offset = partstart;
bsdlabel[B].pi_size = partsize;
partstart += partsize;
if (remain > 0) {
i = NUMSEC(2 *
(rammb < DEFSWAPRAM ? DEFSWAPRAM : rammb),
MEG/sectorsize, dlcylsize) + partstart;
partsize = NUMSEC(i/(MEG/sectorsize)+1, MEG/sectorsize,
dlcylsize) - partstart;
if (partsize > remain)
partsize = remain;
snprintf(isize, 20, "%d", partsize/sizemult);
msg_prompt_add(MSG_askfsswap, isize, isize, 20,
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
if (partsize) {
/* If less than a 'unit' left, also use it */
if (remain - partsize < sizemult)
partsize = remain;
bsdlabel[PART_SWAP].pi_fstype = FS_SWAP;
bsdlabel[PART_SWAP].pi_offset = partstart;
bsdlabel[PART_SWAP].pi_size = partsize;
partstart += partsize;
}
}
/* /usr */
remain = fsdsize - partstart;
if (remain > 0) {
partsize = fsdsize - partstart;
snprintf (isize, 20, "%d", partsize/sizemult);
msg_prompt_add (MSG_askfsusr, isize, isize, 20,
remain/sizemult, multname);
partsize = remain;
snprintf(isize, 20, "%d", partsize/sizemult);
msg_prompt_add(MSG_askfsusr, isize, isize, 20,
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
if (remain - partsize < sizemult)
partsize = remain;
bsdlabel[PART_USR].pi_fstype = FS_BSDFFS;
bsdlabel[PART_USR].pi_offset = partstart;
bsdlabel[PART_USR].pi_size = partsize;
bsdlabel[PART_USR].pi_bsize = 8192;
bsdlabel[PART_USR].pi_fsize = 1024;
strcpy (fsmount[PART_USR], "/usr");
partstart += partsize;
if (partsize) {
/* If less than a 'unit' left, also use it */
if (remain - partsize < sizemult)
partsize = remain;
bsdlabel[PART_USR].pi_fstype = FS_BSDFFS;
bsdlabel[PART_USR].pi_offset = partstart;
bsdlabel[PART_USR].pi_size = partsize;
bsdlabel[PART_USR].pi_bsize = 8192;
bsdlabel[PART_USR].pi_fsize = 1024;
strcpy(fsmount[PART_USR], "/usr");
partstart += partsize;
}
}
/* Others ... */
remain = fsdsize - partstart;
part = F;
if (remain > 0)
msg_display (MSG_otherparts);
while (remain > 0 && part <= H) {
msg_display(MSG_otherparts);
part = PART_FIRST_FREE;
for (; remain > 0 && part <= PART_LAST; ++part ) {
if (bsdlabel[part].pi_fstype != FS_UNUSED)
continue;
partsize = fsdsize - partstart;
snprintf (isize, 20, "%d", partsize/sizemult);
msg_prompt_add (MSG_askfspart, isize, isize, 20,
snprintf(isize, 20, "%d", partsize/sizemult);
msg_prompt_add(MSG_askfspart, isize, isize, 20,
diskdev, partname[part],
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
/* If less than a 'unit' left, also use it */
if (remain - partsize < sizemult)
partsize = remain;
bsdlabel[part].pi_fstype = FS_BSDFFS;
@ -320,13 +360,11 @@ int md_make_bsd_partitions (void)
bsdlabel[part].pi_size = partsize;
bsdlabel[part].pi_bsize = 8192;
bsdlabel[part].pi_fsize = 1024;
msg_prompt_add (MSG_mountpoint, NULL,
fsmount[part], 20);
msg_prompt_add(MSG_mountpoint, NULL, fsmount[part],
20);
partstart += partsize;
remain = fsdsize - partstart;
part++;
}
break;
}
@ -346,33 +384,33 @@ int md_make_bsd_partitions (void)
/* Create the disktab.preinstall */
run_prog (0, 0, NULL, "cp /etc/disktab.preinstall /etc/disktab");
#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);
(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<8; i++) {
(void)fprintf (f, "\t:p%c#%d:o%c#%d:t%c=%s:",
(void)fprintf(f, "\t:p%c#%d:o%c#%d:t%c=%s:",
'a'+i, bsdlabel[i].pi_size,
'a'+i, bsdlabel[i].pi_offset,
'a'+i, fstypenames[bsdlabel[i].pi_fstype]);
if (bsdlabel[i].pi_fstype == FS_BSDFFS)
(void)fprintf (f, "b%c#%d:f%c#%d",
(void)fprintf(f, "b%c#%d:f%c#%d",
'a'+i, bsdlabel[i].pi_bsize,
'a'+i, bsdlabel[i].pi_fsize);
if (i < 7)
(void)fprintf (f, "\\\n");
(void)fprintf(f, "\\\n");
else
(void)fprintf (f, "\n");
(void)fprintf(f, "\n");
}
fclose (f);
@ -380,20 +418,12 @@ int md_make_bsd_partitions (void)
return (1);
}
int md_copy_filesystem (void)
{
return 0;
}
/* Upgrade support */
int
md_update(void)
{
endwin();
md_copy_filesystem ();
md_copy_filesystem();
md_post_newfs();
puts(CL); /* XXX */
wclear(stdscr);
@ -404,4 +434,24 @@ md_update(void)
void
md_cleanup_install(void)
{
char realfrom[STRSIZE];
char realto[STRSIZE];
char sedcmd[STRSIZE];
strncpy(realfrom, target_expand("/etc/rc.conf"), STRSIZE);
strncpy(realto, target_expand("/etc/rc.conf.install"), STRSIZE);
sprintf(sedcmd, "sed 's/rc_configured=NO/rc_configured=YES/' < %s > %s",
realfrom, realto);
if (logging)
(void)fprintf(log, "%s\n", sedcmd);
if (scripting)
(void)fprintf(script, "%s\n", sedcmd);
do_system(sedcmd);
run_prog(1, 0, NULL, "mv -f %s %s", realto, realfrom);
run_prog(0, 0, NULL, "rm -f %s", target_expand("/sysinst"));
run_prog(0, 0, NULL, "rm -f %s", target_expand("/.termcap"));
run_prog(0, 0, NULL, "rm -f %s", target_expand("/.profile"));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: md.c,v 1.16 1999/07/14 16:47:37 abs Exp $ */
/* $NetBSD: md.c,v 1.17 1999/08/10 15:54:55 abs Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -26,19 +26,20 @@
* THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/* changes from the i386 version made by mrg */
/* md.c -- sparc machine specific routines */
/* This file is in close sync with pmax, vax, and x68k md.c */
#include <sys/types.h>
#include <sys/disklabel.h>
@ -58,28 +59,40 @@
/*
* Symbolic names for disk partitions.
*/
#define PART_ROOT A
#define PART_RAW C
#define PART_USR G
#define PART_ROOT A
#define PART_SWAP B
#define PART_RAW C
#define PART_USR G /* Can be after PART_FIRST_FREE */
#define PART_FIRST_FREE D
#define PART_LAST H
#define DEFSWAPRAM 32 /* Assume at least this RAM for swap calc */
#define DEFROOTSIZE 32 /* Default root size */
#define STDNEEDMB 110 /* Min space for non X install */
int
md_get_info()
md_get_info(void)
{
struct disklabel disklabel;
int fd;
char devname[100];
snprintf (devname, 100, "/dev/r%sc", diskdev);
snprintf(devname, 100, "/dev/r%sc", diskdev);
fd = open (devname, O_RDONLY, 0);
fd = open(devname, O_RDONLY, 0);
if (fd < 0) {
if (logging)
(void)fprintf(log, "Can't open %s\n", devname);
endwin();
fprintf (stderr, "Can't open %s\n", devname);
fprintf(stderr, "Can't open %s\n", devname);
exit(1);
}
if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
if (logging)
(void)fprintf(log, "Can't read disklabel on %s.\n",
devname);
endwin();
fprintf (stderr, "Can't read disklabel on %s.\n", devname);
fprintf(stderr, "Can't read disklabel on %s.\n", devname);
close(fd);
exit(1);
}
@ -93,7 +106,7 @@ md_get_info()
/*
* Compute whole disk size. Take max of (dlcyl*dlhead*dlsec)
* and secperunit, just in case the disk is already labelled.
* and secperunit, just in case the disk is already labelled.
* (If our new label's RAW_PART size ends up smaller than the
* in-core RAW_PART size value, updating the label will fail.)
*/
@ -102,7 +115,7 @@ md_get_info()
dlsize = disklabel.d_secperunit;
/* Compute minimum NetBSD partition sizes (in sectors). */
minfsdmb = (80 + 4*rammb) * (MEG / sectorsize);
minfsdmb = STDNEEDMB * (MEG / sectorsize);
return 1;
}
@ -111,7 +124,7 @@ md_get_info()
* hook called before writing new disklabel.
*/
int
md_pre_disklabel()
md_pre_disklabel(void)
{
return 0;
}
@ -119,7 +132,8 @@ md_pre_disklabel()
/*
* hook called after writing disklabel to new target disk.
*/
int md_post_disklabel (void)
int
md_post_disklabel(void)
{
return 0;
}
@ -127,14 +141,14 @@ int md_post_disklabel (void)
/*
* MD hook called after upgrade() or install() has finished setting
* up the target disk but immediately before the user is given the
* ``disks are now set up'' message that, if power fails, they can
* ``disks are now set up'' message, so that if power fails, they can
* continue installation by booting the target disk and doing an
* `upgrade'.
*
* On the sparc, we use this opportunity to install the boot blocks.
*/
int
md_post_newfs()
md_post_newfs(void)
{
/*
* Create a symlink of netbsd to netbsd.GENERIC
@ -154,13 +168,16 @@ md_post_newfs()
* some ports use this to copy the MD filesystem, we do not.
*/
int
md_copy_filesystem()
md_copy_filesystem(void)
{
return 0;
}
/*
* md back-end code for menu-driven BSD disklabel editor.
*/
int
md_make_bsd_partitions()
md_make_bsd_partitions(void)
{
int i, part;
int remain;
@ -168,7 +185,7 @@ md_make_bsd_partitions()
int maxpart = getmaxpartitions();
/*
* Initialize global variables that track space used on this disk.
* Initialize global variables that track space used on this disk.
* Standard 4.3BSD 8-partition labels always cover whole disk.
*/
ptsize = dlsize - ptstart;
@ -177,11 +194,11 @@ md_make_bsd_partitions()
fsdmb = fsdsize / MEG;
/* Ask for layout type -- standard or special */
msg_display (MSG_layout,
(1.0*fsptsize*sectorsize)/MEG,
(1.0*minfsdmb*sectorsize)/MEG,
(1.0*minfsdmb*sectorsize)/MEG+rammb+XNEEDMB);
process_menu (MENU_layout);
msg_display(MSG_layout,
(1.0*fsptsize*sectorsize)/MEG,
(1.0*minfsdmb*sectorsize)/MEG,
(1.0*minfsdmb*sectorsize)/MEG+rammb+XNEEDMB);
process_menu(MENU_layout);
if (layoutkind == 3) {
ask_sizemult();
@ -194,21 +211,20 @@ md_make_bsd_partitions()
/* Build standard partitions */
emptylabel(bsdlabel);
/* Partitions C is predefined (whole disk). */
/* Partitions C is predefined (whole disk). */
bsdlabel[C].pi_fstype = FS_UNUSED;
bsdlabel[C].pi_offset = 0;
bsdlabel[C].pi_size = dlsize;
/* Standard fstypes */
bsdlabel[A].pi_fstype = FS_BSDFFS;
bsdlabel[B].pi_fstype = FS_SWAP;
bsdlabel[B].pi_fstype = FS_UNUSED;
/* Conventionally, C is whole disk. */
bsdlabel[D].pi_fstype = FS_UNUSED; /* fill out below */
bsdlabel[E].pi_fstype = FS_UNUSED;
bsdlabel[F].pi_fstype = FS_UNUSED;
bsdlabel[G].pi_fstype = FS_UNUSED;
bsdlabel[H].pi_fstype = FS_UNUSED;
part = D;
switch (layoutkind) {
@ -217,22 +233,23 @@ md_make_bsd_partitions()
partstart = ptstart;
/* Root */
/* By convention, NetBSD/sparc uses a 328Mbyte root */
partsize= NUMSEC(32, MEG/sectorsize, dlcylsize);
bsdlabel[A].pi_offset = partstart;
bsdlabel[A].pi_size = partsize;
bsdlabel[A].pi_bsize = 8192;
bsdlabel[A].pi_fsize = 1024;
strcpy (fsmount[A], "/");
partsize = NUMSEC(DEFROOTSIZE, MEG/sectorsize, dlcylsize);
bsdlabel[PART_ROOT].pi_offset = partstart;
bsdlabel[PART_ROOT].pi_size = partsize;
bsdlabel[PART_ROOT].pi_bsize = 8192;
bsdlabel[PART_ROOT].pi_fsize = 1024;
strcpy(fsmount[PART_ROOT], "/");
partstart += partsize;
/* swap */
i = NUMSEC(layoutkind * 2 * (rammb < 32 ? 32 : rammb),
i = NUMSEC(layoutkind * 2 *
(rammb < DEFSWAPRAM ? DEFSWAPRAM : rammb),
MEG/sectorsize, dlcylsize) + partstart;
partsize = NUMSEC (i/(MEG/sectorsize)+1, MEG/sectorsize,
partsize = NUMSEC(i/(MEG/sectorsize)+1, MEG/sectorsize,
dlcylsize) - partstart;
bsdlabel[B].pi_offset = partstart;
bsdlabel[B].pi_size = partsize;
bsdlabel[PART_SWAP].pi_fstype = FS_SWAP;
bsdlabel[PART_SWAP].pi_offset = partstart;
bsdlabel[PART_SWAP].pi_size = partsize;
partstart += partsize;
/* /usr */
@ -242,7 +259,7 @@ md_make_bsd_partitions()
bsdlabel[PART_USR].pi_size = partsize;
bsdlabel[PART_USR].pi_bsize = 8192;
bsdlabel[PART_USR].pi_fsize = 1024;
strcpy (fsmount[PART_USR], "/usr");
strcpy(fsmount[PART_USR], "/usr");
break;
@ -251,66 +268,83 @@ md_make_bsd_partitions()
/* root */
partstart = ptstart;
remain = fsdsize - partstart;
/* By convention, NetBSD/sparc uses a 32Mbyte root */
partsize = NUMSEC (32, MEG/sectorsize, dlcylsize);
snprintf (isize, 20, "%d", partsize/sizemult);
msg_prompt (MSG_askfsroot, isize, isize, 20,
partsize = NUMSEC(DEFROOTSIZE, MEG/sectorsize, dlcylsize);
snprintf(isize, 20, "%d", partsize/sizemult);
msg_prompt(MSG_askfsroot, isize, isize, 20,
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
bsdlabel[A].pi_offset = partstart;
bsdlabel[A].pi_size = partsize;
bsdlabel[A].pi_bsize = 8192;
bsdlabel[A].pi_fsize = 1024;
strcpy (fsmount[A], "/");
/* If less than a 'unit' left, also use it */
if (remain - partsize < sizemult)
partsize = remain;
bsdlabel[PART_ROOT].pi_offset = partstart;
bsdlabel[PART_ROOT].pi_size = partsize;
bsdlabel[PART_ROOT].pi_bsize = 8192;
bsdlabel[PART_ROOT].pi_fsize = 1024;
strcpy(fsmount[PART_ROOT], "/");
partstart += partsize;
/* swap */
remain = fsdsize - partstart;
i = NUMSEC(2 * (rammb < 32 ? 32 : rammb),
MEG/sectorsize, dlcylsize) + partstart;
partsize = NUMSEC (i/(MEG/sectorsize)+1, MEG/sectorsize,
dlcylsize) - partstart;
if (partsize > remain)
partsize = remain;
snprintf (isize, 20, "%d", partsize/sizemult);
msg_prompt_add (MSG_askfsswap, isize, isize, 20,
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
bsdlabel[B].pi_offset = partstart;
bsdlabel[B].pi_size = partsize;
partstart += partsize;
/* /usr */
remain = fsdsize - partstart;
if (remain >= dlcylsize) {
partsize = fsdsize - partstart;
snprintf (isize, 20, "%d", partsize/sizemult);
msg_prompt_add (MSG_askfsusr, isize, isize, 20,
if (remain > 0) {
i = NUMSEC(2 *
(rammb < DEFSWAPRAM ? DEFSWAPRAM : rammb),
MEG/sectorsize, dlcylsize) + partstart;
partsize = NUMSEC(i/(MEG/sectorsize)+1, MEG/sectorsize,
dlcylsize) - partstart;
if (partsize > remain)
partsize = remain;
snprintf(isize, 20, "%d", partsize/sizemult);
msg_prompt_add(MSG_askfsswap, isize, isize, 20,
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
if (remain - partsize < sizemult)
partsize = remain;
bsdlabel[PART_USR].pi_fstype = FS_BSDFFS;
bsdlabel[PART_USR].pi_offset = partstart;
bsdlabel[PART_USR].pi_size = partsize;
bsdlabel[PART_USR].pi_bsize = 8192;
bsdlabel[PART_USR].pi_fsize = 1024;
strcpy (fsmount[PART_USR], "/usr");
partstart += partsize;
if (partsize) {
/* If less than a 'unit' left, also use it */
if (remain - partsize < sizemult)
partsize = remain;
bsdlabel[PART_SWAP].pi_fstype = FS_SWAP;
bsdlabel[PART_SWAP].pi_offset = partstart;
bsdlabel[PART_SWAP].pi_size = partsize;
partstart += partsize;
}
}
/* /usr */
remain = fsdsize - partstart;
if (remain > 0) {
partsize = remain;
snprintf(isize, 20, "%d", partsize/sizemult);
msg_prompt_add(MSG_askfsusr, isize, isize, 20,
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
if (partsize) {
/* If less than a 'unit' left, also use it */
if (remain - partsize < sizemult)
partsize = remain;
bsdlabel[PART_USR].pi_fstype = FS_BSDFFS;
bsdlabel[PART_USR].pi_offset = partstart;
bsdlabel[PART_USR].pi_size = partsize;
bsdlabel[PART_USR].pi_bsize = 8192;
bsdlabel[PART_USR].pi_fsize = 1024;
strcpy(fsmount[PART_USR], "/usr");
partstart += partsize;
}
}
/* Others ... */
remain = fsdsize - partstart;
part = F;
if (remain > 0)
msg_display (MSG_otherparts);
while (remain > 0 && part <= H) {
msg_display(MSG_otherparts);
part = PART_FIRST_FREE;
for (; remain > 0 && part <= PART_LAST; ++part ) {
if (bsdlabel[part].pi_fstype != FS_UNUSED)
continue;
partsize = fsdsize - partstart;
snprintf (isize, 20, "%d", partsize/sizemult);
msg_prompt_add (MSG_askfspart, isize, isize, 20,
snprintf(isize, 20, "%d", partsize/sizemult);
msg_prompt_add(MSG_askfspart, isize, isize, 20,
diskdev, partname[part],
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
/* If less than a 'unit' left, also use it */
if (remain - partsize < sizemult)
partsize = remain;
bsdlabel[part].pi_fstype = FS_BSDFFS;
@ -318,17 +352,15 @@ md_make_bsd_partitions()
bsdlabel[part].pi_size = partsize;
bsdlabel[part].pi_bsize = 8192;
bsdlabel[part].pi_fsize = 1024;
msg_prompt_add (MSG_mountpoint, NULL,
fsmount[part], 20);
msg_prompt_add(MSG_mountpoint, NULL, fsmount[part],
20);
partstart += partsize;
remain = fsdsize - partstart;
part++;
}
break;
}
/*
* OK, we have a partition table. Give the user the chance to
* edit it and verify it's OK, or abort altogether.
@ -339,11 +371,10 @@ md_make_bsd_partitions()
}
/* Disk name */
msg_prompt (MSG_packname, "mydisk", bsddiskname, DISKNAME_SIZE);
msg_prompt(MSG_packname, "mydisk", bsddiskname, DISKNAME_SIZE);
/* save label to disk for MI code to update. */
(void) savenewlabel(bsdlabel, 8); /* 8 partitions in label */
(void) savenewlabel(bsdlabel, 8); /* 8 partitions in label */
/* Everything looks OK. */
return (1);
@ -351,11 +382,10 @@ md_make_bsd_partitions()
/* Upgrade support */
int
md_update()
md_update(void)
{
endwin();
md_copy_filesystem ();
md_copy_filesystem();
md_post_newfs();
puts(CL); /* XXX */
wclear(stdscr);
@ -372,6 +402,7 @@ md_cleanup_install(void)
strncpy(realfrom, target_expand("/etc/rc.conf"), STRSIZE);
strncpy(realto, target_expand("/etc/rc.conf.install"), STRSIZE);
sprintf(sedcmd, "sed 's/rc_configured=NO/rc_configured=YES/' < %s > %s",
realfrom, realto);
if (logging)

View File

@ -1,4 +1,4 @@
/* $NetBSD: md.c,v 1.8 1999/06/22 00:57:10 cgd Exp $ */
/* $NetBSD: md.c,v 1.9 1999/08/10 15:54:56 abs Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -26,19 +26,20 @@
* THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/* changes from the i386 version made by mrg */
/* md.c -- vax machine specific routines */
/* This file is in close sync with pmax, sparc, and x68k md.c */
#include <sys/types.h>
#include <sys/disklabel.h>
@ -58,25 +59,32 @@
/*
* Symbolic names for disk partitions.
*/
#define PART_ROOT A
#define PART_RAW C
#define PART_USR G
#define PART_ROOT A
#define PART_SWAP B
#define PART_RAW C
#define PART_USR D /* Can be after PART_FIRST_FREE */
#define PART_FIRST_FREE E
#define PART_LAST H
#define DEFSWAPRAM 16 /* Assume at least this RAM for swap calc */
#define DEFROOTSIZE 32 /* Default root size */
#define STDNEEDMB 80 /* Min space for non X install */
int
md_get_info()
md_get_info(void)
{
struct disklabel disklabel;
int fd;
char devname[100];
snprintf (devname, 100, "/dev/r%sc", diskdev);
snprintf(devname, 100, "/dev/r%sc", diskdev);
fd = open (devname, O_RDONLY, 0);
fd = open(devname, O_RDONLY, 0);
if (fd < 0) {
if (logging)
(void)fprintf(log, "Can't open %s\n", devname);
endwin();
fprintf (stderr, "Can't open %s\n", devname);
fprintf(stderr, "Can't open %s\n", devname);
exit(1);
}
if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
@ -84,7 +92,7 @@ md_get_info()
(void)fprintf(log, "Can't read disklabel on %s.\n",
devname);
endwin();
fprintf (stderr, "Can't read disklabel on %s.\n", devname);
fprintf(stderr, "Can't read disklabel on %s.\n", devname);
close(fd);
exit(1);
}
@ -98,7 +106,7 @@ md_get_info()
/*
* Compute whole disk size. Take max of (dlcyl*dlhead*dlsec)
* and secperunit, just in case the disk is already labelled.
* and secperunit, just in case the disk is already labelled.
* (If our new label's RAW_PART size ends up smaller than the
* in-core RAW_PART size value, updating the label will fail.)
*/
@ -107,7 +115,7 @@ md_get_info()
dlsize = disklabel.d_secperunit;
/* Compute minimum NetBSD partition sizes (in sectors). */
minfsdmb = (80 + 4*rammb) * (MEG / sectorsize);
minfsdmb = STDNEEDMB * (MEG / sectorsize);
return 1;
}
@ -116,15 +124,16 @@ md_get_info()
* hook called before writing new disklabel.
*/
int
md_pre_disklabel()
md_pre_disklabel(void)
{
return 1;
return 0;
}
/*
* hook called after writing disklabel to new target disk.
*/
int md_post_disklabel (void)
int
md_post_disklabel(void)
{
return 0;
}
@ -132,14 +141,14 @@ int md_post_disklabel (void)
/*
* MD hook called after upgrade() or install() has finished setting
* up the target disk but immediately before the user is given the
* ``disks are now set up'' message that, if power fails, they can
* ``disks are now set up'' message, so that if power fails, they can
* continue installation by booting the target disk and doing an
* `upgrade'.
*
* On the vax, we use this opportunity to install the boot blocks.
*/
int
md_post_newfs()
md_post_newfs(void)
{
printf(msg_string(MSG_dobootblks), diskdev);
@ -151,13 +160,16 @@ md_post_newfs()
* some ports use this to copy the MD filesystem, we do not.
*/
int
md_copy_filesystem()
md_copy_filesystem(void)
{
return 0;
}
/*
* md back-end code for menu-driven BSD disklabel editor.
*/
int
md_make_bsd_partitions()
md_make_bsd_partitions(void)
{
int i, part;
int remain;
@ -165,7 +177,7 @@ md_make_bsd_partitions()
int maxpart = getmaxpartitions();
/*
* Initialize global variables that track space used on this disk.
* Initialize global variables that track space used on this disk.
* Standard 4.3BSD 8-partition labels always cover whole disk.
*/
ptsize = dlsize - ptstart;
@ -174,11 +186,11 @@ md_make_bsd_partitions()
fsdmb = fsdsize / MEG;
/* Ask for layout type -- standard or special */
msg_display (MSG_layout,
(1.0*fsptsize*sectorsize)/MEG,
(1.0*minfsdmb*sectorsize)/MEG,
(1.0*minfsdmb*sectorsize)/MEG+rammb+XNEEDMB);
process_menu (MENU_layout);
msg_display(MSG_layout,
(1.0*fsptsize*sectorsize)/MEG,
(1.0*minfsdmb*sectorsize)/MEG,
(1.0*minfsdmb*sectorsize)/MEG+rammb+XNEEDMB);
process_menu(MENU_layout);
if (layoutkind == 3) {
ask_sizemult();
@ -191,21 +203,20 @@ md_make_bsd_partitions()
/* Build standard partitions */
emptylabel(bsdlabel);
/* Partitions C is predefined (whole disk). */
/* Partitions C is predefined (whole disk). */
bsdlabel[C].pi_fstype = FS_UNUSED;
bsdlabel[C].pi_offset = 0;
bsdlabel[C].pi_size = dlsize;
/* Standard fstypes */
bsdlabel[A].pi_fstype = FS_BSDFFS;
bsdlabel[B].pi_fstype = FS_SWAP;
bsdlabel[B].pi_fstype = FS_UNUSED;
/* Conventionally, C is whole disk. */
bsdlabel[D].pi_fstype = FS_UNUSED; /* fill out below */
bsdlabel[E].pi_fstype = FS_UNUSED;
bsdlabel[F].pi_fstype = FS_UNUSED;
bsdlabel[G].pi_fstype = FS_UNUSED;
bsdlabel[H].pi_fstype = FS_UNUSED;
part = D;
switch (layoutkind) {
@ -214,22 +225,23 @@ md_make_bsd_partitions()
partstart = ptstart;
/* Root */
/* NetBSD/vax uses a 16 Mbyte root */
partsize= NUMSEC(16, MEG/sectorsize, dlcylsize);
bsdlabel[A].pi_offset = partstart;
bsdlabel[A].pi_size = partsize;
bsdlabel[A].pi_bsize = 8192;
bsdlabel[A].pi_fsize = 1024;
strcpy (fsmount[A], "/");
partsize = NUMSEC(DEFROOTSIZE, MEG/sectorsize, dlcylsize);
bsdlabel[PART_ROOT].pi_offset = partstart;
bsdlabel[PART_ROOT].pi_size = partsize;
bsdlabel[PART_ROOT].pi_bsize = 8192;
bsdlabel[PART_ROOT].pi_fsize = 1024;
strcpy(fsmount[PART_ROOT], "/");
partstart += partsize;
/* swap */
i = NUMSEC(layoutkind * 2 * (rammb < 16 ? 16 : rammb),
i = NUMSEC(layoutkind * 2 *
(rammb < DEFSWAPRAM ? DEFSWAPRAM : rammb),
MEG/sectorsize, dlcylsize) + partstart;
partsize = NUMSEC (i/(MEG/sectorsize)+1, MEG/sectorsize,
partsize = NUMSEC(i/(MEG/sectorsize)+1, MEG/sectorsize,
dlcylsize) - partstart;
bsdlabel[B].pi_offset = partstart;
bsdlabel[B].pi_size = partsize;
bsdlabel[PART_SWAP].pi_fstype = FS_SWAP;
bsdlabel[PART_SWAP].pi_offset = partstart;
bsdlabel[PART_SWAP].pi_size = partsize;
partstart += partsize;
/* /usr */
@ -239,7 +251,7 @@ md_make_bsd_partitions()
bsdlabel[PART_USR].pi_size = partsize;
bsdlabel[PART_USR].pi_bsize = 8192;
bsdlabel[PART_USR].pi_fsize = 1024;
strcpy (fsmount[PART_USR], "/usr");
strcpy(fsmount[PART_USR], "/usr");
break;
@ -248,62 +260,83 @@ md_make_bsd_partitions()
/* root */
partstart = ptstart;
remain = fsdsize - partstart;
/* NetBSD/vax uses a 32Mbyte root */
partsize = NUMSEC (32, MEG/sectorsize, dlcylsize);
snprintf (isize, 20, "%d", partsize/sizemult);
msg_prompt (MSG_askfsroot, isize, isize, 20,
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
bsdlabel[A].pi_offset = partstart;
bsdlabel[A].pi_size = partsize;
bsdlabel[A].pi_bsize = 8192;
bsdlabel[A].pi_fsize = 1024;
strcpy (fsmount[A], "/");
partstart += partsize;
/* swap */
remain = fsdsize - partstart;
i = NUMSEC(2 * (rammb < 32 ? 32 : rammb),
MEG/sectorsize, dlcylsize) + partstart;
partsize = NUMSEC (i/(MEG/sectorsize)+1, MEG/sectorsize,
dlcylsize) - partstart;
snprintf (isize, 20, "%d", partsize/sizemult);
msg_prompt_add (MSG_askfsswap, isize, isize, 20,
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
bsdlabel[B].pi_offset = partstart;
bsdlabel[B].pi_size = partsize;
partstart += partsize;
/* /usr */
remain = fsdsize - partstart;
partsize = fsdsize - partstart;
snprintf (isize, 20, "%d", partsize/sizemult);
msg_prompt_add (MSG_askfsusr, isize, isize, 20,
partsize = NUMSEC(DEFROOTSIZE, MEG/sectorsize, dlcylsize);
snprintf(isize, 20, "%d", partsize/sizemult);
msg_prompt(MSG_askfsroot, isize, isize, 20,
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
/* If less than a 'unit' left, also use it */
if (remain - partsize < sizemult)
partsize = remain;
bsdlabel[PART_USR].pi_fstype = FS_BSDFFS;
bsdlabel[PART_USR].pi_offset = partstart;
bsdlabel[PART_USR].pi_size = partsize;
bsdlabel[PART_USR].pi_bsize = 8192;
bsdlabel[PART_USR].pi_fsize = 1024;
strcpy (fsmount[PART_USR], "/usr");
bsdlabel[PART_ROOT].pi_offset = partstart;
bsdlabel[PART_ROOT].pi_size = partsize;
bsdlabel[PART_ROOT].pi_bsize = 8192;
bsdlabel[PART_ROOT].pi_fsize = 1024;
strcpy(fsmount[PART_ROOT], "/");
partstart += partsize;
/* swap */
remain = fsdsize - partstart;
if (remain > 0) {
i = NUMSEC(2 *
(rammb < DEFSWAPRAM ? DEFSWAPRAM : rammb),
MEG/sectorsize, dlcylsize) + partstart;
partsize = NUMSEC(i/(MEG/sectorsize)+1, MEG/sectorsize,
dlcylsize) - partstart;
if (partsize > remain)
partsize = remain;
snprintf(isize, 20, "%d", partsize/sizemult);
msg_prompt_add(MSG_askfsswap, isize, isize, 20,
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
if (partsize) {
/* If less than a 'unit' left, also use it */
if (remain - partsize < sizemult)
partsize = remain;
bsdlabel[PART_SWAP].pi_fstype = FS_SWAP;
bsdlabel[PART_SWAP].pi_offset = partstart;
bsdlabel[PART_SWAP].pi_size = partsize;
partstart += partsize;
}
}
/* /usr */
remain = fsdsize - partstart;
if (remain > 0) {
partsize = remain;
snprintf(isize, 20, "%d", partsize/sizemult);
msg_prompt_add(MSG_askfsusr, isize, isize, 20,
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
if (partsize) {
/* If less than a 'unit' left, also use it */
if (remain - partsize < sizemult)
partsize = remain;
bsdlabel[PART_USR].pi_fstype = FS_BSDFFS;
bsdlabel[PART_USR].pi_offset = partstart;
bsdlabel[PART_USR].pi_size = partsize;
bsdlabel[PART_USR].pi_bsize = 8192;
bsdlabel[PART_USR].pi_fsize = 1024;
strcpy(fsmount[PART_USR], "/usr");
partstart += partsize;
}
}
/* Others ... */
remain = fsdsize - partstart;
part = F;
if (remain > 0)
msg_display (MSG_otherparts);
while (remain > 0 && part <= H) {
msg_display(MSG_otherparts);
part = PART_FIRST_FREE;
for (; remain > 0 && part <= PART_LAST; ++part ) {
if (bsdlabel[part].pi_fstype != FS_UNUSED)
continue;
partsize = fsdsize - partstart;
snprintf (isize, 20, "%d", partsize/sizemult);
msg_prompt_add (MSG_askfspart, isize, isize, 20,
snprintf(isize, 20, "%d", partsize/sizemult);
msg_prompt_add(MSG_askfspart, isize, isize, 20,
diskdev, partname[part],
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
/* If less than a 'unit' left, also use it */
if (remain - partsize < sizemult)
partsize = remain;
bsdlabel[part].pi_fstype = FS_BSDFFS;
@ -311,17 +344,15 @@ md_make_bsd_partitions()
bsdlabel[part].pi_size = partsize;
bsdlabel[part].pi_bsize = 8192;
bsdlabel[part].pi_fsize = 1024;
msg_prompt_add (MSG_mountpoint, NULL,
fsmount[part], 20);
msg_prompt_add(MSG_mountpoint, NULL, fsmount[part],
20);
partstart += partsize;
remain = fsdsize - partstart;
part++;
}
break;
}
/*
* OK, we have a partition table. Give the user the chance to
* edit it and verify it's OK, or abort altogether.
@ -332,11 +363,10 @@ md_make_bsd_partitions()
}
/* Disk name */
msg_prompt (MSG_packname, "mydisk", bsddiskname, DISKNAME_SIZE);
msg_prompt(MSG_packname, "mydisk", bsddiskname, DISKNAME_SIZE);
/* save label to disk for MI code to update. */
(void) savenewlabel(bsdlabel, 8); /* 8 partitions in label */
(void) savenewlabel(bsdlabel, 8); /* 8 partitions in label */
/* Everything looks OK. */
return (1);
@ -344,11 +374,10 @@ md_make_bsd_partitions()
/* Upgrade support */
int
md_update()
md_update(void)
{
endwin();
md_copy_filesystem ();
md_copy_filesystem();
md_post_newfs();
puts(CL); /* XXX */
wclear(stdscr);
@ -357,7 +386,26 @@ md_update()
}
void
md_cleanup_install()
md_cleanup_install(void)
{
char realfrom[STRSIZE];
char realto[STRSIZE];
char sedcmd[STRSIZE];
strncpy(realfrom, target_expand("/etc/rc.conf"), STRSIZE);
strncpy(realto, target_expand("/etc/rc.conf.install"), STRSIZE);
sprintf(sedcmd, "sed 's/rc_configured=NO/rc_configured=YES/' < %s > %s",
realfrom, realto);
if (logging)
(void)fprintf(log, "%s\n", sedcmd);
if (scripting)
(void)fprintf(script, "%s\n", sedcmd);
do_system(sedcmd);
run_prog(1, 0, NULL, "mv -f %s %s", realto, realfrom);
run_prog(0, 0, NULL, "rm -f %s", target_expand("/sysinst"));
run_prog(0, 0, NULL, "rm -f %s", target_expand("/.termcap"));
run_prog(0, 0, NULL, "rm -f %s", target_expand("/.profile"));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: md.c,v 1.2 1999/07/11 14:12:21 minoura Exp $ */
/* $NetBSD: md.c,v 1.3 1999/08/10 15:54:56 abs Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -26,17 +26,18 @@
* THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/* md.c -- Machine specific code for x68k */
/* This file is in close sync with pmax, sparc, and vax md.c */
#include <stdio.h>
#include <unistd.h>
@ -53,10 +54,16 @@
/*
* Symbolic names for disk partitions.
*/
#define PART_ROOT A
#define PART_RAW C
#define PART_USR D
#define PART_ROOT A
#define PART_SWAP B
#define PART_RAW C
#define PART_USR D /* Can be after PART_FIRST_FREE */
#define PART_FIRST_FREE E
#define PART_LAST H
#define DEFSWAPRAM 32 /* Assume at least this RAM for swap calc */
#define DEFROOTSIZE 20 /* Default root size */
#define STDNEEDMB 80 /* Min space for non X install */
#ifdef notyet
#undef NDOSPART 8
@ -80,7 +87,7 @@ static int md_newdisk __P((void));
static int md_check_partition_order __P((void));
int
md_get_info()
md_get_info(void)
{
char buf[1024];
int fd;
@ -91,12 +98,16 @@ md_get_info()
fd = open(devname, O_RDONLY, 0);
if (fd < 0) {
if (logging)
(void)fprintf(log, "Can't open %s\n", devname);
endwin();
fprintf(stderr, "Can't open %s\n", devname);
exit(1);
}
if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
if (logging)
(void)fprintf(log, "Can't read disklabel on %s.\n",
devname);
endwin();
fprintf(stderr, "Can't read disklabel on %s.\n", devname);
close(fd);
@ -141,7 +152,7 @@ md_get_info()
close(fd);
/* Compute minimum NetBSD partition sizes (in sectors). */
minfsdmb = (80 + 4*rammb) * (MEG / sectorsize);
minfsdmb = STDNEEDMB * (MEG / sectorsize);
return 1;
}
@ -157,7 +168,7 @@ md_newdisk(void)
size_t size = dlsize + 64;
snprintf(devname, 100, "/dev/r%sc", diskdev);
fd = open (devname, O_WRONLY);
fd = open(devname, O_WRONLY);
if (fd < 0) {
endwin();
fprintf(stderr, "Can't open %s\n", devname);
@ -301,14 +312,14 @@ md_check_partitions(void)
}
/* Partitions should be preserved in md_make_bsdpartitions() */
}
}
#endif
/*
* hook called before writing new disklabel.
*/
int
md_pre_disklabel()
md_pre_disklabel(void)
{
if (md_need_newdisk)
md_newdisk ();
@ -327,7 +338,7 @@ md_post_disklabel(void)
/*
* MD hook called after upgrade() or install() has finished setting
* up the target disk but immediately before the user is given the
* ``disks are now set up'' message that, if power fails, they can
* ``disks are now set up'' message, so that if power fails, they can
* continue installation by booting the target disk and doing an
* `upgrade'.
*
@ -352,20 +363,24 @@ md_copy_filesystem(void)
return 0;
}
/*
* md back-end code for menu-driven BSD disklabel editor.
*/
int
md_make_bsd_partitions(void)
{
int i, part;
int remain;
char isize[20];
int maxpart = getmaxpartitions();
/*
* Initialize global variables that track space used on this disk.
* Initialize global variables that track space used on this disk.
* Standard 4.3BSD 8-partition labels always cover whole disk.
*/
ptstart = 64; /* assume 512 byte/sector */
ptsize = dlsize - ptstart;
fsdsize = dlsize;
fsdsize = dlsize; /* actually means `whole disk' */
fsptsize = dlsize - ptstart; /* netbsd partition -- same as above */
fsdmb = fsdsize / MEG;
@ -383,6 +398,7 @@ md_make_bsd_partitions(void)
multname = msg_string(MSG_megname);
}
/* Build standard partitions */
emptylabel(bsdlabel);
@ -390,17 +406,16 @@ md_make_bsd_partitions(void)
bsdlabel[C].pi_fstype = FS_UNUSED;
bsdlabel[C].pi_offset = 0;
bsdlabel[C].pi_size = dlsize;
/* Standard fstypes */
bsdlabel[A].pi_fstype = FS_BSDFFS;
bsdlabel[B].pi_fstype = FS_SWAP;
bsdlabel[B].pi_fstype = FS_UNUSED;
/* Conventionally, C is whole disk. */
bsdlabel[D].pi_fstype = FS_UNUSED; /* fill out below */
bsdlabel[E].pi_fstype = FS_UNUSED;
bsdlabel[F].pi_fstype = FS_UNUSED;
bsdlabel[G].pi_fstype = FS_UNUSED;
bsdlabel[H].pi_fstype = FS_UNUSED;
part = D;
switch (layoutkind) {
@ -409,22 +424,23 @@ md_make_bsd_partitions(void)
partstart = ptstart;
/* Root */
/* 20Mbyte for root */
partsize= NUMSEC(20, MEG/sectorsize, dlcylsize);
bsdlabel[A].pi_offset = partstart;
bsdlabel[A].pi_size = partsize;
bsdlabel[A].pi_bsize = 8192;
bsdlabel[A].pi_fsize = 1024;
strcpy(fsmount[A], "/");
partsize = NUMSEC(DEFROOTSIZE, MEG/sectorsize, dlcylsize);
bsdlabel[PART_ROOT].pi_offset = partstart;
bsdlabel[PART_ROOT].pi_size = partsize;
bsdlabel[PART_ROOT].pi_bsize = 8192;
bsdlabel[PART_ROOT].pi_fsize = 1024;
strcpy(fsmount[PART_ROOT], "/");
partstart += partsize;
/* swap */
i = NUMSEC (layoutkind * 2 * (rammb < 32 ? 32 : rammb),
MEG/sectorsize, dlcylsize) + partstart;
partsize = NUMSEC (i/(MEG/sectorsize)+1, MEG/sectorsize,
dlcylsize) - partstart;
bsdlabel[B].pi_offset = partstart;
bsdlabel[B].pi_size = partsize;
i = NUMSEC(layoutkind * 2 *
(rammb < DEFSWAPRAM ? DEFSWAPRAM : rammb),
MEG/sectorsize, dlcylsize) + partstart;
partsize = NUMSEC(i/(MEG/sectorsize)+1, MEG/sectorsize,
dlcylsize) - partstart;
bsdlabel[PART_SWAP].pi_fstype = FS_SWAP;
bsdlabel[PART_SWAP].pi_offset = partstart;
bsdlabel[PART_SWAP].pi_size = partsize;
partstart += partsize;
/* /usr */
@ -443,62 +459,83 @@ md_make_bsd_partitions(void)
/* root */
partstart = ptstart;
remain = fsdsize - partstart;
/* 20Mbyte for root */
partsize = NUMSEC (20, MEG/sectorsize, dlcylsize);
partsize = NUMSEC(DEFROOTSIZE, MEG/sectorsize, dlcylsize);
snprintf(isize, 20, "%d", partsize/sizemult);
msg_prompt(MSG_askfsroot, isize, isize, 20,
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
bsdlabel[A].pi_offset = partstart;
bsdlabel[A].pi_size = partsize;
bsdlabel[A].pi_bsize = 8192;
bsdlabel[A].pi_fsize = 1024;
strcpy(fsmount[A], "/");
partstart += partsize;
/* swap */
remain = fsdsize - partstart;
i = NUMSEC(2 * (rammb < 32 ? 32 : rammb),
MEG/sectorsize, dlcylsize) + partstart;
partsize = NUMSEC (i/(MEG/sectorsize)+1, MEG/sectorsize,
dlcylsize) - partstart;
snprintf(isize, 20, "%d", partsize/sizemult);
msg_prompt_add(MSG_askfsswap, isize, isize, 20,
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
bsdlabel[B].pi_offset = partstart;
bsdlabel[B].pi_size = partsize;
partstart += partsize;
/* /usr */
remain = fsdsize - partstart;
partsize = fsdsize - partstart;
snprintf(isize, 20, "%d", partsize/sizemult);
msg_prompt_add(MSG_askfsusr, isize, isize, 20,
remain/sizemult, multname);
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
/* If less than a 'unit' left, also use it */
if (remain - partsize < sizemult)
partsize = remain;
bsdlabel[PART_USR].pi_fstype = FS_BSDFFS;
bsdlabel[PART_USR].pi_offset = partstart;
bsdlabel[PART_USR].pi_size = partsize;
bsdlabel[PART_USR].pi_bsize = 8192;
bsdlabel[PART_USR].pi_fsize = 1024;
strcpy(fsmount[PART_USR], "/usr");
bsdlabel[PART_ROOT].pi_offset = partstart;
bsdlabel[PART_ROOT].pi_size = partsize;
bsdlabel[PART_ROOT].pi_bsize = 8192;
bsdlabel[PART_ROOT].pi_fsize = 1024;
strcpy(fsmount[PART_ROOT], "/");
partstart += partsize;
/* swap */
remain = fsdsize - partstart;
if (remain > 0) {
i = NUMSEC(2 *
(rammb < DEFSWAPRAM ? DEFSWAPRAM : rammb),
MEG/sectorsize, dlcylsize) + partstart;
partsize = NUMSEC(i/(MEG/sectorsize)+1, MEG/sectorsize,
dlcylsize) - partstart;
if (partsize > remain)
partsize = remain;
snprintf(isize, 20, "%d", partsize/sizemult);
msg_prompt_add(MSG_askfsswap, isize, isize, 20,
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
if (partsize) {
/* If less than a 'unit' left, also use it */
if (remain - partsize < sizemult)
partsize = remain;
bsdlabel[PART_SWAP].pi_fstype = FS_SWAP;
bsdlabel[PART_SWAP].pi_offset = partstart;
bsdlabel[PART_SWAP].pi_size = partsize;
partstart += partsize;
}
}
/* /usr */
remain = fsdsize - partstart;
if (remain > 0) {
partsize = remain;
snprintf(isize, 20, "%d", partsize/sizemult);
msg_prompt_add(MSG_askfsusr, isize, isize, 20,
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
if (partsize) {
/* If less than a 'unit' left, also use it */
if (remain - partsize < sizemult)
partsize = remain;
bsdlabel[PART_USR].pi_fstype = FS_BSDFFS;
bsdlabel[PART_USR].pi_offset = partstart;
bsdlabel[PART_USR].pi_size = partsize;
bsdlabel[PART_USR].pi_bsize = 8192;
bsdlabel[PART_USR].pi_fsize = 1024;
strcpy(fsmount[PART_USR], "/usr");
partstart += partsize;
}
}
/* Others ... */
remain = fsdsize - partstart;
part = F;
if (remain > 0)
msg_display(MSG_otherparts);
while (remain > 0 && part <= H) {
part = PART_FIRST_FREE;
for (; remain > 0 && part <= PART_LAST; ++part ) {
if (bsdlabel[part].pi_fstype != FS_UNUSED)
continue;
partsize = fsdsize - partstart;
snprintf(isize, 20, "%d", partsize/sizemult);
msg_prompt_add(MSG_askfspart, isize, isize, 20,
diskdev, partname[part],
remain/sizemult, multname);
diskdev, partname[part],
remain/sizemult, multname);
partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
/* If less than a 'unit' left, also use it */
if (remain - partsize < sizemult)
partsize = remain;
bsdlabel[part].pi_fstype = FS_BSDFFS;
@ -506,23 +543,21 @@ md_make_bsd_partitions(void)
bsdlabel[part].pi_size = partsize;
bsdlabel[part].pi_bsize = 8192;
bsdlabel[part].pi_fsize = 1024;
msg_prompt_add(MSG_mountpoint, NULL,
fsmount[part], 20);
msg_prompt_add(MSG_mountpoint, NULL, fsmount[part],
20);
partstart += partsize;
remain = fsdsize - partstart;
part++;
}
break;
}
/*
* OK, we have a partition table. Give the user the chance to
* edit it and verify it's OK, or abort altogether.
*/
edit_check:
if (edit_and_check_label(bsdlabel, 8, RAW_PART, RAW_PART) == 0) {
if (edit_and_check_label(bsdlabel, maxpart, RAW_PART, RAW_PART) == 0) {
msg_display(MSG_abort);
return 0;
}
@ -533,7 +568,7 @@ md_make_bsd_partitions(void)
msg_prompt(MSG_packname, "mydisk", bsddiskname, DISKNAME_SIZE);
/* save label to disk for MI code to update. */
(void) savenewlabel(bsdlabel, 8); /* 8 partitions in label */
(void) savenewlabel(bsdlabel, 8); /* 8 partitions in label */
/* Everything looks OK. */
return (1);
@ -602,6 +637,7 @@ md_cleanup_install(void)
do_system(sedcmd);
run_prog(1, 0, NULL, "mv -f %s %s", realto, realfrom);
run_prog(0, 0, NULL, "rm -f %s", target_expand("/sysinst"));
run_prog(0, 0, NULL, "rm -f %s", target_expand("/.termcap"));
run_prog(0, 0, NULL, "rm -f %s", target_expand("/.profile"));