Mailing List Archive

Problem with writing to a VHD disk directly using blktap/libvhd
Hello all,

I don't know whether here is the right place for asking my question or not.
Actually I want to write a program for encrypting vhd disk sector by
sector. I couldn't find any library to do it so I started to do it my self.

Now I'm trying to write a char array to a vhd disk using libvhd. But it
failes with 'error number -22' ( -EINVAL /* Invalid argument */). There is
no problem in opening and reading vhd disks using libvhd, but I can't find
the problem that causes the error when writing. Here is part of my code
for writing:

vhd_context_t *ctx = NULL;int size,err;int z;
char *buf =(char *)malloc(VHD_SECTOR_SIZE);
z=vhd_unix_open("/home/zahra/Desktop/zahra/macemu/sys.vhd", &size, false, &ctx);
printf("z: %d \n",z);/*reading a sector from a vhd disk*/if ((err =
vhd_io_read(ctx, buf, (uint64_t)0 ,(uint32_t) 1))){
printf("vhd read error %d \n", err);
}
BIO_dump_fp (stdout, (const char *)buf, size_t
(VHD_SECTOR_SIZE));/*reading is OK*//*writing check*/
char * plaintext= (char *)"This is a writing test"; if ((err =
vhd_io_write(ctx,plaintext ,(uint64_t)0 ,(uint32_t)1))) {
printf("vhd write error %d\n", err);
printf("vhd footer current size %lld\n", ctx->footer.curr_size);}

Writing fails with 'vhd write error -22'.

Thank you,

Zahra