[BACK]Return to disks.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / distrib / utils / sysinst

Annotation of src/distrib/utils/sysinst/disks.c, Revision 1.39

1.39    ! mrg         1: /*     $NetBSD: disks.c,v 1.38 2000/12/06 04:53:37 mrg Exp $ */
1.1       phil        2:
                      3: /*
                      4:  * Copyright 1997 Piermont Information Systems Inc.
                      5:  * All rights reserved.
                      6:  *
                      7:  * Written by Philip A. Nelson for Piermont Information Systems Inc.
                      8:  *
                      9:  * Redistribution and use in source and binary forms, with or without
                     10:  * modification, are permitted provided that the following conditions
                     11:  * are met:
                     12:  * 1. Redistributions of source code must retain the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer.
                     14:  * 2. Redistributions in binary form must reproduce the above copyright
                     15:  *    notice, this list of conditions and the following disclaimer in the
                     16:  *    documentation and/or other materials provided with the distribution.
                     17:  * 3. All advertising materials mentioning features or use of this software
                     18:  *    must display the following acknowledgement:
1.27      cgd        19:  *      This product includes software developed for the NetBSD Project by
1.1       phil       20:  *      Piermont Information Systems Inc.
                     21:  * 4. The name of Piermont Information Systems Inc. may not be used to endorse
                     22:  *    or promote products derived from this software without specific prior
                     23:  *    written permission.
                     24:  *
                     25:  * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
                     26:  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     27:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     28:  * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
                     29:  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     30:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     31:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     32:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     33:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     34:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
                     35:  * THE POSSIBILITY OF SUCH DAMAGE.
                     36:  *
                     37:  */
                     38:
                     39: /* disks.c -- routines to deal with finding disks and labeling disks. */
                     40:
                     41:
1.11      jonathan   42: #include <errno.h>
1.1       phil       43: #include <stdio.h>
                     44: #include <stdlib.h>
1.3       phil       45: #include <unistd.h>
                     46: #include <fcntl.h>
1.9       jonathan   47: #include <util.h>
1.3       phil       48:
                     49: #include <sys/param.h>
                     50: #include <ufs/ufs/dinode.h>
                     51: #include <ufs/ffs/fs.h>
                     52:
1.1       phil       53: #include "defs.h"
1.6       phil       54: #include "md.h"
1.1       phil       55: #include "msg_defs.h"
                     56: #include "menu_defs.h"
                     57: #include "txtwalk.h"
                     58:
1.11      jonathan   59:
1.8       jonathan   60:
1.2       phil       61: /* Local prototypes */
1.4       phil       62: static void get_disks (void);
1.3       phil       63: static void foundffs (struct data *list, int num);
1.11      jonathan   64: static int do_fsck(const char *diskpart);
1.39    ! mrg        65: static int fsck_root (void);
1.24      bouyer     66: static int
1.9       jonathan   67:     do_ffs_newfs(const char *partname, int part, const char *mountpoint);
1.2       phil       68:
1.11      jonathan   69: static int fsck_with_error_menu(const char *diskpart);
                     70: static int target_mount_with_error_menu(const char *opt, char *diskpart,
                     71:                                        const char *mntpt);
                     72:
1.8       jonathan   73:
1.38      mrg        74: static void
                     75: get_disks(void)
1.4       phil       76: {
1.6       phil       77:        char **xd = disk_names;
1.4       phil       78:        char d_name[SSTRSIZE];
                     79:        struct disklabel l;
                     80:        int i;
                     81:
                     82:        while (*xd != NULL) {
1.18      jonathan   83:                for (i=0; i< MAX_DISKS; i++) {
1.23      fvdl       84:                        snprintf(d_name, SSTRSIZE, "%s%d", *xd, i);
                     85:                        if (get_geom(d_name, &l) && numdisks < MAX_DISKS) {
1.22      fvdl       86:                                strncpy (disks[numdisks].dd_name,
1.4       phil       87:                                         d_name, SSTRSIZE);
                     88:                                strncat (disknames, d_name,
                     89:                                         SSTRSIZE-1-strlen(disknames));
                     90:                                strncat (disknames, " ",
                     91:                                         SSTRSIZE-1-strlen(disknames));
1.22      fvdl       92:                                disks[numdisks].dd_cyl = l.d_ncylinders;
                     93:                                disks[numdisks].dd_head = l.d_ntracks;
                     94:                                disks[numdisks].dd_sec = l.d_nsectors;
                     95:                                disks[numdisks].dd_secsize = l.d_secsize;
                     96:                                disks[numdisks].dd_totsec = l.d_secperunit;
1.4       phil       97:                                numdisks++;
                     98:                        }
                     99:                }
                    100:                xd++;
1.3       phil      101:        }
                    102: }
1.4       phil      103:
1.3       phil      104:
1.38      mrg       105: int
                    106: find_disks(void)
1.1       phil      107: {
                    108:        char *tp;
1.3       phil      109:        char defname[STRSIZE];
                    110:        int  i;
1.1       phil      111:
                    112:        /* initialize */
                    113:        disknames[0] = 0;
                    114:        numdisks = 0;
                    115:
1.4       phil      116:        /* Find disks. */
                    117:        get_disks();
1.1       phil      118:
1.20      garbled   119:        /* need a redraw here, kernel messages hose everything */
                    120:        touchwin(stdscr);
                    121:        refresh();
                    122:
1.1       phil      123:        if (numdisks == 0) {
                    124:                /* No disks found! */
1.23      fvdl      125:                msg_display(MSG_nodisk);
                    126:                process_menu(MENU_ok);
1.20      garbled   127:                /*endwin();*/
1.1       phil      128:                return -1;
                    129:        } else if (numdisks == 1) {
                    130:                /* One disk found! */
                    131:                /* Remove that space we added. */
                    132:                disknames[strlen(disknames)-1] = 0;
1.23      fvdl      133:                msg_display(MSG_onedisk, disknames, doingwhat);
                    134:                process_menu(MENU_ok);
                    135:                strcpy(diskdev, disknames);
1.1       phil      136:        } else {
                    137:                /* Multiple disks found! */
1.23      fvdl      138:                strcpy(defname, disknames);
1.1       phil      139:                tp = defname;
                    140:                strsep(&tp, " ");
1.23      fvdl      141:                msg_prompt(MSG_askdisk, defname,  diskdev, 10, disknames);
1.1       phil      142:                tp = diskdev;
                    143:                strsep(&tp, " ");
                    144:                diskdev[strlen(diskdev)+1] = 0;
                    145:                diskdev[strlen(diskdev)] = ' ';
1.6       phil      146:                while (!ISDISKSTART(*diskdev) ||
1.1       phil      147:                       strstr(disknames, diskdev) == NULL) {
1.23      fvdl      148:                        msg_prompt(MSG_badname, defname,  diskdev, 10,
1.1       phil      149:                                    disknames);
                    150:                        tp = diskdev;
                    151:                        strsep(&tp, " ");
                    152:                        diskdev[strlen(diskdev)+1] = 0;
                    153:                        diskdev[strlen(diskdev)] = ' ';
                    154:                }
                    155:
                    156:                /* Remove that space we added. */
                    157:                diskdev[strlen(diskdev)-1] = 0;
                    158:        }
                    159:
1.3       phil      160:        /* Set disk. */
1.23      fvdl      161:        for (i = 0; i < numdisks; i++)
1.22      fvdl      162:                if (strcmp(diskdev, disks[i].dd_name) == 0)
1.3       phil      163:                        disk = &disks[i];
                    164:
1.22      fvdl      165:        sectorsize = disk->dd_secsize;
                    166:        if (disk->dd_totsec == 0)
                    167:                disk->dd_totsec = disk->dd_cyl * disk->dd_head * disk->dd_sec;
1.23      fvdl      168:        dlcyl = disk->dd_cyl;
                    169:        dlhead = disk->dd_head;
                    170:        dlsec = disk->dd_sec;
                    171:        dlsize = disk->dd_totsec;
                    172:        dlcylsize = dlhead * dlsec;
1.1       phil      173:
                    174:        return numdisks;
                    175: }
                    176:
                    177:
1.38      mrg       178: void
                    179: disp_cur_fspart(int disp, int showall)
1.1       phil      180: {
                    181:        int i;
                    182:        int start, stop;
1.19      simonb    183:        int poffset, psize, pend;
1.1       phil      184:
                    185:        if (disp < 0) {
                    186:                start = 0;
1.9       jonathan  187:                stop = getmaxpartitions();
1.1       phil      188:        } else {
                    189:                start = disp;
                    190:                stop = disp+1;
                    191:        }
                    192:
1.28      cgd       193:        msg_table_add (MSG_fspart_header);
1.23      fvdl      194:        for (i = start; i < stop; i++) {
                    195:                if (showall || bsdlabel[i].pi_size > 0) {
                    196:                        poffset = bsdlabel[i].pi_offset / sizemult;
                    197:                        psize = bsdlabel[i].pi_size / sizemult;
1.19      simonb    198:                        if (psize == 0)
                    199:                                pend = 0;
                    200:                        else
1.23      fvdl      201:                                pend = (bsdlabel[i].pi_offset +
                    202:                                bsdlabel[i].pi_size) / sizemult - 1;
1.28      cgd       203:                        msg_table_add(MSG_fspart_row_start,
1.19      simonb    204:                                        'a'+i, psize, poffset, pend,
1.23      fvdl      205:                                        fstypenames[bsdlabel[i].pi_fstype]);
                    206:                        if (bsdlabel[i].pi_fstype == FS_BSDFFS)
1.28      cgd       207:                                msg_table_add(MSG_fspart_row_end_bsd,
1.23      fvdl      208:                                                bsdlabel[i].pi_bsize,
                    209:                                                bsdlabel[i].pi_fsize,
1.1       phil      210:                                                fsmount[i]);
1.23      fvdl      211:                        else if (bsdlabel[i].pi_fstype == FS_MSDOS)
1.28      cgd       212:                                msg_table_add(MSG_fspart_row_end_msdos,
                    213:                                                fsmount[i]);
                    214:                        else
                    215:                                msg_table_add(MSG_fspart_row_end_other);
1.1       phil      216:                }
                    217:        }
1.30      cgd       218:        msg_display_add(MSG_newline);
1.1       phil      219: }
                    220:
1.13      jonathan  221: /*
                    222:  * Label a disk using an MD-specific string DISKLABEL_CMD for
                    223:  * to invoke  disklabel.
                    224:  * if MD code does not define DISKLABEL_CMD, this is a no-op.
                    225:  *
                    226:  * i386  port uses "/sbin/disklabel -w -r", just like i386
                    227:  * miniroot scripts, though this may leave a bogus incore label.
                    228:  *
                    229:  * Sun ports should use  DISKLABEL_CMD "/sbin/disklabel -w"
                    230:  * to get incore  to ondisk inode translation for the Sun proms.
                    231:  */
1.38      mrg       232: int
                    233: write_disklabel (void)
1.1       phil      234: {
1.13      jonathan  235:
                    236: #ifdef DISKLABEL_CMD
1.1       phil      237:        /* disklabel the disk */
1.33      fvdl      238:        return run_prog(RUN_DISPLAY, MSG_cmdfail,
1.24      bouyer    239:            "%s %s %s", DISKLABEL_CMD, diskdev, bsddiskname);
1.13      jonathan  240: #endif
1.24      bouyer    241:        return 0;
1.1       phil      242: }
                    243:
1.38      mrg       244: int
                    245: make_filesystems(void)
1.1       phil      246: {
                    247:        int i;
1.9       jonathan  248:        char partname[STRSIZE];
1.24      bouyer    249:        int error;
1.1       phil      250:
                    251:        /* Making new file systems and mounting them*/
1.23      fvdl      252:        for (i = 0; i < getmaxpartitions(); i++) {
1.9       jonathan  253:                /*
                    254:                 * newfs and mount. For now, process only BSD filesystems.
                    255:                 * but if this is the  mounted-on root, don't touch it!
                    256:                 */
                    257:                snprintf(partname, STRSIZE, "%s%c", diskdev, 'a'+i);
1.23      fvdl      258:                if (bsdlabel[i].pi_fstype == FS_BSDFFS &&
1.9       jonathan  259:                    !is_active_rootpart(partname)) {
1.24      bouyer    260:                        error = do_ffs_newfs(partname, i, fsmount[i]);
                    261:                        if (error)
                    262:                                return error;
1.1       phil      263:                }
1.9       jonathan  264:        }
1.24      bouyer    265:        return 0;
1.9       jonathan  266: }
1.1       phil      267:
1.9       jonathan  268: /* newfs and mount an ffs filesystem. */
1.24      bouyer    269: static int
1.9       jonathan  270: do_ffs_newfs(const char *partname, int partno, const char *mountpoint)
                    271: {
1.10      jonathan  272:        char devname[STRSIZE];
1.24      bouyer    273:        int error;
                    274:
1.33      fvdl      275:        error = run_prog(RUN_DISPLAY, MSG_cmdfail,
1.24      bouyer    276:            "/sbin/newfs /dev/r%s", partname);
                    277:        if (*mountpoint && error == 0) {
1.10      jonathan  278:                snprintf(devname, STRSIZE, "/dev/%s", partname);
1.9       jonathan  279:                if (partno > 0) {
                    280:                        make_target_dir(mountpoint);
1.24      bouyer    281:                        error = target_mount("-v -o async",
                    282:                            devname, mountpoint);
1.9       jonathan  283:                } else
1.24      bouyer    284:                        error = target_mount("-v -o async",
                    285:                            devname, mountpoint);
1.25      bouyer    286:                if (error) {
                    287:                        msg_display(MSG_mountfail, devname, mountpoint);
                    288:                        process_menu (MENU_ok);
                    289:                }
1.9       jonathan  290:        }
1.24      bouyer    291:        return error;
1.1       phil      292: }
                    293:
1.38      mrg       294: int
                    295: make_fstab(void)
1.1       phil      296: {
                    297:        FILE *f;
                    298:        int i;
                    299:
                    300:        /* Create the fstab. */
1.8       jonathan  301:        make_target_dir("/etc");
1.23      fvdl      302:        f = target_fopen("/etc/fstab", "w");
1.20      garbled   303:        if (logging)
                    304:                (void)fprintf(log, "Creating %s/etc/fstab.\n", target_prefix());
                    305:        if (scripting)
                    306:                (void)fprintf(script, "cat <<EOF >%s/etc/fstab\n", target_prefix());
                    307:
1.1       phil      308:        if (f == NULL) {
                    309: #ifndef DEBUG
1.24      bouyer    310:                msg_display(MSG_createfstab);
1.20      garbled   311:                if (logging)
                    312:                        (void)fprintf(log, "Failed to make /etc/fstab!\n");
1.24      bouyer    313:                process_menu(MENU_ok);
1.25      bouyer    314:                return 1;
1.1       phil      315: #else
                    316:                f = stdout;
                    317: #endif
                    318:        }
                    319:        (void)fprintf (f, "/dev/%sa / ffs rw 1 1\n", diskdev);
1.20      garbled   320:        if (scripting)
                    321:                (void)fprintf (script, "/dev/%sa / ffs rw 1 1\n", diskdev);
1.1       phil      322:        (void)fprintf (f, "/dev/%sb none swap sw 0 0\n", diskdev);
1.20      garbled   323:        if (scripting)
                    324:                (void)fprintf (script, "/dev/%sb none swap sw 0 0\n", diskdev);
1.23      fvdl      325:        for (i = getrawpartition() + 1; i < getmaxpartitions(); i++)
                    326:                if (bsdlabel[i].pi_fstype == FS_BSDFFS) {
1.1       phil      327:                        (void)fprintf (f, "/dev/%s%c %s ffs rw 1 2\n",
                    328:                                       diskdev, 'a'+i, fsmount[i]);
1.20      garbled   329:                        if (scripting)
                    330:                                (void)fprintf (script, "/dev/%s%c %s ffs rw 1 2\n",
                    331:                                        diskdev, 'a'+i, fsmount[i]);
1.23      fvdl      332:                } else if (bsdlabel[i].pi_fstype == FS_MSDOS ) {
                    333:                        (void)fprintf(f, "/dev/%s%c %s msdos rw 0 0\n",
1.1       phil      334:                                       diskdev, 'a'+i, fsmount[i]);
1.20      garbled   335:                        if (scripting)
1.23      fvdl      336:                                (void)fprintf(script, "/dev/%s%c %s msdos rw 0 0\n",
1.20      garbled   337:                                        diskdev, 'a'+i, fsmount[i]);
                    338:                }
1.23      fvdl      339:        (void)fprintf(f, "/kern /kern kernfs rw\n");
1.20      garbled   340:        if (scripting) {
1.23      fvdl      341:                (void)fprintf(script, "/kern /kern kernfs rw\n");
                    342:                (void)fprintf(script, "EOF\n");
1.20      garbled   343:        }
1.1       phil      344: #ifndef DEBUG
                    345:        fclose(f);
1.20      garbled   346:        fflush(NULL);
1.1       phil      347: #endif
1.14      jonathan  348:        /* We added /kern to fstab,  make mountpoint. */
                    349:        make_target_dir("/kern");
1.24      bouyer    350:        return 0;
1.1       phil      351: }
1.14      jonathan  352:
1.1       phil      353:
1.2       phil      354: /* Get information on the file systems mounted from the root filesystem.
                    355:  * Offer to convert them into 4.4BSD inodes if they are not 4.4BSD
                    356:  * inodes.  Fsck them.  Mount them.
                    357:  */
                    358:
1.3       phil      359:
                    360: static struct lookfor fstabbuf[] = {
1.37      fvdl      361:        {"/dev/", "/dev/%s %s ffs %s", "c", NULL, 0, 0, foundffs},
                    362:        {"/dev/", "/dev/%s %s ufs %s", "c", NULL, 0, 0, foundffs},
1.2       phil      363: };
1.3       phil      364: static int numfstabbuf = sizeof(fstabbuf) / sizeof(struct lookfor);
                    365:
                    366: #define MAXDEVS 40
                    367:
                    368: static char dev[MAXDEVS][SSTRSIZE];
                    369: static char mnt[MAXDEVS][STRSIZE];
                    370: static int  devcnt = 0;
1.2       phil      371:
1.3       phil      372: static void
1.23      fvdl      373: foundffs(struct data *list, int num)
1.3       phil      374: {
1.37      fvdl      375:        if (strcmp(list[1].u.s_val, "/") != 0 &&
                    376:            strstr(list[2].u.s_val, "noauto") == NULL) {
1.3       phil      377:                strncpy(dev[devcnt], list[0].u.s_val, SSTRSIZE);
                    378:                strncpy(mnt[devcnt], list[1].u.s_val, STRSIZE);
                    379:                devcnt++;
                    380:        }
                    381: }
                    382:
                    383: static int
1.23      fvdl      384: inode_kind(char *dev)
1.2       phil      385: {
1.23      fvdl      386:        union {
                    387:                struct fs fs;
                    388:                char pad[SBSIZE];
                    389:        } fs;
1.3       phil      390:        int fd;
                    391:        int ret;
                    392:
1.23      fvdl      393:        fd = open(dev, O_RDONLY, 0);
1.3       phil      394:        if (fd < 0)
                    395:                return fd;
1.23      fvdl      396:         if (lseek(fd, (off_t)SBOFF, SEEK_SET) == (off_t)-1) {
                    397:                close(fd);
1.3       phil      398:                 return -1;
1.23      fvdl      399:        }
1.3       phil      400:         if ((ret = read(fd, &fs, SBSIZE)) != SBSIZE) {
1.23      fvdl      401:                close(fd);
1.5       phil      402:                 return -2;
1.3       phil      403:        }
1.23      fvdl      404:        close(fd);
1.3       phil      405:        if (fs.fs.fs_magic != FS_MAGIC)
1.5       phil      406:                return -3;
1.3       phil      407:        if (fs.fs.fs_inodefmt < FS_44INODEFMT)
                    408:                return 0;
                    409:        return 1;
1.2       phil      410: }
                    411:
1.11      jonathan  412: /*
                    413:  * Do an fsck. For now, assume ffs filesystems.
                    414:  * Returns zero if the fsck completed with no errors.
                    415:  * Returns a negative numbe to indicate a bad inode type,
                    416:  * and a positive  non-zero value  if exec'ing fsck returns an error.
                    417:  * If the filesystem is an out-of-date version, prompt the user
                    418:  * whether to upgrade the filesystem  level.
                    419:  *
                    420:  */
1.3       phil      421: static int
1.11      jonathan  422: do_fsck(const char *diskpart)
1.2       phil      423: {
1.3       phil      424:        char raw[SSTRSIZE];
                    425:        int inodetype;
                    426:        char * upgr = "";
1.11      jonathan  427:        int err;
1.3       phil      428:
1.11      jonathan  429:        /* cons up raw partition name. */
                    430:        snprintf (raw, SSTRSIZE, "/dev/r%s", diskpart);
1.3       phil      431:        inodetype = inode_kind (raw);
                    432:
                    433:        if (inodetype < 0) {
                    434:                /* error */
1.5       phil      435:                return inodetype;
1.3       phil      436:        }
                    437:        else if (inodetype == 0) {
                    438:                /* Ask to upgrade */
1.23      fvdl      439:                msg_display(MSG_upgrinode, raw);
                    440:                process_menu(MENU_yesno);
1.3       phil      441:                if (yesno)
1.36      fvdl      442:                        upgr = "-c 3 ";
1.3       phil      443:        }
1.2       phil      444:
1.20      garbled   445:        /*endwin();*/
1.31      wiz       446: #ifndef        DEBUG_SETS
1.33      fvdl      447:        err = run_prog(RUN_DISPLAY, NULL, "/sbin/fsck_ffs %s%s", upgr, raw);
1.16      jonathan  448: #else
1.33      fvdl      449:        err = run_prog(RUN_DISPLAY, NULL, "/sbin/fsck_ffs -f %s%s", upgr, raw);
1.16      jonathan  450: #endif
1.3       phil      451:                wrefresh(stdscr);
1.11      jonathan  452:        return err;
1.2       phil      453: }
                    454:
1.11      jonathan  455: /*
                    456:  * Do an fsck. On failure,  inform the user by showing a warning
                    457:  * message and doing menu_ok() before proceeding.
                    458:  * acknowledge the warning before continuing.
                    459:  * Returns 0 on success, or nonzero return code from do_fsck() on failure.
                    460:  */
1.2       phil      461: int
1.11      jonathan  462: fsck_with_error_menu(const char *diskpart)
1.10      jonathan  463: {
1.11      jonathan  464:        register int error;
                    465:        if ((error = do_fsck (diskpart)) != 0) {
                    466: #ifdef DEBUG
                    467:                fprintf(stderr, "sysinst: do_fsck() returned err %d\n", error);
                    468: #endif
1.23      fvdl      469:                msg_display(MSG_badfs, diskpart, "", error);
                    470:                process_menu(MENU_ok);
1.3       phil      471:        }
1.11      jonathan  472:        return error;
                    473: }
                    474:
1.2       phil      475:
1.11      jonathan  476: /*
                    477:  * Do target_mount, but print a message and do menu_ok() before
                    478:  * proceeding, to inform the user.
                    479:  * returns 0 if  the mount completed without indicating errors,
                    480:  *  and an nonzero error code from target_mount() otherwise.
                    481:  */
                    482: int target_mount_with_error_menu(const char *opt,
                    483:                 char *diskpart, const char *mntpoint)
                    484: {
                    485:        register int error;
                    486:        char devname[STRSIZE];
                    487:
                    488:        snprintf(devname, STRSIZE, "/dev/%s", diskpart);
                    489: #ifdef DEBUG
                    490:        fprintf(stderr, "sysinst: mount_with_error_menu: %s %s %s\n",
                    491:                opt, devname, mntpoint);
                    492: #endif
                    493:
                    494:        if ((error = target_mount(opt, devname, mntpoint)) != 0) {
                    495:                msg_display (MSG_badmount, devname, "");
1.3       phil      496:                process_menu (MENU_ok);
1.11      jonathan  497:                return error;
                    498:        } else {
                    499: #ifdef DEBUG
                    500:          printf("mount %s %s %s OK\n", opt, diskpart, mntpoint);
                    501: #endif
1.10      jonathan  502:        }
1.11      jonathan  503:
                    504:        return error;
                    505: }
                    506:
                    507: /*
                    508:  * fsck and mount the root partition.
                    509:  */
                    510: int
                    511: fsck_root()
                    512: {
                    513:        int   error;
                    514:        char    rootdev[STRSIZE];
                    515:
                    516:        /* cons up the root name:  partition 'a' on the target diskdev.*/
                    517:        snprintf(rootdev, STRSIZE, "%s%c", diskdev, 'a');
                    518: #ifdef DEBUG
                    519:        printf("fsck_root: rootdev is %s\n", rootdev);
                    520: #endif
                    521:        error = fsck_with_error_menu(rootdev);
                    522:        if (error != 0)
                    523:                return error;
                    524:
                    525:        if (target_already_root()) {
                    526:                return (0);
                    527:        }
                    528:
                    529:        /* Mount /dev/<diskdev>a on  target's "".
                    530:         * If we pass "" as mount-on, Prefixing will DTRT.
                    531:         * for now, use no options.
                    532:         * XXX consider -o remount in case target root is
                    533:         * current root, still  readonly from single-user?
                    534:         */
                    535:        error = target_mount_with_error_menu("", rootdev, "");
                    536:
                    537: #ifdef DEBUG
                    538:        printf("fsck_root: mount of %s returns %d\n", rootdev, error);
                    539: #endif
                    540:        return (error);
1.10      jonathan  541: }
                    542:
                    543: int
1.23      fvdl      544: fsck_disks(void)
1.10      jonathan  545: {      char *fstab;
                    546:        int   fstabsize;
                    547:        int   i;
1.11      jonathan  548:        int   error;
1.10      jonathan  549:
                    550:        /* First the root device. */
                    551:        if (!target_already_root()) {
1.11      jonathan  552:                error = fsck_root();
                    553:                if (error != 0 && error != EBUSY) {
1.10      jonathan  554:                        return 0;
1.11      jonathan  555:                }
1.2       phil      556:        }
                    557:
1.11      jonathan  558:        /* Check the target /etc/fstab exists before trying to parse it. */
1.16      jonathan  559:        if (target_dir_exists_p("/etc") == 0 ||
                    560:            target_file_exists_p("/etc/fstab") == 0) {
1.11      jonathan  561:                msg_display(MSG_noetcfstab, diskdev);
                    562:                process_menu(MENU_ok);
                    563:                return 0;
                    564:        }
                    565:
                    566:
1.10      jonathan  567:        /* Get fstab entries from the target-root /etc/fstab. */
1.23      fvdl      568:        fstabsize = target_collect_file(T_FILE, &fstab, "/etc/fstab");
1.2       phil      569:        if (fstabsize < 0) {
                    570:                /* error ! */
1.11      jonathan  571:                msg_display(MSG_badetcfstab, diskdev);
                    572:                process_menu(MENU_ok);
1.2       phil      573:                return 0;
                    574:        }
1.23      fvdl      575:        walk(fstab, fstabsize, fstabbuf, numfstabbuf);
1.2       phil      576:        free(fstab);
                    577:
1.23      fvdl      578:        for (i = 0; i < devcnt; i++) {
1.11      jonathan  579:                if (fsck_with_error_menu(dev[i]))
1.3       phil      580:                        return 0;
1.11      jonathan  581:
1.16      jonathan  582: #ifdef DEBUG
1.11      jonathan  583:                printf("sysinst: mount %s\n", dev[i]);
1.16      jonathan  584: #endif
1.11      jonathan  585:                if (target_mount_with_error_menu("", dev[i], mnt[i]) != 0) {
1.3       phil      586:                        return 0;
                    587:                }
                    588:        }
                    589:
1.2       phil      590:        return 1;
1.32      fvdl      591: }
                    592:
                    593: int
                    594: set_swap(dev, pp, enable)
                    595:        const char *dev;
                    596:        partinfo *pp;
                    597: {
                    598:        partinfo parts[16];
                    599:        int i, maxpart;
                    600:
                    601:        if (pp == NULL) {
                    602:                emptylabel(parts);
                    603:                if (incorelabel(dev, parts) < 0)
                    604:                        return -1;
                    605:                pp = parts;
                    606:        }
                    607:
                    608:        maxpart = getmaxpartitions();
                    609:
                    610:        for (i = 0; i < maxpart; i++) {
                    611:                if (pp[i].pi_fstype == FS_SWAP) {
1.33      fvdl      612:                        if (run_prog(0, NULL,
1.32      fvdl      613:                            "/sbin/swapctl -%c /dev/%s%c",
                    614:                            enable ? 'a' : 'd', dev, 'a' + i) != 0)
                    615:                                return -1;
                    616:                        if (enable)
                    617:                                strcpy(swapdev, dev);
                    618:                        else
                    619:                                swapdev[0] = '\0';
                    620:                        break;
                    621:                }
                    622:        }
                    623:
                    624:        return 0;
1.1       phil      625: }

CVSweb <webmaster@jp.NetBSD.org>