From: Richard Jones Date: Thu, 2 Jul 2009 23:22:14 +0000 (+0100) Subject: Merge branch 'master' of git+ssh://192.168.122.1/home/rjones/d/libguestfs X-Git-Tag: 1.0.56~9 X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=commitdiff_plain;h=6fb57e430c8daa06d8d938ac02a104c8aadbbda5;hp=b7e094fa14b306fe776b9b2695cf82fa32d4923f Merge branch 'master' of git+ssh://192.168.122.1/home/rjones/d/libguestfs --- diff --git a/.gitignore b/.gitignore index 296db62..8bffe89 100644 --- a/.gitignore +++ b/.gitignore @@ -20,15 +20,23 @@ ChangeLog Makefile.in Makefile aclocal.m4 +appliance/debian/debirf.conf appliance/initramfs.*.img -appliance/make-initramfs.sh -appliance/make-initramfs.sh.in.old -appliance/update-initramfs.sh +appliance/initramfs.*.supermin.hostfiles +appliance/kmod.whitelist +appliance/libguestfs-supermin-helper +appliance/make.sh +appliance/packagelist +appliance/supermin-make.sh +appliance/supermin-split.sh +appliance/supermin.incfiles +appliance/update.sh appliance/vmlinuz.* autom4te.cache capitests/test-command capitests/test*.img capitests/test*.tmp +capitests/tests.c capitests/tests compile config.h @@ -38,16 +46,27 @@ config.sub config.log config.status configure +daemon/actions.h daemon/guestfsd daemon/install-sh daemon/missing +daemon/names.c +daemon/stubs.c depcomp emptydisk examples/hello examples/to-xml +fish/cmds.c +fish/completion.c fish/guestfish guestfish.1 +guestfish-actions.pod +guestfs-actions.pod +guestfs-structs.pod guestfs.3 +haskell/Bindtests.hs +haskell/Bindtests +haskell/Guestfs.hs haskell/Guestfs005Load haskell/Guestfs010Launch haskell/Guestfs050LVCreate @@ -55,13 +74,28 @@ html/guestfish.1.html html/guestfs.3.html html/recipes.html html/virt-inspector.1.html +images/100kallzeroes +images/100kallnewlines +images/100kallspaces +images/100krandom +images/10klines +images/initrd images/test.sqsh initramfs initramfs.timestamp inspector/virt-inspector.1 install-sh java/api +java/Bindtests.java java/com_redhat_et_libguestfs_GuestFS.h +java/com_redhat_et_libguestfs_GuestFS.c +java/com/redhat/et/libguestfs/Dirent.java +java/com/redhat/et/libguestfs/GuestFS.java +java/com/redhat/et/libguestfs/LV.java +java/com/redhat/et/libguestfs/PV.java +java/com/redhat/et/libguestfs/Stat.java +java/com/redhat/et/libguestfs/StatVFS.java +java/com/redhat/et/libguestfs/VG.java java/doc-stamp missing libguestfs.pc @@ -75,16 +109,24 @@ m4/ltsugar.m4 m4/ltversion.m4 m4/lt~obsolete.m4 ocaml/META +ocaml/bindtests.ml ocaml/bindtests ocaml/examples/lvs +ocaml/guestfs.mli +ocaml/guestfs.ml +ocaml/guestfs_c_actions.c ocaml/t/guestfs_005_load ocaml/t/guestfs_010_launch ocaml/t/guestfs_050_lvcreate +ocaml/t/guestfs_060_readdir +perl/bindtests.pl +perl/blib perl/Guestfs.c perl/Guestfs.bs +perl/Guestfs.xs +perl/lib/Sys/Guestfs.pm perl/Makefile-pl perl/Makefile.PL -perl/blib perl/pm_to_blib po/*.gmo po/Makevars.template @@ -93,8 +135,22 @@ po/remove-potcdate.sed po/stamp-it po/stamp-po pod2htm?.tmp +python/bindtests.py +python/guestfs-py.c +python/guestfs.py python/guestfs.pyc ruby/Rakefile +ruby/bindtests.rb +ruby/ext/guestfs/_guestfs.c ruby/ext/guestfs/extconf.h ruby/ext/guestfs/mkmf.log +src/.pod2text.data +src/guestfs-actions.c +src/guestfs-actions.h +src/guestfs-bindtests.c +src/guestfs_protocol.c +src/guestfs_protocol.h +src/guestfs_protocol.x +src/guestfs-structs.h +src/stamp-generator stamp-h1 diff --git a/HACKING b/HACKING index fc9ed38..b42a807 100644 --- a/HACKING +++ b/HACKING @@ -14,10 +14,6 @@ etc. to the big list called 'functions' at the top of this file. 'do_action' function. Take a look at one of the numerous examples there. -You will need to run src/generator.ml (from the top directory) which -regenerates all the auto-generated files, and then continue with the -ordinary build process. - Formatting ---------------------------------------------------------------------- diff --git a/Makefile.am b/Makefile.am index 142cf3e..1cb2299 100644 --- a/Makefile.am +++ b/Makefile.am @@ -61,13 +61,14 @@ EXTRA_DIST = \ contrib/febootstrap/install.title \ contrib/febootstrap/install.html \ contrib/febootstrap/install.sh \ - bindtests + bindtests \ + libguestfs.3 # Manual pages. # guestfs-actions.pod and guestfs-structs are autogenerated. There is # no include mechanism for POD, so we have to do it by hand. -man_MANS = guestfs.3 guestfish.1 +man_MANS = guestfs.3 libguestfs.3 guestfish.1 guestfs.3: guestfs.pod guestfs-actions.pod guestfs-structs.pod sed \ diff --git a/README b/README index f470a58..e376cc7 100644 --- a/README +++ b/README @@ -37,7 +37,7 @@ Requirements - recent QEMU >= 0.10 with vmchannel support http://lists.gnu.org/archive/html/qemu-devel/2009-02/msg01042.html -- febootstrap >= 2.0 +- febootstrap >= 2.3 - fakeroot @@ -73,6 +73,9 @@ bindings - (Optional) GHC if you want to build the Haskell bindings +- (Optional) Perl XML::XPath, Sys::Virt modules (for libvirt support +in virt-inspector). + Running ./configure will check you have all the requirements installed on your machine. @@ -120,10 +123,13 @@ or build from our source RPMs. Debian ---------------------------------------------------------------------- -libguestfs should build and run on Debian. At the moment we don't -provide Debian packages, and because of the appliance it's rather -complicated to provide a package which could be accepted into the -Debian repositories. Want to help? Please contact us. +libguestfs should build and run on Debian. + +febootstrap, yum, rpm, fakeroot, fakechroot are all packaged in +Debian. + +Please see the fedora-virt mailing list for the status of libguestfs +in Debian. qemu @@ -168,6 +174,62 @@ On some systems, the chmod will not survive a reboot, and you will need to make edits to the udev configuration. +Supermin appliance +---------------------------------------------------------------------- + +If you configure with --enable-supermin then we will build a supermin +appliance (supermin = super-minimized). This is a very specialized +appliance which is built on-the-fly at runtime (specifically, when you +call guestfs_launch). + +The normal appliance is a self-contained Linux operating system, based +on the Fedora/RHEL/CentOS Linux distro. So it contains a complete +copy of all the libraries and programs needed, like kernel, libc, +bash, coreutils etc etc. + +The supermin appliance removes the kernel and all the executable +libraries and programs from the appliance. That just leaves a +skeleton of config files and some data files, which is obviously +massively smaller than the normal appliance. At runtime we rebuild +the appliance on-the-fly from the libraries and programs on the host +(eg. pulling in the real /lib/libc.so, the real /bin/bash etc.) + +Although this process of rebuilding the appliance each time sounds +slow, it turns out to be faster than using the prebuilt appliance. +(Most of the saving comes from not compressing the appliance - it +transpires that decompressing the appliance is the slowest part of the +whole boot sequence). On my machine, a new appliance can be built in +under a fifth of a second, and the boot time is several seconds +shorter. + +The big advantage of the supermin appliance for distributions like +Fedora is that it gets security fixes automatically from the host, so +there is no need to rebuild the whole of libguestfs for a security +update in some underlying library. + +There are several DISADVANTAGES: + +It won't work at all except in very narrow, controlled cases like the +Fedora packaging case. We control the dependencies of the libguestfs +RPM tightly to ensure that the required binaries are actually present +on the host. + +Furthermore there are certain unlikely changes in the packages on the +host which could break a supermin appliance, eg. an updated library +which depends on an additional data file. + +Also supermin appliances are subjected to changes in the host kernel +which might break compatibility with qemu -- these are, of course, +real bugs in any case. + +Lastly, supermin appliances really can't be moved between branches of +distributions (eg. built on Fedora 12 and moved to Fedora 10) because +they are not self-contained and they rely on certain libraries being +around. You shouldn't do this anyway. + +Use supermin appliances with caution. + + Notes on cross-architecture support ---------------------------------------------------------------------- diff --git a/TODO b/TODO index d0e9320..a38a8dc 100644 --- a/TODO +++ b/TODO @@ -54,21 +54,6 @@ ie. CentOS 5.3, Fedora 11, Debian. ---------------------------------------------------------------------- -Qemu options -- After discussion with the KVM developers, they have -recommended some flags which will improve the safety and reliability -of KVM. Need to test that these also work under qemu (or at least, do -no harm): - --no-hpet HPET support is broken and should be disabled. - --rtc-td-hack Keeps the rtc clock source track time correctly. - --drive file=...,if=[ide|virtio],cache=off - cache=off is necessary to improve reliability in the - event of a system crash when writing. - ----------------------------------------------------------------------- - "Standalone/local mode" Instead of running guestfsd (the daemon) inside qemu, there should be @@ -107,3 +92,90 @@ This is mainly useful from live CDs, ie. virt-p2v. Should we bother having the daemon at all and just link the guestfsd code directly into libguestfs? + +---------------------------------------------------------------------- + +PPC problems: + + ppc (32 bit) works with qemu from git, however there is no serial console + + ppc64 requires extra parameters: + -M mac99 -cpu ppc64 + however it still fails: + invalid/unsupported opcode: 01 - 01 - 1a (06301e83) 00000000018c2738 1 + invalid bits: 00400000 for opcode: 0b - 19 - 15 (2d746572) 0000000000009230 + + no serial console in ppc or ppc64 because no one can tell us what + console=ttyXX option to use + +---------------------------------------------------------------------- + +Supermin appliance should be moved into febootstrap. + +---------------------------------------------------------------------- + +Extra commands / functionality: + + General glibc / core programs: + chgrp + grep (do it locally using pipe?) + dd (?) + ln / ln -s + readlink + utime / utimes / futimes / futimens / l.. + more mk*temp calls + readdir / readdir-and-stat + some sort of alloc/fallocate/posix_fallocate call to create empty space + realpath + trunc[ate??] + getfattr (also useful because gives us access to NTFS datastreams) + setfattr + + ext2 properties: + chattr + lsattr + badblocks + blkid + debugfs + dumpe2fs + e2image + e2undo + filefrag + findfs + logsave + mklost+found + + SELinux: + chcat + restorecon + ch??? + + Oddball: + pivot_root + fts(3) / ftw(3) + +---------------------------------------------------------------------- + +Allow swap space from the guest to be used. Is it a good idea? + +---------------------------------------------------------------------- + +Need a way to query a binary or library file for its architecture. +Using objdump or readelf? +What about non-ELF files (eg. Windows, BSD). + +To do this properly requires some serious logic, eg. to cover Linux +and Windows we'd need objdump and i686-pc-mingw32-objdump, and more to +cover a.out, COFF and 64 bit Windows. Therefore this cannot be done +inside the daemon, and should be done by a separate, external program +similar to virt-inspector. + +Probably we should go all the way and have virt-inspector able to +determine kernel and userspace architectures of guests. + +---------------------------------------------------------------------- + +Other initrd-* commands, such as: + +initrd-extract +initrd-replace diff --git a/appliance/Makefile.am b/appliance/Makefile.am index 066becb..03b2a7b 100644 --- a/appliance/Makefile.am +++ b/appliance/Makefile.am @@ -16,36 +16,86 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. EXTRA_DIST = \ - make-initramfs.sh update-initramfs.sh + make.sh update.sh supermin-split.sh supermin-make.sh \ + libguestfs-supermin-helper \ + kmod.whitelist \ + kmod.whitelist.in \ + packagelist.in \ + init # Build the root filesystem (appliance). # Currently this is arch-dependent, so it seems like putting it in # $(libdir) is best. When we build cross-architecture filesystems we # should probably move them to $(datadir). - fsdir = $(libdir)/guestfs - +fs_DATA = $(APPLIANCE_FILES) + +# These are the resulting output files from the whole process: +# VMLINUZ kernel for the full appliance +# INITRAMFSIMG initramfs (ie. root fs) for the full appliance +# For details of the supermin appliance, read the README file: +# SUPERMINIMG initramfs (ie. partial root fs) for the supermin appliance +# SUPERMINFILES list of missing files (the ones we will pull out of the +# host filesystem at runtime) in the supermin appliance +APPLIANCE_FILES = $(INITRAMFSIMG) $(VMLINUZ) +if SUPERMIN +APPLIANCE_FILES += $(SUPERMINIMG) $(SUPERMINFILES) kmod.whitelist +bin_SCRIPTS = libguestfs-supermin-helper +endif + +# Don't change these names - they must be the same as in '*.sh' scripts. INITRAMFSIMG = initramfs.$(REPO).$(host_cpu).img VMLINUZ = vmlinuz.$(REPO).$(host_cpu) +if SUPERMIN +SUPERMINIMG = initramfs.$(REPO).$(host_cpu).supermin.img +SUPERMINFILES = initramfs.$(REPO).$(host_cpu).supermin.hostfiles +endif -fs_DATA = $(INITRAMFSIMG) $(VMLINUZ) - +# This is for building the normal appliance: $(INITRAMFSIMG) $(VMLINUZ): $(top_builddir)/initramfs/fakeroot.log -$(top_builddir)/initramfs/fakeroot.log: make-initramfs.sh.in +$(top_builddir)/initramfs/fakeroot.log: make.sh kmod.whitelist packagelist -mv $(INITRAMFSIMG) $(INITRAMFSIMG).bak -mv $(VMLINUZ) $(VMLINUZ).bak - if ! bash make-initramfs.sh; then rm -f $@; exit 1; fi + if ! bash make.sh; then rm -f $@; exit 1; fi -$(INITRAMFSIMG): $(top_builddir)/initramfs/fakeroot.log $(top_builddir)/daemon/guestfsd +$(INITRAMFSIMG): $(top_builddir)/initramfs/fakeroot.log $(top_builddir)/daemon/guestfsd init update.sh rm -f $@ - bash update-initramfs.sh + bash update.sh touch $@ -make-initramfs.sh: make-initramfs.sh.in - cd .. && ./config.status appliance/$@ +kmod.whitelist: kmod.whitelist.in + grep -v '^[[:space:]]*$$' < $< | grep -v '^#' > $@ + +packagelist: packagelist.in + cpp -undef -D$(DIST)=1 < $< | \ + grep -v '^[[:space:]]*$$' | grep -v '^#' > $@ + +# This is for building the supermin appliance. It has to be enabled +# specifically with './configure --enable-supermin'. You really need +# to read the README file. + +if SUPERMIN + +# First we need to decide which files go in and out of the supermin +# appliance. This decision is made by 'supermin-split.sh'. +$(SUPERMINFILES): supermin.incfiles +supermin.incfiles: $(top_builddir)/initramfs/fakeroot.log $(top_builddir)/daemon/guestfsd supermin-split.sh + rm -f supermin.incfiles $(SUPERMINFILES) + bash supermin-split.sh + +# Second we need to create a supermin appliance with just the included +# files (leaving out the host files, which we'll add back at runtime). +$(SUPERMINIMG): supermin.incfiles supermin-make.sh + rm -f $@ + bash supermin-make.sh + +endif + +#---------------------------------------------------------------------- +# Extra rules for testing the appliance. -# Test-boot the image. +# Test-boot the appliance. test-boot: emptydisk qemu-system-$(host_cpu) \ @@ -66,7 +116,7 @@ test-boot-realistic: emptydisk -m 384 \ -kernel $(VMLINUZ) -initrd $(INITRAMFSIMG) \ -hda emptydisk \ - -append "console=ttyS0 guestfs=10.0.2.4:6666" \ + -append "console=ttyS0 guestfs=10.0.2.4:6666 guestfs_rescue=1" \ -nographic \ -serial stdio \ -net channel,6666:unix:/tmp/sock,server,nowait \ @@ -75,7 +125,7 @@ test-boot-realistic: emptydisk # Make clean. -CLEANFILES = $(fs_DATA) +CLEANFILES = $(APPLIANCE_FILES) clean-local: rm -rf $(top_builddir)/initramfs diff --git a/appliance/debian/debirf.conf.in b/appliance/debian/debirf.conf.in new file mode 100644 index 0000000..a3dc16f --- /dev/null +++ b/appliance/debian/debirf.conf.in @@ -0,0 +1,5 @@ +DEBIRF_LABEL="debirf-libguestfs" +DEBIRF_SUITE=@REPO@ +DEBIRF_MIRROR=@MIRROR@/${DEBIRF_DISTRO} +DEBIRF_KERNEL_ARCH=486 + diff --git a/appliance/debian/modules/a0_motd b/appliance/debian/modules/a0_motd new file mode 120000 index 0000000..8e3ad2f --- /dev/null +++ b/appliance/debian/modules/a0_motd @@ -0,0 +1 @@ +/usr/share/debirf/modules/a0_motd \ No newline at end of file diff --git a/appliance/debian/modules/a0_prep-root b/appliance/debian/modules/a0_prep-root new file mode 120000 index 0000000..654bc70 --- /dev/null +++ b/appliance/debian/modules/a0_prep-root @@ -0,0 +1 @@ +/usr/share/debirf/modules/a0_prep-root \ No newline at end of file diff --git a/appliance/debian/modules/install_kernel b/appliance/debian/modules/install_kernel new file mode 100755 index 0000000..c1076ce --- /dev/null +++ b/appliance/debian/modules/install_kernel @@ -0,0 +1,68 @@ +#!/bin/bash -e + +# debirf module: install-kernel +# install a kernel package, indicated by the expected environment +# variables: +# DEBIRF_PATH +# DEBIRF_ROOT +# DEBIRF_KERNEL_PACKAGE +# +# *** REQUIRED MODULE *** +# WARNING: this module is necessary for proper functioning of debirf. +# +# The debirf scripts were written by +# Jameson Rollins +# and +# Daniel Kahn Gillmor . +# +# They are Copyright 2007, and are all released under the GPL, +# version 3 or later. + +# clear out old modules if they exist, to avoid confusion +rm -rf "$DEBIRF_ROOT/lib/modules" + +# download/copy in kernel package +if [ -z "$DEBIRF_KERNEL_PACKAGE" ] ; then + # determine kernel to install. assume arch of build host. + + # determine kernel arch. need everything after the kernel version + # and debian version + if [ -z "$DEBIRF_KERNEL_ARCH" ]; then + KARCH=$(uname -r | cut -d- -f3-) + else + KARCH="$DEBIRF_KERNEL_ARCH" + fi + + # determine the full kernel version from the dependency of the + # generic 2.6-ARCH package in the debirf root (since it may be + # different than what is installed on the build host) + KNAME=$(debirf_exec apt-cache show linux-image-2.6-"$KARCH" | grep '^Depends: ' | sed 's/^Depends: //') + + # download only the desired kernel package directly into the apt + # cache for dpkg extraction + debirf_exec sh -c "cd /var/cache/apt/archives/ && aptitude download \"$KNAME\"" +else + # install kernel deb if given at command line + debirf_exec sh -c "cd /var/cache/apt/archives/ && aptitude download \"$DEBIRF_KERNEL_PACKAGE\"" +fi + +KPKG=$(basename "$DEBIRF_ROOT"/var/cache/apt/archives/linux-image-2.6.*) + +echo "extracting kernel package $KPKG..." +debirf_exec dpkg --extract /var/cache/apt/archives/"$KPKG" / + +# install the module init tools, since they are needed for depmod +debirf_exec apt-get --assume-yes install module-init-tools + +# depmod to create module list +KVERS=$(ls -1 -t "$DEBIRF_ROOT/lib/modules" | head -n1) +echo "generating modules.dep..." +debirf_exec depmod -a "$KVERS" + +# extract kernel and debian stock initrd from the build root: +mv "$DEBIRF_ROOT"/boot/vmlinu* "$DEBIRF_BUILDD" + +# remove kernel symlinks +if [ -L "$DEBIRF_ROOT"/vmlinuz ] ; then + rm "$DEBIRF_BUILDD"/vmlinuz +fi diff --git a/appliance/debian/modules/network b/appliance/debian/modules/network new file mode 120000 index 0000000..979418d --- /dev/null +++ b/appliance/debian/modules/network @@ -0,0 +1 @@ +/usr/share/debirf/modules/network \ No newline at end of file diff --git a/appliance/debian/modules/root-bashrc b/appliance/debian/modules/root-bashrc new file mode 120000 index 0000000..651d030 --- /dev/null +++ b/appliance/debian/modules/root-bashrc @@ -0,0 +1 @@ +/usr/share/debirf/modules/root-bashrc \ No newline at end of file diff --git a/appliance/debian/modules/serial-terminal b/appliance/debian/modules/serial-terminal new file mode 120000 index 0000000..a5376da --- /dev/null +++ b/appliance/debian/modules/serial-terminal @@ -0,0 +1 @@ +/usr/share/debirf/modules/serial-terminal \ No newline at end of file diff --git a/appliance/debian/modules/y0_install-guestfsd b/appliance/debian/modules/y0_install-guestfsd new file mode 100755 index 0000000..17bbbdc --- /dev/null +++ b/appliance/debian/modules/y0_install-guestfsd @@ -0,0 +1,33 @@ +#!/bin/bash -e +# install guestfsd specific stuff + +# Kernel modules take up nearly half of the image. Only include ones +# which are on the whitelist. +exec 5<../appliance/kmod.whitelist +whitelist= +while read kmod 0<&5; do + whitelist="$whitelist -a -not -name $kmod" +done +exec 5<&- + +echo "Module whitelist: $whitelist" +find $DEBIRF_ROOT/lib/modules/*/kernel -name '*.ko' $whitelist -a -exec rm '{}' \; + +# install additional packages: +PKGLIST=$(< packagelist) +echo "Will add $PKGLIST" +debirf_exec aptitude -R -y install $PKGLIST +debirf_exec aptitude -y remove vim-tiny dhcp3-client iptables + +debirf_exec mkdir -p --mode=0777 /sysroot + +# cleanup some other heavy lifters: +rm -rf "$DEBIRF_ROOT"/usr/share/doc/ +rm -rf "$DEBIRF_ROOT"/usr/share/zoneinfo/ +rm -rf "$DEBIRF_ROOT"/usr/share/man/ + +# Install the actual appliance: +echo $PWD +install -o root -g root -m 0755 ../daemon/guestfsd "$DEBIRF_ROOT"/sbin/guestfsd +install -o root -g root -m 0755 init "$DEBIRF_ROOT"/sbin/init + diff --git a/appliance/debian/modules/z0_remove-aptitude b/appliance/debian/modules/z0_remove-aptitude new file mode 120000 index 0000000..7c56260 --- /dev/null +++ b/appliance/debian/modules/z0_remove-aptitude @@ -0,0 +1 @@ +/usr/share/debirf/modules/z0_remove-aptitude \ No newline at end of file diff --git a/appliance/debian/modules/z0_remove-locales b/appliance/debian/modules/z0_remove-locales new file mode 120000 index 0000000..80a82fa --- /dev/null +++ b/appliance/debian/modules/z0_remove-locales @@ -0,0 +1 @@ +/usr/share/debirf/modules/z0_remove-locales \ No newline at end of file diff --git a/appliance/debian/modules/z1_clean-root b/appliance/debian/modules/z1_clean-root new file mode 120000 index 0000000..f0d3aad --- /dev/null +++ b/appliance/debian/modules/z1_clean-root @@ -0,0 +1 @@ +/usr/share/debirf/modules/z1_clean-root \ No newline at end of file diff --git a/appliance/debian/modules/z99_final-cleanups b/appliance/debian/modules/z99_final-cleanups new file mode 100755 index 0000000..ef5fac7 --- /dev/null +++ b/appliance/debian/modules/z99_final-cleanups @@ -0,0 +1,3 @@ +#!/bin/sh + +rm -rf "$DEBIRF_ROOT"/var/lib/dpkg/info diff --git a/appliance/init b/appliance/init new file mode 100755 index 0000000..dbe53f4 --- /dev/null +++ b/appliance/init @@ -0,0 +1,53 @@ +#!/bin/sh + +echo Starting /init script ... + +PATH=/sbin:/usr/sbin:$PATH + +mount -t proc /proc /proc +mount -t sysfs /sys /sys + +if [ -x /etc/init.d/udev ]; then + /etc/init.d/udev start +elif [ -x /sbin/start_udev ]; then + /sbin/start_udev +else + echo No udev, creating /dev manually + mount -t tmpfs none /dev + mkdir /dev/pts /dev/shm /dev/mapper + mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts + # Must do each MAKEDEV individually, because if one device fails, + # MAKEDEV will quit without creating the rest (RHBZ#507374). + for dev in mem null port zero core full ram tty console fd \ + hda hdb hdc hdd sda sdb sdc sdd loop sd; do + MAKEDEV $dev ||: + done + mknod /dev/ptmx c 5 2; chmod 0666 /dev/ptmx + mknod /dev/random c 1 8; chmod 0666 /dev/random + mknod /dev/urandom c 1 9; chmod 0444 /dev/urandom + ln -sf /proc/self/fd/0 /dev/stdin + ln -sf /proc/self/fd/1 /dev/stdout + ln -sf /proc/self/fd/2 /dev/stderr + + modprobe virtio_pci + modprobe virtio_net +fi + +modprobe dm_mod ||: +mount +ls -l /dev + +/sbin/ifconfig lo 127.0.0.1 +/sbin/ifconfig eth0 10.0.2.10 +/sbin/route add default gw 10.0.2.2 + +lvm vgscan --ignorelockingfailure +lvm vgchange -ay --ignorelockingfailure + +# Improve virtio-blk performance (RHBZ#509383). +for f in /sys/block/vd*/queue/rotational; do echo 1 > $f; done + +if grep -sq guestfs_rescue=1 /proc/cmdline; then + bash -i +fi +exec guestfsd -f diff --git a/appliance/kmod.whitelist.in b/appliance/kmod.whitelist.in new file mode 100644 index 0000000..590285d --- /dev/null +++ b/appliance/kmod.whitelist.in @@ -0,0 +1,48 @@ +# List of kernel modules that we leave in the appliance. This has to +# include any dependencies needed by modules. + +# Any kernel module not listed here is deleted from the appliance. + +# Wildcards are permitted. + +virtio*.ko + +# drivers for QEMUs IDE/SCSI device emulation +cdrom.ko +i2c-piix4.ko +i2c-core.ko +ide-*.ko +libata.ko +piix.ko +scsi_transport_spi.ko +scsi_mod.ko +sd_mod.ko +sym53c8xx.ko + +ext2.ko +ext3.ko +ext4*.ko + +crc16.ko +jbd.ko +jbd2.ko +mbcache.ko + +fuse.ko + +vfat.ko +fat.ko + +udf.ko +crc_itu_t.ko +nls_utf8.ko + +dm-*.ko + +cramfs.ko +squashfs.ko + +hfsplus.ko +ufs.ko +exportfs.ko +xfs.ko diff --git a/appliance/libguestfs-supermin-helper.in b/appliance/libguestfs-supermin-helper.in new file mode 100755 index 0000000..2afd0cf --- /dev/null +++ b/appliance/libguestfs-supermin-helper.in @@ -0,0 +1,82 @@ +#!/bin/bash - +# @configure_input@ +# Copyright (C) 2009 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +# Helper script which constructs the supermin appliance at runtime. + +unset CDPATH + +set -e + +# Source directory containing the supermin input files. +sourcedir=$(cd "$1" > /dev/null; pwd) + +# Output files. +kernel="$2" +initrd="$3" + +# Kernel: +# Look for the most recent kernel named vmlinuz-*.* which has a +# corresponding directory in /lib/modules/. If the architecture is x86, look +# for any x86 kernel. + +arch=$(echo "@host_cpu@" | sed 's/^i.86$/i?86/') +for f in $(ls -1vr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen); do + b=$(basename "$f") + b=$(echo "$b" | sed 's,vmlinuz-,,') + modpath="/lib/modules/$b" + if [ -d "$modpath" ]; then + ln -sf "$f" "$kernel" + break + fi + modpath= +done + +if [ -z "$modpath" ]; then + echo "$0: failed to find a suitable kernel" >&2 + exit 1 +fi + +# The initrd consists of these components: +# (1) The base skeleton appliance that we constructed at build time. +# name = initramfs.@REPO@.@host_cpu@.supermin.img +# format = compressed cpio +# (2) The modules from modpath which are on the module whitelist. +# format = plain cpio +# (3) The host files which match wildcards in *.supermin.hostfiles. +# format = plain cpio + +cp "$sourcedir"/initramfs.@REPO@.@host_cpu@.supermin.img "$initrd" + +# Kernel modules (2). +exec 5<"$sourcedir"/kmod.whitelist +whitelist= +while read kmod 0<&5; do + whitelist="$whitelist -o -name $kmod" +done +exec 5<&- + +find "$modpath" \( -not -name '*.ko' $whitelist \) -a -print0 | + cpio --quiet -o -0 -H newc >> "$initrd" + +# Host files (3). + +(cd / && \ + ls -1df $( + cat "$sourcedir"/initramfs.@REPO@.@host_cpu@.supermin.hostfiles + ) 2>/dev/null | + cpio --quiet -o -H newc ) >> "$initrd" diff --git a/appliance/make-initramfs.sh.in b/appliance/make-initramfs.sh.in deleted file mode 100755 index b1d3c39..0000000 --- a/appliance/make-initramfs.sh.in +++ /dev/null @@ -1,176 +0,0 @@ -#!/bin/bash - -# @configure_input@ -# Copyright (C) 2009 Red Hat Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -# This is called from the Makefile to build the initramfs. - -unset CDPATH - -set -e - -cd @top_builddir@ - -modules=" --i augeas-libs --i bash --i binutils --i coreutils --i dosfstools --i file --i grub --i iputils --i kernel --i lvm2 --i MAKEDEV --i module-init-tools --i net-tools --i ntfs-3g --i ntfsprogs --i procps --i strace --i util-linux-ng --i zerofree -" - -# Decide on names for the final output. These have to match Makefile.am. -output=appliance/initramfs.@REPO@.@host_cpu@.img -koutput=appliance/vmlinuz.@REPO@.@host_cpu@ -rm -f $output -rm -f $koutput - -# Create the basic initramfs. -@FEBOOTSTRAP@ $modules -u @UPDATES@ @REPO@ initramfs @MIRROR@ - -# /sysroot is where the guest root filesystem will be mounted. -@FEBOOTSTRAP_RUN@ initramfs -- mkdir -p --mode=0777 /sysroot - -# Create /tmp if it is missing. -@FEBOOTSTRAP_RUN@ initramfs -- mkdir -p --mode=0777 /tmp - -# Nuke some stuff. The kernel pulls mkinitrd and plymouth which pulls in -# all of Python. Sheez. -(cd initramfs && find -name '*plymouth*' -print0) | - xargs -0 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf -(cd initramfs && find -name '*python*' -print0) | - xargs -0 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf - -# In Fedora >= 11, it pulls in all of Perl from somewhere. Nuke from orbit. -@FEBOOTSTRAP_RUN@ initramfs -- rm -rf /usr/lib/perl5 /usr/lib64/perl5 - -# Anaconda? JPEG images? -@FEBOOTSTRAP_RUN@ initramfs -- rm -rf /usr/lib/anaconda-runtime - -# Modules take up nearly half of the image. It's a rough guess that -# we don't need many drivers (which take up most of the space). -(cd initramfs && find lib/modules/*/kernel \ - -name '*.ko' \ - -a ! -name 'virtio.ko' \ - -a ! -name 'virtio_net.ko' \ - -a ! -name 'virtio_pci.ko' \ - -a ! -name 'virtio_ring.ko' \ - -a ! -name 'ext2.ko' \ - -a ! -name 'ext3.ko' \ - -a ! -name 'ext4*.ko' \ - -a ! -name 'crc16.ko' \ - -a ! -name 'jbd.ko' \ - -a ! -name 'jbd2.ko' \ - -a ! -name 'fuse.ko' \ - -a ! -name 'vfat.ko' \ - -a ! -name 'fat.ko' \ - -a ! -name 'udf.ko' \ - -a ! -name 'crc_itu_t.ko' \ - -a ! -name 'nls_utf8.ko' \ - -a ! -name 'dm-*.ko' \ - -a ! -name 'cramfs.ko' \ - -a ! -name 'squashfs.ko' \ - -a ! -name 'hfsplus.ko' \ - -a ! -name 'ufs.ko' \ - -a ! -name 'exportfs.ko' \ - -a ! -name 'xfs.ko' \ - -a -print0 ) | - xargs -0 @FEBOOTSTRAP_RUN@ initramfs -- rm - -# Pull the kernel out into the current directory. We don't want it in -# the initramfs image. -cp initramfs/boot/vmlinuz* $koutput -@FEBOOTSTRAP_RUN@ initramfs -- rm -rf boot - -# Minimize the image. -@FEBOOTSTRAP_MINIMIZE@ initramfs - -# Add some missing configuration files. -if [ ! -f initramfs/etc/hosts ]; then - cat > hosts.new <<'__EOF__' -127.0.0.1 guestfs localhost.localdomain localhost -::1 localhost6.localdomain6 localhost6 -__EOF__ - @FEBOOTSTRAP_INSTALL@ initramfs hosts.new /etc/hosts 0644 root.root - rm hosts.new -fi - -if [ ! -f initramfs/etc/fstab ]; then - @FEBOOTSTRAP_RUN@ initramfs -- touch /etc/fstab -fi - -echo nameserver 10.0.2.3 > resolv.conf.new -@FEBOOTSTRAP_INSTALL@ initramfs resolv.conf.new /etc/resolv.conf 0644 root.root -rm resolv.conf.new - -# Create the init script. -cat > init.new <<'__EOF__' -#!/bin/sh -echo Starting /init script ... -PATH=/sbin:/usr/sbin:$PATH -mount -t tmpfs none /dev -mkdir /dev/pts /dev/shm /dev/mapper -MAKEDEV mem null port zero core full ram tty console fd \ - hda hdb hdc hdd sda sdb sdc sdd loop sd -mknod /dev/ptmx c 5 2; chmod 0666 /dev/ptmx -mknod /dev/random c 1 8; chmod 0666 /dev/random -mknod /dev/urandom c 1 9; chmod 0444 /dev/urandom -mount -t proc /proc /proc -mount -t sysfs /sys /sys -mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts -ln -sf /proc/self/fd/0 /dev/stdin -ln -sf /proc/self/fd/1 /dev/stdout -ln -sf /proc/self/fd/2 /dev/stderr -modprobe virtio_pci -modprobe virtio_net -modprobe dm_mod ||: -/sbin/ifconfig lo 127.0.0.1 -/sbin/ifconfig eth0 10.0.2.10 -/sbin/route add default gw 10.0.2.2 -lvm vgscan --ignorelockingfailure -lvm vgchange -ay --ignorelockingfailure -exec guestfsd -f -__EOF__ - -@FEBOOTSTRAP_INSTALL@ initramfs init.new /init 0755 root.root -rm init.new - -# Just in case the kernel isn't looking for /init, make /sbin/init -# be our script, not the real init. -#@FEBOOTSTRAP_RUN@ initramfs -- ln -f /init /sbin/init - -# Copy the daemon into the filesystem. -@FEBOOTSTRAP_INSTALL@ initramfs daemon/guestfsd /sbin/guestfsd 0755 root.root - -# Generate final image. -@FEBOOTSTRAP_TO_INITRAMFS@ initramfs > $output-t -mv $output-t $output -ls -lh $output -ls -lh $koutput diff --git a/appliance/make.sh.in b/appliance/make.sh.in new file mode 100755 index 0000000..cf772e0 --- /dev/null +++ b/appliance/make.sh.in @@ -0,0 +1,145 @@ +#!/bin/bash - +# @configure_input@ +# Copyright (C) 2009 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +# This is called from the Makefile to build the initramfs. + +unset CDPATH + +set -e + +if [ "@DIST@" = "REDHAT" ]; then + cd @top_builddir@ + # Decide on names for the final output. These have to match Makefile.am. + output=appliance/initramfs.@REPO@.@host_cpu@.img + koutput=appliance/vmlinuz.@REPO@.@host_cpu@ + rm -f $output + rm -f $koutput + + # Create the basic initramfs. + exec 5= 11, it pulls in all of Perl from somewhere. Nuke from orbit. + @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /usr/lib/perl5 /usr/lib64/perl5 + + # Anaconda? JPEG images? + @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /usr/lib/anaconda-runtime + + # Don't need any firmware. + @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /lib/firmware + + # Don't need any keyboard maps. + @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /lib/kbd + + # Remove anything in home directory. Because this is potentially + # liable to monstrous fuck-ups, we don't put a slash before 'home'. + (cd initramfs && echo home/*) | + xargs @FEBOOTSTRAP_RUN@ initramfs -- rm -rf + + # Remove /var/lib/yum stuff. + @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /var/lib/yum + + # Remove some unreadable binaries which are incompatible with + # the supermin appliance. Since these binaries can't be read + # from the host filesystem, they generate warnings like: + # cpio: ./usr/bin/chfn: Cannot open: Permission denied + # These binaries are not needed for operation of the appliance. + @FEBOOTSTRAP_RUN@ initramfs -- rm -f \ + /usr/bin/chfn \ + /usr/bin/chsh \ + /usr/libexec/pt_chown \ + /usr/sbin/groupdel \ + /usr/sbin/groupadd \ + /usr/sbin/useradd \ + /usr/sbin/tzdata-update \ + /usr/sbin/userdel \ + /usr/sbin/usermod \ + /usr/sbin/groupmod \ + /usr/sbin/groupmems \ + /sbin/unix_update \ + $(cd initramfs && echo usr/sbin/glibc_post_upgrade.*) + + # Kernel modules take up nearly half of the image. Only include ones + # which are on the whitelist. + exec 5 hosts.new <<'__EOF__' + 127.0.0.1 guestfs localhost.localdomain localhost + ::1 localhost6.localdomain6 localhost6 +__EOF__ + @FEBOOTSTRAP_INSTALL@ initramfs hosts.new /etc/hosts 0644 root.root + rm hosts.new + fi + + if [ ! -f initramfs/etc/fstab ]; then + @FEBOOTSTRAP_RUN@ initramfs -- touch /etc/fstab + fi + + echo nameserver 10.0.2.3 > resolv.conf.new + @FEBOOTSTRAP_INSTALL@ initramfs resolv.conf.new /etc/resolv.conf 0644 root.root + rm resolv.conf.new + + ls -lh $koutput + + # Now directly run the update script to copy/update the daemon in the + # initramfs. + cd appliance && bash update.sh + +elif [ "@DIST@" = "DEBIAN" ]; then + cd @top_builddir@/appliance + debirf make -n debian +fi + diff --git a/appliance/packagelist.in b/appliance/packagelist.in new file mode 100644 index 0000000..9dbef11 --- /dev/null +++ b/appliance/packagelist.in @@ -0,0 +1,42 @@ +/* This is the list of distro packages which are + * installed on the appliance. + * + * This file is processed by cpp with one of the + * following symbols defined (depending on the distro): + * + * REDHAT=1 For Fedora, RHEL, EPEL and workalikes. + * DEBIAN=1 For Debian based distros. + */ + +#if REDHAT == 1 + augeas-libs + iputils + kernel + MAKEDEV + ntfsprogs + scrub + udev + util-linux-ng +#elif DEBIAN == 1 + bsdmainutils + iproute + libaugeas0 + udev + util-linux +#endif + +bash +binutils +coreutils +dosfstools +file +grub +lsof +lvm2 +module-init-tools +net-tools +ntfs-3g +procps +strace +zerofree + diff --git a/appliance/update-initramfs.sh.in b/appliance/supermin-make.sh.in similarity index 73% rename from appliance/update-initramfs.sh.in rename to appliance/supermin-make.sh.in index 3b779f8..c40dec9 100755 --- a/appliance/update-initramfs.sh.in +++ b/appliance/supermin-make.sh.in @@ -16,8 +16,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# Update the daemon inside an existing initramfs. Avoids the -# timeconsuming rebuild. +# Build the supermin appliance. +# Read the README file! unset CDPATH @@ -25,12 +25,12 @@ set -e cd @top_builddir@ -output=appliance/initramfs.@REPO@.@host_cpu@.img - -# Copy the daemon into the filesystem. -@FEBOOTSTRAP_INSTALL@ initramfs daemon/guestfsd /sbin/guestfsd 0755 root.root +output=appliance/initramfs.@REPO@.@host_cpu@.supermin.img # Generate final image. -@FEBOOTSTRAP_TO_INITRAMFS@ initramfs > $output-t +@FEBOOTSTRAP_TO_INITRAMFS@ \ + --nocompress \ + --files=$(pwd)/appliance/supermin.incfiles \ + initramfs > $output-t mv $output-t $output ls -lh $output diff --git a/appliance/supermin-split.sh.in b/appliance/supermin-split.sh.in new file mode 100755 index 0000000..fe4ab6e --- /dev/null +++ b/appliance/supermin-split.sh.in @@ -0,0 +1,93 @@ +#!/bin/bash - +# @configure_input@ +# Copyright (C) 2009 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +# Decide which files will stay in the supermin appliance and which +# files will be pulled out of the host at runtime. +# +# Read the README file! +# +# The basic idea is that we create two output files, one containing +# the files that will stay, and the other listing the files that +# will be pulled from the host (ie. not go into the appliance now). +# +# The list of files that stay ('supermin.incfiles') is just a straight +# list of files and directories. +# +# The list of files that come from the host ('*.supermin.hostfiles') +# can include wildcards, to allow libraries to be upgraded on the +# host. + +unset CDPATH + +set -e + +cd @top_builddir@/initramfs + +incfiles=../appliance/supermin.incfiles +hostfiles=../appliance/initramfs.@REPO@.@host_cpu@.supermin.hostfiles + +exec 5>$incfiles +exec 6>$hostfiles + +# Note currently the initramfs contains ~2500 files, and none have +# "funny characters" in the names. So this is reasonable just to +# simplify the script. +for path in $(find -not -name fakeroot.log); do + dir=$(dirname "$path") + file=$(basename "$path") + + # All we're going to keep are the special files /init, the daemon, + # configuration files (/etc), devices and modifiable stuff (/var). + if [ "$path" = "./init" -o "$file" = "guestfsd" ]; then + echo "$path" >&5 + + elif [[ "$path" =~ '^\./etc' || "$path" =~ '^./dev' || "$path" =~ '^\./var' ]]; then + echo "$path" >&5 + + # Kernel modules are always copied in from the host, including all + # the dependency files. + elif [[ "$path" =~ '^\./lib/modules/' ]]; then + : + + elif [ -d "$path" ]; then + # Always write directory names to both output files. + echo "$path" >&5 + echo "$path" >&6 + + # Some libraries need fixed version numbers replaced by wildcards. + + elif [[ "$file" =~ '^ld-[.0-9]+\.so$' ]]; then + echo "$dir/ld-*.so" >&6 + + # libfoo-1.2.3.so + elif [[ "$file" =~ '^lib(.*)-[-.0-9]+\.so$' ]]; then + echo "$dir/lib${BASH_REMATCH[1]}-*.so" >&6 + + # libfoo-1.2.3.so.1.2.3 (but NOT '*.so.N') + elif [[ "$file" =~ '^lib(.*)-[-.0-9]+\.so\.([0-9]+)\.' ]]; then + echo "$dir/lib${BASH_REMATCH[1]}-*.so.${BASH_REMATCH[2]}.*" >&6 + + # libfoo.so.1.2.3 (but NOT '*.so.N') + elif [[ "$file" =~ '^lib(.*)\.so\.([0-9]+)\.' ]]; then + echo "$dir/lib${BASH_REMATCH[1]}.so.${BASH_REMATCH[2]}.*" >&6 + + else + # Anything else comes from the host directly. + echo "$path" >&6 + fi +done diff --git a/appliance/update.sh.in b/appliance/update.sh.in new file mode 100755 index 0000000..01e22b6 --- /dev/null +++ b/appliance/update.sh.in @@ -0,0 +1,49 @@ +#!/bin/bash - +# @configure_input@ +# Copyright (C) 2009 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +# Update the init script or daemon inside an existing initramfs. +# Avoids the timeconsuming rebuild. + +unset CDPATH + +set -e + +if [ "@DIST@" = "REDHAT" ]; then + cd @top_builddir@ + output=appliance/initramfs.@REPO@.@host_cpu@.img + + # Create the init script. + @FEBOOTSTRAP_INSTALL@ initramfs appliance/init /init 0755 root.root + + # Copy the daemon into the filesystem. + @FEBOOTSTRAP_INSTALL@ initramfs daemon/guestfsd /sbin/guestfsd 0755 root.root + + # Generate final image. + @FEBOOTSTRAP_TO_INITRAMFS@ initramfs > $output-t + mv $output-t $output + ls -lh $output +elif [ "@DIST@" = "DEBIAN" ]; then + cd @top_builddir@/appliance + + output=initramfs.@REPO@.@host_cpu@.img + vmlinuz=vmlinuz.@REPO@.@host_cpu@ + + ln -sf debian/debirf-libguestfs_@REPO@*.cgz $output + ln -sf debian/vmlinuz-* $vmlinuz +fi + diff --git a/capitests/tests.c b/capitests/tests.c deleted file mode 100644 index 536da7f..0000000 --- a/capitests/tests.c +++ /dev/null @@ -1,16651 +0,0 @@ -/* libguestfs generated file - * WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'. - * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST. - * - * Copyright (C) 2009 Red Hat Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include -#include -#include -#include -#include -#include - -#include "guestfs.h" - -static guestfs_h *g; -static int suppress_error = 0; - -static void print_error (guestfs_h *g, void *data, const char *msg) -{ - if (!suppress_error) - fprintf (stderr, "%s\n", msg); -} - -static void print_strings (char * const * const argv) -{ - int argc; - - for (argc = 0; argv[argc] != NULL; ++argc) - printf ("\t%s\n", argv[argc]); -} - -/* -static void print_table (char * const * const argv) -{ - int i; - - for (i = 0; argv[i] != NULL; i += 2) - printf ("%s: %s\n", argv[i], argv[i+1]); -} -*/ - -static void no_test_warnings (void) -{ - fprintf (stderr, "warning: \"guestfs_test0\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rint\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rinterr\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rint64\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rint64err\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rbool\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rboolerr\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rconststring\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rconststringerr\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rstring\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rstringerr\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rstringlist\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rstringlisterr\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rintbool\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rintboolerr\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rpvlist\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rpvlisterr\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rvglist\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rvglisterr\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rlvlist\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rlvlisterr\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rstat\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rstaterr\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rstatvfs\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rstatvfserr\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rhashtable\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_test0rhashtableerr\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_launch\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_wait_ready\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_kill_subprocess\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_add_drive\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_add_cdrom\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_add_drive_ro\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_config\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_set_qemu\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_get_qemu\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_set_path\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_get_path\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_set_append\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_get_append\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_set_autosync\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_get_autosync\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_set_verbose\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_get_verbose\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_is_ready\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_is_config\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_is_launching\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_is_busy\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_get_state\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_set_busy\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_set_ready\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_end_busy\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_ll\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_pvs_full\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_vgs_full\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_lvs_full\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_aug_init\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_aug_close\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_aug_defvar\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_aug_defnode\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_aug_get\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_aug_set\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_aug_insert\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_aug_rm\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_aug_mv\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_aug_match\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_aug_save\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_aug_load\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_aug_ls\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_chmod\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_chown\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_sfdisk\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_lvm_remove_all\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_tune2fs_l\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_blockdev_setbsz\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_tar_out\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_tgz_out\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_mount_options\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_mount_vfs\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_debug\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_get_e2label\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_get_e2uuid\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_pvresize\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_sfdisk_N\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_sfdisk_l\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_sfdisk_kernel_geometry\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_sfdisk_disk_geometry\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_vg_activate_all\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_vg_activate\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_resize2fs\" has no tests\n"); - fprintf (stderr, "warning: \"guestfs_e2fsck_f\" has no tests\n"); -} - -static int test_ntfs_3g_probe_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_NTFS_3G_PROBE_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_NTFS_3G_PROBE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_ntfs_3g_probe_0 (void) -{ - if (test_ntfs_3g_probe_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_ntfs_3g_probe_0"); - return 0; - } - - /* InitNone|InitEmpty for test_ntfs_3g_probe_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputInt for ntfs_3g_probe (0) */ - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ntfs"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_ntfs_3g_probe (g, 1, device); - if (r == -1) - return -1; - if (r != 0) { - fprintf (stderr, "test_ntfs_3g_probe_0: expected 0 but got %d\n", (int) r); - return -1; - } - } - return 0; -} - -static int test_ntfs_3g_probe_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_NTFS_3G_PROBE_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_NTFS_3G_PROBE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_ntfs_3g_probe_1 (void) -{ - if (test_ntfs_3g_probe_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_ntfs_3g_probe_1"); - return 0; - } - - /* InitNone|InitEmpty for test_ntfs_3g_probe_1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputInt for ntfs_3g_probe (1) */ - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_ntfs_3g_probe (g, 1, device); - if (r == -1) - return -1; - if (r != 12) { - fprintf (stderr, "test_ntfs_3g_probe_1: expected 12 but got %d\n", (int) r); - return -1; - } - } - return 0; -} - -static int test_sleep_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_SLEEP_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_SLEEP"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_sleep_0 (void) -{ - if (test_sleep_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_sleep_0"); - return 0; - } - - /* InitNone|InitEmpty for test_sleep_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestRun for sleep (0) */ - { - int r; - suppress_error = 0; - r = guestfs_sleep (g, 1); - if (r == -1) - return -1; - } - return 0; -} - -static int test_find_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_FIND_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_FIND"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_find_0 (void) -{ - if (test_find_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_find_0"); - return 0; - } - - /* InitBasicFS for test_find_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for find (0) */ - { - char directory[] = "/"; - char **r; - int i; - suppress_error = 0; - r = guestfs_find (g, directory); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_find_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "lost+found"; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_find_0: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (r[1] != NULL) { - fprintf (stderr, "test_find_0: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_find_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_FIND_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_FIND"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_find_1 (void) -{ - if (test_find_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_find_1"); - return 0; - } - - /* InitBasicFS for test_find_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for find (1) */ - { - char path[] = "/a"; - int r; - suppress_error = 0; - r = guestfs_touch (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/b"; - int r; - suppress_error = 0; - r = guestfs_mkdir (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/b/c"; - int r; - suppress_error = 0; - r = guestfs_touch (g, path); - if (r == -1) - return -1; - } - { - char directory[] = "/"; - char **r; - int i; - suppress_error = 0; - r = guestfs_find (g, directory); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_find_1: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "a"; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_find_1: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (!r[1]) { - fprintf (stderr, "test_find_1: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "b"; - if (strcmp (r[1], expected) != 0) { - fprintf (stderr, "test_find_1: expected \"%s\" but got \"%s\"\n", expected, r[1]); - return -1; - } - } - if (!r[2]) { - fprintf (stderr, "test_find_1: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "b/c"; - if (strcmp (r[2], expected) != 0) { - fprintf (stderr, "test_find_1: expected \"%s\" but got \"%s\"\n", expected, r[2]); - return -1; - } - } - if (!r[3]) { - fprintf (stderr, "test_find_1: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "lost+found"; - if (strcmp (r[3], expected) != 0) { - fprintf (stderr, "test_find_1: expected \"%s\" but got \"%s\"\n", expected, r[3]); - return -1; - } - } - if (r[4] != NULL) { - fprintf (stderr, "test_find_1: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_find_2_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_FIND_2"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_FIND"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_find_2 (void) -{ - if (test_find_2_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_find_2"); - return 0; - } - - /* InitBasicFS for test_find_2: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for find (2) */ - { - char path[] = "/a/b/c"; - int r; - suppress_error = 0; - r = guestfs_mkdir_p (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/a/b/c/d"; - int r; - suppress_error = 0; - r = guestfs_touch (g, path); - if (r == -1) - return -1; - } - { - char directory[] = "/a/b/"; - char **r; - int i; - suppress_error = 0; - r = guestfs_find (g, directory); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_find_2: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "c"; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_find_2: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (!r[1]) { - fprintf (stderr, "test_find_2: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "c/d"; - if (strcmp (r[1], expected) != 0) { - fprintf (stderr, "test_find_2: expected \"%s\" but got \"%s\"\n", expected, r[1]); - return -1; - } - } - if (r[2] != NULL) { - fprintf (stderr, "test_find_2: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_lvresize_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_LVRESIZE_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_LVRESIZE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_lvresize_0 (void) -{ - if (test_lvresize_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_lvresize_0"); - return 0; - } - - /* InitNone|InitEmpty for test_lvresize_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutput for lvresize (0) */ - char expected[] = "test content"; - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char volgroup[] = "VG"; - char physvols_0[] = "/dev/sda1"; - char *physvols[] = { - physvols_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, volgroup, physvols); - if (r == -1) - return -1; - } - { - char logvol[] = "LV"; - char volgroup[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 10); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/VG/LV"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/VG/LV"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char content[] = "test content"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char pathordevice[] = "/"; - int r; - suppress_error = 0; - r = guestfs_umount (g, pathordevice); - if (r == -1) - return -1; - } - { - char device[] = "/dev/VG/LV"; - int r; - suppress_error = 0; - r = guestfs_lvresize (g, device, 20); - if (r == -1) - return -1; - } - { - char device[] = "/dev/VG/LV"; - int r; - suppress_error = 0; - r = guestfs_e2fsck_f (g, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/VG/LV"; - int r; - suppress_error = 0; - r = guestfs_resize2fs (g, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/VG/LV"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_cat (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_lvresize_0: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_zerofree_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_ZEROFREE_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_ZEROFREE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_zerofree_0 (void) -{ - if (test_zerofree_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_zerofree_0"); - return 0; - } - - /* InitNone|InitEmpty for test_zerofree_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutput for zerofree (0) */ - char expected[] = "test file"; - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext3"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char content[] = "test file"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char pathordevice[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_umount (g, pathordevice); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_zerofree (g, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_cat (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_zerofree_0: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_hexdump_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_HEXDUMP_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_HEXDUMP"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_hexdump_0 (void) -{ - if (test_hexdump_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_hexdump_0"); - return 0; - } - - /* InitBasicFS for test_hexdump_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for hexdump (0) */ - char expected[] = "00000000 68 65 6c 6c 6f 0a 77 6f 72 6c 64 0a |hello.world.|\n0000000c\n"; - { - char path[] = "/new"; - char content[] = "hello\nworld\n"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 12); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_hexdump (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_hexdump_0: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_strings_e_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_STRINGS_E_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_STRINGS_E"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_strings_e_0 (void) -{ - if (test_strings_e_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_strings_e_0"); - return 0; - } - - /* InitBasicFS for test_strings_e_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for strings_e (0) */ - { - char path[] = "/new"; - char content[] = "hello\nworld\n"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char encoding[] = "b"; - char path[] = "/new"; - char **r; - int i; - suppress_error = 0; - r = guestfs_strings_e (g, encoding, path); - if (r == NULL) - return -1; - if (r[0] != NULL) { - fprintf (stderr, "test_strings_e_0: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_strings_e_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_STRINGS_E_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_STRINGS_E"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_strings_e_1 (void) -{ - if (test_strings_e_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_strings_e_1"); - return 0; - } - - printf ("%s skipped (reason: test disabled in generator)\n", "test_strings_e_1"); - return 0; -} - -static int test_strings_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_STRINGS_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_STRINGS"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_strings_0 (void) -{ - if (test_strings_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_strings_0"); - return 0; - } - - /* InitBasicFS for test_strings_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for strings (0) */ - { - char path[] = "/new"; - char content[] = "hello\nworld\n"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char **r; - int i; - suppress_error = 0; - r = guestfs_strings (g, path); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_strings_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "hello"; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_strings_0: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (!r[1]) { - fprintf (stderr, "test_strings_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "world"; - if (strcmp (r[1], expected) != 0) { - fprintf (stderr, "test_strings_0: expected \"%s\" but got \"%s\"\n", expected, r[1]); - return -1; - } - } - if (r[2] != NULL) { - fprintf (stderr, "test_strings_0: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_strings_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_STRINGS_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_STRINGS"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_strings_1 (void) -{ - if (test_strings_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_strings_1"); - return 0; - } - - /* InitBasicFS for test_strings_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for strings (1) */ - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_touch (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char **r; - int i; - suppress_error = 0; - r = guestfs_strings (g, path); - if (r == NULL) - return -1; - if (r[0] != NULL) { - fprintf (stderr, "test_strings_1: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_equal_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_EQUAL_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_EQUAL"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_equal_0 (void) -{ - if (test_equal_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_equal_0"); - return 0; - } - - /* InitBasicFS for test_equal_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputTrue for equal (0) */ - { - char path[] = "/file1"; - char content[] = "contents of a file"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char src[] = "/file1"; - char dest[] = "/file2"; - int r; - suppress_error = 0; - r = guestfs_cp (g, src, dest); - if (r == -1) - return -1; - } - { - char file1[] = "/file1"; - char file2[] = "/file2"; - int r; - suppress_error = 0; - r = guestfs_equal (g, file1, file2); - if (r == -1) - return -1; - if (!r) { - fprintf (stderr, "test_equal_0: expected true, got false\n"); - return -1; - } - } - return 0; -} - -static int test_equal_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_EQUAL_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_EQUAL"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_equal_1 (void) -{ - if (test_equal_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_equal_1"); - return 0; - } - - /* InitBasicFS for test_equal_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputFalse for equal (1) */ - { - char path[] = "/file1"; - char content[] = "contents of a file"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char path[] = "/file2"; - char content[] = "contents of another file"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char file1[] = "/file1"; - char file2[] = "/file2"; - int r; - suppress_error = 0; - r = guestfs_equal (g, file1, file2); - if (r == -1) - return -1; - if (r) { - fprintf (stderr, "test_equal_1: expected false, got true\n"); - return -1; - } - } - return 0; -} - -static int test_equal_2_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_EQUAL_2"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_EQUAL"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_equal_2 (void) -{ - if (test_equal_2_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_equal_2"); - return 0; - } - - /* InitBasicFS for test_equal_2: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestLastFail for equal (2) */ - { - char file1[] = "/file1"; - char file2[] = "/file2"; - int r; - suppress_error = 1; - r = guestfs_equal (g, file1, file2); - if (r != -1) - return -1; - } - return 0; -} - -static int test_ping_daemon_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_PING_DAEMON_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_PING_DAEMON"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_ping_daemon_0 (void) -{ - if (test_ping_daemon_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_ping_daemon_0"); - return 0; - } - - /* InitNone|InitEmpty for test_ping_daemon_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestRun for ping_daemon (0) */ - { - int r; - suppress_error = 0; - r = guestfs_ping_daemon (g); - if (r == -1) - return -1; - } - return 0; -} - -static int test_dmesg_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_DMESG_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_DMESG"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_dmesg_0 (void) -{ - if (test_dmesg_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_dmesg_0"); - return 0; - } - - /* InitNone|InitEmpty for test_dmesg_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestRun for dmesg (0) */ - { - char *r; - suppress_error = 0; - r = guestfs_dmesg (g); - if (r == NULL) - return -1; - free (r); - } - return 0; -} - -static int test_drop_caches_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_DROP_CACHES_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_DROP_CACHES"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_drop_caches_0 (void) -{ - if (test_drop_caches_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_drop_caches_0"); - return 0; - } - - /* InitNone|InitEmpty for test_drop_caches_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestRun for drop_caches (0) */ - { - int r; - suppress_error = 0; - r = guestfs_drop_caches (g, 3); - if (r == -1) - return -1; - } - return 0; -} - -static int test_mv_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_MV_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_MV"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_mv_0 (void) -{ - if (test_mv_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_mv_0"); - return 0; - } - - /* InitBasicFS for test_mv_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for mv (0) */ - char expected[] = "file content"; - { - char path[] = "/old"; - char content[] = "file content"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char src[] = "/old"; - char dest[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_mv (g, src, dest); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_cat (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_mv_0: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_mv_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_MV_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_MV"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_mv_1 (void) -{ - if (test_mv_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_mv_1"); - return 0; - } - - /* InitBasicFS for test_mv_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputFalse for mv (1) */ - { - char path[] = "/old"; - char content[] = "file content"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char src[] = "/old"; - char dest[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_mv (g, src, dest); - if (r == -1) - return -1; - } - { - char path[] = "/old"; - int r; - suppress_error = 0; - r = guestfs_is_file (g, path); - if (r == -1) - return -1; - if (r) { - fprintf (stderr, "test_mv_1: expected false, got true\n"); - return -1; - } - } - return 0; -} - -static int test_cp_a_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_CP_A_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_CP_A"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_cp_a_0 (void) -{ - if (test_cp_a_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_cp_a_0"); - return 0; - } - - /* InitBasicFS for test_cp_a_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for cp_a (0) */ - char expected[] = "file content"; - { - char path[] = "/olddir"; - int r; - suppress_error = 0; - r = guestfs_mkdir (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/newdir"; - int r; - suppress_error = 0; - r = guestfs_mkdir (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/olddir/file"; - char content[] = "file content"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char src[] = "/olddir"; - char dest[] = "/newdir"; - int r; - suppress_error = 0; - r = guestfs_cp_a (g, src, dest); - if (r == -1) - return -1; - } - { - char path[] = "/newdir/olddir/file"; - char *r; - suppress_error = 0; - r = guestfs_cat (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_cp_a_0: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_cp_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_CP_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_CP"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_cp_0 (void) -{ - if (test_cp_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_cp_0"); - return 0; - } - - /* InitBasicFS for test_cp_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for cp (0) */ - char expected[] = "file content"; - { - char path[] = "/old"; - char content[] = "file content"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char src[] = "/old"; - char dest[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_cp (g, src, dest); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_cat (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_cp_0: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_cp_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_CP_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_CP"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_cp_1 (void) -{ - if (test_cp_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_cp_1"); - return 0; - } - - /* InitBasicFS for test_cp_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputTrue for cp (1) */ - { - char path[] = "/old"; - char content[] = "file content"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char src[] = "/old"; - char dest[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_cp (g, src, dest); - if (r == -1) - return -1; - } - { - char path[] = "/old"; - int r; - suppress_error = 0; - r = guestfs_is_file (g, path); - if (r == -1) - return -1; - if (!r) { - fprintf (stderr, "test_cp_1: expected true, got false\n"); - return -1; - } - } - return 0; -} - -static int test_cp_2_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_CP_2"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_CP"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_cp_2 (void) -{ - if (test_cp_2_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_cp_2"); - return 0; - } - - /* InitBasicFS for test_cp_2: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for cp (2) */ - char expected[] = "file content"; - { - char path[] = "/old"; - char content[] = "file content"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char path[] = "/dir"; - int r; - suppress_error = 0; - r = guestfs_mkdir (g, path); - if (r == -1) - return -1; - } - { - char src[] = "/old"; - char dest[] = "/dir/new"; - int r; - suppress_error = 0; - r = guestfs_cp (g, src, dest); - if (r == -1) - return -1; - } - { - char path[] = "/dir/new"; - char *r; - suppress_error = 0; - r = guestfs_cat (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_cp_2: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_grub_install_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_GRUB_INSTALL_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_GRUB_INSTALL"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_grub_install_0 (void) -{ - if (test_grub_install_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_grub_install_0"); - return 0; - } - - /* InitBasicFS for test_grub_install_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputTrue for grub_install (0) */ - { - char root[] = "/"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_grub_install (g, root, device); - if (r == -1) - return -1; - } - { - char path[] = "/boot"; - int r; - suppress_error = 0; - r = guestfs_is_dir (g, path); - if (r == -1) - return -1; - if (!r) { - fprintf (stderr, "test_grub_install_0: expected true, got false\n"); - return -1; - } - } - return 0; -} - -static int test_zero_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_ZERO_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_ZERO"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_zero_0 (void) -{ - if (test_zero_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_zero_0"); - return 0; - } - - /* InitBasicFS for test_zero_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for zero (0) */ - char expected[] = "data"; - { - char pathordevice[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_umount (g, pathordevice); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_zero (g, device); - if (r == -1) - return -1; - } - { - char path[] = "/dev/sda1"; - char *r; - suppress_error = 0; - r = guestfs_file (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_zero_0: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_fsck_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_FSCK_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_FSCK"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_fsck_0 (void) -{ - if (test_fsck_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_fsck_0"); - return 0; - } - - /* InitBasicFS for test_fsck_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputInt for fsck (0) */ - { - char pathordevice[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_umount (g, pathordevice); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_fsck (g, fstype, device); - if (r == -1) - return -1; - if (r != 0) { - fprintf (stderr, "test_fsck_0: expected 0 but got %d\n", (int) r); - return -1; - } - } - return 0; -} - -static int test_fsck_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_FSCK_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_FSCK"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_fsck_1 (void) -{ - if (test_fsck_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_fsck_1"); - return 0; - } - - /* InitBasicFS for test_fsck_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputInt for fsck (1) */ - { - char pathordevice[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_umount (g, pathordevice); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_zero (g, device); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_fsck (g, fstype, device); - if (r == -1) - return -1; - if (r != 8) { - fprintf (stderr, "test_fsck_1: expected 8 but got %d\n", (int) r); - return -1; - } - } - return 0; -} - -static int test_set_e2uuid_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_SET_E2UUID_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_SET_E2UUID"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_set_e2uuid_0 (void) -{ - if (test_set_e2uuid_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_set_e2uuid_0"); - return 0; - } - - /* InitBasicFS for test_set_e2uuid_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for set_e2uuid (0) */ - char expected[] = "a3a61220-882b-4f61-89f4-cf24dcc7297d"; - { - char device[] = "/dev/sda1"; - char uuid[] = "a3a61220-882b-4f61-89f4-cf24dcc7297d"; - int r; - suppress_error = 0; - r = guestfs_set_e2uuid (g, device, uuid); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char *r; - suppress_error = 0; - r = guestfs_get_e2uuid (g, device); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_set_e2uuid_0: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_set_e2uuid_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_SET_E2UUID_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_SET_E2UUID"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_set_e2uuid_1 (void) -{ - if (test_set_e2uuid_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_set_e2uuid_1"); - return 0; - } - - /* InitBasicFS for test_set_e2uuid_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for set_e2uuid (1) */ - char expected[] = ""; - { - char device[] = "/dev/sda1"; - char uuid[] = "clear"; - int r; - suppress_error = 0; - r = guestfs_set_e2uuid (g, device, uuid); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char *r; - suppress_error = 0; - r = guestfs_get_e2uuid (g, device); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_set_e2uuid_1: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_set_e2uuid_2_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_SET_E2UUID_2"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_SET_E2UUID"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_set_e2uuid_2 (void) -{ - if (test_set_e2uuid_2_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_set_e2uuid_2"); - return 0; - } - - /* InitBasicFS for test_set_e2uuid_2: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestRun for set_e2uuid (2) */ - { - char device[] = "/dev/sda1"; - char uuid[] = "random"; - int r; - suppress_error = 0; - r = guestfs_set_e2uuid (g, device, uuid); - if (r == -1) - return -1; - } - return 0; -} - -static int test_set_e2uuid_3_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_SET_E2UUID_3"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_SET_E2UUID"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_set_e2uuid_3 (void) -{ - if (test_set_e2uuid_3_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_set_e2uuid_3"); - return 0; - } - - /* InitBasicFS for test_set_e2uuid_3: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestRun for set_e2uuid (3) */ - { - char device[] = "/dev/sda1"; - char uuid[] = "time"; - int r; - suppress_error = 0; - r = guestfs_set_e2uuid (g, device, uuid); - if (r == -1) - return -1; - } - return 0; -} - -static int test_set_e2label_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_SET_E2LABEL_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_SET_E2LABEL"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_set_e2label_0 (void) -{ - if (test_set_e2label_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_set_e2label_0"); - return 0; - } - - /* InitBasicFS for test_set_e2label_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for set_e2label (0) */ - char expected[] = "testlabel"; - { - char device[] = "/dev/sda1"; - char label[] = "testlabel"; - int r; - suppress_error = 0; - r = guestfs_set_e2label (g, device, label); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char *r; - suppress_error = 0; - r = guestfs_get_e2label (g, device); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_set_e2label_0: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_pvremove_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_PVREMOVE_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_PVREMOVE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_pvremove_0 (void) -{ - if (test_pvremove_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_pvremove_0"); - return 0; - } - - /* InitNone|InitEmpty for test_pvremove_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputListOfDevices for pvremove (0) */ - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char volgroup[] = "VG"; - char physvols_0[] = "/dev/sda1"; - char *physvols[] = { - physvols_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, volgroup, physvols); - if (r == -1) - return -1; - } - { - char logvol[] = "LV1"; - char volgroup[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char logvol[] = "LV2"; - char volgroup[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char vgname[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_vgremove (g, vgname); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvremove (g, device); - if (r == -1) - return -1; - } - { - char **r; - int i; - suppress_error = 0; - r = guestfs_lvs (g); - if (r == NULL) - return -1; - if (r[0] != NULL) { - fprintf (stderr, "test_pvremove_0: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_pvremove_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_PVREMOVE_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_PVREMOVE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_pvremove_1 (void) -{ - if (test_pvremove_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_pvremove_1"); - return 0; - } - - /* InitNone|InitEmpty for test_pvremove_1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputListOfDevices for pvremove (1) */ - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char volgroup[] = "VG"; - char physvols_0[] = "/dev/sda1"; - char *physvols[] = { - physvols_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, volgroup, physvols); - if (r == -1) - return -1; - } - { - char logvol[] = "LV1"; - char volgroup[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char logvol[] = "LV2"; - char volgroup[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char vgname[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_vgremove (g, vgname); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvremove (g, device); - if (r == -1) - return -1; - } - { - char **r; - int i; - suppress_error = 0; - r = guestfs_vgs (g); - if (r == NULL) - return -1; - if (r[0] != NULL) { - fprintf (stderr, "test_pvremove_1: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_pvremove_2_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_PVREMOVE_2"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_PVREMOVE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_pvremove_2 (void) -{ - if (test_pvremove_2_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_pvremove_2"); - return 0; - } - - /* InitNone|InitEmpty for test_pvremove_2 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputListOfDevices for pvremove (2) */ - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char volgroup[] = "VG"; - char physvols_0[] = "/dev/sda1"; - char *physvols[] = { - physvols_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, volgroup, physvols); - if (r == -1) - return -1; - } - { - char logvol[] = "LV1"; - char volgroup[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char logvol[] = "LV2"; - char volgroup[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char vgname[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_vgremove (g, vgname); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvremove (g, device); - if (r == -1) - return -1; - } - { - char **r; - int i; - suppress_error = 0; - r = guestfs_pvs (g); - if (r == NULL) - return -1; - if (r[0] != NULL) { - fprintf (stderr, "test_pvremove_2: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_vgremove_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_VGREMOVE_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_VGREMOVE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_vgremove_0 (void) -{ - if (test_vgremove_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_vgremove_0"); - return 0; - } - - /* InitNone|InitEmpty for test_vgremove_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputList for vgremove (0) */ - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char volgroup[] = "VG"; - char physvols_0[] = "/dev/sda1"; - char *physvols[] = { - physvols_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, volgroup, physvols); - if (r == -1) - return -1; - } - { - char logvol[] = "LV1"; - char volgroup[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char logvol[] = "LV2"; - char volgroup[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char vgname[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_vgremove (g, vgname); - if (r == -1) - return -1; - } - { - char **r; - int i; - suppress_error = 0; - r = guestfs_lvs (g); - if (r == NULL) - return -1; - if (r[0] != NULL) { - fprintf (stderr, "test_vgremove_0: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_vgremove_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_VGREMOVE_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_VGREMOVE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_vgremove_1 (void) -{ - if (test_vgremove_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_vgremove_1"); - return 0; - } - - /* InitNone|InitEmpty for test_vgremove_1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputList for vgremove (1) */ - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char volgroup[] = "VG"; - char physvols_0[] = "/dev/sda1"; - char *physvols[] = { - physvols_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, volgroup, physvols); - if (r == -1) - return -1; - } - { - char logvol[] = "LV1"; - char volgroup[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char logvol[] = "LV2"; - char volgroup[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char vgname[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_vgremove (g, vgname); - if (r == -1) - return -1; - } - { - char **r; - int i; - suppress_error = 0; - r = guestfs_vgs (g); - if (r == NULL) - return -1; - if (r[0] != NULL) { - fprintf (stderr, "test_vgremove_1: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_lvremove_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_LVREMOVE_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_LVREMOVE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_lvremove_0 (void) -{ - if (test_lvremove_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_lvremove_0"); - return 0; - } - - /* InitNone|InitEmpty for test_lvremove_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputList for lvremove (0) */ - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char volgroup[] = "VG"; - char physvols_0[] = "/dev/sda1"; - char *physvols[] = { - physvols_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, volgroup, physvols); - if (r == -1) - return -1; - } - { - char logvol[] = "LV1"; - char volgroup[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char logvol[] = "LV2"; - char volgroup[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char device[] = "/dev/VG/LV1"; - int r; - suppress_error = 0; - r = guestfs_lvremove (g, device); - if (r == -1) - return -1; - } - { - char **r; - int i; - suppress_error = 0; - r = guestfs_lvs (g); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_lvremove_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/VG/LV2"; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_lvremove_0: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (r[1] != NULL) { - fprintf (stderr, "test_lvremove_0: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_lvremove_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_LVREMOVE_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_LVREMOVE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_lvremove_1 (void) -{ - if (test_lvremove_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_lvremove_1"); - return 0; - } - - /* InitNone|InitEmpty for test_lvremove_1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputList for lvremove (1) */ - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char volgroup[] = "VG"; - char physvols_0[] = "/dev/sda1"; - char *physvols[] = { - physvols_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, volgroup, physvols); - if (r == -1) - return -1; - } - { - char logvol[] = "LV1"; - char volgroup[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char logvol[] = "LV2"; - char volgroup[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char device[] = "/dev/VG"; - int r; - suppress_error = 0; - r = guestfs_lvremove (g, device); - if (r == -1) - return -1; - } - { - char **r; - int i; - suppress_error = 0; - r = guestfs_lvs (g); - if (r == NULL) - return -1; - if (r[0] != NULL) { - fprintf (stderr, "test_lvremove_1: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_lvremove_2_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_LVREMOVE_2"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_LVREMOVE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_lvremove_2 (void) -{ - if (test_lvremove_2_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_lvremove_2"); - return 0; - } - - /* InitNone|InitEmpty for test_lvremove_2 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputList for lvremove (2) */ - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char volgroup[] = "VG"; - char physvols_0[] = "/dev/sda1"; - char *physvols[] = { - physvols_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, volgroup, physvols); - if (r == -1) - return -1; - } - { - char logvol[] = "LV1"; - char volgroup[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char logvol[] = "LV2"; - char volgroup[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char device[] = "/dev/VG"; - int r; - suppress_error = 0; - r = guestfs_lvremove (g, device); - if (r == -1) - return -1; - } - { - char **r; - int i; - suppress_error = 0; - r = guestfs_vgs (g); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_lvremove_2: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "VG"; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_lvremove_2: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (r[1] != NULL) { - fprintf (stderr, "test_lvremove_2: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_mount_ro_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_MOUNT_RO_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_MOUNT_RO"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_mount_ro_0 (void) -{ - if (test_mount_ro_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_mount_ro_0"); - return 0; - } - - /* InitBasicFS for test_mount_ro_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestLastFail for mount_ro (0) */ - { - char pathordevice[] = "/"; - int r; - suppress_error = 0; - r = guestfs_umount (g, pathordevice); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount_ro (g, device, mountpoint); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - int r; - suppress_error = 1; - r = guestfs_touch (g, path); - if (r != -1) - return -1; - } - return 0; -} - -static int test_mount_ro_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_MOUNT_RO_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_MOUNT_RO"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_mount_ro_1 (void) -{ - if (test_mount_ro_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_mount_ro_1"); - return 0; - } - - /* InitBasicFS for test_mount_ro_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for mount_ro (1) */ - char expected[] = "data"; - { - char path[] = "/new"; - char content[] = "data"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char pathordevice[] = "/"; - int r; - suppress_error = 0; - r = guestfs_umount (g, pathordevice); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount_ro (g, device, mountpoint); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_cat (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_mount_ro_1: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_tgz_in_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_TGZ_IN_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_TGZ_IN"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_tgz_in_0 (void) -{ - if (test_tgz_in_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_tgz_in_0"); - return 0; - } - - /* InitBasicFS for test_tgz_in_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for tgz_in (0) */ - char expected[] = "hello\n"; - { - char directory[] = "/"; - int r; - suppress_error = 0; - r = guestfs_tgz_in (g, "../images/helloworld.tar.gz", directory); - if (r == -1) - return -1; - } - { - char path[] = "/hello"; - char *r; - suppress_error = 0; - r = guestfs_cat (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_tgz_in_0: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_tar_in_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_TAR_IN_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_TAR_IN"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_tar_in_0 (void) -{ - if (test_tar_in_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_tar_in_0"); - return 0; - } - - /* InitBasicFS for test_tar_in_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for tar_in (0) */ - char expected[] = "hello\n"; - { - char directory[] = "/"; - int r; - suppress_error = 0; - r = guestfs_tar_in (g, "../images/helloworld.tar", directory); - if (r == -1) - return -1; - } - { - char path[] = "/hello"; - char *r; - suppress_error = 0; - r = guestfs_cat (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_tar_in_0: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_checksum_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_CHECKSUM_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_CHECKSUM"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_checksum_0 (void) -{ - if (test_checksum_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_checksum_0"); - return 0; - } - - /* InitBasicFS for test_checksum_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for checksum (0) */ - char expected[] = "935282863"; - { - char path[] = "/new"; - char content[] = "test\n"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char csumtype[] = "crc"; - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_checksum (g, csumtype, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_checksum_0: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_checksum_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_CHECKSUM_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_CHECKSUM"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_checksum_1 (void) -{ - if (test_checksum_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_checksum_1"); - return 0; - } - - /* InitBasicFS for test_checksum_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestLastFail for checksum (1) */ - { - char csumtype[] = "crc"; - char path[] = "/new"; - char *r; - suppress_error = 1; - r = guestfs_checksum (g, csumtype, path); - if (r != NULL) - return -1; - free (r); - } - return 0; -} - -static int test_checksum_2_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_CHECKSUM_2"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_CHECKSUM"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_checksum_2 (void) -{ - if (test_checksum_2_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_checksum_2"); - return 0; - } - - /* InitBasicFS for test_checksum_2: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for checksum (2) */ - char expected[] = "d8e8fca2dc0f896fd7cb4cb0031ba249"; - { - char path[] = "/new"; - char content[] = "test\n"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char csumtype[] = "md5"; - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_checksum (g, csumtype, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_checksum_2: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_checksum_3_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_CHECKSUM_3"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_CHECKSUM"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_checksum_3 (void) -{ - if (test_checksum_3_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_checksum_3"); - return 0; - } - - /* InitBasicFS for test_checksum_3: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for checksum (3) */ - char expected[] = "4e1243bd22c66e76c2ba9eddc1f91394e57f9f83"; - { - char path[] = "/new"; - char content[] = "test\n"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char csumtype[] = "sha1"; - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_checksum (g, csumtype, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_checksum_3: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_checksum_4_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_CHECKSUM_4"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_CHECKSUM"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_checksum_4 (void) -{ - if (test_checksum_4_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_checksum_4"); - return 0; - } - - /* InitBasicFS for test_checksum_4: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for checksum (4) */ - char expected[] = "52f1bf093f4b7588726035c176c0cdb4376cfea53819f1395ac9e6ec"; - { - char path[] = "/new"; - char content[] = "test\n"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char csumtype[] = "sha224"; - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_checksum (g, csumtype, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_checksum_4: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_checksum_5_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_CHECKSUM_5"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_CHECKSUM"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_checksum_5 (void) -{ - if (test_checksum_5_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_checksum_5"); - return 0; - } - - /* InitBasicFS for test_checksum_5: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for checksum (5) */ - char expected[] = "f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2"; - { - char path[] = "/new"; - char content[] = "test\n"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char csumtype[] = "sha256"; - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_checksum (g, csumtype, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_checksum_5: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_checksum_6_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_CHECKSUM_6"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_CHECKSUM"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_checksum_6 (void) -{ - if (test_checksum_6_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_checksum_6"); - return 0; - } - - /* InitBasicFS for test_checksum_6: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for checksum (6) */ - char expected[] = "109bb6b5b6d5547c1ce03c7a8bd7d8f80c1cb0957f50c4f7fda04692079917e4f9cad52b878f3d8234e1a170b154b72d"; - { - char path[] = "/new"; - char content[] = "test\n"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char csumtype[] = "sha384"; - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_checksum (g, csumtype, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_checksum_6: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_checksum_7_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_CHECKSUM_7"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_CHECKSUM"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_checksum_7 (void) -{ - if (test_checksum_7_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_checksum_7"); - return 0; - } - - /* InitBasicFS for test_checksum_7: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for checksum (7) */ - char expected[] = "0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123"; - { - char path[] = "/new"; - char content[] = "test\n"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char csumtype[] = "sha512"; - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_checksum (g, csumtype, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_checksum_7: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_checksum_8_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_CHECKSUM_8"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_CHECKSUM"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_checksum_8 (void) -{ - if (test_checksum_8_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_checksum_8"); - return 0; - } - - /* InitBasicFS for test_checksum_8: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for checksum (8) */ - char expected[] = "46d6ca27ee07cdc6fa99c2e138cc522c"; - { - char options[] = "ro"; - char vfstype[] = "squashfs"; - char device[] = "/dev/sdd"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount_vfs (g, options, vfstype, device, mountpoint); - if (r == -1) - return -1; - } - { - char csumtype[] = "md5"; - char path[] = "/known-3"; - char *r; - suppress_error = 0; - r = guestfs_checksum (g, csumtype, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_checksum_8: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_download_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_DOWNLOAD_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_DOWNLOAD"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_download_0 (void) -{ - if (test_download_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_download_0"); - return 0; - } - - /* InitBasicFS for test_download_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for download (0) */ - char expected[] = "e3eda01d9815f8d24aae2dbd89b68b06"; - { - char remotefilename[] = "/COPYING.LIB"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "../COPYING.LIB", remotefilename); - if (r == -1) - return -1; - } - { - char remotefilename[] = "/COPYING.LIB"; - int r; - suppress_error = 0; - r = guestfs_download (g, remotefilename, "testdownload.tmp"); - if (r == -1) - return -1; - } - { - char remotefilename[] = "/upload"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "testdownload.tmp", remotefilename); - if (r == -1) - return -1; - } - { - char csumtype[] = "md5"; - char path[] = "/upload"; - char *r; - suppress_error = 0; - r = guestfs_checksum (g, csumtype, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_download_0: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_upload_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_UPLOAD_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_UPLOAD"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_upload_0 (void) -{ - if (test_upload_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_upload_0"); - return 0; - } - - /* InitBasicFS for test_upload_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for upload (0) */ - char expected[] = "e3eda01d9815f8d24aae2dbd89b68b06"; - { - char remotefilename[] = "/COPYING.LIB"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "../COPYING.LIB", remotefilename); - if (r == -1) - return -1; - } - { - char csumtype[] = "md5"; - char path[] = "/COPYING.LIB"; - char *r; - suppress_error = 0; - r = guestfs_checksum (g, csumtype, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_upload_0: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_blockdev_rereadpt_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_BLOCKDEV_REREADPT_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_BLOCKDEV_REREADPT"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_blockdev_rereadpt_0 (void) -{ - if (test_blockdev_rereadpt_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_blockdev_rereadpt_0"); - return 0; - } - - /* InitNone|InitEmpty for test_blockdev_rereadpt_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestRun for blockdev_rereadpt (0) */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_rereadpt (g, device); - if (r == -1) - return -1; - } - return 0; -} - -static int test_blockdev_flushbufs_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_BLOCKDEV_FLUSHBUFS_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_BLOCKDEV_FLUSHBUFS"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_blockdev_flushbufs_0 (void) -{ - if (test_blockdev_flushbufs_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_blockdev_flushbufs_0"); - return 0; - } - - /* InitNone|InitEmpty for test_blockdev_flushbufs_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestRun for blockdev_flushbufs (0) */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_flushbufs (g, device); - if (r == -1) - return -1; - } - return 0; -} - -static int test_blockdev_getsize64_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_BLOCKDEV_GETSIZE64_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_BLOCKDEV_GETSIZE64"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_blockdev_getsize64_0 (void) -{ - if (test_blockdev_getsize64_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_blockdev_getsize64_0"); - return 0; - } - - /* InitNone|InitEmpty for test_blockdev_getsize64_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputInt for blockdev_getsize64 (0) */ - { - char device[] = "/dev/sda"; - int64_t r; - suppress_error = 0; - r = guestfs_blockdev_getsize64 (g, device); - if (r == -1) - return -1; - if (r != 524288000) { - fprintf (stderr, "test_blockdev_getsize64_0: expected 524288000 but got %d\n", (int) r); - return -1; - } - } - return 0; -} - -static int test_blockdev_getsz_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_BLOCKDEV_GETSZ_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_BLOCKDEV_GETSZ"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_blockdev_getsz_0 (void) -{ - if (test_blockdev_getsz_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_blockdev_getsz_0"); - return 0; - } - - /* InitNone|InitEmpty for test_blockdev_getsz_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputInt for blockdev_getsz (0) */ - { - char device[] = "/dev/sda"; - int64_t r; - suppress_error = 0; - r = guestfs_blockdev_getsz (g, device); - if (r == -1) - return -1; - if (r != 1024000) { - fprintf (stderr, "test_blockdev_getsz_0: expected 1024000 but got %d\n", (int) r); - return -1; - } - } - return 0; -} - -static int test_blockdev_getbsz_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_BLOCKDEV_GETBSZ_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_BLOCKDEV_GETBSZ"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_blockdev_getbsz_0 (void) -{ - if (test_blockdev_getbsz_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_blockdev_getbsz_0"); - return 0; - } - - /* InitNone|InitEmpty for test_blockdev_getbsz_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputInt for blockdev_getbsz (0) */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_getbsz (g, device); - if (r == -1) - return -1; - if (r != 4096) { - fprintf (stderr, "test_blockdev_getbsz_0: expected 4096 but got %d\n", (int) r); - return -1; - } - } - return 0; -} - -static int test_blockdev_getss_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_BLOCKDEV_GETSS_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_BLOCKDEV_GETSS"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_blockdev_getss_0 (void) -{ - if (test_blockdev_getss_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_blockdev_getss_0"); - return 0; - } - - /* InitNone|InitEmpty for test_blockdev_getss_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputInt for blockdev_getss (0) */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_getss (g, device); - if (r == -1) - return -1; - if (r != 512) { - fprintf (stderr, "test_blockdev_getss_0: expected 512 but got %d\n", (int) r); - return -1; - } - } - return 0; -} - -static int test_blockdev_getro_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_BLOCKDEV_GETRO_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_BLOCKDEV_GETRO"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_blockdev_getro_0 (void) -{ - if (test_blockdev_getro_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_blockdev_getro_0"); - return 0; - } - - /* InitNone|InitEmpty for test_blockdev_getro_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputTrue for blockdev_getro (0) */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setro (g, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_getro (g, device); - if (r == -1) - return -1; - if (!r) { - fprintf (stderr, "test_blockdev_getro_0: expected true, got false\n"); - return -1; - } - } - return 0; -} - -static int test_blockdev_setrw_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_BLOCKDEV_SETRW_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_BLOCKDEV_SETRW"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_blockdev_setrw_0 (void) -{ - if (test_blockdev_setrw_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_blockdev_setrw_0"); - return 0; - } - - /* InitNone|InitEmpty for test_blockdev_setrw_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputFalse for blockdev_setrw (0) */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_getro (g, device); - if (r == -1) - return -1; - if (r) { - fprintf (stderr, "test_blockdev_setrw_0: expected false, got true\n"); - return -1; - } - } - return 0; -} - -static int test_blockdev_setro_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_BLOCKDEV_SETRO_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_BLOCKDEV_SETRO"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_blockdev_setro_0 (void) -{ - if (test_blockdev_setro_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_blockdev_setro_0"); - return 0; - } - - /* InitNone|InitEmpty for test_blockdev_setro_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputTrue for blockdev_setro (0) */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setro (g, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_getro (g, device); - if (r == -1) - return -1; - if (!r) { - fprintf (stderr, "test_blockdev_setro_0: expected true, got false\n"); - return -1; - } - } - return 0; -} - -static int test_statvfs_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_STATVFS_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_STATVFS"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_statvfs_0 (void) -{ - if (test_statvfs_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_statvfs_0"); - return 0; - } - - /* InitBasicFS for test_statvfs_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputStruct for statvfs (0) */ - { - char path[] = "/"; - struct guestfs_statvfs *r; - suppress_error = 0; - r = guestfs_statvfs (g, path); - if (r == NULL) - return -1; - if (r->bfree != 487702) { - fprintf (stderr, "test_statvfs_0: bfree was %d, expected 487702\n", - (int) r->bfree); - return -1; - } - if (r->blocks != 490020) { - fprintf (stderr, "test_statvfs_0: blocks was %d, expected 490020\n", - (int) r->blocks); - return -1; - } - if (r->bsize != 1024) { - fprintf (stderr, "test_statvfs_0: bsize was %d, expected 1024\n", - (int) r->bsize); - return -1; - } - free (r); - } - return 0; -} - -static int test_lstat_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_LSTAT_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_LSTAT"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_lstat_0 (void) -{ - if (test_lstat_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_lstat_0"); - return 0; - } - - /* InitBasicFS for test_lstat_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputStruct for lstat (0) */ - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_touch (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - struct guestfs_stat *r; - suppress_error = 0; - r = guestfs_lstat (g, path); - if (r == NULL) - return -1; - if (r->size != 0) { - fprintf (stderr, "test_lstat_0: size was %d, expected 0\n", - (int) r->size); - return -1; - } - free (r); - } - return 0; -} - -static int test_stat_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_STAT_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_STAT"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_stat_0 (void) -{ - if (test_stat_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_stat_0"); - return 0; - } - - /* InitBasicFS for test_stat_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputStruct for stat (0) */ - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_touch (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - struct guestfs_stat *r; - suppress_error = 0; - r = guestfs_stat (g, path); - if (r == NULL) - return -1; - if (r->size != 0) { - fprintf (stderr, "test_stat_0: size was %d, expected 0\n", - (int) r->size); - return -1; - } - free (r); - } - return 0; -} - -static int test_command_lines_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_LINES_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND_LINES"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_lines_0 (void) -{ - if (test_command_lines_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_lines_0"); - return 0; - } - - /* InitBasicFS for test_command_lines_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for command_lines (0) */ - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "1"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char **r; - int i; - suppress_error = 0; - r = guestfs_command_lines (g, arguments); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_command_lines_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "Result1"; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_command_lines_0: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (r[1] != NULL) { - fprintf (stderr, "test_command_lines_0: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_command_lines_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_LINES_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND_LINES"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_lines_1 (void) -{ - if (test_command_lines_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_lines_1"); - return 0; - } - - /* InitBasicFS for test_command_lines_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for command_lines (1) */ - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "2"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char **r; - int i; - suppress_error = 0; - r = guestfs_command_lines (g, arguments); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_command_lines_1: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "Result2"; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_command_lines_1: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (r[1] != NULL) { - fprintf (stderr, "test_command_lines_1: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_command_lines_2_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_LINES_2"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND_LINES"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_lines_2 (void) -{ - if (test_command_lines_2_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_lines_2"); - return 0; - } - - /* InitBasicFS for test_command_lines_2: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for command_lines (2) */ - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "3"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char **r; - int i; - suppress_error = 0; - r = guestfs_command_lines (g, arguments); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_command_lines_2: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = ""; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_command_lines_2: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (!r[1]) { - fprintf (stderr, "test_command_lines_2: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "Result3"; - if (strcmp (r[1], expected) != 0) { - fprintf (stderr, "test_command_lines_2: expected \"%s\" but got \"%s\"\n", expected, r[1]); - return -1; - } - } - if (r[2] != NULL) { - fprintf (stderr, "test_command_lines_2: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_command_lines_3_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_LINES_3"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND_LINES"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_lines_3 (void) -{ - if (test_command_lines_3_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_lines_3"); - return 0; - } - - /* InitBasicFS for test_command_lines_3: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for command_lines (3) */ - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "4"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char **r; - int i; - suppress_error = 0; - r = guestfs_command_lines (g, arguments); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_command_lines_3: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = ""; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_command_lines_3: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (!r[1]) { - fprintf (stderr, "test_command_lines_3: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "Result4"; - if (strcmp (r[1], expected) != 0) { - fprintf (stderr, "test_command_lines_3: expected \"%s\" but got \"%s\"\n", expected, r[1]); - return -1; - } - } - if (r[2] != NULL) { - fprintf (stderr, "test_command_lines_3: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_command_lines_4_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_LINES_4"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND_LINES"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_lines_4 (void) -{ - if (test_command_lines_4_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_lines_4"); - return 0; - } - - /* InitBasicFS for test_command_lines_4: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for command_lines (4) */ - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "5"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char **r; - int i; - suppress_error = 0; - r = guestfs_command_lines (g, arguments); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_command_lines_4: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = ""; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_command_lines_4: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (!r[1]) { - fprintf (stderr, "test_command_lines_4: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "Result5"; - if (strcmp (r[1], expected) != 0) { - fprintf (stderr, "test_command_lines_4: expected \"%s\" but got \"%s\"\n", expected, r[1]); - return -1; - } - } - if (!r[2]) { - fprintf (stderr, "test_command_lines_4: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = ""; - if (strcmp (r[2], expected) != 0) { - fprintf (stderr, "test_command_lines_4: expected \"%s\" but got \"%s\"\n", expected, r[2]); - return -1; - } - } - if (r[3] != NULL) { - fprintf (stderr, "test_command_lines_4: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_command_lines_5_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_LINES_5"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND_LINES"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_lines_5 (void) -{ - if (test_command_lines_5_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_lines_5"); - return 0; - } - - /* InitBasicFS for test_command_lines_5: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for command_lines (5) */ - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "6"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char **r; - int i; - suppress_error = 0; - r = guestfs_command_lines (g, arguments); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_command_lines_5: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = ""; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_command_lines_5: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (!r[1]) { - fprintf (stderr, "test_command_lines_5: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = ""; - if (strcmp (r[1], expected) != 0) { - fprintf (stderr, "test_command_lines_5: expected \"%s\" but got \"%s\"\n", expected, r[1]); - return -1; - } - } - if (!r[2]) { - fprintf (stderr, "test_command_lines_5: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "Result6"; - if (strcmp (r[2], expected) != 0) { - fprintf (stderr, "test_command_lines_5: expected \"%s\" but got \"%s\"\n", expected, r[2]); - return -1; - } - } - if (!r[3]) { - fprintf (stderr, "test_command_lines_5: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = ""; - if (strcmp (r[3], expected) != 0) { - fprintf (stderr, "test_command_lines_5: expected \"%s\" but got \"%s\"\n", expected, r[3]); - return -1; - } - } - if (r[4] != NULL) { - fprintf (stderr, "test_command_lines_5: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_command_lines_6_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_LINES_6"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND_LINES"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_lines_6 (void) -{ - if (test_command_lines_6_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_lines_6"); - return 0; - } - - /* InitBasicFS for test_command_lines_6: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for command_lines (6) */ - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "7"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char **r; - int i; - suppress_error = 0; - r = guestfs_command_lines (g, arguments); - if (r == NULL) - return -1; - if (r[0] != NULL) { - fprintf (stderr, "test_command_lines_6: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_command_lines_7_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_LINES_7"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND_LINES"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_lines_7 (void) -{ - if (test_command_lines_7_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_lines_7"); - return 0; - } - - /* InitBasicFS for test_command_lines_7: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for command_lines (7) */ - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "8"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char **r; - int i; - suppress_error = 0; - r = guestfs_command_lines (g, arguments); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_command_lines_7: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = ""; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_command_lines_7: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (r[1] != NULL) { - fprintf (stderr, "test_command_lines_7: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_command_lines_8_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_LINES_8"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND_LINES"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_lines_8 (void) -{ - if (test_command_lines_8_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_lines_8"); - return 0; - } - - /* InitBasicFS for test_command_lines_8: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for command_lines (8) */ - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "9"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char **r; - int i; - suppress_error = 0; - r = guestfs_command_lines (g, arguments); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_command_lines_8: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = ""; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_command_lines_8: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (!r[1]) { - fprintf (stderr, "test_command_lines_8: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = ""; - if (strcmp (r[1], expected) != 0) { - fprintf (stderr, "test_command_lines_8: expected \"%s\" but got \"%s\"\n", expected, r[1]); - return -1; - } - } - if (r[2] != NULL) { - fprintf (stderr, "test_command_lines_8: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_command_lines_9_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_LINES_9"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND_LINES"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_lines_9 (void) -{ - if (test_command_lines_9_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_lines_9"); - return 0; - } - - /* InitBasicFS for test_command_lines_9: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for command_lines (9) */ - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "10"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char **r; - int i; - suppress_error = 0; - r = guestfs_command_lines (g, arguments); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_command_lines_9: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "Result10-1"; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_command_lines_9: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (!r[1]) { - fprintf (stderr, "test_command_lines_9: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "Result10-2"; - if (strcmp (r[1], expected) != 0) { - fprintf (stderr, "test_command_lines_9: expected \"%s\" but got \"%s\"\n", expected, r[1]); - return -1; - } - } - if (r[2] != NULL) { - fprintf (stderr, "test_command_lines_9: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_command_lines_10_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_LINES_10"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND_LINES"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_lines_10 (void) -{ - if (test_command_lines_10_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_lines_10"); - return 0; - } - - /* InitBasicFS for test_command_lines_10: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for command_lines (10) */ - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "11"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char **r; - int i; - suppress_error = 0; - r = guestfs_command_lines (g, arguments); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_command_lines_10: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "Result11-1"; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_command_lines_10: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (!r[1]) { - fprintf (stderr, "test_command_lines_10: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "Result11-2"; - if (strcmp (r[1], expected) != 0) { - fprintf (stderr, "test_command_lines_10: expected \"%s\" but got \"%s\"\n", expected, r[1]); - return -1; - } - } - if (r[2] != NULL) { - fprintf (stderr, "test_command_lines_10: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_command_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_0 (void) -{ - if (test_command_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_0"); - return 0; - } - - /* InitBasicFS for test_command_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for command (0) */ - char expected[] = "Result1"; - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "1"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char *r; - suppress_error = 0; - r = guestfs_command (g, arguments); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_command_0: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_command_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_1 (void) -{ - if (test_command_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_1"); - return 0; - } - - /* InitBasicFS for test_command_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for command (1) */ - char expected[] = "Result2\n"; - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "2"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char *r; - suppress_error = 0; - r = guestfs_command (g, arguments); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_command_1: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_command_2_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_2"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_2 (void) -{ - if (test_command_2_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_2"); - return 0; - } - - /* InitBasicFS for test_command_2: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for command (2) */ - char expected[] = "\nResult3"; - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "3"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char *r; - suppress_error = 0; - r = guestfs_command (g, arguments); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_command_2: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_command_3_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_3"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_3 (void) -{ - if (test_command_3_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_3"); - return 0; - } - - /* InitBasicFS for test_command_3: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for command (3) */ - char expected[] = "\nResult4\n"; - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "4"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char *r; - suppress_error = 0; - r = guestfs_command (g, arguments); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_command_3: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_command_4_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_4"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_4 (void) -{ - if (test_command_4_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_4"); - return 0; - } - - /* InitBasicFS for test_command_4: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for command (4) */ - char expected[] = "\nResult5\n\n"; - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "5"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char *r; - suppress_error = 0; - r = guestfs_command (g, arguments); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_command_4: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_command_5_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_5"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_5 (void) -{ - if (test_command_5_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_5"); - return 0; - } - - /* InitBasicFS for test_command_5: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for command (5) */ - char expected[] = "\n\nResult6\n\n"; - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "6"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char *r; - suppress_error = 0; - r = guestfs_command (g, arguments); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_command_5: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_command_6_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_6"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_6 (void) -{ - if (test_command_6_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_6"); - return 0; - } - - /* InitBasicFS for test_command_6: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for command (6) */ - char expected[] = ""; - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "7"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char *r; - suppress_error = 0; - r = guestfs_command (g, arguments); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_command_6: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_command_7_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_7"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_7 (void) -{ - if (test_command_7_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_7"); - return 0; - } - - /* InitBasicFS for test_command_7: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for command (7) */ - char expected[] = "\n"; - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "8"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char *r; - suppress_error = 0; - r = guestfs_command (g, arguments); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_command_7: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_command_8_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_8"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_8 (void) -{ - if (test_command_8_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_8"); - return 0; - } - - /* InitBasicFS for test_command_8: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for command (8) */ - char expected[] = "\n\n"; - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "9"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char *r; - suppress_error = 0; - r = guestfs_command (g, arguments); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_command_8: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_command_9_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_9"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_9 (void) -{ - if (test_command_9_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_9"); - return 0; - } - - /* InitBasicFS for test_command_9: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for command (9) */ - char expected[] = "Result10-1\nResult10-2\n"; - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "10"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char *r; - suppress_error = 0; - r = guestfs_command (g, arguments); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_command_9: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_command_10_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_10"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_10 (void) -{ - if (test_command_10_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_10"); - return 0; - } - - /* InitBasicFS for test_command_10: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for command (10) */ - char expected[] = "Result11-1\nResult11-2"; - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char arguments_1[] = "11"; - char *arguments[] = { - arguments_0, - arguments_1, - NULL - }; - char *r; - suppress_error = 0; - r = guestfs_command (g, arguments); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_command_10: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_command_11_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_COMMAND_11"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_COMMAND"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_command_11 (void) -{ - if (test_command_11_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_command_11"); - return 0; - } - - /* InitBasicFS for test_command_11: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestLastFail for command (11) */ - { - char remotefilename[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_upload (g, "test-command", remotefilename); - if (r == -1) - return -1; - } - { - char path[] = "/test-command"; - int r; - suppress_error = 0; - r = guestfs_chmod (g, 493, path); - if (r == -1) - return -1; - } - { - char arguments_0[] = "/test-command"; - char *arguments[] = { - arguments_0, - NULL - }; - char *r; - suppress_error = 1; - r = guestfs_command (g, arguments); - if (r != NULL) - return -1; - free (r); - } - return 0; -} - -static int test_file_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_FILE_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_FILE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_file_0 (void) -{ - if (test_file_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_file_0"); - return 0; - } - - /* InitBasicFS for test_file_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for file (0) */ - char expected[] = "empty"; - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_touch (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_file (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_file_0: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_file_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_FILE_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_FILE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_file_1 (void) -{ - if (test_file_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_file_1"); - return 0; - } - - /* InitBasicFS for test_file_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for file (1) */ - char expected[] = "ASCII text"; - { - char path[] = "/new"; - char content[] = "some content\n"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_file (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_file_1: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_file_2_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_FILE_2"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_FILE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_file_2 (void) -{ - if (test_file_2_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_file_2"); - return 0; - } - - /* InitBasicFS for test_file_2: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestLastFail for file (2) */ - { - char path[] = "/nofile"; - char *r; - suppress_error = 1; - r = guestfs_file (g, path); - if (r != NULL) - return -1; - free (r); - } - return 0; -} - -static int test_umount_all_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_UMOUNT_ALL_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_UMOUNT_ALL"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_umount_all_0 (void) -{ - if (test_umount_all_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_umount_all_0"); - return 0; - } - - /* InitBasicFS for test_umount_all_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for umount_all (0) */ - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - char **r; - int i; - suppress_error = 0; - r = guestfs_mounts (g); - if (r == NULL) - return -1; - if (r[0] != NULL) { - fprintf (stderr, "test_umount_all_0: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_umount_all_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_UMOUNT_ALL_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_UMOUNT_ALL"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_umount_all_1 (void) -{ - if (test_umount_all_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_umount_all_1"); - return 0; - } - - /* InitNone|InitEmpty for test_umount_all_1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputList for umount_all (1) */ - { - char device[] = "/dev/sda"; - char lines_0[] = ",10"; - char lines_1[] = ",20"; - char lines_2[] = ","; - char *lines[] = { - lines_0, - lines_1, - lines_2, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda2"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda3"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - { - char path[] = "/mp1"; - int r; - suppress_error = 0; - r = guestfs_mkdir (g, path); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda2"; - char mountpoint[] = "/mp1"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - { - char path[] = "/mp1/mp2"; - int r; - suppress_error = 0; - r = guestfs_mkdir (g, path); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda3"; - char mountpoint[] = "/mp1/mp2"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - { - char path[] = "/mp1/mp2/mp3"; - int r; - suppress_error = 0; - r = guestfs_mkdir (g, path); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - char **r; - int i; - suppress_error = 0; - r = guestfs_mounts (g); - if (r == NULL) - return -1; - if (r[0] != NULL) { - fprintf (stderr, "test_umount_all_1: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_mounts_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_MOUNTS_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_MOUNTS"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_mounts_0 (void) -{ - if (test_mounts_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_mounts_0"); - return 0; - } - - /* InitBasicFS for test_mounts_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputListOfDevices for mounts (0) */ - { - char **r; - int i; - suppress_error = 0; - r = guestfs_mounts (g); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_mounts_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/sda1"; - r[0][5] = 's'; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_mounts_0: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (r[1] != NULL) { - fprintf (stderr, "test_mounts_0: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_umount_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_UMOUNT_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_UMOUNT"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_umount_0 (void) -{ - if (test_umount_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_umount_0"); - return 0; - } - - /* InitNone|InitEmpty for test_umount_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputListOfDevices for umount (0) */ - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - { - char **r; - int i; - suppress_error = 0; - r = guestfs_mounts (g); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_umount_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/sda1"; - r[0][5] = 's'; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_umount_0: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (r[1] != NULL) { - fprintf (stderr, "test_umount_0: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_umount_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_UMOUNT_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_UMOUNT"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_umount_1 (void) -{ - if (test_umount_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_umount_1"); - return 0; - } - - /* InitNone|InitEmpty for test_umount_1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputList for umount (1) */ - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - { - char pathordevice[] = "/"; - int r; - suppress_error = 0; - r = guestfs_umount (g, pathordevice); - if (r == -1) - return -1; - } - { - char **r; - int i; - suppress_error = 0; - r = guestfs_mounts (g); - if (r == NULL) - return -1; - if (r[0] != NULL) { - fprintf (stderr, "test_umount_1: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_write_file_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_WRITE_FILE_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_WRITE_FILE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_write_file_0 (void) -{ - if (test_write_file_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_write_file_0"); - return 0; - } - - /* InitBasicFS for test_write_file_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for write_file (0) */ - char expected[] = "new file contents"; - { - char path[] = "/new"; - char content[] = "new file contents"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_cat (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_write_file_0: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_write_file_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_WRITE_FILE_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_WRITE_FILE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_write_file_1 (void) -{ - if (test_write_file_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_write_file_1"); - return 0; - } - - /* InitBasicFS for test_write_file_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for write_file (1) */ - char expected[] = "\nnew file contents\n"; - { - char path[] = "/new"; - char content[] = "\nnew file contents\n"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_cat (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_write_file_1: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_write_file_2_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_WRITE_FILE_2"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_WRITE_FILE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_write_file_2 (void) -{ - if (test_write_file_2_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_write_file_2"); - return 0; - } - - /* InitBasicFS for test_write_file_2: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for write_file (2) */ - char expected[] = "\n\n"; - { - char path[] = "/new"; - char content[] = "\n\n"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_cat (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_write_file_2: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_write_file_3_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_WRITE_FILE_3"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_WRITE_FILE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_write_file_3 (void) -{ - if (test_write_file_3_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_write_file_3"); - return 0; - } - - /* InitBasicFS for test_write_file_3: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for write_file (3) */ - char expected[] = ""; - { - char path[] = "/new"; - char content[] = ""; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_cat (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_write_file_3: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_write_file_4_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_WRITE_FILE_4"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_WRITE_FILE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_write_file_4 (void) -{ - if (test_write_file_4_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_write_file_4"); - return 0; - } - - /* InitBasicFS for test_write_file_4: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for write_file (4) */ - char expected[] = "\n\n\n"; - { - char path[] = "/new"; - char content[] = "\n\n\n"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_cat (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_write_file_4: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_write_file_5_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_WRITE_FILE_5"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_WRITE_FILE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_write_file_5 (void) -{ - if (test_write_file_5_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_write_file_5"); - return 0; - } - - /* InitBasicFS for test_write_file_5: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for write_file (5) */ - char expected[] = "\n"; - { - char path[] = "/new"; - char content[] = "\n"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_cat (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_write_file_5: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_mkfs_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_MKFS_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_MKFS"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_mkfs_0 (void) -{ - if (test_mkfs_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_mkfs_0"); - return 0; - } - - /* InitNone|InitEmpty for test_mkfs_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutput for mkfs (0) */ - char expected[] = "new file contents"; - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char content[] = "new file contents"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_cat (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_mkfs_0: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_lvcreate_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_LVCREATE_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_LVCREATE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_lvcreate_0 (void) -{ - if (test_lvcreate_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_lvcreate_0"); - return 0; - } - - /* InitNone|InitEmpty for test_lvcreate_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputList for lvcreate (0) */ - { - char device[] = "/dev/sda"; - char lines_0[] = ",10"; - char lines_1[] = ",20"; - char lines_2[] = ","; - char *lines[] = { - lines_0, - lines_1, - lines_2, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda2"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda3"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char volgroup[] = "VG1"; - char physvols_0[] = "/dev/sda1"; - char physvols_1[] = "/dev/sda2"; - char *physvols[] = { - physvols_0, - physvols_1, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, volgroup, physvols); - if (r == -1) - return -1; - } - { - char volgroup[] = "VG2"; - char physvols_0[] = "/dev/sda3"; - char *physvols[] = { - physvols_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, volgroup, physvols); - if (r == -1) - return -1; - } - { - char logvol[] = "LV1"; - char volgroup[] = "VG1"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char logvol[] = "LV2"; - char volgroup[] = "VG1"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char logvol[] = "LV3"; - char volgroup[] = "VG2"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char logvol[] = "LV4"; - char volgroup[] = "VG2"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char logvol[] = "LV5"; - char volgroup[] = "VG2"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char **r; - int i; - suppress_error = 0; - r = guestfs_lvs (g); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_lvcreate_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/VG1/LV1"; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_lvcreate_0: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (!r[1]) { - fprintf (stderr, "test_lvcreate_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/VG1/LV2"; - if (strcmp (r[1], expected) != 0) { - fprintf (stderr, "test_lvcreate_0: expected \"%s\" but got \"%s\"\n", expected, r[1]); - return -1; - } - } - if (!r[2]) { - fprintf (stderr, "test_lvcreate_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/VG2/LV3"; - if (strcmp (r[2], expected) != 0) { - fprintf (stderr, "test_lvcreate_0: expected \"%s\" but got \"%s\"\n", expected, r[2]); - return -1; - } - } - if (!r[3]) { - fprintf (stderr, "test_lvcreate_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/VG2/LV4"; - if (strcmp (r[3], expected) != 0) { - fprintf (stderr, "test_lvcreate_0: expected \"%s\" but got \"%s\"\n", expected, r[3]); - return -1; - } - } - if (!r[4]) { - fprintf (stderr, "test_lvcreate_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/VG2/LV5"; - if (strcmp (r[4], expected) != 0) { - fprintf (stderr, "test_lvcreate_0: expected \"%s\" but got \"%s\"\n", expected, r[4]); - return -1; - } - } - if (r[5] != NULL) { - fprintf (stderr, "test_lvcreate_0: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_vgcreate_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_VGCREATE_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_VGCREATE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_vgcreate_0 (void) -{ - if (test_vgcreate_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_vgcreate_0"); - return 0; - } - - /* InitNone|InitEmpty for test_vgcreate_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputList for vgcreate (0) */ - { - char device[] = "/dev/sda"; - char lines_0[] = ",10"; - char lines_1[] = ",20"; - char lines_2[] = ","; - char *lines[] = { - lines_0, - lines_1, - lines_2, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda2"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda3"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char volgroup[] = "VG1"; - char physvols_0[] = "/dev/sda1"; - char physvols_1[] = "/dev/sda2"; - char *physvols[] = { - physvols_0, - physvols_1, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, volgroup, physvols); - if (r == -1) - return -1; - } - { - char volgroup[] = "VG2"; - char physvols_0[] = "/dev/sda3"; - char *physvols[] = { - physvols_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, volgroup, physvols); - if (r == -1) - return -1; - } - { - char **r; - int i; - suppress_error = 0; - r = guestfs_vgs (g); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_vgcreate_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "VG1"; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_vgcreate_0: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (!r[1]) { - fprintf (stderr, "test_vgcreate_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "VG2"; - if (strcmp (r[1], expected) != 0) { - fprintf (stderr, "test_vgcreate_0: expected \"%s\" but got \"%s\"\n", expected, r[1]); - return -1; - } - } - if (r[2] != NULL) { - fprintf (stderr, "test_vgcreate_0: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_pvcreate_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_PVCREATE_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_PVCREATE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_pvcreate_0 (void) -{ - if (test_pvcreate_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_pvcreate_0"); - return 0; - } - - /* InitNone|InitEmpty for test_pvcreate_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputListOfDevices for pvcreate (0) */ - { - char device[] = "/dev/sda"; - char lines_0[] = ",10"; - char lines_1[] = ",20"; - char lines_2[] = ","; - char *lines[] = { - lines_0, - lines_1, - lines_2, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda2"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda3"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char **r; - int i; - suppress_error = 0; - r = guestfs_pvs (g); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_pvcreate_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/sda1"; - r[0][5] = 's'; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_pvcreate_0: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (!r[1]) { - fprintf (stderr, "test_pvcreate_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/sda2"; - r[1][5] = 's'; - if (strcmp (r[1], expected) != 0) { - fprintf (stderr, "test_pvcreate_0: expected \"%s\" but got \"%s\"\n", expected, r[1]); - return -1; - } - } - if (!r[2]) { - fprintf (stderr, "test_pvcreate_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/sda3"; - r[2][5] = 's'; - if (strcmp (r[2], expected) != 0) { - fprintf (stderr, "test_pvcreate_0: expected \"%s\" but got \"%s\"\n", expected, r[2]); - return -1; - } - } - if (r[3] != NULL) { - fprintf (stderr, "test_pvcreate_0: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_is_dir_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_IS_DIR_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_IS_DIR"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_is_dir_0 (void) -{ - if (test_is_dir_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_is_dir_0"); - return 0; - } - - /* InitBasicFS for test_is_dir_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputFalse for is_dir (0) */ - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_touch (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_is_dir (g, path); - if (r == -1) - return -1; - if (r) { - fprintf (stderr, "test_is_dir_0: expected false, got true\n"); - return -1; - } - } - return 0; -} - -static int test_is_dir_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_IS_DIR_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_IS_DIR"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_is_dir_1 (void) -{ - if (test_is_dir_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_is_dir_1"); - return 0; - } - - /* InitBasicFS for test_is_dir_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputTrue for is_dir (1) */ - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_mkdir (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_is_dir (g, path); - if (r == -1) - return -1; - if (!r) { - fprintf (stderr, "test_is_dir_1: expected true, got false\n"); - return -1; - } - } - return 0; -} - -static int test_is_file_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_IS_FILE_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_IS_FILE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_is_file_0 (void) -{ - if (test_is_file_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_is_file_0"); - return 0; - } - - /* InitBasicFS for test_is_file_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputTrue for is_file (0) */ - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_touch (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_is_file (g, path); - if (r == -1) - return -1; - if (!r) { - fprintf (stderr, "test_is_file_0: expected true, got false\n"); - return -1; - } - } - return 0; -} - -static int test_is_file_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_IS_FILE_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_IS_FILE"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_is_file_1 (void) -{ - if (test_is_file_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_is_file_1"); - return 0; - } - - /* InitBasicFS for test_is_file_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputFalse for is_file (1) */ - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_mkdir (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_is_file (g, path); - if (r == -1) - return -1; - if (r) { - fprintf (stderr, "test_is_file_1: expected false, got true\n"); - return -1; - } - } - return 0; -} - -static int test_exists_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_EXISTS_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_EXISTS"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_exists_0 (void) -{ - if (test_exists_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_exists_0"); - return 0; - } - - /* InitBasicFS for test_exists_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputTrue for exists (0) */ - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_touch (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_exists (g, path); - if (r == -1) - return -1; - if (!r) { - fprintf (stderr, "test_exists_0: expected true, got false\n"); - return -1; - } - } - return 0; -} - -static int test_exists_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_EXISTS_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_EXISTS"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_exists_1 (void) -{ - if (test_exists_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_exists_1"); - return 0; - } - - /* InitBasicFS for test_exists_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputTrue for exists (1) */ - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_mkdir (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_exists (g, path); - if (r == -1) - return -1; - if (!r) { - fprintf (stderr, "test_exists_1: expected true, got false\n"); - return -1; - } - } - return 0; -} - -static int test_mkdir_p_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_MKDIR_P_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_MKDIR_P"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_mkdir_p_0 (void) -{ - if (test_mkdir_p_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_mkdir_p_0"); - return 0; - } - - /* InitBasicFS for test_mkdir_p_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputTrue for mkdir_p (0) */ - { - char path[] = "/new/foo/bar"; - int r; - suppress_error = 0; - r = guestfs_mkdir_p (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new/foo/bar"; - int r; - suppress_error = 0; - r = guestfs_is_dir (g, path); - if (r == -1) - return -1; - if (!r) { - fprintf (stderr, "test_mkdir_p_0: expected true, got false\n"); - return -1; - } - } - return 0; -} - -static int test_mkdir_p_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_MKDIR_P_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_MKDIR_P"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_mkdir_p_1 (void) -{ - if (test_mkdir_p_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_mkdir_p_1"); - return 0; - } - - /* InitBasicFS for test_mkdir_p_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputTrue for mkdir_p (1) */ - { - char path[] = "/new/foo/bar"; - int r; - suppress_error = 0; - r = guestfs_mkdir_p (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new/foo"; - int r; - suppress_error = 0; - r = guestfs_is_dir (g, path); - if (r == -1) - return -1; - if (!r) { - fprintf (stderr, "test_mkdir_p_1: expected true, got false\n"); - return -1; - } - } - return 0; -} - -static int test_mkdir_p_2_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_MKDIR_P_2"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_MKDIR_P"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_mkdir_p_2 (void) -{ - if (test_mkdir_p_2_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_mkdir_p_2"); - return 0; - } - - /* InitBasicFS for test_mkdir_p_2: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputTrue for mkdir_p (2) */ - { - char path[] = "/new/foo/bar"; - int r; - suppress_error = 0; - r = guestfs_mkdir_p (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_is_dir (g, path); - if (r == -1) - return -1; - if (!r) { - fprintf (stderr, "test_mkdir_p_2: expected true, got false\n"); - return -1; - } - } - return 0; -} - -static int test_mkdir_p_3_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_MKDIR_P_3"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_MKDIR_P"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_mkdir_p_3 (void) -{ - if (test_mkdir_p_3_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_mkdir_p_3"); - return 0; - } - - /* InitBasicFS for test_mkdir_p_3: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestRun for mkdir_p (3) */ - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_mkdir (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_mkdir_p (g, path); - if (r == -1) - return -1; - } - return 0; -} - -static int test_mkdir_p_4_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_MKDIR_P_4"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_MKDIR_P"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_mkdir_p_4 (void) -{ - if (test_mkdir_p_4_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_mkdir_p_4"); - return 0; - } - - /* InitBasicFS for test_mkdir_p_4: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestLastFail for mkdir_p (4) */ - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_touch (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - int r; - suppress_error = 1; - r = guestfs_mkdir_p (g, path); - if (r != -1) - return -1; - } - return 0; -} - -static int test_mkdir_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_MKDIR_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_MKDIR"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_mkdir_0 (void) -{ - if (test_mkdir_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_mkdir_0"); - return 0; - } - - /* InitBasicFS for test_mkdir_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputTrue for mkdir (0) */ - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_mkdir (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_is_dir (g, path); - if (r == -1) - return -1; - if (!r) { - fprintf (stderr, "test_mkdir_0: expected true, got false\n"); - return -1; - } - } - return 0; -} - -static int test_mkdir_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_MKDIR_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_MKDIR"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_mkdir_1 (void) -{ - if (test_mkdir_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_mkdir_1"); - return 0; - } - - /* InitBasicFS for test_mkdir_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestLastFail for mkdir (1) */ - { - char path[] = "/new/foo/bar"; - int r; - suppress_error = 1; - r = guestfs_mkdir (g, path); - if (r != -1) - return -1; - } - return 0; -} - -static int test_rm_rf_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_RM_RF_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_RM_RF"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_rm_rf_0 (void) -{ - if (test_rm_rf_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_rm_rf_0"); - return 0; - } - - /* InitBasicFS for test_rm_rf_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputFalse for rm_rf (0) */ - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_mkdir (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new/foo"; - int r; - suppress_error = 0; - r = guestfs_mkdir (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new/foo/bar"; - int r; - suppress_error = 0; - r = guestfs_touch (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_rm_rf (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_exists (g, path); - if (r == -1) - return -1; - if (r) { - fprintf (stderr, "test_rm_rf_0: expected false, got true\n"); - return -1; - } - } - return 0; -} - -static int test_rmdir_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_RMDIR_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_RMDIR"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_rmdir_0 (void) -{ - if (test_rmdir_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_rmdir_0"); - return 0; - } - - /* InitBasicFS for test_rmdir_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestRun for rmdir (0) */ - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_mkdir (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_rmdir (g, path); - if (r == -1) - return -1; - } - return 0; -} - -static int test_rmdir_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_RMDIR_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_RMDIR"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_rmdir_1 (void) -{ - if (test_rmdir_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_rmdir_1"); - return 0; - } - - /* InitBasicFS for test_rmdir_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestLastFail for rmdir (1) */ - { - char path[] = "/new"; - int r; - suppress_error = 1; - r = guestfs_rmdir (g, path); - if (r != -1) - return -1; - } - return 0; -} - -static int test_rmdir_2_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_RMDIR_2"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_RMDIR"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_rmdir_2 (void) -{ - if (test_rmdir_2_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_rmdir_2"); - return 0; - } - - /* InitBasicFS for test_rmdir_2: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestLastFail for rmdir (2) */ - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_touch (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - int r; - suppress_error = 1; - r = guestfs_rmdir (g, path); - if (r != -1) - return -1; - } - return 0; -} - -static int test_rm_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_RM_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_RM"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_rm_0 (void) -{ - if (test_rm_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_rm_0"); - return 0; - } - - /* InitBasicFS for test_rm_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestRun for rm (0) */ - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_touch (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_rm (g, path); - if (r == -1) - return -1; - } - return 0; -} - -static int test_rm_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_RM_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_RM"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_rm_1 (void) -{ - if (test_rm_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_rm_1"); - return 0; - } - - /* InitBasicFS for test_rm_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestLastFail for rm (1) */ - { - char path[] = "/new"; - int r; - suppress_error = 1; - r = guestfs_rm (g, path); - if (r != -1) - return -1; - } - return 0; -} - -static int test_rm_2_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_RM_2"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_RM"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_rm_2 (void) -{ - if (test_rm_2_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_rm_2"); - return 0; - } - - /* InitBasicFS for test_rm_2: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestLastFail for rm (2) */ - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_mkdir (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - int r; - suppress_error = 1; - r = guestfs_rm (g, path); - if (r != -1) - return -1; - } - return 0; -} - -static int test_read_lines_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_READ_LINES_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_READ_LINES"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_read_lines_0 (void) -{ - if (test_read_lines_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_read_lines_0"); - return 0; - } - - /* InitBasicFS for test_read_lines_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for read_lines (0) */ - { - char path[] = "/new"; - char content[] = "line1\r\nline2\nline3"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char **r; - int i; - suppress_error = 0; - r = guestfs_read_lines (g, path); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_read_lines_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "line1"; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_read_lines_0: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (!r[1]) { - fprintf (stderr, "test_read_lines_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "line2"; - if (strcmp (r[1], expected) != 0) { - fprintf (stderr, "test_read_lines_0: expected \"%s\" but got \"%s\"\n", expected, r[1]); - return -1; - } - } - if (!r[2]) { - fprintf (stderr, "test_read_lines_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "line3"; - if (strcmp (r[2], expected) != 0) { - fprintf (stderr, "test_read_lines_0: expected \"%s\" but got \"%s\"\n", expected, r[2]); - return -1; - } - } - if (r[3] != NULL) { - fprintf (stderr, "test_read_lines_0: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_read_lines_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_READ_LINES_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_READ_LINES"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_read_lines_1 (void) -{ - if (test_read_lines_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_read_lines_1"); - return 0; - } - - /* InitBasicFS for test_read_lines_1: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for read_lines (1) */ - { - char path[] = "/new"; - char content[] = ""; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char **r; - int i; - suppress_error = 0; - r = guestfs_read_lines (g, path); - if (r == NULL) - return -1; - if (r[0] != NULL) { - fprintf (stderr, "test_read_lines_1: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_lvs_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_LVS_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_LVS"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_lvs_0 (void) -{ - if (test_lvs_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_lvs_0"); - return 0; - } - - /* InitBasicFSonLVM for test_lvs_0: create ext2 on /dev/VG/LV */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char volgroup[] = "VG"; - char physvols_0[] = "/dev/sda1"; - char *physvols[] = { - physvols_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, volgroup, physvols); - if (r == -1) - return -1; - } - { - char logvol[] = "LV"; - char volgroup[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 8); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/VG/LV"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/VG/LV"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for lvs (0) */ - { - char **r; - int i; - suppress_error = 0; - r = guestfs_lvs (g); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_lvs_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/VG/LV"; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_lvs_0: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (r[1] != NULL) { - fprintf (stderr, "test_lvs_0: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_lvs_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_LVS_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_LVS"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_lvs_1 (void) -{ - if (test_lvs_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_lvs_1"); - return 0; - } - - /* InitNone|InitEmpty for test_lvs_1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputList for lvs (1) */ - { - char device[] = "/dev/sda"; - char lines_0[] = ",10"; - char lines_1[] = ",20"; - char lines_2[] = ","; - char *lines[] = { - lines_0, - lines_1, - lines_2, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda2"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda3"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char volgroup[] = "VG1"; - char physvols_0[] = "/dev/sda1"; - char physvols_1[] = "/dev/sda2"; - char *physvols[] = { - physvols_0, - physvols_1, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, volgroup, physvols); - if (r == -1) - return -1; - } - { - char volgroup[] = "VG2"; - char physvols_0[] = "/dev/sda3"; - char *physvols[] = { - physvols_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, volgroup, physvols); - if (r == -1) - return -1; - } - { - char logvol[] = "LV1"; - char volgroup[] = "VG1"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char logvol[] = "LV2"; - char volgroup[] = "VG1"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char logvol[] = "LV3"; - char volgroup[] = "VG2"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 50); - if (r == -1) - return -1; - } - { - char **r; - int i; - suppress_error = 0; - r = guestfs_lvs (g); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_lvs_1: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/VG1/LV1"; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_lvs_1: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (!r[1]) { - fprintf (stderr, "test_lvs_1: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/VG1/LV2"; - if (strcmp (r[1], expected) != 0) { - fprintf (stderr, "test_lvs_1: expected \"%s\" but got \"%s\"\n", expected, r[1]); - return -1; - } - } - if (!r[2]) { - fprintf (stderr, "test_lvs_1: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/VG2/LV3"; - if (strcmp (r[2], expected) != 0) { - fprintf (stderr, "test_lvs_1: expected \"%s\" but got \"%s\"\n", expected, r[2]); - return -1; - } - } - if (r[3] != NULL) { - fprintf (stderr, "test_lvs_1: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_vgs_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_VGS_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_VGS"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_vgs_0 (void) -{ - if (test_vgs_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_vgs_0"); - return 0; - } - - /* InitBasicFSonLVM for test_vgs_0: create ext2 on /dev/VG/LV */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char volgroup[] = "VG"; - char physvols_0[] = "/dev/sda1"; - char *physvols[] = { - physvols_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, volgroup, physvols); - if (r == -1) - return -1; - } - { - char logvol[] = "LV"; - char volgroup[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 8); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/VG/LV"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/VG/LV"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for vgs (0) */ - { - char **r; - int i; - suppress_error = 0; - r = guestfs_vgs (g); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_vgs_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "VG"; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_vgs_0: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (r[1] != NULL) { - fprintf (stderr, "test_vgs_0: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_vgs_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_VGS_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_VGS"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_vgs_1 (void) -{ - if (test_vgs_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_vgs_1"); - return 0; - } - - /* InitNone|InitEmpty for test_vgs_1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputList for vgs (1) */ - { - char device[] = "/dev/sda"; - char lines_0[] = ",10"; - char lines_1[] = ",20"; - char lines_2[] = ","; - char *lines[] = { - lines_0, - lines_1, - lines_2, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda2"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda3"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char volgroup[] = "VG1"; - char physvols_0[] = "/dev/sda1"; - char physvols_1[] = "/dev/sda2"; - char *physvols[] = { - physvols_0, - physvols_1, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, volgroup, physvols); - if (r == -1) - return -1; - } - { - char volgroup[] = "VG2"; - char physvols_0[] = "/dev/sda3"; - char *physvols[] = { - physvols_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, volgroup, physvols); - if (r == -1) - return -1; - } - { - char **r; - int i; - suppress_error = 0; - r = guestfs_vgs (g); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_vgs_1: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "VG1"; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_vgs_1: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (!r[1]) { - fprintf (stderr, "test_vgs_1: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "VG2"; - if (strcmp (r[1], expected) != 0) { - fprintf (stderr, "test_vgs_1: expected \"%s\" but got \"%s\"\n", expected, r[1]); - return -1; - } - } - if (r[2] != NULL) { - fprintf (stderr, "test_vgs_1: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_pvs_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_PVS_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_PVS"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_pvs_0 (void) -{ - if (test_pvs_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_pvs_0"); - return 0; - } - - /* InitBasicFSonLVM for test_pvs_0: create ext2 on /dev/VG/LV */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char volgroup[] = "VG"; - char physvols_0[] = "/dev/sda1"; - char *physvols[] = { - physvols_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, volgroup, physvols); - if (r == -1) - return -1; - } - { - char logvol[] = "LV"; - char volgroup[] = "VG"; - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, logvol, volgroup, 8); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/VG/LV"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/VG/LV"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputListOfDevices for pvs (0) */ - { - char **r; - int i; - suppress_error = 0; - r = guestfs_pvs (g); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_pvs_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/sda1"; - r[0][5] = 's'; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_pvs_0: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (r[1] != NULL) { - fprintf (stderr, "test_pvs_0: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_pvs_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_PVS_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_PVS"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_pvs_1 (void) -{ - if (test_pvs_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_pvs_1"); - return 0; - } - - /* InitNone|InitEmpty for test_pvs_1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputListOfDevices for pvs (1) */ - { - char device[] = "/dev/sda"; - char lines_0[] = ",10"; - char lines_1[] = ",20"; - char lines_2[] = ","; - char *lines[] = { - lines_0, - lines_1, - lines_2, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda2"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda3"; - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, device); - if (r == -1) - return -1; - } - { - char **r; - int i; - suppress_error = 0; - r = guestfs_pvs (g); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_pvs_1: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/sda1"; - r[0][5] = 's'; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_pvs_1: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (!r[1]) { - fprintf (stderr, "test_pvs_1: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/sda2"; - r[1][5] = 's'; - if (strcmp (r[1], expected) != 0) { - fprintf (stderr, "test_pvs_1: expected \"%s\" but got \"%s\"\n", expected, r[1]); - return -1; - } - } - if (!r[2]) { - fprintf (stderr, "test_pvs_1: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/sda3"; - r[2][5] = 's'; - if (strcmp (r[2], expected) != 0) { - fprintf (stderr, "test_pvs_1: expected \"%s\" but got \"%s\"\n", expected, r[2]); - return -1; - } - } - if (r[3] != NULL) { - fprintf (stderr, "test_pvs_1: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_list_partitions_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_LIST_PARTITIONS_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_LIST_PARTITIONS"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_list_partitions_0 (void) -{ - if (test_list_partitions_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_list_partitions_0"); - return 0; - } - - /* InitBasicFS for test_list_partitions_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputListOfDevices for list_partitions (0) */ - { - char **r; - int i; - suppress_error = 0; - r = guestfs_list_partitions (g); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_list_partitions_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/sda1"; - r[0][5] = 's'; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_list_partitions_0: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (r[1] != NULL) { - fprintf (stderr, "test_list_partitions_0: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_list_partitions_1_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_LIST_PARTITIONS_1"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_LIST_PARTITIONS"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_list_partitions_1 (void) -{ - if (test_list_partitions_1_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_list_partitions_1"); - return 0; - } - - /* InitNone|InitEmpty for test_list_partitions_1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputListOfDevices for list_partitions (1) */ - { - char device[] = "/dev/sda"; - char lines_0[] = ",10"; - char lines_1[] = ",20"; - char lines_2[] = ","; - char *lines[] = { - lines_0, - lines_1, - lines_2, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char **r; - int i; - suppress_error = 0; - r = guestfs_list_partitions (g); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_list_partitions_1: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/sda1"; - r[0][5] = 's'; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_list_partitions_1: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (!r[1]) { - fprintf (stderr, "test_list_partitions_1: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/sda2"; - r[1][5] = 's'; - if (strcmp (r[1], expected) != 0) { - fprintf (stderr, "test_list_partitions_1: expected \"%s\" but got \"%s\"\n", expected, r[1]); - return -1; - } - } - if (!r[2]) { - fprintf (stderr, "test_list_partitions_1: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/sda3"; - r[2][5] = 's'; - if (strcmp (r[2], expected) != 0) { - fprintf (stderr, "test_list_partitions_1: expected \"%s\" but got \"%s\"\n", expected, r[2]); - return -1; - } - } - if (r[3] != NULL) { - fprintf (stderr, "test_list_partitions_1: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_list_devices_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_LIST_DEVICES_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_LIST_DEVICES"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_list_devices_0 (void) -{ - if (test_list_devices_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_list_devices_0"); - return 0; - } - - /* InitNone|InitEmpty for test_list_devices_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutputListOfDevices for list_devices (0) */ - { - char **r; - int i; - suppress_error = 0; - r = guestfs_list_devices (g); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_list_devices_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/sda"; - r[0][5] = 's'; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_list_devices_0: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (!r[1]) { - fprintf (stderr, "test_list_devices_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/sdb"; - r[1][5] = 's'; - if (strcmp (r[1], expected) != 0) { - fprintf (stderr, "test_list_devices_0: expected \"%s\" but got \"%s\"\n", expected, r[1]); - return -1; - } - } - if (!r[2]) { - fprintf (stderr, "test_list_devices_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/sdc"; - r[2][5] = 's'; - if (strcmp (r[2], expected) != 0) { - fprintf (stderr, "test_list_devices_0: expected \"%s\" but got \"%s\"\n", expected, r[2]); - return -1; - } - } - if (!r[3]) { - fprintf (stderr, "test_list_devices_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "/dev/sdd"; - r[3][5] = 's'; - if (strcmp (r[3], expected) != 0) { - fprintf (stderr, "test_list_devices_0: expected \"%s\" but got \"%s\"\n", expected, r[3]); - return -1; - } - } - if (r[4] != NULL) { - fprintf (stderr, "test_list_devices_0: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_ls_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_LS_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_LS"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_ls_0 (void) -{ - if (test_ls_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_ls_0"); - return 0; - } - - /* InitBasicFS for test_ls_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputList for ls (0) */ - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_touch (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/newer"; - int r; - suppress_error = 0; - r = guestfs_touch (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/newest"; - int r; - suppress_error = 0; - r = guestfs_touch (g, path); - if (r == -1) - return -1; - } - { - char directory[] = "/"; - char **r; - int i; - suppress_error = 0; - r = guestfs_ls (g, directory); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_ls_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "lost+found"; - if (strcmp (r[0], expected) != 0) { - fprintf (stderr, "test_ls_0: expected \"%s\" but got \"%s\"\n", expected, r[0]); - return -1; - } - } - if (!r[1]) { - fprintf (stderr, "test_ls_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "new"; - if (strcmp (r[1], expected) != 0) { - fprintf (stderr, "test_ls_0: expected \"%s\" but got \"%s\"\n", expected, r[1]); - return -1; - } - } - if (!r[2]) { - fprintf (stderr, "test_ls_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "newer"; - if (strcmp (r[2], expected) != 0) { - fprintf (stderr, "test_ls_0: expected \"%s\" but got \"%s\"\n", expected, r[2]); - return -1; - } - } - if (!r[3]) { - fprintf (stderr, "test_ls_0: short list returned from command\n"); - print_strings (r); - return -1; - } - { - char expected[] = "newest"; - if (strcmp (r[3], expected) != 0) { - fprintf (stderr, "test_ls_0: expected \"%s\" but got \"%s\"\n", expected, r[3]); - return -1; - } - } - if (r[4] != NULL) { - fprintf (stderr, "test_ls_0: extra elements returned from command\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_cat_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_CAT_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_CAT"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_cat_0 (void) -{ - if (test_cat_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_cat_0"); - return 0; - } - - /* InitBasicFS for test_cat_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutput for cat (0) */ - char expected[] = "new file contents"; - { - char path[] = "/new"; - char content[] = "new file contents"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_cat (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_cat_0: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -static int test_touch_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_TOUCH_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_TOUCH"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_touch_0 (void) -{ - if (test_touch_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_touch_0"); - return 0; - } - - /* InitBasicFS for test_touch_0: create ext2 on /dev/sda1 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - /* TestOutputTrue for touch (0) */ - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_touch (g, path); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - int r; - suppress_error = 0; - r = guestfs_exists (g, path); - if (r == -1) - return -1; - if (!r) { - fprintf (stderr, "test_touch_0: expected true, got false\n"); - return -1; - } - } - return 0; -} - -static int test_sync_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_SYNC_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_SYNC"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_sync_0 (void) -{ - if (test_sync_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_sync_0"); - return 0; - } - - /* InitNone|InitEmpty for test_sync_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestRun for sync (0) */ - { - int r; - suppress_error = 0; - r = guestfs_sync (g); - if (r == -1) - return -1; - } - return 0; -} - -static int test_mount_0_skip (void) -{ - const char *str; - - str = getenv ("SKIP_TEST_MOUNT_0"); - if (str && strcmp (str, "1") == 0) return 1; - str = getenv ("SKIP_TEST_MOUNT"); - if (str && strcmp (str, "1") == 0) return 1; - return 0; -} - -static int test_mount_0 (void) -{ - if (test_mount_0_skip ()) { - printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_mount_0"); - return 0; - } - - /* InitNone|InitEmpty for test_mount_0 */ - { - char device[] = "/dev/sda"; - int r; - suppress_error = 0; - r = guestfs_blockdev_setrw (g, device); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - /* TestOutput for mount (0) */ - char expected[] = "new file contents"; - { - char device[] = "/dev/sda"; - char lines_0[] = ","; - char *lines[] = { - lines_0, - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, device, 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - char fstype[] = "ext2"; - char device[] = "/dev/sda1"; - int r; - suppress_error = 0; - r = guestfs_mkfs (g, fstype, device); - if (r == -1) - return -1; - } - { - char device[] = "/dev/sda1"; - char mountpoint[] = "/"; - int r; - suppress_error = 0; - r = guestfs_mount (g, device, mountpoint); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char content[] = "new file contents"; - int r; - suppress_error = 0; - r = guestfs_write_file (g, path, content, 0); - if (r == -1) - return -1; - } - { - char path[] = "/new"; - char *r; - suppress_error = 0; - r = guestfs_cat (g, path); - if (r == NULL) - return -1; - if (strcmp (r, expected) != 0) { - fprintf (stderr, "test_mount_0: expected \"%s\" but got \"%s\"\n", expected, r); - return -1; - } - free (r); - } - return 0; -} - -int main (int argc, char *argv[]) -{ - char c = 0; - int failed = 0; - const char *filename; - int fd; - int nr_tests, test_num = 0; - - no_test_warnings (); - - g = guestfs_create (); - if (g == NULL) { - printf ("guestfs_create FAILED\n"); - exit (1); - } - - guestfs_set_error_handler (g, print_error, NULL); - - guestfs_set_path (g, "../appliance"); - - filename = "test1.img"; - fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666); - if (fd == -1) { - perror (filename); - exit (1); - } - if (lseek (fd, 524288000, SEEK_SET) == -1) { - perror ("lseek"); - close (fd); - unlink (filename); - exit (1); - } - if (write (fd, &c, 1) == -1) { - perror ("write"); - close (fd); - unlink (filename); - exit (1); - } - if (close (fd) == -1) { - perror (filename); - unlink (filename); - exit (1); - } - if (guestfs_add_drive (g, filename) == -1) { - printf ("guestfs_add_drive %s FAILED\n", filename); - exit (1); - } - - filename = "test2.img"; - fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666); - if (fd == -1) { - perror (filename); - exit (1); - } - if (lseek (fd, 52428800, SEEK_SET) == -1) { - perror ("lseek"); - close (fd); - unlink (filename); - exit (1); - } - if (write (fd, &c, 1) == -1) { - perror ("write"); - close (fd); - unlink (filename); - exit (1); - } - if (close (fd) == -1) { - perror (filename); - unlink (filename); - exit (1); - } - if (guestfs_add_drive (g, filename) == -1) { - printf ("guestfs_add_drive %s FAILED\n", filename); - exit (1); - } - - filename = "test3.img"; - fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666); - if (fd == -1) { - perror (filename); - exit (1); - } - if (lseek (fd, 10485760, SEEK_SET) == -1) { - perror ("lseek"); - close (fd); - unlink (filename); - exit (1); - } - if (write (fd, &c, 1) == -1) { - perror ("write"); - close (fd); - unlink (filename); - exit (1); - } - if (close (fd) == -1) { - perror (filename); - unlink (filename); - exit (1); - } - if (guestfs_add_drive (g, filename) == -1) { - printf ("guestfs_add_drive %s FAILED\n", filename); - exit (1); - } - - if (guestfs_add_drive_ro (g, "../images/test.sqsh") == -1) { - printf ("guestfs_add_drive_ro ../images/test.sqsh FAILED\n"); - exit (1); - } - - if (guestfs_launch (g) == -1) { - printf ("guestfs_launch FAILED\n"); - exit (1); - } - if (guestfs_wait_ready (g) == -1) { - printf ("guestfs_wait_ready FAILED\n"); - exit (1); - } - - nr_tests = 146; - - test_num++; - printf ("%3d/%3d test_ntfs_3g_probe_0\n", test_num, nr_tests); - if (test_ntfs_3g_probe_0 () == -1) { - printf ("test_ntfs_3g_probe_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_ntfs_3g_probe_1\n", test_num, nr_tests); - if (test_ntfs_3g_probe_1 () == -1) { - printf ("test_ntfs_3g_probe_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_sleep_0\n", test_num, nr_tests); - if (test_sleep_0 () == -1) { - printf ("test_sleep_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_find_0\n", test_num, nr_tests); - if (test_find_0 () == -1) { - printf ("test_find_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_find_1\n", test_num, nr_tests); - if (test_find_1 () == -1) { - printf ("test_find_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_find_2\n", test_num, nr_tests); - if (test_find_2 () == -1) { - printf ("test_find_2 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_lvresize_0\n", test_num, nr_tests); - if (test_lvresize_0 () == -1) { - printf ("test_lvresize_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_zerofree_0\n", test_num, nr_tests); - if (test_zerofree_0 () == -1) { - printf ("test_zerofree_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_hexdump_0\n", test_num, nr_tests); - if (test_hexdump_0 () == -1) { - printf ("test_hexdump_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_strings_e_0\n", test_num, nr_tests); - if (test_strings_e_0 () == -1) { - printf ("test_strings_e_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_strings_e_1\n", test_num, nr_tests); - if (test_strings_e_1 () == -1) { - printf ("test_strings_e_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_strings_0\n", test_num, nr_tests); - if (test_strings_0 () == -1) { - printf ("test_strings_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_strings_1\n", test_num, nr_tests); - if (test_strings_1 () == -1) { - printf ("test_strings_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_equal_0\n", test_num, nr_tests); - if (test_equal_0 () == -1) { - printf ("test_equal_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_equal_1\n", test_num, nr_tests); - if (test_equal_1 () == -1) { - printf ("test_equal_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_equal_2\n", test_num, nr_tests); - if (test_equal_2 () == -1) { - printf ("test_equal_2 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_ping_daemon_0\n", test_num, nr_tests); - if (test_ping_daemon_0 () == -1) { - printf ("test_ping_daemon_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_dmesg_0\n", test_num, nr_tests); - if (test_dmesg_0 () == -1) { - printf ("test_dmesg_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_drop_caches_0\n", test_num, nr_tests); - if (test_drop_caches_0 () == -1) { - printf ("test_drop_caches_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_mv_0\n", test_num, nr_tests); - if (test_mv_0 () == -1) { - printf ("test_mv_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_mv_1\n", test_num, nr_tests); - if (test_mv_1 () == -1) { - printf ("test_mv_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_cp_a_0\n", test_num, nr_tests); - if (test_cp_a_0 () == -1) { - printf ("test_cp_a_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_cp_0\n", test_num, nr_tests); - if (test_cp_0 () == -1) { - printf ("test_cp_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_cp_1\n", test_num, nr_tests); - if (test_cp_1 () == -1) { - printf ("test_cp_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_cp_2\n", test_num, nr_tests); - if (test_cp_2 () == -1) { - printf ("test_cp_2 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_grub_install_0\n", test_num, nr_tests); - if (test_grub_install_0 () == -1) { - printf ("test_grub_install_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_zero_0\n", test_num, nr_tests); - if (test_zero_0 () == -1) { - printf ("test_zero_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_fsck_0\n", test_num, nr_tests); - if (test_fsck_0 () == -1) { - printf ("test_fsck_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_fsck_1\n", test_num, nr_tests); - if (test_fsck_1 () == -1) { - printf ("test_fsck_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_set_e2uuid_0\n", test_num, nr_tests); - if (test_set_e2uuid_0 () == -1) { - printf ("test_set_e2uuid_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_set_e2uuid_1\n", test_num, nr_tests); - if (test_set_e2uuid_1 () == -1) { - printf ("test_set_e2uuid_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_set_e2uuid_2\n", test_num, nr_tests); - if (test_set_e2uuid_2 () == -1) { - printf ("test_set_e2uuid_2 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_set_e2uuid_3\n", test_num, nr_tests); - if (test_set_e2uuid_3 () == -1) { - printf ("test_set_e2uuid_3 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_set_e2label_0\n", test_num, nr_tests); - if (test_set_e2label_0 () == -1) { - printf ("test_set_e2label_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_pvremove_0\n", test_num, nr_tests); - if (test_pvremove_0 () == -1) { - printf ("test_pvremove_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_pvremove_1\n", test_num, nr_tests); - if (test_pvremove_1 () == -1) { - printf ("test_pvremove_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_pvremove_2\n", test_num, nr_tests); - if (test_pvremove_2 () == -1) { - printf ("test_pvremove_2 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_vgremove_0\n", test_num, nr_tests); - if (test_vgremove_0 () == -1) { - printf ("test_vgremove_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_vgremove_1\n", test_num, nr_tests); - if (test_vgremove_1 () == -1) { - printf ("test_vgremove_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_lvremove_0\n", test_num, nr_tests); - if (test_lvremove_0 () == -1) { - printf ("test_lvremove_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_lvremove_1\n", test_num, nr_tests); - if (test_lvremove_1 () == -1) { - printf ("test_lvremove_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_lvremove_2\n", test_num, nr_tests); - if (test_lvremove_2 () == -1) { - printf ("test_lvremove_2 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_mount_ro_0\n", test_num, nr_tests); - if (test_mount_ro_0 () == -1) { - printf ("test_mount_ro_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_mount_ro_1\n", test_num, nr_tests); - if (test_mount_ro_1 () == -1) { - printf ("test_mount_ro_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_tgz_in_0\n", test_num, nr_tests); - if (test_tgz_in_0 () == -1) { - printf ("test_tgz_in_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_tar_in_0\n", test_num, nr_tests); - if (test_tar_in_0 () == -1) { - printf ("test_tar_in_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_checksum_0\n", test_num, nr_tests); - if (test_checksum_0 () == -1) { - printf ("test_checksum_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_checksum_1\n", test_num, nr_tests); - if (test_checksum_1 () == -1) { - printf ("test_checksum_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_checksum_2\n", test_num, nr_tests); - if (test_checksum_2 () == -1) { - printf ("test_checksum_2 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_checksum_3\n", test_num, nr_tests); - if (test_checksum_3 () == -1) { - printf ("test_checksum_3 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_checksum_4\n", test_num, nr_tests); - if (test_checksum_4 () == -1) { - printf ("test_checksum_4 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_checksum_5\n", test_num, nr_tests); - if (test_checksum_5 () == -1) { - printf ("test_checksum_5 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_checksum_6\n", test_num, nr_tests); - if (test_checksum_6 () == -1) { - printf ("test_checksum_6 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_checksum_7\n", test_num, nr_tests); - if (test_checksum_7 () == -1) { - printf ("test_checksum_7 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_checksum_8\n", test_num, nr_tests); - if (test_checksum_8 () == -1) { - printf ("test_checksum_8 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_download_0\n", test_num, nr_tests); - if (test_download_0 () == -1) { - printf ("test_download_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_upload_0\n", test_num, nr_tests); - if (test_upload_0 () == -1) { - printf ("test_upload_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_blockdev_rereadpt_0\n", test_num, nr_tests); - if (test_blockdev_rereadpt_0 () == -1) { - printf ("test_blockdev_rereadpt_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_blockdev_flushbufs_0\n", test_num, nr_tests); - if (test_blockdev_flushbufs_0 () == -1) { - printf ("test_blockdev_flushbufs_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_blockdev_getsize64_0\n", test_num, nr_tests); - if (test_blockdev_getsize64_0 () == -1) { - printf ("test_blockdev_getsize64_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_blockdev_getsz_0\n", test_num, nr_tests); - if (test_blockdev_getsz_0 () == -1) { - printf ("test_blockdev_getsz_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_blockdev_getbsz_0\n", test_num, nr_tests); - if (test_blockdev_getbsz_0 () == -1) { - printf ("test_blockdev_getbsz_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_blockdev_getss_0\n", test_num, nr_tests); - if (test_blockdev_getss_0 () == -1) { - printf ("test_blockdev_getss_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_blockdev_getro_0\n", test_num, nr_tests); - if (test_blockdev_getro_0 () == -1) { - printf ("test_blockdev_getro_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_blockdev_setrw_0\n", test_num, nr_tests); - if (test_blockdev_setrw_0 () == -1) { - printf ("test_blockdev_setrw_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_blockdev_setro_0\n", test_num, nr_tests); - if (test_blockdev_setro_0 () == -1) { - printf ("test_blockdev_setro_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_statvfs_0\n", test_num, nr_tests); - if (test_statvfs_0 () == -1) { - printf ("test_statvfs_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_lstat_0\n", test_num, nr_tests); - if (test_lstat_0 () == -1) { - printf ("test_lstat_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_stat_0\n", test_num, nr_tests); - if (test_stat_0 () == -1) { - printf ("test_stat_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_lines_0\n", test_num, nr_tests); - if (test_command_lines_0 () == -1) { - printf ("test_command_lines_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_lines_1\n", test_num, nr_tests); - if (test_command_lines_1 () == -1) { - printf ("test_command_lines_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_lines_2\n", test_num, nr_tests); - if (test_command_lines_2 () == -1) { - printf ("test_command_lines_2 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_lines_3\n", test_num, nr_tests); - if (test_command_lines_3 () == -1) { - printf ("test_command_lines_3 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_lines_4\n", test_num, nr_tests); - if (test_command_lines_4 () == -1) { - printf ("test_command_lines_4 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_lines_5\n", test_num, nr_tests); - if (test_command_lines_5 () == -1) { - printf ("test_command_lines_5 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_lines_6\n", test_num, nr_tests); - if (test_command_lines_6 () == -1) { - printf ("test_command_lines_6 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_lines_7\n", test_num, nr_tests); - if (test_command_lines_7 () == -1) { - printf ("test_command_lines_7 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_lines_8\n", test_num, nr_tests); - if (test_command_lines_8 () == -1) { - printf ("test_command_lines_8 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_lines_9\n", test_num, nr_tests); - if (test_command_lines_9 () == -1) { - printf ("test_command_lines_9 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_lines_10\n", test_num, nr_tests); - if (test_command_lines_10 () == -1) { - printf ("test_command_lines_10 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_0\n", test_num, nr_tests); - if (test_command_0 () == -1) { - printf ("test_command_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_1\n", test_num, nr_tests); - if (test_command_1 () == -1) { - printf ("test_command_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_2\n", test_num, nr_tests); - if (test_command_2 () == -1) { - printf ("test_command_2 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_3\n", test_num, nr_tests); - if (test_command_3 () == -1) { - printf ("test_command_3 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_4\n", test_num, nr_tests); - if (test_command_4 () == -1) { - printf ("test_command_4 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_5\n", test_num, nr_tests); - if (test_command_5 () == -1) { - printf ("test_command_5 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_6\n", test_num, nr_tests); - if (test_command_6 () == -1) { - printf ("test_command_6 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_7\n", test_num, nr_tests); - if (test_command_7 () == -1) { - printf ("test_command_7 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_8\n", test_num, nr_tests); - if (test_command_8 () == -1) { - printf ("test_command_8 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_9\n", test_num, nr_tests); - if (test_command_9 () == -1) { - printf ("test_command_9 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_10\n", test_num, nr_tests); - if (test_command_10 () == -1) { - printf ("test_command_10 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_command_11\n", test_num, nr_tests); - if (test_command_11 () == -1) { - printf ("test_command_11 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_file_0\n", test_num, nr_tests); - if (test_file_0 () == -1) { - printf ("test_file_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_file_1\n", test_num, nr_tests); - if (test_file_1 () == -1) { - printf ("test_file_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_file_2\n", test_num, nr_tests); - if (test_file_2 () == -1) { - printf ("test_file_2 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_umount_all_0\n", test_num, nr_tests); - if (test_umount_all_0 () == -1) { - printf ("test_umount_all_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_umount_all_1\n", test_num, nr_tests); - if (test_umount_all_1 () == -1) { - printf ("test_umount_all_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_mounts_0\n", test_num, nr_tests); - if (test_mounts_0 () == -1) { - printf ("test_mounts_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_umount_0\n", test_num, nr_tests); - if (test_umount_0 () == -1) { - printf ("test_umount_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_umount_1\n", test_num, nr_tests); - if (test_umount_1 () == -1) { - printf ("test_umount_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_write_file_0\n", test_num, nr_tests); - if (test_write_file_0 () == -1) { - printf ("test_write_file_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_write_file_1\n", test_num, nr_tests); - if (test_write_file_1 () == -1) { - printf ("test_write_file_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_write_file_2\n", test_num, nr_tests); - if (test_write_file_2 () == -1) { - printf ("test_write_file_2 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_write_file_3\n", test_num, nr_tests); - if (test_write_file_3 () == -1) { - printf ("test_write_file_3 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_write_file_4\n", test_num, nr_tests); - if (test_write_file_4 () == -1) { - printf ("test_write_file_4 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_write_file_5\n", test_num, nr_tests); - if (test_write_file_5 () == -1) { - printf ("test_write_file_5 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_mkfs_0\n", test_num, nr_tests); - if (test_mkfs_0 () == -1) { - printf ("test_mkfs_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_lvcreate_0\n", test_num, nr_tests); - if (test_lvcreate_0 () == -1) { - printf ("test_lvcreate_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_vgcreate_0\n", test_num, nr_tests); - if (test_vgcreate_0 () == -1) { - printf ("test_vgcreate_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_pvcreate_0\n", test_num, nr_tests); - if (test_pvcreate_0 () == -1) { - printf ("test_pvcreate_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_is_dir_0\n", test_num, nr_tests); - if (test_is_dir_0 () == -1) { - printf ("test_is_dir_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_is_dir_1\n", test_num, nr_tests); - if (test_is_dir_1 () == -1) { - printf ("test_is_dir_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_is_file_0\n", test_num, nr_tests); - if (test_is_file_0 () == -1) { - printf ("test_is_file_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_is_file_1\n", test_num, nr_tests); - if (test_is_file_1 () == -1) { - printf ("test_is_file_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_exists_0\n", test_num, nr_tests); - if (test_exists_0 () == -1) { - printf ("test_exists_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_exists_1\n", test_num, nr_tests); - if (test_exists_1 () == -1) { - printf ("test_exists_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_mkdir_p_0\n", test_num, nr_tests); - if (test_mkdir_p_0 () == -1) { - printf ("test_mkdir_p_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_mkdir_p_1\n", test_num, nr_tests); - if (test_mkdir_p_1 () == -1) { - printf ("test_mkdir_p_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_mkdir_p_2\n", test_num, nr_tests); - if (test_mkdir_p_2 () == -1) { - printf ("test_mkdir_p_2 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_mkdir_p_3\n", test_num, nr_tests); - if (test_mkdir_p_3 () == -1) { - printf ("test_mkdir_p_3 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_mkdir_p_4\n", test_num, nr_tests); - if (test_mkdir_p_4 () == -1) { - printf ("test_mkdir_p_4 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_mkdir_0\n", test_num, nr_tests); - if (test_mkdir_0 () == -1) { - printf ("test_mkdir_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_mkdir_1\n", test_num, nr_tests); - if (test_mkdir_1 () == -1) { - printf ("test_mkdir_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_rm_rf_0\n", test_num, nr_tests); - if (test_rm_rf_0 () == -1) { - printf ("test_rm_rf_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_rmdir_0\n", test_num, nr_tests); - if (test_rmdir_0 () == -1) { - printf ("test_rmdir_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_rmdir_1\n", test_num, nr_tests); - if (test_rmdir_1 () == -1) { - printf ("test_rmdir_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_rmdir_2\n", test_num, nr_tests); - if (test_rmdir_2 () == -1) { - printf ("test_rmdir_2 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_rm_0\n", test_num, nr_tests); - if (test_rm_0 () == -1) { - printf ("test_rm_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_rm_1\n", test_num, nr_tests); - if (test_rm_1 () == -1) { - printf ("test_rm_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_rm_2\n", test_num, nr_tests); - if (test_rm_2 () == -1) { - printf ("test_rm_2 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_read_lines_0\n", test_num, nr_tests); - if (test_read_lines_0 () == -1) { - printf ("test_read_lines_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_read_lines_1\n", test_num, nr_tests); - if (test_read_lines_1 () == -1) { - printf ("test_read_lines_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_lvs_0\n", test_num, nr_tests); - if (test_lvs_0 () == -1) { - printf ("test_lvs_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_lvs_1\n", test_num, nr_tests); - if (test_lvs_1 () == -1) { - printf ("test_lvs_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_vgs_0\n", test_num, nr_tests); - if (test_vgs_0 () == -1) { - printf ("test_vgs_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_vgs_1\n", test_num, nr_tests); - if (test_vgs_1 () == -1) { - printf ("test_vgs_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_pvs_0\n", test_num, nr_tests); - if (test_pvs_0 () == -1) { - printf ("test_pvs_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_pvs_1\n", test_num, nr_tests); - if (test_pvs_1 () == -1) { - printf ("test_pvs_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_list_partitions_0\n", test_num, nr_tests); - if (test_list_partitions_0 () == -1) { - printf ("test_list_partitions_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_list_partitions_1\n", test_num, nr_tests); - if (test_list_partitions_1 () == -1) { - printf ("test_list_partitions_1 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_list_devices_0\n", test_num, nr_tests); - if (test_list_devices_0 () == -1) { - printf ("test_list_devices_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_ls_0\n", test_num, nr_tests); - if (test_ls_0 () == -1) { - printf ("test_ls_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_cat_0\n", test_num, nr_tests); - if (test_cat_0 () == -1) { - printf ("test_cat_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_touch_0\n", test_num, nr_tests); - if (test_touch_0 () == -1) { - printf ("test_touch_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_sync_0\n", test_num, nr_tests); - if (test_sync_0 () == -1) { - printf ("test_sync_0 FAILED\n"); - failed++; - } - test_num++; - printf ("%3d/%3d test_mount_0\n", test_num, nr_tests); - if (test_mount_0 () == -1) { - printf ("test_mount_0 FAILED\n"); - failed++; - } - - guestfs_close (g); - unlink ("test1.img"); - unlink ("test2.img"); - unlink ("test3.img"); - - if (failed > 0) { - printf ("***** %d / %d tests FAILED *****\n", failed, nr_tests); - exit (1); - } - - exit (0); -} diff --git a/configure.ac b/configure.ac index 2ba0dd9..4a57fa3 100644 --- a/configure.ac +++ b/configure.ac @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -AC_INIT([libguestfs],[1.0.43]) +AC_INIT([libguestfs],[1.0.55]) AM_INIT_AUTOMAKE AC_CONFIG_MACRO_DIR([m4]) @@ -102,41 +102,52 @@ the --with-qemu option. AC_MSG_RESULT([yes]) fi +dnl Set drive interface used by the guestfs_add_drive{,_ro} calls +dnl ('-drive ...,if=...' option to qemu). +dnl +dnl NB. We will change the default in future to virtio, but at the +dnl moment this causes a performance problem, RHBZ#509383. +AC_ARG_WITH([drive-if], + [AS_HELP_STRING([--with-drive-if], + [set default driver (ide|scsi|virtio) @<:@default=ide@:>@])], + [], + [with_drive_if=ide]) +AC_DEFINE_UNQUOTED([DRIVE_IF],["$with_drive_if"],[Default drive interface.]) + dnl Check for febootstrap etc. AC_CHECK_PROG([FEBOOTSTRAP], [febootstrap],[febootstrap],[no]) -test "x$FEBOOTSTRAP" = "xno" && \ - AC_MSG_ERROR([febootstrap must be installed]) -AC_CHECK_PROG([FEBOOTSTRAP_RUN], +if test "x$FEBOOTSTRAP" != "xno"; then + AC_CHECK_PROG([FEBOOTSTRAP_RUN], [febootstrap-run],[febootstrap-run],[no]) -test "x$FEBOOTSTRAP_RUN" = "xno" && \ + test "x$FEBOOTSTRAP_RUN" = "xno" && \ AC_MSG_ERROR([febootstrap-run must be installed]) -AC_CHECK_PROG([FEBOOTSTRAP_INSTALL], + AC_CHECK_PROG([FEBOOTSTRAP_INSTALL], [febootstrap-install],[febootstrap-install],[no]) -test "x$FEBOOTSTRAP_INSTALL" = "xno" && \ + test "x$FEBOOTSTRAP_INSTALL" = "xno" && \ AC_MSG_ERROR([febootstrap-install must be installed]) -AC_CHECK_PROG([FEBOOTSTRAP_MINIMIZE], + AC_CHECK_PROG([FEBOOTSTRAP_MINIMIZE], [febootstrap-minimize],[febootstrap-minimize],[no]) -test "x$FEBOOTSTRAP_MINIMIZE" = "xno" && \ + test "x$FEBOOTSTRAP_MINIMIZE" = "xno" && \ AC_MSG_ERROR([febootstrap-minimize must be installed]) -AC_CHECK_PROG([FEBOOTSTRAP_TO_INITRAMFS], + AC_CHECK_PROG([FEBOOTSTRAP_TO_INITRAMFS], [febootstrap-to-initramfs],[febootstrap-to-initramfs],[no]) -test "x$FEBOOTSTRAP_TO_INITRAMFS" = "xno" && \ + test "x$FEBOOTSTRAP_TO_INITRAMFS" = "xno" && \ AC_MSG_ERROR([febootstrap-to-initramfs must be installed]) -dnl Check we have fakechroot >= 2.9 (it's an indirect requirement -dnl of febootstrap, but old versions will fail with yum). -AC_CHECK_PROG([FAKECHROOT], + dnl Check we have fakechroot >= 2.9 (it's an indirect requirement + dnl of febootstrap, but old versions will fail with yum). + AC_CHECK_PROG([FAKECHROOT], [fakechroot],[fakechroot],[no]) -test "x$FAKECHROOT" = "xno" && \ + test "x$FAKECHROOT" = "xno" && \ AC_MSG_ERROR([fakechroot must be installed]) -AC_MSG_CHECKING([fakechroot version]) -fakechroot_version=`$FAKECHROOT --version | awk '{print $3}'` -if test -z "$fakechroot_version"; then + AC_MSG_CHECKING([fakechroot version]) + fakechroot_version=`$FAKECHROOT --version | awk '{print $3}'` + if test -z "$fakechroot_version"; then AC_MSG_RESULT([failed]) AC_MSG_WARN([fakechroot --version command failed, proceeding anyway]) -else + else AC_MSG_RESULT([$fakechroot_version]) fakechroot_major=`echo $fakechroot_version | awk -F. '{print $1}'` fakechroot_minor=`echo $fakechroot_version | awk -F. '{print $2}'` @@ -144,7 +155,21 @@ else \( "$fakechroot_major" -eq 2 -a "$fakechroot_minor" -lt 9 \); then AC_MSG_ERROR([fakechroot version must be >= 2.9]) fi + fi + DIST="REDHAT" +else + # check for debootstrap and debirf + AC_CHECK_PROG([DEBOOTSTRAP], + [debootstrap],[debootstrap],[no]) + test "x$DEBOOTSTRAP" = "xno" && \ + AC_MSG_ERROR([Either febootstrap or debootstrap must be installed]) + AC_CHECK_PROG([DEBIRF],[debirf],[debirf],[no]) + test "x$DEBIRF" = "xno" && + AC_MSG_ERROR([debirf must be installed]) + DIST="DEBIAN" fi +AC_SUBST(DIST) + dnl --with-repo to specify a Fedora repository. AC_ARG_WITH([repo], @@ -179,6 +204,49 @@ AC_ARG_WITH([mirror], MIRROR="$with_mirror" AC_SUBST(MIRROR) +dnl Build the supermin appliance? Please see README file before +dnl enabling this option. +AC_ARG_ENABLE([supermin], + [AS_HELP_STRING([--enable-supermin], + [enable supermin appliance (see README) @<:@default=no@:>@])], + [], + [enable_supermin=no]) +AM_CONDITIONAL([SUPERMIN],[test "x$enable_supermin" = "xyes"]) + +if test "x$enable_supermin" = "xyes"; then + dnl Check febootstrap-to-initramfs accepts the --files option + dnl (febootstrap >= 2.2). + AC_MSG_CHECKING([for --files support in $FEBOOTSTRAP_TO_INITRAMFS]) + out=`$FEBOOTSTRAP_TO_INITRAMFS 2>&1 ||:` + echo "febootstrap_to_initramfs test command output: $out" >&AS_MESSAGE_LOG_FD + if ! echo $out | grep -sq -- "--files" ; then + AC_MSG_RESULT([no]) + AC_MSG_FAILURE( +[febootstrap-to-initramfs does not support the --files option. + +To build the supermin appliance, you need to upgrade to the latest +version of febootstrap. +]) + fi + AC_MSG_RESULT([yes]) + + dnl Check febootstrap-to-initramfs accepts the --nocompress option + dnl (febootstrap >= 2.3). + AC_MSG_CHECKING([for --nocompress support in $FEBOOTSTRAP_TO_INITRAMFS]) + out=`$FEBOOTSTRAP_TO_INITRAMFS 2>&1 ||:` + echo "febootstrap_to_initramfs test command output: $out" >&AS_MESSAGE_LOG_FD + if ! echo $out | grep -sq -- "--nocompress" ; then + AC_MSG_RESULT([no]) + AC_MSG_FAILURE( +[febootstrap-to-initramfs does not support the --nocompress option. + +To build the supermin appliance, you need to upgrade to the latest +version of febootstrap. +]) + fi + AC_MSG_RESULT([yes]) +fi + dnl Readline. AC_ARG_WITH([readline], [AS_HELP_STRING([--with-readline], @@ -428,7 +496,7 @@ AM_CONDITIONAL([HAVE_HASKELL], dnl Check for Perl modules needed by the inspector. missing_perl_modules=no -for pm in Pod::Usage Getopt::Long Sys::Virt Data::Dumper; do +for pm in Pod::Usage Getopt::Long Sys::Virt Data::Dumper XML::Writer; do AC_MSG_CHECKING([for $pm]) if ! perl -M$pm -e1 >/dev/null 2>&1; then AC_MSG_RESULT([no]) @@ -444,15 +512,30 @@ fi AM_CONDITIONAL([HAVE_INSPECTOR], [test "x$PERL" != "xno" -a "x$missing_perl_modules" != "xyes"]) +dnl Library versioning. +MAX_PROC_NR=`cat $srcdir/src/MAX_PROC_NR` +AC_SUBST(MAX_PROC_NR) + dnl Run in subdirs. AC_CONFIG_SUBDIRS([daemon]) dnl Produce output files. AC_CONFIG_HEADERS([config.h]) +dnl http://www.mail-archive.com/automake@gnu.org/msg10204.html +AC_CONFIG_FILES([appliance/make.sh], + [chmod +x appliance/make.sh]) +AC_CONFIG_FILES([appliance/update.sh], + [chmod +x appliance/update.sh]) +AC_CONFIG_FILES([appliance/supermin-split.sh], + [chmod +x appliance/supermin-split.sh]) +AC_CONFIG_FILES([appliance/supermin-make.sh], + [chmod +x appliance/supermin-make.sh]) +AC_CONFIG_FILES([appliance/libguestfs-supermin-helper], + [chmod +x appliance/libguestfs-supermin-helper]) AC_CONFIG_FILES([Makefile src/Makefile fish/Makefile po/Makefile.in examples/Makefile appliance/Makefile - appliance/make-initramfs.sh appliance/update-initramfs.sh + appliance/debian/debirf.conf images/Makefile capitests/Makefile regressions/Makefile @@ -467,9 +550,6 @@ AC_CONFIG_FILES([Makefile ocaml/META perl/Makefile.PL]) AC_OUTPUT -dnl WTF? -chmod +x appliance/make-initramfs.sh appliance/update-initramfs.sh - dnl Produce summary. echo echo @@ -493,6 +573,7 @@ echo -n "Haskell bindings .................... " if test "x$HAVE_HASKELL" = "x"; then echo "yes"; else echo "no"; fi echo -n "virt-inspector ...................... " if test "x$HAVE_INSPECTOR" = "x"; then echo "yes"; else echo "no"; fi +echo "supermin appliance .................. $enable_supermin" echo echo "If any optional component is configured 'no' when you expected 'yes'" echo "then you should check the preceeding messages." diff --git a/daemon/Makefile.am b/daemon/Makefile.am index ea4b721..141dfad 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -29,30 +29,42 @@ guestfsd_SOURCES = \ daemon.h \ debug.c \ devsparts.c \ + df.c \ dir.c \ dmesg.c \ dropcaches.c \ + du.c \ ext2.c \ file.c \ find.c \ fsck.c \ + glob.c \ grub.c \ guestfsd.c \ + headtail.c \ hexdump.c \ + initrd.c \ ls.c \ lvm.c \ + mknod.c \ mount.c \ + names.c \ ntfs.c \ pingdaemon.c \ proto.c \ + readdir.c \ + scrub.c \ sfdisk.c \ sleep.c \ stat.c \ strings.c \ stubs.c \ + swap.c \ sync.c \ tar.c \ + umask.c \ upload.c \ + wc.c \ zero.c \ zerofree.c \ ../src/guestfs_protocol.h \ diff --git a/daemon/actions.h b/daemon/actions.h deleted file mode 100644 index c8e285c..0000000 --- a/daemon/actions.h +++ /dev/null @@ -1,133 +0,0 @@ -/* libguestfs generated file - * WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'. - * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST. - * - * Copyright (C) 2009 Red Hat Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "../src/guestfs_protocol.h" - -extern int do_mount (char *device, char *mountpoint); -extern int do_sync (void); -extern int do_touch (char *path); -extern char *do_cat (char *path); -extern char *do_ll (char *directory); -extern char **do_ls (char *directory); -extern char **do_list_devices (void); -extern char **do_list_partitions (void); -extern char **do_pvs (void); -extern char **do_vgs (void); -extern char **do_lvs (void); -extern guestfs_lvm_int_pv_list *do_pvs_full (void); -extern guestfs_lvm_int_vg_list *do_vgs_full (void); -extern guestfs_lvm_int_lv_list *do_lvs_full (void); -extern char **do_read_lines (char *path); -extern int do_aug_init (char *root, int flags); -extern int do_aug_close (void); -extern int do_aug_defvar (char *name, char *expr); -extern guestfs_aug_defnode_ret *do_aug_defnode (char *name, char *expr, char *val); -extern char *do_aug_get (char *path); -extern int do_aug_set (char *path, char *val); -extern int do_aug_insert (char *path, char *label, int before); -extern int do_aug_rm (char *path); -extern int do_aug_mv (char *src, char *dest); -extern char **do_aug_match (char *path); -extern int do_aug_save (void); -extern int do_aug_load (void); -extern char **do_aug_ls (char *path); -extern int do_rm (char *path); -extern int do_rmdir (char *path); -extern int do_rm_rf (char *path); -extern int do_mkdir (char *path); -extern int do_mkdir_p (char *path); -extern int do_chmod (int mode, char *path); -extern int do_chown (int owner, int group, char *path); -extern int do_exists (char *path); -extern int do_is_file (char *path); -extern int do_is_dir (char *path); -extern int do_pvcreate (char *device); -extern int do_vgcreate (char *volgroup, char **physvols); -extern int do_lvcreate (char *logvol, char *volgroup, int mbytes); -extern int do_mkfs (char *fstype, char *device); -extern int do_sfdisk (char *device, int cyls, int heads, int sectors, char **lines); -extern int do_write_file (char *path, char *content, int size); -extern int do_umount (char *pathordevice); -extern char **do_mounts (void); -extern int do_umount_all (void); -extern int do_lvm_remove_all (void); -extern char *do_file (char *path); -extern char *do_command (char **arguments); -extern char **do_command_lines (char **arguments); -extern guestfs_int_stat *do_stat (char *path); -extern guestfs_int_stat *do_lstat (char *path); -extern guestfs_int_statvfs *do_statvfs (char *path); -extern char **do_tune2fs_l (char *device); -extern int do_blockdev_setro (char *device); -extern int do_blockdev_setrw (char *device); -extern int do_blockdev_getro (char *device); -extern int do_blockdev_getss (char *device); -extern int do_blockdev_getbsz (char *device); -extern int do_blockdev_setbsz (char *device, int blocksize); -extern int64_t do_blockdev_getsz (char *device); -extern int64_t do_blockdev_getsize64 (char *device); -extern int do_blockdev_flushbufs (char *device); -extern int do_blockdev_rereadpt (char *device); -extern int do_upload (char *remotefilename); -extern int do_download (char *remotefilename); -extern char *do_checksum (char *csumtype, char *path); -extern int do_tar_in (char *directory); -extern int do_tar_out (char *directory); -extern int do_tgz_in (char *directory); -extern int do_tgz_out (char *directory); -extern int do_mount_ro (char *device, char *mountpoint); -extern int do_mount_options (char *options, char *device, char *mountpoint); -extern int do_mount_vfs (char *options, char *vfstype, char *device, char *mountpoint); -extern char *do_debug (char *subcmd, char **extraargs); -extern int do_lvremove (char *device); -extern int do_vgremove (char *vgname); -extern int do_pvremove (char *device); -extern int do_set_e2label (char *device, char *label); -extern char *do_get_e2label (char *device); -extern int do_set_e2uuid (char *device, char *uuid); -extern char *do_get_e2uuid (char *device); -extern int do_fsck (char *fstype, char *device); -extern int do_zero (char *device); -extern int do_grub_install (char *root, char *device); -extern int do_cp (char *src, char *dest); -extern int do_cp_a (char *src, char *dest); -extern int do_mv (char *src, char *dest); -extern int do_drop_caches (int whattodrop); -extern char *do_dmesg (void); -extern int do_ping_daemon (void); -extern int do_equal (char *file1, char *file2); -extern char **do_strings (char *path); -extern char **do_strings_e (char *encoding, char *path); -extern char *do_hexdump (char *path); -extern int do_zerofree (char *device); -extern int do_pvresize (char *device); -extern int do_sfdisk_N (char *device, int n, int cyls, int heads, int sectors, char *line); -extern char *do_sfdisk_l (char *device); -extern char *do_sfdisk_kernel_geometry (char *device); -extern char *do_sfdisk_disk_geometry (char *device); -extern int do_vg_activate_all (int activate); -extern int do_vg_activate (int activate, char **volgroups); -extern int do_lvresize (char *device, int mbytes); -extern int do_resize2fs (char *device); -extern char **do_find (char *directory); -extern int do_e2fsck_f (char *device); -extern int do_sleep (int secs); -extern int do_ntfs_3g_probe (int rw, char *device); diff --git a/daemon/command.c b/daemon/command.c index 3254de5..b33f2db 100644 --- a/daemon/command.c +++ b/daemon/command.c @@ -101,3 +101,19 @@ do_command_lines (char **argv) return lines; /* Caller frees. */ } + +char * +do_sh (char *command) +{ + char *argv[] = { "/bin/sh", "-c", command, NULL }; + + return do_command (argv); +} + +char ** +do_sh_lines (char *command) +{ + char *argv[] = { "/bin/sh", "-c", command, NULL }; + + return do_command_lines (argv); +} diff --git a/daemon/configure.ac b/daemon/configure.ac index a91db6d..6ecbb8a 100644 --- a/daemon/configure.ac +++ b/daemon/configure.ac @@ -44,7 +44,7 @@ AC_PROG_CPP AC_C_PROTOTYPES test "x$U" != "x" && AC_MSG_ERROR([Compiler not ANSI compliant]) -AC_PROG_CC_C_O +AM_PROG_CC_C_O dnl Check for Augeas (now optional). AC_CHECK_LIB([augeas],[aug_match],[ diff --git a/daemon/daemon.h b/daemon/daemon.h index c3b9120..5f22a4f 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -51,8 +51,13 @@ extern int shell_quote (char *out, int len, const char *in); extern int device_name_translation (char *device, const char *func); +extern void udev_settle (void); + extern int verbose; +/*-- in names.c (auto-generated) --*/ +extern const char *function_names[]; + /*-- in proto.c --*/ extern int proc_nr; extern int serial; @@ -139,7 +144,13 @@ extern void reply (xdrproc_t xdrp, char *ret); /* Helper for functions which need either an absolute path in the * mounted filesystem, OR a /dev/ device which exists. + * * NB. Cannot be used for FileIn functions. + * + * NB #2: Functions which mix filenames and device paths should be + * avoided, and existing functions should be deprecated. This is + * because we intend in future to make device parameters a distinct + * type from filenames. */ #define NEED_ROOT_OR_IS_DEVICE(path,errcode) \ do { \ @@ -156,11 +167,22 @@ extern void reply (xdrproc_t xdrp, char *ret); * (2) You must not change directory! cwd must always be "/", otherwise * we can't escape our own chroot. * (3) All paths specified must be absolute. - * (4) CHROOT_OUT does not affect errno. + * (4) Neither macro affects errno. */ -#define CHROOT_IN chroot ("/sysroot"); -#define CHROOT_OUT \ - do { int old_errno = errno; chroot ("."); errno = old_errno; } while (0) +#define CHROOT_IN \ + do { \ + int __old_errno = errno; \ + if (chroot ("/sysroot") == -1) \ + perror ("CHROOT_IN: sysroot"); \ + errno = __old_errno; \ + } while (0) +#define CHROOT_OUT \ + do { \ + int __old_errno = errno; \ + if (chroot (".") == -1) \ + perror ("CHROOT_OUT: ."); \ + errno = __old_errno; \ + } while (0) /* Marks functions which are not implemented. * NB. Cannot be used for FileIn functions. diff --git a/daemon/debug.c b/daemon/debug.c index ce760e6..d6e469b 100644 --- a/daemon/debug.c +++ b/daemon/debug.c @@ -189,23 +189,47 @@ debug_segv (const char *subcmd, int argc, char *const *const argv) return NULL; } -/* Run an arbitrary shell command. */ +/* Run an arbitrary shell command using /bin/sh from the appliance. + * + * Note this is somewhat different from the ordinary guestfs_sh command + * because it's not using the guest shell, and is not chrooted. + * + * Also we ignore any errors and you can see the full output if you + * add 2>&1 to the end of the command string. + */ static char * debug_sh (const char *subcmd, int argc, char *const *const argv) { - int r; - char *out, *err; + char *cmd; + int len, i, j; + char *out; - r = commandv (&out, &err, argv); - if (r == -1) { - reply_with_error ("sh: %s", err); - free (out); - free (err); + if (argc < 1) { + reply_with_error ("debug: sh: expecting a command to run"); return NULL; } - free (err); + /* guestfish splits the parameter(s) into a list of strings, + * and we have to reassemble them here. Not ideal. XXX + */ + for (i = len = 0; i < argc; ++i) + len += strlen (argv[i]) + 1; + cmd = malloc (len); + if (!cmd) { + reply_with_perror ("malloc"); + return NULL; + } + for (i = j = 0; i < argc; ++i) { + len = strlen (argv[i]); + memcpy (&cmd[j], argv[i], len); + j += len; + cmd[j] = ' '; + j++; + } + cmd[j-1] = '\0'; + command (&out, NULL, "/bin/sh", "-c", cmd, NULL); + free (cmd); return out; } diff --git a/daemon/devsparts.c b/daemon/devsparts.c index 83e4bb9..4c7a643 100644 --- a/daemon/devsparts.c +++ b/daemon/devsparts.c @@ -46,7 +46,8 @@ do_list_devices (void) while ((d = readdir (dir)) != NULL) { if (strncmp (d->d_name, "sd", 2) == 0 || - strncmp (d->d_name, "hd", 2) == 0) { + strncmp (d->d_name, "hd", 2) == 0 || + strncmp (d->d_name, "vd", 2) == 0) { snprintf (buf, sizeof buf, "/dev/%s", d->d_name); if (add_string (&r, &size, &alloc, buf) == -1) { closedir (dir); @@ -87,7 +88,8 @@ do_list_partitions (void) while ((d = readdir (dir)) != NULL) { if (strncmp (d->d_name, "sd", 2) == 0 || - strncmp (d->d_name, "hd", 2) == 0) { + strncmp (d->d_name, "hd", 2) == 0 || + strncmp (d->d_name, "vd", 2) == 0) { strncpy (devname, d->d_name, sizeof devname); devname[sizeof devname - 1] = '\0'; diff --git a/daemon/df.c b/daemon/df.c new file mode 100644 index 0000000..0a7303c --- /dev/null +++ b/daemon/df.c @@ -0,0 +1,70 @@ +/* libguestfs - the guestfsd daemon + * Copyright (C) 2009 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include +#include +#include +#include + +#include "../src/guestfs_protocol.h" +#include "daemon.h" +#include "actions.h" + +char * +do_df () +{ + int r; + char *out, *err; + + NEED_ROOT (NULL); + + r = command (&out, &err, "df", NULL); + if (r == -1) { + reply_with_error ("df: %s", err); + free (out); + free (err); + return NULL; + } + + free (err); + + return out; /* Caller frees. */ +} + +char * +do_df_h () +{ + int r; + char *out, *err; + + NEED_ROOT (NULL); + + r = command (&out, &err, "df", "-h", NULL); + if (r == -1) { + reply_with_error ("df -h: %s", err); + free (out); + free (err); + return NULL; + } + + free (err); + + return out; /* Caller frees. */ +} diff --git a/daemon/dir.c b/daemon/dir.c index 83536ef..753323d 100644 --- a/daemon/dir.c +++ b/daemon/dir.c @@ -201,3 +201,33 @@ do_is_dir (char *path) return S_ISDIR (buf.st_mode); } + +char * +do_mkdtemp (char *template) +{ + char *r; + + NEED_ROOT (NULL); + ABS_PATH (template, NULL); + + CHROOT_IN; + r = mkdtemp (template); + CHROOT_OUT; + + if (r == NULL) { + reply_with_perror ("mkdtemp: %s", template); + return NULL; + } + + /* The caller will free template AND try to free the return value, + * so we must make a copy here. + */ + if (r == template) { + r = strdup (template); + if (r == NULL) { + reply_with_perror ("strdup"); + return NULL; + } + } + return r; +} diff --git a/daemon/du.c b/daemon/du.c new file mode 100644 index 0000000..6287a20 --- /dev/null +++ b/daemon/du.c @@ -0,0 +1,72 @@ +/* libguestfs - the guestfsd daemon + * Copyright (C) 2009 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include +#include +#include +#include +#include + +#include "../src/guestfs_protocol.h" +#include "daemon.h" +#include "actions.h" + +int64_t +do_du (char *path) +{ + int r; + int64_t rv; + char *out, *err; + char *buf; + int len; + + NEED_ROOT (-1); + ABS_PATH (path, -1); + + /* Make the path relative to /sysroot. */ + len = strlen (path) + 9; + buf = malloc (len); + if (!buf) { + reply_with_perror ("malloc"); + return -1; + } + snprintf (buf, len, "/sysroot%s", path); + + r = command (&out, &err, "du", "-s", buf, NULL); + free (buf); + if (r == -1) { + reply_with_error ("du: %s: %s", path, err); + free (out); + free (err); + return -1; + } + + free (err); + + if (sscanf (out, "%"SCNi64, &rv) != 1) { + reply_with_error ("du: %s: could not read output: %s", path, out); + free (out); + return -1; + } + + free (out); + + return rv; +} diff --git a/daemon/file.c b/daemon/file.c index 0eef0c0..3f07ffc 100644 --- a/daemon/file.c +++ b/daemon/file.c @@ -58,7 +58,11 @@ do_touch (char *path) return -1; } - close (fd); + if (close (fd) == -1) { + reply_with_perror ("close: %s", path); + return -1; + } + return 0; } diff --git a/daemon/find.c b/daemon/find.c index a873bca..7ceeafa 100644 --- a/daemon/find.c +++ b/daemon/find.c @@ -113,7 +113,11 @@ do_find (char *dir) return NULL; } } - pclose (fp); + if (pclose (fp) != 0) { + reply_with_perror ("pclose: find"); + free_stringslen (res, size); + return NULL; + } if (r == -1) { free_stringslen (res, size); diff --git a/daemon/glob.c b/daemon/glob.c new file mode 100644 index 0000000..f39832e --- /dev/null +++ b/daemon/glob.c @@ -0,0 +1,63 @@ +/* libguestfs - the guestfsd daemon + * Copyright (C) 2009 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include +#include +#include + +#include "daemon.h" +#include "actions.h" + +char ** +do_glob_expand (char *pattern) +{ + int r; + glob_t buf; + + NEED_ROOT (NULL); + ABS_PATH (pattern, NULL); /* Required so chroot can be used. */ + + /* glob(3) in glibc never calls chdir, so this seems to be safe: */ + CHROOT_IN; + r = glob (pattern, GLOB_MARK|GLOB_BRACE, NULL, &buf); + CHROOT_OUT; + + if (r == GLOB_NOMATCH) { /* Return an empty list instead of an error. */ + char **rv; + + rv = malloc (sizeof (char *) * 1); + rv[0] = NULL; + return rv; /* Caller frees. */ + } + + if (r != 0) { + if (errno != 0) + reply_with_perror ("glob: %s", pattern); + else + reply_with_error ("glob failed: %s", pattern); + return NULL; + } + + /* We take a bit of a liberty here. 'globfree' just frees the + * strings in the glob_t structure. We will pass them out directly + * and the caller will free them. + */ + return buf.gl_pathv; +} diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index 2e83b9f..e5f2cf0 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -160,6 +160,9 @@ main (int argc, char *argv[]) setenv ("SHELL", "/bin/sh", 1); setenv ("LANG", "C", 1); + /* We document that umask defaults to 022 (it should be this anyway). */ + umask (022); + /* Resolve the hostname. */ memset (&hints, 0, sizeof hints); hints.ai_socktype = SOCK_STREAM; @@ -453,7 +456,8 @@ commandrv (char **stdoutput, char **stderror, char * const* const argv) { int so_size = 0, se_size = 0; int so_fd[2], se_fd[2]; - int pid, r, quit, i; + pid_t pid; + int r, quit, i; fd_set rset, rset2; char buf[256]; char *p; @@ -589,7 +593,10 @@ commandrv (char **stdoutput, char **stderror, char * const* const argv) } /* Get the exit status of the command. */ - waitpid (pid, &r, 0); + if (waitpid (pid, &r, 0) != pid) { + perror ("waitpid"); + return -1; + } if (WIFEXITED (r)) { return WEXITSTATUS (r); @@ -707,7 +714,7 @@ device_name_translation (char *device, const char *func) return 0; } - if (errno != ENXIO) { + if (errno != ENXIO && errno != ENOENT) { error: reply_with_perror ("%s: %s", func, device); return -1; @@ -734,3 +741,16 @@ device_name_translation (char *device, const char *func) device[5] = 's'; /* Restore original device name. */ goto error; } + +/* LVM and other commands aren't synchronous, especially when udev is + * involved. eg. You can create or remove some device, but the /dev + * device node won't appear until some time later. This means that + * you get an error if you run one command followed by another. + * Use 'udevadm settle' after certain commands, but don't be too + * fussed if it fails. + */ +void +udev_settle (void) +{ + command (NULL, NULL, "/sbin/udevadm", "settle", NULL); +} diff --git a/daemon/headtail.c b/daemon/headtail.c new file mode 100644 index 0000000..b522c55 --- /dev/null +++ b/daemon/headtail.c @@ -0,0 +1,107 @@ +/* libguestfs - the guestfsd daemon + * Copyright (C) 2009 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include +#include +#include +#include + +#include "../src/guestfs_protocol.h" +#include "daemon.h" +#include "actions.h" + +static char ** +headtail (const char *prog, const char *flag, const char *n, char *path) +{ + char *buf; + char *out, *err; + int r, len; + char **lines; + + NEED_ROOT (NULL); + ABS_PATH (path, NULL); + + /* Make the path relative to /sysroot. */ + len = strlen (path) + 9; + buf = malloc (len); + if (!buf) { + reply_with_perror ("malloc"); + return NULL; + } + snprintf (buf, len, "/sysroot%s", path); + + r = command (&out, &err, prog, flag, n, buf, NULL); + free (buf); + if (r == -1) { + reply_with_error ("%s %s %s: %s", prog, flag, n, err); + free (out); + free (err); + return NULL; + } + + free (err); + +#if 0 + /* Split it at the first whitespace. */ + len = strcspn (out, " \t\n"); + out[len] = '\0'; +#endif + + lines = split_lines (out); + free (out); + if (lines == NULL) return NULL; + + return lines; +} + +char ** +do_head (char *path) +{ + return headtail ("head", "-n", "10", path); +} + +char ** +do_tail (char *path) +{ + return headtail ("tail", "-n", "10", path); +} + +char ** +do_head_n (int n, char *path) +{ + char nbuf[16]; + + snprintf (nbuf, sizeof nbuf, "%d", n); + + return headtail ("head", "-n", nbuf, path); +} + +char ** +do_tail_n (int n, char *path) +{ + char nbuf[16]; + + if (n >= 0) + snprintf (nbuf, sizeof nbuf, "%d", n); + else + snprintf (nbuf, sizeof nbuf, "+%d", -n); + + return headtail ("tail", "-n", nbuf, path); +} diff --git a/daemon/initrd.c b/daemon/initrd.c new file mode 100644 index 0000000..2d6cbdd --- /dev/null +++ b/daemon/initrd.c @@ -0,0 +1,88 @@ +/* libguestfs - the guestfsd daemon + * Copyright (C) 2009 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include +#include +#include +#include + +#include "../src/guestfs_protocol.h" +#include "daemon.h" +#include "actions.h" + +char ** +do_initrd_list (char *path) +{ + FILE *fp; + int len; + char *cmd; + char filename[PATH_MAX]; + char **filenames = NULL; + int size = 0, alloc = 0; + + NEED_ROOT (NULL); + ABS_PATH (path, NULL); + + /* "zcat /sysroot/ | cpio --quiet -it", but path must be quoted. */ + len = 64 + 2 * strlen (path); + cmd = malloc (len); + if (!cmd) { + reply_with_perror ("malloc"); + return NULL; + } + + strcpy (cmd, "zcat /sysroot"); + shell_quote (cmd+13, len-13, path); + strcat (cmd, " | cpio --quiet -it"); + + fprintf (stderr, "%s\n", cmd); + + fp = popen (cmd, "r"); + if (fp == NULL) { + reply_with_perror ("popen: %s", cmd); + free (cmd); + return NULL; + } + free (cmd); + + while (fgets (filename, sizeof filename, fp) != NULL) { + len = strlen (filename); + if (len > 0 && filename[len-1] == '\n') + filename[len-1] = '\0'; + + if (add_string (&filenames, &size, &alloc, filename) == -1) { + pclose (fp); + return NULL; + } + } + + if (add_string (&filenames, &size, &alloc, NULL) == -1) { + pclose (fp); + return NULL; + } + + if (pclose (fp) != 0) { + reply_with_perror ("pclose"); + free_strings (filenames); + return NULL; + } + + return filenames; +} diff --git a/daemon/lvm.c b/daemon/lvm.c index 143c5a8..0fba447 100644 --- a/daemon/lvm.c +++ b/daemon/lvm.c @@ -187,6 +187,9 @@ do_pvcreate (char *device) } free (err); + + udev_settle (); + return 0; } @@ -221,6 +224,9 @@ do_vgcreate (char *volgroup, char **physvols) } free (err); + + udev_settle (); + return 0; } @@ -243,6 +249,9 @@ do_lvcreate (char *logvol, char *volgroup, int mbytes) } free (err); + + udev_settle (); + return 0; } @@ -331,6 +340,8 @@ do_lvm_remove_all (void) } free_strings (xs); + udev_settle (); + /* There, that was easy, sorry about your data. */ return 0; } @@ -352,6 +363,9 @@ do_lvremove (char *device) } free (err); + + udev_settle (); + return 0; } @@ -370,6 +384,9 @@ do_vgremove (char *device) } free (err); + + udev_settle (); + return 0; } @@ -390,6 +407,9 @@ do_pvremove (char *device) } free (err); + + udev_settle (); + return 0; } @@ -442,6 +462,9 @@ do_vg_activate (int activate, char **volgroups) } free (err); + + udev_settle (); + return 0; } diff --git a/daemon/mknod.c b/daemon/mknod.c new file mode 100644 index 0000000..5af791f --- /dev/null +++ b/daemon/mknod.c @@ -0,0 +1,69 @@ +/* libguestfs - the guestfsd daemon + * Copyright (C) 2009 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "../src/guestfs_protocol.h" +#include "daemon.h" +#include "actions.h" + +int +do_mknod (int mode, int devmajor, int devminor, char *path) +{ + int r; + + NEED_ROOT (-1); + ABS_PATH (path, -1); + + CHROOT_IN; + r = mknod (path, mode, makedev (devmajor, devminor)); + CHROOT_OUT; + + if (r == -1) { + reply_with_perror ("mknod: %s", path); + return -1; + } + + return 0; +} + +int +do_mkfifo (int mode, char *path) +{ + return do_mknod (mode | S_IFIFO, 0, 0, path); +} + +int +do_mknod_b (int mode, int devmajor, int devminor, char *path) +{ + return do_mknod (mode | S_IFBLK, devmajor, devminor, path); +} + +int +do_mknod_c (int mode, int devmajor, int devminor, char *path) +{ + return do_mknod (mode | S_IFCHR, devmajor, devminor, path); +} diff --git a/daemon/mount.c b/daemon/mount.c index 4955fcf..b0cb496 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -71,6 +71,7 @@ do_mount_vfs (char *options, char *vfstype, else r = command (NULL, &error, "mount", "-o", options, device, mp, NULL); + free (mp); if (r == -1) { reply_with_error ("mount: %s on %s: %s", device, mountpoint, error); free (error); @@ -277,3 +278,47 @@ do_umount_all (void) return 0; } + +/* Mount using the loopback device. You can't use the generic + * do_mount call for this because the first parameter isn't a + * device. + */ +int +do_mount_loop (char *file, char *mountpoint) +{ + int len, r; + char *buf, *mp; + char *error; + + NEED_ROOT (-1); + ABS_PATH (file, -1); + + /* We have to prefix /sysroot on both the filename and the mountpoint. */ + len = strlen (mountpoint) + 9; + mp = malloc (len); + if (!mp) { + reply_with_perror ("malloc"); + return -1; + } + snprintf (mp, len, "/sysroot%s", mountpoint); + + len = strlen (file) + 9; + buf = malloc (len); + if (!file) { + reply_with_perror ("malloc"); + free (mp); + return -1; + } + snprintf (buf, len, "/sysroot%s", file); + + r = command (NULL, &error, "mount", "-o", "loop", buf, mp, NULL); + free (mp); + free (buf); + if (r == -1) { + reply_with_error ("mount: %s on %s: %s", file, mountpoint, error); + free (error); + return -1; + } + + return 0; +} diff --git a/daemon/proto.c b/daemon/proto.c index ffb4a4e..3ca4316 100644 --- a/daemon/proto.c +++ b/daemon/proto.c @@ -47,6 +47,8 @@ main_loop (int _sock) char lenbuf[4]; unsigned len; struct guestfs_message_header hdr; + struct timeval start_t, end_t; + int64_t start_us, end_us, elapsed_us; sock = _sock; @@ -102,6 +104,10 @@ main_loop (int _sock) } #endif + /* In verbose mode, display the time taken to run each command. */ + if (verbose) + gettimeofday (&start_t, NULL); + /* Decode the message header. */ xdrmem_create (&xdr, buf, len, XDR_DECODE); if (!xdr_guestfs_message_header (&xdr, &hdr)) { @@ -133,6 +139,21 @@ main_loop (int _sock) dispatch_incoming_message (&xdr); /* Note that dispatch_incoming_message will also send a reply. */ + /* In verbose mode, display the time taken to run each command. */ + if (verbose) { + gettimeofday (&end_t, NULL); + + start_us = (int64_t) start_t.tv_sec * 1000000 + start_t.tv_usec; + end_us = (int64_t) end_t.tv_sec * 1000000 + end_t.tv_usec; + elapsed_us = end_us - start_us; + fprintf (stderr, "proc %d (%s) took %d.%02d seconds\n", + proc_nr, + proc_nr >= 0 && proc_nr < GUESTFS_PROC_NR_PROCS + ? function_names[proc_nr] : "UNKNOWN PROCEDURE", + (int) (elapsed_us / 1000000), + (int) ((elapsed_us / 10000) % 100)); + } + cont: xdr_destroy (&xdr); free (buf); diff --git a/daemon/readdir.c b/daemon/readdir.c new file mode 100644 index 0000000..cea6fdd --- /dev/null +++ b/daemon/readdir.c @@ -0,0 +1,105 @@ +/* libguestfs - the guestfsd daemon + * Copyright (C) 2009 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include +#include +#include +#include +#include + +#include "daemon.h" +#include "actions.h" + +guestfs_int_dirent_list * +do_readdir (char *path) +{ + guestfs_int_dirent_list *ret; + guestfs_int_dirent v; + DIR *dir; + struct dirent *d; + int i; + + NEED_ROOT (NULL); + ABS_PATH (path, NULL); + + ret = malloc (sizeof *ret); + if (ret == NULL) { + reply_with_perror ("malloc"); + return NULL; + } + + ret->guestfs_int_dirent_list_len = 0; + ret->guestfs_int_dirent_list_val = NULL; + + CHROOT_IN; + dir = opendir (path); + CHROOT_OUT; + + if (dir == NULL) { + reply_with_perror ("opendir: %s", path); + free (ret); + return NULL; + } + + i = 0; + while ((d = readdir (dir)) != NULL) { + guestfs_int_dirent *p; + + p = realloc (ret->guestfs_int_dirent_list_val, + sizeof (guestfs_int_dirent) * (i+1)); + v.name = strdup (d->d_name); + if (!p || !v.name) { + reply_with_perror ("allocate"); + free (ret->guestfs_int_dirent_list_val); + free (ret); + closedir (dir); + return NULL; + } + ret->guestfs_int_dirent_list_val = p; + + v.ino = d->d_ino; + switch (d->d_type) { + case DT_BLK: v.ftyp = 'b'; break; + case DT_CHR: v.ftyp = 'c'; break; + case DT_DIR: v.ftyp = 'd'; break; + case DT_FIFO: v.ftyp = 'f'; break; + case DT_LNK: v.ftyp = 'l'; break; + case DT_REG: v.ftyp = 'r'; break; + case DT_SOCK: v.ftyp = 's'; break; + case DT_UNKNOWN: v.ftyp = 'u'; break; + default: v.ftyp = '?'; break; + } + + ret->guestfs_int_dirent_list_val[i] = v; + + i++; + } + + ret->guestfs_int_dirent_list_len = i; + + if (closedir (dir) == -1) { + reply_with_perror ("closedir"); + free (ret->guestfs_int_dirent_list_val); + free (ret); + return NULL; + } + + return ret; +} diff --git a/daemon/scrub.c b/daemon/scrub.c new file mode 100644 index 0000000..9b6d49d --- /dev/null +++ b/daemon/scrub.c @@ -0,0 +1,114 @@ +/* libguestfs - the guestfsd daemon + * Copyright (C) 2009 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include +#include +#include +#include +#include + +#include "daemon.h" +#include "actions.h" + +int +do_scrub_device (char *device) +{ + char *err; + int r; + + IS_DEVICE (device, -1); + + r = command (NULL, &err, "scrub", device, NULL); + if (r == -1) { + reply_with_error ("scrub_device: %s: %s", device, err); + free (err); + return -1; + } + + free (err); + + return 0; +} + +int +do_scrub_file (char *file) +{ + char *buf; + int len; + char *err; + int r; + + NEED_ROOT (-1); + ABS_PATH (file, -1); + + /* Make the path relative to /sysroot. */ + len = strlen (file) + 9; + buf = malloc (len); + if (!buf) { + reply_with_perror ("malloc"); + return -1; + } + snprintf (buf, len, "/sysroot%s", file); + + r = command (NULL, &err, "scrub", "-r", buf, NULL); + free (buf); + if (r == -1) { + reply_with_error ("scrub_file: %s: %s", file, err); + free (err); + return -1; + } + + free (err); + + return 0; +} + +int +do_scrub_freespace (char *dir) +{ + char *buf; + int len; + char *err; + int r; + + NEED_ROOT (-1); + ABS_PATH (dir, -1); + + /* Make the path relative to /sysroot. */ + len = strlen (dir) + 9; + buf = malloc (len); + if (!buf) { + reply_with_perror ("malloc"); + return -1; + } + snprintf (buf, len, "/sysroot%s", dir); + + r = command (NULL, &err, "scrub", "-X", buf, NULL); + free (buf); + if (r == -1) { + reply_with_error ("scrub_freespace: %s: %s", dir, err); + free (err); + return -1; + } + + free (err); + + return 0; +} diff --git a/daemon/sfdisk.c b/daemon/sfdisk.c index 95f04af..f1726fc 100644 --- a/daemon/sfdisk.c +++ b/daemon/sfdisk.c @@ -31,6 +31,7 @@ static int sfdisk (char *device, int n, int cyls, int heads, int sectors, + const char *extra_flag, char * const* const lines) { FILE *fp; @@ -40,6 +41,7 @@ sfdisk (char *device, int n, int cyls, int heads, int sectors, IS_DEVICE (device, -1); strcpy (buf, "/sbin/sfdisk"); + if (n > 0) sprintf (buf + strlen (buf), " -N %d", n); if (cyls) @@ -48,6 +50,9 @@ sfdisk (char *device, int n, int cyls, int heads, int sectors, sprintf (buf + strlen (buf), " -H %d", heads); if (sectors) sprintf (buf + strlen (buf), " -S %d", sectors); + if (extra_flag) + sprintf (buf + strlen (buf), " %s", extra_flag); + /* Safe because of IS_DEVICE above: */ sprintf (buf + strlen (buf), " %s", device); @@ -63,17 +68,18 @@ sfdisk (char *device, int n, int cyls, int heads, int sectors, for (i = 0; lines[i] != NULL; ++i) { if (fprintf (fp, "%s\n", lines[i]) < 0) { reply_with_perror (buf); - fclose (fp); + pclose (fp); return -1; } } - if (fclose (fp) == EOF) { - reply_with_perror (buf); - fclose (fp); + if (pclose (fp) != 0) { + reply_with_error ("%s: external command failed", buf); return -1; } + udev_settle (); + return 0; } @@ -81,7 +87,7 @@ int do_sfdisk (char *device, int cyls, int heads, int sectors, char **lines) { - return sfdisk (device, 0, cyls, heads, sectors, lines); + return sfdisk (device, 0, cyls, heads, sectors, NULL, lines); } int @@ -90,7 +96,13 @@ do_sfdisk_N (char *device, int n, int cyls, int heads, int sectors, { const char *lines[2] = { line, NULL }; - return sfdisk (device, n, cyls, heads, sectors, lines); + return sfdisk (device, n, cyls, heads, sectors, NULL, lines); +} + +int +do_sfdiskM (char *device, char **lines) +{ + return sfdisk (device, 0, 0, 0, 0, "-uM", lines); } static char * @@ -111,6 +123,8 @@ sfdisk_flag (char *device, const char *flag) free (err); + udev_settle (); + return out; /* caller frees */ } diff --git a/daemon/stubs.c b/daemon/stubs.c deleted file mode 100644 index 7842640..0000000 --- a/daemon/stubs.c +++ /dev/null @@ -1,4040 +0,0 @@ -/* libguestfs generated file - * WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'. - * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST. - * - * Copyright (C) 2009 Red Hat Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "daemon.h" -#include "../src/guestfs_protocol.h" -#include "actions.h" - -static void mount_stub (XDR *xdr_in) -{ - int r; - struct guestfs_mount_args args; - char *device; - char *mountpoint; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_mount_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "mount"); - return; - } - device = args.device; - mountpoint = args.mountpoint; - - r = do_mount (device, mountpoint); - if (r == -1) - /* do_mount has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_mount_args, (char *) &args); -} - -static void sync_stub (XDR *xdr_in) -{ - int r; - - r = do_sync (); - if (r == -1) - /* do_sync has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: ; -} - -static void touch_stub (XDR *xdr_in) -{ - int r; - struct guestfs_touch_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_touch_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "touch"); - return; - } - path = args.path; - - r = do_touch (path); - if (r == -1) - /* do_touch has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_touch_args, (char *) &args); -} - -static void cat_stub (XDR *xdr_in) -{ - char *r; - struct guestfs_cat_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_cat_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "cat"); - return; - } - path = args.path; - - r = do_cat (path); - if (r == NULL) - /* do_cat has already called reply_with_error */ - goto done; - - struct guestfs_cat_ret ret; - ret.content = r; - reply ((xdrproc_t) &xdr_guestfs_cat_ret, (char *) &ret); - free (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_cat_args, (char *) &args); -} - -static void ll_stub (XDR *xdr_in) -{ - char *r; - struct guestfs_ll_args args; - char *directory; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_ll_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "ll"); - return; - } - directory = args.directory; - - r = do_ll (directory); - if (r == NULL) - /* do_ll has already called reply_with_error */ - goto done; - - struct guestfs_ll_ret ret; - ret.listing = r; - reply ((xdrproc_t) &xdr_guestfs_ll_ret, (char *) &ret); - free (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_ll_args, (char *) &args); -} - -static void ls_stub (XDR *xdr_in) -{ - char **r; - struct guestfs_ls_args args; - char *directory; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_ls_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "ls"); - return; - } - directory = args.directory; - - r = do_ls (directory); - if (r == NULL) - /* do_ls has already called reply_with_error */ - goto done; - - struct guestfs_ls_ret ret; - ret.listing.listing_len = count_strings (r); - ret.listing.listing_val = r; - reply ((xdrproc_t) &xdr_guestfs_ls_ret, (char *) &ret); - free_strings (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_ls_args, (char *) &args); -} - -static void list_devices_stub (XDR *xdr_in) -{ - char **r; - - r = do_list_devices (); - if (r == NULL) - /* do_list_devices has already called reply_with_error */ - goto done; - - struct guestfs_list_devices_ret ret; - ret.devices.devices_len = count_strings (r); - ret.devices.devices_val = r; - reply ((xdrproc_t) &xdr_guestfs_list_devices_ret, (char *) &ret); - free_strings (r); -done: ; -} - -static void list_partitions_stub (XDR *xdr_in) -{ - char **r; - - r = do_list_partitions (); - if (r == NULL) - /* do_list_partitions has already called reply_with_error */ - goto done; - - struct guestfs_list_partitions_ret ret; - ret.partitions.partitions_len = count_strings (r); - ret.partitions.partitions_val = r; - reply ((xdrproc_t) &xdr_guestfs_list_partitions_ret, (char *) &ret); - free_strings (r); -done: ; -} - -static void pvs_stub (XDR *xdr_in) -{ - char **r; - - r = do_pvs (); - if (r == NULL) - /* do_pvs has already called reply_with_error */ - goto done; - - struct guestfs_pvs_ret ret; - ret.physvols.physvols_len = count_strings (r); - ret.physvols.physvols_val = r; - reply ((xdrproc_t) &xdr_guestfs_pvs_ret, (char *) &ret); - free_strings (r); -done: ; -} - -static void vgs_stub (XDR *xdr_in) -{ - char **r; - - r = do_vgs (); - if (r == NULL) - /* do_vgs has already called reply_with_error */ - goto done; - - struct guestfs_vgs_ret ret; - ret.volgroups.volgroups_len = count_strings (r); - ret.volgroups.volgroups_val = r; - reply ((xdrproc_t) &xdr_guestfs_vgs_ret, (char *) &ret); - free_strings (r); -done: ; -} - -static void lvs_stub (XDR *xdr_in) -{ - char **r; - - r = do_lvs (); - if (r == NULL) - /* do_lvs has already called reply_with_error */ - goto done; - - struct guestfs_lvs_ret ret; - ret.logvols.logvols_len = count_strings (r); - ret.logvols.logvols_val = r; - reply ((xdrproc_t) &xdr_guestfs_lvs_ret, (char *) &ret); - free_strings (r); -done: ; -} - -static void pvs_full_stub (XDR *xdr_in) -{ - guestfs_lvm_int_pv_list *r; - - r = do_pvs_full (); - if (r == NULL) - /* do_pvs_full has already called reply_with_error */ - goto done; - - struct guestfs_pvs_full_ret ret; - ret.physvols = *r; - reply ((xdrproc_t) xdr_guestfs_pvs_full_ret, (char *) &ret); - xdr_free ((xdrproc_t) xdr_guestfs_pvs_full_ret, (char *) &ret); -done: ; -} - -static void vgs_full_stub (XDR *xdr_in) -{ - guestfs_lvm_int_vg_list *r; - - r = do_vgs_full (); - if (r == NULL) - /* do_vgs_full has already called reply_with_error */ - goto done; - - struct guestfs_vgs_full_ret ret; - ret.volgroups = *r; - reply ((xdrproc_t) xdr_guestfs_vgs_full_ret, (char *) &ret); - xdr_free ((xdrproc_t) xdr_guestfs_vgs_full_ret, (char *) &ret); -done: ; -} - -static void lvs_full_stub (XDR *xdr_in) -{ - guestfs_lvm_int_lv_list *r; - - r = do_lvs_full (); - if (r == NULL) - /* do_lvs_full has already called reply_with_error */ - goto done; - - struct guestfs_lvs_full_ret ret; - ret.logvols = *r; - reply ((xdrproc_t) xdr_guestfs_lvs_full_ret, (char *) &ret); - xdr_free ((xdrproc_t) xdr_guestfs_lvs_full_ret, (char *) &ret); -done: ; -} - -static void read_lines_stub (XDR *xdr_in) -{ - char **r; - struct guestfs_read_lines_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_read_lines_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "read_lines"); - return; - } - path = args.path; - - r = do_read_lines (path); - if (r == NULL) - /* do_read_lines has already called reply_with_error */ - goto done; - - struct guestfs_read_lines_ret ret; - ret.lines.lines_len = count_strings (r); - ret.lines.lines_val = r; - reply ((xdrproc_t) &xdr_guestfs_read_lines_ret, (char *) &ret); - free_strings (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_read_lines_args, (char *) &args); -} - -static void aug_init_stub (XDR *xdr_in) -{ - int r; - struct guestfs_aug_init_args args; - char *root; - int flags; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_aug_init_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "aug_init"); - return; - } - root = args.root; - flags = args.flags; - - r = do_aug_init (root, flags); - if (r == -1) - /* do_aug_init has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_aug_init_args, (char *) &args); -} - -static void aug_close_stub (XDR *xdr_in) -{ - int r; - - r = do_aug_close (); - if (r == -1) - /* do_aug_close has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: ; -} - -static void aug_defvar_stub (XDR *xdr_in) -{ - int r; - struct guestfs_aug_defvar_args args; - char *name; - char *expr; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_aug_defvar_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "aug_defvar"); - return; - } - name = args.name; - expr = args.expr ? *args.expr : NULL; - - r = do_aug_defvar (name, expr); - if (r == -1) - /* do_aug_defvar has already called reply_with_error */ - goto done; - - struct guestfs_aug_defvar_ret ret; - ret.nrnodes = r; - reply ((xdrproc_t) &xdr_guestfs_aug_defvar_ret, (char *) &ret); -done: - xdr_free ((xdrproc_t) xdr_guestfs_aug_defvar_args, (char *) &args); -} - -static void aug_defnode_stub (XDR *xdr_in) -{ - guestfs_aug_defnode_ret *r; - struct guestfs_aug_defnode_args args; - char *name; - char *expr; - char *val; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_aug_defnode_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "aug_defnode"); - return; - } - name = args.name; - expr = args.expr; - val = args.val; - - r = do_aug_defnode (name, expr, val); - if (r == NULL) - /* do_aug_defnode has already called reply_with_error */ - goto done; - - reply ((xdrproc_t) xdr_guestfs_aug_defnode_ret, (char *) r); - xdr_free ((xdrproc_t) xdr_guestfs_aug_defnode_ret, (char *) r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_aug_defnode_args, (char *) &args); -} - -static void aug_get_stub (XDR *xdr_in) -{ - char *r; - struct guestfs_aug_get_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_aug_get_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "aug_get"); - return; - } - path = args.path; - - r = do_aug_get (path); - if (r == NULL) - /* do_aug_get has already called reply_with_error */ - goto done; - - struct guestfs_aug_get_ret ret; - ret.val = r; - reply ((xdrproc_t) &xdr_guestfs_aug_get_ret, (char *) &ret); - free (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_aug_get_args, (char *) &args); -} - -static void aug_set_stub (XDR *xdr_in) -{ - int r; - struct guestfs_aug_set_args args; - char *path; - char *val; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_aug_set_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "aug_set"); - return; - } - path = args.path; - val = args.val; - - r = do_aug_set (path, val); - if (r == -1) - /* do_aug_set has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_aug_set_args, (char *) &args); -} - -static void aug_insert_stub (XDR *xdr_in) -{ - int r; - struct guestfs_aug_insert_args args; - char *path; - char *label; - int before; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_aug_insert_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "aug_insert"); - return; - } - path = args.path; - label = args.label; - before = args.before; - - r = do_aug_insert (path, label, before); - if (r == -1) - /* do_aug_insert has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_aug_insert_args, (char *) &args); -} - -static void aug_rm_stub (XDR *xdr_in) -{ - int r; - struct guestfs_aug_rm_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_aug_rm_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "aug_rm"); - return; - } - path = args.path; - - r = do_aug_rm (path); - if (r == -1) - /* do_aug_rm has already called reply_with_error */ - goto done; - - struct guestfs_aug_rm_ret ret; - ret.nrnodes = r; - reply ((xdrproc_t) &xdr_guestfs_aug_rm_ret, (char *) &ret); -done: - xdr_free ((xdrproc_t) xdr_guestfs_aug_rm_args, (char *) &args); -} - -static void aug_mv_stub (XDR *xdr_in) -{ - int r; - struct guestfs_aug_mv_args args; - char *src; - char *dest; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_aug_mv_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "aug_mv"); - return; - } - src = args.src; - dest = args.dest; - - r = do_aug_mv (src, dest); - if (r == -1) - /* do_aug_mv has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_aug_mv_args, (char *) &args); -} - -static void aug_match_stub (XDR *xdr_in) -{ - char **r; - struct guestfs_aug_match_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_aug_match_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "aug_match"); - return; - } - path = args.path; - - r = do_aug_match (path); - if (r == NULL) - /* do_aug_match has already called reply_with_error */ - goto done; - - struct guestfs_aug_match_ret ret; - ret.matches.matches_len = count_strings (r); - ret.matches.matches_val = r; - reply ((xdrproc_t) &xdr_guestfs_aug_match_ret, (char *) &ret); - free_strings (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_aug_match_args, (char *) &args); -} - -static void aug_save_stub (XDR *xdr_in) -{ - int r; - - r = do_aug_save (); - if (r == -1) - /* do_aug_save has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: ; -} - -static void aug_load_stub (XDR *xdr_in) -{ - int r; - - r = do_aug_load (); - if (r == -1) - /* do_aug_load has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: ; -} - -static void aug_ls_stub (XDR *xdr_in) -{ - char **r; - struct guestfs_aug_ls_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_aug_ls_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "aug_ls"); - return; - } - path = args.path; - - r = do_aug_ls (path); - if (r == NULL) - /* do_aug_ls has already called reply_with_error */ - goto done; - - struct guestfs_aug_ls_ret ret; - ret.matches.matches_len = count_strings (r); - ret.matches.matches_val = r; - reply ((xdrproc_t) &xdr_guestfs_aug_ls_ret, (char *) &ret); - free_strings (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_aug_ls_args, (char *) &args); -} - -static void rm_stub (XDR *xdr_in) -{ - int r; - struct guestfs_rm_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_rm_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "rm"); - return; - } - path = args.path; - - r = do_rm (path); - if (r == -1) - /* do_rm has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_rm_args, (char *) &args); -} - -static void rmdir_stub (XDR *xdr_in) -{ - int r; - struct guestfs_rmdir_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_rmdir_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "rmdir"); - return; - } - path = args.path; - - r = do_rmdir (path); - if (r == -1) - /* do_rmdir has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_rmdir_args, (char *) &args); -} - -static void rm_rf_stub (XDR *xdr_in) -{ - int r; - struct guestfs_rm_rf_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_rm_rf_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "rm_rf"); - return; - } - path = args.path; - - r = do_rm_rf (path); - if (r == -1) - /* do_rm_rf has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_rm_rf_args, (char *) &args); -} - -static void mkdir_stub (XDR *xdr_in) -{ - int r; - struct guestfs_mkdir_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_mkdir_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "mkdir"); - return; - } - path = args.path; - - r = do_mkdir (path); - if (r == -1) - /* do_mkdir has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_mkdir_args, (char *) &args); -} - -static void mkdir_p_stub (XDR *xdr_in) -{ - int r; - struct guestfs_mkdir_p_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_mkdir_p_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "mkdir_p"); - return; - } - path = args.path; - - r = do_mkdir_p (path); - if (r == -1) - /* do_mkdir_p has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_mkdir_p_args, (char *) &args); -} - -static void chmod_stub (XDR *xdr_in) -{ - int r; - struct guestfs_chmod_args args; - int mode; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_chmod_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "chmod"); - return; - } - mode = args.mode; - path = args.path; - - r = do_chmod (mode, path); - if (r == -1) - /* do_chmod has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_chmod_args, (char *) &args); -} - -static void chown_stub (XDR *xdr_in) -{ - int r; - struct guestfs_chown_args args; - int owner; - int group; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_chown_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "chown"); - return; - } - owner = args.owner; - group = args.group; - path = args.path; - - r = do_chown (owner, group, path); - if (r == -1) - /* do_chown has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_chown_args, (char *) &args); -} - -static void exists_stub (XDR *xdr_in) -{ - int r; - struct guestfs_exists_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_exists_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "exists"); - return; - } - path = args.path; - - r = do_exists (path); - if (r == -1) - /* do_exists has already called reply_with_error */ - goto done; - - struct guestfs_exists_ret ret; - ret.existsflag = r; - reply ((xdrproc_t) &xdr_guestfs_exists_ret, (char *) &ret); -done: - xdr_free ((xdrproc_t) xdr_guestfs_exists_args, (char *) &args); -} - -static void is_file_stub (XDR *xdr_in) -{ - int r; - struct guestfs_is_file_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_is_file_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "is_file"); - return; - } - path = args.path; - - r = do_is_file (path); - if (r == -1) - /* do_is_file has already called reply_with_error */ - goto done; - - struct guestfs_is_file_ret ret; - ret.fileflag = r; - reply ((xdrproc_t) &xdr_guestfs_is_file_ret, (char *) &ret); -done: - xdr_free ((xdrproc_t) xdr_guestfs_is_file_args, (char *) &args); -} - -static void is_dir_stub (XDR *xdr_in) -{ - int r; - struct guestfs_is_dir_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_is_dir_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "is_dir"); - return; - } - path = args.path; - - r = do_is_dir (path); - if (r == -1) - /* do_is_dir has already called reply_with_error */ - goto done; - - struct guestfs_is_dir_ret ret; - ret.dirflag = r; - reply ((xdrproc_t) &xdr_guestfs_is_dir_ret, (char *) &ret); -done: - xdr_free ((xdrproc_t) xdr_guestfs_is_dir_args, (char *) &args); -} - -static void pvcreate_stub (XDR *xdr_in) -{ - int r; - struct guestfs_pvcreate_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_pvcreate_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "pvcreate"); - return; - } - device = args.device; - - r = do_pvcreate (device); - if (r == -1) - /* do_pvcreate has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_pvcreate_args, (char *) &args); -} - -static void vgcreate_stub (XDR *xdr_in) -{ - int r; - struct guestfs_vgcreate_args args; - char *volgroup; - char **physvols; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_vgcreate_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "vgcreate"); - return; - } - volgroup = args.volgroup; - physvols = realloc (args.physvols.physvols_val, - sizeof (char *) * (args.physvols.physvols_len+1)); - if (physvols == NULL) { - reply_with_perror ("realloc"); - goto done; - } - physvols[args.physvols.physvols_len] = NULL; - args.physvols.physvols_val = physvols; - - r = do_vgcreate (volgroup, physvols); - if (r == -1) - /* do_vgcreate has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_vgcreate_args, (char *) &args); -} - -static void lvcreate_stub (XDR *xdr_in) -{ - int r; - struct guestfs_lvcreate_args args; - char *logvol; - char *volgroup; - int mbytes; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_lvcreate_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "lvcreate"); - return; - } - logvol = args.logvol; - volgroup = args.volgroup; - mbytes = args.mbytes; - - r = do_lvcreate (logvol, volgroup, mbytes); - if (r == -1) - /* do_lvcreate has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_lvcreate_args, (char *) &args); -} - -static void mkfs_stub (XDR *xdr_in) -{ - int r; - struct guestfs_mkfs_args args; - char *fstype; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_mkfs_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "mkfs"); - return; - } - fstype = args.fstype; - device = args.device; - - r = do_mkfs (fstype, device); - if (r == -1) - /* do_mkfs has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_mkfs_args, (char *) &args); -} - -static void sfdisk_stub (XDR *xdr_in) -{ - int r; - struct guestfs_sfdisk_args args; - char *device; - int cyls; - int heads; - int sectors; - char **lines; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_sfdisk_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "sfdisk"); - return; - } - device = args.device; - cyls = args.cyls; - heads = args.heads; - sectors = args.sectors; - lines = realloc (args.lines.lines_val, - sizeof (char *) * (args.lines.lines_len+1)); - if (lines == NULL) { - reply_with_perror ("realloc"); - goto done; - } - lines[args.lines.lines_len] = NULL; - args.lines.lines_val = lines; - - r = do_sfdisk (device, cyls, heads, sectors, lines); - if (r == -1) - /* do_sfdisk has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_sfdisk_args, (char *) &args); -} - -static void write_file_stub (XDR *xdr_in) -{ - int r; - struct guestfs_write_file_args args; - char *path; - char *content; - int size; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_write_file_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "write_file"); - return; - } - path = args.path; - content = args.content; - size = args.size; - - r = do_write_file (path, content, size); - if (r == -1) - /* do_write_file has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_write_file_args, (char *) &args); -} - -static void umount_stub (XDR *xdr_in) -{ - int r; - struct guestfs_umount_args args; - char *pathordevice; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_umount_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "umount"); - return; - } - pathordevice = args.pathordevice; - - r = do_umount (pathordevice); - if (r == -1) - /* do_umount has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_umount_args, (char *) &args); -} - -static void mounts_stub (XDR *xdr_in) -{ - char **r; - - r = do_mounts (); - if (r == NULL) - /* do_mounts has already called reply_with_error */ - goto done; - - struct guestfs_mounts_ret ret; - ret.devices.devices_len = count_strings (r); - ret.devices.devices_val = r; - reply ((xdrproc_t) &xdr_guestfs_mounts_ret, (char *) &ret); - free_strings (r); -done: ; -} - -static void umount_all_stub (XDR *xdr_in) -{ - int r; - - r = do_umount_all (); - if (r == -1) - /* do_umount_all has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: ; -} - -static void lvm_remove_all_stub (XDR *xdr_in) -{ - int r; - - r = do_lvm_remove_all (); - if (r == -1) - /* do_lvm_remove_all has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: ; -} - -static void file_stub (XDR *xdr_in) -{ - char *r; - struct guestfs_file_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_file_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "file"); - return; - } - path = args.path; - - r = do_file (path); - if (r == NULL) - /* do_file has already called reply_with_error */ - goto done; - - struct guestfs_file_ret ret; - ret.description = r; - reply ((xdrproc_t) &xdr_guestfs_file_ret, (char *) &ret); - free (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_file_args, (char *) &args); -} - -static void command_stub (XDR *xdr_in) -{ - char *r; - struct guestfs_command_args args; - char **arguments; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_command_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "command"); - return; - } - arguments = realloc (args.arguments.arguments_val, - sizeof (char *) * (args.arguments.arguments_len+1)); - if (arguments == NULL) { - reply_with_perror ("realloc"); - goto done; - } - arguments[args.arguments.arguments_len] = NULL; - args.arguments.arguments_val = arguments; - - r = do_command (arguments); - if (r == NULL) - /* do_command has already called reply_with_error */ - goto done; - - struct guestfs_command_ret ret; - ret.output = r; - reply ((xdrproc_t) &xdr_guestfs_command_ret, (char *) &ret); - free (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_command_args, (char *) &args); -} - -static void command_lines_stub (XDR *xdr_in) -{ - char **r; - struct guestfs_command_lines_args args; - char **arguments; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_command_lines_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "command_lines"); - return; - } - arguments = realloc (args.arguments.arguments_val, - sizeof (char *) * (args.arguments.arguments_len+1)); - if (arguments == NULL) { - reply_with_perror ("realloc"); - goto done; - } - arguments[args.arguments.arguments_len] = NULL; - args.arguments.arguments_val = arguments; - - r = do_command_lines (arguments); - if (r == NULL) - /* do_command_lines has already called reply_with_error */ - goto done; - - struct guestfs_command_lines_ret ret; - ret.lines.lines_len = count_strings (r); - ret.lines.lines_val = r; - reply ((xdrproc_t) &xdr_guestfs_command_lines_ret, (char *) &ret); - free_strings (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_command_lines_args, (char *) &args); -} - -static void stat_stub (XDR *xdr_in) -{ - guestfs_int_stat *r; - struct guestfs_stat_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_stat_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "stat"); - return; - } - path = args.path; - - r = do_stat (path); - if (r == NULL) - /* do_stat has already called reply_with_error */ - goto done; - - struct guestfs_stat_ret ret; - ret.statbuf = *r; - reply ((xdrproc_t) xdr_guestfs_stat_ret, (char *) &ret); - xdr_free ((xdrproc_t) xdr_guestfs_stat_ret, (char *) &ret); -done: - xdr_free ((xdrproc_t) xdr_guestfs_stat_args, (char *) &args); -} - -static void lstat_stub (XDR *xdr_in) -{ - guestfs_int_stat *r; - struct guestfs_lstat_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_lstat_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "lstat"); - return; - } - path = args.path; - - r = do_lstat (path); - if (r == NULL) - /* do_lstat has already called reply_with_error */ - goto done; - - struct guestfs_lstat_ret ret; - ret.statbuf = *r; - reply ((xdrproc_t) xdr_guestfs_lstat_ret, (char *) &ret); - xdr_free ((xdrproc_t) xdr_guestfs_lstat_ret, (char *) &ret); -done: - xdr_free ((xdrproc_t) xdr_guestfs_lstat_args, (char *) &args); -} - -static void statvfs_stub (XDR *xdr_in) -{ - guestfs_int_statvfs *r; - struct guestfs_statvfs_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_statvfs_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "statvfs"); - return; - } - path = args.path; - - r = do_statvfs (path); - if (r == NULL) - /* do_statvfs has already called reply_with_error */ - goto done; - - struct guestfs_statvfs_ret ret; - ret.statbuf = *r; - reply ((xdrproc_t) xdr_guestfs_statvfs_ret, (char *) &ret); - xdr_free ((xdrproc_t) xdr_guestfs_statvfs_ret, (char *) &ret); -done: - xdr_free ((xdrproc_t) xdr_guestfs_statvfs_args, (char *) &args); -} - -static void tune2fs_l_stub (XDR *xdr_in) -{ - char **r; - struct guestfs_tune2fs_l_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_tune2fs_l_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "tune2fs_l"); - return; - } - device = args.device; - - r = do_tune2fs_l (device); - if (r == NULL) - /* do_tune2fs_l has already called reply_with_error */ - goto done; - - struct guestfs_tune2fs_l_ret ret; - ret.superblock.superblock_len = count_strings (r); - ret.superblock.superblock_val = r; - reply ((xdrproc_t) &xdr_guestfs_tune2fs_l_ret, (char *) &ret); - free_strings (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_tune2fs_l_args, (char *) &args); -} - -static void blockdev_setro_stub (XDR *xdr_in) -{ - int r; - struct guestfs_blockdev_setro_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_blockdev_setro_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "blockdev_setro"); - return; - } - device = args.device; - - r = do_blockdev_setro (device); - if (r == -1) - /* do_blockdev_setro has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_blockdev_setro_args, (char *) &args); -} - -static void blockdev_setrw_stub (XDR *xdr_in) -{ - int r; - struct guestfs_blockdev_setrw_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_blockdev_setrw_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "blockdev_setrw"); - return; - } - device = args.device; - - r = do_blockdev_setrw (device); - if (r == -1) - /* do_blockdev_setrw has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_blockdev_setrw_args, (char *) &args); -} - -static void blockdev_getro_stub (XDR *xdr_in) -{ - int r; - struct guestfs_blockdev_getro_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_blockdev_getro_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "blockdev_getro"); - return; - } - device = args.device; - - r = do_blockdev_getro (device); - if (r == -1) - /* do_blockdev_getro has already called reply_with_error */ - goto done; - - struct guestfs_blockdev_getro_ret ret; - ret.ro = r; - reply ((xdrproc_t) &xdr_guestfs_blockdev_getro_ret, (char *) &ret); -done: - xdr_free ((xdrproc_t) xdr_guestfs_blockdev_getro_args, (char *) &args); -} - -static void blockdev_getss_stub (XDR *xdr_in) -{ - int r; - struct guestfs_blockdev_getss_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_blockdev_getss_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "blockdev_getss"); - return; - } - device = args.device; - - r = do_blockdev_getss (device); - if (r == -1) - /* do_blockdev_getss has already called reply_with_error */ - goto done; - - struct guestfs_blockdev_getss_ret ret; - ret.sectorsize = r; - reply ((xdrproc_t) &xdr_guestfs_blockdev_getss_ret, (char *) &ret); -done: - xdr_free ((xdrproc_t) xdr_guestfs_blockdev_getss_args, (char *) &args); -} - -static void blockdev_getbsz_stub (XDR *xdr_in) -{ - int r; - struct guestfs_blockdev_getbsz_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_blockdev_getbsz_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "blockdev_getbsz"); - return; - } - device = args.device; - - r = do_blockdev_getbsz (device); - if (r == -1) - /* do_blockdev_getbsz has already called reply_with_error */ - goto done; - - struct guestfs_blockdev_getbsz_ret ret; - ret.blocksize = r; - reply ((xdrproc_t) &xdr_guestfs_blockdev_getbsz_ret, (char *) &ret); -done: - xdr_free ((xdrproc_t) xdr_guestfs_blockdev_getbsz_args, (char *) &args); -} - -static void blockdev_setbsz_stub (XDR *xdr_in) -{ - int r; - struct guestfs_blockdev_setbsz_args args; - char *device; - int blocksize; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_blockdev_setbsz_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "blockdev_setbsz"); - return; - } - device = args.device; - blocksize = args.blocksize; - - r = do_blockdev_setbsz (device, blocksize); - if (r == -1) - /* do_blockdev_setbsz has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_blockdev_setbsz_args, (char *) &args); -} - -static void blockdev_getsz_stub (XDR *xdr_in) -{ - int64_t r; - struct guestfs_blockdev_getsz_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_blockdev_getsz_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "blockdev_getsz"); - return; - } - device = args.device; - - r = do_blockdev_getsz (device); - if (r == -1) - /* do_blockdev_getsz has already called reply_with_error */ - goto done; - - struct guestfs_blockdev_getsz_ret ret; - ret.sizeinsectors = r; - reply ((xdrproc_t) &xdr_guestfs_blockdev_getsz_ret, (char *) &ret); -done: - xdr_free ((xdrproc_t) xdr_guestfs_blockdev_getsz_args, (char *) &args); -} - -static void blockdev_getsize64_stub (XDR *xdr_in) -{ - int64_t r; - struct guestfs_blockdev_getsize64_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_blockdev_getsize64_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "blockdev_getsize64"); - return; - } - device = args.device; - - r = do_blockdev_getsize64 (device); - if (r == -1) - /* do_blockdev_getsize64 has already called reply_with_error */ - goto done; - - struct guestfs_blockdev_getsize64_ret ret; - ret.sizeinbytes = r; - reply ((xdrproc_t) &xdr_guestfs_blockdev_getsize64_ret, (char *) &ret); -done: - xdr_free ((xdrproc_t) xdr_guestfs_blockdev_getsize64_args, (char *) &args); -} - -static void blockdev_flushbufs_stub (XDR *xdr_in) -{ - int r; - struct guestfs_blockdev_flushbufs_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_blockdev_flushbufs_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "blockdev_flushbufs"); - return; - } - device = args.device; - - r = do_blockdev_flushbufs (device); - if (r == -1) - /* do_blockdev_flushbufs has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_blockdev_flushbufs_args, (char *) &args); -} - -static void blockdev_rereadpt_stub (XDR *xdr_in) -{ - int r; - struct guestfs_blockdev_rereadpt_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_blockdev_rereadpt_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "blockdev_rereadpt"); - return; - } - device = args.device; - - r = do_blockdev_rereadpt (device); - if (r == -1) - /* do_blockdev_rereadpt has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_blockdev_rereadpt_args, (char *) &args); -} - -static void upload_stub (XDR *xdr_in) -{ - int r; - struct guestfs_upload_args args; - char *remotefilename; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_upload_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "upload"); - return; - } - remotefilename = args.remotefilename; - - r = do_upload (remotefilename); - if (r == -1) - /* do_upload has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_upload_args, (char *) &args); -} - -static void download_stub (XDR *xdr_in) -{ - int r; - struct guestfs_download_args args; - char *remotefilename; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_download_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "download"); - return; - } - remotefilename = args.remotefilename; - - r = do_download (remotefilename); - if (r == -1) - /* do_download has already called reply_with_error */ - goto done; - - /* do_download has already sent a reply */ -done: - xdr_free ((xdrproc_t) xdr_guestfs_download_args, (char *) &args); -} - -static void checksum_stub (XDR *xdr_in) -{ - char *r; - struct guestfs_checksum_args args; - char *csumtype; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_checksum_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "checksum"); - return; - } - csumtype = args.csumtype; - path = args.path; - - r = do_checksum (csumtype, path); - if (r == NULL) - /* do_checksum has already called reply_with_error */ - goto done; - - struct guestfs_checksum_ret ret; - ret.checksum = r; - reply ((xdrproc_t) &xdr_guestfs_checksum_ret, (char *) &ret); - free (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_checksum_args, (char *) &args); -} - -static void tar_in_stub (XDR *xdr_in) -{ - int r; - struct guestfs_tar_in_args args; - char *directory; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_tar_in_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "tar_in"); - return; - } - directory = args.directory; - - r = do_tar_in (directory); - if (r == -1) - /* do_tar_in has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_tar_in_args, (char *) &args); -} - -static void tar_out_stub (XDR *xdr_in) -{ - int r; - struct guestfs_tar_out_args args; - char *directory; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_tar_out_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "tar_out"); - return; - } - directory = args.directory; - - r = do_tar_out (directory); - if (r == -1) - /* do_tar_out has already called reply_with_error */ - goto done; - - /* do_tar_out has already sent a reply */ -done: - xdr_free ((xdrproc_t) xdr_guestfs_tar_out_args, (char *) &args); -} - -static void tgz_in_stub (XDR *xdr_in) -{ - int r; - struct guestfs_tgz_in_args args; - char *directory; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_tgz_in_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "tgz_in"); - return; - } - directory = args.directory; - - r = do_tgz_in (directory); - if (r == -1) - /* do_tgz_in has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_tgz_in_args, (char *) &args); -} - -static void tgz_out_stub (XDR *xdr_in) -{ - int r; - struct guestfs_tgz_out_args args; - char *directory; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_tgz_out_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "tgz_out"); - return; - } - directory = args.directory; - - r = do_tgz_out (directory); - if (r == -1) - /* do_tgz_out has already called reply_with_error */ - goto done; - - /* do_tgz_out has already sent a reply */ -done: - xdr_free ((xdrproc_t) xdr_guestfs_tgz_out_args, (char *) &args); -} - -static void mount_ro_stub (XDR *xdr_in) -{ - int r; - struct guestfs_mount_ro_args args; - char *device; - char *mountpoint; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_mount_ro_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "mount_ro"); - return; - } - device = args.device; - mountpoint = args.mountpoint; - - r = do_mount_ro (device, mountpoint); - if (r == -1) - /* do_mount_ro has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_mount_ro_args, (char *) &args); -} - -static void mount_options_stub (XDR *xdr_in) -{ - int r; - struct guestfs_mount_options_args args; - char *options; - char *device; - char *mountpoint; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_mount_options_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "mount_options"); - return; - } - options = args.options; - device = args.device; - mountpoint = args.mountpoint; - - r = do_mount_options (options, device, mountpoint); - if (r == -1) - /* do_mount_options has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_mount_options_args, (char *) &args); -} - -static void mount_vfs_stub (XDR *xdr_in) -{ - int r; - struct guestfs_mount_vfs_args args; - char *options; - char *vfstype; - char *device; - char *mountpoint; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_mount_vfs_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "mount_vfs"); - return; - } - options = args.options; - vfstype = args.vfstype; - device = args.device; - mountpoint = args.mountpoint; - - r = do_mount_vfs (options, vfstype, device, mountpoint); - if (r == -1) - /* do_mount_vfs has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_mount_vfs_args, (char *) &args); -} - -static void debug_stub (XDR *xdr_in) -{ - char *r; - struct guestfs_debug_args args; - char *subcmd; - char **extraargs; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_debug_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "debug"); - return; - } - subcmd = args.subcmd; - extraargs = realloc (args.extraargs.extraargs_val, - sizeof (char *) * (args.extraargs.extraargs_len+1)); - if (extraargs == NULL) { - reply_with_perror ("realloc"); - goto done; - } - extraargs[args.extraargs.extraargs_len] = NULL; - args.extraargs.extraargs_val = extraargs; - - r = do_debug (subcmd, extraargs); - if (r == NULL) - /* do_debug has already called reply_with_error */ - goto done; - - struct guestfs_debug_ret ret; - ret.result = r; - reply ((xdrproc_t) &xdr_guestfs_debug_ret, (char *) &ret); - free (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_debug_args, (char *) &args); -} - -static void lvremove_stub (XDR *xdr_in) -{ - int r; - struct guestfs_lvremove_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_lvremove_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "lvremove"); - return; - } - device = args.device; - - r = do_lvremove (device); - if (r == -1) - /* do_lvremove has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_lvremove_args, (char *) &args); -} - -static void vgremove_stub (XDR *xdr_in) -{ - int r; - struct guestfs_vgremove_args args; - char *vgname; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_vgremove_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "vgremove"); - return; - } - vgname = args.vgname; - - r = do_vgremove (vgname); - if (r == -1) - /* do_vgremove has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_vgremove_args, (char *) &args); -} - -static void pvremove_stub (XDR *xdr_in) -{ - int r; - struct guestfs_pvremove_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_pvremove_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "pvremove"); - return; - } - device = args.device; - - r = do_pvremove (device); - if (r == -1) - /* do_pvremove has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_pvremove_args, (char *) &args); -} - -static void set_e2label_stub (XDR *xdr_in) -{ - int r; - struct guestfs_set_e2label_args args; - char *device; - char *label; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_set_e2label_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "set_e2label"); - return; - } - device = args.device; - label = args.label; - - r = do_set_e2label (device, label); - if (r == -1) - /* do_set_e2label has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_set_e2label_args, (char *) &args); -} - -static void get_e2label_stub (XDR *xdr_in) -{ - char *r; - struct guestfs_get_e2label_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_get_e2label_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "get_e2label"); - return; - } - device = args.device; - - r = do_get_e2label (device); - if (r == NULL) - /* do_get_e2label has already called reply_with_error */ - goto done; - - struct guestfs_get_e2label_ret ret; - ret.label = r; - reply ((xdrproc_t) &xdr_guestfs_get_e2label_ret, (char *) &ret); - free (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_get_e2label_args, (char *) &args); -} - -static void set_e2uuid_stub (XDR *xdr_in) -{ - int r; - struct guestfs_set_e2uuid_args args; - char *device; - char *uuid; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_set_e2uuid_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "set_e2uuid"); - return; - } - device = args.device; - uuid = args.uuid; - - r = do_set_e2uuid (device, uuid); - if (r == -1) - /* do_set_e2uuid has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_set_e2uuid_args, (char *) &args); -} - -static void get_e2uuid_stub (XDR *xdr_in) -{ - char *r; - struct guestfs_get_e2uuid_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_get_e2uuid_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "get_e2uuid"); - return; - } - device = args.device; - - r = do_get_e2uuid (device); - if (r == NULL) - /* do_get_e2uuid has already called reply_with_error */ - goto done; - - struct guestfs_get_e2uuid_ret ret; - ret.uuid = r; - reply ((xdrproc_t) &xdr_guestfs_get_e2uuid_ret, (char *) &ret); - free (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_get_e2uuid_args, (char *) &args); -} - -static void fsck_stub (XDR *xdr_in) -{ - int r; - struct guestfs_fsck_args args; - char *fstype; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_fsck_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "fsck"); - return; - } - fstype = args.fstype; - device = args.device; - - r = do_fsck (fstype, device); - if (r == -1) - /* do_fsck has already called reply_with_error */ - goto done; - - struct guestfs_fsck_ret ret; - ret.status = r; - reply ((xdrproc_t) &xdr_guestfs_fsck_ret, (char *) &ret); -done: - xdr_free ((xdrproc_t) xdr_guestfs_fsck_args, (char *) &args); -} - -static void zero_stub (XDR *xdr_in) -{ - int r; - struct guestfs_zero_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_zero_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "zero"); - return; - } - device = args.device; - - r = do_zero (device); - if (r == -1) - /* do_zero has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_zero_args, (char *) &args); -} - -static void grub_install_stub (XDR *xdr_in) -{ - int r; - struct guestfs_grub_install_args args; - char *root; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_grub_install_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "grub_install"); - return; - } - root = args.root; - device = args.device; - - r = do_grub_install (root, device); - if (r == -1) - /* do_grub_install has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_grub_install_args, (char *) &args); -} - -static void cp_stub (XDR *xdr_in) -{ - int r; - struct guestfs_cp_args args; - char *src; - char *dest; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_cp_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "cp"); - return; - } - src = args.src; - dest = args.dest; - - r = do_cp (src, dest); - if (r == -1) - /* do_cp has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_cp_args, (char *) &args); -} - -static void cp_a_stub (XDR *xdr_in) -{ - int r; - struct guestfs_cp_a_args args; - char *src; - char *dest; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_cp_a_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "cp_a"); - return; - } - src = args.src; - dest = args.dest; - - r = do_cp_a (src, dest); - if (r == -1) - /* do_cp_a has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_cp_a_args, (char *) &args); -} - -static void mv_stub (XDR *xdr_in) -{ - int r; - struct guestfs_mv_args args; - char *src; - char *dest; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_mv_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "mv"); - return; - } - src = args.src; - dest = args.dest; - - r = do_mv (src, dest); - if (r == -1) - /* do_mv has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_mv_args, (char *) &args); -} - -static void drop_caches_stub (XDR *xdr_in) -{ - int r; - struct guestfs_drop_caches_args args; - int whattodrop; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_drop_caches_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "drop_caches"); - return; - } - whattodrop = args.whattodrop; - - r = do_drop_caches (whattodrop); - if (r == -1) - /* do_drop_caches has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_drop_caches_args, (char *) &args); -} - -static void dmesg_stub (XDR *xdr_in) -{ - char *r; - - r = do_dmesg (); - if (r == NULL) - /* do_dmesg has already called reply_with_error */ - goto done; - - struct guestfs_dmesg_ret ret; - ret.kmsgs = r; - reply ((xdrproc_t) &xdr_guestfs_dmesg_ret, (char *) &ret); - free (r); -done: ; -} - -static void ping_daemon_stub (XDR *xdr_in) -{ - int r; - - r = do_ping_daemon (); - if (r == -1) - /* do_ping_daemon has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: ; -} - -static void equal_stub (XDR *xdr_in) -{ - int r; - struct guestfs_equal_args args; - char *file1; - char *file2; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_equal_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "equal"); - return; - } - file1 = args.file1; - file2 = args.file2; - - r = do_equal (file1, file2); - if (r == -1) - /* do_equal has already called reply_with_error */ - goto done; - - struct guestfs_equal_ret ret; - ret.equality = r; - reply ((xdrproc_t) &xdr_guestfs_equal_ret, (char *) &ret); -done: - xdr_free ((xdrproc_t) xdr_guestfs_equal_args, (char *) &args); -} - -static void strings_stub (XDR *xdr_in) -{ - char **r; - struct guestfs_strings_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_strings_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "strings"); - return; - } - path = args.path; - - r = do_strings (path); - if (r == NULL) - /* do_strings has already called reply_with_error */ - goto done; - - struct guestfs_strings_ret ret; - ret.stringsout.stringsout_len = count_strings (r); - ret.stringsout.stringsout_val = r; - reply ((xdrproc_t) &xdr_guestfs_strings_ret, (char *) &ret); - free_strings (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_strings_args, (char *) &args); -} - -static void strings_e_stub (XDR *xdr_in) -{ - char **r; - struct guestfs_strings_e_args args; - char *encoding; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_strings_e_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "strings_e"); - return; - } - encoding = args.encoding; - path = args.path; - - r = do_strings_e (encoding, path); - if (r == NULL) - /* do_strings_e has already called reply_with_error */ - goto done; - - struct guestfs_strings_e_ret ret; - ret.stringsout.stringsout_len = count_strings (r); - ret.stringsout.stringsout_val = r; - reply ((xdrproc_t) &xdr_guestfs_strings_e_ret, (char *) &ret); - free_strings (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_strings_e_args, (char *) &args); -} - -static void hexdump_stub (XDR *xdr_in) -{ - char *r; - struct guestfs_hexdump_args args; - char *path; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_hexdump_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "hexdump"); - return; - } - path = args.path; - - r = do_hexdump (path); - if (r == NULL) - /* do_hexdump has already called reply_with_error */ - goto done; - - struct guestfs_hexdump_ret ret; - ret.dump = r; - reply ((xdrproc_t) &xdr_guestfs_hexdump_ret, (char *) &ret); - free (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_hexdump_args, (char *) &args); -} - -static void zerofree_stub (XDR *xdr_in) -{ - int r; - struct guestfs_zerofree_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_zerofree_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "zerofree"); - return; - } - device = args.device; - - r = do_zerofree (device); - if (r == -1) - /* do_zerofree has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_zerofree_args, (char *) &args); -} - -static void pvresize_stub (XDR *xdr_in) -{ - int r; - struct guestfs_pvresize_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_pvresize_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "pvresize"); - return; - } - device = args.device; - - r = do_pvresize (device); - if (r == -1) - /* do_pvresize has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_pvresize_args, (char *) &args); -} - -static void sfdisk_N_stub (XDR *xdr_in) -{ - int r; - struct guestfs_sfdisk_N_args args; - char *device; - int n; - int cyls; - int heads; - int sectors; - char *line; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_sfdisk_N_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "sfdisk_N"); - return; - } - device = args.device; - n = args.n; - cyls = args.cyls; - heads = args.heads; - sectors = args.sectors; - line = args.line; - - r = do_sfdisk_N (device, n, cyls, heads, sectors, line); - if (r == -1) - /* do_sfdisk_N has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_sfdisk_N_args, (char *) &args); -} - -static void sfdisk_l_stub (XDR *xdr_in) -{ - char *r; - struct guestfs_sfdisk_l_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_sfdisk_l_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "sfdisk_l"); - return; - } - device = args.device; - - r = do_sfdisk_l (device); - if (r == NULL) - /* do_sfdisk_l has already called reply_with_error */ - goto done; - - struct guestfs_sfdisk_l_ret ret; - ret.partitions = r; - reply ((xdrproc_t) &xdr_guestfs_sfdisk_l_ret, (char *) &ret); - free (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_sfdisk_l_args, (char *) &args); -} - -static void sfdisk_kernel_geometry_stub (XDR *xdr_in) -{ - char *r; - struct guestfs_sfdisk_kernel_geometry_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_sfdisk_kernel_geometry_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "sfdisk_kernel_geometry"); - return; - } - device = args.device; - - r = do_sfdisk_kernel_geometry (device); - if (r == NULL) - /* do_sfdisk_kernel_geometry has already called reply_with_error */ - goto done; - - struct guestfs_sfdisk_kernel_geometry_ret ret; - ret.partitions = r; - reply ((xdrproc_t) &xdr_guestfs_sfdisk_kernel_geometry_ret, (char *) &ret); - free (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_sfdisk_kernel_geometry_args, (char *) &args); -} - -static void sfdisk_disk_geometry_stub (XDR *xdr_in) -{ - char *r; - struct guestfs_sfdisk_disk_geometry_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_sfdisk_disk_geometry_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "sfdisk_disk_geometry"); - return; - } - device = args.device; - - r = do_sfdisk_disk_geometry (device); - if (r == NULL) - /* do_sfdisk_disk_geometry has already called reply_with_error */ - goto done; - - struct guestfs_sfdisk_disk_geometry_ret ret; - ret.partitions = r; - reply ((xdrproc_t) &xdr_guestfs_sfdisk_disk_geometry_ret, (char *) &ret); - free (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_sfdisk_disk_geometry_args, (char *) &args); -} - -static void vg_activate_all_stub (XDR *xdr_in) -{ - int r; - struct guestfs_vg_activate_all_args args; - int activate; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_vg_activate_all_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "vg_activate_all"); - return; - } - activate = args.activate; - - r = do_vg_activate_all (activate); - if (r == -1) - /* do_vg_activate_all has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_vg_activate_all_args, (char *) &args); -} - -static void vg_activate_stub (XDR *xdr_in) -{ - int r; - struct guestfs_vg_activate_args args; - int activate; - char **volgroups; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_vg_activate_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "vg_activate"); - return; - } - activate = args.activate; - volgroups = realloc (args.volgroups.volgroups_val, - sizeof (char *) * (args.volgroups.volgroups_len+1)); - if (volgroups == NULL) { - reply_with_perror ("realloc"); - goto done; - } - volgroups[args.volgroups.volgroups_len] = NULL; - args.volgroups.volgroups_val = volgroups; - - r = do_vg_activate (activate, volgroups); - if (r == -1) - /* do_vg_activate has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_vg_activate_args, (char *) &args); -} - -static void lvresize_stub (XDR *xdr_in) -{ - int r; - struct guestfs_lvresize_args args; - char *device; - int mbytes; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_lvresize_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "lvresize"); - return; - } - device = args.device; - mbytes = args.mbytes; - - r = do_lvresize (device, mbytes); - if (r == -1) - /* do_lvresize has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_lvresize_args, (char *) &args); -} - -static void resize2fs_stub (XDR *xdr_in) -{ - int r; - struct guestfs_resize2fs_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_resize2fs_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "resize2fs"); - return; - } - device = args.device; - - r = do_resize2fs (device); - if (r == -1) - /* do_resize2fs has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_resize2fs_args, (char *) &args); -} - -static void find_stub (XDR *xdr_in) -{ - char **r; - struct guestfs_find_args args; - char *directory; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_find_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "find"); - return; - } - directory = args.directory; - - r = do_find (directory); - if (r == NULL) - /* do_find has already called reply_with_error */ - goto done; - - struct guestfs_find_ret ret; - ret.names.names_len = count_strings (r); - ret.names.names_val = r; - reply ((xdrproc_t) &xdr_guestfs_find_ret, (char *) &ret); - free_strings (r); -done: - xdr_free ((xdrproc_t) xdr_guestfs_find_args, (char *) &args); -} - -static void e2fsck_f_stub (XDR *xdr_in) -{ - int r; - struct guestfs_e2fsck_f_args args; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_e2fsck_f_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "e2fsck_f"); - return; - } - device = args.device; - - r = do_e2fsck_f (device); - if (r == -1) - /* do_e2fsck_f has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_e2fsck_f_args, (char *) &args); -} - -static void sleep_stub (XDR *xdr_in) -{ - int r; - struct guestfs_sleep_args args; - int secs; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_sleep_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "sleep"); - return; - } - secs = args.secs; - - r = do_sleep (secs); - if (r == -1) - /* do_sleep has already called reply_with_error */ - goto done; - - reply (NULL, NULL); -done: - xdr_free ((xdrproc_t) xdr_guestfs_sleep_args, (char *) &args); -} - -static void ntfs_3g_probe_stub (XDR *xdr_in) -{ - int r; - struct guestfs_ntfs_3g_probe_args args; - int rw; - char *device; - - memset (&args, 0, sizeof args); - - if (!xdr_guestfs_ntfs_3g_probe_args (xdr_in, &args)) { - reply_with_error ("%s: daemon failed to decode procedure arguments", "ntfs_3g_probe"); - return; - } - rw = args.rw; - device = args.device; - - r = do_ntfs_3g_probe (rw, device); - if (r == -1) - /* do_ntfs_3g_probe has already called reply_with_error */ - goto done; - - struct guestfs_ntfs_3g_probe_ret ret; - ret.status = r; - reply ((xdrproc_t) &xdr_guestfs_ntfs_3g_probe_ret, (char *) &ret); -done: - xdr_free ((xdrproc_t) xdr_guestfs_ntfs_3g_probe_args, (char *) &args); -} - -void dispatch_incoming_message (XDR *xdr_in) -{ - switch (proc_nr) { - case GUESTFS_PROC_MOUNT: - mount_stub (xdr_in); - break; - case GUESTFS_PROC_SYNC: - sync_stub (xdr_in); - break; - case GUESTFS_PROC_TOUCH: - touch_stub (xdr_in); - break; - case GUESTFS_PROC_CAT: - cat_stub (xdr_in); - break; - case GUESTFS_PROC_LL: - ll_stub (xdr_in); - break; - case GUESTFS_PROC_LS: - ls_stub (xdr_in); - break; - case GUESTFS_PROC_LIST_DEVICES: - list_devices_stub (xdr_in); - break; - case GUESTFS_PROC_LIST_PARTITIONS: - list_partitions_stub (xdr_in); - break; - case GUESTFS_PROC_PVS: - pvs_stub (xdr_in); - break; - case GUESTFS_PROC_VGS: - vgs_stub (xdr_in); - break; - case GUESTFS_PROC_LVS: - lvs_stub (xdr_in); - break; - case GUESTFS_PROC_PVS_FULL: - pvs_full_stub (xdr_in); - break; - case GUESTFS_PROC_VGS_FULL: - vgs_full_stub (xdr_in); - break; - case GUESTFS_PROC_LVS_FULL: - lvs_full_stub (xdr_in); - break; - case GUESTFS_PROC_READ_LINES: - read_lines_stub (xdr_in); - break; - case GUESTFS_PROC_AUG_INIT: - aug_init_stub (xdr_in); - break; - case GUESTFS_PROC_AUG_CLOSE: - aug_close_stub (xdr_in); - break; - case GUESTFS_PROC_AUG_DEFVAR: - aug_defvar_stub (xdr_in); - break; - case GUESTFS_PROC_AUG_DEFNODE: - aug_defnode_stub (xdr_in); - break; - case GUESTFS_PROC_AUG_GET: - aug_get_stub (xdr_in); - break; - case GUESTFS_PROC_AUG_SET: - aug_set_stub (xdr_in); - break; - case GUESTFS_PROC_AUG_INSERT: - aug_insert_stub (xdr_in); - break; - case GUESTFS_PROC_AUG_RM: - aug_rm_stub (xdr_in); - break; - case GUESTFS_PROC_AUG_MV: - aug_mv_stub (xdr_in); - break; - case GUESTFS_PROC_AUG_MATCH: - aug_match_stub (xdr_in); - break; - case GUESTFS_PROC_AUG_SAVE: - aug_save_stub (xdr_in); - break; - case GUESTFS_PROC_AUG_LOAD: - aug_load_stub (xdr_in); - break; - case GUESTFS_PROC_AUG_LS: - aug_ls_stub (xdr_in); - break; - case GUESTFS_PROC_RM: - rm_stub (xdr_in); - break; - case GUESTFS_PROC_RMDIR: - rmdir_stub (xdr_in); - break; - case GUESTFS_PROC_RM_RF: - rm_rf_stub (xdr_in); - break; - case GUESTFS_PROC_MKDIR: - mkdir_stub (xdr_in); - break; - case GUESTFS_PROC_MKDIR_P: - mkdir_p_stub (xdr_in); - break; - case GUESTFS_PROC_CHMOD: - chmod_stub (xdr_in); - break; - case GUESTFS_PROC_CHOWN: - chown_stub (xdr_in); - break; - case GUESTFS_PROC_EXISTS: - exists_stub (xdr_in); - break; - case GUESTFS_PROC_IS_FILE: - is_file_stub (xdr_in); - break; - case GUESTFS_PROC_IS_DIR: - is_dir_stub (xdr_in); - break; - case GUESTFS_PROC_PVCREATE: - pvcreate_stub (xdr_in); - break; - case GUESTFS_PROC_VGCREATE: - vgcreate_stub (xdr_in); - break; - case GUESTFS_PROC_LVCREATE: - lvcreate_stub (xdr_in); - break; - case GUESTFS_PROC_MKFS: - mkfs_stub (xdr_in); - break; - case GUESTFS_PROC_SFDISK: - sfdisk_stub (xdr_in); - break; - case GUESTFS_PROC_WRITE_FILE: - write_file_stub (xdr_in); - break; - case GUESTFS_PROC_UMOUNT: - umount_stub (xdr_in); - break; - case GUESTFS_PROC_MOUNTS: - mounts_stub (xdr_in); - break; - case GUESTFS_PROC_UMOUNT_ALL: - umount_all_stub (xdr_in); - break; - case GUESTFS_PROC_LVM_REMOVE_ALL: - lvm_remove_all_stub (xdr_in); - break; - case GUESTFS_PROC_FILE: - file_stub (xdr_in); - break; - case GUESTFS_PROC_COMMAND: - command_stub (xdr_in); - break; - case GUESTFS_PROC_COMMAND_LINES: - command_lines_stub (xdr_in); - break; - case GUESTFS_PROC_STAT: - stat_stub (xdr_in); - break; - case GUESTFS_PROC_LSTAT: - lstat_stub (xdr_in); - break; - case GUESTFS_PROC_STATVFS: - statvfs_stub (xdr_in); - break; - case GUESTFS_PROC_TUNE2FS_L: - tune2fs_l_stub (xdr_in); - break; - case GUESTFS_PROC_BLOCKDEV_SETRO: - blockdev_setro_stub (xdr_in); - break; - case GUESTFS_PROC_BLOCKDEV_SETRW: - blockdev_setrw_stub (xdr_in); - break; - case GUESTFS_PROC_BLOCKDEV_GETRO: - blockdev_getro_stub (xdr_in); - break; - case GUESTFS_PROC_BLOCKDEV_GETSS: - blockdev_getss_stub (xdr_in); - break; - case GUESTFS_PROC_BLOCKDEV_GETBSZ: - blockdev_getbsz_stub (xdr_in); - break; - case GUESTFS_PROC_BLOCKDEV_SETBSZ: - blockdev_setbsz_stub (xdr_in); - break; - case GUESTFS_PROC_BLOCKDEV_GETSZ: - blockdev_getsz_stub (xdr_in); - break; - case GUESTFS_PROC_BLOCKDEV_GETSIZE64: - blockdev_getsize64_stub (xdr_in); - break; - case GUESTFS_PROC_BLOCKDEV_FLUSHBUFS: - blockdev_flushbufs_stub (xdr_in); - break; - case GUESTFS_PROC_BLOCKDEV_REREADPT: - blockdev_rereadpt_stub (xdr_in); - break; - case GUESTFS_PROC_UPLOAD: - upload_stub (xdr_in); - break; - case GUESTFS_PROC_DOWNLOAD: - download_stub (xdr_in); - break; - case GUESTFS_PROC_CHECKSUM: - checksum_stub (xdr_in); - break; - case GUESTFS_PROC_TAR_IN: - tar_in_stub (xdr_in); - break; - case GUESTFS_PROC_TAR_OUT: - tar_out_stub (xdr_in); - break; - case GUESTFS_PROC_TGZ_IN: - tgz_in_stub (xdr_in); - break; - case GUESTFS_PROC_TGZ_OUT: - tgz_out_stub (xdr_in); - break; - case GUESTFS_PROC_MOUNT_RO: - mount_ro_stub (xdr_in); - break; - case GUESTFS_PROC_MOUNT_OPTIONS: - mount_options_stub (xdr_in); - break; - case GUESTFS_PROC_MOUNT_VFS: - mount_vfs_stub (xdr_in); - break; - case GUESTFS_PROC_DEBUG: - debug_stub (xdr_in); - break; - case GUESTFS_PROC_LVREMOVE: - lvremove_stub (xdr_in); - break; - case GUESTFS_PROC_VGREMOVE: - vgremove_stub (xdr_in); - break; - case GUESTFS_PROC_PVREMOVE: - pvremove_stub (xdr_in); - break; - case GUESTFS_PROC_SET_E2LABEL: - set_e2label_stub (xdr_in); - break; - case GUESTFS_PROC_GET_E2LABEL: - get_e2label_stub (xdr_in); - break; - case GUESTFS_PROC_SET_E2UUID: - set_e2uuid_stub (xdr_in); - break; - case GUESTFS_PROC_GET_E2UUID: - get_e2uuid_stub (xdr_in); - break; - case GUESTFS_PROC_FSCK: - fsck_stub (xdr_in); - break; - case GUESTFS_PROC_ZERO: - zero_stub (xdr_in); - break; - case GUESTFS_PROC_GRUB_INSTALL: - grub_install_stub (xdr_in); - break; - case GUESTFS_PROC_CP: - cp_stub (xdr_in); - break; - case GUESTFS_PROC_CP_A: - cp_a_stub (xdr_in); - break; - case GUESTFS_PROC_MV: - mv_stub (xdr_in); - break; - case GUESTFS_PROC_DROP_CACHES: - drop_caches_stub (xdr_in); - break; - case GUESTFS_PROC_DMESG: - dmesg_stub (xdr_in); - break; - case GUESTFS_PROC_PING_DAEMON: - ping_daemon_stub (xdr_in); - break; - case GUESTFS_PROC_EQUAL: - equal_stub (xdr_in); - break; - case GUESTFS_PROC_STRINGS: - strings_stub (xdr_in); - break; - case GUESTFS_PROC_STRINGS_E: - strings_e_stub (xdr_in); - break; - case GUESTFS_PROC_HEXDUMP: - hexdump_stub (xdr_in); - break; - case GUESTFS_PROC_ZEROFREE: - zerofree_stub (xdr_in); - break; - case GUESTFS_PROC_PVRESIZE: - pvresize_stub (xdr_in); - break; - case GUESTFS_PROC_SFDISK_N: - sfdisk_N_stub (xdr_in); - break; - case GUESTFS_PROC_SFDISK_L: - sfdisk_l_stub (xdr_in); - break; - case GUESTFS_PROC_SFDISK_KERNEL_GEOMETRY: - sfdisk_kernel_geometry_stub (xdr_in); - break; - case GUESTFS_PROC_SFDISK_DISK_GEOMETRY: - sfdisk_disk_geometry_stub (xdr_in); - break; - case GUESTFS_PROC_VG_ACTIVATE_ALL: - vg_activate_all_stub (xdr_in); - break; - case GUESTFS_PROC_VG_ACTIVATE: - vg_activate_stub (xdr_in); - break; - case GUESTFS_PROC_LVRESIZE: - lvresize_stub (xdr_in); - break; - case GUESTFS_PROC_RESIZE2FS: - resize2fs_stub (xdr_in); - break; - case GUESTFS_PROC_FIND: - find_stub (xdr_in); - break; - case GUESTFS_PROC_E2FSCK_F: - e2fsck_f_stub (xdr_in); - break; - case GUESTFS_PROC_SLEEP: - sleep_stub (xdr_in); - break; - case GUESTFS_PROC_NTFS_3G_PROBE: - ntfs_3g_probe_stub (xdr_in); - break; - default: - reply_with_error ("dispatch_incoming_message: unknown procedure number %d", proc_nr); - } -} - -static const char *lvm_pv_cols = "pv_name,pv_uuid,pv_fmt,pv_size,dev_size,pv_free,pv_used,pv_attr,pv_pe_count,pv_pe_alloc_count,pv_tags,pe_start,pv_mda_count,pv_mda_free"; - -static int lvm_tokenize_pv (char *str, struct guestfs_lvm_int_pv *r) -{ - char *tok, *p, *next; - int i, j; - - if (!str) { - fprintf (stderr, "%s: failed: passed a NULL string\n", __func__); - return -1; - } - if (!*str || isspace (*str)) { - fprintf (stderr, "%s: failed: passed a empty string or one beginning with whitespace\n", __func__); - return -1; - } - tok = str; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_name"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - r->pv_name = strdup (tok); - if (r->pv_name == NULL) { - perror ("strdup"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_uuid"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - for (i = j = 0; i < 32; ++j) { - if (tok[j] == '\0') { - fprintf (stderr, "%s: failed to parse UUID from '%s'\n", __func__, tok); - return -1; - } else if (tok[j] != '-') - r->pv_uuid[i++] = tok[j]; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_fmt"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - r->pv_fmt = strdup (tok); - if (r->pv_fmt == NULL) { - perror ("strdup"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_size"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNu64, &r->pv_size) != 1) { - fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "pv_size"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "dev_size"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNu64, &r->dev_size) != 1) { - fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "dev_size"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_free"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNu64, &r->pv_free) != 1) { - fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "pv_free"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_used"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNu64, &r->pv_used) != 1) { - fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "pv_used"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_attr"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - r->pv_attr = strdup (tok); - if (r->pv_attr == NULL) { - perror ("strdup"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_pe_count"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNi64, &r->pv_pe_count) != 1) { - fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "pv_pe_count"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_pe_alloc_count"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNi64, &r->pv_pe_alloc_count) != 1) { - fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "pv_pe_alloc_count"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_tags"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - r->pv_tags = strdup (tok); - if (r->pv_tags == NULL) { - perror ("strdup"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pe_start"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNu64, &r->pe_start) != 1) { - fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "pe_start"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_mda_count"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNi64, &r->pv_mda_count) != 1) { - fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "pv_mda_count"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_mda_free"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNu64, &r->pv_mda_free) != 1) { - fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "pv_mda_free"); - return -1; - } - tok = next; - if (tok != NULL) { - fprintf (stderr, "%s: failed: extra tokens at end of string\n", __func__); - return -1; - } - return 0; -} - -guestfs_lvm_int_pv_list * -parse_command_line_pvs (void) -{ - char *out, *err; - char *p, *pend; - int r, i; - guestfs_lvm_int_pv_list *ret; - void *newp; - - ret = malloc (sizeof *ret); - if (!ret) { - reply_with_perror ("malloc"); - return NULL; - } - - ret->guestfs_lvm_int_pv_list_len = 0; - ret->guestfs_lvm_int_pv_list_val = NULL; - - r = command (&out, &err, - "/sbin/lvm", "pvs", - "-o", lvm_pv_cols, "--unbuffered", "--noheadings", - "--nosuffix", "--separator", ",", "--units", "b", NULL); - if (r == -1) { - reply_with_error ("%s", err); - free (out); - free (err); - free (ret); - return NULL; - } - - free (err); - - /* Tokenize each line of the output. */ - p = out; - i = 0; - while (p) { - pend = strchr (p, '\n'); /* Get the next line of output. */ - if (pend) { - *pend = '\0'; - pend++; - } - - while (*p && isspace (*p)) /* Skip any leading whitespace. */ - p++; - - if (!*p) { /* Empty line? Skip it. */ - p = pend; - continue; - } - - /* Allocate some space to store this next entry. */ - newp = realloc (ret->guestfs_lvm_int_pv_list_val, - sizeof (guestfs_lvm_int_pv) * (i+1)); - if (newp == NULL) { - reply_with_perror ("realloc"); - free (ret->guestfs_lvm_int_pv_list_val); - free (ret); - free (out); - return NULL; - } - ret->guestfs_lvm_int_pv_list_val = newp; - - /* Tokenize the next entry. */ - r = lvm_tokenize_pv (p, &ret->guestfs_lvm_int_pv_list_val[i]); - if (r == -1) { - reply_with_error ("failed to parse output of 'pvs' command"); - free (ret->guestfs_lvm_int_pv_list_val); - free (ret); - free (out); - return NULL; - } - - ++i; - p = pend; - } - - ret->guestfs_lvm_int_pv_list_len = i; - - free (out); - return ret; -} -static const char *lvm_vg_cols = "vg_name,vg_uuid,vg_fmt,vg_attr,vg_size,vg_free,vg_sysid,vg_extent_size,vg_extent_count,vg_free_count,max_lv,max_pv,pv_count,lv_count,snap_count,vg_seqno,vg_tags,vg_mda_count,vg_mda_free"; - -static int lvm_tokenize_vg (char *str, struct guestfs_lvm_int_vg *r) -{ - char *tok, *p, *next; - int i, j; - - if (!str) { - fprintf (stderr, "%s: failed: passed a NULL string\n", __func__); - return -1; - } - if (!*str || isspace (*str)) { - fprintf (stderr, "%s: failed: passed a empty string or one beginning with whitespace\n", __func__); - return -1; - } - tok = str; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_name"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - r->vg_name = strdup (tok); - if (r->vg_name == NULL) { - perror ("strdup"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_uuid"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - for (i = j = 0; i < 32; ++j) { - if (tok[j] == '\0') { - fprintf (stderr, "%s: failed to parse UUID from '%s'\n", __func__, tok); - return -1; - } else if (tok[j] != '-') - r->vg_uuid[i++] = tok[j]; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_fmt"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - r->vg_fmt = strdup (tok); - if (r->vg_fmt == NULL) { - perror ("strdup"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_attr"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - r->vg_attr = strdup (tok); - if (r->vg_attr == NULL) { - perror ("strdup"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_size"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNu64, &r->vg_size) != 1) { - fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "vg_size"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_free"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNu64, &r->vg_free) != 1) { - fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "vg_free"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_sysid"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - r->vg_sysid = strdup (tok); - if (r->vg_sysid == NULL) { - perror ("strdup"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_extent_size"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNu64, &r->vg_extent_size) != 1) { - fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "vg_extent_size"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_extent_count"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNi64, &r->vg_extent_count) != 1) { - fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "vg_extent_count"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_free_count"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNi64, &r->vg_free_count) != 1) { - fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "vg_free_count"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "max_lv"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNi64, &r->max_lv) != 1) { - fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "max_lv"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "max_pv"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNi64, &r->max_pv) != 1) { - fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "max_pv"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_count"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNi64, &r->pv_count) != 1) { - fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "pv_count"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "lv_count"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNi64, &r->lv_count) != 1) { - fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "lv_count"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "snap_count"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNi64, &r->snap_count) != 1) { - fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "snap_count"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_seqno"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNi64, &r->vg_seqno) != 1) { - fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "vg_seqno"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_tags"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - r->vg_tags = strdup (tok); - if (r->vg_tags == NULL) { - perror ("strdup"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_mda_count"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNi64, &r->vg_mda_count) != 1) { - fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "vg_mda_count"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_mda_free"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNu64, &r->vg_mda_free) != 1) { - fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "vg_mda_free"); - return -1; - } - tok = next; - if (tok != NULL) { - fprintf (stderr, "%s: failed: extra tokens at end of string\n", __func__); - return -1; - } - return 0; -} - -guestfs_lvm_int_vg_list * -parse_command_line_vgs (void) -{ - char *out, *err; - char *p, *pend; - int r, i; - guestfs_lvm_int_vg_list *ret; - void *newp; - - ret = malloc (sizeof *ret); - if (!ret) { - reply_with_perror ("malloc"); - return NULL; - } - - ret->guestfs_lvm_int_vg_list_len = 0; - ret->guestfs_lvm_int_vg_list_val = NULL; - - r = command (&out, &err, - "/sbin/lvm", "vgs", - "-o", lvm_vg_cols, "--unbuffered", "--noheadings", - "--nosuffix", "--separator", ",", "--units", "b", NULL); - if (r == -1) { - reply_with_error ("%s", err); - free (out); - free (err); - free (ret); - return NULL; - } - - free (err); - - /* Tokenize each line of the output. */ - p = out; - i = 0; - while (p) { - pend = strchr (p, '\n'); /* Get the next line of output. */ - if (pend) { - *pend = '\0'; - pend++; - } - - while (*p && isspace (*p)) /* Skip any leading whitespace. */ - p++; - - if (!*p) { /* Empty line? Skip it. */ - p = pend; - continue; - } - - /* Allocate some space to store this next entry. */ - newp = realloc (ret->guestfs_lvm_int_vg_list_val, - sizeof (guestfs_lvm_int_vg) * (i+1)); - if (newp == NULL) { - reply_with_perror ("realloc"); - free (ret->guestfs_lvm_int_vg_list_val); - free (ret); - free (out); - return NULL; - } - ret->guestfs_lvm_int_vg_list_val = newp; - - /* Tokenize the next entry. */ - r = lvm_tokenize_vg (p, &ret->guestfs_lvm_int_vg_list_val[i]); - if (r == -1) { - reply_with_error ("failed to parse output of 'vgs' command"); - free (ret->guestfs_lvm_int_vg_list_val); - free (ret); - free (out); - return NULL; - } - - ++i; - p = pend; - } - - ret->guestfs_lvm_int_vg_list_len = i; - - free (out); - return ret; -} -static const char *lvm_lv_cols = "lv_name,lv_uuid,lv_attr,lv_major,lv_minor,lv_kernel_major,lv_kernel_minor,lv_size,seg_count,origin,snap_percent,copy_percent,move_pv,lv_tags,mirror_log,modules"; - -static int lvm_tokenize_lv (char *str, struct guestfs_lvm_int_lv *r) -{ - char *tok, *p, *next; - int i, j; - - if (!str) { - fprintf (stderr, "%s: failed: passed a NULL string\n", __func__); - return -1; - } - if (!*str || isspace (*str)) { - fprintf (stderr, "%s: failed: passed a empty string or one beginning with whitespace\n", __func__); - return -1; - } - tok = str; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "lv_name"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - r->lv_name = strdup (tok); - if (r->lv_name == NULL) { - perror ("strdup"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "lv_uuid"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - for (i = j = 0; i < 32; ++j) { - if (tok[j] == '\0') { - fprintf (stderr, "%s: failed to parse UUID from '%s'\n", __func__, tok); - return -1; - } else if (tok[j] != '-') - r->lv_uuid[i++] = tok[j]; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "lv_attr"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - r->lv_attr = strdup (tok); - if (r->lv_attr == NULL) { - perror ("strdup"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "lv_major"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNi64, &r->lv_major) != 1) { - fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "lv_major"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "lv_minor"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNi64, &r->lv_minor) != 1) { - fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "lv_minor"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "lv_kernel_major"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNi64, &r->lv_kernel_major) != 1) { - fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "lv_kernel_major"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "lv_kernel_minor"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNi64, &r->lv_kernel_minor) != 1) { - fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "lv_kernel_minor"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "lv_size"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNu64, &r->lv_size) != 1) { - fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "lv_size"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "seg_count"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (sscanf (tok, "%"SCNi64, &r->seg_count) != 1) { - fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "seg_count"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "origin"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - r->origin = strdup (tok); - if (r->origin == NULL) { - perror ("strdup"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "snap_percent"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (tok[0] == '\0') - r->snap_percent = -1; - else if (sscanf (tok, "%f", &r->snap_percent) != 1) { - fprintf (stderr, "%s: failed to parse float '%s' from token %s\n", __func__, tok, "snap_percent"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "copy_percent"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - if (tok[0] == '\0') - r->copy_percent = -1; - else if (sscanf (tok, "%f", &r->copy_percent) != 1) { - fprintf (stderr, "%s: failed to parse float '%s' from token %s\n", __func__, tok, "copy_percent"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "move_pv"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - r->move_pv = strdup (tok); - if (r->move_pv == NULL) { - perror ("strdup"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "lv_tags"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - r->lv_tags = strdup (tok); - if (r->lv_tags == NULL) { - perror ("strdup"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "mirror_log"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - r->mirror_log = strdup (tok); - if (r->mirror_log == NULL) { - perror ("strdup"); - return -1; - } - tok = next; - if (!tok) { - fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "modules"); - return -1; - } - p = strchrnul (tok, ','); - if (*p) next = p+1; else next = NULL; - *p = '\0'; - r->modules = strdup (tok); - if (r->modules == NULL) { - perror ("strdup"); - return -1; - } - tok = next; - if (tok != NULL) { - fprintf (stderr, "%s: failed: extra tokens at end of string\n", __func__); - return -1; - } - return 0; -} - -guestfs_lvm_int_lv_list * -parse_command_line_lvs (void) -{ - char *out, *err; - char *p, *pend; - int r, i; - guestfs_lvm_int_lv_list *ret; - void *newp; - - ret = malloc (sizeof *ret); - if (!ret) { - reply_with_perror ("malloc"); - return NULL; - } - - ret->guestfs_lvm_int_lv_list_len = 0; - ret->guestfs_lvm_int_lv_list_val = NULL; - - r = command (&out, &err, - "/sbin/lvm", "lvs", - "-o", lvm_lv_cols, "--unbuffered", "--noheadings", - "--nosuffix", "--separator", ",", "--units", "b", NULL); - if (r == -1) { - reply_with_error ("%s", err); - free (out); - free (err); - free (ret); - return NULL; - } - - free (err); - - /* Tokenize each line of the output. */ - p = out; - i = 0; - while (p) { - pend = strchr (p, '\n'); /* Get the next line of output. */ - if (pend) { - *pend = '\0'; - pend++; - } - - while (*p && isspace (*p)) /* Skip any leading whitespace. */ - p++; - - if (!*p) { /* Empty line? Skip it. */ - p = pend; - continue; - } - - /* Allocate some space to store this next entry. */ - newp = realloc (ret->guestfs_lvm_int_lv_list_val, - sizeof (guestfs_lvm_int_lv) * (i+1)); - if (newp == NULL) { - reply_with_perror ("realloc"); - free (ret->guestfs_lvm_int_lv_list_val); - free (ret); - free (out); - return NULL; - } - ret->guestfs_lvm_int_lv_list_val = newp; - - /* Tokenize the next entry. */ - r = lvm_tokenize_lv (p, &ret->guestfs_lvm_int_lv_list_val[i]); - if (r == -1) { - reply_with_error ("failed to parse output of 'lvs' command"); - free (ret->guestfs_lvm_int_lv_list_val); - free (ret); - free (out); - return NULL; - } - - ++i; - p = pend; - } - - ret->guestfs_lvm_int_lv_list_len = i; - - free (out); - return ret; -} diff --git a/daemon/swap.c b/daemon/swap.c new file mode 100644 index 0000000..7dac96e --- /dev/null +++ b/daemon/swap.c @@ -0,0 +1,70 @@ +/* libguestfs - the guestfsd daemon + * Copyright (C) 2009 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include +#include +#include +#include + +#include "../src/guestfs_protocol.h" +#include "daemon.h" +#include "actions.h" + +static int +mkswap (char *device, const char *flag, const char *value) +{ + char *err; + int r; + + IS_DEVICE (device, -1); + + if (!flag) + r = command (NULL, &err, "/sbin/mkswap", device, NULL); + else + r = command (NULL, &err, "/sbin/mkswap", flag, value, device, NULL); + + if (r == -1) { + reply_with_error ("mkswap: %s", err); + free (err); + return -1; + } + + free (err); + + return 0; +} + +int +do_mkswap (char *device) +{ + return mkswap (device, NULL, NULL); +} + +int +do_mkswap_L (char *label, char *device) +{ + return mkswap (device, "-L", label); +} + +int +do_mkswap_U (char *uuid, char *device) +{ + return mkswap (device, "-U", uuid); +} diff --git a/daemon/tar.c b/daemon/tar.c index 4d9feaa..0320604 100644 --- a/daemon/tar.c +++ b/daemon/tar.c @@ -88,7 +88,7 @@ do_tar_in (char *dir) return -1; } - if (pclose (fp) == -1) { + if (pclose (fp) != 0) { err = errno; cancel_receive (); errno = err; @@ -150,7 +150,7 @@ do_tar_out (char *dir) return -1; } - if (pclose (fp) == -1) { + if (pclose (fp) != 0) { perror (dir); send_file_end (1); /* Cancel. */ return -1; @@ -214,7 +214,7 @@ do_tgz_in (char *dir) return -1; } - if (pclose (fp) == -1) { + if (pclose (fp) != 0) { err = errno; cancel_receive (); errno = err; @@ -276,7 +276,7 @@ do_tgz_out (char *dir) return -1; } - if (pclose (fp) == -1) { + if (pclose (fp) != 0) { perror (dir); send_file_end (1); /* Cancel. */ return -1; diff --git a/daemon/umask.c b/daemon/umask.c new file mode 100644 index 0000000..ad8573d --- /dev/null +++ b/daemon/umask.c @@ -0,0 +1,46 @@ +/* libguestfs - the guestfsd daemon + * Copyright (C) 2009 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "../src/guestfs_protocol.h" +#include "daemon.h" +#include "actions.h" + +int +do_umask (int mask) +{ + int r; + + r = umask (mask); + + if (r == -1) { + reply_with_perror ("umask"); + return -1; + } + + return r; +} diff --git a/daemon/wc.c b/daemon/wc.c new file mode 100644 index 0000000..91e1942 --- /dev/null +++ b/daemon/wc.c @@ -0,0 +1,93 @@ +/* libguestfs - the guestfsd daemon + * Copyright (C) 2009 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include +#include +#include +#include + +#include "../src/guestfs_protocol.h" +#include "daemon.h" +#include "actions.h" + +static int +wc (char *flag, char *path) +{ + char *buf; + char *out, *err; + int r, len; + + NEED_ROOT (-1); + ABS_PATH (path, -1); + + /* Make the path relative to /sysroot. */ + len = strlen (path) + 9; + buf = malloc (len); + if (!buf) { + reply_with_perror ("malloc"); + return -1; + } + snprintf (buf, len, "/sysroot%s", path); + + r = command (&out, &err, "wc", flag, buf, NULL); + free (buf); + if (r == -1) { + reply_with_error ("wc %s: %s", flag, err); + free (out); + free (err); + return -1; + } + + free (err); + +#if 0 + /* Split it at the first whitespace. */ + len = strcspn (out, " \t\n"); + out[len] = '\0'; +#endif + + /* Parse the number. */ + if (sscanf (out, "%d", &r) != 1) { + reply_with_error ("wc: cannot parse number: %s", out); + free (out); + return -1; + } + + free (out); + return r; +} + +int +do_wc_l (char *path) +{ + return wc ("-l", path); +} + +int +do_wc_w (char *path) +{ + return wc ("-w", path); +} + +int +do_wc_c (char *path) +{ + return wc ("-c", path); +} diff --git a/fish/Makefile.am b/fish/Makefile.am index 5f88894..03e872c 100644 --- a/fish/Makefile.am +++ b/fish/Makefile.am @@ -21,11 +21,15 @@ guestfish_SOURCES = \ alloc.c \ cmds.c \ completion.c \ + destpaths.c \ echo.c \ edit.c \ fish.c \ fish.h \ - lcd.c + glob.c \ + lcd.c \ + more.c \ + time.c guestfish_CFLAGS = \ -I$(top_builddir)/src -Wall \ diff --git a/fish/cmds.c b/fish/cmds.c deleted file mode 100644 index 334d715..0000000 --- a/fish/cmds.c +++ /dev/null @@ -1,3142 +0,0 @@ -/* libguestfs generated file - * WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'. - * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST. - * - * Copyright (C) 2009 Red Hat Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include -#include -#include -#include - -#include -#include "fish.h" - -void list_commands (void) -{ - printf (" %-16s %s\n", "Command", "Description"); - list_builtin_commands (); - printf ("%-20s %s\n", "add-cdrom", "add a CD-ROM disk image to examine"); - printf ("%-20s %s\n", "add-drive", "add an image to examine or modify"); - printf ("%-20s %s\n", "add-drive-ro", "add a drive in snapshot mode (read-only)"); - printf ("%-20s %s\n", "aug-close", "close the current Augeas handle"); - printf ("%-20s %s\n", "aug-defnode", "define an Augeas node"); - printf ("%-20s %s\n", "aug-defvar", "define an Augeas variable"); - printf ("%-20s %s\n", "aug-get", "look up the value of an Augeas path"); - printf ("%-20s %s\n", "aug-init", "create a new Augeas handle"); - printf ("%-20s %s\n", "aug-insert", "insert a sibling Augeas node"); - printf ("%-20s %s\n", "aug-load", "load files into the tree"); - printf ("%-20s %s\n", "aug-ls", "list Augeas nodes under a path"); - printf ("%-20s %s\n", "aug-match", "return Augeas nodes which match path"); - printf ("%-20s %s\n", "aug-mv", "move Augeas node"); - printf ("%-20s %s\n", "aug-rm", "remove an Augeas path"); - printf ("%-20s %s\n", "aug-save", "write all pending Augeas changes to disk"); - printf ("%-20s %s\n", "aug-set", "set Augeas path to value"); - printf ("%-20s %s\n", "blockdev-flushbufs", "flush device buffers"); - printf ("%-20s %s\n", "blockdev-getbsz", "get blocksize of block device"); - printf ("%-20s %s\n", "blockdev-getro", "is block device set to read-only"); - printf ("%-20s %s\n", "blockdev-getsize64", "get total size of device in bytes"); - printf ("%-20s %s\n", "blockdev-getss", "get sectorsize of block device"); - printf ("%-20s %s\n", "blockdev-getsz", "get total size of device in 512-byte sectors"); - printf ("%-20s %s\n", "blockdev-rereadpt", "reread partition table"); - printf ("%-20s %s\n", "blockdev-setbsz", "set blocksize of block device"); - printf ("%-20s %s\n", "blockdev-setro", "set block device to read-only"); - printf ("%-20s %s\n", "blockdev-setrw", "set block device to read-write"); - printf ("%-20s %s\n", "cat", "list the contents of a file"); - printf ("%-20s %s\n", "checksum", "compute MD5, SHAx or CRC checksum of file"); - printf ("%-20s %s\n", "chmod", "change file mode"); - printf ("%-20s %s\n", "chown", "change file owner and group"); - printf ("%-20s %s\n", "command", "run a command from the guest filesystem"); - printf ("%-20s %s\n", "command-lines", "run a command, returning lines"); - printf ("%-20s %s\n", "config", "add qemu parameters"); - printf ("%-20s %s\n", "cp", "copy a file"); - printf ("%-20s %s\n", "cp-a", "copy a file or directory recursively"); - printf ("%-20s %s\n", "debug", "debugging and internals"); - printf ("%-20s %s\n", "dmesg", "return kernel messages"); - printf ("%-20s %s\n", "download", "download a file to the local machine"); - printf ("%-20s %s\n", "drop-caches", "drop kernel page cache, dentries and inodes"); - printf ("%-20s %s\n", "e2fsck-f", "check an ext2/ext3 filesystem"); - printf ("%-20s %s\n", "equal", "test if two files have equal contents"); - printf ("%-20s %s\n", "exists", "test if file or directory exists"); - printf ("%-20s %s\n", "file", "determine file type"); - printf ("%-20s %s\n", "find", "find all files and directories"); - printf ("%-20s %s\n", "fsck", "run the filesystem checker"); - printf ("%-20s %s\n", "get-append", "get the additional kernel options"); - printf ("%-20s %s\n", "get-autosync", "get autosync mode"); - printf ("%-20s %s\n", "get-e2label", "get the ext2/3/4 filesystem label"); - printf ("%-20s %s\n", "get-e2uuid", "get the ext2/3/4 filesystem UUID"); - printf ("%-20s %s\n", "get-path", "get the search path"); - printf ("%-20s %s\n", "get-qemu", "get the qemu binary"); - printf ("%-20s %s\n", "get-state", "get the current state"); - printf ("%-20s %s\n", "get-verbose", "get verbose mode"); - printf ("%-20s %s\n", "grub-install", "install GRUB"); - printf ("%-20s %s\n", "hexdump", "dump a file in hexadecimal"); - printf ("%-20s %s\n", "is-busy", "is busy processing a command"); - printf ("%-20s %s\n", "is-config", "is in configuration state"); - printf ("%-20s %s\n", "is-dir", "test if file exists"); - printf ("%-20s %s\n", "is-file", "test if file exists"); - printf ("%-20s %s\n", "is-launching", "is launching subprocess"); - printf ("%-20s %s\n", "is-ready", "is ready to accept commands"); - printf ("%-20s %s\n", "kill-subprocess", "kill the qemu subprocess"); - printf ("%-20s %s\n", "launch", "launch the qemu subprocess"); - printf ("%-20s %s\n", "list-devices", "list the block devices"); - printf ("%-20s %s\n", "list-partitions", "list the partitions"); - printf ("%-20s %s\n", "ll", "list the files in a directory (long format)"); - printf ("%-20s %s\n", "ls", "list the files in a directory"); - printf ("%-20s %s\n", "lstat", "get file information for a symbolic link"); - printf ("%-20s %s\n", "lvcreate", "create an LVM volume group"); - printf ("%-20s %s\n", "lvm-remove-all", "remove all LVM LVs, VGs and PVs"); - printf ("%-20s %s\n", "lvremove", "remove an LVM logical volume"); - printf ("%-20s %s\n", "lvresize", "resize an LVM logical volume"); - printf ("%-20s %s\n", "lvs", "list the LVM logical volumes (LVs)"); - printf ("%-20s %s\n", "lvs-full", "list the LVM logical volumes (LVs)"); - printf ("%-20s %s\n", "mkdir", "create a directory"); - printf ("%-20s %s\n", "mkdir-p", "create a directory and parents"); - printf ("%-20s %s\n", "mkfs", "make a filesystem"); - printf ("%-20s %s\n", "mount", "mount a guest disk at a position in the filesystem"); - printf ("%-20s %s\n", "mount-options", "mount a guest disk with mount options"); - printf ("%-20s %s\n", "mount-ro", "mount a guest disk, read-only"); - printf ("%-20s %s\n", "mount-vfs", "mount a guest disk with mount options and vfstype"); - printf ("%-20s %s\n", "mounts", "show mounted filesystems"); - printf ("%-20s %s\n", "mv", "move a file"); - printf ("%-20s %s\n", "ntfs-3g-probe", "probe NTFS volume"); - printf ("%-20s %s\n", "ping-daemon", "ping the guest daemon"); - printf ("%-20s %s\n", "pvcreate", "create an LVM physical volume"); - printf ("%-20s %s\n", "pvremove", "remove an LVM physical volume"); - printf ("%-20s %s\n", "pvresize", "resize an LVM physical volume"); - printf ("%-20s %s\n", "pvs", "list the LVM physical volumes (PVs)"); - printf ("%-20s %s\n", "pvs-full", "list the LVM physical volumes (PVs)"); - printf ("%-20s %s\n", "read-lines", "read file as lines"); - printf ("%-20s %s\n", "resize2fs", "resize an ext2/ext3 filesystem"); - printf ("%-20s %s\n", "rm", "remove a file"); - printf ("%-20s %s\n", "rm-rf", "remove a file or directory recursively"); - printf ("%-20s %s\n", "rmdir", "remove a directory"); - printf ("%-20s %s\n", "set-append", "add options to kernel command line"); - printf ("%-20s %s\n", "set-autosync", "set autosync mode"); - printf ("%-20s %s\n", "set-e2label", "set the ext2/3/4 filesystem label"); - printf ("%-20s %s\n", "set-e2uuid", "set the ext2/3/4 filesystem UUID"); - printf ("%-20s %s\n", "set-path", "set the search path"); - printf ("%-20s %s\n", "set-qemu", "set the qemu binary"); - printf ("%-20s %s\n", "set-verbose", "set verbose mode"); - printf ("%-20s %s\n", "sfdisk", "create partitions on a block device"); - printf ("%-20s %s\n", "sfdisk-N", "modify a single partition on a block device"); - printf ("%-20s %s\n", "sfdisk-disk-geometry", "display the disk geometry from the partition table"); - printf ("%-20s %s\n", "sfdisk-kernel-geometry", "display the kernel geometry"); - printf ("%-20s %s\n", "sfdisk-l", "display the partition table"); - printf ("%-20s %s\n", "sleep", "sleep for some seconds"); - printf ("%-20s %s\n", "stat", "get file information"); - printf ("%-20s %s\n", "statvfs", "get file system statistics"); - printf ("%-20s %s\n", "strings", "print the printable strings in a file"); - printf ("%-20s %s\n", "strings-e", "print the printable strings in a file"); - printf ("%-20s %s\n", "sync", "sync disks, writes are flushed through to the disk image"); - printf ("%-20s %s\n", "tar-in", "unpack tarfile to directory"); - printf ("%-20s %s\n", "tar-out", "pack directory into tarfile"); - printf ("%-20s %s\n", "tgz-in", "unpack compressed tarball to directory"); - printf ("%-20s %s\n", "tgz-out", "pack directory into compressed tarball"); - printf ("%-20s %s\n", "touch", "update file timestamps or create a new file"); - printf ("%-20s %s\n", "tune2fs-l", "get ext2/ext3/ext4 superblock details"); - printf ("%-20s %s\n", "umount", "unmount a filesystem"); - printf ("%-20s %s\n", "umount-all", "unmount all filesystems"); - printf ("%-20s %s\n", "upload", "upload a file from the local machine"); - printf ("%-20s %s\n", "vg-activate", "activate or deactivate some volume groups"); - printf ("%-20s %s\n", "vg-activate-all", "activate or deactivate all volume groups"); - printf ("%-20s %s\n", "vgcreate", "create an LVM volume group"); - printf ("%-20s %s\n", "vgremove", "remove an LVM volume group"); - printf ("%-20s %s\n", "vgs", "list the LVM volume groups (VGs)"); - printf ("%-20s %s\n", "vgs-full", "list the LVM volume groups (VGs)"); - printf ("%-20s %s\n", "write-file", "create a file"); - printf ("%-20s %s\n", "zero", "write zeroes to the device"); - printf ("%-20s %s\n", "zerofree", "zero unused inodes and disk blocks on ext2/3 filesystem"); - printf (" Use -h / help to show detailed help for a command.\n"); -} - -void display_command (const char *cmd) -{ - if (strcasecmp (cmd, "launch") == 0 || strcasecmp (cmd, "run") == 0) - pod2text ("launch - launch the qemu subprocess", " launch\n\nInternally libguestfs is implemented by running a virtual machine\nusing L.\n\nYou should call this after configuring the handle\n(eg. adding drives) but before performing any actions.\n\nYou can use 'run' as an alias for this command."); - else - if (strcasecmp (cmd, "kill_subprocess") == 0 || strcasecmp (cmd, "kill-subprocess") == 0) - pod2text ("kill-subprocess - kill the qemu subprocess", " kill-subprocess\n\nThis kills the qemu subprocess. You should never need to call this."); - else - if (strcasecmp (cmd, "add_drive") == 0 || strcasecmp (cmd, "add-drive") == 0 || strcasecmp (cmd, "add") == 0) - pod2text ("add-drive - add an image to examine or modify", " add-drive \n\nThis function adds a virtual machine disk image C to the\nguest. The first time you call this function, the disk appears as IDE\ndisk 0 (C) in the guest, the second time as C, and\nso on.\n\nYou don't necessarily need to be root when using libguestfs. However\nyou obviously do need sufficient permissions to access the filename\nfor whatever operations you want to perform (ie. read access if you\njust want to read the image or write access if you want to modify the\nimage).\n\nThis is equivalent to the qemu parameter C<-drive file=filename>.\n\nNote that this call checks for the existence of C. This\nstops you from specifying other types of drive which are supported\nby qemu such as C and C URLs. To specify those, use\nthe general C call instead.\n\nYou can use 'add' as an alias for this command."); - else - if (strcasecmp (cmd, "add_cdrom") == 0 || strcasecmp (cmd, "add-cdrom") == 0 || strcasecmp (cmd, "cdrom") == 0) - pod2text ("add-cdrom - add a CD-ROM disk image to examine", " add-cdrom \n\nThis function adds a virtual CD-ROM disk image to the guest.\n\nThis is equivalent to the qemu parameter C<-cdrom filename>.\n\nNote that this call checks for the existence of C. This\nstops you from specifying other types of drive which are supported\nby qemu such as C and C URLs. To specify those, use\nthe general C call instead.\n\nYou can use 'cdrom' as an alias for this command."); - else - if (strcasecmp (cmd, "add_drive_ro") == 0 || strcasecmp (cmd, "add-drive-ro") == 0 || strcasecmp (cmd, "add-ro") == 0) - pod2text ("add-drive-ro - add a drive in snapshot mode (read-only)", " add-drive-ro \n\nThis adds a drive in snapshot mode, making it effectively\nread-only.\n\nNote that writes to the device are allowed, and will be seen for\nthe duration of the guestfs handle, but they are written\nto a temporary file which is discarded as soon as the guestfs\nhandle is closed. We don't currently have any method to enable\nchanges to be committed, although qemu can support this.\n\nThis is equivalent to the qemu parameter\nC<-drive file=filename,snapshot=on>.\n\nNote that this call checks for the existence of C. This\nstops you from specifying other types of drive which are supported\nby qemu such as C and C URLs. To specify those, use\nthe general C call instead.\n\nYou can use 'add-ro' as an alias for this command."); - else - if (strcasecmp (cmd, "config") == 0) - pod2text ("config - add qemu parameters", " config \n\nThis can be used to add arbitrary qemu command line parameters\nof the form C<-param value>. Actually it's not quite arbitrary - we\nprevent you from setting some parameters which would interfere with\nparameters that we use.\n\nThe first character of C string must be a C<-> (dash).\n\nC can be NULL."); - else - if (strcasecmp (cmd, "set_qemu") == 0 || strcasecmp (cmd, "set-qemu") == 0 || strcasecmp (cmd, "qemu") == 0) - pod2text ("set-qemu - set the qemu binary", " set-qemu \n\nSet the qemu binary that we will use.\n\nThe default is chosen when the library was compiled by the\nconfigure script.\n\nYou can also override this by setting the C\nenvironment variable.\n\nSetting C to C restores the default qemu binary.\n\nYou can use 'qemu' as an alias for this command."); - else - if (strcasecmp (cmd, "get_qemu") == 0 || strcasecmp (cmd, "get-qemu") == 0) - pod2text ("get-qemu - get the qemu binary", " get-qemu\n\nReturn the current qemu binary.\n\nThis is always non-NULL. If it wasn't set already, then this will\nreturn the default qemu binary name."); - else - if (strcasecmp (cmd, "set_path") == 0 || strcasecmp (cmd, "set-path") == 0 || strcasecmp (cmd, "path") == 0) - pod2text ("set-path - set the search path", " set-path \n\nSet the path that libguestfs searches for kernel and initrd.img.\n\nThe default is C<$libdir/guestfs> unless overridden by setting\nC environment variable.\n\nSetting C to C restores the default path.\n\nYou can use 'path' as an alias for this command."); - else - if (strcasecmp (cmd, "get_path") == 0 || strcasecmp (cmd, "get-path") == 0) - pod2text ("get-path - get the search path", " get-path\n\nReturn the current search path.\n\nThis is always non-NULL. If it wasn't set already, then this will\nreturn the default path."); - else - if (strcasecmp (cmd, "set_append") == 0 || strcasecmp (cmd, "set-append") == 0 || strcasecmp (cmd, "append") == 0) - pod2text ("set-append - add options to kernel command line", " set-append \n\nThis function is used to add additional options to the\nguest kernel command line.\n\nThe default is C unless overridden by setting\nC environment variable.\n\nSetting C to C means I additional options\nare passed (libguestfs always adds a few of its own).\n\nYou can use 'append' as an alias for this command."); - else - if (strcasecmp (cmd, "get_append") == 0 || strcasecmp (cmd, "get-append") == 0) - pod2text ("get-append - get the additional kernel options", " get-append\n\nReturn the additional kernel options which are added to the\nguest kernel command line.\n\nIf C then no options are added."); - else - if (strcasecmp (cmd, "set_autosync") == 0 || strcasecmp (cmd, "set-autosync") == 0 || strcasecmp (cmd, "autosync") == 0) - pod2text ("set-autosync - set autosync mode", " set-autosync \n\nIf C is true, this enables autosync. Libguestfs will make a\nbest effort attempt to run C followed by\nC when the handle is closed\n(also if the program exits without closing handles).\n\nThis is disabled by default (except in guestfish where it is\nenabled by default).\n\nYou can use 'autosync' as an alias for this command."); - else - if (strcasecmp (cmd, "get_autosync") == 0 || strcasecmp (cmd, "get-autosync") == 0) - pod2text ("get-autosync - get autosync mode", " get-autosync\n\nGet the autosync flag."); - else - if (strcasecmp (cmd, "set_verbose") == 0 || strcasecmp (cmd, "set-verbose") == 0 || strcasecmp (cmd, "verbose") == 0) - pod2text ("set-verbose - set verbose mode", " set-verbose \n\nIf C is true, this turns on verbose messages (to C).\n\nVerbose messages are disabled unless the environment variable\nC is defined and set to C<1>.\n\nYou can use 'verbose' as an alias for this command."); - else - if (strcasecmp (cmd, "get_verbose") == 0 || strcasecmp (cmd, "get-verbose") == 0) - pod2text ("get-verbose - get verbose mode", " get-verbose\n\nThis returns the verbose messages flag."); - else - if (strcasecmp (cmd, "is_ready") == 0 || strcasecmp (cmd, "is-ready") == 0) - pod2text ("is-ready - is ready to accept commands", " is-ready\n\nThis returns true iff this handle is ready to accept commands\n(in the C state).\n\nFor more information on states, see L."); - else - if (strcasecmp (cmd, "is_config") == 0 || strcasecmp (cmd, "is-config") == 0) - pod2text ("is-config - is in configuration state", " is-config\n\nThis returns true iff this handle is being configured\n(in the C state).\n\nFor more information on states, see L."); - else - if (strcasecmp (cmd, "is_launching") == 0 || strcasecmp (cmd, "is-launching") == 0) - pod2text ("is-launching - is launching subprocess", " is-launching\n\nThis returns true iff this handle is launching the subprocess\n(in the C state).\n\nFor more information on states, see L."); - else - if (strcasecmp (cmd, "is_busy") == 0 || strcasecmp (cmd, "is-busy") == 0) - pod2text ("is-busy - is busy processing a command", " is-busy\n\nThis returns true iff this handle is busy processing a command\n(in the C state).\n\nFor more information on states, see L."); - else - if (strcasecmp (cmd, "get_state") == 0 || strcasecmp (cmd, "get-state") == 0) - pod2text ("get-state - get the current state", " get-state\n\nThis returns the current state as an opaque integer. This is\nonly useful for printing debug and internal error messages.\n\nFor more information on states, see L."); - else - if (strcasecmp (cmd, "mount") == 0) - pod2text ("mount - mount a guest disk at a position in the filesystem", " mount \n\nMount a guest disk at a position in the filesystem. Block devices\nare named C, C and so on, as they were added to\nthe guest. If those block devices contain partitions, they will have\nthe usual names (eg. C). Also LVM C-style\nnames can be used.\n\nThe rules are the same as for L: A filesystem must\nfirst be mounted on C before others can be mounted. Other\nfilesystems can only be mounted on directories which already\nexist.\n\nThe mounted filesystem is writable, if we have sufficient permissions\non the underlying device.\n\nThe filesystem options C and C are set with this\ncall, in order to improve reliability."); - else - if (strcasecmp (cmd, "sync") == 0) - pod2text ("sync - sync disks, writes are flushed through to the disk image", " sync\n\nThis syncs the disk, so that any writes are flushed through to the\nunderlying disk image.\n\nYou should always call this if you have modified a disk image, before\nclosing the handle."); - else - if (strcasecmp (cmd, "touch") == 0) - pod2text ("touch - update file timestamps or create a new file", " touch \n\nTouch acts like the L command. It can be used to\nupdate the timestamps on a file, or, if the file does not exist,\nto create a new zero-length file."); - else - if (strcasecmp (cmd, "cat") == 0) - pod2text ("cat - list the contents of a file", " cat \n\nReturn the contents of the file named C.\n\nNote that this function cannot correctly handle binary files\n(specifically, files containing C<\\0> character which is treated\nas end of string). For those you need to use the C\nfunction which has a more complex interface.\n\nBecause of the message protocol, there is a transfer limit \nof somewhere between 2MB and 4MB. To transfer large files you should use\nFTP."); - else - if (strcasecmp (cmd, "ll") == 0) - pod2text ("ll - list the files in a directory (long format)", " ll \n\nList the files in C (relative to the root directory,\nthere is no cwd) in the format of 'ls -la'.\n\nThis command is mostly useful for interactive sessions. It\nis I intended that you try to parse the output string."); - else - if (strcasecmp (cmd, "ls") == 0) - pod2text ("ls - list the files in a directory", " ls \n\nList the files in C (relative to the root directory,\nthere is no cwd). The '.' and '..' entries are not returned, but\nhidden files are shown.\n\nThis command is mostly useful for interactive sessions. Programs\nshould probably use C instead."); - else - if (strcasecmp (cmd, "list_devices") == 0 || strcasecmp (cmd, "list-devices") == 0) - pod2text ("list-devices - list the block devices", " list-devices\n\nList all the block devices.\n\nThe full block device names are returned, eg. C"); - else - if (strcasecmp (cmd, "list_partitions") == 0 || strcasecmp (cmd, "list-partitions") == 0) - pod2text ("list-partitions - list the partitions", " list-partitions\n\nList all the partitions detected on all block devices.\n\nThe full partition device names are returned, eg. C\n\nThis does not return logical volumes. For that you will need to\ncall C."); - else - if (strcasecmp (cmd, "pvs") == 0) - pod2text ("pvs - list the LVM physical volumes (PVs)", " pvs\n\nList all the physical volumes detected. This is the equivalent\nof the L command.\n\nThis returns a list of just the device names that contain\nPVs (eg. C).\n\nSee also C."); - else - if (strcasecmp (cmd, "vgs") == 0) - pod2text ("vgs - list the LVM volume groups (VGs)", " vgs\n\nList all the volumes groups detected. This is the equivalent\nof the L command.\n\nThis returns a list of just the volume group names that were\ndetected (eg. C).\n\nSee also C."); - else - if (strcasecmp (cmd, "lvs") == 0) - pod2text ("lvs - list the LVM logical volumes (LVs)", " lvs\n\nList all the logical volumes detected. This is the equivalent\nof the L command.\n\nThis returns a list of the logical volume device names\n(eg. C).\n\nSee also C."); - else - if (strcasecmp (cmd, "pvs_full") == 0 || strcasecmp (cmd, "pvs-full") == 0) - pod2text ("pvs-full - list the LVM physical volumes (PVs)", " pvs-full\n\nList all the physical volumes detected. This is the equivalent\nof the L command. The \"full\" version includes all fields."); - else - if (strcasecmp (cmd, "vgs_full") == 0 || strcasecmp (cmd, "vgs-full") == 0) - pod2text ("vgs-full - list the LVM volume groups (VGs)", " vgs-full\n\nList all the volumes groups detected. This is the equivalent\nof the L command. The \"full\" version includes all fields."); - else - if (strcasecmp (cmd, "lvs_full") == 0 || strcasecmp (cmd, "lvs-full") == 0) - pod2text ("lvs-full - list the LVM logical volumes (LVs)", " lvs-full\n\nList all the logical volumes detected. This is the equivalent\nof the L command. The \"full\" version includes all fields."); - else - if (strcasecmp (cmd, "read_lines") == 0 || strcasecmp (cmd, "read-lines") == 0) - pod2text ("read-lines - read file as lines", " read-lines \n\nReturn the contents of the file named C.\n\nThe file contents are returned as a list of lines. Trailing\nC and C character sequences are I returned.\n\nNote that this function cannot correctly handle binary files\n(specifically, files containing C<\\0> character which is treated\nas end of line). For those you need to use the C\nfunction which has a more complex interface."); - else - if (strcasecmp (cmd, "aug_init") == 0 || strcasecmp (cmd, "aug-init") == 0) - pod2text ("aug-init - create a new Augeas handle", " aug-init \n\nCreate a new Augeas handle for editing configuration files.\nIf there was any previous Augeas handle associated with this\nguestfs session, then it is closed.\n\nYou must call this before using any other C\ncommands.\n\nC is the filesystem root. C must not be NULL,\nuse C instead.\n\nThe flags are the same as the flags defined in\nEaugeas.hE, the logical I of the following\nintegers:\n\n=over 4\n\n=item C = 1\n\nKeep the original file with a C<.augsave> extension.\n\n=item C = 2\n\nSave changes into a file with extension C<.augnew>, and\ndo not overwrite original. Overrides C.\n\n=item C = 4\n\nTypecheck lenses (can be expensive).\n\n=item C = 8\n\nDo not use standard load path for modules.\n\n=item C = 16\n\nMake save a no-op, just record what would have been changed.\n\n=item C = 32\n\nDo not load the tree in C.\n\n=back\n\nTo close the handle, you can call C.\n\nTo find out more about Augeas, see L."); - else - if (strcasecmp (cmd, "aug_close") == 0 || strcasecmp (cmd, "aug-close") == 0) - pod2text ("aug-close - close the current Augeas handle", " aug-close\n\nClose the current Augeas handle and free up any resources\nused by it. After calling this, you have to call\nC again before you can use any other\nAugeas functions."); - else - if (strcasecmp (cmd, "aug_defvar") == 0 || strcasecmp (cmd, "aug-defvar") == 0) - pod2text ("aug-defvar - define an Augeas variable", " aug-defvar \n\nDefines an Augeas variable C whose value is the result\nof evaluating C. If C is NULL, then C is\nundefined.\n\nOn success this returns the number of nodes in C, or\nC<0> if C evaluates to something which is not a nodeset."); - else - if (strcasecmp (cmd, "aug_defnode") == 0 || strcasecmp (cmd, "aug-defnode") == 0) - pod2text ("aug-defnode - define an Augeas node", " aug-defnode \n\nDefines a variable C whose value is the result of\nevaluating C.\n\nIf C evaluates to an empty nodeset, a node is created,\nequivalent to calling C C, C.\nC will be the nodeset containing that single node.\n\nOn success this returns a pair containing the\nnumber of nodes in the nodeset, and a boolean flag\nif a node was created."); - else - if (strcasecmp (cmd, "aug_get") == 0 || strcasecmp (cmd, "aug-get") == 0) - pod2text ("aug-get - look up the value of an Augeas path", " aug-get \n\nLook up the value associated with C. If C\nmatches exactly one node, the C is returned."); - else - if (strcasecmp (cmd, "aug_set") == 0 || strcasecmp (cmd, "aug-set") == 0) - pod2text ("aug-set - set Augeas path to value", " aug-set \n\nSet the value associated with C to C."); - else - if (strcasecmp (cmd, "aug_insert") == 0 || strcasecmp (cmd, "aug-insert") == 0) - pod2text ("aug-insert - insert a sibling Augeas node", " aug-insert