Changeset View
Changeset View
Standalone View
Standalone View
stand/efi/libefi/efipart.c
Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | if (dev->dv_type == DEVT_DISK) | ||||
return (&hdinfo); | return (&hdinfo); | ||||
if (dev->dv_type == DEVT_CD) | if (dev->dv_type == DEVT_CD) | ||||
return (&cdinfo); | return (&cdinfo); | ||||
if (dev->dv_type == DEVT_FD) | if (dev->dv_type == DEVT_FD) | ||||
return (&fdinfo); | return (&fdinfo); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
/* XXX this gets called way way too often, investigate */ | |||||
pdinfo_t * | pdinfo_t * | ||||
efiblk_get_pdinfo(struct devdesc *dev) | efiblk_get_pdinfo(struct devdesc *dev) | ||||
{ | { | ||||
pdinfo_list_t *pdi; | pdinfo_list_t *pdi; | ||||
pdinfo_t *pd = NULL; | pdinfo_t *pd = NULL; | ||||
pdi = efiblk_get_pdinfo_list(dev->d_dev); | pdi = efiblk_get_pdinfo_list(dev->d_dev); | ||||
if (pdi == NULL) | if (pdi == NULL) | ||||
return (pd); | return (pd); | ||||
STAILQ_FOREACH(pd, pdi, pd_link) { | STAILQ_FOREACH(pd, pdi, pd_link) { | ||||
if (pd->pd_unit == dev->d_unit) | if (pd->pd_unit == dev->d_unit) | ||||
return (pd); | return (pd); | ||||
} | } | ||||
return (pd); | return (pd); | ||||
} | } | ||||
static bool | |||||
same_handle(pdinfo_t *pd, EFI_HANDLE h) | |||||
{ | |||||
return (pd->pd_handle == h || pd->pd_alias == h); | |||||
} | |||||
pdinfo_t * | |||||
efiblk_get_pdinfo_by_handle(EFI_HANDLE h) | |||||
{ | |||||
pdinfo_t *dp, *pp; | |||||
/* | |||||
* Check hard disks, then cd, then floppy | |||||
*/ | |||||
STAILQ_FOREACH(dp, &hdinfo, pd_link) { | |||||
if (same_handle(dp, h)) | |||||
return (dp); | |||||
STAILQ_FOREACH(pp, &dp->pd_part, pd_link) { | |||||
if (same_handle(pp, h)) | |||||
return (pp); | |||||
} | |||||
} | |||||
STAILQ_FOREACH(dp, &cdinfo, pd_link) { | |||||
if (same_handle(dp, h)) | |||||
return (dp); | |||||
} | |||||
STAILQ_FOREACH(dp, &fdinfo, pd_link) { | |||||
if (same_handle(dp, h)) | |||||
return (dp); | |||||
} | |||||
return (NULL); | |||||
} | |||||
static int | static int | ||||
efiblk_pdinfo_count(pdinfo_list_t *pdi) | efiblk_pdinfo_count(pdinfo_list_t *pdi) | ||||
{ | { | ||||
pdinfo_t *pd; | pdinfo_t *pd; | ||||
int i = 0; | int i = 0; | ||||
STAILQ_FOREACH(pd, pdi, pd_link) { | STAILQ_FOREACH(pd, pdi, pd_link) { | ||||
i++; | i++; | ||||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | if (fd == NULL) { | ||||
printf("Failed to register floppy %d, out of memory\n", uid); | printf("Failed to register floppy %d, out of memory\n", uid); | ||||
return (ENOMEM); | return (ENOMEM); | ||||
} | } | ||||
STAILQ_INIT(&fd->pd_part); | STAILQ_INIT(&fd->pd_part); | ||||
fd->pd_unit = uid; | fd->pd_unit = uid; | ||||
fd->pd_handle = handle; | fd->pd_handle = handle; | ||||
fd->pd_devpath = devpath; | fd->pd_devpath = devpath; | ||||
fd->pd_parent = NULL; | |||||
fd->pd_devsw = &efipart_fddev; | |||||
STAILQ_INSERT_TAIL(&fdinfo, fd, pd_link); | STAILQ_INSERT_TAIL(&fdinfo, fd, pd_link); | ||||
return (0); | return (0); | ||||
} | } | ||||
static void | static void | ||||
efipart_updatefd(void) | efipart_updatefd(void) | ||||
{ | { | ||||
EFI_DEVICE_PATH *devpath, *node; | EFI_DEVICE_PATH *devpath, *node; | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | if (cd == NULL) { | ||||
return (ENOMEM); | return (ENOMEM); | ||||
} | } | ||||
STAILQ_INIT(&cd->pd_part); | STAILQ_INIT(&cd->pd_part); | ||||
cd->pd_handle = handle; | cd->pd_handle = handle; | ||||
cd->pd_unit = unit; | cd->pd_unit = unit; | ||||
cd->pd_alias = alias; | cd->pd_alias = alias; | ||||
cd->pd_devpath = devpath; | cd->pd_devpath = devpath; | ||||
cd->pd_parent = NULL; | |||||
cd->pd_devsw = &efipart_cddev; | |||||
STAILQ_INSERT_TAIL(&cdinfo, cd, pd_link); | STAILQ_INSERT_TAIL(&cdinfo, cd, pd_link); | ||||
return (0); | return (0); | ||||
} | } | ||||
static void | static void | ||||
efipart_updatecd(void) | efipart_updatecd(void) | ||||
{ | { | ||||
int i, nin; | int i, nin; | ||||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | STAILQ_FOREACH(hd, &hdinfo, pd_link) { | ||||
if (efi_devpath_match(hd->pd_devpath, disk_devpath) == true) { | if (efi_devpath_match(hd->pd_devpath, disk_devpath) == true) { | ||||
if (part_devpath == NULL) | if (part_devpath == NULL) | ||||
return (0); | return (0); | ||||
/* Add the partition. */ | /* Add the partition. */ | ||||
pd->pd_handle = part_handle; | pd->pd_handle = part_handle; | ||||
pd->pd_unit = node->PartitionNumber; | pd->pd_unit = node->PartitionNumber; | ||||
pd->pd_devpath = part_devpath; | pd->pd_devpath = part_devpath; | ||||
pd->pd_parent = hd; | |||||
pd->pd_devsw = &efipart_hddev; | |||||
STAILQ_INSERT_TAIL(&hd->pd_part, pd, pd_link); | STAILQ_INSERT_TAIL(&hd->pd_part, pd, pd_link); | ||||
return (0); | return (0); | ||||
} | } | ||||
} | } | ||||
last = STAILQ_LAST(&hdinfo, pdinfo, pd_link); | last = STAILQ_LAST(&hdinfo, pdinfo, pd_link); | ||||
if (last != NULL) | if (last != NULL) | ||||
unit = last->pd_unit + 1; | unit = last->pd_unit + 1; | ||||
else | else | ||||
unit = 0; | unit = 0; | ||||
/* Add the disk. */ | /* Add the disk. */ | ||||
hd = pd; | hd = pd; | ||||
hd->pd_handle = disk_handle; | hd->pd_handle = disk_handle; | ||||
hd->pd_unit = unit; | hd->pd_unit = unit; | ||||
hd->pd_devpath = disk_devpath; | hd->pd_devpath = disk_devpath; | ||||
hd->pd_parent = NULL; | |||||
hd->pd_devsw = &efipart_hddev; | |||||
STAILQ_INSERT_TAIL(&hdinfo, hd, pd_link); | STAILQ_INSERT_TAIL(&hdinfo, hd, pd_link); | ||||
if (part_devpath == NULL) | if (part_devpath == NULL) | ||||
return (0); | return (0); | ||||
pd = calloc(1, sizeof(pdinfo_t)); | pd = calloc(1, sizeof(pdinfo_t)); | ||||
if (pd == NULL) { | if (pd == NULL) { | ||||
printf("Failed to add partition, out of memory\n"); | printf("Failed to add partition, out of memory\n"); | ||||
return (ENOMEM); | return (ENOMEM); | ||||
} | } | ||||
STAILQ_INIT(&pd->pd_part); | STAILQ_INIT(&pd->pd_part); | ||||
/* Add the partition. */ | /* Add the partition. */ | ||||
pd->pd_handle = part_handle; | pd->pd_handle = part_handle; | ||||
pd->pd_unit = node->PartitionNumber; | pd->pd_unit = node->PartitionNumber; | ||||
pd->pd_devpath = part_devpath; | pd->pd_devpath = part_devpath; | ||||
pd->pd_parent = hd; | |||||
pd->pd_devsw = &efipart_hddev; | |||||
STAILQ_INSERT_TAIL(&hd->pd_part, pd, pd_link); | STAILQ_INSERT_TAIL(&hd->pd_part, pd, pd_link); | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* The MEDIA_FILEPATH_DP has device name. | * The MEDIA_FILEPATH_DP has device name. | ||||
* From U-Boot sources it looks like names are in the form | * From U-Boot sources it looks like names are in the form | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | efipart_hdinfo_add_filepath(EFI_HANDLE disk_handle) | ||||
* Assume we are receiving handles in order, first disk handle, | * Assume we are receiving handles in order, first disk handle, | ||||
* then partitions for this disk. If this assumption proves | * then partitions for this disk. If this assumption proves | ||||
* false, this code would need update. | * false, this code would need update. | ||||
*/ | */ | ||||
if (p == NULL) { /* no colon, add the disk */ | if (p == NULL) { /* no colon, add the disk */ | ||||
pd->pd_handle = disk_handle; | pd->pd_handle = disk_handle; | ||||
pd->pd_unit = unit; | pd->pd_unit = unit; | ||||
pd->pd_devpath = devpath; | pd->pd_devpath = devpath; | ||||
pd->pd_parent = NULL; | |||||
pd->pd_devsw = &efipart_hddev; | |||||
STAILQ_INSERT_TAIL(&hdinfo, pd, pd_link); | STAILQ_INSERT_TAIL(&hdinfo, pd, pd_link); | ||||
free(pathname); | free(pathname); | ||||
return (0); | return (0); | ||||
} | } | ||||
p++; /* skip the colon */ | p++; /* skip the colon */ | ||||
errno = 0; | errno = 0; | ||||
unit = (int)strtol(p, NULL, 0); | unit = (int)strtol(p, NULL, 0); | ||||
if (errno != 0) { | if (errno != 0) { | ||||
Show All 14 Lines | if (last == NULL) { | ||||
free(pathname); | free(pathname); | ||||
free(pd); | free(pd); | ||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
/* Add the partition. */ | /* Add the partition. */ | ||||
pd->pd_handle = disk_handle; | pd->pd_handle = disk_handle; | ||||
pd->pd_unit = unit; | pd->pd_unit = unit; | ||||
pd->pd_devpath = devpath; | pd->pd_devpath = devpath; | ||||
pd->pd_parent = last; | |||||
pd->pd_devsw = &efipart_hddev; | |||||
STAILQ_INSERT_TAIL(&last->pd_part, pd, pd_link); | STAILQ_INSERT_TAIL(&last->pd_part, pd, pd_link); | ||||
free(pathname); | free(pathname); | ||||
return (0); | return (0); | ||||
} | } | ||||
static void | static void | ||||
efipart_updatehd(void) | efipart_updatehd(void) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 455 Lines • Show Last 20 Lines |