block: Replace bdrv_get_format() by bdrv_get_format_name()

So callers don't need to know anything about maximum name length.
Returning a pointer is safe, because the name string lives as long as
the block driver it names, and block drivers don't die.

Requested by Peter Maydell.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Markus Armbruster 2012-06-13 10:11:48 +02:00 committed by Kevin Wolf
parent f085800e24
commit f8d6bba1c1
3 changed files with 7 additions and 11 deletions

11
block.c
View File

@ -1035,7 +1035,8 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top)
* swapping bs_new and bs_top contents. */ * swapping bs_new and bs_top contents. */
tmp.backing_hd = bs_new; tmp.backing_hd = bs_new;
pstrcpy(tmp.backing_file, sizeof(tmp.backing_file), bs_top->filename); pstrcpy(tmp.backing_file, sizeof(tmp.backing_file), bs_top->filename);
bdrv_get_format(bs_top, tmp.backing_format, sizeof(tmp.backing_format)); pstrcpy(tmp.backing_format, sizeof(tmp.backing_format),
bs_top->drv ? bs_top->drv->format_name : "");
/* swap contents of the fixed new bs and the current top */ /* swap contents of the fixed new bs and the current top */
*bs_new = *bs_top; *bs_new = *bs_top;
@ -2428,13 +2429,9 @@ int bdrv_set_key(BlockDriverState *bs, const char *key)
return ret; return ret;
} }
void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size) const char *bdrv_get_format_name(BlockDriverState *bs)
{ {
if (!bs->drv) { return bs->drv ? bs->drv->format_name : NULL;
buf[0] = '\0';
} else {
pstrcpy(buf, buf_size, bs->drv->format_name);
}
} }
void bdrv_iterate_format(void (*it)(void *opaque, const char *name), void bdrv_iterate_format(void (*it)(void *opaque, const char *name),

View File

@ -296,7 +296,7 @@ int bdrv_is_inserted(BlockDriverState *bs);
int bdrv_media_changed(BlockDriverState *bs); int bdrv_media_changed(BlockDriverState *bs);
void bdrv_lock_medium(BlockDriverState *bs, bool locked); void bdrv_lock_medium(BlockDriverState *bs, bool locked);
void bdrv_eject(BlockDriverState *bs, bool eject_flag); void bdrv_eject(BlockDriverState *bs, bool eject_flag);
void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size); const char *bdrv_get_format_name(BlockDriverState *bs);
BlockDriverState *bdrv_find(const char *name); BlockDriverState *bdrv_find(const char *name);
BlockDriverState *bdrv_next(BlockDriverState *bs); BlockDriverState *bdrv_next(BlockDriverState *bs);
void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs), void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs),

View File

@ -1107,7 +1107,7 @@ static int img_info(int argc, char **argv)
int c; int c;
const char *filename, *fmt; const char *filename, *fmt;
BlockDriverState *bs; BlockDriverState *bs;
char fmt_name[128], size_buf[128], dsize_buf[128]; char size_buf[128], dsize_buf[128];
uint64_t total_sectors; uint64_t total_sectors;
int64_t allocated_size; int64_t allocated_size;
char backing_filename[1024]; char backing_filename[1024];
@ -1139,7 +1139,6 @@ static int img_info(int argc, char **argv)
if (!bs) { if (!bs) {
return 1; return 1;
} }
bdrv_get_format(bs, fmt_name, sizeof(fmt_name));
bdrv_get_geometry(bs, &total_sectors); bdrv_get_geometry(bs, &total_sectors);
get_human_readable_size(size_buf, sizeof(size_buf), total_sectors * 512); get_human_readable_size(size_buf, sizeof(size_buf), total_sectors * 512);
allocated_size = bdrv_get_allocated_file_size(bs); allocated_size = bdrv_get_allocated_file_size(bs);
@ -1153,7 +1152,7 @@ static int img_info(int argc, char **argv)
"file format: %s\n" "file format: %s\n"
"virtual size: %s (%" PRId64 " bytes)\n" "virtual size: %s (%" PRId64 " bytes)\n"
"disk size: %s\n", "disk size: %s\n",
filename, fmt_name, size_buf, filename, bdrv_get_format_name(bs), size_buf,
(total_sectors * 512), (total_sectors * 512),
dsize_buf); dsize_buf);
if (bdrv_is_encrypted(bs)) { if (bdrv_is_encrypted(bs)) {