Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20150212' into staging
[qemu.git] / hw / block / block.c
bloba625773d442cf4bd16263e0549fe91602550ecc9
1 /*
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.
8 */
10 #include "sysemu/blockdev.h"
11 #include "sysemu/block-backend.h"
12 #include "hw/block/block.h"
13 #include "qemu/error-report.h"
15 void blkconf_serial(BlockConf *conf, char **serial)
17 DriveInfo *dinfo;
19 if (!*serial) {
20 /* try to fall back to value set with legacy -drive serial=... */
21 dinfo = blk_legacy_dinfo(conf->blk);
22 if (dinfo) {
23 *serial = g_strdup(dinfo->serial);
28 void blkconf_geometry(BlockConf *conf, int *ptrans,
29 unsigned cyls_max, unsigned heads_max, unsigned secs_max,
30 Error **errp)
32 DriveInfo *dinfo;
34 if (!conf->cyls && !conf->heads && !conf->secs) {
35 /* try to fall back to value set with legacy -drive cyls=... */
36 dinfo = blk_legacy_dinfo(conf->blk);
37 if (dinfo) {
38 conf->cyls = dinfo->cyls;
39 conf->heads = dinfo->heads;
40 conf->secs = dinfo->secs;
41 if (ptrans) {
42 *ptrans = dinfo->trans;
46 if (!conf->cyls && !conf->heads && !conf->secs) {
47 hd_geometry_guess(conf->blk,
48 &conf->cyls, &conf->heads, &conf->secs,
49 ptrans);
50 } else if (ptrans && *ptrans == BIOS_ATA_TRANSLATION_AUTO) {
51 *ptrans = hd_bios_chs_auto_trans(conf->cyls, conf->heads, conf->secs);
53 if (conf->cyls || conf->heads || conf->secs) {
54 if (conf->cyls < 1 || conf->cyls > cyls_max) {
55 error_setg(errp, "cyls must be between 1 and %u", cyls_max);
56 return;
58 if (conf->heads < 1 || conf->heads > heads_max) {
59 error_setg(errp, "heads must be between 1 and %u", heads_max);
60 return;
62 if (conf->secs < 1 || conf->secs > secs_max) {
63 error_setg(errp, "secs must be between 1 and %u", secs_max);
64 return;