int read_partitions(void) { char *altptr; struct ipart *iptr, *active, *extended; int i, sector; int base =0; int ext_base = 0; struct evtoc *evp; int di; di = get_diskinfo(BDEV(dev,unit)); spc = (spt = SPT(di)) * HEADS(di); use_badsect = FALSE; npartitions = 0; active_partition = 0; active = (struct ipart *)0; extended = (struct ipart *)0; disk_read(0, BPS, (vm_offset_t)0); iptr = (struct ipart *)((struct mboot *)0)->parts; for (i = 0; i < FD_NUMPART; i++, iptr++) { #if DEBUG if (debug) show_part(iptr, i, 0); #endif if (iptr->bootid == ACTIVE) { active = iptr; active_partition = i; } if (iptr->systid == EXT_PART) extended = iptr; partitions[i].p_start = iptr->relsect; partitions[i].p_size = iptr->numsect; } if (active && active->systid == UNIXOS) { sector = active->relsect + HDPDLOC; evp = (struct evtoc *)0; if (disk_read(sector++, BPS, (vm_offset_t)0) == 0 && evp->sanity == VTOC_SANE) { /* compatibility */ bcopy((char *)evp->part, (char *)partitions, sizeof(partitions)); npartitions = evp->nparts; altptr = (char *)(&alt_info); for (i = 0; i++ < 4; altptr += BPS, sector++) { if (disk_read(sector, BPS, (vm_offset_t)altptr)) return 1; } if (alt_info.alt_sanity != ALT_SANITY) { printf("Bad alt_sanity\n"); return 1; } active_partition = 0; use_badsect = TRUE; return 0; } } if (extended) { /* look for extended partitions */ base = extended->relsect; ext_base = base; while (1) { if (disk_read(base, BPS, (vm_offset_t)0)) return 1; iptr = (struct ipart *)((struct mboot *)0)->parts; #if DEBUG if (debug) show_part(iptr, i, base); #endif partitions[i].p_start = base + iptr->relsect; partitions[i].p_size = iptr->numsect; i++; iptr++; #if DEBUG if (debug) show_part(iptr, i, base); #endif if (iptr->systid == EXT_PART) { extended = iptr; base = extended->relsect + ext_base; } else break; } } npartitions = i; return 0; }
int main(int argc, char **argv) { struct stat hdst; struct part_geom whole, entry; struct part_entry table[4], *pe; int drive, par = 0, device, incr; int partf; char *table_file; int hd_major, hd_minor; int needsort; int shrink; /* True if partitions are shrinked to fit. */ unsigned long base, size, limit; if ((arg0= strrchr(argv[0], '/')) == nil) arg0= argv[0]; else arg0++; if (argc < 2 || argc > 3) { fprintf(stderr, "Usage: %s device [partition-file]\n", arg0); exit(1); } dev_file= argv[1]; table_file= argv[argc - 1]; shrink= (argc == 2); if (stat(dev_file, &hdst) < 0) fatal(dev_file); /* Geometry (to print nice numbers.) */ if (diocntl(hdst.st_rdev, DGETP, &geometry) < 0) fatal(dev_file); if (!S_ISBLK(hdst.st_mode)) { fprintf(stderr, "%s: %s is not a device\n", arg0, dev_file); exit(1); } hd_major= major(hdst.st_rdev); hd_minor= minor(hdst.st_rdev); if (hd_minor >= MINOR_d0p0s0) { errno= EINVAL; fatal(dev_file); } if (hd_major == major(DEV_FD0)) { /* HD is actually a floppy. */ if (hd_minor >= 4) { errno= EINVAL; fatal(dev_file); } device= hd_minor + (28 << 2); incr= 4; needsort= 0; } else if (hd_minor % (1 + NR_PARTITIONS) == 0) { /* Partitioning hd0, hd5, ... */ device= hd_minor + 1; incr= 1; needsort= 1; } else { /* Subpartitioning hd[1-4], hd[6-9], ... */ drive= hd_minor / (1 + NR_PARTITIONS); par= hd_minor % (1 + NR_PARTITIONS) - 1; device= MINOR_d0p0s0 + (drive * NR_PARTITIONS + par) * NR_PARTITIONS; if (device + NR_PARTITIONS - 1 > BYTE) { errno= EINVAL; fatal(dev_file); } incr= 1; needsort= 0; } /* Device is now the first of the minor devices to be repartitioned. */ /* Read the partition table from the boot block. */ if ((partf= open(table_file, O_RDONLY)) < 0 || lseek(partf, (off_t) PART_TABLE_OFF, SEEK_SET) == -1 || (par= read(partf, (char *) table, (int) sizeof(table))) < 0 ) fatal(table_file); if (par < sizeof(table)) { fprintf(stderr, "%s: %s does not contain a partition table\n", arg0, table_file); exit(1); } if (needsort) partsort(table); /* Show the geometry of the affected drive or partition. */ if (diocntl(hdst.st_rdev, DGETP, &whole) < 0) fatal(dev_file); /* Use sector numbers. */ base = whole.base / SECTOR_SIZE; size = whole.size / SECTOR_SIZE; limit = base + size; show_part(dev_file, base, size); /* Send the partition table entries to the device driver. */ for (par= 0; par < NR_PARTITIONS; par++, device+= incr) { pe = &table[par]; if (shrink && pe->size != 0) { /* Shrink the partition entry to fit within the * enclosing device just like the driver does. */ unsigned long part_limit= pe->lowsec + pe->size; if (part_limit < pe->lowsec) part_limit= limit; if (part_limit > limit) part_limit= limit; if (pe->lowsec < base) pe->lowsec= base; if (part_limit < pe->lowsec) part_limit= pe->lowsec; pe->size= part_limit - pe->lowsec; } entry.base= pe->lowsec * SECTOR_SIZE; entry.size= pe->size * SECTOR_SIZE; if (diocntl(makedev(hd_major, device), DSETP, &entry) < 0) fatal(dev_file); show_part(finddev(makedev(hd_major, device)), pe->lowsec, pe->size); } exit(0); }
void spell_show() { const char *draftmessage=cgi("draftmessage"); struct ispell_misspelled *msp; struct ispell_suggestion *isps; size_t p, l=strlen(ispellline), n; const char *ignorelab=getarg("IGNORE"); const char *ignorealllab=getarg("IGNOREALL"); const char *replacelab=getarg("REPLACE"); const char *replacealllab=getarg("REPLACEALL"); const char *insertlab=getarg("INSERT"); const char *continuelab=getarg("CONTINUE"); const char *finishlab=getarg("FINISH"); if (!ispellptr) enomem(); if (!ignorelab) ignorelab=""; if (!ignorealllab) ignorealllab=""; if (!replacelab) replacelab=""; if (!replacealllab) replacealllab=""; if (!continuelab) continuelab=""; if (!finishlab) finishlab=""; for (msp=ispellptr->first_misspelled; msp; msp=msp->next) if (msp->misspelled_word) break; if (!msp) enomem(); CHECKFILENAME(draftmessage); printf("<input type=\"hidden\" name=\"form\" value=\"spellchk\" />\n"); printf("<input type=\"hidden\" name=\"pos\" value=\"%s\" />\n", cgi("pos")); if (*cgi("globignore")) { printf("<input type=\"hidden\" name=\"globignore\" value=\""); output_attrencoded(cgi("globignore")); printf("\" />\n"); } if (*cgi("globreplace")) { printf("<input type=\"hidden\" name=\"globreplace\" value=\""); output_attrencoded(cgi("globreplace")); printf("\" />\n"); } printf("<input type=\"hidden\" name=\"draftmessage\" value=\""); output_attrencoded(draftmessage); printf("\" />"); printf("<input type=\"hidden\" name=\"row\" value=\"%u\" /><input type=\"hidden\" name=\"col\" value=\"%u\" /><input type=\"hidden\" name=\"word\" value=\"", (unsigned)paragraph, (unsigned)msp->word_pos); output_attrencoded(msp->misspelled_word); printf("\" /><table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" " "class=\"box-small-outer\"><tr><td>"); printf("<table border=\"0\" cellspacing=\"0\" class=\"spellcheck-background\"><tr><td>"); printf("<table border=\"1\" cellspacing=\"0\" cellpadding=\"8\" class=\"spellcheck-excerpt\"><tr><td align=\"center\"><span style=\"color: #000000\" class=\"spellcheck-excerpt\">"); if (msp->word_pos > 30) { p=msp->word_pos-30; for (n=p; n<msp->word_pos; n++) if (ispellline[n] == ' ') { while (n < p && ispellline[n] == ' ') ++n; p=n; break; } printf("... "); } else p=0; show_part(ispellline+p, msp->word_pos-p); printf("<strong>"); show_part(ispellline+msp->word_pos, strlen(msp->misspelled_word)); printf("</strong>"); p=msp->word_pos+strlen(msp->misspelled_word); if (l-p < 30) { n=l-p; } else n=30; while (n) { if (ispellline[n+p] != ' ') { --n; continue; } while (n && ispellline[n+p-1] == ' ') --n; break; } show_part(ispellline+p, n); if (n != l-p) printf(" ..."); printf("</span></td></tr></table><br />"); printf("<table border=\"1\" cellpadding=\"8\" class=\"spellcheck-main\"><tr><td>"); printf("<table border=\"0\">"); for (isps=msp->first_suggestion; isps; isps=isps->next) { printf("<tr><td>%s</td><td><input type=\"radio\" name=\"REPLACE\" value=\"%s\" /></td><td>%s</td></tr>\n", replacelab, isps->suggested_word, isps->suggested_word); replacelab=" "; } printf("<tr><td>%s</td><td><input type=\"radio\" name=\"REPLACE\" value=\"#other\" /></td><td><input type=\"text\" name=\"OTHER\" size=\"20\" /></td></tr>\n", replacelab); printf("<tr><td> </td><td><input type=\"radio\" name=\"REPLACE\" value=\"#insert\" /></td><td>%s</td></tr>\n", insertlab); printf("<tr><td> </td><td><input type=\"checkbox\" name=\"REPLACEALL\" /></td><td>%s</td></tr>\n", replacealllab); printf("<tr><td> </td><td colspan=\"2\"><hr width=\"100%%\" /></td></tr>\n"); printf("<tr><td> </td><td><input type=\"radio\" name=\"REPLACE\" value=\"#ignore\" /></td><td>%s</td></tr>\n", ignorelab); printf("<tr><td> </td><td><input type=\"radio\" name=\"REPLACE\" value=\"#ignoreall\" /></td><td>%s</td></tr>\n", ignorealllab); printf("</table>"); printf("</td></tr></table><br />"); printf("<table border=\"1\" cellpadding=\"8\" class=\"spellcheck-continue\"><tr><td>"); printf("<input type=\"submit\" name=\"continue\" value=\"%s\" />\n", continuelab); printf("<input type=\"submit\" name=\"finish\" value=\"%s\" />\n", finishlab); printf("</td></tr></table>\n"); printf("</td></tr></table>\n"); printf("</td></tr></table>\n"); }