mirror of https://gitlab.com/qemu-project/qemu
hd-geometry: Factor out guess_chs_for_size()
Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
c06aaf018b
commit
2fa5008ffd
|
@ -97,14 +97,31 @@ static int guess_disk_lchs(BlockDriverState *bs,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void guess_chs_for_size(BlockDriverState *bs,
|
||||||
|
int *pcyls, int *pheads, int *psecs)
|
||||||
|
{
|
||||||
|
uint64_t nb_sectors;
|
||||||
|
int cylinders;
|
||||||
|
|
||||||
|
bdrv_get_geometry(bs, &nb_sectors);
|
||||||
|
|
||||||
|
cylinders = nb_sectors / (16 * 63);
|
||||||
|
if (cylinders > 16383) {
|
||||||
|
cylinders = 16383;
|
||||||
|
} else if (cylinders < 2) {
|
||||||
|
cylinders = 2;
|
||||||
|
}
|
||||||
|
*pcyls = cylinders;
|
||||||
|
*pheads = 16;
|
||||||
|
*psecs = 63;
|
||||||
|
}
|
||||||
|
|
||||||
void hd_geometry_guess(BlockDriverState *bs,
|
void hd_geometry_guess(BlockDriverState *bs,
|
||||||
int *pcyls, int *pheads, int *psecs)
|
int *pcyls, int *pheads, int *psecs)
|
||||||
{
|
{
|
||||||
int translation, lba_detected = 0;
|
int translation, lba_detected = 0;
|
||||||
int cylinders, heads, secs;
|
int cylinders, heads, secs;
|
||||||
uint64_t nb_sectors;
|
|
||||||
|
|
||||||
bdrv_get_geometry(bs, &nb_sectors);
|
|
||||||
bdrv_get_geometry_hint(bs, &cylinders, &heads, &secs);
|
bdrv_get_geometry_hint(bs, &cylinders, &heads, &secs);
|
||||||
translation = bdrv_get_translation_hint(bs);
|
translation = bdrv_get_translation_hint(bs);
|
||||||
|
|
||||||
|
@ -119,16 +136,7 @@ void hd_geometry_guess(BlockDriverState *bs,
|
||||||
if (guess_disk_lchs(bs, &cylinders, &heads, &secs) < 0) {
|
if (guess_disk_lchs(bs, &cylinders, &heads, &secs) < 0) {
|
||||||
/* no LCHS guess: use a standard physical disk geometry */
|
/* no LCHS guess: use a standard physical disk geometry */
|
||||||
default_geometry:
|
default_geometry:
|
||||||
cylinders = nb_sectors / (16 * 63);
|
guess_chs_for_size(bs, pcyls, pheads, psecs);
|
||||||
|
|
||||||
if (cylinders > 16383) {
|
|
||||||
cylinders = 16383;
|
|
||||||
} else if (cylinders < 2) {
|
|
||||||
cylinders = 2;
|
|
||||||
}
|
|
||||||
*pcyls = cylinders;
|
|
||||||
*pheads = 16;
|
|
||||||
*psecs = 63;
|
|
||||||
if ((lba_detected == 1) && (translation == BIOS_ATA_TRANSLATION_AUTO)) {
|
if ((lba_detected == 1) && (translation == BIOS_ATA_TRANSLATION_AUTO)) {
|
||||||
if ((*pcyls * *pheads) <= 131072) {
|
if ((*pcyls * *pheads) <= 131072) {
|
||||||
bdrv_set_translation_hint(bs,
|
bdrv_set_translation_hint(bs,
|
||||||
|
|
Loading…
Reference in New Issue