Merge tag 'seabios-1.16.1-20221128-pull-request' of https://gitlab.com/kraxel/qemu...
[qemu/ar7.git] / util / block-helpers.c
blobc4851432f56601158becd975f49c62dc7dfbbb74
1 /*
2 * Block utility functions
4 * Copyright IBM, Corp. 2011
5 * Copyright (c) 2020 Coiby Xu <coiby.xu@gmail.com>
7 * This work is licensed under the terms of the GNU GPL, version 2 or later.
8 * See the COPYING file in the top-level directory.
9 */
11 #include "qemu/osdep.h"
12 #include "qapi/error.h"
13 #include "qapi/qmp/qerror.h"
14 #include "block-helpers.h"
16 /**
17 * check_block_size:
18 * @id: The unique ID of the object
19 * @name: The name of the property being validated
20 * @value: The block size in bytes
21 * @errp: A pointer to an area to store an error
23 * This function checks that the block size meets the following conditions:
24 * 1. At least MIN_BLOCK_SIZE
25 * 2. No larger than MAX_BLOCK_SIZE
26 * 3. A power of 2
28 void check_block_size(const char *id, const char *name, int64_t value,
29 Error **errp)
31 /* value of 0 means "unset" */
32 if (value && (value < MIN_BLOCK_SIZE || value > MAX_BLOCK_SIZE)) {
33 error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
34 id, name, value, MIN_BLOCK_SIZE, MAX_BLOCK_SIZE);
35 return;
38 /* We rely on power-of-2 blocksizes for bitmasks */
39 if ((value & (value - 1)) != 0) {
40 error_setg(errp,
41 "Property %s.%s doesn't take value '%" PRId64
42 "', it's not a power of 2",
43 id, name, value);
44 return;