On 10/02/2016 02:13 PM, Tomáš Golembiovský wrote: > Added two new options 'offset' and 'size'. This makes it possible to use > only part of the file as a device. This can be used e.g. to limit the > access only to single partition in a disk image or use a disk inside a > tar archive (like OVA). > > For now this is only possible for files in read-only mode. It should be > possible to extend it later to allow read-write mode, but would probably > require that the size of the device is kept constant (i.e. no resizing). > > Signed-off-by: Tomáš Golembiovský <tgole...@redhat.com> > --- > block/raw-posix.c | 97 > +++++++++++++++++++++++++++++++++++++++++++++++++++---- > 1 file changed, 91 insertions(+), 6 deletions(-) >
> + s->offset = qemu_opt_get_size(opts, "offset", 0); > + s->assumed_size = qemu_opt_get_size(opts, BLOCK_OPT_SIZE, 0); > + > + if (((bs->drv != &bdrv_file) || !bs->read_only) && > + ((s->offset > 0) || (s->assumed_size > 0))) { Over-parenthesized. > @@ -443,6 +468,23 @@ static int raw_open_common(BlockDriverState *bs, QDict > *options, > } > s->fd = fd; > > + /* Check size and offset */ > + real_size = raw_getlength_real(bs); > + if (real_size < (s->offset + s->assumed_size)) { > + if (s->assumed_size == 0) { > + error_setg(errp, "The offset has to be smaller than actual size " > + "of the containing file (%ld) ", > + real_size); Won't compile on 32-bit platforms. %ld is not necessarily synonymous with int64_t; you need to use PRId64 instead. Multiple times through your patch. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature