Home | History | Annotate | Line # | Download | only in x68k
md.c revision 1.4.14.1
      1  1.4.14.1  pgoyette /*	$NetBSD: md.c,v 1.4.14.1 2018/05/21 04:36:20 pgoyette Exp $ */
      2       1.1  dholland 
      3       1.1  dholland /*
      4       1.1  dholland  * Copyright 1997 Piermont Information Systems Inc.
      5       1.1  dholland  * All rights reserved.
      6       1.1  dholland  *
      7       1.1  dholland  * Based on code written by Philip A. Nelson for Piermont Information
      8       1.1  dholland  * Systems Inc.  Modified by Minoura Makoto for x68k.
      9       1.1  dholland  *
     10       1.1  dholland  * Redistribution and use in source and binary forms, with or without
     11       1.1  dholland  * modification, are permitted provided that the following conditions
     12       1.1  dholland  * are met:
     13       1.1  dholland  * 1. Redistributions of source code must retain the above copyright
     14       1.1  dholland  *    notice, this list of conditions and the following disclaimer.
     15       1.1  dholland  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1  dholland  *    notice, this list of conditions and the following disclaimer in the
     17       1.1  dholland  *    documentation and/or other materials provided with the distribution.
     18       1.1  dholland  * 3. The name of Piermont Information Systems Inc. may not be used to endorse
     19       1.1  dholland  *    or promote products derived from this software without specific prior
     20       1.1  dholland  *    written permission.
     21       1.1  dholland  *
     22       1.1  dholland  * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
     23       1.1  dholland  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24       1.1  dholland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25       1.1  dholland  * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
     26       1.1  dholland  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     27       1.1  dholland  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     28       1.1  dholland  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     29       1.1  dholland  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     30       1.1  dholland  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     31       1.1  dholland  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     32       1.1  dholland  * THE POSSIBILITY OF SUCH DAMAGE.
     33       1.1  dholland  */
     34       1.1  dholland 
     35       1.1  dholland /* md.c -- x68k machine specific routines */
     36       1.1  dholland /* This file is in close sync with pmax, sparc, and vax md.c */
     37       1.1  dholland 
     38       1.1  dholland #include <stdio.h>
     39       1.1  dholland #include <unistd.h>
     40       1.1  dholland #include <sys/disklabel.h>
     41       1.1  dholland #include <sys/ioctl.h>
     42       1.1  dholland #include <sys/param.h>
     43       1.1  dholland #include <util.h>
     44       1.1  dholland 
     45       1.1  dholland #include "defs.h"
     46       1.1  dholland #include "md.h"
     47       1.1  dholland #include "msg_defs.h"
     48       1.1  dholland #include "menu_defs.h"
     49       1.1  dholland 
     50       1.1  dholland #ifdef notyet
     51       1.1  dholland #undef NDOSPART 8
     52       1.1  dholland #define NDOSPART 16
     53       1.1  dholland typedef struct parttab {
     54       1.1  dholland 	struct dos_partition dosparts[NDOSPART];
     55       1.1  dholland } parttab;
     56       1.1  dholland 
     57       1.1  dholland parttab md_disklabel;
     58       1.1  dholland int md_freepart;
     59       1.1  dholland int md_nfreepart;
     60       1.1  dholland #endif /* notyet */
     61       1.1  dholland 
     62       1.1  dholland int md_need_newdisk = 0;
     63       1.1  dholland 
     64       1.1  dholland /* prototypes */
     65       1.1  dholland static int md_newdisk(void);
     66       1.1  dholland 
     67       1.1  dholland void
     68       1.1  dholland md_init(void)
     69       1.1  dholland {
     70       1.1  dholland }
     71       1.1  dholland 
     72       1.1  dholland void
     73       1.1  dholland md_init_set_status(int flags)
     74       1.1  dholland {
     75       1.1  dholland 	(void)flags;
     76       1.1  dholland }
     77       1.1  dholland 
     78       1.1  dholland int
     79       1.1  dholland md_get_info(void)
     80       1.1  dholland {
     81       1.1  dholland 	char buf[1024];
     82       1.1  dholland 	int fd;
     83       1.1  dholland 	char dev_name[100];
     84       1.1  dholland 	struct disklabel disklabel;
     85       1.1  dholland 
     86       1.2    martin 	snprintf(dev_name, 100, "/dev/r%sc", pm->diskdev);
     87       1.1  dholland 
     88       1.1  dholland 	fd = open(dev_name, O_RDONLY, 0);
     89       1.1  dholland 	if (fd < 0) {
     90       1.1  dholland 		if (logfp)
     91       1.1  dholland 			(void)fprintf(logfp, "Can't open %s\n", dev_name);
     92       1.1  dholland 		endwin();
     93       1.1  dholland 		fprintf(stderr, "Can't open %s\n", dev_name);
     94       1.1  dholland 		exit(1);
     95       1.1  dholland 	}
     96       1.1  dholland 	if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
     97       1.1  dholland 		if (logfp)
     98       1.1  dholland 			(void)fprintf(logfp, "Can't read disklabel on %s.\n",
     99       1.1  dholland 				dev_name);
    100       1.1  dholland 		endwin();
    101       1.1  dholland 		fprintf(stderr, "Can't read disklabel on %s.\n", dev_name);
    102       1.1  dholland 		close(fd);
    103       1.1  dholland 		exit(1);
    104       1.1  dholland 	}
    105       1.1  dholland 	if (disklabel.d_secsize != 512) {
    106       1.1  dholland 		endwin();
    107       1.1  dholland 		fprintf(stderr, "Non-512byte/sector disk is not supported.\n");
    108       1.1  dholland 		close(fd);
    109       1.1  dholland 		exit(1);
    110       1.1  dholland 	}
    111       1.1  dholland 
    112       1.2    martin 	pm->dlcyl = disklabel.d_ncylinders;
    113       1.2    martin 	pm->dlhead = disklabel.d_ntracks;
    114       1.2    martin 	pm->dlsec = disklabel.d_nsectors;
    115       1.2    martin 	pm->sectorsize = disklabel.d_secsize;
    116       1.2    martin 	pm->dlcylsize = disklabel.d_secpercyl;
    117       1.2    martin 	pm->dlsize = pm->dlcyl*pm->dlhead*pm->dlsec;
    118       1.1  dholland 
    119       1.1  dholland 	if (read(fd, buf, 1024) < 0) {
    120       1.1  dholland 		endwin();
    121       1.1  dholland 		fprintf(stderr, "Can't read %s\n", dev_name);
    122       1.1  dholland 		close(fd);
    123       1.1  dholland 		exit(1);
    124       1.1  dholland 	}
    125       1.1  dholland 	if (memcmp(buf, "X68SCSI1", 8) != 0)
    126       1.1  dholland 		md_need_newdisk = 1;
    127       1.1  dholland #ifdef notyet
    128       1.1  dholland 	else
    129       1.1  dholland 		if (read(fd, md_disklabel, sizeof(md_disklabel)) < 0) {
    130       1.1  dholland 			endwin();
    131       1.1  dholland 			fprintf(stderr, "Can't read %s\n", dev_name);
    132       1.1  dholland 			close(fd);
    133       1.1  dholland 			exit(1);
    134       1.1  dholland 		}
    135       1.1  dholland #endif
    136       1.1  dholland 	/* preserve first 64 sectors for system. */
    137       1.2    martin 	pm->ptstart = 64;
    138       1.1  dholland 
    139       1.1  dholland 	/* preserve existing partitions? */
    140       1.1  dholland 
    141       1.1  dholland 	close(fd);
    142       1.1  dholland 
    143       1.1  dholland 	return 1;
    144       1.1  dholland }
    145       1.1  dholland 
    146       1.1  dholland /*
    147       1.1  dholland  * md back-end code for menu-driven BSD disklabel editor.
    148       1.1  dholland  */
    149       1.1  dholland int
    150       1.1  dholland md_make_bsd_partitions(void)
    151       1.1  dholland {
    152       1.1  dholland 	return(make_bsd_partitions());
    153       1.1  dholland }
    154       1.1  dholland 
    155       1.1  dholland /*
    156       1.1  dholland  * any additional partition validation
    157       1.1  dholland  */
    158       1.1  dholland int
    159       1.1  dholland md_check_partitions(void)
    160       1.1  dholland {
    161       1.1  dholland 	/* X68k partitions must be in order of the range. */
    162       1.1  dholland 	int part, last = PART_A-1;
    163       1.1  dholland 	uint32_t start = 0;
    164       1.1  dholland 
    165       1.1  dholland 	for (part = PART_A; part < 8; part++) {
    166       1.1  dholland 		if (part == PART_C)
    167       1.1  dholland 			continue;
    168       1.2    martin 		if (last >= PART_A && pm->bsdlabel[part].pi_size > 0) {
    169       1.1  dholland 			msg_display(MSG_emptypart, part+'a');
    170       1.1  dholland 			process_menu(MENU_ok, NULL);
    171       1.1  dholland 			return 0;
    172       1.1  dholland 		}
    173       1.2    martin 		if (pm->bsdlabel[part].pi_size == 0) {
    174       1.1  dholland 			if (last < PART_A)
    175       1.1  dholland 				last = part;
    176       1.1  dholland 		} else {
    177       1.2    martin 			if (start >= pm->bsdlabel[part].pi_offset) {
    178       1.1  dholland 				msg_display(MSG_ordering, part+'a');
    179       1.4    martin 				if (ask_yesno(NULL))
    180       1.1  dholland 					return 0;
    181       1.1  dholland 			}
    182       1.2    martin 			start = pm->bsdlabel[part].pi_offset;
    183       1.1  dholland 		}
    184       1.1  dholland 	}
    185       1.1  dholland 
    186       1.1  dholland 	return 1;
    187       1.1  dholland }
    188       1.1  dholland 
    189       1.1  dholland #ifdef notyet
    190       1.1  dholland static int
    191       1.1  dholland md_check_partitions(void)
    192       1.1  dholland {
    193       1.1  dholland 	int i, j;
    194       1.1  dholland 	int preserve;
    195       1.1  dholland 
    196       1.1  dholland 	/* check existing BSD partitions. */
    197       1.1  dholland 	for (i = 0; i < NDOSPART; i++) {
    198       1.1  dholland 		if (md_disklabel.dosparts[i].dp_size == 0)
    199       1.1  dholland 			break;
    200       1.1  dholland 		if (memcmp(md_disklabel.dosparts[i].dp_typename, "Human68k", 8)) {
    201       1.1  dholland 			msg_display(MSG_existing);
    202       1.4    martin 			preserve = ask_noyes(NULL);
    203       1.1  dholland 			break;
    204       1.1  dholland 		}
    205       1.1  dholland 	}
    206       1.2    martin 	emptylabel(pm->bsdlabel);
    207       1.2    martin 	pm->bsdlabel[C].pi_fstype = FS_UNUSED;
    208       1.2    martin 	pm->bsdlabel[C].pi_offset = 0;
    209       1.2    martin 	pm->bsdlabel[C].pi_size = pm->dlsize;
    210       1.1  dholland 	for (i = 0, j = A; i < NDOSPART;) {
    211       1.1  dholland 		if (j == C) {
    212       1.1  dholland 			j++;
    213       1.1  dholland 			continue;
    214       1.1  dholland 		}
    215       1.1  dholland 		if (!preserve &&
    216       1.1  dholland 		    memcmp(md_disklabel.dosparts[i].dp_typename,
    217       1.1  dholland 			    "Human68k", 8)) {
    218       1.1  dholland 			/* discard it. */
    219       1.1  dholland 			i++;
    220       1.1  dholland 			continue;
    221       1.1  dholland 		}
    222       1.2    martin 		pm->bsdlabel[j].pi_fstype = (i == 1) ? FS_SWAP : FS_BSDFFS;
    223       1.2    martin 		pm->bsdlabel[j].pi_offset = md_disklabel.dosparts[i].dp_start*2;
    224       1.2    martin 		pm->bsdlabel[j].pi_size = md_disklabel.dosparts[i].dp_size*2;
    225       1.1  dholland 		i++;
    226       1.1  dholland 		j++;
    227       1.1  dholland 	}
    228       1.1  dholland 	if (j > 6) {
    229       1.2    martin 		msg_display(MSG_nofreepart, pm->diskdev);
    230       1.1  dholland 		return 0;
    231       1.1  dholland 	}
    232       1.1  dholland 	md_nfreepart = 8 - j;
    233       1.1  dholland 
    234       1.1  dholland 	/* check for free space */
    235       1.2    martin 	fspm->ptsize = pm->bsdlabel[A].pi_offset - 64;
    236       1.2    martin 	if (fpm->ptsize <= 0) {	/* XXX: should not be 0; minfsdb?  */
    237       1.2    martin 		msg_display(MSG_notfirst, pm->diskdev);
    238       1.1  dholland 		process_menu(MENU_ok);
    239       1.1  dholland 		exit(1);
    240       1.1  dholland 	}
    241       1.1  dholland 
    242       1.1  dholland 	/* Partitions should be preserved in md_make_bsdpartitions() */
    243       1.1  dholland }
    244       1.1  dholland #endif /* notyet */
    245       1.1  dholland 
    246       1.1  dholland /*
    247       1.1  dholland  * hook called before writing new disklabel.
    248       1.1  dholland  */
    249       1.1  dholland int
    250       1.1  dholland md_pre_disklabel(void)
    251       1.1  dholland {
    252       1.1  dholland 	if (md_need_newdisk)
    253       1.1  dholland 		md_newdisk ();
    254       1.1  dholland 	return 0;
    255       1.1  dholland }
    256       1.1  dholland 
    257       1.1  dholland /*
    258       1.1  dholland  * hook called after writing disklabel to new target disk.
    259       1.1  dholland  */
    260       1.1  dholland int
    261       1.1  dholland md_post_disklabel(void)
    262       1.1  dholland {
    263       1.1  dholland 	return 0;
    264       1.1  dholland }
    265       1.1  dholland 
    266       1.1  dholland /*
    267       1.1  dholland  * hook called after upgrade() or install() has finished setting
    268       1.1  dholland  * up the target disk but immediately before the user is given the
    269       1.1  dholland  * ``disks are now set up'' message.
    270       1.1  dholland  *
    271       1.1  dholland  * On the x68k, we use this opportunity to install the boot blocks.
    272       1.1  dholland  */
    273       1.1  dholland int
    274       1.1  dholland md_post_newfs(void)
    275       1.1  dholland {
    276       1.1  dholland 	/* boot blocks ... */
    277       1.2    martin 	msg_display(MSG_dobootblks, pm->diskdev);
    278       1.1  dholland 	cp_to_target("/usr/mdec/boot", "/boot");
    279       1.1  dholland 	if (run_program(RUN_DISPLAY | RUN_NO_CLEAR,
    280       1.1  dholland 	    "/usr/mdec/installboot.new /usr/mdec/sdboot_ufs /dev/r%sa",
    281       1.2    martin 	    pm->diskdev))
    282       1.1  dholland 		process_menu(MENU_ok,
    283  1.4.14.1  pgoyette 			__UNCONST("Warning: disk is probably not bootable"));
    284       1.1  dholland 	return 0;
    285       1.1  dholland }
    286       1.1  dholland 
    287       1.1  dholland int
    288       1.1  dholland md_post_extract(void)
    289       1.1  dholland {
    290       1.1  dholland 	return 0;
    291       1.1  dholland }
    292       1.1  dholland 
    293       1.1  dholland void
    294       1.1  dholland md_cleanup_install(void)
    295       1.1  dholland {
    296       1.1  dholland #ifndef DEBUG
    297       1.1  dholland 	enable_rc_conf();
    298       1.1  dholland #endif
    299       1.1  dholland }
    300       1.1  dholland 
    301       1.1  dholland int
    302       1.1  dholland md_pre_update(void)
    303       1.1  dholland {
    304       1.1  dholland 	return 1;
    305       1.1  dholland }
    306       1.1  dholland 
    307       1.1  dholland /* Upgrade support */
    308       1.1  dholland int
    309       1.1  dholland md_update(void)
    310       1.1  dholland {
    311       1.1  dholland 	md_post_newfs();
    312       1.1  dholland 	return 1;
    313       1.1  dholland }
    314       1.1  dholland 
    315       1.1  dholland static int
    316       1.1  dholland md_newdisk(void)
    317       1.1  dholland {
    318       1.2    martin 	msg_display(MSG_newdisk, pm->diskdev, pm->diskdev);
    319       1.1  dholland 
    320       1.1  dholland 	return run_program(RUN_FATAL|RUN_DISPLAY,
    321       1.2    martin 	    "/usr/mdec/newdisk -v %s", pm->diskdev);
    322       1.1  dholland }
    323       1.1  dholland 
    324       1.1  dholland 
    325       1.1  dholland int
    326       1.1  dholland md_pre_mount()
    327       1.1  dholland {
    328       1.1  dholland 	return 0;
    329       1.1  dholland }
    330