Commit cf98951b82adefb46318b3ed45c8456aac2b9575
1 parent
f72b519c
force boot sector feature
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@616 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
19 additions
and
1 deletions
block.c
@@ -55,6 +55,9 @@ struct BlockDriverState { | @@ -55,6 +55,9 @@ struct BlockDriverState { | ||
55 | int cow_bitmap_size; | 55 | int cow_bitmap_size; |
56 | int cow_fd; | 56 | int cow_fd; |
57 | int64_t cow_sectors_offset; | 57 | int64_t cow_sectors_offset; |
58 | + int boot_sector_enabled; | ||
59 | + uint8_t boot_sector_data[512]; | ||
60 | + | ||
58 | char filename[1024]; | 61 | char filename[1024]; |
59 | }; | 62 | }; |
60 | 63 | ||
@@ -262,6 +265,10 @@ int bdrv_read(BlockDriverState *bs, int64_t sector_num, | @@ -262,6 +265,10 @@ int bdrv_read(BlockDriverState *bs, int64_t sector_num, | ||
262 | if (is_changed(bs->cow_bitmap, sector_num, nb_sectors, &n)) { | 265 | if (is_changed(bs->cow_bitmap, sector_num, nb_sectors, &n)) { |
263 | fd = bs->cow_fd; | 266 | fd = bs->cow_fd; |
264 | offset = bs->cow_sectors_offset; | 267 | offset = bs->cow_sectors_offset; |
268 | + } else if (sector_num == 0 && bs->boot_sector_enabled) { | ||
269 | + memcpy(buf, bs->boot_sector_data, 512); | ||
270 | + n = 1; | ||
271 | + goto next; | ||
265 | } else { | 272 | } else { |
266 | fd = bs->fd; | 273 | fd = bs->fd; |
267 | offset = 0; | 274 | offset = 0; |
@@ -278,6 +285,7 @@ int bdrv_read(BlockDriverState *bs, int64_t sector_num, | @@ -278,6 +285,7 @@ int bdrv_read(BlockDriverState *bs, int64_t sector_num, | ||
278 | return -1; | 285 | return -1; |
279 | } | 286 | } |
280 | } | 287 | } |
288 | + next: | ||
281 | nb_sectors -= n; | 289 | nb_sectors -= n; |
282 | sector_num += n; | 290 | sector_num += n; |
283 | buf += n * 512; | 291 | buf += n * 512; |
@@ -291,7 +299,7 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num, | @@ -291,7 +299,7 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num, | ||
291 | { | 299 | { |
292 | int ret, fd, i; | 300 | int ret, fd, i; |
293 | int64_t offset, retl; | 301 | int64_t offset, retl; |
294 | - | 302 | + |
295 | if (bs->read_only) | 303 | if (bs->read_only) |
296 | return -1; | 304 | return -1; |
297 | 305 | ||
@@ -324,3 +332,13 @@ void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr) | @@ -324,3 +332,13 @@ void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr) | ||
324 | { | 332 | { |
325 | *nb_sectors_ptr = bs->total_sectors; | 333 | *nb_sectors_ptr = bs->total_sectors; |
326 | } | 334 | } |
335 | + | ||
336 | +/* force a given boot sector. */ | ||
337 | +void bdrv_set_boot_sector(BlockDriverState *bs, const uint8_t *data, int size) | ||
338 | +{ | ||
339 | + bs->boot_sector_enabled = 1; | ||
340 | + if (size > 512) | ||
341 | + size = 512; | ||
342 | + memcpy(bs->boot_sector_data, data, size); | ||
343 | + memset(bs->boot_sector_data + size, 0, 512 - size); | ||
344 | +} |