#!/bin/rc # # command: /bin/boddle /n/juke/plan_9/sys/lib/pcdist/src /sys/lib/pcdist/src # srcdir: /n/juke/plan_9/sys/lib/pcdist/src # version: 816316890 # date: Mon Nov 13 21:41:30 EST 1995 # myname=$0 doextract=no fn usage{ echo $myname: usage: $myname '[-X] [src-directory]' >[1=2] exit usage } fn sigint{ rm -rf 816316890 exit interrupt } while(~ $1 -*){ switch($1){ case -X doextract=yes case -* usage } shift } switch($#*){ case 0 srcdir=/sys/lib/pcdist/src case 1 srcdir=$1 case * usage } if(! ~ $doextract yes){ echo This shell file contains a bundle of diffs representing changes echo to original source files in the Plan 9 distribution. It will run echo against the files in echo ' ' $srcdir echo '(unless overridden by the optional source directory argument)' echo and create a directory 816316890 containing the updated files. echo It will NOT automatically update the original files. echo echo Invoke with argument -X to perform the actual extraction. exit 0 } rm -rf 816316890 mkdir 816316890 target=816316890/build.c echo -n '816316890/build.c: ' if(! test -f $srcdir/build.c || ! test -r $srcdir/build.c){ echo $srcdir/build.c unreadable exit unreadable } sum=`{sum < $srcdir/build.c} if(! ~ fa9c304d35298 $sum(1)^$sum(2)){ echo $srcdir/build.c is not the original distribution file exit original } cp $srcdir/build.c 816316890/build.c ed 816316890/build.c >/dev/null >[2=1] <<'//GO.SYSIN DD VADIM build.c' 2132,2187d 1916,2006d 1876,1892d 1869,1874c cgainit(n1); . 1866d 1832a mountc(); . 1821c warnbox(12, 12, emount, &s1); . 1812c warnbox(12, 12, edosfs, &s1); . 1777c warnbox(10, 10, no9660, &s1); . 1714a mountc(); . 1556c scrolldone(&s1); . 1554c scrollinit(&s1); . 1548c warnbox(10, 10, no9660, &s1); . 1520c warnbox(12, 12, se, &s1); . 1506c warnbox(12, 12, baddial, &s2); . 1459c warnbox(10, 10, baddom, &s1); . 1446c warnbox(10, 10, samenet, &s1); . 1422c warnbox(10, 10, nogw, &s1); . 1414c warnbox(10, 10, noip, &s1); . 1311c warnbox(10, 10, editf, &s1); . 1294c warnbox(10, 10, editf, &s1); . 1284c warnbox(10, 10, nomem, &s1); . 1058c warnbox(15, 17, invip, &s1); . 940c scrolldone(&s1); . 938c scrollinit(&s1); . 932c warnbox(10, 10, no9660, &s1); . 922c warnbox(10, 10, nokfs, &s1); . 915c warnbox(10, 10, nospace, &s1); . 907c warnbox(10, 10, preperr, &s1); . 885c warnbox(10, 10, nocd, &s1); . 865a else if(c == 1){ unit = atapiunit(buf); restore(&s1); if(unit == -1) return -1; } . 840a atapiunit(char* name) { Menu ld; int c, l, i; Saved s1, s2; char drives[NMENU][20]; l = 0; memset(&ld, 0, sizeof(Menu)); for(i = 0; i < 8; i++) { sprint(drives[l], "#H/atapi%ddisk", i); if(access(drives[l], 0) == 0) ld.items[l++] = drives[l]; } if(l == 0) { warnbox(10, 10, noatapidisks, &s1); getc(); restore(&s1); return -1; } infobox(10, 10, choosatapi, &s1); c = menu(14, 13, &ld, &s2); restore(&s2); restore(&s1); if(ld.selected == 0) return -1; strcpy(name, drives[c]); return 0; } int . 839a char *choosatapi[] = { "Select an ATAPI drive to load the", "distribution from:", 0, }; char *noatapidisks[] = { "No suitable ATAPI disk available", anykey, 0, }; . 751a "ATAPI (IDE) CD-ROM", . 738a cgacursoron(); . 733a mountc(); . 729a mountc(); . 710a char *nomountc[] = { "Unable to mount the directory \\plan9", "on the filesysetm you selected in order", "to update the configuration.", " ", anykey, 0, }; static int mountc(void) { Dir d; char *p; int fd; Saved s1; if(dirstat("/n/c/plan9", &d) == 0) return 0; if(p = getenv("bootdisk")){ if((fd = open("#s/dos", ORDWR)) >= 0){ if(mount(fd, "/n/c", MREPL|MCREATE, p) != -1){ close(fd); return 0; } close(fd); warn(p); } else warn("#s/dos"); } warnbox(10, 14, nomountc, &s1); getc(); restore(&s1); return 1; } . 693c warnbox(10, 10, nokfs, &s1); . 686c warnbox(10, 10, nospace, &s1); . 678c warnbox(10, 10, preperr, &s1); . 607c warnbox(12, 12, eexpand, &s2); . 593c warnbox(12, 12, edisk, &s2); . 579c warnbox(12, 12, emount, &s2); . 569c warnbox(12, 12, edosfs, &s2); . 479c warnbox(12, 12, se, &s2); . 468c warnbox(12, 12, se, &s2); . 436c warnbox(12, 12, se, &s2); . 426c warnbox(12, 12, se, &s2); . 359c warnbox(10, 10, preperr, &s2); . 296c warnbox(7, 7, nodisks, &s1); . 36,233d 32d 29a void itsdone(char*); . 19,27d wq //GO.SYSIN DD VADIM build.c sum=`{sum < 816316890/build.c} if(~ 158c252030594 $sum(1)^$sum(2)) echo if not{ echo 816316890/build.c checksum error creating updated file exit checksum } target=816316890/dat.h echo -n '816316890/dat.h: ' if(! test -f $srcdir/dat.h || ! test -r $srcdir/dat.h){ echo $srcdir/dat.h unreadable exit unreadable } sum=`{sum < $srcdir/dat.h} if(! ~ e4564b93726 $sum(1)^$sum(2)){ echo $srcdir/dat.h is not the original distribution file exit original } cp $srcdir/dat.h 816316890/dat.h ed 816316890/dat.h >/dev/null >[2=1] <<'//GO.SYSIN DD VADIM dat.h' 39,50c /* cga.c */ extern void xclrscrn(int); extern void xprint(int, int, int, char*fmt, ...); extern void xputc(int, int, int, int); extern void restore(Saved*); extern void infobox(int, int, char*[], Saved*); extern void warnbox(int, int, char*[], Saved*); extern int getc(void); extern int menu(int, int, Menu*, Saved*); extern void scrollinit(Saved*); extern void scroll(char*); extern void scrolldone(Saved*); extern void error(char*, ...); extern void warn(char*); extern void cgacursoroff(void); extern void cgacursoron(void); extern void cgainit(char*); extern char anykey[]; /* ini.c */ extern void scsiini(void); extern void diskconfigure(char*, char*, char*); extern void configure(char*, char*, char*); extern void fixplan9(char*, char*); extern char dosdisk[]; extern int doslba; /* mbr.c */ extern int readmbr(char*); extern int choosafat(void); /* scsi.c */ extern void probe(char*[]); /* subr.c */ extern int docmd(char**, char*); extern void reboot(int); . 25c MENUATTR = 0x07, WARNATTR = 0x47, . 11,13d 0a #define ISDIR 0x80000000L . wq //GO.SYSIN DD VADIM dat.h sum=`{sum < 816316890/dat.h} if(~ dc3264dc1387 $sum(1)^$sum(2)) echo if not{ echo 816316890/dat.h checksum error creating updated file exit checksum } target=816316890/ini.c echo -n '816316890/ini.c: ' if(! test -f $srcdir/ini.c || ! test -r $srcdir/ini.c){ echo $srcdir/ini.c unreadable exit unreadable } sum=`{sum < $srcdir/ini.c} if(! ~ b9d0714b14047 $sum(1)^$sum(2)){ echo $srcdir/ini.c is not the original distribution file exit original } cp $srcdir/ini.c 816316890/ini.c ed 816316890/ini.c >/dev/null >[2=1] <<'//GO.SYSIN DD VADIM ini.c' 814a p = strstr(buf, "bootdisk="); if(p != 0) { q = strchr(p, '\n'); if(q != 0) { q++; memmove(p, q, (buf+n) - q); n -= q-p; buf[n] = '\0'; } } . 766,787d 755c case 8: . 740c case 7: . 737c if(cdrom < 4){ laser = menu(19, 15, &cdromif, &s2); restore(&s2); } . 735a case 4: configata(); cdrom = 0; cdroms.selected = 0; break; . 734a restore(&s2); . 731a restore(&s2); . 721c case 6: . 707c case 5: . 677a configata(); break; case 4: . 565,574d 539,562d 537c restore(&st); . 527,534c case 2: if(scsis.selected == 0 && atas.selected == 0){ warnbox(8, 8, nodefl, &s1); getc(); restore(&s1); break; } if(mkplan9ini(inifile, bootfile, rootdir)) { restore(&st); return; } . 525a aha1542ports.selected = 0; switch(stype) { case AHA1542: sel = menu(20, 13, &aha1542ports, &s1); restore(&s1); if(aha1542ports.selected == 0) { sport = 0; break; } sport = aha1542portn[sel]; break; case ULTRA14F: sel = menu(20, 13, &ultra14fports, &s1); restore(&s1); if(ultra14fports.selected == 0) { sport = 0; break; } sport = ultra14fportn[sel]; } . 518,524d 512,516c case 1: stype = menu(17, 11, &scsis, &s1); restore(&s1); if(stype == 0) { scsis.selected = 0; break; } . 509,510c sel = menu(15, 7, &inidiskonly, &st); if(aion) { aion = 0; restore(&ai); } switch(sel) { case 0: configata(); . 507a aion = 1; infobox(38, 3, allinfo, &ai); . 504,506c int sel, aion; Saved ai, st, s1; . 502c diskconfigure(char *inifile, char *bootfile, char *rootdir) . 500a type = menu(17, 11, &atas, &s1); restore(&s1); switch(type){ case 0: atas.selected = 0; break; default: sel = menu(17, 13, &atairqs, &s1); restore(&s1); if(atairqs.selected) ataselected[type] = atairqn[sel]; else atas.selected = 0; break; } } . 499c void configata(void) { int type, sel; Saved s1; . 494,495c "You must enter information about all", "devices every time you use this menu", "to configure a device. This is not an", "editor; it makes a new PLAN9.INI file", "each time.", . 492c char *allinfo[] = . 478,479c "To make the system recognize the new", "controller(s) you must now reboot. Press", . 476c char *diskreboot[] = . 472c anykey, . 470c "You must select a controller for", . 443a if(dosdisk[0]){ if(strncmp(dosdisk, "/dev/hd", 7) == 0){ c = strtol(&dosdisk[7], 0, 0); j = sprint(lines[i], "bootdisk=#H/hd%ddisk", c); } else if(strncmp(dosdisk, "/dev/sd", 7) == 0){ c = strtol(&dosdisk[7], 0, 0); j = sprint(lines[i], "bootdisk=#w%d/sd%ddisk", c, c); } if(doslba) sprint(lines[i]+j, ":%d", doslba); i++; } . 428a if(laser) strcat(lines[i], " laser"); . 399a for(j = 1; j < 3; j++) if(ataselected[j]) sprint(lines[i++], "ata%d=irq=%d", j, ataselected[j]); . 354c static int . 343c Menu cdromif = { 0, 0, "Creative Labs", "Laser Mate", }; int cdrom, cdromp, laser, eport, eirq, esize, emem, sport, cons, consbaud; . 339a { 0x1F0, 0x170, 0x1E8, 0x168 }, /* ATAPI (IDE) */ . 334c int cdport[5][10] = . 310a "ATAPI (IDE)" . 232a Menu atas = { 0, 0, "None", "secondary - Port 0x170", "tertiary - Port 0x1E8", "quaternary - Port 0x168", }; int ataselected[4]; Menu atairqs = { 3, 0, "IRQ 10", "IRQ 11", "IRQ 12", "IRQ 15", }; int atairqn[] = { 10, 11, 12, 15 }; int ataselected[4]; . 82c "3C509 - the 3COM ISA/EISA/PCI 10Mbps card", . 70c "1024x768x8", "1280x768x8", . 18a Menu inidiskonly = { 0, 0, "ATA (IDE) controller", "SCSI controller", "Save configuration", }; . 12c "ATA (IDE) controller", "SCSI controller", . 4a char dosdisk[3*NAMELEN]; int doslba; . wq //GO.SYSIN DD VADIM ini.c sum=`{sum < 816316890/ini.c} if(~ a4b307b715379 $sum(1)^$sum(2)) echo if not{ echo 816316890/ini.c checksum error creating updated file exit checksum } target=816316890/inst.c echo -n '816316890/inst.c: ' if(! test -f $srcdir/inst.c || ! test -r $srcdir/inst.c){ echo $srcdir/inst.c unreadable exit unreadable } sum=`{sum < $srcdir/inst.c} if(! ~ 2d1af6c713772 $sum(1)^$sum(2)){ echo $srcdir/inst.c is not the original distribution file exit original } cp $srcdir/inst.c 816316890/inst.c ed 816316890/inst.c >/dev/null >[2=1] <<'//GO.SYSIN DD VADIM inst.c' 783,786c scrolldone(&s1); . 767,768d 761,765c scrollinit(&s1); . 750,751d 741d 735,736c diskconfigure("/n/a/plan9.ini", "fd!0!9dos", 0); . 732a restore(&s1); . 730,731c infobox(8, 3, moredisks, &s1); c = menu(27, 19, &cfgdisk, &s2); . 725,728c for(;;){ if(disksel(dosdisk, "disk", cdisk) == 0) break; if(readmbr(dosdisk) == 0) continue; if((doslba = choosafat()) == -1) continue; if((fd = open("#s/dos", ORDWR)) >= 0){ sprint(buf, "%sdisk:%d", dosdisk, doslba); if(mount(fd, "/n/c", MREPL|MCREATE, buf) != -1){ close(fd); return; } close(fd); warn(buf); } } . 723a char buf[3*NAMELEN]; . 722c int c, fd; . 718a char *cdisk[] = { "Select a disc containing a FAT-based filesystem.", "If the disc you want does not appear in the menu", "press ESC to abort then configure extra ATA (IDE)", "or SCSI controllers.", 0, }; . 715c "Configure Disk Controller", . 711c Menu cfgdisk = . 696,707c "If you think the FAT-based partition you wish to use", "is on a configured drive, Plan 9 has failed to find it.", "Without modifying your hardware configuration install", "is unable to proceed.", . 693,694c "If the FAT-based partition you wish to use is on", "a SCSI device or an ATA (IDE) drive attached to a", "controller other than the primary, you must first", "configure the controller and then reboot to continue", "the installation. To do this, first make a writable", "copy of diskette 1 using the DOS DISKCOPY command.", "Then reboot using the new copy and you will be able", "to use the `Configure Disk Controller' option.", . 691c char *moredisks[] = . 682c "Plan 9 is now installed on the disk", "you selected in the subdirectory \\plan9.", . 637,679d 617,619c "a new directory \\plan9 in the", "filesystem you selected and copy", "copy about 1.44 Mbytes into it", . 465a checkdos(); . 410,451d 396,397c "Plan 9 is already installed on the", "filesystem you selected in \\plan9", . 387c if(c == 1 && disksel(disk, "boot", cbootpart) == 1) . 351c infobox(10, 8, message, &s1); . 345c warnbox(10, 10, nodisks, &s1); . 337c sprint(drives[l], "/dev/sd%d%s", i, partition); . 329,330c for(i = 0; i < 8; i++) { sprint(drives[l], "/dev/hd%d%s", i, partition); . 318c disksel(char* dev, char* partition, char* message[]) . 312c "Install cannot proceed because it cannot find a", "Master Boot Record or suitable FAT-based partition." "", . 303c char *cbootpart[] = . 291c "to \\PLAN9\\B.", . 255,278d 253c cgainit(n1); . 236a if(dosdisk[0]){ if(strncmp(dosdisk, "/dev/hd", 7) == 0) bfbuf[0] = 'h'; else if(strncmp(dosdisk, "/dev/sd", 7) == 0) bfbuf[0] = 's'; sprint(&bfbuf[1], "d!%d!/plan9/9dos", strtol(&dosdisk[7], 0, 0)); return bfbuf; } . 229a static char bfbuf[32]; . 217d 18,215d 15d 5,11c void checkdos(void); . wq //GO.SYSIN DD VADIM inst.c sum=`{sum < 816316890/inst.c} if(~ f4a827cb9478 $sum(1)^$sum(2)) echo if not{ echo 816316890/inst.c checksum error creating updated file exit checksum } target=816316890/mkfile echo -n '816316890/mkfile: ' if(! test -f $srcdir/mkfile || ! test -r $srcdir/mkfile){ echo $srcdir/mkfile unreadable exit unreadable } sum=`{sum < $srcdir/mkfile} if(! ~ 6ebfc9e2197 $sum(1)^$sum(2)){ echo $srcdir/mkfile is not the original distribution file exit original } cp $srcdir/mkfile 816316890/mkfile ed 816316890/mkfile >/dev/null >[2=1] <<'//GO.SYSIN DD VADIM mkfile' 15,16c inst: inst.$O ini.$O mbr.$O cga.$O subr.$O $LD -o $target $prereq %.$O: %.c $CC $CFLAGS $stem.c %.$O: $HFILES clean: rm -f *.[$OS] [$OS].* y.tab.? y.debug y.output $TARG . 12,13c build: build.$O ini.$O scsi.$O cga.$O subr.$O $LD -o $target $prereq . 9,10c all:V: $TARG . 6,7c HFILES=\ dat.h\ . 4c TARG=\ build\ inst\ . 2a CFLAGS=-w BIN=. . wq //GO.SYSIN DD VADIM mkfile sum=`{sum < 816316890/mkfile} if(~ c343f9e6349 $sum(1)^$sum(2)) echo if not{ echo 816316890/mkfile checksum error creating updated file exit checksum } target=816316890/cga.c echo -n '816316890/cga.c (new): ' cat > 816316890/cga.c >[2]/dev/null <<'//GO.SYSIN DD VADIM /sys/lib/pcdist/src' #include #include #include "dat.h" char anykey[] = "Press almost any key to continue..."; static uchar* cga; static char kbdc[10]; static int kbdcnt; static int cfd; static int kfd; static char* window[NLINES+1]; static char notice[] = " Plan 9 (TM) Copyright (c) 1995 AT&T Bell Laboratories"; static void done(char *status) { cgacursoron(); exits(status); } void xclrscrn(int attr) { int i; for(i = 0; i < CGAWIDTH*CGAHEIGHT; i += 2) { cga[i] = ' '; cga[i+1] = attr; } } void xprint(int x, int y, int attr, char* fmt, ...) { uchar *p; int out, i; char buf[CGAWIDTH]; x *= 2; out = doprint(buf, buf+sizeof(buf), fmt, (&fmt+1)) - buf; p = (uchar*)(cga + x + (y*CGAWIDTH)); for(i = 0; i < out; i++) { *p++ = buf[i]; *p++ = attr; } } void xputc(int x, int y, int attr, int c) { uchar *p; x *= 2; p = (uchar*)(cga + x + (y*CGAWIDTH)); p[0] = c; p[1] = attr; } void restore(Saved *s) { int l; char *sv, *cm; sv = s->store; for(l = 0; l < s->nitems; l++) { cm = (char*)cga + (s->x*2) + ((s->y+l)*CGAWIDTH); memmove(cm, sv, s->wid*2); sv += s->wid*2; } free(s->store); } void infoboxa(int x, int y, char *items[], Saved *s, int attr) { int nitem; int i, wid, l; char *store, *sv, *cm; wid = 0; for(i = 0; items[i] != 0; i++) { l = strlen(items[i]); if(l > wid) wid = l; } nitem = i; sv = 0; store = 0; if(s != 0) { store = malloc((wid+2)*(i+2)*2); if(store == 0) { fprint(2, "install: no memory"); done("malloc"); } sv = store; } for(l = -1; l < nitem+1; l++) { cm = (char*)cga + ((x-1)*2) + ((y+l)*CGAWIDTH); if(sv != 0) { memmove(sv, cm, (wid+2)*2); sv += (wid+2)*2; } cm += 2; for(i = 0; i < wid; i++) { *cm++ = ' '; *cm++ = attr; } } if(s != 0) { s->store = store; s->nitems = nitem+2; s->x = x-1; s->y = y-1; s->wid = wid+2; } for(i = 0; i < wid; i++) { xputc(x+i, y-1, attr, 0xc4); xputc(x+i, y+nitem, attr, 0xc4); } for(i = 0; items[i] != 0; i++) { xputc(x-1, y+i, attr, 0xb3); xputc(x+wid, y+i, attr, 0xb3); xprint(x, y+i, attr, "%s", items[i]); } xputc(x-1, y-1, attr, 0xda); xputc(x+wid, y-1, attr, 0xbf); xputc(x-1, y+nitem, attr, 0xc0); xputc(x+wid, y+nitem, attr, 0xd9); } void infobox(int x, int y, char *items[], Saved *s) { infoboxa(x, y, items, s, MENUATTR); } void warnbox(int x, int y, char *items[], Saved *s) { infoboxa(x, y, items, s, WARNATTR); } int getc(void) { Rune r; int n, w; while(!fullrune((char*)kbdc, kbdcnt)) { n = read(kfd, kbdc+kbdcnt, 1); if(n < 1) { fprint(2, "install: eof or error on input: %r\n"); done("read"); } kbdcnt += n; } w = chartorune(&r, (char*)kbdc); memmove(kbdc, kbdc+w, kbdcnt-w); kbdcnt -= w; return r; } int menu(int x, int y, Menu *menu, Saved *s) { char *cm; int r, nitem, choice, i, wid; infobox(x, y, menu->items, s); nitem = s->nitems-2; wid = s->wid-2; choice = menu->choice; for(;;) { cm = (char*)cga + (x*2) + ((y+choice)*CGAWIDTH) + 1; for(i = 0; i < wid; i++) { *cm = HIGHMENUATTR; cm += 2; } r = getc(); if(r == 'q') { for(i = 0; i < CGAWIDTH*CGAHEIGHT; i += 2) { cga[i] = ' '; cga[i+1] = 0; } done(0); } if(r == '\n') { menu->selected = 1; break; } if(r == 0x1b) return menu->choice; cm = (char*)cga + (x*2) + ((y+choice)*CGAWIDTH) + 1; for(i = 0; i < wid; i++) { *cm = MENUATTR; cm += 2; } switch(r) { case 128: case '\t': /* Arrow down */ if(choice < nitem-1) choice++; else choice = 0; break; case 206: /* Arrow up */ choice--; if(choice < 0) choice = nitem-1; break; } } menu->choice = choice; return choice; } void scrollinit(Saved* s) { int i; for(i = 0; i < NLINES; i++) { if(window[i] == 0) window[i] = malloc(NWIDTH); memset(window[i], ' ', NWIDTH); window[i][NWIDTH-1] = '\0'; } infobox(WLOCX, WLOCY, window, s); } void scroll(char *str) { int i, l; for(i = 0; i < NLINES-1; i++) memmove(window[i], window[i+1], NWIDTH); memset(window[NLINES-1], ' ', NWIDTH); window[NLINES-1][NWIDTH-1] = '\0'; l = strlen(str); if(l > NWIDTH-1) l = NWIDTH-1; strncpy(window[NLINES-1], str, l); window[NLINES-1][NWIDTH-1] = '\0'; infobox(WLOCX, WLOCY, window, 0); } void scrolldone(Saved* s) { int i; restore(s); for(i = 0; i < NLINES; i++){ free(window[i]); window[i] = 0; } } static char *errorbox[] = { 0, anykey, 0, }; void error(char* format, ...) { char buf[512]; Saved s1; doprint(buf, buf+sizeof(buf), format, (&format+1)); errorbox[0] = buf; warnbox(WLOCX+5, WLOCY+7, errorbox, &s1); getc(); restore(&s1); } char *warni[] = { "Problem Accessing File", 0, 0, anykey, 0, }; void warn(char *s) { Saved s1; char err[ERRLEN], error[80], file[80]; sprint(file, "File: %s", s); warni[1] = file; err[0] = '\0'; errstr(err); sprint(error, "Errstr: %s", err); warni[2] = error; warnbox(WLOCX+5, WLOCY+7, warni, &s1); getc(); restore(&s1); } static int iobfd = -1; static int devopen(char *device, int mode) { int fd; if((fd = open(device, mode)) < 0) error("devopen(%s, %d): %r", device, mode); return fd; } static uchar inportb(long port) { uchar data; if(iobfd == -1) iobfd = devopen("#v/vgaiob", ORDWR); seek(iobfd, port, 0); if(read(iobfd, &data, sizeof(data)) != sizeof(data)) error("inportb(0x%4.4x): %r", port); return data; } static void outportb(long port, uchar data) { if(iobfd == -1) iobfd = devopen("#v/vgaiob", ORDWR); seek(iobfd, port, 0); if(write(iobfd, &data, sizeof(data)) != sizeof(data)) error("outportb(0x%4.4x, 0x%2.2X): %r", port, data); } static uchar crt0A; void cgacursoroff(void) { outportb(0x03D4, 0x0A); crt0A = inportb(0x03D4+1); outportb(0x03D4+1, 0x20|crt0A); } void cgacursoron(void) { outportb(0x03D4, 0x0A); outportb(0x03D4+1, crt0A); } void cgainit(char* banner) { ulong v; v = segattach(0, "cga", 0, 4*1024); if(v == -1) { fprint(2, "cgainit: cannot attach CGA memory: %r\n"); exits("segattach"); } cga = (uchar*)v; xclrscrn(17); xprint(0, 0, 116, "%-80s", banner); xprint(0, 23, 116, "%-80s", notice); cfd = open("/dev/consctl", OWRITE); if(cfd < 0) { fprint(2, "open /dev/consctl: %r"); exits("open"); } write(cfd, "rawon", 5); kfd = open("/dev/cons", OREAD); if(kfd < 0) { fprint(2, "open /dev/cons: %r"); exits("open"); } cgacursoroff(); } //GO.SYSIN DD VADIM /sys/lib/pcdist/src sum=`{sum < 816316890/cga.c} if(~ 85ec336e6399 $sum(1)^$sum(2)) echo if not{ echo 816316890/cga.c checksum error extracting new file exit checksum } target=816316890/mbr.c echo -n '816316890/mbr.c (new): ' cat > 816316890/mbr.c >[2]/dev/null <<'//GO.SYSIN DD VADIM /sys/lib/pcdist/src' #include #include #include "dat.h" typedef struct Tentry { uchar active; /* active flag */ uchar starth; /* starting head */ uchar starts; /* starting sector */ uchar startc; /* starting cylinder */ uchar type; /* partition type */ uchar endh; /* ending head */ uchar ends; /* ending sector */ uchar endc; /* ending cylinder */ uchar lba[4]; /* starting LBA from beginning of disc */ uchar size[4]; /* size in sectors */ } Tentry; enum { Active = 0x80, /* partition is active */ Primary = 0x01, /* internal flag */ TypeEMPTY = 0x00, TypeFAT12 = 0x01, TypeFAT16 = 0x04, TypeEXTENDED = 0x05, TypeFATHUGE = 0x06, TypeBB = 0xFF, TypeXENIX = 0x02, /* root */ TypeXENIXUSR = 0x03, /* usr */ TypeHPFS = 0x07, TypeAIXBOOT = 0x08, TypeAIXDATA = 0x09, TypeOS2BOOT = 0x0A, /* OS/2 Boot Manager */ TypeUNFORMATTED = 0x16, /* unformatted primary partition (OS/2 FDISK)? */ TypeHPFS2 = 0x17, TypeCPM0 = 0x52, TypeDMDDO = 0x54, /* Disk Manager Dynamic Disk Overlay */ TypeGB = 0x56, /* ???? */ TypeSPEEDSTOR = 0x61, TypeSYSV386 = 0x63, /* also HURD? */ TypeNETWARE = 0x64, TypePCIX = 0x75, TypeMINIX13 = 0x80, /* Minix v1.3 and below */ TypeMINIX = 0x81, /* Minix v1.5+ */ TypeLINUXSWAP = 0x82, TypeLINUX = 0x83, TypeAMOEBA = 0x93, TypeAMOEBABB = 0x94, TypeBSD386 = 0xA5, TypeBSDI = 0xB7, TypeBSDISWAP = 0xB8, TypeCPM = 0xDB, TypeSPEEDSTOR12 = 0xE1, TypeSPEEDSTOR16 = 0xE4, TypeLANSTEP = 0xFE, Type9 = 0x39, Toffset = 446, /* offset of partition table in sector */ NTentry = 4, Magic0 = 0x55, Magic1 = 0xAA, }; typedef struct Table { Tentry entry[NTentry]; uchar magic[2]; } Table; static char* types[256] = { [TypeEMPTY] "EMPTY", [TypeFAT12] "FAT (12-bit)", [TypeFAT16] "FAT (16-bit)", [TypeEXTENDED] "EXTENDED", [TypeFATHUGE] "FAT (HUGE)", [TypeBB] "BB", [TypeXENIX] "XENIX", [TypeXENIXUSR] "XENIX USR", [TypeHPFS] "HPFS", [TypeAIXBOOT] "AIX BOOT", [TypeAIXDATA] "AIX DATA", [TypeOS2BOOT] "OS/2 BOOT", [TypeUNFORMATTED] "UNFORMATTED", [TypeHPFS2] "HPFS2", [TypeCPM0] "CPM0", [TypeDMDDO] "DMDDO", [TypeGB] "GB", [TypeSPEEDSTOR] "SPEEDSTOR", [TypeSYSV386] "SYSV386", [TypeNETWARE] "NETWARE", [TypePCIX] "PCIX", [TypeMINIX13] "MINIX V1.3", [TypeMINIX] "MINIX V1.5", [TypeLINUXSWAP] "LINUX SWAP", [TypeLINUX] "LINUX", [TypeAMOEBA] "AMOEBA", [TypeAMOEBABB] "AMOEBA BB", [TypeBSD386] "BSD386", [TypeBSDI] "BSDI", [TypeBSDISWAP] "BSDI SWAP", [TypeCPM] "CPM", [TypeSPEEDSTOR12] "SPEEDSTOR12", [TypeSPEEDSTOR16] "SPEEDSTOR16", [TypeLANSTEP] "LANSTEP", [Type9] "PLAN9", }; typedef struct Chunk Chunk; typedef struct Chunk { char name[NAMELEN+1]; uint start; uint end; int available; Tentry; Chunk* next; int index; } Chunk; enum { MaxChunk = 16, MaxPath = 256, }; static Chunk* clist; static Chunk* cliste; static Chunk chunkpool[MaxChunk]; static int nchunk; static uchar chunknos[MaxChunk] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', }; static int diskfd; static char diskname[MaxPath]; static ulong size; static ulong secsize; static ulong secs; static ulong mbroffset; uint getle32(void* v) { uchar *p; p = v; return (p[3]<<24)|(p[2]<<16)|(p[1]<<8)|p[0]; } void putle32(void* v, uint i) { uchar *p; p = v; p[0] = i; p[1] = i>>8; p[2] = i>>16; p[3] = i>>24; } static Chunk* addchunk(char* name, uint offset, Tentry* tentry) { Chunk *chunk, **clistp, *cp; chunk = &chunkpool[nchunk]; chunk->Tentry = *tentry; strncpy(chunk->name, name, NAMELEN); chunk->start = mbroffset+offset+getle32(chunk->lba); chunk->end = chunk->start+getle32(chunk->size)-1; chunk->available = 0; clistp = &clist; for(cp = *clistp; cp && (cp->start <= chunk->start); cp = cp->next) clistp = &cp->next; *clistp = chunk; chunk->next = cp; if(chunk->next == 0) cliste = chunk; chunk->index = nchunk; nchunk++; return chunk; } static void mkunused(void) { Tentry tentry; Chunk *chunk; if(cliste == 0 || cliste->end+1 >= secs) return; memset(&tentry, 0, sizeof(Tentry)); putle32(tentry.lba, cliste->end+1-mbroffset); putle32(tentry.size, secs-cliste->end-1); chunk = addchunk("", 0, &tentry); chunk->available = 1; } static void mkclist(int fd, uint base, uint offset) { Table table; Tentry *tp; uint lba; seek(fd, ((mbroffset+offset)*secsize)+Toffset, 0); if(read(fd, &table, sizeof(Table)) < 0){ error("read %s: %r", diskname); return; } if(table.magic[0] != Magic0 || table.magic[1] != Magic1) return; for(tp = table.entry; tp < &table.entry[NTentry]; tp++){ if(tp->type == TypeEMPTY) continue; if(base == 0) tp->active |= Primary; if(tp->type == TypeEXTENDED){ lba = getle32(tp->lba); addchunk("", base, tp); if(base == 0) mkclist(fd, lba, lba); else mkclist(fd, base, base+lba); } else addchunk("", offset, tp); } } int readmbr(char* special) { Dir d; char name[MaxPath]; Table table; Tentry *tp; sprint(name, "%spartition", special); if(dirstat(name, &d) < 0){ error("stat %s", name); return 0; } secsize = d.length; sprint(diskname, "%sdisk", special); if(dirstat(diskname, &d) < 0){ error("stat %s", diskname); return 0; } size = d.length; secs = size/secsize; if((diskfd = open(diskname, OREAD)) < 0){ error("open %s", diskname); return 0; } seek(diskfd, Toffset, 0); if(read(diskfd, &table, sizeof(Table)) < 0){ error("read %s: %r", name); return 0; } if(table.magic[0] != Magic0 || table.magic[1] != Magic1){ error("%s: no MBR magic number"); return 0; } mbroffset = 0; for(tp = table.entry; tp < &table.entry[NTentry]; tp++){ if(tp->type != TypeDMDDO) continue; mbroffset = 63; break; } clist = cliste = 0; nchunk = 0; mkclist(diskfd, 0, 0); close(diskfd); if(clist == 0) return 0; mkunused(); return 1; } char *chunksfound[] = { "The following partitions were found. Select", "a FAT-based partition for the installation.", 0, }; char *unsuitable[] = { "Not a suitable partition", " ", anykey, 0, }; int choosafat(void) { int i, item, nfat; char index, type[32], available; Chunk *chunk, *cross[MaxChunk]; char mbuf[512], *p; Menu m; Saved s0, s1, s2; p = mbuf; item = 0; nfat = 0; memset(cross, 0, sizeof(cross)); i = 0; for(chunk = clist; chunk; chunk = chunk->next){ index = chunknos[i]; switch(chunk->type){ case TypeFAT12: case TypeFAT16: case TypeFATHUGE: available = '*'; nfat++; break; default: available = ' '; break; } if(types[chunk->type] == 0) sprint(type, "%2.2uX", chunk->type); else strcpy(type, types[chunk->type]); sprint(p, "%c %cType: %-12.12s LBA: %8d -> %8d", index, available, type, chunk->start, chunk->end); m.items[item] = p; item++; p += strlen(p)+1; cross[i] = chunk; i++; } m.items[item] = 0; m.choice = 0; infobox(4, 4, chunksfound, &s0); for(;;){ m.selected = 0; item = menu(6, 7, &m, &s1); if(m.selected == 0){ restore(&s1); break; } chunk = cross[item]; switch(chunk->type){ case TypeFAT12: case TypeFAT16: case TypeFATHUGE: restore(&s1); restore(&s0); return chunk->start; default: warnbox(10, 14, unsuitable, &s2); getc(); restore(&s2); restore(&s1); break; } } restore(&s0); return -1; } //GO.SYSIN DD VADIM /sys/lib/pcdist/src sum=`{sum < 816316890/mbr.c} if(~ 86a0e95a7357 $sum(1)^$sum(2)) echo if not{ echo 816316890/mbr.c checksum error extracting new file exit checksum } target=816316890/subr.c echo -n '816316890/subr.c (new): ' cat > 816316890/subr.c >[2]/dev/null <<'//GO.SYSIN DD VADIM /sys/lib/pcdist/src' #include #include #include "dat.h" int docmd(char **av, char *output) { Waitmsg w; int n, fd[2]; Saved s1, tbox; char *p, buf[NWIDTH], *err[10]; if(output) { if(pipe(fd) < 0) { err[0] = "Pipe system call failed"; goto syserr; } scrollinit(&tbox); scroll(output); } switch(fork()) { case 0: if(output == 0) { close(1); /* Not interested in idle chatter */ close(2); } else { close(fd[1]); dup(fd[0], 1); dup(fd[0], 2); } exec(av[0], av); exits("exec failed"); case -1: if(output) { close(fd[0]); close(fd[1]); } err[0] = "Fork System call failed"; syserr: errstr(w.msg); err[1] = w.msg; err[2] = "Reboot and try again"; err[3] = 0; warnbox(20, 20, err, &s1); getc(); restore(&s1); reboot(0); break; default: if(output) { close(fd[0]); for(;;) { n = read(fd[1], buf, NWIDTH); if(n <= 0) { close(fd[1]); break; } buf[n] = '\0'; p = strchr(buf, '\n'); if(p != 0) *p = '\0'; scroll(buf); } } if(wait(&w) < 0) { err[0] = "Wait System call failed"; goto syserr; } if(w.msg[0] != '\0') { w.msg[ERRLEN-1] = '\0'; err[0] = "An Error occurred executing the command"; err[1] = av[0]; err[2] = "The error was:", err[3] = w.msg; err[4] = anykey; err[5] = 0; warnbox(15, 15, err, &s1); getc(); restore(&s1); if(output) scrolldone(&tbox); return -1; } if(output) scrolldone(&tbox); return 0; } if(output) scrolldone(&tbox); return -1; } void reboot(int ask) { int fd; char *av[10]; if(access("#s/kfs", 0) == 0) { av[0] = "/bin/disk/kfscmd"; av[1] = "halt"; av[2] = 0; docmd(av, 0); } if(ask) getc(); fd = open("#↑/zot", OWRITE); write(fd, "reboot", 6); close(fd); cgacursoron(); exits("reboot"); } //GO.SYSIN DD VADIM /sys/lib/pcdist/src sum=`{sum < 816316890/subr.c} if(~ 4a4a75fa1830 $sum(1)^$sum(2)) echo if not{ echo 816316890/subr.c checksum error extracting new file exit checksum } echo obsolete files: /n/juke/plan_9/sys/lib/pcdist/src/build /n/juke/plan_9/sys/lib/pcdist/src/inst