Exemplo n.º 1
0
int
/*ARGSUSED*/
savenewlabel(partinfo *lp, int nparts)
{
	FILE *f;
	int i;

	/*
	  N.B. disklabels only support up to 2TB (32-bit field for sectors).
	  This function explicitly narrows from daddr_t (64-bit unsigned) to
	  uint32_t when writing the disklabel.
	 */

	/* Create /etc/disktab */
	f = fopen("/tmp/disktab", "w");
	if (logfp)
		(void)fprintf(logfp, "Creating disklabel %s\n", bsddiskname);
	scripting_fprintf(NULL, "cat <<EOF >>/etc/disktab\n");
	if (f == NULL) {
		endwin();
		(void)fprintf(stderr, "Could not open /etc/disktab");
		if (logfp)
			(void)fprintf(logfp,
			    "Failed to open /etc/disktab for appending.\n");
		exit (1);
	}
	scripting_fprintf(f, "%s|NetBSD installation generated:\\\n", bsddiskname);
	scripting_fprintf(f, "\t:dt=%s:ty=winchester:\\\n", disktype);
	scripting_fprintf(f, "\t:nc#%d:nt#%d:ns#%d:\\\n", dlcyl, dlhead, dlsec);
	scripting_fprintf(f, "\t:sc#%d:su#%" PRIu32 ":\\\n", dlhead*dlsec,
	    (uint32_t)dlsize);
	scripting_fprintf(f, "\t:se#%d:%s\\\n", sectorsize, doessf);
	if ((size_t)nparts > __arraycount(bsdlabel)) {
		nparts = __arraycount(bsdlabel);
		if (logfp)
			(void)fprintf(logfp, "nparts limited to %d.\n", nparts);
	}
	for (i = 0; i < nparts; i++) {
		scripting_fprintf(f, "\t:p%c#%" PRIu32 ":o%c#%" PRIu32
		    ":t%c=%s:", 'a'+i, (uint32_t)bsdlabel[i].pi_size,
		    'a'+i, (uint32_t)bsdlabel[i].pi_offset, 'a'+i,
		    getfslabelname(bsdlabel[i].pi_fstype));
		if (PI_ISBSDFS(&bsdlabel[i]))
			scripting_fprintf (f, "b%c#%" PRIu32 ":f%c#%" PRIu32
			    ":", 'a'+i,
			    (uint32_t)(bsdlabel[i].pi_fsize *
			    bsdlabel[i].pi_frag),
			    'a'+i, (uint32_t)bsdlabel[i].pi_fsize);
	
		if (i < nparts - 1)
			scripting_fprintf(f, "\\\n");
		else
			scripting_fprintf(f, "\n");
	}
	fclose (f);
	scripting_fprintf(NULL, "EOF\n");
	fflush(NULL);
	return(0);
}
Exemplo n.º 2
0
static void
set_ptn_label(menudesc *m, int opt, void *arg)
{
	partinfo *p = arg;
	const char *c;

	if (m->opts[opt].opt_flags & OPT_IGNORE
	    && (opt != PTN_MENU_END || p->pi_fstype == FS_UNUSED)) {
		wprintw(m->mw, "            -");
		return;
	}

	switch (opt) {
	case PTN_MENU_FSKIND:
		if (p->pi_fstype == FS_BSDFFS)
			if (p->pi_flags & PIF_FFSv2)
				c = "FFSv2";
			else
				c = "FFSv1";
		else
			c = getfslabelname(p->pi_fstype);
		wprintw(m->mw, msg_string(MSG_fstype_fmt), c);
		break;
	case PTN_MENU_START:
		disp_sector_count(m, MSG_start_fmt, p->pi_offset);
		break;
	case PTN_MENU_SIZE:
		disp_sector_count(m, MSG_size_fmt, p->pi_size);
		break;
	case PTN_MENU_END:
		disp_sector_count(m, MSG_end_fmt, p->pi_offset + p->pi_size);
		break;
	case PTN_MENU_NEWFS:
		wprintw(m->mw, msg_string(MSG_newfs_fmt),
			msg_string(p->pi_flags & PIF_NEWFS ? MSG_Yes : MSG_No));
		break;
	case PTN_MENU_ISIZE:
		wprintw(m->mw, msg_string(p->pi_isize > 0 ?
			MSG_isize_fmt : MSG_isize_fmt_dflt), p->pi_isize);
		break;
	case PTN_MENU_BSIZE:
		wprintw(m->mw, msg_string(MSG_bsize_fmt),
			p->pi_fsize * p->pi_frag);
		break;
	case PTN_MENU_FSIZE:
		wprintw(m->mw, msg_string(MSG_fsize_fmt), p->pi_fsize);
		break;
	case PTN_MENU_MOUNT:
		wprintw(m->mw, msg_string(MSG_mount_fmt),
			msg_string(p->pi_flags & PIF_MOUNT ? MSG_Yes : MSG_No));
		break;
	case PTN_MENU_MOUNTOPT:
		wprintw(m->mw, "%s", msg_string(MSG_mount_options_fmt));
		if (p->pi_flags & PIF_ASYNC)
			wprintw(m->mw, "async ");
		if (p->pi_flags & PIF_NOATIME)
			wprintw(m->mw, "noatime ");
		if (p->pi_flags & PIF_NODEV)
			wprintw(m->mw, "nodev ");
		if (p->pi_flags & PIF_NODEVMTIME)
			wprintw(m->mw, "nodevmtime ");
		if (p->pi_flags & PIF_NOEXEC)
			wprintw(m->mw, "noexec ");
		if (p->pi_flags & PIF_NOSUID)
			wprintw(m->mw, "nosuid ");
		if (p->pi_flags & PIF_LOG)
			wprintw(m->mw, "log ");
		break;
	case PTN_MENU_MOUNTPT:
		wprintw(m->mw, msg_string(MSG_mountpt_fmt), p->pi_mount);
		break;
	}
}
Exemplo n.º 3
0
/*
 * md back-end code for menu-driven BSD disklabel editor.
 */
int
md_make_bsd_partitions(void)
{
	FILE *f;
	int i, j, pl;
	EBZB *bzb;

	/*
	 * Scan for any problems and report them before continuing.
	 *  The user can abort installation and we'll take them back
	 *  to the main menu; continue ignoring the warnings, or
	 *  ask to reedit the Disk Partition Map.
	 */
	while (1) {
	    if (check_for_errors()) {
	        process_menu (MENU_sanity, NULL);
	        if (yesno < 0)
		    return 0;
	        else if (yesno)
		    break;
	        edit_diskmap();
	    } else
		break;
	}

	/* Build standard partitions */
	memset(&bsdlabel, 0, sizeof bsdlabel);

	/*
	 * The mac68k port has a predefined partition for "c" which
	 *  is the size of the disk, everything else is unused.
	 */
	bsdlabel[RAW_PART].pi_size = dlsize;
	/*
	 * Now, scan through the Disk Partition Map and transfer the
	 *  information into the incore disklabel.
	 */
	for (i=0;i<map.usable_cnt;i++) {
	    j = map.mblk[i];
	    bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
	    if (bzb->flags.part) {
		pl = bzb->flags.part - 'a';
		switch (whichType(&map.blk[j])) {
		    case HFS_PART:
			bsdlabel[pl].pi_fstype = FS_HFS;
			strcpy (bsdlabel[pl].pi_mount, (char *)bzb->mount_point);
			break;
		    case ROOT_PART:
		    case UFS_PART:
			bsdlabel[pl].pi_fstype = FS_BSDFFS;
			strcpy (bsdlabel[pl].pi_mount, (char *)bzb->mount_point);
			bsdlabel[pl].pi_flags |= PIF_NEWFS | PIF_MOUNT;
			break;
		    case SWAP_PART:
			bsdlabel[pl].pi_fstype = FS_SWAP;
			break;
		    case SCRATCH_PART:
			bsdlabel[pl].pi_fstype = FS_OTHER;
			strcpy (bsdlabel[pl].pi_mount, (char *)bzb->mount_point);
		    default:
			break;
		}
	        if (bsdlabel[pl].pi_fstype != FS_UNUSED) {
		    bsdlabel[pl].pi_size = map.blk[j].pmPartBlkCnt;
		    bsdlabel[pl].pi_offset = map.blk[j].pmPyPartStart;
		    if (bsdlabel[pl].pi_fstype != FS_SWAP) {
		        bsdlabel[pl].pi_frag = 8;
		        bsdlabel[pl].pi_fsize = 1024;
		    }
		}
	    }
	}

	/* Disk name  - don't bother asking, just use the physical name*/
	strcpy (bsddiskname, diskdev);

#ifdef DEBUG
	f = fopen ("/tmp/disktab", "w");
#else
	f = fopen ("/etc/disktab", "w");
#endif
	if (f == NULL) {
		endwin();
		(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#%" PRIu32 ":\\\n", dlhead*dlsec, (uint32_t)dlsize);
	(void)fprintf (f, "\t:se#%d:%s\\\n", blk_size, doessf);
	for (i=0; i<8; i++) {
		if (bsdlabel[i].pi_fstype == FS_HFS)
		    (void)fprintf (f, "\t:p%c#%d:o%c#%d:t%c=macos:",
			       'a'+i, bsdlabel[i].pi_size,
			       'a'+i, bsdlabel[i].pi_offset,
			       'a'+i);
		else
		    (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, getfslabelname(bsdlabel[i].pi_fstype));
		if (bsdlabel[i].pi_fstype == FS_BSDFFS)
			(void)fprintf (f, "b%c#%d:f%c#%d",
			   'a'+i, bsdlabel[i].pi_fsize * bsdlabel[i].pi_frag,
			   'a'+i, bsdlabel[i].pi_fsize);
		if (i < 7)
			(void)fprintf (f, "\\\n");
		else
			(void)fprintf (f, "\n");
	}
	fclose (f);

	/* Everything looks OK. */
	return 1;
}
Exemplo n.º 4
0
int
edit_ptn(menudesc *menu, void *arg)
{
	static menu_ent fs_fields[] = {
#define PTN_MENU_FSKIND		0
	    {NULL, MENU_selfskind, OPT_SUB, NULL},
#define PTN_MENU_START		1
	    {NULL, OPT_NOMENU, 0, edit_fs_start},
#define PTN_MENU_SIZE		2
	    {NULL, OPT_NOMENU, 0, edit_fs_size},
#define PTN_MENU_END		3
	    {NULL, OPT_NOMENU, OPT_IGNORE, NULL},	/* displays 'end' */
#define PTN_MENU_NEWFS		4
	    {NULL, OPT_NOMENU, 0, edit_fs_preserve},
#define PTN_MENU_ISIZE		5
	    {NULL, OPT_NOMENU, 0, edit_fs_isize},
#define PTN_MENU_BSIZE		6
	    {NULL, MENU_selbsize, OPT_SUB, NULL},
#define PTN_MENU_FSIZE		7
	    {NULL, MENU_selfsize, OPT_SUB, NULL},
#define PTN_MENU_MOUNT		8
	    {NULL, OPT_NOMENU, 0, edit_fs_mount},
#define PTN_MENU_MOUNTOPT	9
	    {NULL, MENU_mountoptions, OPT_SUB, NULL},
#define PTN_MENU_MOUNTPT	10
	    {NULL, OPT_NOMENU, 0, edit_fs_mountpt},
	    {MSG_askunits, MENU_sizechoice, OPT_SUB, NULL},
	    {MSG_restore, OPT_NOMENU, 0, edit_restore},
	};
	static int fspart_menu = -1;
	static menu_ent all_fstypes[FSMAXTYPES];
	partinfo *p, p_save;
	unsigned int i;

	if (fspart_menu == -1) {
		fspart_menu = new_menu(NULL, fs_fields, nelem(fs_fields),
			0, -1, 0, 70,
			MC_NOBOX | MC_NOCLEAR | MC_SCROLL,
			set_ptn_header, set_ptn_label, NULL,
			NULL, MSG_partition_sizes_ok);
	}

	if (all_fstype_menu == -1) {
		for (i = 0; i < nelem(all_fstypes); i++) {
			all_fstypes[i].opt_name = getfslabelname(i);
			all_fstypes[i].opt_menu = OPT_NOMENU;
			all_fstypes[i].opt_flags = 0;
			all_fstypes[i].opt_action = set_fstype;
		}
		all_fstype_menu = new_menu(MSG_Select_the_type,
			all_fstypes, nelem(all_fstypes),
			30, 6, 10, 0, MC_SUBMENU | MC_SCROLL,
			get_fstype, NULL, NULL, NULL, MSG_unchanged);
	}

	p = pm->bsdlabel + menu->cursel;
	p->pi_flags &= ~PIF_RESET;
	p_save = *p;
	for (;;) {
		process_menu(fspart_menu, p);
		if (!(p->pi_flags & PIF_RESET))
			break;
		*p = p_save;
	}

	return 0;
}