Revision 2fa5008f

b/hw/hd-geometry.c
97 97
    return -1;
98 98
}
99 99

  
100
static void guess_chs_for_size(BlockDriverState *bs,
101
                               int *pcyls, int *pheads, int *psecs)
102
{
103
    uint64_t nb_sectors;
104
    int cylinders;
105

  
106
    bdrv_get_geometry(bs, &nb_sectors);
107

  
108
    cylinders = nb_sectors / (16 * 63);
109
    if (cylinders > 16383) {
110
        cylinders = 16383;
111
    } else if (cylinders < 2) {
112
        cylinders = 2;
113
    }
114
    *pcyls = cylinders;
115
    *pheads = 16;
116
    *psecs = 63;
117
}
118

  
100 119
void hd_geometry_guess(BlockDriverState *bs,
101 120
                       int *pcyls, int *pheads, int *psecs)
102 121
{
103 122
    int translation, lba_detected = 0;
104 123
    int cylinders, heads, secs;
105
    uint64_t nb_sectors;
106 124

  
107
    bdrv_get_geometry(bs, &nb_sectors);
108 125
    bdrv_get_geometry_hint(bs, &cylinders, &heads, &secs);
109 126
    translation = bdrv_get_translation_hint(bs);
110 127

  
......
119 136
    if (guess_disk_lchs(bs, &cylinders, &heads, &secs) < 0) {
120 137
        /* no LCHS guess: use a standard physical disk geometry  */
121 138
    default_geometry:
122
        cylinders = nb_sectors / (16 * 63);
123

  
124
        if (cylinders > 16383) {
125
            cylinders = 16383;
126
        } else if (cylinders < 2) {
127
            cylinders = 2;
128
        }
129
        *pcyls = cylinders;
130
        *pheads = 16;
131
        *psecs = 63;
139
        guess_chs_for_size(bs, pcyls, pheads, psecs);
132 140
        if ((lba_detected == 1) && (translation == BIOS_ATA_TRANSLATION_AUTO)) {
133 141
            if ((*pcyls * *pheads) <= 131072) {
134 142
                bdrv_set_translation_hint(bs,

Also available in: Unified diff