Ejemplo 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);
}
Ejemplo n.º 2
0
static int
check_one_root(partinfo *lp, int nparts)
{
	int part;
	int foundroot = 0;

	for (part = 0; part < nparts; lp++, part++) {
#if 0
		if (!PI_ISBSDFS(lp))
			continue;
#endif
		if (!(lp->pi_flags & PIF_MOUNT))
			continue;
		if (strcmp(lp->pi_mount, "/") != 0)
			continue;
		if (foundroot)
			/* Duplicate */
			return 0;
		foundroot = 1;
		/* Save partition number, a few things need to know it */
		pm->rootpart = part;
	}
	return foundroot;
}
Ejemplo n.º 3
0
/*
 * md back-end code for menu-driven BSD disklabel editor.
 */
int
md_make_bsd_partitions(void)
{
    int i;
    int part;
    int maxpart = getmaxpartitions();
    int partstart;
    int part_raw, part_bsd;
    int ptend;
    int no_swap = 0;
    partinfo *p;

    /*
     * Initialize global variables that track space used on this disk.
     * Standard 4.4BSD 8-partition labels always cover whole disk.
     */
    if (ptsize == 0)
        ptsize = dlsize - ptstart;
    if (dlsize == 0)
        dlsize = ptstart + ptsize;

    partstart = ptstart;
    ptend = ptstart + ptsize;

    /* Ask for layout type -- standard or special */
    msg_display(MSG_layout,
                ptsize / (MEG / sectorsize),
                DEFROOTSIZE + DEFSWAPSIZE + DEFUSRSIZE,
                DEFROOTSIZE + DEFSWAPSIZE + DEFUSRSIZE + XNEEDMB);

    process_menu(MENU_layout, NULL);

    /* Set so we use the 'real' geometry for rounding, input in MB */
    current_cylsize = dlcylsize;
    set_sizemultname_meg();

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

    /* Set initial partition types to unused */
    for (part = 0 ; part < maxpart ; ++part)
        bsdlabel[part].pi_fstype = FS_UNUSED;

    /* Whole disk partition */
    part_raw = getrawpartition();
    if (part_raw == -1)
        part_raw = PART_C;	/* for sanity... */
    bsdlabel[part_raw].pi_offset = 0;
    bsdlabel[part_raw].pi_size = dlsize;

    if (part_raw == PART_D) {
        /* Probably a system that expects an i386 style mbr */
        part_bsd = PART_C;
        bsdlabel[PART_C].pi_offset = ptstart;
        bsdlabel[PART_C].pi_size = ptsize;
    } else {
        part_bsd = part_raw;
    }

    if (bootsize != 0) {
        bsdlabel[PART_BOOT_FAT12].pi_fstype = FS_MSDOS;
        bsdlabel[PART_BOOT_FAT12].pi_size = bootsize;
        bsdlabel[PART_BOOT_FAT12].pi_offset = bootstart;
        bsdlabel[PART_BOOT_FAT12].pi_flags |= PART_BOOT_FAT12_PI_FLAGS;
        strlcpy(bsdlabel[PART_BOOT_FAT12].pi_mount,
                PART_BOOT_FAT12_PI_MOUNT,
                sizeof bsdlabel[PART_BOOT_FAT12].pi_mount);
    }

#ifdef PART_REST
    bsdlabel[PART_REST].pi_offset = 0;
    bsdlabel[PART_REST].pi_size = ptstart;
#endif

    /*
     * Save any partitions that are outside the area we are
     * going to use.
     * In particular this saves details of the other MBR
     * partitions on a multiboot i386 system.
     */
    for (i = maxpart; i--;) {
        if (bsdlabel[i].pi_size != 0)
            /* Don't overwrite special partitions */
            continue;
        p = &oldlabel[i];
        if (p->pi_fstype == FS_UNUSED || p->pi_size == 0)
            continue;
        if (layoutkind == 4) {
            if (PI_ISBSDFS(p))
                p->pi_flags |= PIF_MOUNT;
        } else {
            if (p->pi_offset < ptstart + ptsize &&
                    p->pi_offset + p->pi_size > ptstart)
                /* Not outside area we are allocating */
                continue;
            if (p->pi_fstype == FS_SWAP)
                no_swap = 1;
        }
        bsdlabel[i] = oldlabel[i];
    }

    if (layoutkind == 4) {
        /* XXX Check we have a sensible layout */
        ;
    } else
        get_ptn_sizes(partstart, ptend - partstart, no_swap);

    /*
     * OK, we have a partition table. Give the user the chance to
     * edit it and verify it's OK, or abort altogether.
     */
edit_check:
    if (edit_and_check_label(bsdlabel, maxpart, part_raw, part_bsd) == 0) {
        msg_display(MSG_abort);
        return 0;
    }
    if (md_check_partitions() == 0)
        goto edit_check;

    /* Disk name */
    msg_prompt(MSG_packname, bsddiskname, bsddiskname, sizeof bsddiskname);

    /* save label to disk for MI code to update. */
    (void)savenewlabel(bsdlabel, maxpart);

    /* Everything looks OK. */
    return 1;
}