static void p9part(SDunit *unit, char *name) { SDpart *p; char *field[4], *line[Npart+1]; uint32_t start, end; int i, n; p = sdfindpart(unit, name); if(p == nil) return; if(tsdbio(unit, p, partbuf, unit->secsize, 0) < 0) return; partbuf[unit->secsize-1] = '\0'; if(strncmp((char*)partbuf, "part ", 5) != 0) return; n = getfields((char*)partbuf, line, Npart+1, '\n'); if(n == 0) return; for(i = 0; i < n && unit->npart < SDnpart; i++){ if(strncmp(line[i], "part ", 5) != 0) break; if(getfields(line[i], field, 4, ' ') != 4) break; start = strtoul(field[2], 0, 0); end = strtoul(field[3], 0, 0); if(start >= end || end > unit->sectors) break; sdaddpart(unit, field[1], p->start+start, p->start+end); } }
/* * look for a plan 9 partition table on drive `unit' in the second * sector (sector 1) of partition `name'. * if found, add the partitions defined in the table. */ static void p9part(SDunit *unit, char *name) { SDpart *p; char *field[4], *line[Npart+1]; uvlong start, end; int i, n; dprint("p9part %s %s\n", unit->name, name); p = sdfindpart(unit, name); if(p == nil) return; if(sdreadblk(unit, p, partbuf, unit->secsize, 0) < 0) return; partbuf[unit->secsize-1] = '\0'; if(strncmp((char*)partbuf, "part ", 5) != 0) return; n = gettokens((char*)partbuf, line, Npart+1, "\n"); if(n == 0) return; for(i = 0; i < n && unit->npart < SDnpart; i++){ if(strncmp(line[i], "part ", 5) != 0) break; if(gettokens(line[i], field, 4, " ") != 4) break; start = strtoull(field[2], 0, 0); end = strtoull(field[3], 0, 0); if(start >= end || end > unit->sectors) break; sdaddpart(unit, field[1], p->start+start, p->start+end); } }
void* sdgetfspart(int i, char *s, int chatty) { SDunit *unit; SDpart *p; Scsicrud *crud; if(cdmask&(1<<i)){ if(strcmp(s, "cdboot") != 0) return nil; }else if(sdmask&(1<<i)){ if(strcmp(s, "cdboot") == 0) return nil; } unit = sdindex2unit(i); if((p = sdfindpart(unit, s)) == nil){ if(chatty) print("unknown partition %s!%s\n", unit->name, s); return nil; } if(p->crud == nil) { crud = malloc(sizeof(Scsicrud)); crud->fs.dev = i; crud->fs.diskread = sdread; crud->fs.diskseek = sdseek; // crud->start = 0; crud->unit = unit; crud->part = p; if(dosinit(&crud->fs) < 0 && dosinit(&crud->fs) < 0 && kfsinit(&crud->fs) < 0){ if(chatty) print("partition %s!%s does not contain a DOS or KFS file system\n", unit->name, s); return nil; } p->crud = crud; } return p->crud; }