Michael Huang
2011-Jul-07 18:18 UTC
[Libguestfs] hivex patch to solve device or resource busy error when access Windows directory while open system hive
I have found a strange issue related to hivex/ntfs-3g. After opening a system hive on a volume mounted by ntfs-3g, any access to the Windows directory results device or resource busy error. The patch below fix it by closing the hive file handle in hivex_open() call in the writable path because the handle never been used after its content been read into memory. --- hivex-1.2.5.orig/lib/hivex.c 2011-04-13 06:04:49.000000000 -0700 +++ hivex-1.2.5/lib/hivex.c 2011-07-07 09:10:06.927429068 -0700 @@ -321,6 +321,8 @@ if (full_read (h->fd, h->addr, h->size) < h->size) goto error; + close(h->fd); + h->fd = -1; } /* Check header. */ @@ -541,7 +543,10 @@ munmap (h->addr, h->size); else free (h->addr); - r = close (h->fd); + if (h->fd >= 0) + r = close (h->fd); + else + r = 0; free (h->filename); free (h); -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://listman.redhat.com/archives/libguestfs/attachments/20110707/df9faac2/attachment.htm> -------------- next part -------------- A non-text attachment was scrubbed... Name: hivex.c.patch Type: application/octet-stream Size: 499 bytes Desc: hivex.c.patch URL: <http://listman.redhat.com/archives/libguestfs/attachments/20110707/df9faac2/attachment.obj>
Richard W.M. Jones
2011-Jul-08 22:01 UTC
[Libguestfs] hivex patch to solve device or resource busy error when access Windows directory while open system hive
On Thu, Jul 07, 2011 at 06:18:46PM +0000, Michael Huang wrote:> I have found a strange issue related to hivex/ntfs-3g. After opening a system hive on a volume mounted by ntfs-3g, any access to the Windows directory results device or resource busy error. The patch below fix it by closing the hive file handle in hivex_open() call in the writable path because the handle never been used after its content been read into memory. > > --- hivex-1.2.5.orig/lib/hivex.c 2011-04-13 06:04:49.000000000 -0700 > +++ hivex-1.2.5/lib/hivex.c 2011-07-07 09:10:06.927429068 -0700 > @@ -321,6 +321,8 @@ > if (full_read (h->fd, h->addr, h->size) < h->size) > goto error; > + close(h->fd); > + h->fd = -1; > } > /* Check header. */ > @@ -541,7 +543,10 @@ > munmap (h->addr, h->size); > else > free (h->addr); > - r = close (h->fd); > + if (h->fd >= 0) > + r = close (h->fd); > + else > + r = 0; > free (h->filename); > free (h); >Yes, I think from a preliminary look, this is correct. I will take a closer look, test it, and apply it on Monday. Thanks, Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
Richard W.M. Jones
2011-Jul-11 14:08 UTC
[Libguestfs] hivex patch to solve device or resource busy error when access Windows directory while open system hive
On Thu, Jul 07, 2011 at 06:18:46PM +0000, Michael Huang wrote:> I have found a strange issue related to hivex/ntfs-3g. After opening a system hive on a volume mounted by ntfs-3g, any access to the Windows directory results device or resource busy error. The patch below fix it by closing the hive file handle in hivex_open() call in the writable path because the handle never been used after its content been read into memory. > > --- hivex-1.2.5.orig/lib/hivex.c 2011-04-13 06:04:49.000000000 -0700 > +++ hivex-1.2.5/lib/hivex.c 2011-07-07 09:10:06.927429068 -0700 > @@ -321,6 +321,8 @@ > if (full_read (h->fd, h->addr, h->size) < h->size) > goto error; > + close(h->fd); > + h->fd = -1; > } > /* Check header. */ > @@ -541,7 +543,10 @@ > munmap (h->addr, h->size); > else > free (h->addr); > - r = close (h->fd); > + if (h->fd >= 0) > + r = close (h->fd); > + else > + r = 0; > free (h->filename); > free (h); >I've pushed this, slightly modified. Thanks for your contribution! Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/
Seemingly Similar Threads
- Patch to build hivex lib on Windows
- [PATCH v4 0/5] hivex: handle corrupted hives better.
- [PATCH v2 0/2] hivex: handle corrupted hives better
- [hivex] [PATCH 1/2] hivex: Expose hive major and minor version
- [PATCH] Report last-modified time of hive root and nodes