2 * Common code for block device models
4 * Copyright (C) 2012 Red Hat, Inc.
6 * This work is licensed under the terms of the GNU GPL, version 2 or
7 * later. See the COPYING file in the top-level directory.
10 #include "qemu/osdep.h"
11 #include "sysemu/blockdev.h"
12 #include "sysemu/block-backend.h"
13 #include "hw/block/block.h"
14 #include "qapi/error.h"
15 #include "qemu/error-report.h"
17 void blkconf_serial(BlockConf
*conf
, char **serial
)
22 /* try to fall back to value set with legacy -drive serial=... */
23 dinfo
= blk_legacy_dinfo(conf
->blk
);
25 *serial
= g_strdup(dinfo
->serial
);
30 void blkconf_blocksizes(BlockConf
*conf
)
32 BlockBackend
*blk
= conf
->blk
;
33 BlockSizes blocksizes
;
36 backend_ret
= blk_probe_blocksizes(blk
, &blocksizes
);
37 /* fill in detected values if they are not defined via qemu command line */
38 if (!conf
->physical_block_size
) {
40 conf
->physical_block_size
= blocksizes
.phys
;
42 conf
->physical_block_size
= BDRV_SECTOR_SIZE
;
45 if (!conf
->logical_block_size
) {
47 conf
->logical_block_size
= blocksizes
.log
;
49 conf
->logical_block_size
= BDRV_SECTOR_SIZE
;
54 void blkconf_geometry(BlockConf
*conf
, int *ptrans
,
55 unsigned cyls_max
, unsigned heads_max
, unsigned secs_max
,
60 if (!conf
->cyls
&& !conf
->heads
&& !conf
->secs
) {
61 /* try to fall back to value set with legacy -drive cyls=... */
62 dinfo
= blk_legacy_dinfo(conf
->blk
);
64 conf
->cyls
= dinfo
->cyls
;
65 conf
->heads
= dinfo
->heads
;
66 conf
->secs
= dinfo
->secs
;
68 *ptrans
= dinfo
->trans
;
72 if (!conf
->cyls
&& !conf
->heads
&& !conf
->secs
) {
73 hd_geometry_guess(conf
->blk
,
74 &conf
->cyls
, &conf
->heads
, &conf
->secs
,
76 } else if (ptrans
&& *ptrans
== BIOS_ATA_TRANSLATION_AUTO
) {
77 *ptrans
= hd_bios_chs_auto_trans(conf
->cyls
, conf
->heads
, conf
->secs
);
79 if (conf
->cyls
|| conf
->heads
|| conf
->secs
) {
80 if (conf
->cyls
< 1 || conf
->cyls
> cyls_max
) {
81 error_setg(errp
, "cyls must be between 1 and %u", cyls_max
);
84 if (conf
->heads
< 1 || conf
->heads
> heads_max
) {
85 error_setg(errp
, "heads must be between 1 and %u", heads_max
);
88 if (conf
->secs
< 1 || conf
->secs
> secs_max
) {
89 error_setg(errp
, "secs must be between 1 and %u", secs_max
);