]> Git Repo - qemu.git/blobdiff - hw/hd-geometry.c
add a boot parameter to set reboot timeout
[qemu.git] / hw / hd-geometry.c
index db47846782f9cb944abcee465e5a600b5ce27f78..1cdb9fb75370b6270c6cd1a13d5a1a355988cc00 100644 (file)
@@ -97,53 +97,43 @@ static int guess_disk_lchs(BlockDriverState *bs,
     return -1;
 }
 
-void hd_geometry_guess(BlockDriverState *bs,
-                       int *pcyls, int *pheads, int *psecs)
+static void guess_chs_for_size(BlockDriverState *bs,
+                uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs)
 {
-    int translation, lba_detected = 0;
-    int cylinders, heads, secs;
     uint64_t nb_sectors;
+    int cylinders;
 
     bdrv_get_geometry(bs, &nb_sectors);
-    bdrv_get_geometry_hint(bs, &cylinders, &heads, &secs);
-    translation = bdrv_get_translation_hint(bs);
 
-    if (cylinders != 0) {
-        /* already got a geometry hint: use it */
-        *pcyls = cylinders;
-        *pheads = heads;
-        *psecs = secs;
-        return;
+    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,
+                       uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs,
+                       int *ptrans)
+{
+    int cylinders, heads, secs, translation;
 
     if (guess_disk_lchs(bs, &cylinders, &heads, &secs) < 0) {
         /* no LCHS guess: use a standard physical disk geometry  */
-    default_geometry:
-        cylinders = nb_sectors / (16 * 63);
-
-        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 ((*pcyls * *pheads) <= 131072) {
-                bdrv_set_translation_hint(bs,
-                                          BIOS_ATA_TRANSLATION_LARGE);
-            } else {
-                bdrv_set_translation_hint(bs,
-                                          BIOS_ATA_TRANSLATION_LBA);
-            }
-        }
+        guess_chs_for_size(bs, pcyls, pheads, psecs);
+        translation = hd_bios_chs_auto_trans(*pcyls, *pheads, *psecs);
     } else if (heads > 16) {
         /* LCHS guess with heads > 16 means that a BIOS LBA
            translation was active, so a standard physical disk
            geometry is OK */
-        lba_detected = 1;
-        goto default_geometry;
+        guess_chs_for_size(bs, pcyls, pheads, psecs);
+        translation = *pcyls * *pheads <= 131072
+            ? BIOS_ATA_TRANSLATION_LARGE
+            : BIOS_ATA_TRANSLATION_LBA;
     } else {
         /* LCHS guess with heads <= 16: use as physical geometry */
         *pcyls = cylinders;
@@ -151,11 +141,17 @@ void hd_geometry_guess(BlockDriverState *bs,
         *psecs = secs;
         /* disable any translation to be in sync with
            the logical geometry */
-        if (translation == BIOS_ATA_TRANSLATION_AUTO) {
-            bdrv_set_translation_hint(bs,
-                                      BIOS_ATA_TRANSLATION_NONE);
-        }
+        translation = BIOS_ATA_TRANSLATION_NONE;
+    }
+    if (ptrans) {
+        *ptrans = translation;
     }
-    bdrv_set_geometry_hint(bs, *pcyls, *pheads, *psecs);
     trace_hd_geometry_guess(bs, *pcyls, *pheads, *psecs, translation);
 }
+
+int hd_bios_chs_auto_trans(uint32_t cyls, uint32_t heads, uint32_t secs)
+{
+    return cyls <= 1024 && heads <= 16 && secs <= 63
+        ? BIOS_ATA_TRANSLATION_NONE
+        : BIOS_ATA_TRANSLATION_LBA;
+}
This page took 0.028959 seconds and 4 git commands to generate.