Changeset View
Changeset View
Standalone View
Standalone View
head/stand/common/disk.c
Show First 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | ptable_print(void *arg, const char *pname, const struct ptable_entry *part) | ||||
if (pager_output(line)) | if (pager_output(line)) | ||||
return 1; | return 1; | ||||
res = 0; | res = 0; | ||||
if (part->type == PART_FREEBSD) { | if (part->type == PART_FREEBSD) { | ||||
/* Open slice with BSD label */ | /* Open slice with BSD label */ | ||||
dev.dd.d_dev = pa->dev->dd.d_dev; | dev.dd.d_dev = pa->dev->dd.d_dev; | ||||
dev.dd.d_unit = pa->dev->dd.d_unit; | dev.dd.d_unit = pa->dev->dd.d_unit; | ||||
dev.d_slice = part->index; | dev.d_slice = part->index; | ||||
dev.d_partition = -1; | dev.d_partition = D_PARTNONE; | ||||
if (disk_open(&dev, partsize, sectsize) == 0) { | if (disk_open(&dev, partsize, sectsize) == 0) { | ||||
/* | |||||
* disk_open() for partition -1 on a bsd slice assumes | |||||
* you want the first bsd partition. Reset things so | |||||
* that we're looking at the start of the raw slice. | |||||
*/ | |||||
dev.d_partition = -1; | |||||
dev.d_offset = part->start; | |||||
table = ptable_open(&dev, partsize, sectsize, ptblread); | table = ptable_open(&dev, partsize, sectsize, ptblread); | ||||
if (table != NULL) { | if (table != NULL) { | ||||
sprintf(line, " %s%s", pa->prefix, pname); | sprintf(line, " %s%s", pa->prefix, pname); | ||||
bsd.dev = pa->dev; | bsd.dev = pa->dev; | ||||
bsd.prefix = line; | bsd.prefix = line; | ||||
bsd.verbose = pa->verbose; | bsd.verbose = pa->verbose; | ||||
res = ptable_iterate(table, &bsd, ptable_print); | res = ptable_iterate(table, &bsd, ptable_print); | ||||
ptable_close(table); | ptable_close(table); | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | disk_open(struct disk_devdesc *dev, uint64_t mediasize, u_int sectorsize) | ||||
od->mediasize = mediasize; | od->mediasize = mediasize; | ||||
od->sectorsize = sectorsize; | od->sectorsize = sectorsize; | ||||
/* | /* | ||||
* While we are reading disk metadata, make sure we do it relative | * While we are reading disk metadata, make sure we do it relative | ||||
* to the start of the disk | * to the start of the disk | ||||
*/ | */ | ||||
memcpy(&partdev, dev, sizeof(partdev)); | memcpy(&partdev, dev, sizeof(partdev)); | ||||
partdev.d_offset = 0; | partdev.d_offset = 0; | ||||
partdev.d_slice = -1; | partdev.d_slice = D_SLICENONE; | ||||
partdev.d_partition = -1; | partdev.d_partition = D_PARTNONE; | ||||
dev->d_offset = 0; | dev->d_offset = 0; | ||||
table = NULL; | table = NULL; | ||||
slice = dev->d_slice; | slice = dev->d_slice; | ||||
partition = dev->d_partition; | partition = dev->d_partition; | ||||
DPRINTF("%s unit %d, slice %d, partition %d => %p", | DPRINTF("%s unit %d, slice %d, partition %d => %p", | ||||
disk_fmtdev(dev), dev->dd.d_unit, dev->d_slice, dev->d_partition, od); | disk_fmtdev(dev), dev->dd.d_unit, dev->d_slice, dev->d_partition, od); | ||||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | |||||
char* | char* | ||||
disk_fmtdev(struct disk_devdesc *dev) | disk_fmtdev(struct disk_devdesc *dev) | ||||
{ | { | ||||
static char buf[128]; | static char buf[128]; | ||||
char *cp; | char *cp; | ||||
cp = buf + sprintf(buf, "%s%d", dev->dd.d_dev->dv_name, dev->dd.d_unit); | cp = buf + sprintf(buf, "%s%d", dev->dd.d_dev->dv_name, dev->dd.d_unit); | ||||
if (dev->d_slice >= 0) { | if (dev->d_slice > D_SLICENONE) { | ||||
#ifdef LOADER_GPT_SUPPORT | #ifdef LOADER_GPT_SUPPORT | ||||
if (dev->d_partition == 255) { | if (dev->d_partition == D_PARTISGPT) { | ||||
sprintf(cp, "p%d:", dev->d_slice); | sprintf(cp, "p%d:", dev->d_slice); | ||||
return (buf); | return (buf); | ||||
} else | } else | ||||
#endif | #endif | ||||
#ifdef LOADER_MBR_SUPPORT | #ifdef LOADER_MBR_SUPPORT | ||||
cp += sprintf(cp, "s%d", dev->d_slice); | cp += sprintf(cp, "s%d", dev->d_slice); | ||||
#endif | #endif | ||||
} | } | ||||
if (dev->d_partition >= 0) | if (dev->d_partition > D_PARTNONE) | ||||
cp += sprintf(cp, "%c", dev->d_partition + 'a'); | cp += sprintf(cp, "%c", dev->d_partition + 'a'); | ||||
strcat(cp, ":"); | strcat(cp, ":"); | ||||
return (buf); | return (buf); | ||||
} | } | ||||
int | int | ||||
disk_parsedev(struct disk_devdesc *dev, const char *devspec, const char **path) | disk_parsedev(struct disk_devdesc *dev, const char *devspec, const char **path) | ||||
{ | { | ||||
int unit, slice, partition; | int unit, slice, partition; | ||||
const char *np; | const char *np; | ||||
char *cp; | char *cp; | ||||
np = devspec; | np = devspec; | ||||
unit = slice = partition = -1; | unit = -1; | ||||
slice = D_SLICEWILD; | |||||
partition = D_PARTWILD; | |||||
if (*np != '\0' && *np != ':') { | if (*np != '\0' && *np != ':') { | ||||
unit = strtol(np, &cp, 10); | unit = strtol(np, &cp, 10); | ||||
if (cp == np) | if (cp == np) | ||||
return (EUNIT); | return (EUNIT); | ||||
#ifdef LOADER_GPT_SUPPORT | #ifdef LOADER_GPT_SUPPORT | ||||
if (*cp == 'p') { | if (*cp == 'p') { | ||||
np = cp + 1; | np = cp + 1; | ||||
slice = strtol(np, &cp, 10); | slice = strtol(np, &cp, 10); | ||||
Show All 34 Lines |