Richard W.M. Jones
2010-Dec-16 20:28 UTC
[Libguestfs] [PATCH 0/2] Document problems with symlinks on NTFS
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://et.redhat.com/~rjones/libguestfs/ See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html
Richard W.M. Jones
2010-Dec-16 20:28 UTC
[Libguestfs] [PATCH 1/2] New APIs: getxattr and lgetxattr to get single extended attributes.
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v -------------- next part -------------->From 3a3836b933b80c4f9f2c767fda4f8b459f998db2 Mon Sep 17 00:00:00 2001From: Richard W.M. Jones <rjones at redhat.com> Date: Thu, 16 Dec 2010 20:05:48 +0000 Subject: [PATCH 1/2] New APIs: getxattr and lgetxattr to get single extended attributes. These APIs are essentially required to work around a problem with ntfs-3g. This filesystem (or FUSE?) does not list all extended attributes of a file when you call listxattr(2). However if you know the name of an extended attribute, you can retrieve it directly using getxattr(2). The current APIs (getxattrs etc) are simple to use, but they don't work if we can't list out the extended attributes (ie. by calling listxattr(2)). Example using the new APIs on an ntfs-3g filesystem:><fs> lgetxattr "/Documents and Settings" system.ntfs_attrib | hexdump -C00000000 16 24 00 00 |.$..| 00000004><fs> lgetxattr "/Documents and Settings" system.ntfs_reparse_data | hexdump -C00000000 03 00 00 a0 34 00 00 00 00 00 18 00 1a 00 10 00 |....4...........| 00000010 5c 00 3f 00 3f 00 5c 00 43 00 3a 00 5c 00 55 00 |\.?.?.\.C.:.\.U.| 00000020 73 00 65 00 72 00 73 00 00 00 43 00 3a 00 5c 00 |s.e.r.s...C.:.\.| 00000030 55 00 73 00 65 00 72 00 73 00 00 00 |U.s.e.r.s...| 0000003c><fs> getxattr "/Documents and Settings" system.ntfs_reparse_data | hexdump -Clibguestfs: error: getxattr: getxattr: No such file or directory><fs> getxattr "/Documents and Settings" system.ntfs_attrib | hexdump -Clibguestfs: error: getxattr: getxattr: No such file or directory><fs> lgetxattr "/Documents and Settings" system.ntfs_attrib | hexdump -C00000000 16 24 00 00 |.$..| 00000004><fs> getxattr "/Users" system.ntfs_attrib | hexdump -C00000000 11 00 00 00 |....| 00000004 --- daemon/xattr.c | 96 ++++++++++++++++++++++++++++++++++++++++ generator/generator_actions.ml | 40 +++++++++++++++++ src/MAX_PROC_NR | 2 +- 3 files changed, 137 insertions(+), 1 deletions(-) diff --git a/daemon/xattr.c b/daemon/xattr.c index a5169cf..bbccc5c 100644 --- a/daemon/xattr.c +++ b/daemon/xattr.c @@ -448,6 +448,90 @@ do_lxattrlist (const char *path, char *const *names) #endif } +char * +do_getxattr (const char *path, const char *name, size_t *size_r) +{ + ssize_t r; + char *buf; + size_t len; + + CHROOT_IN; + r = getxattr (path, name, NULL, 0); + CHROOT_OUT; + if (r == -1) { + reply_with_perror ("getxattr"); + return NULL; + } + + len = r; + buf = malloc (len); + if (buf == NULL) { + reply_with_perror ("malloc"); + return NULL; + } + + CHROOT_IN; + r = getxattr (path, name, buf, len); + CHROOT_OUT; + if (r == -1) { + reply_with_perror ("getxattr"); + free (buf); + return NULL; + } + + if (len != (size_t) r) { + reply_with_error ("getxattr: unexpected size (%zu/%zd)", len, r); + free (buf); + return NULL; + } + + /* Must set size_r last thing before returning. */ + *size_r = len; + return buf; /* caller frees */ +} + +char * +do_lgetxattr (const char *path, const char *name, size_t *size_r) +{ + ssize_t r; + char *buf; + size_t len; + + CHROOT_IN; + r = lgetxattr (path, name, NULL, 0); + CHROOT_OUT; + if (r == -1) { + reply_with_perror ("lgetxattr"); + return NULL; + } + + len = r; + buf = malloc (len); + if (buf == NULL) { + reply_with_perror ("malloc"); + return NULL; + } + + CHROOT_IN; + r = lgetxattr (path, name, buf, len); + CHROOT_OUT; + if (r == -1) { + reply_with_perror ("lgetxattr"); + free (buf); + return NULL; + } + + if (len != (size_t) r) { + reply_with_error ("lgetxattr: unexpected size (%zu/%zd)", len, r); + free (buf); + return NULL; + } + + /* Must set size_r last thing before returning. */ + *size_r = len; + return buf; /* caller frees */ +} + #else /* no xattr.h */ int optgroup_linuxxattrs_available (void) @@ -497,4 +581,16 @@ do_lxattrlist (const char *path, char *const *names) NOT_AVAILABLE (NULL); } +char * +do_getxattr (const char *path, const char *name, size_t *size_r) +{ + NOT_AVAILABLE (NULL); +} + +char * +do_lgetxattr (const char *path, const char *name, size_t *size_r) +{ + NOT_AVAILABLE (NULL); +} + #endif /* no xattr.h */ diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index 5624dec..84e8eee 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -5633,6 +5633,46 @@ the requested cluster size. =back"); + ("getxattr", (RBufferOut "xattr", [Pathname "path"; String "name"], []), 279, [Optional "linuxxattrs"], + [], + "get a single extended attribute", + "\ +Get a single extended attribute from file C<path> named C<name>. +This call follows symlinks. If you want to lookup an extended +attribute for the symlink itself, use C<guestfs_lgetxattr>. + +Normally it is better to get all extended attributes from a file +in one go by calling C<guestfs_getxattrs>. However some Linux +filesystem implementations are buggy and do not provide a way to +list out attributes. For these filesystems (notably ntfs-3g) +you have to know the names of the extended attributes you want +in advance and call this function. + +Extended attribute values are blobs of binary data. If there +is no extended attribute named C<name>, this returns an error. + +See also: C<guestfs_getxattrs>, C<guestfs_lgetxattr>, L<attr(5)>."); + + ("lgetxattr", (RBufferOut "xattr", [Pathname "path"; String "name"], []), 280, [Optional "linuxxattrs"], + [], + "get a single extended attribute", + "\ +Get a single extended attribute from file C<path> named C<name>. +If C<path> is a symlink, then this call returns an extended +attribute from the symlink. + +Normally it is better to get all extended attributes from a file +in one go by calling C<guestfs_getxattrs>. However some Linux +filesystem implementations are buggy and do not provide a way to +list out attributes. For these filesystems (notably ntfs-3g) +you have to know the names of the extended attributes you want +in advance and call this function. + +Extended attribute values are blobs of binary data. If there +is no extended attribute named C<name>, this returns an error. + +See also: C<guestfs_lgetxattrs>, C<guestfs_getxattr>, L<attr(5)>."); + ] let all_functions = non_daemon_functions @ daemon_functions diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 3d242f5..1b1c131 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -278 +280 -- 1.7.3.3
Richard W.M. Jones
2010-Dec-16 20:29 UTC
[Libguestfs] [PATCH 2/2] ntfs-3g: Document problems with symlinks and alternatives (RHBZ#663407).
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v -------------- next part -------------->From 933e970b8ac654586bc3595f56b187fab65b1173 Mon Sep 17 00:00:00 2001From: Richard W.M. Jones <rjones at redhat.com> Date: Thu, 16 Dec 2010 20:23:17 +0000 Subject: [PATCH 2/2] ntfs-3g: Document problems with symlinks and alternatives (RHBZ#663407). --- src/guestfs.pod | 31 +++++++++++++++++++++++++++++++ 1 files changed, 31 insertions(+), 0 deletions(-) diff --git a/src/guestfs.pod b/src/guestfs.pod index 9cf66f3..bb90de8 100644 --- a/src/guestfs.pod +++ b/src/guestfs.pod @@ -587,6 +587,8 @@ documentation for that function for details). Libguestfs can mount NTFS partitions. It does this using the L<http://www.ntfs-3g.org/> driver. +=head3 DRIVE LETTERS AND PATHS + DOS and Windows still use drive letters, and the filesystems are always treated as case insensitive by Windows itself, and therefore you might find a Windows configuration file referring to a path like @@ -604,6 +606,8 @@ outside the scope of libguestfs, but something that you can easily do. Where we can help is in resolving the case insensitivity of paths. For this, call L</guestfs_case_sensitive_path>. +=head3 ACCESSING THE WINDOWS REGISTRY + Libguestfs also provides some help for decoding Windows Registry "hive" files, through the library C<hivex> which is part of the libguestfs project although ships as a separate tarball. You have to @@ -612,6 +616,33 @@ C<hivex> functions. See also the programs L<hivexml(1)>, L<hivexsh(1)>, L<hivexregedit(1)> and L<virt-win-reg(1)> for more help on this issue. +=head3 SYMLINKS ON NTFS-3G FILESYSTEMS + +Ntfs-3g tries to rewrite "Junction Points" and NTFS "symbolic links" +to provide something which looks like a Linux symlink. The way it +tries to do the rewriting is described here: + +L<http://www.tuxera.com/community/ntfs-3g-advanced/junction-points-and-symbolic-links/> + +The essential problem is that ntfs-3g simply does not have enough +information to do a correct job. NTFS links can contain drive letters +and references to external device GUIDs that ntfs-3g has no way of +resolving. It is almost certainly the case that libguestfs callers +should ignore what ntfs-3g does (ie. don't use L</guestfs_readlink> on +NTFS volumes). + +Instead if you encounter a symbolic link on an ntfs-3g filesystem, use +L</guestfs_lgetxattr> to read the C<system.ntfs_reparse_data> extended +attribute, and read the raw reparse data from that (you can find the +format documented in various places around the web). + +=head3 EXTENDED ATTRIBUTES ON NTFS-3G FILESYSTEMS + +There are other useful extended attributes that can be read from +ntfs-3g filesystems (using L</guestfs_getxattr>). See: + +L<http://www.tuxera.com/community/ntfs-3g-advanced/extended-attributes/> + =head2 USING LIBGUESTFS WITH OTHER PROGRAMMING LANGUAGES Although we don't want to discourage you from using the C API, we will -- 1.7.3.3
Maybe Matching Threads
- [PATCH 0/10] Miscellaneous patches to fix some compile problems on Mac OS X
- [PATCH 0/3] Fix resolving absolute symlinks (RHBZ#579608).
- [PATCH 0/3] Build fixes for gcc 4.5
- [PATCH 0/9] Enhance virt-resize so it can really expand Linux and Windows guests
- [PATCH 0/5] Add new tools virt-tar and virt-ls and tidy up the tools code