2000-09-27 16:42:04 +04:00
|
|
|
/* $NetBSD: disks.c,v 1.32 2000/09/27 12:42:04 fvdl Exp $ */
|
1997-09-27 03:02:53 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1997 Piermont Information Systems Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Written by Philip A. Nelson for Piermont Information Systems Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
1999-06-20 10:08:13 +04:00
|
|
|
* This product includes software developed for the NetBSD Project by
|
1997-09-27 03:02:53 +04:00
|
|
|
* Piermont Information Systems Inc.
|
|
|
|
* 4. The name of Piermont Information Systems Inc. may not be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* 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
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* disks.c -- routines to deal with finding disks and labeling disks. */
|
|
|
|
|
|
|
|
|
1997-11-05 10:28:20 +03:00
|
|
|
#include <errno.h>
|
1997-09-27 03:02:53 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1997-10-07 08:01:29 +04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
1997-11-03 03:04:53 +03:00
|
|
|
#include <util.h>
|
1997-10-07 08:01:29 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <ufs/ufs/dinode.h>
|
|
|
|
#include <ufs/ffs/fs.h>
|
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
#include "defs.h"
|
1997-10-29 04:06:42 +03:00
|
|
|
#include "md.h"
|
1997-09-27 03:02:53 +04:00
|
|
|
#include "msg_defs.h"
|
|
|
|
#include "menu_defs.h"
|
|
|
|
#include "txtwalk.h"
|
|
|
|
|
1997-11-05 10:28:20 +03:00
|
|
|
|
1997-11-02 11:20:40 +03:00
|
|
|
|
1997-10-01 09:04:24 +04:00
|
|
|
/* Local prototypes */
|
1997-10-15 08:35:17 +04:00
|
|
|
static void get_disks (void);
|
1997-10-07 08:01:29 +04:00
|
|
|
static void foundffs (struct data *list, int num);
|
1997-11-05 10:28:20 +03:00
|
|
|
static int do_fsck(const char *diskpart);
|
1997-11-03 05:38:41 +03:00
|
|
|
static int fsck_root __P((void));
|
1999-04-09 14:24:38 +04:00
|
|
|
static int
|
1997-11-03 03:04:53 +03:00
|
|
|
do_ffs_newfs(const char *partname, int part, const char *mountpoint);
|
1997-10-01 09:04:24 +04:00
|
|
|
|
1997-11-05 10:28:20 +03:00
|
|
|
static int fsck_with_error_menu(const char *diskpart);
|
|
|
|
static int target_mount_with_error_menu(const char *opt, char *diskpart,
|
|
|
|
const char *mntpt);
|
|
|
|
|
1997-11-02 11:20:40 +03:00
|
|
|
|
1997-10-15 08:35:17 +04:00
|
|
|
static void get_disks(void)
|
|
|
|
{
|
1997-10-29 04:06:42 +03:00
|
|
|
char **xd = disk_names;
|
1997-10-15 08:35:17 +04:00
|
|
|
char d_name[SSTRSIZE];
|
|
|
|
struct disklabel l;
|
|
|
|
int i;
|
1997-10-07 08:01:29 +04:00
|
|
|
|
1997-10-15 08:35:17 +04:00
|
|
|
while (*xd != NULL) {
|
1998-10-31 06:54:44 +03:00
|
|
|
for (i=0; i< MAX_DISKS; i++) {
|
1999-03-31 04:44:48 +04:00
|
|
|
snprintf(d_name, SSTRSIZE, "%s%d", *xd, i);
|
|
|
|
if (get_geom(d_name, &l) && numdisks < MAX_DISKS) {
|
1999-03-14 17:19:05 +03:00
|
|
|
strncpy (disks[numdisks].dd_name,
|
1997-10-15 08:35:17 +04:00
|
|
|
d_name, SSTRSIZE);
|
|
|
|
strncat (disknames, d_name,
|
|
|
|
SSTRSIZE-1-strlen(disknames));
|
|
|
|
strncat (disknames, " ",
|
|
|
|
SSTRSIZE-1-strlen(disknames));
|
1999-03-14 17:19:05 +03:00
|
|
|
disks[numdisks].dd_cyl = l.d_ncylinders;
|
|
|
|
disks[numdisks].dd_head = l.d_ntracks;
|
|
|
|
disks[numdisks].dd_sec = l.d_nsectors;
|
|
|
|
disks[numdisks].dd_secsize = l.d_secsize;
|
|
|
|
disks[numdisks].dd_totsec = l.d_secperunit;
|
1997-10-15 08:35:17 +04:00
|
|
|
numdisks++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xd++;
|
1997-10-07 08:01:29 +04:00
|
|
|
}
|
|
|
|
}
|
1997-10-15 08:35:17 +04:00
|
|
|
|
1997-10-07 08:01:29 +04:00
|
|
|
|
1999-03-31 04:44:48 +04:00
|
|
|
int find_disks(void)
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
|
|
|
char *tp;
|
1997-10-07 08:01:29 +04:00
|
|
|
char defname[STRSIZE];
|
|
|
|
int i;
|
1997-09-27 03:02:53 +04:00
|
|
|
|
|
|
|
/* initialize */
|
|
|
|
disknames[0] = 0;
|
|
|
|
numdisks = 0;
|
|
|
|
|
1997-10-15 08:35:17 +04:00
|
|
|
/* Find disks. */
|
|
|
|
get_disks();
|
1997-09-27 03:02:53 +04:00
|
|
|
|
1999-01-21 11:02:17 +03:00
|
|
|
/* need a redraw here, kernel messages hose everything */
|
|
|
|
touchwin(stdscr);
|
|
|
|
refresh();
|
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
if (numdisks == 0) {
|
|
|
|
/* No disks found! */
|
1999-03-31 04:44:48 +04:00
|
|
|
msg_display(MSG_nodisk);
|
|
|
|
process_menu(MENU_ok);
|
1999-01-21 11:02:17 +03:00
|
|
|
/*endwin();*/
|
1997-09-27 03:02:53 +04:00
|
|
|
return -1;
|
|
|
|
} else if (numdisks == 1) {
|
|
|
|
/* One disk found! */
|
|
|
|
/* Remove that space we added. */
|
|
|
|
disknames[strlen(disknames)-1] = 0;
|
1999-03-31 04:44:48 +04:00
|
|
|
msg_display(MSG_onedisk, disknames, doingwhat);
|
|
|
|
process_menu(MENU_ok);
|
|
|
|
strcpy(diskdev, disknames);
|
1997-09-27 03:02:53 +04:00
|
|
|
} else {
|
|
|
|
/* Multiple disks found! */
|
1999-03-31 04:44:48 +04:00
|
|
|
strcpy(defname, disknames);
|
1997-09-27 03:02:53 +04:00
|
|
|
tp = defname;
|
|
|
|
strsep(&tp, " ");
|
1999-03-31 04:44:48 +04:00
|
|
|
msg_prompt(MSG_askdisk, defname, diskdev, 10, disknames);
|
1997-09-27 03:02:53 +04:00
|
|
|
tp = diskdev;
|
|
|
|
strsep(&tp, " ");
|
|
|
|
diskdev[strlen(diskdev)+1] = 0;
|
|
|
|
diskdev[strlen(diskdev)] = ' ';
|
1997-10-29 04:06:42 +03:00
|
|
|
while (!ISDISKSTART(*diskdev) ||
|
1997-09-27 03:02:53 +04:00
|
|
|
strstr(disknames, diskdev) == NULL) {
|
1999-03-31 04:44:48 +04:00
|
|
|
msg_prompt(MSG_badname, defname, diskdev, 10,
|
1997-09-27 03:02:53 +04:00
|
|
|
disknames);
|
|
|
|
tp = diskdev;
|
|
|
|
strsep(&tp, " ");
|
|
|
|
diskdev[strlen(diskdev)+1] = 0;
|
|
|
|
diskdev[strlen(diskdev)] = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove that space we added. */
|
|
|
|
diskdev[strlen(diskdev)-1] = 0;
|
|
|
|
}
|
|
|
|
|
1997-10-07 08:01:29 +04:00
|
|
|
/* Set disk. */
|
1999-03-31 04:44:48 +04:00
|
|
|
for (i = 0; i < numdisks; i++)
|
1999-03-14 17:19:05 +03:00
|
|
|
if (strcmp(diskdev, disks[i].dd_name) == 0)
|
1997-10-07 08:01:29 +04:00
|
|
|
disk = &disks[i];
|
|
|
|
|
1999-03-14 17:19:05 +03:00
|
|
|
sectorsize = disk->dd_secsize;
|
|
|
|
if (disk->dd_totsec == 0)
|
|
|
|
disk->dd_totsec = disk->dd_cyl * disk->dd_head * disk->dd_sec;
|
1999-03-31 04:44:48 +04:00
|
|
|
dlcyl = disk->dd_cyl;
|
|
|
|
dlhead = disk->dd_head;
|
|
|
|
dlsec = disk->dd_sec;
|
|
|
|
dlsize = disk->dd_totsec;
|
|
|
|
dlcylsize = dlhead * dlsec;
|
1997-09-27 03:02:53 +04:00
|
|
|
|
|
|
|
return numdisks;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-31 04:44:48 +04:00
|
|
|
void disp_cur_fspart(int disp, int showall)
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int start, stop;
|
1998-12-17 01:35:26 +03:00
|
|
|
int poffset, psize, pend;
|
1997-09-27 03:02:53 +04:00
|
|
|
|
|
|
|
if (disp < 0) {
|
|
|
|
start = 0;
|
1997-11-03 03:04:53 +03:00
|
|
|
stop = getmaxpartitions();
|
1997-09-27 03:02:53 +04:00
|
|
|
} else {
|
|
|
|
start = disp;
|
|
|
|
stop = disp+1;
|
|
|
|
}
|
|
|
|
|
1999-07-04 12:01:39 +04:00
|
|
|
msg_table_add (MSG_fspart_header);
|
1999-03-31 04:44:48 +04:00
|
|
|
for (i = start; i < stop; i++) {
|
|
|
|
if (showall || bsdlabel[i].pi_size > 0) {
|
|
|
|
poffset = bsdlabel[i].pi_offset / sizemult;
|
|
|
|
psize = bsdlabel[i].pi_size / sizemult;
|
1998-12-17 01:35:26 +03:00
|
|
|
if (psize == 0)
|
|
|
|
pend = 0;
|
|
|
|
else
|
1999-03-31 04:44:48 +04:00
|
|
|
pend = (bsdlabel[i].pi_offset +
|
|
|
|
bsdlabel[i].pi_size) / sizemult - 1;
|
1999-07-04 12:01:39 +04:00
|
|
|
msg_table_add(MSG_fspart_row_start,
|
1998-12-17 01:35:26 +03:00
|
|
|
'a'+i, psize, poffset, pend,
|
1999-03-31 04:44:48 +04:00
|
|
|
fstypenames[bsdlabel[i].pi_fstype]);
|
|
|
|
if (bsdlabel[i].pi_fstype == FS_BSDFFS)
|
1999-07-04 12:01:39 +04:00
|
|
|
msg_table_add(MSG_fspart_row_end_bsd,
|
1999-03-31 04:44:48 +04:00
|
|
|
bsdlabel[i].pi_bsize,
|
|
|
|
bsdlabel[i].pi_fsize,
|
1997-09-27 03:02:53 +04:00
|
|
|
fsmount[i]);
|
1999-03-31 04:44:48 +04:00
|
|
|
else if (bsdlabel[i].pi_fstype == FS_MSDOS)
|
1999-07-04 12:01:39 +04:00
|
|
|
msg_table_add(MSG_fspart_row_end_msdos,
|
|
|
|
fsmount[i]);
|
|
|
|
else
|
|
|
|
msg_table_add(MSG_fspart_row_end_other);
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
}
|
1999-07-05 01:52:11 +04:00
|
|
|
msg_display_add(MSG_newline);
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-09 07:14:10 +03:00
|
|
|
/*
|
|
|
|
* Label a disk using an MD-specific string DISKLABEL_CMD for
|
|
|
|
* to invoke disklabel.
|
|
|
|
* if MD code does not define DISKLABEL_CMD, this is a no-op.
|
|
|
|
*
|
|
|
|
* i386 port uses "/sbin/disklabel -w -r", just like i386
|
|
|
|
* miniroot scripts, though this may leave a bogus incore label.
|
|
|
|
*
|
|
|
|
* Sun ports should use DISKLABEL_CMD "/sbin/disklabel -w"
|
|
|
|
* to get incore to ondisk inode translation for the Sun proms.
|
|
|
|
*/
|
1999-04-09 14:24:38 +04:00
|
|
|
int write_disklabel (void)
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
1997-11-09 07:14:10 +03:00
|
|
|
|
|
|
|
#ifdef DISKLABEL_CMD
|
1997-09-27 03:02:53 +04:00
|
|
|
/* disklabel the disk */
|
1999-07-05 01:39:33 +04:00
|
|
|
return run_prog(0, 1, MSG_cmdfail,
|
1999-04-09 14:24:38 +04:00
|
|
|
"%s %s %s", DISKLABEL_CMD, diskdev, bsddiskname);
|
1997-11-09 07:14:10 +03:00
|
|
|
#endif
|
1999-04-09 14:24:38 +04:00
|
|
|
return 0;
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
1997-11-02 11:20:40 +03:00
|
|
|
|
|
|
|
|
1999-04-09 14:24:38 +04:00
|
|
|
int make_filesystems(void)
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
|
|
|
int i;
|
1997-11-03 03:04:53 +03:00
|
|
|
char partname[STRSIZE];
|
1999-04-09 14:24:38 +04:00
|
|
|
int error;
|
1997-09-27 03:02:53 +04:00
|
|
|
|
|
|
|
/* Making new file systems and mounting them*/
|
1999-03-31 04:44:48 +04:00
|
|
|
for (i = 0; i < getmaxpartitions(); i++) {
|
1997-11-03 03:04:53 +03:00
|
|
|
/*
|
|
|
|
* newfs and mount. For now, process only BSD filesystems.
|
|
|
|
* but if this is the mounted-on root, don't touch it!
|
|
|
|
*/
|
|
|
|
snprintf(partname, STRSIZE, "%s%c", diskdev, 'a'+i);
|
1999-03-31 04:44:48 +04:00
|
|
|
if (bsdlabel[i].pi_fstype == FS_BSDFFS &&
|
1997-11-03 03:04:53 +03:00
|
|
|
!is_active_rootpart(partname)) {
|
1999-04-09 14:24:38 +04:00
|
|
|
error = do_ffs_newfs(partname, i, fsmount[i]);
|
|
|
|
if (error)
|
|
|
|
return error;
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
1997-11-03 03:04:53 +03:00
|
|
|
}
|
1999-04-09 14:24:38 +04:00
|
|
|
return 0;
|
1997-11-03 03:04:53 +03:00
|
|
|
}
|
1997-09-27 03:02:53 +04:00
|
|
|
|
1997-11-03 03:04:53 +03:00
|
|
|
|
|
|
|
/* newfs and mount an ffs filesystem. */
|
1999-04-09 14:24:38 +04:00
|
|
|
static int
|
1997-11-03 03:04:53 +03:00
|
|
|
do_ffs_newfs(const char *partname, int partno, const char *mountpoint)
|
|
|
|
{
|
1997-11-03 05:38:41 +03:00
|
|
|
char devname[STRSIZE];
|
1999-04-09 14:24:38 +04:00
|
|
|
int error;
|
|
|
|
|
1999-07-05 01:39:33 +04:00
|
|
|
error = run_prog(0, 1, MSG_cmdfail,
|
1999-04-09 14:24:38 +04:00
|
|
|
"/sbin/newfs /dev/r%s", partname);
|
|
|
|
if (*mountpoint && error == 0) {
|
1997-11-03 05:38:41 +03:00
|
|
|
snprintf(devname, STRSIZE, "/dev/%s", partname);
|
1997-11-03 03:04:53 +03:00
|
|
|
if (partno > 0) {
|
|
|
|
make_target_dir(mountpoint);
|
1999-04-09 14:24:38 +04:00
|
|
|
error = target_mount("-v -o async",
|
|
|
|
devname, mountpoint);
|
1997-11-03 03:04:53 +03:00
|
|
|
} else
|
1999-04-09 14:24:38 +04:00
|
|
|
error = target_mount("-v -o async",
|
|
|
|
devname, mountpoint);
|
- Add 2 functions in label.c, getpartoff()/getpartsize() used to let the user
enter partitions offet and size. The user can chose unit independantly of
the unit used for display ('M'/'c'/'s'). These functions do the proper
bound checks and alignement/roudups. Used in the edfspart menu and
i386 md_make_bsd_partitions() (other ports should do the change as
well).
- now that getpartsize() does the rigth thing, kill the swapadj hack (which was
buggy anyway).
- in i386 md_make_bsd_partitions(), don't propose defaults that don't fit on
the disk. If the disk is too small, fallback to custom instead.
- fix a bug in mbr.c, where the partition flags would not have always been
reset. sysinst created me a MBR with 2 active partition. The boot code
doesn't like it :)
- added a message for eventual mount failures.
- killed donewfs and extracting messages, as we run the commands in a
subwindow these messages just flashed on the screen.
- Changes a few exit(1) to return(1), to give the user a second chance.
- added msg_clear() or wclear(stdscr) in a place or two, to make
display a bit nicer.
- in run_cmd(), if the command succeeded, don't wait for the user to
press enter.
1999-04-12 02:40:19 +04:00
|
|
|
if (error) {
|
|
|
|
msg_display(MSG_mountfail, devname, mountpoint);
|
|
|
|
process_menu (MENU_ok);
|
|
|
|
}
|
1997-11-03 03:04:53 +03:00
|
|
|
}
|
1999-04-09 14:24:38 +04:00
|
|
|
return error;
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
1999-04-09 14:24:38 +04:00
|
|
|
int make_fstab(void)
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Create the fstab. */
|
1997-11-02 11:20:40 +03:00
|
|
|
make_target_dir("/etc");
|
1999-03-31 04:44:48 +04:00
|
|
|
f = target_fopen("/etc/fstab", "w");
|
1999-01-21 11:02:17 +03:00
|
|
|
if (logging)
|
|
|
|
(void)fprintf(log, "Creating %s/etc/fstab.\n", target_prefix());
|
|
|
|
if (scripting)
|
|
|
|
(void)fprintf(script, "cat <<EOF >%s/etc/fstab\n", target_prefix());
|
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
if (f == NULL) {
|
|
|
|
#ifndef DEBUG
|
1999-04-09 14:24:38 +04:00
|
|
|
msg_display(MSG_createfstab);
|
1999-01-21 11:02:17 +03:00
|
|
|
if (logging)
|
|
|
|
(void)fprintf(log, "Failed to make /etc/fstab!\n");
|
1999-04-09 14:24:38 +04:00
|
|
|
process_menu(MENU_ok);
|
- Add 2 functions in label.c, getpartoff()/getpartsize() used to let the user
enter partitions offet and size. The user can chose unit independantly of
the unit used for display ('M'/'c'/'s'). These functions do the proper
bound checks and alignement/roudups. Used in the edfspart menu and
i386 md_make_bsd_partitions() (other ports should do the change as
well).
- now that getpartsize() does the rigth thing, kill the swapadj hack (which was
buggy anyway).
- in i386 md_make_bsd_partitions(), don't propose defaults that don't fit on
the disk. If the disk is too small, fallback to custom instead.
- fix a bug in mbr.c, where the partition flags would not have always been
reset. sysinst created me a MBR with 2 active partition. The boot code
doesn't like it :)
- added a message for eventual mount failures.
- killed donewfs and extracting messages, as we run the commands in a
subwindow these messages just flashed on the screen.
- Changes a few exit(1) to return(1), to give the user a second chance.
- added msg_clear() or wclear(stdscr) in a place or two, to make
display a bit nicer.
- in run_cmd(), if the command succeeded, don't wait for the user to
press enter.
1999-04-12 02:40:19 +04:00
|
|
|
return 1;
|
1997-09-27 03:02:53 +04:00
|
|
|
#else
|
|
|
|
f = stdout;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
(void)fprintf (f, "/dev/%sa / ffs rw 1 1\n", diskdev);
|
1999-01-21 11:02:17 +03:00
|
|
|
if (scripting)
|
|
|
|
(void)fprintf (script, "/dev/%sa / ffs rw 1 1\n", diskdev);
|
1997-09-27 03:02:53 +04:00
|
|
|
(void)fprintf (f, "/dev/%sb none swap sw 0 0\n", diskdev);
|
1999-01-21 11:02:17 +03:00
|
|
|
if (scripting)
|
|
|
|
(void)fprintf (script, "/dev/%sb none swap sw 0 0\n", diskdev);
|
1999-03-31 04:44:48 +04:00
|
|
|
for (i = getrawpartition() + 1; i < getmaxpartitions(); i++)
|
|
|
|
if (bsdlabel[i].pi_fstype == FS_BSDFFS) {
|
1997-09-27 03:02:53 +04:00
|
|
|
(void)fprintf (f, "/dev/%s%c %s ffs rw 1 2\n",
|
|
|
|
diskdev, 'a'+i, fsmount[i]);
|
1999-01-21 11:02:17 +03:00
|
|
|
if (scripting)
|
|
|
|
(void)fprintf (script, "/dev/%s%c %s ffs rw 1 2\n",
|
|
|
|
diskdev, 'a'+i, fsmount[i]);
|
1999-03-31 04:44:48 +04:00
|
|
|
} else if (bsdlabel[i].pi_fstype == FS_MSDOS ) {
|
|
|
|
(void)fprintf(f, "/dev/%s%c %s msdos rw 0 0\n",
|
1997-09-27 03:02:53 +04:00
|
|
|
diskdev, 'a'+i, fsmount[i]);
|
1999-01-21 11:02:17 +03:00
|
|
|
if (scripting)
|
1999-03-31 04:44:48 +04:00
|
|
|
(void)fprintf(script, "/dev/%s%c %s msdos rw 0 0\n",
|
1999-01-21 11:02:17 +03:00
|
|
|
diskdev, 'a'+i, fsmount[i]);
|
|
|
|
}
|
1999-03-31 04:44:48 +04:00
|
|
|
(void)fprintf(f, "/kern /kern kernfs rw\n");
|
1999-01-21 11:02:17 +03:00
|
|
|
if (scripting) {
|
1999-03-31 04:44:48 +04:00
|
|
|
(void)fprintf(script, "/kern /kern kernfs rw\n");
|
|
|
|
(void)fprintf(script, "EOF\n");
|
1999-01-21 11:02:17 +03:00
|
|
|
}
|
1997-09-27 03:02:53 +04:00
|
|
|
#ifndef DEBUG
|
|
|
|
fclose(f);
|
1999-01-21 11:02:17 +03:00
|
|
|
fflush(NULL);
|
1997-09-27 03:02:53 +04:00
|
|
|
#endif
|
1997-11-13 06:06:44 +03:00
|
|
|
/* We added /kern to fstab, make mountpoint. */
|
|
|
|
make_target_dir("/kern");
|
1999-04-09 14:24:38 +04:00
|
|
|
return 0;
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
1997-11-13 06:06:44 +03:00
|
|
|
|
1997-10-01 09:04:24 +04:00
|
|
|
/* Get information on the file systems mounted from the root filesystem.
|
|
|
|
* Offer to convert them into 4.4BSD inodes if they are not 4.4BSD
|
|
|
|
* inodes. Fsck them. Mount them.
|
|
|
|
*/
|
|
|
|
|
1997-10-07 08:01:29 +04:00
|
|
|
|
|
|
|
static struct lookfor fstabbuf[] = {
|
1998-10-25 22:15:04 +03:00
|
|
|
{"/dev/", "/dev/%s %s ffs", "c", NULL, 0, 0, foundffs},
|
|
|
|
{"/dev/", "/dev/%s %s ufs", "c", NULL, 0, 0, foundffs},
|
1997-10-01 09:04:24 +04:00
|
|
|
};
|
1997-10-07 08:01:29 +04:00
|
|
|
static int numfstabbuf = sizeof(fstabbuf) / sizeof(struct lookfor);
|
|
|
|
|
|
|
|
#define MAXDEVS 40
|
1997-10-01 09:04:24 +04:00
|
|
|
|
1997-10-07 08:01:29 +04:00
|
|
|
static char dev[MAXDEVS][SSTRSIZE];
|
|
|
|
static char mnt[MAXDEVS][STRSIZE];
|
|
|
|
static int devcnt = 0;
|
|
|
|
|
|
|
|
static void
|
1999-03-31 04:44:48 +04:00
|
|
|
foundffs(struct data *list, int num)
|
1997-10-01 09:04:24 +04:00
|
|
|
{
|
1997-10-07 08:01:29 +04:00
|
|
|
if (strcmp(list[1].u.s_val, "/") != 0) {
|
|
|
|
strncpy(dev[devcnt], list[0].u.s_val, SSTRSIZE);
|
|
|
|
strncpy(mnt[devcnt], list[1].u.s_val, STRSIZE);
|
|
|
|
devcnt++;
|
|
|
|
}
|
1997-10-01 09:04:24 +04:00
|
|
|
}
|
|
|
|
|
1997-10-07 08:01:29 +04:00
|
|
|
static int
|
1999-03-31 04:44:48 +04:00
|
|
|
inode_kind(char *dev)
|
1997-10-07 08:01:29 +04:00
|
|
|
{
|
1999-03-31 04:44:48 +04:00
|
|
|
union {
|
|
|
|
struct fs fs;
|
|
|
|
char pad[SBSIZE];
|
|
|
|
} fs;
|
1997-10-07 08:01:29 +04:00
|
|
|
int fd;
|
|
|
|
int ret;
|
|
|
|
|
1999-03-31 04:44:48 +04:00
|
|
|
fd = open(dev, O_RDONLY, 0);
|
1997-10-07 08:01:29 +04:00
|
|
|
if (fd < 0)
|
|
|
|
return fd;
|
1999-03-31 04:44:48 +04:00
|
|
|
if (lseek(fd, (off_t)SBOFF, SEEK_SET) == (off_t)-1) {
|
|
|
|
close(fd);
|
1997-10-07 08:01:29 +04:00
|
|
|
return -1;
|
1999-03-31 04:44:48 +04:00
|
|
|
}
|
1997-10-07 08:01:29 +04:00
|
|
|
if ((ret = read(fd, &fs, SBSIZE)) != SBSIZE) {
|
1999-03-31 04:44:48 +04:00
|
|
|
close(fd);
|
1997-10-22 19:28:33 +04:00
|
|
|
return -2;
|
1997-10-07 08:01:29 +04:00
|
|
|
}
|
1999-03-31 04:44:48 +04:00
|
|
|
close(fd);
|
1997-10-07 08:01:29 +04:00
|
|
|
if (fs.fs.fs_magic != FS_MAGIC)
|
1997-10-22 19:28:33 +04:00
|
|
|
return -3;
|
1997-10-07 08:01:29 +04:00
|
|
|
if (fs.fs.fs_inodefmt < FS_44INODEFMT)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1997-11-05 10:28:20 +03:00
|
|
|
/*
|
|
|
|
* Do an fsck. For now, assume ffs filesystems.
|
|
|
|
* Returns zero if the fsck completed with no errors.
|
|
|
|
* Returns a negative numbe to indicate a bad inode type,
|
|
|
|
* and a positive non-zero value if exec'ing fsck returns an error.
|
|
|
|
* If the filesystem is an out-of-date version, prompt the user
|
|
|
|
* whether to upgrade the filesystem level.
|
|
|
|
*
|
|
|
|
*/
|
1997-10-07 08:01:29 +04:00
|
|
|
static int
|
1997-11-05 10:28:20 +03:00
|
|
|
do_fsck(const char *diskpart)
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
1997-10-07 08:01:29 +04:00
|
|
|
char raw[SSTRSIZE];
|
|
|
|
int inodetype;
|
|
|
|
char * upgr = "";
|
1997-11-05 10:28:20 +03:00
|
|
|
int err;
|
1997-10-07 08:01:29 +04:00
|
|
|
|
1997-11-05 10:28:20 +03:00
|
|
|
/* cons up raw partition name. */
|
|
|
|
snprintf (raw, SSTRSIZE, "/dev/r%s", diskpart);
|
1997-10-07 08:01:29 +04:00
|
|
|
inodetype = inode_kind (raw);
|
|
|
|
|
|
|
|
if (inodetype < 0) {
|
|
|
|
/* error */
|
1997-10-22 19:28:33 +04:00
|
|
|
return inodetype;
|
1997-10-07 08:01:29 +04:00
|
|
|
}
|
|
|
|
else if (inodetype == 0) {
|
|
|
|
/* Ask to upgrade */
|
1999-03-31 04:44:48 +04:00
|
|
|
msg_display(MSG_upgrinode, raw);
|
|
|
|
process_menu(MENU_yesno);
|
1997-10-07 08:01:29 +04:00
|
|
|
if (yesno)
|
|
|
|
upgr = "-c ";
|
|
|
|
}
|
1997-10-01 09:04:24 +04:00
|
|
|
|
1999-01-21 11:02:17 +03:00
|
|
|
/*endwin();*/
|
2000-05-20 04:45:45 +04:00
|
|
|
#ifndef DEBUG_SETS
|
1999-04-09 14:24:38 +04:00
|
|
|
err = run_prog(0, 1, NULL, "/sbin/fsck_ffs %s%s", upgr, raw);
|
1997-12-05 17:00:59 +03:00
|
|
|
#else
|
1999-04-09 14:24:38 +04:00
|
|
|
err = run_prog(0, 1, NULL, "/sbin/fsck_ffs -f %s%s", upgr, raw);
|
1997-12-05 17:00:59 +03:00
|
|
|
#endif
|
1997-10-07 08:01:29 +04:00
|
|
|
wrefresh(stdscr);
|
1997-11-05 10:28:20 +03:00
|
|
|
return err;
|
1997-10-01 09:04:24 +04:00
|
|
|
}
|
|
|
|
|
1997-11-05 10:28:20 +03:00
|
|
|
/*
|
|
|
|
* Do an fsck. On failure, inform the user by showing a warning
|
|
|
|
* message and doing menu_ok() before proceeding.
|
|
|
|
* acknowledge the warning before continuing.
|
|
|
|
* Returns 0 on success, or nonzero return code from do_fsck() on failure.
|
|
|
|
*/
|
1997-10-01 09:04:24 +04:00
|
|
|
int
|
1997-11-05 10:28:20 +03:00
|
|
|
fsck_with_error_menu(const char *diskpart)
|
1997-11-03 05:38:41 +03:00
|
|
|
{
|
1997-11-05 10:28:20 +03:00
|
|
|
register int error;
|
|
|
|
if ((error = do_fsck (diskpart)) != 0) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, "sysinst: do_fsck() returned err %d\n", error);
|
|
|
|
#endif
|
1999-03-31 04:44:48 +04:00
|
|
|
msg_display(MSG_badfs, diskpart, "", error);
|
|
|
|
process_menu(MENU_ok);
|
1997-10-07 08:01:29 +04:00
|
|
|
}
|
1997-11-05 10:28:20 +03:00
|
|
|
return error;
|
|
|
|
}
|
1997-10-01 09:04:24 +04:00
|
|
|
|
1997-11-05 10:28:20 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Do target_mount, but print a message and do menu_ok() before
|
|
|
|
* proceeding, to inform the user.
|
|
|
|
* returns 0 if the mount completed without indicating errors,
|
|
|
|
* and an nonzero error code from target_mount() otherwise.
|
|
|
|
*/
|
|
|
|
int target_mount_with_error_menu(const char *opt,
|
|
|
|
char *diskpart, const char *mntpoint)
|
|
|
|
{
|
|
|
|
register int error;
|
|
|
|
char devname[STRSIZE];
|
|
|
|
|
|
|
|
snprintf(devname, STRSIZE, "/dev/%s", diskpart);
|
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, "sysinst: mount_with_error_menu: %s %s %s\n",
|
|
|
|
opt, devname, mntpoint);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ((error = target_mount(opt, devname, mntpoint)) != 0) {
|
|
|
|
msg_display (MSG_badmount, devname, "");
|
1997-10-07 08:01:29 +04:00
|
|
|
process_menu (MENU_ok);
|
1997-11-05 10:28:20 +03:00
|
|
|
return error;
|
|
|
|
} else {
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("mount %s %s %s OK\n", opt, diskpart, mntpoint);
|
|
|
|
#endif
|
1997-11-03 05:38:41 +03:00
|
|
|
}
|
1997-11-05 10:28:20 +03:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fsck and mount the root partition.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
fsck_root()
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
char rootdev[STRSIZE];
|
|
|
|
|
|
|
|
/* cons up the root name: partition 'a' on the target diskdev.*/
|
|
|
|
snprintf(rootdev, STRSIZE, "%s%c", diskdev, 'a');
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("fsck_root: rootdev is %s\n", rootdev);
|
|
|
|
#endif
|
|
|
|
error = fsck_with_error_menu(rootdev);
|
|
|
|
if (error != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
if (target_already_root()) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mount /dev/<diskdev>a on target's "".
|
|
|
|
* If we pass "" as mount-on, Prefixing will DTRT.
|
|
|
|
* for now, use no options.
|
|
|
|
* XXX consider -o remount in case target root is
|
|
|
|
* current root, still readonly from single-user?
|
|
|
|
*/
|
|
|
|
error = target_mount_with_error_menu("", rootdev, "");
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("fsck_root: mount of %s returns %d\n", rootdev, error);
|
|
|
|
#endif
|
|
|
|
return (error);
|
1997-11-03 05:38:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1999-03-31 04:44:48 +04:00
|
|
|
fsck_disks(void)
|
1997-11-03 05:38:41 +03:00
|
|
|
{ char *fstab;
|
|
|
|
int fstabsize;
|
|
|
|
int i;
|
1997-11-05 10:28:20 +03:00
|
|
|
int error;
|
1997-11-03 05:38:41 +03:00
|
|
|
|
|
|
|
/* First the root device. */
|
|
|
|
if (!target_already_root()) {
|
1997-11-05 10:28:20 +03:00
|
|
|
error = fsck_root();
|
|
|
|
if (error != 0 && error != EBUSY) {
|
1997-11-03 05:38:41 +03:00
|
|
|
return 0;
|
1997-11-05 10:28:20 +03:00
|
|
|
}
|
1997-10-01 09:04:24 +04:00
|
|
|
}
|
|
|
|
|
1997-11-05 10:28:20 +03:00
|
|
|
/* Check the target /etc/fstab exists before trying to parse it. */
|
1997-12-05 17:00:59 +03:00
|
|
|
if (target_dir_exists_p("/etc") == 0 ||
|
|
|
|
target_file_exists_p("/etc/fstab") == 0) {
|
1997-11-05 10:28:20 +03:00
|
|
|
msg_display(MSG_noetcfstab, diskdev);
|
|
|
|
process_menu(MENU_ok);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-03 05:38:41 +03:00
|
|
|
/* Get fstab entries from the target-root /etc/fstab. */
|
1999-03-31 04:44:48 +04:00
|
|
|
fstabsize = target_collect_file(T_FILE, &fstab, "/etc/fstab");
|
1997-10-01 09:04:24 +04:00
|
|
|
if (fstabsize < 0) {
|
|
|
|
/* error ! */
|
1997-11-05 10:28:20 +03:00
|
|
|
msg_display(MSG_badetcfstab, diskdev);
|
|
|
|
process_menu(MENU_ok);
|
1997-10-01 09:04:24 +04:00
|
|
|
return 0;
|
|
|
|
}
|
1999-03-31 04:44:48 +04:00
|
|
|
walk(fstab, fstabsize, fstabbuf, numfstabbuf);
|
1997-10-01 09:04:24 +04:00
|
|
|
free(fstab);
|
|
|
|
|
1999-03-31 04:44:48 +04:00
|
|
|
for (i = 0; i < devcnt; i++) {
|
1997-11-05 10:28:20 +03:00
|
|
|
if (fsck_with_error_menu(dev[i]))
|
1997-10-07 08:01:29 +04:00
|
|
|
return 0;
|
1997-11-05 10:28:20 +03:00
|
|
|
|
1997-12-05 17:00:59 +03:00
|
|
|
#ifdef DEBUG
|
1997-11-05 10:28:20 +03:00
|
|
|
printf("sysinst: mount %s\n", dev[i]);
|
1997-12-05 17:00:59 +03:00
|
|
|
#endif
|
1997-11-05 10:28:20 +03:00
|
|
|
if (target_mount_with_error_menu("", dev[i], mnt[i]) != 0) {
|
1997-10-07 08:01:29 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-01 09:04:24 +04:00
|
|
|
return 1;
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
2000-09-27 16:42:04 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
set_swap(dev, pp, enable)
|
|
|
|
const char *dev;
|
|
|
|
partinfo *pp;
|
|
|
|
{
|
|
|
|
partinfo parts[16];
|
|
|
|
int i, maxpart;
|
|
|
|
|
|
|
|
if (pp == NULL) {
|
|
|
|
emptylabel(parts);
|
|
|
|
if (incorelabel(dev, parts) < 0)
|
|
|
|
return -1;
|
|
|
|
pp = parts;
|
|
|
|
}
|
|
|
|
|
|
|
|
maxpart = getmaxpartitions();
|
|
|
|
|
|
|
|
for (i = 0; i < maxpart; i++) {
|
|
|
|
if (pp[i].pi_fstype == FS_SWAP) {
|
|
|
|
if (run_prog(0, 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|