diff options
author | phk <phk@FreeBSD.org> | 1994-11-01 10:10:43 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 1994-11-01 10:10:43 +0000 |
commit | 79436024c142d153a12cdf9995b92ea23ad02615 (patch) | |
tree | 3f6ff700acaa2869e5e6ea33e48b639db10f1d2f /sbin | |
parent | 8a9b63d2771180b6ef1c3e66ad93bf3c39a6381e (diff) | |
download | FreeBSD-src-79436024c142d153a12cdf9995b92ea23ad02615.zip FreeBSD-src-79436024c142d153a12cdf9995b92ea23ad02615.tar.gz |
Public apology:
I have walked all over Paul Richards code again, and severely lobotomized
some of his stuff, in order to cut some corners for the 2.0-Alpha release.
I belive that we can now manipulate fdisk and disklabel-stuff sufficiently
for the release to actually be produced.
It's not that I don't like Paul and his code, I just need something I
can kick out of the door RSN.
Sysinstall is now under absolute code-freeze, only Jordan has my permission
to commit to this code (stage0 & 5). I would appreciate if everybody
else would finds problems in sysinstall send patches to me, and I will
commit them. THANKYOU.
The fdisk/disklabel editors are made in pure ncurses, and follow a model
"a`la spreadsheet".
There are some important functions which are missing still, and I would
appreciate if somebody would look at them.
The FDISK part needs a "whole-disk" option, and it needs a "rewrite
MBR-boot code" option.
The DISKLABEL part needs to be able to "import DOS-partition".
Both need a "HELP" function, (display a file "/HELP" using dialog is OK).
It seems to me like the wd.c and sd.c should reread the physical record
when a DIOCGDINFO is made, so that they can pick up changes in the
MBR-data. Otherwise there will be a couple of weird cases where we
cannot avoid replicating code from the kernel.
If you want to play with this, look at src/release/Makefile. You may need
to step back to version 1.38 of sys/i386/isa/fd.c to make "rootable"
floppies, it is not clear at this time if that indeed is the problem I
have been having.
Sleep well, my friends, and expect the real Alpha in 24H, if the tree is
still solid.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/sysinstall/Makefile | 4 | ||||
-rw-r--r-- | sbin/sysinstall/bootarea.c | 147 | ||||
-rw-r--r-- | sbin/sysinstall/bootarea.h | 4 | ||||
-rw-r--r-- | sbin/sysinstall/label.c | 399 | ||||
-rw-r--r-- | sbin/sysinstall/main.c | 41 | ||||
-rw-r--r-- | sbin/sysinstall/mbr.c | 250 | ||||
-rw-r--r-- | sbin/sysinstall/mbr.h | 3 | ||||
-rw-r--r-- | sbin/sysinstall/ourcurses.c | 170 | ||||
-rw-r--r-- | sbin/sysinstall/stage0.c | 8 | ||||
-rw-r--r-- | sbin/sysinstall/stage1.c | 117 | ||||
-rw-r--r-- | sbin/sysinstall/stage2.c | 181 | ||||
-rw-r--r-- | sbin/sysinstall/sysinstall.h | 48 | ||||
-rw-r--r-- | sbin/sysinstall/utils.c | 62 |
13 files changed, 965 insertions, 469 deletions
diff --git a/sbin/sysinstall/Makefile b/sbin/sysinstall/Makefile index 677bb62..da04863 100644 --- a/sbin/sysinstall/Makefile +++ b/sbin/sysinstall/Makefile @@ -6,9 +6,9 @@ NOMAN= yet SRCS = bootarea.c exec.c dkcksum.c label.c main.c mbr.c \ stage0.c stage1.c stage2.c stage3.c stage4.c stage5.c \ - termcap.c utils.c makedevs.c + termcap.c utils.c makedevs.c ourcurses.c -CFLAGS += -Wall +CFLAGS += -Wall -g -static LDADD = -ldialog -lncurses -lmytinfo DPADD = ${LIBDIALOG} ${LIBNCURSES} ${LIBMYTINFO} diff --git a/sbin/sysinstall/bootarea.c b/sbin/sysinstall/bootarea.c index ec9c37c..399f7ae 100644 --- a/sbin/sysinstall/bootarea.c +++ b/sbin/sysinstall/bootarea.c @@ -31,115 +31,100 @@ extern struct mbr *mbr; extern char boot1[]; extern char boot2[]; -int +void enable_label(int fd) { int flag = 1; - if (ioctl(fd, DIOCWLABEL, &flag) < 0) { - return(-1); - } - return(0); + if (ioctl(fd, DIOCWLABEL, &flag) < 0) + Fatal("ioctl(DIOCWLABEL,1) failed: %s",strerror(errno)); } -int +void disable_label(int fd) { int flag = 0; - if (ioctl(fd, DIOCWLABEL, &flag) < 0) { - return(-1); - } - return(0); + if (ioctl(fd, DIOCWLABEL, &flag) < 0) + Fatal("ioctl(DIOCWLABEL,0) failed: %s",strerror(errno)); } int -write_bootblocks(int fd, off_t offset, int bbsize) +write_bootblocks(int fd, struct disklabel *lbl) { - if (ioctl(fd, DIOCWDINFO, &avail_disklabels[inst_disk]) < 0) { - Fatal("Failed to write disklabel: %s\n", strerror(errno)); - return(-1); - } - - Debug("Seeking to block %ld ", offset); - Debug("Seeking to byte %ld ", (offset * avail_disklabels[inst_disk].d_secsize)); - if (lseek(fd, (offset * avail_disklabels[inst_disk].d_secsize), SEEK_SET) < 0) { - sprintf(errmsg, "Couldn't seek to start of partition\n"); - return(-1); - } - - if (enable_label(fd) == -1) - return(-1); - - if (write(fd, bootblocks, bbsize) != bbsize) { - sprintf(errmsg, "Failed to write bootblocks (%p,%d) %d %s\n", - bootblocks, bbsize, - errno, strerror(errno) - ); - return(-1); - } - - if (disable_label(fd) == -1) - return(-1); - - return(0); + off_t of = lbl->d_partitions[OURPART].p_offset; + + Debug("Seeking to byte %ld ", of * lbl->d_secsize); + if (lseek(fd, (of * lbl->d_secsize), SEEK_SET) < 0) { + Fatal("Couldn't seek to start of partition\n"); + } + + enable_label(fd); + + if (write(fd, bootblocks, lbl->d_bbsize) != lbl->d_bbsize) { + Fatal("Failed to write bootblocks (%p,%d) %d %s\n", + bootblocks, lbl->d_bbsize, + errno, strerror(errno) + ); + } + + disable_label(fd); + + return(0); } int -build_bootblocks(struct disklabel *label) +build_bootblocks(int dfd,struct disklabel *label,struct dos_partition *dospart) { + int fd; + off_t of = label->d_partitions[OURPART].p_offset; + + Debug("Loading boot code from %s", boot1); + + fd = open(boot1, O_RDONLY); + if (fd < 0) + Fatal("Couldn't open boot file %s\n", boot1); - int fd; + if (read(fd, bootblocks, MBRSIZE) < 0) + Fatal("Couldn't read from boot file %s\n", boot1); - sprintf(scratch, "\nLoading boot code from %s\n", boot1); - dialog_msgbox(TITLE, scratch, 5, 60, 0); - fd = open(boot1, O_RDONLY); - if (fd < 0) { - sprintf(errmsg, "Couldn't open boot file %s\n", boot1); - return(-1); - } + if (close(fd) == -1) + Fatal("Couldn't close boot file %s\n", boot1); - if (read(fd, bootblocks, MBRSIZE) < 0) { - sprintf(errmsg, "Couldn't read from boot file %s\n", boot1); - return(-1); - } + Debug("Loading boot code from %s", boot2); - if (close(fd) == -1) { - sprintf(errmsg, "Couldn't close boot file %s\n", boot1); - return(-1); - } + fd = open(boot2, O_RDONLY); + if (fd < 0) + Fatal("Couldn't open boot file %s", boot2); - dialog_clear(); - sprintf(scratch, "\nLoading boot code from %s\n", boot2); - dialog_msgbox(TITLE, scratch, 5, 60, 0); + if (read(fd, &bootblocks[MBRSIZE], (int)(label->d_bbsize - MBRSIZE)) < 0) + Fatal("Couldn't read from boot file %s\n", boot2); - fd = open(boot2, O_RDONLY); - if (fd < 0) { - sprintf(errmsg, "Couldn't open boot file %s\n", boot2); - return(-1); - } + if (close(fd) == -1) + Fatal("Couldn't close boot file %s", boot2); - if (read(fd, &bootblocks[MBRSIZE], - (int)(label->d_bbsize - MBRSIZE)) < 0) { - sprintf(errmsg, "Couldn't read from boot file %s\n", boot2); - return(-1); - } + bcopy(dospart, &bootblocks[DOSPARTOFF], + sizeof(struct dos_partition) * NDOSPART); - if (close(fd) == -1) { - sprintf(errmsg, "Couldn't close boot file %s\n", boot2); - return(-1); - } + label->d_checksum = 0; + label->d_checksum = dkcksum(label); + bcopy(label, &bootblocks[(LABELSECTOR * label->d_secsize) + LABELOFFSET], + sizeof *label); - dialog_clear(); + Debug("Seeking to byte %ld ", of * label->d_secsize); - /* Copy MBR partition area into bootblocks */ + if (lseek(dfd, (of * label->d_secsize), SEEK_SET) < 0) { + Fatal("Couldn't seek to start of partition\n"); + } - bcopy(mbr->dospart, &bootblocks[DOSPARTOFF], - sizeof(struct dos_partition) * NDOSPART); + enable_label(dfd); - /* Write the disklabel into the bootblocks */ + if (write(dfd, bootblocks, label->d_bbsize) != label->d_bbsize) { + Fatal("Failed to write bootblocks (%p,%d) %d %s\n", + bootblocks, label->d_bbsize, + errno, strerror(errno) + ); + } - label->d_checksum = dkcksum(label); - bcopy(label, &bootblocks[(LABELSECTOR * label->d_secsize) + LABELOFFSET], - sizeof *label); + disable_label(dfd); - return(0); + return(0); } diff --git a/sbin/sysinstall/bootarea.h b/sbin/sysinstall/bootarea.h index fe25116..3c17eb9 100644 --- a/sbin/sysinstall/bootarea.h +++ b/sbin/sysinstall/bootarea.h @@ -19,10 +19,6 @@ #define DEFFSIZE 1024 #define DEFFRAG 8 -int enable_label(int); -int disable_label(int); -int write_bootblocks(int, off_t, int); -int build_bootblocks(struct disklabel *); int Mb_to_cylbdry(int, struct disklabel *); void default_disklabel(struct disklabel *, int, int); int disk_size(struct disklabel *); diff --git a/sbin/sysinstall/label.c b/sbin/sysinstall/label.c index b2db49a..de62605 100644 --- a/sbin/sysinstall/label.c +++ b/sbin/sysinstall/label.c @@ -2,8 +2,8 @@ #define ESC 27 #define TAB 9 -#define DKTYPENAMES -#include <sys/param.h> +#include <stdlib.h> +#include <limits.h> #define DKTYPENAMES #include <sys/param.h> #include <ufs/ffs/fs.h> @@ -62,6 +62,7 @@ void update_label_form(WINDOW *window, struct disklabel *lbl) { int i; + long used = 0,ul; mvwprintw(window, 2, 2, "Partition"); mvwprintw(window, 2, 15, "Filesystem Type"); @@ -71,162 +72,24 @@ update_label_form(WINDOW *window, struct disklabel *lbl) mvwprintw(window, 4+(i*2), 6, "%s", partname[i]); mvwprintw(window, label_fields[i][0].y, label_fields[i][0].x, "%s", &label_fields[i][0].field); - mvwprintw(window, label_fields[i][1].y, label_fields[i][1].x, "%s", + if(i < 2 || i > 3) { + ul = strtol(label_fields[i][1].field,0,0); + sprintf(label_fields[i][1].field, "%lu",ul); + used += ul; + } + mvwprintw(window, label_fields[i][1].y, label_fields[i][1].x, "%-5s", &label_fields[i][1].field); if (label_fields[i][2].field) mvwprintw(window, label_fields[i][2].y, label_fields[i][2].x, "%s", &label_fields[i][2].field); } - wrefresh(window); -} - -int -edit_line(WINDOW *window, int y, int x, char *field, int width, int maxlen) -{ - int len; - int key = 0; - int fpos, dispos, curpos; - int i; - int done = 0; - - len = strlen(field); - if (len < width) { - fpos = len; - curpos = len; - dispos = 0; - } else { - fpos = width; - curpos = width; - dispos = len - width; - }; - - - do { - wattrset(window, item_selected_attr); - wmove(window, y, x); - for (i=0; i < width; i++) - if (i < (len - dispos)) - waddch(window, field[dispos+i]); - else - waddch(window, ' '); - wmove(window, y, x + curpos); - wrefresh(window); + mvwprintw(window, 20, 10, "Allocated %5luMb, Unalloacted %5lu Mb", + used, disk_size(lbl) - used); - key = wgetch(window); - switch (key) { - case TAB: - case KEY_BTAB: - case KEY_UP: - case KEY_DOWN: - case ESC: - case '\n': - done = 1; - break; - case KEY_HOME: - if (len < width) { - fpos = len; - curpos = len; - dispos = 0; - } else { - fpos = width; - curpos = width; - dispos = len - width; - }; - break; - case KEY_END: - if (len < width) { - dispos = 0; - curpos = len - 1; - } else { - dispos = len - width - 1; - curpos = width - 1; - } - fpos = len - 1; - break; - case KEY_LEFT: - if ((!curpos) && (!dispos)) { - beep(); - break; - } - if (--curpos < 0) { - curpos = 0; - if (--dispos < 0) - dispos = 0; - } - if (--fpos < 0) - fpos = 0; - break; - case KEY_RIGHT: - if ((curpos + dispos) == len) { - beep(); - break; - } - if ((curpos == (width-1)) && (dispos == (maxlen - width -1))) { - beep(); - break; - } - if (++curpos >= width) { - curpos = width - 1; - dispos++; - } - if (dispos >= len) - dispos = len - 1; - if (++fpos >= len) { - fpos = len; - } - break; - case KEY_BACKSPACE: - case KEY_DC: - if ((!curpos) && (!dispos)) { - beep(); - break; - } - if (fpos > 0) { - memmove(field+fpos-1, field+fpos, len - fpos); - len--; - fpos--; - if (curpos > 0) - --curpos; - if (!curpos) - --dispos; - if (dispos < 0) - dispos = 0; - } else - beep(); - break; - default: - if (len < maxlen - 1) { - memmove(field+fpos+1, field+fpos, len - fpos); - field[fpos] = key; - len++; - fpos++; - if (++curpos == width) { - --curpos; - dispos++; - } - if (len == (maxlen - 1)) { - dispos = (maxlen - width - 1); - } - } else - beep(); - break; - } - } while (!done); - wattrset(window, dialog_attr); - wmove(window, y, x); - for (i=0; i < width; i++) - if (i < (len - dispos)) - waddch(window, field[dispos+i]); - else - waddch(window, ' '); - wmove(window, y, x + curpos); wrefresh(window); - field[len] = 0; - delwin(window); - refresh(); - return (key); } + int disk_size(struct disklabel *lbl) { @@ -369,25 +232,24 @@ edit_disklabel(struct disklabel *lbl) y_pos--; break; case KEY_DOWN: - if (y_pos != MAXPARTITIONS) - y_pos++; + if (++y_pos == MAXPARTITIONS) + y_pos--; break; + case '\n': case TAB: x_pos++; - if (x_pos == EDITABLES) + if (x_pos == EDITABLES) { x_pos = 0; + if (++y_pos == MAXPARTITIONS) + y_pos--; + } break; case KEY_BTAB: x_pos--; - if (x_pos < 0) + if (x_pos < 0) { x_pos = EDITABLES - 1; - break; - case '\n': - ++y_pos; - if (y_pos == MAXPARTITIONS) { - y_pos = 0; - if (++x_pos == EDITABLES) - x_pos = 0; + if (--y_pos < 0) + y_pos++; } break; default: @@ -403,7 +265,6 @@ build_disklabel(struct disklabel *lbl) int i, offset; int nsects; int total_sects; - int mounts = 0; /* Get start of FreeBSD partition from default label */ offset = lbl->d_partitions[2].p_offset; @@ -412,15 +273,11 @@ build_disklabel(struct disklabel *lbl) if (strlen(label_fields[i][MOUNTPOINTS].field) && atoi(label_fields[i][UPARTSIZES].field)) { sprintf(scratch, "%s%s", avail_disknames[inst_disk], partname[i]); - devicename[mounts] = StrAlloc(scratch); - mountpoint[mounts] = StrAlloc(label_fields[i][MOUNTPOINTS].field); - mounts++; + Fname[Nfs] = StrAlloc(scratch); + Fmount[Nfs] = StrAlloc(label_fields[i][MOUNTPOINTS].field); + Nfs++; nsects = Mbtosects(atoi(label_fields[i][UPARTSIZES].field), lbl->d_secsize); -#if 0 /* Rounding the offset is at best wrong */ - nsects = rndtocylbdry(nsects, lbl->d_secpercyl); - offset = rndtocylbdry(offset, lbl->d_secpercyl); -#endif lbl->d_partitions[i].p_size = nsects; lbl->d_partitions[i].p_offset = offset; offset += nsects; @@ -521,3 +378,209 @@ display_disklabel(int disk) delwin(window); dialog_clear(); } + +static int +AskWhichPartition(char *prompt) +{ + char buf[10]; + int i; + *buf = 0; + i = AskEm(stdscr,prompt,buf,1); + if(i != '\n' && i != '\r') return -1; + if(!strchr("abefghABEFGH",*buf)) return -1; + return tolower(*buf) - 'a'; +} + +static void +CleanMount(int disk, int part) +{ + int i = MP[disk][part]; + if(Fmount[i]) { + free(Fmount[i]); + Fmount[i] = 0; + } + if(Fname[i]) { + free(Fname[i]); + Fname[i] = 0; + } + if(Ftype[i]) { + free(Ftype[i]); + Ftype[i] = 0; + } + MP[disk][part] = 0; +} + +void +DiskLabel() +{ + int i,j,done=0,diskno,flag,k; + char buf[128]; + struct disklabel *lbl,olbl; + u_long cyl,hd,sec,tsec; + u_long l1,l2,l3,l4; + + *buf = 0; + i = AskEm(stdscr,"Enter number of disk to Disklabel ",buf,1); + printf("%d",i); + if(i != '\n' && i != '\r') return; + diskno = atoi(buf); + if(!(diskno >= 0 && diskno < MAX_NO_DISKS && Dname[diskno])) return; + olbl = *Dlbl[diskno]; + lbl = &olbl; + cyl = lbl->d_ncylinders; + hd = lbl->d_ntracks; + sec = lbl->d_nsectors; + tsec = lbl->d_secperunit; + while(!done) { + clear(); standend(); + j = 0; + mvprintw(j++,0,"%s -- Diskspace editor -- DISKLABEL",TITLE); + j++; + mvprintw(j++,0,"Part Start End Blocks MB Type Mountpoint"); + for(i=0;i<MAXPARTITIONS;i++) { + mvprintw(j++,0,"%c ",'a'+i); + if(i>=lbl->d_npartitions) continue; + printw(" %8u %8u %8u %5u ", + lbl->d_partitions[i].p_offset, + lbl->d_partitions[i].p_offset+ + (lbl->d_partitions[i].p_size ? + lbl->d_partitions[i].p_size-1 : 0), + lbl->d_partitions[i].p_size, + (lbl->d_partitions[i].p_size + 1024)/2048); + + k = lbl->d_partitions[i].p_fstype; + if(k > FSMAXTYPES) + printw(" %04x ",k); + else + printw("%-10s ",fstypenames[k]); + if(i == OURPART) + printw("<Entire FreeBSD slice>"); + else if(i == RAWPART) + printw("<Entire Disk>"); + else if(Fmount[MP[diskno][i]]) + printw(Fmount[MP[diskno][i]]); + } + mvprintw(21,0,"Commands available:"); + mvprintw(22,0,"(S)ize (M)ountpoint (D)elete (R)eread (W)rite (Q)uit"); + mvprintw(23,0,"Enter Command> "); + i=getch(); + switch(i) { + case 'd': case 'D': + j = AskWhichPartition("Delete which partition ? "); + if(j < 0) break; + CleanMount(diskno,j); + lbl->d_partitions[j].p_fstype = FS_UNUSED; + lbl->d_partitions[j].p_size = 0; + lbl->d_partitions[j].p_offset = 0; + break; + case 's': case 'S': + j = AskWhichPartition("Change size of which partition ? "); + if(j < 0) break; + if(lbl->d_partitions[j].p_fstype != FS_BSDFFS && + lbl->d_partitions[j].p_fstype != FS_UNUSED && + lbl->d_partitions[j].p_fstype != FS_SWAP) break; + if(lbl->d_partitions[OURPART].p_size == 0) break; + l1=lbl->d_partitions[OURPART].p_offset; + l2=lbl->d_partitions[OURPART].p_offset + + lbl->d_partitions[OURPART].p_size; + for (i=0;i<MAXPARTITIONS;i++) { + if(i == OURPART) continue; + if(i == RAWPART) continue; + if(i == j) continue; + if(lbl->d_partitions[i].p_size == 0) continue; + if(lbl->d_partitions[i].p_offset >= l2) continue; + if((lbl->d_partitions[i].p_offset+ + lbl->d_partitions[i].p_size) <= l1) continue; + l3 = lbl->d_partitions[i].p_offset - l1; + l4 = l2 - (lbl->d_partitions[i].p_offset+ + lbl->d_partitions[i].p_size); + if(l3 > 0 && l3 >= l4) + l2 = l1+l3; + else if (l4 > 0 && l4 > l3) + l1 = l2-l4; + else + l2 = l1; + } + if(!(l2-l1)) break; + sprintf(buf,"%lu",(l2-l1+1024L)/2048L); + i = AskEm(stdscr,"Size of slice in MB ",buf,10); + l3=strtol(buf,0,0) * 2048L; + if(!l3) break; + if(l3 > l2-l1) + l3 = l2-l1; + lbl->d_partitions[j].p_size = l3; + lbl->d_partitions[j].p_offset = l1; + if(j == 1) + lbl->d_partitions[j].p_fstype = FS_SWAP; + else + lbl->d_partitions[j].p_fstype = FS_BSDFFS; + + break; + case 'r': case 'R': + olbl = *Dlbl[diskno]; + /* XXX be more selective here */ + for(i=0;i<MAXPARTITIONS;i++) + CleanMount(diskno,i); + break; + case 'm': case 'M': + j = AskWhichPartition("Mountpoint of which partition ? "); + if(j < 0) break; + k = lbl->d_partitions[j].p_fstype; + if(k != FS_BSDFFS && k != FS_MSDOS && k != FS_SWAP) break; + if(!lbl->d_partitions[j].p_size) break; + if(k == FS_SWAP) + strcpy(buf,"swap"); + else if(Fmount[MP[diskno][j]]) + strcpy(buf,Fmount[MP[diskno][j]]); + else + *buf = 0; + if(k != FS_SWAP) { + i = AskEm(stdscr,"Mount on directory ",buf,28); + if(i != '\n' && i != '\r') break; + } + CleanMount(diskno,j); + for(k=1;k<MAX_NO_FS;k++) + if(!Fmount[k]) + break; + if(k >= MAX_NO_FS) break; + Fmount[k] = StrAlloc(buf); + MP[diskno][j] = k; + sprintf(buf,"%s%c",Dname[diskno],j+'a'); + Fname[MP[diskno][j]] = StrAlloc(buf); + if(lbl->d_partitions[j].p_fstype == FS_BSDFFS) + Ftype[MP[diskno][j]] = StrAlloc("ufs"); + else if(lbl->d_partitions[j].p_fstype == FS_MSDOS) + Ftype[MP[diskno][j]] = StrAlloc("msdos"); + else if(lbl->d_partitions[j].p_fstype == FS_SWAP) + Ftype[MP[diskno][j]] = StrAlloc("swap"); + Fsize[MP[diskno][j]] = (lbl->d_partitions[j].p_size+1024)/2048; + break; + case 'w': case 'W': + *Dlbl[diskno] = *lbl; + Dlbl[diskno]->d_magic = DISKMAGIC; + Dlbl[diskno]->d_magic2 = DISKMAGIC; + Dlbl[diskno]->d_checksum = 0; + Dlbl[diskno]->d_checksum = dkcksum(Dlbl[diskno]); + *lbl= *Dlbl[diskno]; + flag=1; + if (ioctl(Dfd[diskno], DIOCWLABEL, &flag) < 0) + Fatal("Couldn't enable writing of labels"); + if(ioctl(Dfd[diskno],DIOCSDINFO,Dlbl[diskno]) == -1) + Fatal("Couldn't set label: %s",strerror(errno)); + if(ioctl(Dfd[diskno],DIOCWDINFO,Dlbl[diskno]) == -1) + Fatal("Couldn't write label: %s",strerror(errno)); + flag=0; + if (ioctl(Dfd[diskno], DIOCWLABEL, &flag) < 0) + Fatal("Couldn't disable writing of labels"); + break; + case 'q': case 'Q': + if(!memcmp(lbl,Dlbl[diskno],sizeof *lbl)) + return; + /* XXX be more selective here */ + for(i=0;i<MAXPARTITIONS;i++) + CleanMount(diskno,i); + return; + break; + } + } +} diff --git a/sbin/sysinstall/main.c b/sbin/sysinstall/main.c index 046b9b3..8ae6466 100644 --- a/sbin/sysinstall/main.c +++ b/sbin/sysinstall/main.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: main.c,v 1.8 1994/10/26 02:53:09 phk Exp $ + * $Id: main.c,v 1.9 1994/10/29 10:01:34 phk Exp $ * */ @@ -29,36 +29,10 @@ jmp_buf jmp_restart; /* - * This is the overall plan: (phk's version) - * - * If (pid == 1) - * reopen stdin, stdout, stderr, and do various other magic. - * - * If (file exists /this_is_boot.flp) - * stage0: - * present /README - * stage1: - * Ask about diskallocation and do the fdisk/disklabel stunt. - * stage2: - * Do newfs, mount and copy over a minimal world. - * make /mnt/etc/fstab. Install ourself as /mnt/sbin/init - * Else - * stage3: - * Read cpio.flp and fiddle around with the bits a bit. - * stage4: - * Read bin-tarballs: - * Using ftp - * Using NFS (?) - * Using floppy - * Using tape - * Using shell-prompt - * stage5: - * Extract bin-tarballs - * stage6: - * Ask various questions and collect answers into system-config - * files. - * stage7: - * execl("/sbin/init"); + * XXX: utils: Mkdir must do "-p". + * XXX: stage2: do mkdir for msdos-mounts. + * XXX: label: Import dos-slice. + * XXX: mbr: edit geometry */ extern int alloc_memory(); @@ -77,8 +51,11 @@ main(int argc, char **argv) i = 1; ioctl(0,TIOCSPGRP,&i); setlogin("root"); + debug_fd = open("/dev/ttyv1",O_WRONLY); + } else { + debug_fd = open("sysinstall.debug", + O_WRONLY|O_CREAT|O_TRUNC,0644); } - debug_fd = open("/dev/ttyv1",O_WRONLY); if (set_termcap() == -1) { Fatal("Can't find terminal entry\n"); } diff --git a/sbin/sysinstall/mbr.c b/sbin/sysinstall/mbr.c index 3199198..b74a483 100644 --- a/sbin/sysinstall/mbr.c +++ b/sbin/sysinstall/mbr.c @@ -17,6 +17,11 @@ #include <dialog.h> #include <fcntl.h> +#ifdef __i386__ /* temp measure delete nov 15 1994 */ +#define i386 1 +#else +#warning FOO +#endif #include <sys/types.h> #include <sys/disklabel.h> #include <sys/uio.h> @@ -43,7 +48,42 @@ part_type(int type) ptr++; next_type++; } - return("Uknown"); + return("Unknown"); +} + +void +read_dospart(int fd, struct dos_partition *dp) +{ + u_char buf[512]; + if (lseek(fd, 0, SEEK_SET) == -1) + Fatal("Couldn't seek for master boot record read\n"); + if (read(fd, buf, 512) != 512) { + Fatal("Failed to read master boot record\n"); + } + memcpy(dp,buf+DOSPARTOFF,sizeof(*dp)*NDOSPART); +} + +void +write_dospart(int fd, struct dos_partition *dp) +{ + u_char buf[512]; + int flag; + if (lseek(fd, 0, SEEK_SET) == -1) + Fatal("Couldn't seek for master boot record read\n"); + if (read(fd, buf, 512) != 512) { + Fatal("Failed to read master boot record\n"); + } + memcpy(buf+DOSPARTOFF,dp,sizeof(*dp)*NDOSPART); + if (lseek(fd, 0, SEEK_SET) == -1) + Fatal("Couldn't seek for master boot record read\n"); + flag=1; + if (ioctl(fd, DIOCWLABEL, &flag) < 0) + Fatal("Couldn't enable writing of labels"); + if (write(fd, buf, 512) != 512) + Fatal("Failed to write master boot record\n"); + flag=0; + if (ioctl(fd, DIOCWLABEL, &flag) < 0) + Fatal("Couldn't disable writing of labels"); } int @@ -57,11 +97,6 @@ read_mbr(int fd, struct mbr *mbr) sprintf(errmsg, "Failed to read master boot record\n"); return(-1); } - /* Validate the master boot record */ - if (mbr->magic != MBR_MAGIC) { - sprintf(errmsg, "Master boot record is invalid\n"); - return(-1); - } return(0); } @@ -73,16 +108,14 @@ write_mbr(int fd, struct mbr *mbr) return(-1); } - if (enable_label(fd) == -1) - return(-1); + enable_label(fd); if (write(fd, mbr->bootcode, MBRSIZE) == -1) { sprintf(errmsg, "Failed to write master boot record\n"); return(-1); } - if(disable_label(fd) == -1) - return(-1); + disable_label(fd); return(0); } @@ -230,3 +263,200 @@ edit_mbr(struct mbr *mbr, struct disklabel *label) "This editor is still under construction :-)", 10, 75, 1); show_mbr(mbr); } + +void +Fdisk() +{ + int i,j,done=0,diskno,flag; + char buf[128]; + struct dos_partition dp[NDOSPART]; + struct disklabel *lbl; + u_long cyl,hd,sec,tsec; + u_long l,l1,l2,l3,l4; + + *buf = 0; + i = AskEm(stdscr,"Enter number of disk to Fdisk ",buf,1); + printf("%d",i); + if(i != '\n' && i != '\r') return; + diskno = atoi(buf); + if(!(diskno >= 0 && diskno < MAX_NO_DISKS && Dname[diskno])) return; + lbl = Dlbl[diskno]; + lbl->d_bbsize = 8192; + cyl = lbl->d_ncylinders; + hd = lbl->d_ntracks; + sec = lbl->d_nsectors; + tsec = Dlbl[diskno]->d_partitions[RAWPART].p_size; + cyl = tsec/(hd*sec); + read_dospart(Dfd[diskno],dp); + while(!done) { + clear(); standend(); + j = 0; + mvprintw(j++,0,"%s -- Diskspace editor -- FDISK",TITLE); + j++; + mvprintw(j++,0, + "Geometry: %lu Cylinders, %lu Heads, %lu Sectors, %luMb", + cyl,hd,sec,(tsec+1024)/2048); + j++; + for(i=0;i<NDOSPART;i++,j+=3) { + mvprintw(j++,0,"%d ",i+1); +#if 0 + printw("[%02x %02x %02x %02x %02x %02x %02x %02x %08lx %08lx]\n", + dp[i].dp_flag, dp[i].dp_shd, dp[i].dp_ssect, dp[i].dp_scyl, + dp[i].dp_typ, dp[i].dp_ehd, dp[i].dp_esect, dp[i].dp_ecyl, + dp[i].dp_start, dp[i].dp_size); +#endif + if(!dp[i].dp_size) { + printw("Unused"); + continue; + } + printw("Boot?=%s",dp[i].dp_flag == 0x80 ? "Yes" : "No "); + printw(" Type=%s\n", part_type(dp[i].dp_typ)); + printw(" Phys=(c%d/h%d/s%d..c%d/h%d/s%d)", + DPCYL(dp[i].dp_scyl,dp[i].dp_ssect),dp[i].dp_shd, + DPSECT(dp[i].dp_ssect), + DPCYL(dp[i].dp_ecyl,dp[i].dp_esect),dp[i].dp_ehd, + DPSECT(dp[i].dp_esect)); + printw(" Sector=(%lu..%lu)\n", + dp[i].dp_start, dp[i].dp_size + dp[i].dp_start-1); + printw(" Size=%lu MB, %lu Cylinders",(dp[i].dp_size+1024L)/2048L, + dp[i].dp_size/lbl->d_secpercyl); + l = dp[i].dp_size%lbl->d_secpercyl; + if(l) { + printw(" + %lu Tracks", l/lbl->d_nsectors); + l = l % lbl->d_nsectors; + if(l) { + printw(" + %lu Sectors",l); + } + } + } + mvprintw(21,0,"Commands available:"); + mvprintw(22,0,"(D)elete (E)dit (R)eread (W)rite (Q)uit"); + mvprintw(23,0,"Enter Command> "); + i=getch(); + switch(i) { + case 'r': case 'R': + read_dospart(Dfd[diskno],dp); + break; + case 'e': case 'E': + *buf = 0; + i = AskEm(stdscr,"Edit which Slice ? ",buf,1); + if(i != '\n' && i != '\r') break; + l = strtol(buf,0,0); + if(l < 1 || l > NDOSPART) break; + l1=sec; l2=tsec; + for(i=0;i<NDOSPART;i++) { + if((i+1) == l) continue; + if(!dp[i].dp_size) continue; + if(dp[i].dp_start > l2) continue; + if((dp[i].dp_start + dp[i].dp_size) <= l1) continue; + if(dp[i].dp_start > l1) + l3 = dp[i].dp_start - l1; + else + l3 = 0; + if(l2 > (dp[i].dp_start + dp[i].dp_size)) + l4 = l2 - (dp[i].dp_start + dp[i].dp_size); + else + l4 = 0; + if(l3 >= l4) + l2 = dp[i].dp_start; + else + l1 = dp[i].dp_start + dp[i].dp_size; + } + sprintf(buf,"%lu",(l2-l1+1024L)/2048L); + i = AskEm(stdscr,"Size of slice in MB ",buf,10); + l3=strtol(buf,0,0) * 2048L; + if(!l3) break; + if(l3 > l2-l1) + l3 = l2-l1; + if((l1+l3) % lbl->d_secpercyl) { /* Special for cyl==0 */ + l3 += lbl->d_secpercyl - ((l1+l3) % lbl->d_secpercyl); + } + if(l3+l1 > tsec) + l3 = tsec - l1; + dp[l-1].dp_start=l1; + dp[l-1].dp_size=l3; + + l3 += l1 - 1; + + l2 = l1 / (sec*hd); + if(l2>1023) l2 = 1023; + dp[l-1].dp_scyl = (l2 & 0xff); + dp[l-1].dp_ssect = (l2 >> 2) & 0xc0; + l1 -= l2*sec*hd; + l2 = l1 / sec; + dp[l-1].dp_shd = l2; + l1 -= l2*sec; + dp[l-1].dp_ssect |= (l1+1) & 0x3f; + + l2 = l3 / (sec*hd); + if(l2>1023) l2 = 1023; + dp[l-1].dp_ecyl = (l2 & 0xff); + dp[l-1].dp_esect = (l2 >> 2) & 0xc0; + l3 -= l2*sec*hd; + l2 = l3 / sec; + dp[l-1].dp_ehd = l2; + l3 -= l2*sec; + dp[l-1].dp_esect |= (l3+1) & 0x3f; + + l4 = dp[l-1].dp_typ; + if(!l4) l4 = MBR_PTYPE_FreeBSD; + sprintf(buf,"0x%lx",l4); + i = AskEm(stdscr,"Type of slice (0xa5=FreeBSD) ",buf,5); + l3 = strtol(buf,0,0); + if(l3 == MBR_PTYPE_FreeBSD) { + for(i=0;i<NDOSPART;i++) + if(i != (l-1) && dp[i].dp_typ== MBR_PTYPE_FreeBSD) + memset(&dp[i],0,sizeof dp[i]); + sprintf(buf,"0x80"); + } else { + sprintf(buf,"0"); + } + dp[l-1].dp_typ=l3; + i = AskEm(stdscr,"Bootflag (0x80 for YES) ",buf,5); + dp[l-1].dp_flag=strtol(buf,0,0); + break; + case 'd': case 'D': + *buf = 0; + i = AskEm(stdscr,"Delete which Slice ? ",buf,1); + if(i != '\n' && i != '\r') break; + l = strtol(buf,0,0); + if(l < 1 || l > NDOSPART) break; + memset(&dp[l-1],0,sizeof dp[l-1]); + break; + case 'w': case 'W': + strcpy(buf,"N"); + i = AskEm(stdscr,"Confirm write ",buf,1); + if(*buf != 'y' && *buf != 'Y') break; + write_dospart(Dfd[diskno],dp); + Dlbl[diskno]->d_partitions[OURPART].p_offset = 0; + Dlbl[diskno]->d_partitions[OURPART].p_size = 0; + for(i=0;i<NDOSPART;i++) { + if(dp[i].dp_typ == MBR_PTYPE_FreeBSD) { + Dlbl[diskno]->d_partitions[OURPART].p_offset = + dp[i].dp_start; + Dlbl[diskno]->d_partitions[OURPART].p_size = + dp[i].dp_size; + } + } + Dlbl[diskno]->d_magic = DISKMAGIC; + Dlbl[diskno]->d_magic2 = DISKMAGIC; + Dlbl[diskno]->d_checksum = 0; + Dlbl[diskno]->d_checksum = dkcksum(Dlbl[diskno]); + flag=1; + enable_label(Dfd[diskno]); + if(ioctl(Dfd[diskno],DIOCSDINFO,Dlbl[diskno]) == -1) + Fatal("Couldn't set label: %s",strerror(errno)); + if(ioctl(Dfd[diskno],DIOCWDINFO,Dlbl[diskno]) == -1) + Fatal("Couldn't write label: %s",strerror(errno)); + flag=0; + disable_label(Dfd[diskno]); + + if (Dlbl[diskno]->d_partitions[OURPART].p_size) + build_bootblocks(Dfd[diskno],lbl,dp); + break; + case 'q': case 'Q': + return; + break; + } + } +} diff --git a/sbin/sysinstall/mbr.h b/sbin/sysinstall/mbr.h index ea4de02..db9edc7 100644 --- a/sbin/sysinstall/mbr.h +++ b/sbin/sysinstall/mbr.h @@ -18,7 +18,6 @@ struct mbr { - unsigned char padding[2]; /* force longs to be long aligned */ unsigned char bootcode[DOSPARTOFF]; struct dos_partition dospart[4]; unsigned short magic; @@ -73,8 +72,6 @@ struct part_type }; extern char *part_type(int); -extern int enable_label(int); -extern int disable_label(int); extern int write_mbr(int, struct mbr *); extern int read_mbr(int, struct mbr *); extern void show_mbr(struct mbr *); diff --git a/sbin/sysinstall/ourcurses.c b/sbin/sysinstall/ourcurses.c new file mode 100644 index 0000000..b542d9c --- /dev/null +++ b/sbin/sysinstall/ourcurses.c @@ -0,0 +1,170 @@ +/* Stopgap, until Paul does the right thing */ +#define ESC 27 +#define TAB 9 + +#include <stdlib.h> +#include <limits.h> +#include <sys/types.h> +#include <string.h> + +#include <string.h> +#include <dialog.h> +#include "sysinstall.h" + +int +edit_line(WINDOW *window, int y, int x, char *field, int width, int maxlen) +{ + int len; + int key = 0; + int fpos, dispos, curpos; + int i; + int done = 0; + + len = strlen(field); + if (len < width) { + fpos = len; + curpos = len; + dispos = 0; + } else { + fpos = width; + curpos = width; + dispos = len - width; + }; + + + do { + wattrset(window, item_selected_attr); + wmove(window, y, x); + for (i=0; i < width; i++) + if (i < (len - dispos)) + waddch(window, field[dispos+i]); + else + waddch(window, ' '); + wmove(window, y, x + curpos); + wrefresh(window); + + key = wgetch(window); + switch (key) { + case TAB: + case KEY_BTAB: + case KEY_UP: + case KEY_DOWN: + case ESC: + case '\n': + case '\r': + done = 1; + break; + case KEY_HOME: + if (len < width) { + fpos = len; + curpos = len; + dispos = 0; + } else { + fpos = width; + curpos = width; + dispos = len - width; + }; + break; + case KEY_END: + if (len < width) { + dispos = 0; + curpos = len - 1; + } else { + dispos = len - width - 1; + curpos = width - 1; + } + fpos = len - 1; + break; + case KEY_LEFT: + if ((!curpos) && (!dispos)) { + beep(); + break; + } + if (--curpos < 0) { + curpos = 0; + if (--dispos < 0) + dispos = 0; + } + if (--fpos < 0) + fpos = 0; + break; + case KEY_RIGHT: + if ((curpos + dispos) == len) { + beep(); + break; + } + if ((curpos == (width-1)) && (dispos == (maxlen - width -1))) { + beep(); + break; + } + if (++curpos >= width) { + curpos = width - 1; + dispos++; + } + if (dispos >= len) + dispos = len - 1; + if (++fpos >= len) { + fpos = len; + } + break; + case KEY_BACKSPACE: + case KEY_DC: + if ((!curpos) && (!dispos)) { + beep(); + break; + } + if (fpos > 0) { + memmove(field+fpos-1, field+fpos, len - fpos); + len--; + fpos--; + if (curpos > 0) + --curpos; + if (!curpos) + --dispos; + if (dispos < 0) + dispos = 0; + } else + beep(); + break; + default: + if (len < maxlen - 1) { + memmove(field+fpos+1, field+fpos, len - fpos); + field[fpos] = key; + len++; + fpos++; + if (++curpos == width) { + --curpos; + dispos++; + } + if (len == (maxlen - 1)) { + dispos = (maxlen - width - 1); + } + } else + beep(); + break; + } + } while (!done); + wattrset(window, dialog_attr); + wmove(window, y, x); + for (i=0; i < width; i++) + if (i < (len - dispos)) + waddch(window, field[dispos+i]); + else + waddch(window, ' '); + wmove(window, y, x + curpos); + wrefresh(window); + field[len] = 0; + delwin(window); + refresh(); + return (key); +} + +int +AskEm(WINDOW *w,char *prompt, char *answer, int len) +{ + int x,y; + mvwprintw(w,23,0,prompt); + wclrtoeol(w); + getyx(w,y,x); + return edit_line(w,y,x,answer,len,len+1); +} diff --git a/sbin/sysinstall/stage0.c b/sbin/sysinstall/stage0.c index b7b815d..fee3dfd 100644 --- a/sbin/sysinstall/stage0.c +++ b/sbin/sysinstall/stage0.c @@ -24,7 +24,7 @@ #include "sysinstall.h" -static unsigned char *welcome[] = { +static char *welcome[] = { "View 'READ ME FIRST' File.", "View FreeBSD Copyright Information.", "Proceed with installation.", @@ -39,7 +39,7 @@ stage0() if (!access(README_FILE, R_OK)) { dialog_clear(); - dialog_textbox("READ ME FIRST", README_FILE, LINES-1, COLS); + dialog_textbox("READ ME FIRST", README_FILE, 24, 80); } return; @@ -54,14 +54,14 @@ stage0() case 1: /* View readme */ if (!access(README_FILE, R_OK)) { dialog_clear(); - dialog_textbox("READ ME FIRST", README_FILE, LINES-1, COLS); + dialog_textbox("READ ME FIRST", README_FILE, 24, 80); } break; case 2: /* View copyrights */ if (!access(COPYRIGHT_FILE, R_OK)) { dialog_clear(); - dialog_textbox("COPYRIGHT", COPYRIGHT_FILE, LINES-1, COLS); + dialog_textbox("COPYRIGHT", COPYRIGHT_FILE, 24, 80); } break; diff --git a/sbin/sysinstall/stage1.c b/sbin/sysinstall/stage1.c index b1f88fb..8c1a3ef 100644 --- a/sbin/sysinstall/stage1.c +++ b/sbin/sysinstall/stage1.c @@ -131,39 +131,48 @@ free_memory() } +char * device_list[] = {"wd","sd",0}; + void query_disks() { - int i; - char disk[15]; - char diskname[5]; - struct stat st; - int fd; - - no_disks = 0; - for (i=0;i<10;i++) { - sprintf(diskname,"wd%d",i); - sprintf(disk,"/dev/r%sd",diskname); - if ((stat(disk, &st) == 0) && (st.st_mode & S_IFCHR)) - if ((fd = open(disk, O_RDWR)) != -1) { - avail_fds[no_disks] = fd; - bcopy(diskname, avail_disknames[no_disks], strlen(diskname)); - if (ioctl(fd, DIOCGDINFO, &avail_disklabels[no_disks++]) == -1) - no_disks--; - } + int i,j; + char disk[15]; + char diskname[5]; + struct stat st; + struct disklabel dl; + int fd; + + for(i=0;i<MAX_NO_DISKS;i++) + if(Dname[i]) { + close(Dfd[i]); Dfd[i] = 0; + free(Dlbl[i]); Dlbl[i] = 0; + free(Dname[i]); Dname[i] = 0; } + Ndisk = 0; + + for (j=0; device_list[j]; j++) { for (i=0;i<10;i++) { - sprintf(diskname,"sd%d",i); - sprintf(disk,"/dev/r%sd",diskname); - if ((stat(disk, &st) == 0) && (st.st_mode & S_IFCHR)) - if ((fd = open(disk, O_RDWR)) != -1) { - avail_fds[no_disks] = fd; - bcopy(diskname, avail_disknames[no_disks], strlen(diskname)); - if (ioctl(fd, DIOCGDINFO, &avail_disklabels[no_disks++]) == -1) - no_disks--; - } + sprintf(diskname,"%s%d",device_list[j],i); + sprintf(disk,"/dev/r%sd",diskname); + if (stat(disk, &st) || !(st.st_mode & S_IFCHR)) + continue; + if ((fd = open(disk, O_RDWR)) == -1) + continue; + if (ioctl(fd, DIOCGDINFO, &dl) == -1) { + close(fd); + continue; + } + Dlbl[Ndisk] = Malloc(sizeof dl); + memcpy(Dlbl[Ndisk], &dl, sizeof dl); + Dname[Ndisk]=StrAlloc(diskname); + Dfd[Ndisk] = fd; + Ndisk++; + if(Ndisk == MAX_NO_DISKS) + return; } + } } int @@ -239,12 +248,61 @@ select_partition(int disk) void stage1() { - int i; + int i,j; int ok = 0; int ready = 0; query_disks(); + while (!ready) { + clear(); standend(); + j = 0; + mvprintw(j++,0,"%s -- Diskspace editor",TITLE); + j++; + mvprintw(j++,0,"Disks Total FreeBSD "); + j++; + for(i=0;i<MAX_NO_DISKS;i++) { + if(!Dname[i]) + continue; + mvprintw(j++,0,"%2d: %-6s %5lu MB %5lu MB", + i, + Dname[i], + PartMb(Dlbl[i],RAWPART), + PartMb(Dlbl[i],OURPART) ); + } + j++; + mvprintw(j++,0,"Filesystems Type Size Mountpoint"); + j++; + for(i=0;i<MAX_NO_FS;i++) { + if(!Fname[i]) + continue; + mvprintw(j++,0,"%2d: %-5s %-5s %5lu MB %-s", + i,Fname[i],Ftype[i],Fsize[i],Fmount[i]); + } + + mvprintw(21,0,"Commands available:"); + mvprintw(22,0,"(F)disk (D)isklabel (Q)uit"); + mvprintw(23,0,"Enter Command> "); + i = getch(); + switch(i) { + case 'q': case 'Q': + return; + case 'f': case 'F': + Fdisk(); + query_disks(); + break; + case 'd': case 'D': + DiskLabel(); + break; + default: + beep(); + } + } + for (i=0; Dname[i]; i++) + close(Dfd[i]); + return; +} +#if 0 while (!ready) { ready = 1; @@ -321,7 +379,9 @@ stage1() dialog_clear(); } } - + if(getenv("STAGE0")) { + Fatal("We stop here"); + } /* Write master boot record and bootblocks */ if (write_mbr(avail_fds[inst_disk], mbr) == -1) Fatal(errmsg); @@ -338,3 +398,4 @@ stage1() Fatal(errmsg); } } +#endif diff --git a/sbin/sysinstall/stage2.c b/sbin/sysinstall/stage2.c index 908b147..3161114 100644 --- a/sbin/sysinstall/stage2.c +++ b/sbin/sysinstall/stage2.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: stage2.c,v 1.7 1994/10/26 05:41:00 phk Exp $ + * $Id: stage2.c,v 1.8 1994/10/26 10:33:36 jkh Exp $ * */ @@ -30,91 +30,104 @@ void stage2() { - char **p,**q; - char pbuf[90]; - char dbuf[90]; - FILE *f1; - int i; - - for(q=mountpoint,p = devicename; *p; p++,q++) { - if(!strcmp(*q,"swap")) - continue; - TellEm("newfs /dev/r%s",*p); - strcpy(pbuf, "/dev/r"); - strcat(pbuf, *p); - i = exec(0, "/stand/newfs", "/stand/newfs", pbuf, 0); - if (i) - Fatal("Exec(/stand/newfs) failed, code=%d.",i); - } + char *p,*q; + char pbuf[90]; + char dbuf[90]; + FILE *f1; + int i,j; - for(q=mountpoint,p = devicename; *p; p++,q++) { - if(!strcmp(*q,"swap")) - continue; - strcpy(dbuf,"/mnt"); - if(strcmp(*q,"/")) - strcat(dbuf,*q); - MountUfs(*p, dbuf, 1, 0); - } + /* Sort in mountpoint order */ + memset(Fsize,0,sizeof Fsize); - Mkdir("/mnt/etc"); - Mkdir("/mnt/dev"); - Mkdir("/mnt/mnt"); - Mkdir("/mnt/stand"); - - CopyFile("/stand/sysinstall","/mnt/stand/sysinstall"); - link("/mnt/stand/sysinstall","/mnt/stand/cpio"); - link("/mnt/stand/sysinstall","/mnt/stand/gunzip"); - link("/mnt/stand/sysinstall","/mnt/stand/gzip"); - link("/mnt/stand/sysinstall","/mnt/stand/zcat"); - link("/mnt/stand/sysinstall","/mnt/stand/newfs"); - link("/mnt/stand/sysinstall","/mnt/stand/fsck"); - link("/mnt/stand/sysinstall","/mnt/stand/dialog"); - CopyFile("/kernel","/mnt/kernel"); - TellEm("make /dev entries"); - chdir("/mnt/dev"); - makedevs(); - chdir("/"); - - TellEm("Making /mnt/etc/fstab"); - f1 = fopen("/mnt/etc/fstab","w"); - if(!f1) - Fatal("Couldn't open /mnt/etc/fstab for writing."); - - TellEm("Writing filesystems"); - for(q=mountpoint,p = devicename; *p; p++,q++) { - if(!strcmp(*q,"swap")) - continue; - fprintf(f1,"/dev/%s\t\t%s\tufs rw 1 1\n",*p,*q); - } - TellEm("Writing swap-devs"); - for(q=mountpoint,p = devicename; *p; p++,q++) { - if(strcmp(*q,"swap")) - continue; - fprintf(f1,"/dev/%s\t\tnone\tswap sw 0 0\n",*p); + for(i=1; Fname[i]; i++) + Fsize[i] = i; + + for(j=1;j;) + for(j=0,i=1;Fsize[i+1];i++) { + if(strcmp(Fmount[Fsize[i]],Fmount[Fsize[i+1]]) > 0) { + j = Fsize[i]; + Fsize[i] = Fsize[i+1]; + Fsize[i+1] = j; + } } - TellEm("Writing procfs"); - fprintf(f1,"proc\t\t/proc\tprocfs rw 0 0\n"); - fclose(f1); - - sync(); - TellEm("Make marker-file"); - i = open("/mnt/stand/need_cpio_floppy",O_CREAT|O_WRONLY|O_TRUNC); - close(i); + + for(j=1;Fsize[j];j++) { + if(strcmp(Ftype[Fsize[j]],"ufs")) + continue; + p = Fname[Fsize[j]]; + TellEm("newfs /dev/r%s",p); + strcpy(pbuf, "/dev/r"); + strcat(pbuf, p); + i = exec(0, "/stand/newfs", "/stand/newfs", "-n", "1", pbuf, 0); + if (i) + Fatal("Exec(/stand/newfs) failed, code=%d.",i); + } + + for(j=1;Fsize[j];j++) { + if(strcmp(Ftype[Fsize[j]],"ufs")) + continue; + strcpy(dbuf,"/mnt"); + p = Fname[Fsize[j]]; + q = Fmount[Fsize[j]]; + if(strcmp(q,"/")) + strcat(dbuf,q); + MountUfs(p, dbuf, 1, 0); + } + + Mkdir("/mnt/etc"); + Mkdir("/mnt/dev"); + Mkdir("/mnt/mnt"); + Mkdir("/mnt/stand"); + + CopyFile("/stand/sysinstall","/mnt/stand/sysinstall"); + link("/mnt/stand/sysinstall","/mnt/stand/cpio"); + link("/mnt/stand/sysinstall","/mnt/stand/gunzip"); + link("/mnt/stand/sysinstall","/mnt/stand/gzip"); + link("/mnt/stand/sysinstall","/mnt/stand/zcat"); + link("/mnt/stand/sysinstall","/mnt/stand/newfs"); + link("/mnt/stand/sysinstall","/mnt/stand/fsck"); + link("/mnt/stand/sysinstall","/mnt/stand/dialog"); + CopyFile("/kernel","/mnt/kernel"); + TellEm("make /dev entries"); + chdir("/mnt/dev"); + makedevs(); + chdir("/"); + + TellEm("Making /mnt/etc/fstab"); + f1 = fopen("/mnt/etc/fstab","w"); + if(!f1) + Fatal("Couldn't open /mnt/etc/fstab for writing."); + + TellEm("Writing filesystems"); + for(j=1;Fsize[j];j++) { + if(!strcmp(Ftype[Fsize[j]],"swap")) + fprintf(f1,"/dev/%s\t\tnone\tswap sw 0 0\n",Fname[Fsize[j]]); + else + fprintf(f1,"/dev/%s\t\t%s\t%s rw 1 1\n", + Fname[Fsize[j]], Fmount[Fsize[j]], Ftype[Fsize[j]]); + } + TellEm("Writing procfs"); + fprintf(f1,"proc\t\t/proc\tprocfs rw 0 0\n"); + fclose(f1); + + sync(); + TellEm("Make marker-file"); + i = open("/mnt/stand/need_cpio_floppy",O_CREAT|O_WRONLY|O_TRUNC); + close(i); + + TellEm("Unmount disks"); + for(j=1;Fsize[j];j++) + continue; - /* we have to unmount in reverse order */ - for(p = mountpoint; *p; p++) - continue; - - TellEm("Unmount disks"); - for(p--;p >= mountpoint;p--) { - if(!strcmp(*p,"swap")) - continue; - strcpy(dbuf,"/mnt"); - if(strcmp(*p,"/")) - strcat(dbuf,*p); - TellEm("unmount %s",dbuf); - /* Don't do error-check, we reboot anyway... */ - unmount(dbuf, 0); - } - dialog_msgbox(TITLE,"Remove the floppy from the drive, and hit return to reboot from the hard disk",6, 75, 1); + for(j--;j > 0;j--) { + if(!strcmp(Ftype[Fsize[j]],"swap")) + continue; + strcpy(dbuf,"/mnt"); + if(strcmp(Fmount[Fsize[j]],"/")) + strcat(dbuf,Fmount[Fsize[j]]); + TellEm("unmount %s",dbuf); + /* Don't do error-check, we reboot anyway... */ + unmount(dbuf, 0); + } + dialog_msgbox(TITLE,"Remove the floppy from the drive, and hit return to reboot from the hard disk",6, 75, 1); } diff --git a/sbin/sysinstall/sysinstall.h b/sbin/sysinstall/sysinstall.h index ebfadb6..014de7b 100644 --- a/sbin/sysinstall/sysinstall.h +++ b/sbin/sysinstall/sysinstall.h @@ -17,9 +17,24 @@ #define BOOT1 "/stand/sdboot" #define BOOT2 "/stand/bootsd" -#define MAXFS 25 +#define MAX_NO_DISKS 10 +#define MAX_NO_FS 30 +#define MAXFS MAX_NO_FS + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <ncurses.h> +#include <string.h> +#include <errno.h> +#include <dialog.h> +#include <ctype.h> + +#include <sys/types.h> +#include <sys/ioctl.h> +#include <sys/dkbad.h> +#include <sys/disklabel.h> -#define MAX_NO_DISKS 10 #define SCRATCHSIZE 1024 #define ERRMSGSIZE 256 #define DEFROOTSIZE 16 @@ -38,12 +53,26 @@ # define EXTERN extern #endif -EXTERN char *devicename[MAXFS+1]; -EXTERN char *mountpoint[MAXFS+1]; +/* All this "disk" stuff */ +EXTERN int Ndisk; +EXTERN struct disklabel *Dlbl[MAX_NO_DISKS]; +EXTERN char *Dname[MAX_NO_DISKS]; +EXTERN int Dfd[MAX_NO_DISKS]; + +EXTERN int MP[MAX_NO_DISKS][MAXPARTITIONS]; + +/* All this "filesystem" stuff */ +EXTERN int Nfs; +EXTERN char *Fname[MAX_NO_FS+1]; +EXTERN char *Fmount[MAX_NO_FS+1]; +EXTERN char *Ftype[MAX_NO_FS+1]; +EXTERN u_long Fsize[MAX_NO_FS+1]; + EXTERN int dialog_active; EXTERN char selection[]; EXTERN int debug_fd; + extern unsigned char **avail_disknames; extern int no_disks; extern int inst_disk; @@ -67,6 +96,7 @@ void AskAbort __P((char *fmt, ...)); void MountUfs __P((char *device, char *mountpoint, int do_mkdir,int flags)); void Mkdir __P((char *path)); void CopyFile __P((char *p1, char *p2)); +u_long PartMb(struct disklabel *lbl,int part); /* exec.c */ int exec __P((int magic, char *cmd, char *args, ...)); @@ -95,3 +125,13 @@ int set_termcap __P((void)); /* makedevs.c */ int makedevs __P((void)); + +/* outcurses.c */ +int edit_line __P((WINDOW *window, int y, int x, char *field, int width, int maxlen)); +int AskEm __P((WINDOW *w,char *prompt, char *answer, int len)); + +/* bootarea.c */ +void enable_label __P((int fd)); +void disable_label __P((int fd)); +int write_bootblocks __P((int fd, struct disklabel *lbl)); +int build_bootblocks __P((int dfd,struct disklabel *label,struct dos_partition *dospart)); diff --git a/sbin/sysinstall/utils.c b/sbin/sysinstall/utils.c index addf12d..9c265ce 100644 --- a/sbin/sysinstall/utils.c +++ b/sbin/sysinstall/utils.c @@ -25,46 +25,12 @@ #include <sys/param.h> #include <sys/mount.h> #include <sys/reboot.h> +#include <sys/dkbad.h> +#include <sys/disklabel.h> #include "sysinstall.h" void -strip_trailing_newlines(char *p) -{ - int len = strlen(p); - while (len > 0 && p[len-1] == '\n') - p[--len] = '\0'; -} - -int strwidth(char *p) -{ - int i = 0, len; - char *start, *s; - - for (start = s = p; (s = strchr(s, '\n')) != NULL; start = ++s) { - *s = '\0'; - len = strlen(start); - *s = '\n'; - if (len > i) - i = len; - } - len = strlen(start); - if (len > i) - i = len; - return i; -} - -int strheight(char *p) -{ - int i = 1; - char *s; - - for (s = p; (s = strchr(s, '\n')) != NULL; s++) - i++; - return i; -} - -void Debug(char *fmt, ...) { char *p; @@ -84,19 +50,14 @@ TellEm(char *fmt, ...) { char *p; va_list ap; - int width, height; - p = Malloc(2048); va_start(ap,fmt); vsnprintf(p, 2048, fmt, ap); va_end(ap); - strip_trailing_newlines(p); write(debug_fd,"Progress <",10); write(debug_fd,p,strlen(p)); write(debug_fd,">\n\r",3); - width = strwidth(p); - height = strheight(p); - dialog_msgbox("Progress", p, height+2, width+4, 0); + dialog_msgbox("Progress", p, 3, 75, 0); free(p); } @@ -105,19 +66,14 @@ Fatal(char *fmt, ...) { char *p; va_list ap; - int width, height; - p = Malloc(2048); va_start(ap,fmt); vsnprintf(p, 2048, fmt, ap); va_end(ap); - strip_trailing_newlines(p); - width = strwidth(p); - height = strheight(p); if (dialog_active) - dialog_msgbox("Fatal", p, height+4, width+4, 1); + dialog_msgbox("Fatal", p, 12, 75, 1); else - fprintf(stderr, "Fatal -- %s\n", p); + fprintf(stderr, "Fatal -- %s", p); free(p); ExitSysinstall(); } @@ -259,3 +215,11 @@ CopyFile(char *p1, char *p2) close(fd1); close(fd2); } + +u_long +PartMb(struct disklabel *lbl,int part) +{ + u_long l; + l = 1024*1024/lbl->d_secsize; + return (lbl->d_partitions[part].p_size + l/2)/l; +} |