Correct check for active swap on install disk.

Use swapctl() for all swap operations.
Remove md_upgrade_mbrtype() from arc and hpcmips ports.
(I haven't finalised what I'm doing about type 165 partitions, but the
existing code is borked.)
This commit is contained in:
dsl 2003-06-16 10:42:47 +00:00
parent 1430af815a
commit 430c90c3f6
9 changed files with 86 additions and 100 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: md.c,v 1.17 2003/06/14 12:58:47 dsl Exp $ */
/* $NetBSD: md.c,v 1.18 2003/06/16 10:42:48 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -56,8 +56,6 @@
mbr_sector_t mbr;
static void md_upgrade_mbrtype (void);
/* prototypes */
@ -82,7 +80,6 @@ md_pre_disklabel(void)
process_menu(MENU_ok, NULL);
return 1;
}
md_upgrade_mbrtype();
return 0;
}
@ -90,7 +87,7 @@ int
md_post_disklabel(void)
{
if (rammb <= 32)
set_swap(diskdev, bsdlabel, 1);
set_swap(diskdev, bsdlabel);
/* Sector forwarding / badblocks ... */
if (*doessf) {
@ -132,7 +129,7 @@ int
md_pre_update(void)
{
if (rammb <= 8)
set_swap(diskdev, NULL, 1);
set_swap(diskdev, NULL);
return 1;
}
@ -144,7 +141,6 @@ md_update(void)
endwin();
md_copy_filesystem();
md_post_newfs();
md_upgrade_mbrtype();
wrefresh(curscr);
wmove(stdscr, 0, 0);
wclear(stdscr);
@ -152,32 +148,6 @@ md_update(void)
return 1;
}
void
md_upgrade_mbrtype(void)
{
struct mbr_partition *mbrp;
int i, netbsdpart = -1, oldbsdpart = -1, oldbsdcount = 0;
if (read_mbr(diskdev, &mbr) < 0)
return;
mbrp = &mbr.mbr_parts[0];
for (i = 0; i < NMBRPART; i++) {
if (mbrp[i].mbrp_typ == MBR_PTYPE_386BSD) {
oldbsdpart = i;
oldbsdcount++;
} else if (mbrp[i].mbrp_typ == MBR_PTYPE_NETBSD)
netbsdpart = i;
}
if (netbsdpart == -1 && oldbsdcount == 1) {
mbrp[oldbsdpart].mbrp_typ = MBR_PTYPE_NETBSD;
write_mbr(diskdev, &mbr, 0);
}
}
void
md_cleanup_install(void)

View File

@ -1,4 +1,4 @@
/* $NetBSD: md.c,v 1.9 2003/06/13 11:57:31 dsl Exp $ */
/* $NetBSD: md.c,v 1.10 2003/06/16 10:42:48 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -126,7 +126,7 @@ md_post_disklabel(void)
{
if (rammb < 6)
set_swap(diskdev, bsdlabel, 1);
set_swap(diskdev, bsdlabel);
return (0);
}
@ -250,7 +250,7 @@ md_pre_update()
{
if (rammb < 6)
set_swap(diskdev, NULL, 1);
set_swap(diskdev, NULL);
return (1);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: md.c,v 1.32 2003/06/14 12:58:48 dsl Exp $ */
/* $NetBSD: md.c,v 1.33 2003/06/16 10:42:49 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -58,8 +58,6 @@ mbr_sector_t mbr;
#endif
int mbr_present;
static void md_upgrade_mbrtype (void);
/* prototypes */
@ -86,7 +84,6 @@ md_pre_disklabel(void)
process_menu(MENU_ok, NULL);
return 1;
}
md_upgrade_mbrtype();
return 0;
}
@ -135,7 +132,6 @@ md_update(void)
endwin();
md_copy_filesystem();
md_post_newfs();
md_upgrade_mbrtype();
wrefresh(curscr);
wmove(stdscr, 0, 0);
wclear(stdscr);
@ -143,32 +139,6 @@ md_update(void)
return 1;
}
void
md_upgrade_mbrtype(void)
{
struct mbr_partition *mbrp;
int i, netbsdpart = -1, oldbsdpart = -1, oldbsdcount = 0;
if (read_mbr(diskdev, &mbr) < 0)
return;
mbrp = &mbr.mbr_parts[0];
for (i = 0; i < NMBRPART; i++) {
if (mbrp[i].mbrp_typ == MBR_PTYPE_386BSD) {
oldbsdpart = i;
oldbsdcount++;
} else if (mbrp[i].mbrp_typ == MBR_PTYPE_NETBSD)
netbsdpart = i;
}
if (netbsdpart == -1 && oldbsdcount == 1) {
mbrp[oldbsdpart].mbrp_typ = MBR_PTYPE_NETBSD;
write_mbr(diskdev, &mbr, 0);
}
}
void
md_cleanup_install(void)

View File

@ -1,4 +1,4 @@
/* $NetBSD: md.c,v 1.88 2003/06/14 12:58:49 dsl Exp $ */
/* $NetBSD: md.c,v 1.89 2003/06/16 10:42:50 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -191,7 +191,7 @@ int
md_post_disklabel(void)
{
if (rammb <= 32)
set_swap(diskdev, bsdlabel, 1);
set_swap(diskdev, bsdlabel);
return 0;
}
@ -265,7 +265,7 @@ int
md_pre_update(void)
{
if (rammb <= 8)
set_swap(diskdev, NULL, 1);
set_swap(diskdev, NULL);
return 1;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: md.c,v 1.8 2003/06/13 11:57:32 dsl Exp $ */
/* $NetBSD: md.c,v 1.9 2003/06/16 10:42:51 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -126,7 +126,7 @@ md_post_disklabel(void)
{
if (rammb < 6)
set_swap(diskdev, bsdlabel, 1);
set_swap(diskdev, bsdlabel);
return (0);
}
@ -250,7 +250,7 @@ md_pre_update()
{
if (rammb < 6)
set_swap(diskdev, NULL, 1);
set_swap(diskdev, NULL);
return (1);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: md.c,v 1.23 2003/06/13 11:57:37 dsl Exp $ */
/* $NetBSD: md.c,v 1.24 2003/06/16 10:42:51 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -221,7 +221,7 @@ int
md_post_disklabel(void)
{
if (rammb < 6)
set_swap(diskdev, bsdlabel, 1);
set_swap(diskdev, bsdlabel);
return 0;
}
@ -340,7 +340,7 @@ int
md_pre_update()
{
if (rammb < 6)
set_swap(diskdev, NULL, 1);
set_swap(diskdev, NULL);
return 1;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: defs.h,v 1.90 2003/06/14 12:58:45 dsl Exp $ */
/* $NetBSD: defs.h,v 1.91 2003/06/16 10:42:47 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -197,7 +197,6 @@ EXTERN char diskdev[SSTRSIZE] INIT("");
EXTERN char disknames[STRSIZE];
EXTERN int numdisks;
EXTERN char *disktype; /* ST506, SCSI, ... */
EXTERN char swapdev[SSTRSIZE] INIT("");
/* Used in editing partitions ... BSD disklabel and others */
EXTERN int editpart;
@ -328,7 +327,8 @@ int write_disklabel(void);
int make_filesystems(void);
int make_fstab(void);
int fsck_disks(void);
int set_swap(const char *, partinfo *, int);
int set_swap(const char *, partinfo *);
int check_swap(const char *, int);
/* from disks_lfs.c */
int fs_is_lfs(void *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: disks.c,v 1.57 2003/06/09 19:06:48 dsl Exp $ */
/* $NetBSD: disks.c,v 1.58 2003/06/16 10:42:47 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -47,6 +47,7 @@
#include <util.h>
#include <sys/param.h>
#include <sys/swap.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h>
#define FSTYPENAMES
@ -649,13 +650,14 @@ fsck_disks(void)
}
int
set_swap(dev, pp, enable)
set_swap(dev, pp)
const char *dev;
partinfo *pp;
int enable;
{
partinfo parts[16];
int i, maxpart;
char *cp;
int rval;
if (pp == NULL) {
emptylabel(parts);
@ -667,18 +669,66 @@ set_swap(dev, pp, enable)
maxpart = getmaxpartitions();
for (i = 0; i < maxpart; i++) {
if (pp[i].pi_fstype == FS_SWAP) {
if (run_prog(0, NULL,
"/sbin/swapctl -%c /dev/%s%c",
enable ? 'a' : 'd', dev, 'a' + i) != 0)
return -1;
if (enable)
strcpy(swapdev, dev);
else
swapdev[0] = '\0';
break;
}
if (pp[i].pi_fstype != FS_SWAP)
continue;
asprintf(&cp, "/dev/%s%c", dev, 'a' + i);
rval = swapctl(SWAP_ON, cp, 0);
free(cp);
if (rval != 0)
return -1;
}
return 0;
}
int
check_swap(const char *dev, int remove)
{
struct swapent *swap;
char *cp;
int nswap;
int l;
int rval = 0;
nswap = swapctl(SWAP_NSWAP, 0, 0);
if (nswap <= 0)
return 0;
swap = malloc(nswap * sizeof *swap);
if (swap == NULL)
return -1;
nswap = swapctl(SWAP_STATS, swap, nswap);
if (nswap < 0)
goto bad_swap;
l = strlen(dev);
while (--nswap >= 0) {
/* Should we check the se_dev or se_path? */
cp = swap[nswap].se_path;
if (memcmp(cp, "/dev/", 5) != 0)
continue;
if (memcmp(cp + 5, dev, l) != 0)
continue;
if (!isalpha(*(unsigned char *)(cp + 5 + l)))
continue;
if (cp[5 + l + 1] != 0)
continue;
/* ok path looks like it is for this device */
if (!remove) {
/* count active swap areas */
rval++;
continue;
}
if (swapctl(SWAP_OFF, cp, 0) == -1)
rval = -1;
}
done:
free(swap);
return rval;
bad_swap:
rval = -1;
goto done;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: install.c,v 1.32 2003/06/11 21:35:35 dsl Exp $ */
/* $NetBSD: install.c,v 1.33 2003/06/16 10:42:47 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -55,10 +55,6 @@ do_install()
process_menu(MENU_noyes, NULL);
if (!yesno)
return;
#if 0
if (!askyesno(0))
return;
#endif
get_ramsize();
@ -67,10 +63,10 @@ do_install()
if (find_disks() < 0)
return;
if (!strcmp(diskdev, swapdev)) {
if (check_swap(diskdev, 0) > 0) {
msg_display(MSG_swapactive);
process_menu(MENU_ok, NULL);
if (set_swap(swapdev, NULL, 0) < 0) {
if (check_swap(diskdev, 1) < 0) {
msg_display(MSG_swapdelfailed);
process_menu(MENU_ok, NULL);
return;