[hivex] [PATCH v5 0/8] Add byte run reporting to hivexml
by Alex Nelson
This patch series completes byte run outputting for long values.
Several unit tests are now in place for the new RLenValue generator
type, including one added example unit test for Perl. An additional
hive file, rlenvalue_test_hive, is included specifically to test the
positions of non-inline values.
Alex Nelson (8):
Add test hive and generator script
generator: Add new return type to ABI: RLenValue
hivex: Add offset-&-length function for long value data
ocaml: Add unit test for new RLenValue type
perl: Add unit test for enw RLenValue type
python: Add unit test for new RLenValue type
ruby: Add unit test for new RLenValue type
hivexml: Add byte run reporting functions
.gitignore | 1 +
generator/generator.ml | 90 +++++++++++++++++++++++++++++++++
images/mkrlenvalue_test_hive.py | 37 ++++++++++++++
images/rlenvalue_test_hive | Bin 0 -> 12288 bytes
lib/hivex.c | 60 ++++++++++++++++++++++
ocaml/Makefile.am | 1 +
ocaml/t/hivex_120_rlenvalue.ml | 43 ++++++++++++++++
perl/t/120-rlenvalue.t | 46 +++++++++++++++++
python/t/120-rlenvalue.py | 42 ++++++++++++++++
ruby/tests/tc_120_rlenvalue.rb | 46 +++++++++++++++++
xml/hivexml.c | 104 +++++++++++++++++++++++++++++++++++---
11 files changed, 461 insertions(+), 9 deletions(-)
create mode 100755 images/mkrlenvalue_test_hive.py
create mode 100644 images/rlenvalue_test_hive
create mode 100644 ocaml/t/hivex_120_rlenvalue.ml
create mode 100644 perl/t/120-rlenvalue.t
create mode 100644 python/t/120-rlenvalue.py
create mode 100644 ruby/tests/tc_120_rlenvalue.rb
--
1.7.6.4
12 years, 11 months
guestmount - unable to get device geometry
by Evaggelos Balaskas
Hi,
i am trying to use libguestfs (libvirt/kvm etc) into archlinux.
But it seems that i am keep getting this error
warning: Unable to get device geometry for /var/tmp/guestfs.NwkQVJ/root
In the attached file, i've written some debug info.
If someone can give me some pointer, i would appreciate it
Evaggelos Balaskas
Unix System Engineer - http://ebalaskas.gr.
12 years, 11 months
[PATCH] let the user explicitly choose ruby and rake programs
by Hilko Bengen
---
configure.ac | 4 +++-
ruby/Makefile.am | 11 ++++++-----
ruby/Rakefile.in | 2 +-
ruby/run-bindtests | 2 +-
ruby/run-ruby-tests | 4 ++--
5 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/configure.ac b/configure.ac
index ea0aec4..130db51 100644
--- a/configure.ac
+++ b/configure.ac
@@ -769,8 +769,10 @@ AC_ARG_ENABLE([ruby],
[enable_ruby=yes])
AS_IF([test "x$enable_ruby" != "xno"],
[
- AC_CHECK_LIB([ruby],[ruby_init],[HAVE_LIBRUBY=1],[HAVE_LIBRUBY=0])
+ AC_CHECK_PROG([RUBY],[ruby],[ruby],[no])
AC_CHECK_PROG([RAKE],[rake],[rake],[no])
+ AC_CHECK_LIB([ruby],[ruby_init],[HAVE_LIBRUBY=1],[HAVE_LIBRUBY=0])
+ AC_SUBST([RAKE])
])
AM_CONDITIONAL([HAVE_RUBY],
[test "x$RAKE" != "xno" && test -n "$HAVE_LIBRUBY"])
diff --git a/ruby/Makefile.am b/ruby/Makefile.am
index 757855a..8139140 100644
--- a/ruby/Makefile.am
+++ b/ruby/Makefile.am
@@ -49,14 +49,15 @@ TESTS = run-bindtests run-ruby-tests
TESTS_ENVIRONMENT = \
LD_LIBRARY_PATH=$(top_builddir)/src/.libs \
LIBGUESTFS_PATH=$(top_builddir)/appliance \
- TMPDIR=$(top_builddir)
+ TMPDIR=$(top_builddir) \
+ RUBY=$(RUBY)
all: $(generator_built)
- rake build
- rake rdoc
+ $(RAKE) build
+ $(RAKE) rdoc
-RUBY_SITELIB := $(shell ruby -rrbconfig -e "puts Config::CONFIG['sitelibdir']")
-RUBY_SITEARCH := $(shell ruby -rrbconfig -e "puts Config::CONFIG['sitearchdir']")
+RUBY_SITELIB := $(shell $(RUBY) -rrbconfig -e "puts Config::CONFIG['sitelibdir']")
+RUBY_SITEARCH := $(shell $(RUBY) -rrbconfig -e "puts Config::CONFIG['sitearchdir']")
install:
$(MKDIR_P) $(DESTDIR)$(RUBY_SITELIB)
diff --git a/ruby/Rakefile.in b/ruby/Rakefile.in
index f4bf901..9ae993b 100644
--- a/ruby/Rakefile.in
+++ b/ruby/Rakefile.in
@@ -38,7 +38,7 @@ CLOBBER.include [ "@builddir(a)/config.save", "@builddir(a)/ext/**/mkmf.log",
# Build locally
file MAKEFILE => EXT_CONF do |t|
- unless sh "top_srcdir=$(pwd)/@top_srcdir@; top_builddir=$(pwd)/@top_builddir@; export ARCHFLAGS=\"-arch $(uname -m)\"; mkdir -p @builddir@/ext/guestfs; cd @builddir@/ext/guestfs; ruby #{EXT_CONF} --with-_guestfs-include=$top_srcdir/src --with-_guestfs-lib=$top_builddir/src/.libs"
+ unless sh "top_srcdir=$(pwd)/@top_srcdir@; top_builddir=$(pwd)/@top_builddir@; export ARCHFLAGS=\"-arch $(uname -m)\"; mkdir -p @builddir@/ext/guestfs; cd @builddir@/ext/guestfs; @RUBY@ #{EXT_CONF} --with-_guestfs-include=$top_srcdir/src --with-_guestfs-lib=$top_builddir/src/.libs"
$stderr.puts "Failed to run extconf"
break
end
diff --git a/ruby/run-bindtests b/ruby/run-bindtests
index 4cac863..aafcfba 100755
--- a/ruby/run-bindtests
+++ b/ruby/run-bindtests
@@ -18,5 +18,5 @@
set -e
-ruby -I${srcdir}/lib -Iext/guestfs ${srcdir}/bindtests.rb > bindtests.tmp
+$RUBY -I${srcdir}/lib -Iext/guestfs ${srcdir}/bindtests.rb > bindtests.tmp
diff -u ${srcdir}/../bindtests bindtests.tmp
diff --git a/ruby/run-ruby-tests b/ruby/run-ruby-tests
index e21899a..c618241 100755
--- a/ruby/run-ruby-tests
+++ b/ruby/run-ruby-tests
@@ -22,6 +22,6 @@ set -e
# is bound to fail because they all use a single test image file).
for f in tests/tc_*.rb; do
- echo rake test "$@" TEST="$f"
- rake test "$@" TEST="$f"
+ echo $RAKE test "$@" TEST="$f"
+ $RAKE test "$@" TEST="$f"
done
--
1.7.7.3
12 years, 11 months
[PATCH] Fix rpcgen post-processing for out-of-tree builds
by Hilko Bengen
---
fish/Makefile.am | 2 +-
src/Makefile.am | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/fish/Makefile.am b/fish/Makefile.am
index 6ca8a82..16a29b0 100644
--- a/fish/Makefile.am
+++ b/fish/Makefile.am
@@ -139,7 +139,7 @@ if HAVE_RPCGEN
rc_protocol.c: rc_protocol.x
rm -f $@-t $@-t2
$(RPCGEN) -c -o $@-t $<
- sed 's,\.\./\.\./fish/,,' < $@-t > $@-t2
+ sed 's,\.\./\(\.\./\)*fish,.,' < $@-t > $@-t2
rm $@-t
mv $@-t2 $@
diff --git a/src/Makefile.am b/src/Makefile.am
index 82a4004..28a1b92 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -171,7 +171,7 @@ if HAVE_RPCGEN
guestfs_protocol.c: guestfs_protocol.x
rm -f $@-t $@-t2
$(RPCGEN) -c -o $@-t $(srcdir)/$<
- sed 's,\.\./\.\./src/,,' < $@-t > $@-t2
+ sed 's,\.\./\(\.\./\)*src,.,' < $@-t > $@-t2
rm $@-t
mv $@-t2 $@
--
1.7.7.3
12 years, 11 months
Re: [Libguestfs] P2Vs seem to require a very robust Ethernet
by Greg Scott
I did one with ntbackup and restore a few months ago and ran into problems
with the virtual cpu not matching the virtual bios. That one was in a
libvirt environment and that VM will retire soon. But with the current
project, these VMs will be around a while.
Sent from my Droid Charge on Verizon 4GLTE
Matthew Booth <mbooth(a)redhat.com> wrote:
On 12/02/2011 03:12 AM, Greg Scott wrote:
> Hey Matt -
>
> With a new release of virt-v2v a while away, what if we were to try a
> P2V by hand? I'm thinking of maybe provisioning a Windows RHEV VM,
> doing an ntbackup of the source physical machine and doing a bare metal
> restore on the VM. I've done it that way before with mixed results.
>
> We have that hack I put together to load the viostor block driver stuff
> on the source machine so the target VM will boot. Are there any HAL
> kinds of things or other hardware/firmware issues we need to also be
> thinking about?
Windows mostly fixes itself. If it boots and you don't see any missing
drivers in Device Manager, you're probably good to go.
Matt
--
Matthew Booth, RHCA, RHCSS
Red Hat Engineering, Virtualisation Team
GPG ID: D33C3490
GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490
12 years, 11 months
New release 0.8.5 of virt-v2v and virt-p2v
by Matthew Booth
We just released virt-v2v 0.8.5, which also covers virt-p2v. This is
primarily a bugfix release, with a couple of new features thrown in. The
major changes are summarised below:
V2V
***
* Default -ic and -oc to qemu:///session or qemu:///system as
appropriate depending on root.
* Allow Windows conversions to succeed when firstboot.bat, rhsrvany.exe
and rhev-apt.exe aren't available.
* Include rhsrvany.exe in default packaging.
* Fix various crashes.
P2V Client
**********
* Support for NetworkManager 0.9.
* Fix no cursor on startup issue.
* Fix percentages displayed by progress bar during transfer.
* More robust error handling.
* Fix various crashes.
* Support machines with cciss devices.
* Add a console on tty2 for debugging during P2V.
P2V Image Builder
*****************
* Support RHEL 6 and F16
New Fedora packages will be available in F16 updates-testing shortly.
Note that the P2V client is built by running virt-p2v-image-builder
which, by default, creates an ISO image from the current stable Fedora
repositories. This means that until this update makes it into stable you
will have to manually add updates-testing when building the P2V image,
for example:
virt-p2v-image-builder -a
http://download.fedora.redhat.com/pub/fedora/linux/updates/testing/16/i386
If you don't do this, you'll be testing the older version of virt-p2v
from stable. Also note that you have to add the i386 repository
specifically, as we only build for i386. This image is also able to
convert x86_64 machines.
Happy testing,
Matt
--
Matthew Booth, RHCA, RHCSS
Red Hat Engineering, Virtualisation Team
GPG ID: D33C3490
GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490
12 years, 11 months
[hivex][PATCH 2/8] generator: Add new return type to ABI: RLenValue
by Alex Nelson
RLenValue is similar to RLenType, though with one less argument. This
required adding additional conversion functions for several languages'
bindings.
Signed-off-by: Alex Nelson <ajnelson(a)cs.ucsc.edu>
---
generator/generator.ml | 78 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 78 insertions(+), 0 deletions(-)
diff --git a/generator/generator.ml b/generator/generator.ml
index def516f..7ece245 100755
--- a/generator/generator.ml
+++ b/generator/generator.ml
@@ -51,6 +51,7 @@ and ret =
| RNodeList (* Returns hive_node_h* or NULL. *)
| RValue (* Returns hive_value_h or 0. *)
| RValueList (* Returns hive_value_h* or NULL. *)
+ | RLenValue (* Returns offset and length of value. *)
| RString (* Returns char* or NULL. *)
| RStringList (* Returns char** or NULL. *)
| RLenType (* See hivex_value_type. *)
@@ -888,6 +889,7 @@ and generate_c_prototype ?(extern = false) name style =
| RValueList -> pr "hive_value_h *"
| RString -> pr "char *"
| RStringList -> pr "char **"
+ | RLenValue -> pr "hive_value_h "
| RLenType -> pr "int "
| RLenTypeVal -> pr "char *"
| RInt32 -> pr "int32_t "
@@ -909,6 +911,7 @@ and generate_c_prototype ?(extern = false) name style =
) (snd style);
(match fst style with
| RLenType | RLenTypeVal -> pr ", hive_type *t, size_t *len"
+ | RLenValue -> pr ", size_t *len"
| _ -> ()
);
pr ");\n"
@@ -1111,6 +1114,10 @@ On error this returns NULL and sets errno.\n\n"
pr "\
Returns 0 on success.
On error this returns -1 and sets errno.\n\n"
+ | RLenValue ->
+ pr "\
+Returns a value handle.
+On error this returns 0 and sets errno.\n\n"
| RLenTypeVal ->
pr "\
The value is returned as an array of bytes (of length C<len>).
@@ -1622,6 +1629,7 @@ and generate_ocaml_prototype ?(is_external = false) name style =
| RString -> pr "string"
| RStringList -> pr "string array"
| RLenType -> pr "hive_type * int"
+ | RLenValue -> pr "value * int"
| RLenTypeVal -> pr "hive_type * string"
| RInt32 -> pr "int32"
| RInt64 -> pr "int64"
@@ -1685,6 +1693,7 @@ static hive_type HiveType_val (value);
static value Val_hive_type (hive_type);
static value copy_int_array (size_t *);
static value copy_type_len (size_t, hive_type);
+static value copy_len_value (size_t, hive_value_h);
static value copy_type_value (const char *, size_t, hive_type);
static void raise_error (const char *) Noreturn;
static void raise_closed (const char *) Noreturn;
@@ -1707,6 +1716,7 @@ static void raise_closed (const char *) Noreturn;
let c_params =
match fst style with
| RLenType | RLenTypeVal -> c_params @ [["&t"; "&len"]]
+ | RLenValue -> c_params @ [["&len"]]
| _ -> c_params in
let c_params = List.concat c_params in
@@ -1779,6 +1789,11 @@ static void raise_closed (const char *) Noreturn;
pr " size_t len;\n";
pr " hive_type t;\n";
"-1"
+ | RLenValue ->
+ pr " errno = 0;";
+ pr " hive_value_h r;\n";
+ pr " size_t len;\n";
+ "0 && errno != 0"
| RLenTypeVal ->
pr " char *r;\n";
pr " size_t len;\n";
@@ -1859,6 +1874,7 @@ static void raise_closed (const char *) Noreturn;
pr " for (int i = 0; r[i] != NULL; ++i) free (r[i]);\n";
pr " free (r);\n"
| RLenType -> pr " rv = copy_type_len (len, t);\n"
+ | RLenValue -> pr " rv = copy_len_value (len, r);\n"
| RLenTypeVal ->
pr " rv = copy_type_value (r, len, t);\n";
pr " free (r);\n"
@@ -1981,6 +1997,20 @@ copy_type_len (size_t len, hive_type t)
}
static value
+copy_len_value (size_t len, hive_value_h r)
+{
+ CAMLparam0 ();
+ CAMLlocal2 (v, rv);
+
+ rv = caml_alloc (2, 0);
+ v = Val_int (len);
+ Store_field (rv, 0, v);
+ v = Val_int (r);
+ Store_field (rv, 1, v);
+ CAMLreturn (rv);
+}
+
+static value
copy_type_value (const char *r, size_t len, hive_type t)
{
CAMLparam0 ();
@@ -2170,6 +2200,7 @@ sub open {
| RString
| RStringList
| RLenType
+ | RLenValue
| RLenTypeVal
| RInt32
| RInt64 -> ()
@@ -2244,6 +2275,7 @@ and generate_perl_prototype name style =
| RString -> pr "$string = "
| RStringList -> pr "@strings = "
| RLenType -> pr "($type, $len) = "
+ | RLenValue -> pr "($len, $value) = "
| RLenTypeVal -> pr "($type, $data) = "
| RInt32 -> pr "$int32 = "
| RInt64 -> pr "$int64 = "
@@ -2467,6 +2499,7 @@ DESTROY (h)
| RValueList
| RStringList
| RLenType
+ | RLenValue
| RLenTypeVal -> pr "void\n"
| RInt32 -> pr "SV *\n"
| RInt64 -> pr "SV *\n"
@@ -2639,6 +2672,22 @@ DESTROY (h)
pr " PUSHs (sv_2mortal (newSViv (type)));\n";
pr " PUSHs (sv_2mortal (newSViv (len)));\n";
+ | RLenValue ->
+ pr "PREINIT:\n";
+ pr " hive_value_h r;\n";
+ pr " size_t len;\n";
+ pr " PPCODE:\n";
+ pr " errno = 0;\n";
+ pr " r = hivex_%s (%s, &len);\n"
+ name (String.concat ", " c_params);
+ free_args ();
+ pr " if (r == 0 && errno)\n";
+ pr " croak (\"%%s: \", \"%s\", strerror (errno));\n"
+ name;
+ pr " EXTEND (SP, 2);\n";
+ pr " PUSHs (sv_2mortal (newSViv (len)));\n";
+ pr " PUSHs (sv_2mortal (newSViv (r)));\n";
+
| RLenTypeVal ->
pr "PREINIT:\n";
pr " char *r;\n";
@@ -2877,6 +2926,15 @@ put_len_type (size_t len, hive_type t)
}
static PyObject *
+put_len_val (size_t len, hive_value_h value)
+{
+ PyObject *r = PyTuple_New (2);
+ PyTuple_SetItem (r, 0, PyLong_FromLongLong ((long) len));
+ PyTuple_SetItem (r, 1, PyLong_FromLongLong ((long) value));
+ return r;
+}
+
+static PyObject *
put_val_type (char *val, size_t len, hive_type t)
{
PyObject *r = PyTuple_New (2);
@@ -2916,6 +2974,11 @@ put_val_type (char *val, size_t len, hive_type t)
pr " size_t len;\n";
pr " hive_type t;\n";
"-1"
+ | RLenValue ->
+ pr " errno = 0;\n";
+ pr " int r;\n";
+ pr " size_t len;\n";
+ "0 && errno != 0"
| RLenTypeVal ->
pr " char *r;\n";
pr " size_t len;\n";
@@ -2940,6 +3003,7 @@ put_val_type (char *val, size_t len, hive_type t)
let c_params =
match fst style with
| RLenType | RLenTypeVal -> c_params @ ["&t"; "&len"]
+ | RLenValue -> c_params @ ["&len"]
| _ -> c_params in
List.iter (
@@ -3084,6 +3148,8 @@ put_val_type (char *val, size_t len, hive_type t)
pr " free_strings (r);\n"
| RLenType ->
pr " py_r = put_len_type (len, t);\n"
+ | RLenValue ->
+ pr " py_r = put_len_val (len, r);\n"
| RLenTypeVal ->
pr " py_r = put_val_type (r, len, t);\n";
pr " free (r);\n"
@@ -3294,6 +3360,7 @@ get_values (VALUE valuesv, size_t *nr_values)
| RString -> "string"
| RStringList -> "list"
| RLenType -> "hash"
+ | RLenValue -> "integer"
| RLenTypeVal -> "hash"
| RInt32 -> "integer"
| RInt64 -> "integer" in
@@ -3392,6 +3459,11 @@ get_values (VALUE valuesv, size_t *nr_values)
pr " size_t len;\n";
pr " hive_type t;\n";
"-1"
+ | RLenValue ->
+ pr " errno = 0;\n";
+ pr " hive_value_h r;\n";
+ pr " size_t len;\n";
+ "0 && errno != 0"
| RLenTypeVal ->
pr " char *r;\n";
pr " size_t len;\n";
@@ -3416,6 +3488,7 @@ get_values (VALUE valuesv, size_t *nr_values)
let c_params =
match ret with
| RLenType | RLenTypeVal -> c_params @ [["&t"; "&len"]]
+ | RLenValue -> c_params @ [["&len"]]
| _ -> c_params in
let c_params = List.concat c_params in
@@ -3497,6 +3570,11 @@ get_values (VALUE valuesv, size_t *nr_values)
pr " rb_hash_aset (rv, ID2SYM (rb_intern (\"len\")), INT2NUM (len));\n";
pr " rb_hash_aset (rv, ID2SYM (rb_intern (\"type\")), INT2NUM (t));\n";
pr " return rv;\n"
+ | RLenValue ->
+ pr " VALUE rv = rb_hash_new ();\n";
+ pr " rb_hash_aset (rv, ID2SYM (rb_intern (\"len\")), INT2NUM (len));\n";
+ pr " rb_hash_aset (rv, ID2SYM (rb_intern (\"off\")), ULL2NUM (r));\n";
+ pr " return rv;\n"
| RLenTypeVal ->
pr " VALUE rv = rb_hash_new ();\n";
pr " rb_hash_aset (rv, ID2SYM (rb_intern (\"len\")), INT2NUM (len));\n";
--
1.7.4.4
12 years, 11 months
[PATCH] mdadm: fix a possible memory leak when error
by Wanlong Gao
When add_string() error, it returned without free the *ret*.
Signed-off-by: Wanlong Gao <gaowanlong(a)cn.fujitsu.com>
---
daemon/md.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/daemon/md.c b/daemon/md.c
index 5a4d815..8d28878 100644
--- a/daemon/md.c
+++ b/daemon/md.c
@@ -294,12 +294,12 @@ do_md_detail(const char *md)
}
}
+ if (add_string(&ret, &size, &alloc, NULL) == -1) goto error;
+
free(out);
free(err);
free(lines); /* We freed the contained strings when we freed out */
- if (add_string(&ret, &size, &alloc, NULL) == -1) return NULL;
-
return ret;
error:
--
1.7.8.rc4
12 years, 11 months
Problem to convert ESX guest into the KVM
by Berezovski, Vladimir
Hi , I attached log files on the problem posted here :
https://access.redhat.com/discussion/problem-convert-esx-guest-kvm
Host server:
OS level rhel 6.1
2.6.32-214.el6.x86_64
virt-v2v-0.8.3-5.el6.x86_64
libvirt-0.9.4-21.el6.x86_64
libvirt-client-0.9.4-21.el6.x86_64
RHEV-M:
OS level rhel 6.1
rhevm-3.0.0_0001-51.el6.x86_64
Best regards ,
Vladimir Berezovski
NDS IL , Unix group
Tel:
+972 (2) 589-4287
Mobile:
+972 (54) 566-4287
Email:
vberezovski(a)nds.com<mailto:vberezovski@nds.com>
________________________________
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster(a)nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes.
To protect the environment please do not print this e-mail unless necessary.
An NDS Group Limited company. www.nds.com
12 years, 11 months
[PATCH] blkid: split the RHEL5 which can't support some options
by Wanlong Gao
RHEL5 shoult not support '-p', '-i' and '-o export' options.
But we just split it according to the '-p' option.
Signed-off-by: Wanlong Gao <gaowanlong(a)cn.fujitsu.com>
---
daemon/blkid.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 73 insertions(+), 7 deletions(-)
diff --git a/daemon/blkid.c b/daemon/blkid.c
index a7fd6bc..8c2cdc6 100644
--- a/daemon/blkid.c
+++ b/daemon/blkid.c
@@ -84,18 +84,42 @@ do_vfs_uuid (const char *device)
return get_blkid_tag (device, "UUID");
}
-char **
-do_blkid(const char *device)
+/* RHEL5 blkid doesn't have the -p(partition info) option and the
+ * -i(I/O limits) option so we must test for these options the first
+ * time the function is called.
+ */
+static int
+test_blkid_p_opt(void)
+{
+ static int result = -1;
+ char *err = NULL;
+
+ int r = commandr (NULL, &err, "blkid", "-p", "/dev/null", NULL);
+ if (r == -1) {
+ reply_with_error("Could not run 'blkid' command");
+ free(err);
+ return -1;
+ }
+
+ if (err && strstr(err, "invalid option --"))
+ result = 0;
+ else
+ result = 1;
+ free(err);
+ return result;
+}
+
+static char **
+blkid_with_p_opt(const char *device)
{
int r;
char *out = NULL, *err = NULL;
char **lines = NULL;
-
char **ret = NULL;
int size = 0, alloc = 0;
- const char *blkid[] = {"blkid", "-p", "-i", "-o", "export", device, NULL};
- r = commandv(&out, &err, blkid);
+ r = command(&out, &err, "blkid", "-c", "/dev/null",
+ "-p", "-i", "-o", "export", device, NULL);
if (r == -1) {
reply_with_error("%s", err);
goto error;
@@ -142,12 +166,12 @@ do_blkid(const char *device)
}
}
+ if (add_string(&ret, &size, &alloc, NULL) == -1) goto error;
+
free(out);
free(err);
free(lines);
- if (add_string(&ret, &size, &alloc, NULL) == -1) return NULL;
-
return ret;
error:
@@ -158,3 +182,45 @@ error:
return NULL;
}
+
+static char **
+blkid_without_p_opt(const char *device)
+{
+ char **ret = NULL;
+ int size = 0, alloc = 0;
+
+ if (add_string(&ret, &size, &alloc, "TYPE") == -1) goto error;
+ if (add_string(&ret, &size, &alloc, get_blkid_tag(device, "TYPE")) == -1)
+ goto error;
+ if (add_string(&ret, &size, &alloc, "LABEL") == -1) goto error;
+ if (add_string(&ret, &size, &alloc, get_blkid_tag(device, "LABEL")) == -1)
+ goto error;
+ if (add_string(&ret, &size, &alloc, "UUID") == -1) goto error;
+ if (add_string(&ret, &size, &alloc, get_blkid_tag(device, "UUID")) == -1)
+ goto error;
+ if (add_string_nodup(&ret, &size, &alloc, NULL) == -1) goto error;
+
+ return ret;
+error:
+ if (ret) free_strings(ret);
+ return NULL;
+}
+
+char **
+do_blkid(const char *device)
+{
+ int r;
+ char *out = NULL, *err = NULL;
+ char **lines = NULL;
+
+ char **ret = NULL;
+ int size = 0, alloc = 0;
+ int blkid_has_p_opt = -1;
+
+ if ((blkid_has_p_opt = test_blkid_p_opt()) == -1)
+ return NULL;
+ else if (blkid_has_p_opt)
+ return blkid_with_p_opt(device);
+ else
+ return blkid_without_p_opt(device);
+}
--
1.7.8.rc4
12 years, 11 months