aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorbellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>2004-02-16 21:56:36 +0000
committerbellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>2004-02-16 21:56:36 +0000
commitcf98951b82adefb46318b3ed45c8456aac2b9575 (patch)
tree8032f582a72f67740642514317dbc4e41af9fa9c /block.c
parentf72b519c86b0700473155194a39edf937007eab8 (diff)
downloadqemu-cf98951b82adefb46318b3ed45c8456aac2b9575.zip
qemu-cf98951b82adefb46318b3ed45c8456aac2b9575.tar.gz
qemu-cf98951b82adefb46318b3ed45c8456aac2b9575.tar.bz2
force boot sector feature
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@616 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'block.c')
-rw-r--r--block.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/block.c b/block.c
index 3e1ae0d..6a1701a 100644
--- a/block.c
+++ b/block.c
@@ -55,6 +55,9 @@ struct BlockDriverState {
int cow_bitmap_size;
int cow_fd;
int64_t cow_sectors_offset;
+ int boot_sector_enabled;
+ uint8_t boot_sector_data[512];
+
char filename[1024];
};
@@ -262,6 +265,10 @@ int bdrv_read(BlockDriverState *bs, int64_t sector_num,
if (is_changed(bs->cow_bitmap, sector_num, nb_sectors, &n)) {
fd = bs->cow_fd;
offset = bs->cow_sectors_offset;
+ } else if (sector_num == 0 && bs->boot_sector_enabled) {
+ memcpy(buf, bs->boot_sector_data, 512);
+ n = 1;
+ goto next;
} else {
fd = bs->fd;
offset = 0;
@@ -278,6 +285,7 @@ int bdrv_read(BlockDriverState *bs, int64_t sector_num,
return -1;
}
}
+ next:
nb_sectors -= n;
sector_num += n;
buf += n * 512;
@@ -291,7 +299,7 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num,
{
int ret, fd, i;
int64_t offset, retl;
-
+
if (bs->read_only)
return -1;
@@ -324,3 +332,13 @@ void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr)
{
*nb_sectors_ptr = bs->total_sectors;
}
+
+/* force a given boot sector. */
+void bdrv_set_boot_sector(BlockDriverState *bs, const uint8_t *data, int size)
+{
+ bs->boot_sector_enabled = 1;
+ if (size > 512)
+ size = 512;
+ memcpy(bs->boot_sector_data, data, size);
+ memset(bs->boot_sector_data + size, 0, 512 - size);
+}