]> Git Repo - qemu.git/blame - hw/block/block.c
macio-ide: add to storage category
[qemu.git] / hw / block / block.c
CommitLineData
911525db
MA
1/*
2 * Common code for block device models
3 *
4 * Copyright (C) 2012 Red Hat, Inc.
5 *
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 */
9
9c17d615 10#include "sysemu/blockdev.h"
4be74634 11#include "sysemu/block-backend.h"
0d09e41a 12#include "hw/block/block.h"
1de7afc9 13#include "qemu/error-report.h"
911525db
MA
14
15void blkconf_serial(BlockConf *conf, char **serial)
16{
17 DriveInfo *dinfo;
18
19 if (!*serial) {
20 /* try to fall back to value set with legacy -drive serial=... */
4be74634 21 dinfo = blk_legacy_dinfo(conf->blk);
26f8b3a8
MA
22 if (dinfo) {
23 *serial = g_strdup(dinfo->serial);
24 }
911525db
MA
25 }
26}
b7eb0c9f 27
0eb28a42
ET
28void blkconf_blocksizes(BlockConf *conf)
29{
30 BlockBackend *blk = conf->blk;
31 BlockSizes blocksizes;
32 int backend_ret;
33
34 backend_ret = blk_probe_blocksizes(blk, &blocksizes);
35 /* fill in detected values if they are not defined via qemu command line */
36 if (!conf->physical_block_size) {
37 if (!backend_ret) {
38 conf->physical_block_size = blocksizes.phys;
39 } else {
40 conf->physical_block_size = BDRV_SECTOR_SIZE;
41 }
42 }
43 if (!conf->logical_block_size) {
44 if (!backend_ret) {
45 conf->logical_block_size = blocksizes.log;
46 } else {
47 conf->logical_block_size = BDRV_SECTOR_SIZE;
48 }
49 }
50}
51
5ff5efb4
FZ
52void blkconf_geometry(BlockConf *conf, int *ptrans,
53 unsigned cyls_max, unsigned heads_max, unsigned secs_max,
54 Error **errp)
b7eb0c9f
MA
55{
56 DriveInfo *dinfo;
57
58 if (!conf->cyls && !conf->heads && !conf->secs) {
59 /* try to fall back to value set with legacy -drive cyls=... */
4be74634 60 dinfo = blk_legacy_dinfo(conf->blk);
26f8b3a8
MA
61 if (dinfo) {
62 conf->cyls = dinfo->cyls;
63 conf->heads = dinfo->heads;
64 conf->secs = dinfo->secs;
65 if (ptrans) {
66 *ptrans = dinfo->trans;
67 }
b7eb0c9f
MA
68 }
69 }
70 if (!conf->cyls && !conf->heads && !conf->secs) {
4be74634 71 hd_geometry_guess(conf->blk,
b7eb0c9f
MA
72 &conf->cyls, &conf->heads, &conf->secs,
73 ptrans);
74 } else if (ptrans && *ptrans == BIOS_ATA_TRANSLATION_AUTO) {
75 *ptrans = hd_bios_chs_auto_trans(conf->cyls, conf->heads, conf->secs);
76 }
77 if (conf->cyls || conf->heads || conf->secs) {
78 if (conf->cyls < 1 || conf->cyls > cyls_max) {
5ff5efb4
FZ
79 error_setg(errp, "cyls must be between 1 and %u", cyls_max);
80 return;
b7eb0c9f
MA
81 }
82 if (conf->heads < 1 || conf->heads > heads_max) {
5ff5efb4
FZ
83 error_setg(errp, "heads must be between 1 and %u", heads_max);
84 return;
b7eb0c9f
MA
85 }
86 if (conf->secs < 1 || conf->secs > secs_max) {
5ff5efb4
FZ
87 error_setg(errp, "secs must be between 1 and %u", secs_max);
88 return;
b7eb0c9f
MA
89 }
90 }
b7eb0c9f 91}
This page took 0.22369 seconds and 4 git commands to generate.