void partall(void) { Disk *d; Dir *ent; char *name; int fd, i, n; fd = open("#S", OREAD); if(fd == -1) { fprint(2, "No disk\n"); return; } while((n = dirread(fd, &ent)) > 0) { for(i = 0; i < n; i++) { if(ent[i].mode & DMDIR) { name = smprint("#S/%s/data", ent[i].name); d = opendisk(name, 1, 0); if(!d) { fprint(2, "%s: %r\n", name); continue; } // XXX not safe yet: if(!mbrpart(d) && !cdpart(d) && !p9part(d, "data", 0)) if(!mbrpart(d) && !cdpart(d)) fprint(2, "%s: no partitions\n", name); close(d->fd); } } } close(fd); }
void partition(SDunit *unit) { int type; char *p; if(unit->part == 0) return; if(part9660(unit) == 0) return; p = getconf("partition"); if(p == nil) p = defaultpartition; if(p != nil && strncmp(p, "new", 3) == 0) type = NEW; else if(p != nil && strncmp(p, "old", 3) == 0) type = OLD; else type = NEW|OLD; if(nbuf < unit->secsize) { free(mbrbuf); free(partbuf); mbrbuf = malloc(unit->secsize); partbuf = malloc(unit->secsize); if(mbrbuf==nil || partbuf==nil) { free(mbrbuf); free(partbuf); partbuf = mbrbuf = nil; nbuf = 0; return; } nbuf = unit->secsize; } if((type & NEW) && mbrpart(unit) >= 0){ /* nothing to do */; } else if(type & OLD) oldp9part(unit); }
/* * read unit->data to look for partition tables. * if found, stash partitions in environment and write them to ctl too. */ static void partition(PSDunit *unit) { int type; char *p; if(unit->part == 0) return; if(part9660(unit) == 0) return; p = getconf("partition"); if(p != nil && strncmp(p, "new", 3) == 0) type = NEW; else if(p != nil && strncmp(p, "old", 3) == 0) type = OLD; else type = NEW|OLD; if(mbrbuf == nil) { mbrbuf = malloc(Maxsec); partbuf = malloc(Maxsec); if(mbrbuf==nil || partbuf==nil) { free(mbrbuf); free(partbuf); partbuf = mbrbuf = nil; return; } } /* * there might be no mbr (e.g. on a very large device), so look for * a bare plan 9 partition table if mbrpart fails. */ if((type & NEW) && mbrpart(unit) >= 0){ /* nothing to do */ } else if (type & NEW) p9part(unit, "data"); else if(type & OLD) oldp9part(unit); }