1 /* libguestfs generated file
2 * WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'.
3 * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
5 * Copyright (C) 2009 Red Hat Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 package com.redhat.et.libguestfs;
24 import java.util.HashMap;
25 import com.redhat.et.libguestfs.LibGuestFSException;
26 import com.redhat.et.libguestfs.PV;
27 import com.redhat.et.libguestfs.VG;
28 import com.redhat.et.libguestfs.LV;
29 import com.redhat.et.libguestfs.Stat;
30 import com.redhat.et.libguestfs.StatVFS;
31 import com.redhat.et.libguestfs.IntBool;
34 * The GuestFS object is a libguestfs handle.
38 public class GuestFS {
39 // Load the native code.
41 System.loadLibrary ("guestfs_jni");
45 * The native guestfs_h pointer.
50 * Create a libguestfs handle.
52 * @throws LibGuestFSException
54 public GuestFS () throws LibGuestFSException
58 private native long _create () throws LibGuestFSException;
61 * Close a libguestfs handle.
63 * You can also leave handles to be collected by the garbage
64 * collector, but this method ensures that the resources used
65 * by the handle are freed up immediately. If you call any
66 * other methods after closing the handle, you will get an
69 * @throws LibGuestFSException
71 public void close () throws LibGuestFSException
77 private native void _close (long g) throws LibGuestFSException;
79 public void finalize () throws LibGuestFSException
85 * launch the qemu subprocess
87 * Internally libguestfs is implemented by running a
88 * virtual machine using qemu(1).
90 * You should call this after configuring the handle (eg.
91 * adding drives) but before performing any actions.
93 * @throws LibGuestFSException
96 throws LibGuestFSException
99 throw new LibGuestFSException ("launch: handle is closed");
102 private native void _launch (long g)
103 throws LibGuestFSException;
106 * wait until the qemu subprocess launches
108 * Internally libguestfs is implemented by running a
109 * virtual machine using qemu(1).
111 * You should call this after "g.launch" to wait for the
112 * launch to complete.
114 * @throws LibGuestFSException
116 public void wait_ready ()
117 throws LibGuestFSException
120 throw new LibGuestFSException ("wait_ready: handle is closed");
123 private native void _wait_ready (long g)
124 throws LibGuestFSException;
127 * kill the qemu subprocess
129 * This kills the qemu subprocess. You should never need to
132 * @throws LibGuestFSException
134 public void kill_subprocess ()
135 throws LibGuestFSException
138 throw new LibGuestFSException ("kill_subprocess: handle is closed");
139 _kill_subprocess (g);
141 private native void _kill_subprocess (long g)
142 throws LibGuestFSException;
145 * add an image to examine or modify
147 * This function adds a virtual machine disk image
148 * "filename" to the guest. The first time you call this
149 * function, the disk appears as IDE disk 0 ("/dev/sda") in
150 * the guest, the second time as "/dev/sdb", and so on.
152 * You don't necessarily need to be root when using
153 * libguestfs. However you obviously do need sufficient
154 * permissions to access the filename for whatever
155 * operations you want to perform (ie. read access if you
156 * just want to read the image or write access if you want
157 * to modify the image).
159 * This is equivalent to the qemu parameter "-drive
162 * @throws LibGuestFSException
164 public void add_drive (String filename)
165 throws LibGuestFSException
168 throw new LibGuestFSException ("add_drive: handle is closed");
169 _add_drive (g, filename);
171 private native void _add_drive (long g, String filename)
172 throws LibGuestFSException;
175 * add a CD-ROM disk image to examine
177 * This function adds a virtual CD-ROM disk image to the
180 * This is equivalent to the qemu parameter "-cdrom
183 * @throws LibGuestFSException
185 public void add_cdrom (String filename)
186 throws LibGuestFSException
189 throw new LibGuestFSException ("add_cdrom: handle is closed");
190 _add_cdrom (g, filename);
192 private native void _add_cdrom (long g, String filename)
193 throws LibGuestFSException;
196 * add qemu parameters
198 * This can be used to add arbitrary qemu command line
199 * parameters of the form "-param value". Actually it's not
200 * quite arbitrary - we prevent you from setting some
201 * parameters which would interfere with parameters that we
204 * The first character of "param" string must be a "-"
207 * "value" can be NULL.
209 * @throws LibGuestFSException
211 public void config (String qemuparam, String qemuvalue)
212 throws LibGuestFSException
215 throw new LibGuestFSException ("config: handle is closed");
216 _config (g, qemuparam, qemuvalue);
218 private native void _config (long g, String qemuparam, String qemuvalue)
219 throws LibGuestFSException;
222 * set the qemu binary
224 * Set the qemu binary that we will use.
226 * The default is chosen when the library was compiled by
227 * the configure script.
229 * You can also override this by setting the
230 * "LIBGUESTFS_QEMU" environment variable.
232 * Setting "qemu" to "NULL" restores the default qemu
235 * @throws LibGuestFSException
237 public void set_qemu (String qemu)
238 throws LibGuestFSException
241 throw new LibGuestFSException ("set_qemu: handle is closed");
244 private native void _set_qemu (long g, String qemu)
245 throws LibGuestFSException;
248 * get the qemu binary
250 * Return the current qemu binary.
252 * This is always non-NULL. If it wasn't set already, then
253 * this will return the default qemu binary name.
255 * @throws LibGuestFSException
257 public String get_qemu ()
258 throws LibGuestFSException
261 throw new LibGuestFSException ("get_qemu: handle is closed");
262 return _get_qemu (g);
264 private native String _get_qemu (long g)
265 throws LibGuestFSException;
268 * set the search path
270 * Set the path that libguestfs searches for kernel and
273 * The default is "$libdir/guestfs" unless overridden by
274 * setting "LIBGUESTFS_PATH" environment variable.
276 * Setting "path" to "NULL" restores the default path.
278 * @throws LibGuestFSException
280 public void set_path (String path)
281 throws LibGuestFSException
284 throw new LibGuestFSException ("set_path: handle is closed");
287 private native void _set_path (long g, String path)
288 throws LibGuestFSException;
291 * get the search path
293 * Return the current search path.
295 * This is always non-NULL. If it wasn't set already, then
296 * this will return the default path.
298 * @throws LibGuestFSException
300 public String get_path ()
301 throws LibGuestFSException
304 throw new LibGuestFSException ("get_path: handle is closed");
305 return _get_path (g);
307 private native String _get_path (long g)
308 throws LibGuestFSException;
311 * add options to kernel command line
313 * This function is used to add additional options to the
314 * guest kernel command line.
316 * The default is "NULL" unless overridden by setting
317 * "LIBGUESTFS_APPEND" environment variable.
319 * Setting "append" to "NULL" means *no* additional options
320 * are passed (libguestfs always adds a few of its own).
322 * @throws LibGuestFSException
324 public void set_append (String append)
325 throws LibGuestFSException
328 throw new LibGuestFSException ("set_append: handle is closed");
329 _set_append (g, append);
331 private native void _set_append (long g, String append)
332 throws LibGuestFSException;
335 * get the additional kernel options
337 * Return the additional kernel options which are added to
338 * the guest kernel command line.
340 * If "NULL" then no options are added.
342 * @throws LibGuestFSException
344 public String get_append ()
345 throws LibGuestFSException
348 throw new LibGuestFSException ("get_append: handle is closed");
349 return _get_append (g);
351 private native String _get_append (long g)
352 throws LibGuestFSException;
357 * If "autosync" is true, this enables autosync. Libguestfs
358 * will make a best effort attempt to run "g.umount_all"
359 * followed by "g.sync" when the handle is closed (also if
360 * the program exits without closing handles).
362 * This is disabled by default (except in guestfish where
363 * it is enabled by default).
365 * @throws LibGuestFSException
367 public void set_autosync (boolean autosync)
368 throws LibGuestFSException
371 throw new LibGuestFSException ("set_autosync: handle is closed");
372 _set_autosync (g, autosync);
374 private native void _set_autosync (long g, boolean autosync)
375 throws LibGuestFSException;
380 * Get the autosync flag.
382 * @throws LibGuestFSException
384 public boolean get_autosync ()
385 throws LibGuestFSException
388 throw new LibGuestFSException ("get_autosync: handle is closed");
389 return _get_autosync (g);
391 private native boolean _get_autosync (long g)
392 throws LibGuestFSException;
397 * If "verbose" is true, this turns on verbose messages (to
400 * Verbose messages are disabled unless the environment
401 * variable "LIBGUESTFS_DEBUG" is defined and set to 1.
403 * @throws LibGuestFSException
405 public void set_verbose (boolean verbose)
406 throws LibGuestFSException
409 throw new LibGuestFSException ("set_verbose: handle is closed");
410 _set_verbose (g, verbose);
412 private native void _set_verbose (long g, boolean verbose)
413 throws LibGuestFSException;
418 * This returns the verbose messages flag.
420 * @throws LibGuestFSException
422 public boolean get_verbose ()
423 throws LibGuestFSException
426 throw new LibGuestFSException ("get_verbose: handle is closed");
427 return _get_verbose (g);
429 private native boolean _get_verbose (long g)
430 throws LibGuestFSException;
433 * is ready to accept commands
435 * This returns true iff this handle is ready to accept
436 * commands (in the "READY" state).
438 * For more information on states, see guestfs(3).
440 * @throws LibGuestFSException
442 public boolean is_ready ()
443 throws LibGuestFSException
446 throw new LibGuestFSException ("is_ready: handle is closed");
447 return _is_ready (g);
449 private native boolean _is_ready (long g)
450 throws LibGuestFSException;
453 * is in configuration state
455 * This returns true iff this handle is being configured
456 * (in the "CONFIG" state).
458 * For more information on states, see guestfs(3).
460 * @throws LibGuestFSException
462 public boolean is_config ()
463 throws LibGuestFSException
466 throw new LibGuestFSException ("is_config: handle is closed");
467 return _is_config (g);
469 private native boolean _is_config (long g)
470 throws LibGuestFSException;
473 * is launching subprocess
475 * This returns true iff this handle is launching the
476 * subprocess (in the "LAUNCHING" state).
478 * For more information on states, see guestfs(3).
480 * @throws LibGuestFSException
482 public boolean is_launching ()
483 throws LibGuestFSException
486 throw new LibGuestFSException ("is_launching: handle is closed");
487 return _is_launching (g);
489 private native boolean _is_launching (long g)
490 throws LibGuestFSException;
493 * is busy processing a command
495 * This returns true iff this handle is busy processing a
496 * command (in the "BUSY" state).
498 * For more information on states, see guestfs(3).
500 * @throws LibGuestFSException
502 public boolean is_busy ()
503 throws LibGuestFSException
506 throw new LibGuestFSException ("is_busy: handle is closed");
509 private native boolean _is_busy (long g)
510 throws LibGuestFSException;
513 * get the current state
515 * This returns the current state as an opaque integer.
516 * This is only useful for printing debug and internal
519 * For more information on states, see guestfs(3).
521 * @throws LibGuestFSException
523 public int get_state ()
524 throws LibGuestFSException
527 throw new LibGuestFSException ("get_state: handle is closed");
528 return _get_state (g);
530 private native int _get_state (long g)
531 throws LibGuestFSException;
536 * This sets the state to "BUSY". This is only used when
537 * implementing actions using the low-level API.
539 * For more information on states, see guestfs(3).
541 * @throws LibGuestFSException
543 public void set_busy ()
544 throws LibGuestFSException
547 throw new LibGuestFSException ("set_busy: handle is closed");
550 private native void _set_busy (long g)
551 throws LibGuestFSException;
556 * This sets the state to "READY". This is only used when
557 * implementing actions using the low-level API.
559 * For more information on states, see guestfs(3).
561 * @throws LibGuestFSException
563 public void set_ready ()
564 throws LibGuestFSException
567 throw new LibGuestFSException ("set_ready: handle is closed");
570 private native void _set_ready (long g)
571 throws LibGuestFSException;
574 * leave the busy state
576 * This sets the state to "READY", or if in "CONFIG" then
577 * it leaves the state as is. This is only used when
578 * implementing actions using the low-level API.
580 * For more information on states, see guestfs(3).
582 * @throws LibGuestFSException
584 public void end_busy ()
585 throws LibGuestFSException
588 throw new LibGuestFSException ("end_busy: handle is closed");
591 private native void _end_busy (long g)
592 throws LibGuestFSException;
595 * mount a guest disk at a position in the filesystem
597 * Mount a guest disk at a position in the filesystem.
598 * Block devices are named "/dev/sda", "/dev/sdb" and so
599 * on, as they were added to the guest. If those block
600 * devices contain partitions, they will have the usual
601 * names (eg. "/dev/sda1"). Also LVM "/dev/VG/LV"-style
604 * The rules are the same as for mount(2): A filesystem
605 * must first be mounted on "/" before others can be
606 * mounted. Other filesystems can only be mounted on
607 * directories which already exist.
609 * The mounted filesystem is writable, if we have
610 * sufficient permissions on the underlying device.
612 * The filesystem options "sync" and "noatime" are set with
613 * this call, in order to improve reliability.
615 * @throws LibGuestFSException
617 public void mount (String device, String mountpoint)
618 throws LibGuestFSException
621 throw new LibGuestFSException ("mount: handle is closed");
622 _mount (g, device, mountpoint);
624 private native void _mount (long g, String device, String mountpoint)
625 throws LibGuestFSException;
628 * sync disks, writes are flushed through to the disk image
630 * This syncs the disk, so that any writes are flushed
631 * through to the underlying disk image.
633 * You should always call this if you have modified a disk
634 * image, before closing the handle.
636 * @throws LibGuestFSException
639 throws LibGuestFSException
642 throw new LibGuestFSException ("sync: handle is closed");
645 private native void _sync (long g)
646 throws LibGuestFSException;
649 * update file timestamps or create a new file
651 * Touch acts like the touch(1) command. It can be used to
652 * update the timestamps on a file, or, if the file does
653 * not exist, to create a new zero-length file.
655 * @throws LibGuestFSException
657 public void touch (String path)
658 throws LibGuestFSException
661 throw new LibGuestFSException ("touch: handle is closed");
664 private native void _touch (long g, String path)
665 throws LibGuestFSException;
668 * list the contents of a file
670 * Return the contents of the file named "path".
672 * Note that this function cannot correctly handle binary
673 * files (specifically, files containing "\0" character
674 * which is treated as end of string). For those you need
675 * to use the "g.download" function which has a more
678 * Because of the message protocol, there is a transfer
679 * limit of somewhere between 2MB and 4MB. To transfer
680 * large files you should use FTP.
682 * @throws LibGuestFSException
684 public String cat (String path)
685 throws LibGuestFSException
688 throw new LibGuestFSException ("cat: handle is closed");
689 return _cat (g, path);
691 private native String _cat (long g, String path)
692 throws LibGuestFSException;
695 * list the files in a directory (long format)
697 * List the files in "directory" (relative to the root
698 * directory, there is no cwd) in the format of 'ls -la'.
700 * This command is mostly useful for interactive sessions.
701 * It is *not* intended that you try to parse the output
704 * @throws LibGuestFSException
706 public String ll (String directory)
707 throws LibGuestFSException
710 throw new LibGuestFSException ("ll: handle is closed");
711 return _ll (g, directory);
713 private native String _ll (long g, String directory)
714 throws LibGuestFSException;
717 * list the files in a directory
719 * List the files in "directory" (relative to the root
720 * directory, there is no cwd). The '.' and '..' entries
721 * are not returned, but hidden files are shown.
723 * This command is mostly useful for interactive sessions.
724 * Programs should probably use "g.readdir" instead.
726 * @throws LibGuestFSException
728 public String[] ls (String directory)
729 throws LibGuestFSException
732 throw new LibGuestFSException ("ls: handle is closed");
733 return _ls (g, directory);
735 private native String[] _ls (long g, String directory)
736 throws LibGuestFSException;
739 * list the block devices
741 * List all the block devices.
743 * The full block device names are returned, eg. "/dev/sda"
745 * @throws LibGuestFSException
747 public String[] list_devices ()
748 throws LibGuestFSException
751 throw new LibGuestFSException ("list_devices: handle is closed");
752 return _list_devices (g);
754 private native String[] _list_devices (long g)
755 throws LibGuestFSException;
758 * list the partitions
760 * List all the partitions detected on all block devices.
762 * The full partition device names are returned, eg.
765 * This does not return logical volumes. For that you will
766 * need to call "g.lvs".
768 * @throws LibGuestFSException
770 public String[] list_partitions ()
771 throws LibGuestFSException
774 throw new LibGuestFSException ("list_partitions: handle is closed");
775 return _list_partitions (g);
777 private native String[] _list_partitions (long g)
778 throws LibGuestFSException;
781 * list the LVM physical volumes (PVs)
783 * List all the physical volumes detected. This is the
784 * equivalent of the pvs(8) command.
786 * This returns a list of just the device names that
787 * contain PVs (eg. "/dev/sda2").
789 * See also "g.pvs_full".
791 * @throws LibGuestFSException
793 public String[] pvs ()
794 throws LibGuestFSException
797 throw new LibGuestFSException ("pvs: handle is closed");
800 private native String[] _pvs (long g)
801 throws LibGuestFSException;
804 * list the LVM volume groups (VGs)
806 * List all the volumes groups detected. This is the
807 * equivalent of the vgs(8) command.
809 * This returns a list of just the volume group names that
810 * were detected (eg. "VolGroup00").
812 * See also "g.vgs_full".
814 * @throws LibGuestFSException
816 public String[] vgs ()
817 throws LibGuestFSException
820 throw new LibGuestFSException ("vgs: handle is closed");
823 private native String[] _vgs (long g)
824 throws LibGuestFSException;
827 * list the LVM logical volumes (LVs)
829 * List all the logical volumes detected. This is the
830 * equivalent of the lvs(8) command.
832 * This returns a list of the logical volume device names
833 * (eg. "/dev/VolGroup00/LogVol00").
835 * See also "g.lvs_full".
837 * @throws LibGuestFSException
839 public String[] lvs ()
840 throws LibGuestFSException
843 throw new LibGuestFSException ("lvs: handle is closed");
846 private native String[] _lvs (long g)
847 throws LibGuestFSException;
850 * list the LVM physical volumes (PVs)
852 * List all the physical volumes detected. This is the
853 * equivalent of the pvs(8) command. The "full" version
854 * includes all fields.
856 * @throws LibGuestFSException
858 public PV[] pvs_full ()
859 throws LibGuestFSException
862 throw new LibGuestFSException ("pvs_full: handle is closed");
863 return _pvs_full (g);
865 private native PV[] _pvs_full (long g)
866 throws LibGuestFSException;
869 * list the LVM volume groups (VGs)
871 * List all the volumes groups detected. This is the
872 * equivalent of the vgs(8) command. The "full" version
873 * includes all fields.
875 * @throws LibGuestFSException
877 public VG[] vgs_full ()
878 throws LibGuestFSException
881 throw new LibGuestFSException ("vgs_full: handle is closed");
882 return _vgs_full (g);
884 private native VG[] _vgs_full (long g)
885 throws LibGuestFSException;
888 * list the LVM logical volumes (LVs)
890 * List all the logical volumes detected. This is the
891 * equivalent of the lvs(8) command. The "full" version
892 * includes all fields.
894 * @throws LibGuestFSException
896 public LV[] lvs_full ()
897 throws LibGuestFSException
900 throw new LibGuestFSException ("lvs_full: handle is closed");
901 return _lvs_full (g);
903 private native LV[] _lvs_full (long g)
904 throws LibGuestFSException;
909 * Return the contents of the file named "path".
911 * The file contents are returned as a list of lines.
912 * Trailing "LF" and "CRLF" character sequences are *not*
915 * Note that this function cannot correctly handle binary
916 * files (specifically, files containing "\0" character
917 * which is treated as end of line). For those you need to
918 * use the "g.read_file" function which has a more complex
921 * @throws LibGuestFSException
923 public String[] read_lines (String path)
924 throws LibGuestFSException
927 throw new LibGuestFSException ("read_lines: handle is closed");
928 return _read_lines (g, path);
930 private native String[] _read_lines (long g, String path)
931 throws LibGuestFSException;
934 * create a new Augeas handle
936 * Create a new Augeas handle for editing configuration
937 * files. If there was any previous Augeas handle
938 * associated with this guestfs session, then it is closed.
940 * You must call this before using any other "g.aug_*"
943 * "root" is the filesystem root. "root" must not be NULL,
946 * The flags are the same as the flags defined in
947 * <augeas.h>, the logical *or* of the following integers:
949 * "AUG_SAVE_BACKUP" = 1
950 * Keep the original file with a ".augsave" extension.
952 * "AUG_SAVE_NEWFILE" = 2
953 * Save changes into a file with extension ".augnew",
954 * and do not overwrite original. Overrides
957 * "AUG_TYPE_CHECK" = 4
958 * Typecheck lenses (can be expensive).
960 * "AUG_NO_STDINC" = 8
961 * Do not use standard load path for modules.
963 * "AUG_SAVE_NOOP" = 16
964 * Make save a no-op, just record what would have been
968 * Do not load the tree in "g.aug_init".
970 * To close the handle, you can call "g.aug_close".
972 * To find out more about Augeas, see <http://augeas.net/>.
974 * @throws LibGuestFSException
976 public void aug_init (String root, int flags)
977 throws LibGuestFSException
980 throw new LibGuestFSException ("aug_init: handle is closed");
981 _aug_init (g, root, flags);
983 private native void _aug_init (long g, String root, int flags)
984 throws LibGuestFSException;
987 * close the current Augeas handle
989 * Close the current Augeas handle and free up any
990 * resources used by it. After calling this, you have to
991 * call "g.aug_init" again before you can use any other
994 * @throws LibGuestFSException
996 public void aug_close ()
997 throws LibGuestFSException
1000 throw new LibGuestFSException ("aug_close: handle is closed");
1003 private native void _aug_close (long g)
1004 throws LibGuestFSException;
1007 * define an Augeas variable
1009 * Defines an Augeas variable "name" whose value is the
1010 * result of evaluating "expr". If "expr" is NULL, then
1011 * "name" is undefined.
1013 * On success this returns the number of nodes in "expr",
1014 * or 0 if "expr" evaluates to something which is not a
1017 * @throws LibGuestFSException
1019 public int aug_defvar (String name, String expr)
1020 throws LibGuestFSException
1023 throw new LibGuestFSException ("aug_defvar: handle is closed");
1024 return _aug_defvar (g, name, expr);
1026 private native int _aug_defvar (long g, String name, String expr)
1027 throws LibGuestFSException;
1030 * define an Augeas node
1032 * Defines a variable "name" whose value is the result of
1033 * evaluating "expr".
1035 * If "expr" evaluates to an empty nodeset, a node is
1036 * created, equivalent to calling "g.aug_set" "expr",
1037 * "value". "name" will be the nodeset containing that
1040 * On success this returns a pair containing the number of
1041 * nodes in the nodeset, and a boolean flag if a node was
1044 * @throws LibGuestFSException
1046 public IntBool aug_defnode (String name, String expr, String val)
1047 throws LibGuestFSException
1050 throw new LibGuestFSException ("aug_defnode: handle is closed");
1051 return _aug_defnode (g, name, expr, val);
1053 private native IntBool _aug_defnode (long g, String name, String expr, String val)
1054 throws LibGuestFSException;
1057 * look up the value of an Augeas path
1059 * Look up the value associated with "path". If "path"
1060 * matches exactly one node, the "value" is returned.
1062 * @throws LibGuestFSException
1064 public String aug_get (String path)
1065 throws LibGuestFSException
1068 throw new LibGuestFSException ("aug_get: handle is closed");
1069 return _aug_get (g, path);
1071 private native String _aug_get (long g, String path)
1072 throws LibGuestFSException;
1075 * set Augeas path to value
1077 * Set the value associated with "path" to "value".
1079 * @throws LibGuestFSException
1081 public void aug_set (String path, String val)
1082 throws LibGuestFSException
1085 throw new LibGuestFSException ("aug_set: handle is closed");
1086 _aug_set (g, path, val);
1088 private native void _aug_set (long g, String path, String val)
1089 throws LibGuestFSException;
1092 * insert a sibling Augeas node
1094 * Create a new sibling "label" for "path", inserting it
1095 * into the tree before or after "path" (depending on the
1096 * boolean flag "before").
1098 * "path" must match exactly one existing node in the tree,
1099 * and "label" must be a label, ie. not contain "/", "*" or
1100 * end with a bracketed index "[N]".
1102 * @throws LibGuestFSException
1104 public void aug_insert (String path, String label, boolean before)
1105 throws LibGuestFSException
1108 throw new LibGuestFSException ("aug_insert: handle is closed");
1109 _aug_insert (g, path, label, before);
1111 private native void _aug_insert (long g, String path, String label, boolean before)
1112 throws LibGuestFSException;
1115 * remove an Augeas path
1117 * Remove "path" and all of its children.
1119 * On success this returns the number of entries which were
1122 * @throws LibGuestFSException
1124 public int aug_rm (String path)
1125 throws LibGuestFSException
1128 throw new LibGuestFSException ("aug_rm: handle is closed");
1129 return _aug_rm (g, path);
1131 private native int _aug_rm (long g, String path)
1132 throws LibGuestFSException;
1137 * Move the node "src" to "dest". "src" must match exactly
1138 * one node. "dest" is overwritten if it exists.
1140 * @throws LibGuestFSException
1142 public void aug_mv (String src, String dest)
1143 throws LibGuestFSException
1146 throw new LibGuestFSException ("aug_mv: handle is closed");
1147 _aug_mv (g, src, dest);
1149 private native void _aug_mv (long g, String src, String dest)
1150 throws LibGuestFSException;
1153 * return Augeas nodes which match path
1155 * Returns a list of paths which match the path expression
1156 * "path". The returned paths are sufficiently qualified so
1157 * that they match exactly one node in the current tree.
1159 * @throws LibGuestFSException
1161 public String[] aug_match (String path)
1162 throws LibGuestFSException
1165 throw new LibGuestFSException ("aug_match: handle is closed");
1166 return _aug_match (g, path);
1168 private native String[] _aug_match (long g, String path)
1169 throws LibGuestFSException;
1172 * write all pending Augeas changes to disk
1174 * This writes all pending changes to disk.
1176 * The flags which were passed to "g.aug_init" affect
1177 * exactly how files are saved.
1179 * @throws LibGuestFSException
1181 public void aug_save ()
1182 throws LibGuestFSException
1185 throw new LibGuestFSException ("aug_save: handle is closed");
1188 private native void _aug_save (long g)
1189 throws LibGuestFSException;
1192 * load files into the tree
1194 * Load files into the tree.
1196 * See "aug_load" in the Augeas documentation for the full
1199 * @throws LibGuestFSException
1201 public void aug_load ()
1202 throws LibGuestFSException
1205 throw new LibGuestFSException ("aug_load: handle is closed");
1208 private native void _aug_load (long g)
1209 throws LibGuestFSException;
1212 * list Augeas nodes under a path
1214 * This is just a shortcut for listing "g.aug_match"
1215 * "path/*" and sorting the resulting nodes into
1216 * alphabetical order.
1218 * @throws LibGuestFSException
1220 public String[] aug_ls (String path)
1221 throws LibGuestFSException
1224 throw new LibGuestFSException ("aug_ls: handle is closed");
1225 return _aug_ls (g, path);
1227 private native String[] _aug_ls (long g, String path)
1228 throws LibGuestFSException;
1233 * Remove the single file "path".
1235 * @throws LibGuestFSException
1237 public void rm (String path)
1238 throws LibGuestFSException
1241 throw new LibGuestFSException ("rm: handle is closed");
1244 private native void _rm (long g, String path)
1245 throws LibGuestFSException;
1248 * remove a directory
1250 * Remove the single directory "path".
1252 * @throws LibGuestFSException
1254 public void rmdir (String path)
1255 throws LibGuestFSException
1258 throw new LibGuestFSException ("rmdir: handle is closed");
1261 private native void _rmdir (long g, String path)
1262 throws LibGuestFSException;
1265 * remove a file or directory recursively
1267 * Remove the file or directory "path", recursively
1268 * removing the contents if its a directory. This is like
1269 * the "rm -rf" shell command.
1271 * @throws LibGuestFSException
1273 public void rm_rf (String path)
1274 throws LibGuestFSException
1277 throw new LibGuestFSException ("rm_rf: handle is closed");
1280 private native void _rm_rf (long g, String path)
1281 throws LibGuestFSException;
1284 * create a directory
1286 * Create a directory named "path".
1288 * @throws LibGuestFSException
1290 public void mkdir (String path)
1291 throws LibGuestFSException
1294 throw new LibGuestFSException ("mkdir: handle is closed");
1297 private native void _mkdir (long g, String path)
1298 throws LibGuestFSException;
1301 * create a directory and parents
1303 * Create a directory named "path", creating any parent
1304 * directories as necessary. This is like the "mkdir -p"
1307 * @throws LibGuestFSException
1309 public void mkdir_p (String path)
1310 throws LibGuestFSException
1313 throw new LibGuestFSException ("mkdir_p: handle is closed");
1316 private native void _mkdir_p (long g, String path)
1317 throws LibGuestFSException;
1322 * Change the mode (permissions) of "path" to "mode". Only
1323 * numeric modes are supported.
1325 * @throws LibGuestFSException
1327 public void chmod (int mode, String path)
1328 throws LibGuestFSException
1331 throw new LibGuestFSException ("chmod: handle is closed");
1332 _chmod (g, mode, path);
1334 private native void _chmod (long g, int mode, String path)
1335 throws LibGuestFSException;
1338 * change file owner and group
1340 * Change the file owner to "owner" and group to "group".
1342 * Only numeric uid and gid are supported. If you want to
1343 * use names, you will need to locate and parse the
1344 * password file yourself (Augeas support makes this
1347 * @throws LibGuestFSException
1349 public void chown (int owner, int group, String path)
1350 throws LibGuestFSException
1353 throw new LibGuestFSException ("chown: handle is closed");
1354 _chown (g, owner, group, path);
1356 private native void _chown (long g, int owner, int group, String path)
1357 throws LibGuestFSException;
1360 * test if file or directory exists
1362 * This returns "true" if and only if there is a file,
1363 * directory (or anything) with the given "path" name.
1365 * See also "g.is_file", "g.is_dir", "g.stat".
1367 * @throws LibGuestFSException
1369 public boolean exists (String path)
1370 throws LibGuestFSException
1373 throw new LibGuestFSException ("exists: handle is closed");
1374 return _exists (g, path);
1376 private native boolean _exists (long g, String path)
1377 throws LibGuestFSException;
1380 * test if file exists
1382 * This returns "true" if and only if there is a file with
1383 * the given "path" name. Note that it returns false for
1384 * other objects like directories.
1386 * See also "g.stat".
1388 * @throws LibGuestFSException
1390 public boolean is_file (String path)
1391 throws LibGuestFSException
1394 throw new LibGuestFSException ("is_file: handle is closed");
1395 return _is_file (g, path);
1397 private native boolean _is_file (long g, String path)
1398 throws LibGuestFSException;
1401 * test if file exists
1403 * This returns "true" if and only if there is a directory
1404 * with the given "path" name. Note that it returns false
1405 * for other objects like files.
1407 * See also "g.stat".
1409 * @throws LibGuestFSException
1411 public boolean is_dir (String path)
1412 throws LibGuestFSException
1415 throw new LibGuestFSException ("is_dir: handle is closed");
1416 return _is_dir (g, path);
1418 private native boolean _is_dir (long g, String path)
1419 throws LibGuestFSException;
1422 * create an LVM physical volume
1424 * This creates an LVM physical volume on the named
1425 * "device", where "device" should usually be a partition
1426 * name such as "/dev/sda1".
1428 * @throws LibGuestFSException
1430 public void pvcreate (String device)
1431 throws LibGuestFSException
1434 throw new LibGuestFSException ("pvcreate: handle is closed");
1435 _pvcreate (g, device);
1437 private native void _pvcreate (long g, String device)
1438 throws LibGuestFSException;
1441 * create an LVM volume group
1443 * This creates an LVM volume group called "volgroup" from
1444 * the non-empty list of physical volumes "physvols".
1446 * @throws LibGuestFSException
1448 public void vgcreate (String volgroup, String[] physvols)
1449 throws LibGuestFSException
1452 throw new LibGuestFSException ("vgcreate: handle is closed");
1453 _vgcreate (g, volgroup, physvols);
1455 private native void _vgcreate (long g, String volgroup, String[] physvols)
1456 throws LibGuestFSException;
1459 * create an LVM volume group
1461 * This creates an LVM volume group called "logvol" on the
1462 * volume group "volgroup", with "size" megabytes.
1464 * @throws LibGuestFSException
1466 public void lvcreate (String logvol, String volgroup, int mbytes)
1467 throws LibGuestFSException
1470 throw new LibGuestFSException ("lvcreate: handle is closed");
1471 _lvcreate (g, logvol, volgroup, mbytes);
1473 private native void _lvcreate (long g, String logvol, String volgroup, int mbytes)
1474 throws LibGuestFSException;
1479 * This creates a filesystem on "device" (usually a
1480 * partition or LVM logical volume). The filesystem type is
1481 * "fstype", for example "ext3".
1483 * @throws LibGuestFSException
1485 public void mkfs (String fstype, String device)
1486 throws LibGuestFSException
1489 throw new LibGuestFSException ("mkfs: handle is closed");
1490 _mkfs (g, fstype, device);
1492 private native void _mkfs (long g, String fstype, String device)
1493 throws LibGuestFSException;
1496 * create partitions on a block device
1498 * This is a direct interface to the sfdisk(8) program for
1499 * creating partitions on block devices.
1501 * "device" should be a block device, for example
1504 * "cyls", "heads" and "sectors" are the number of
1505 * cylinders, heads and sectors on the device, which are
1506 * passed directly to sfdisk as the *-C*, *-H* and *-S*
1507 * parameters. If you pass 0 for any of these, then the
1508 * corresponding parameter is omitted. Usually for 'large'
1509 * disks, you can just pass 0 for these, but for small
1510 * (floppy-sized) disks, sfdisk (or rather, the kernel)
1511 * cannot work out the right geometry and you will need to
1514 * "lines" is a list of lines that we feed to "sfdisk". For
1515 * more information refer to the sfdisk(8) manpage.
1517 * To create a single partition occupying the whole disk,
1518 * you would pass "lines" as a single element list, when
1519 * the single element being the string "," (comma).
1521 * See also: "g.sfdisk_l", "g.sfdisk_N"
1523 * This command is dangerous. Without careful use you can
1524 * easily destroy all your data.
1526 * @throws LibGuestFSException
1528 public void sfdisk (String device, int cyls, int heads, int sectors, String[] lines)
1529 throws LibGuestFSException
1532 throw new LibGuestFSException ("sfdisk: handle is closed");
1533 _sfdisk (g, device, cyls, heads, sectors, lines);
1535 private native void _sfdisk (long g, String device, int cyls, int heads, int sectors, String[] lines)
1536 throws LibGuestFSException;
1541 * This call creates a file called "path". The contents of
1542 * the file is the string "content" (which can contain any
1543 * 8 bit data), with length "size".
1545 * As a special case, if "size" is 0 then the length is
1546 * calculated using "strlen" (so in this case the content
1547 * cannot contain embedded ASCII NULs).
1549 * *NB.* Owing to a bug, writing content containing ASCII
1550 * NUL characters does *not* work, even if the length is
1551 * specified. We hope to resolve this bug in a future
1552 * version. In the meantime use "g.upload".
1554 * Because of the message protocol, there is a transfer
1555 * limit of somewhere between 2MB and 4MB. To transfer
1556 * large files you should use FTP.
1558 * @throws LibGuestFSException
1560 public void write_file (String path, String content, int size)
1561 throws LibGuestFSException
1564 throw new LibGuestFSException ("write_file: handle is closed");
1565 _write_file (g, path, content, size);
1567 private native void _write_file (long g, String path, String content, int size)
1568 throws LibGuestFSException;
1571 * unmount a filesystem
1573 * This unmounts the given filesystem. The filesystem may
1574 * be specified either by its mountpoint (path) or the
1575 * device which contains the filesystem.
1577 * @throws LibGuestFSException
1579 public void umount (String pathordevice)
1580 throws LibGuestFSException
1583 throw new LibGuestFSException ("umount: handle is closed");
1584 _umount (g, pathordevice);
1586 private native void _umount (long g, String pathordevice)
1587 throws LibGuestFSException;
1590 * show mounted filesystems
1592 * This returns the list of currently mounted filesystems.
1593 * It returns the list of devices (eg. "/dev/sda1",
1596 * Some internal mounts are not shown.
1598 * @throws LibGuestFSException
1600 public String[] mounts ()
1601 throws LibGuestFSException
1604 throw new LibGuestFSException ("mounts: handle is closed");
1607 private native String[] _mounts (long g)
1608 throws LibGuestFSException;
1611 * unmount all filesystems
1613 * This unmounts all mounted filesystems.
1615 * Some internal mounts are not unmounted by this call.
1617 * @throws LibGuestFSException
1619 public void umount_all ()
1620 throws LibGuestFSException
1623 throw new LibGuestFSException ("umount_all: handle is closed");
1626 private native void _umount_all (long g)
1627 throws LibGuestFSException;
1630 * remove all LVM LVs, VGs and PVs
1632 * This command removes all LVM logical volumes, volume
1633 * groups and physical volumes.
1635 * This command is dangerous. Without careful use you can
1636 * easily destroy all your data.
1638 * @throws LibGuestFSException
1640 public void lvm_remove_all ()
1641 throws LibGuestFSException
1644 throw new LibGuestFSException ("lvm_remove_all: handle is closed");
1645 _lvm_remove_all (g);
1647 private native void _lvm_remove_all (long g)
1648 throws LibGuestFSException;
1651 * determine file type
1653 * This call uses the standard file(1) command to determine
1654 * the type or contents of the file. This also works on
1655 * devices, for example to find out whether a partition
1656 * contains a filesystem.
1658 * The exact command which runs is "file -bsL path". Note
1659 * in particular that the filename is not prepended to the
1660 * output (the "-b" option).
1662 * @throws LibGuestFSException
1664 public String file (String path)
1665 throws LibGuestFSException
1668 throw new LibGuestFSException ("file: handle is closed");
1669 return _file (g, path);
1671 private native String _file (long g, String path)
1672 throws LibGuestFSException;
1675 * run a command from the guest filesystem
1677 * This call runs a command from the guest filesystem. The
1678 * filesystem must be mounted, and must contain a
1679 * compatible operating system (ie. something Linux, with
1680 * the same or compatible processor architecture).
1682 * The single parameter is an argv-style list of arguments.
1683 * The first element is the name of the program to run.
1684 * Subsequent elements are parameters. The list must be
1685 * non-empty (ie. must contain a program name).
1687 * The return value is anything printed to *stdout* by the
1690 * If the command returns a non-zero exit status, then this
1691 * function returns an error message. The error message
1692 * string is the content of *stderr* from the command.
1694 * The $PATH environment variable will contain at least
1695 * "/usr/bin" and "/bin". If you require a program from
1696 * another location, you should provide the full path in
1697 * the first parameter.
1699 * Shared libraries and data files required by the program
1700 * must be available on filesystems which are mounted in
1701 * the correct places. It is the caller's responsibility to
1702 * ensure all filesystems that are needed are mounted at
1703 * the right locations.
1705 * Because of the message protocol, there is a transfer
1706 * limit of somewhere between 2MB and 4MB. To transfer
1707 * large files you should use FTP.
1709 * @throws LibGuestFSException
1711 public String command (String[] arguments)
1712 throws LibGuestFSException
1715 throw new LibGuestFSException ("command: handle is closed");
1716 return _command (g, arguments);
1718 private native String _command (long g, String[] arguments)
1719 throws LibGuestFSException;
1722 * run a command, returning lines
1724 * This is the same as "g.command", but splits the result
1725 * into a list of lines.
1727 * Because of the message protocol, there is a transfer
1728 * limit of somewhere between 2MB and 4MB. To transfer
1729 * large files you should use FTP.
1731 * @throws LibGuestFSException
1733 public String[] command_lines (String[] arguments)
1734 throws LibGuestFSException
1737 throw new LibGuestFSException ("command_lines: handle is closed");
1738 return _command_lines (g, arguments);
1740 private native String[] _command_lines (long g, String[] arguments)
1741 throws LibGuestFSException;
1744 * get file information
1746 * Returns file information for the given "path".
1748 * This is the same as the stat(2) system call.
1750 * @throws LibGuestFSException
1752 public Stat stat (String path)
1753 throws LibGuestFSException
1756 throw new LibGuestFSException ("stat: handle is closed");
1757 return _stat (g, path);
1759 private native Stat _stat (long g, String path)
1760 throws LibGuestFSException;
1763 * get file information for a symbolic link
1765 * Returns file information for the given "path".
1767 * This is the same as "g.stat" except that if "path" is a
1768 * symbolic link, then the link is stat-ed, not the file it
1771 * This is the same as the lstat(2) system call.
1773 * @throws LibGuestFSException
1775 public Stat lstat (String path)
1776 throws LibGuestFSException
1779 throw new LibGuestFSException ("lstat: handle is closed");
1780 return _lstat (g, path);
1782 private native Stat _lstat (long g, String path)
1783 throws LibGuestFSException;
1786 * get file system statistics
1788 * Returns file system statistics for any mounted file
1789 * system. "path" should be a file or directory in the
1790 * mounted file system (typically it is the mount point
1791 * itself, but it doesn't need to be).
1793 * This is the same as the statvfs(2) system call.
1795 * @throws LibGuestFSException
1797 public StatVFS statvfs (String path)
1798 throws LibGuestFSException
1801 throw new LibGuestFSException ("statvfs: handle is closed");
1802 return _statvfs (g, path);
1804 private native StatVFS _statvfs (long g, String path)
1805 throws LibGuestFSException;
1808 * get ext2/ext3/ext4 superblock details
1810 * This returns the contents of the ext2, ext3 or ext4
1811 * filesystem superblock on "device".
1813 * It is the same as running "tune2fs -l device". See
1814 * tune2fs(8) manpage for more details. The list of fields
1815 * returned isn't clearly defined, and depends on both the
1816 * version of "tune2fs" that libguestfs was built against,
1817 * and the filesystem itself.
1819 * @throws LibGuestFSException
1821 public HashMap<String,String> tune2fs_l (String device)
1822 throws LibGuestFSException
1825 throw new LibGuestFSException ("tune2fs_l: handle is closed");
1826 return _tune2fs_l (g, device);
1828 private native HashMap<String,String> _tune2fs_l (long g, String device)
1829 throws LibGuestFSException;
1832 * set block device to read-only
1834 * Sets the block device named "device" to read-only.
1836 * This uses the blockdev(8) command.
1838 * @throws LibGuestFSException
1840 public void blockdev_setro (String device)
1841 throws LibGuestFSException
1844 throw new LibGuestFSException ("blockdev_setro: handle is closed");
1845 _blockdev_setro (g, device);
1847 private native void _blockdev_setro (long g, String device)
1848 throws LibGuestFSException;
1851 * set block device to read-write
1853 * Sets the block device named "device" to read-write.
1855 * This uses the blockdev(8) command.
1857 * @throws LibGuestFSException
1859 public void blockdev_setrw (String device)
1860 throws LibGuestFSException
1863 throw new LibGuestFSException ("blockdev_setrw: handle is closed");
1864 _blockdev_setrw (g, device);
1866 private native void _blockdev_setrw (long g, String device)
1867 throws LibGuestFSException;
1870 * is block device set to read-only
1872 * Returns a boolean indicating if the block device is
1873 * read-only (true if read-only, false if not).
1875 * This uses the blockdev(8) command.
1877 * @throws LibGuestFSException
1879 public boolean blockdev_getro (String device)
1880 throws LibGuestFSException
1883 throw new LibGuestFSException ("blockdev_getro: handle is closed");
1884 return _blockdev_getro (g, device);
1886 private native boolean _blockdev_getro (long g, String device)
1887 throws LibGuestFSException;
1890 * get sectorsize of block device
1892 * This returns the size of sectors on a block device.
1893 * Usually 512, but can be larger for modern devices.
1895 * (Note, this is not the size in sectors, use
1896 * "g.blockdev_getsz" for that).
1898 * This uses the blockdev(8) command.
1900 * @throws LibGuestFSException
1902 public int blockdev_getss (String device)
1903 throws LibGuestFSException
1906 throw new LibGuestFSException ("blockdev_getss: handle is closed");
1907 return _blockdev_getss (g, device);
1909 private native int _blockdev_getss (long g, String device)
1910 throws LibGuestFSException;
1913 * get blocksize of block device
1915 * This returns the block size of a device.
1917 * (Note this is different from both *size in blocks* and
1918 * *filesystem block size*).
1920 * This uses the blockdev(8) command.
1922 * @throws LibGuestFSException
1924 public int blockdev_getbsz (String device)
1925 throws LibGuestFSException
1928 throw new LibGuestFSException ("blockdev_getbsz: handle is closed");
1929 return _blockdev_getbsz (g, device);
1931 private native int _blockdev_getbsz (long g, String device)
1932 throws LibGuestFSException;
1935 * set blocksize of block device
1937 * This sets the block size of a device.
1939 * (Note this is different from both *size in blocks* and
1940 * *filesystem block size*).
1942 * This uses the blockdev(8) command.
1944 * @throws LibGuestFSException
1946 public void blockdev_setbsz (String device, int blocksize)
1947 throws LibGuestFSException
1950 throw new LibGuestFSException ("blockdev_setbsz: handle is closed");
1951 _blockdev_setbsz (g, device, blocksize);
1953 private native void _blockdev_setbsz (long g, String device, int blocksize)
1954 throws LibGuestFSException;
1957 * get total size of device in 512-byte sectors
1959 * This returns the size of the device in units of 512-byte
1960 * sectors (even if the sectorsize isn't 512 bytes ...
1963 * See also "g.blockdev_getss" for the real sector size of
1964 * the device, and "g.blockdev_getsize64" for the more
1965 * useful *size in bytes*.
1967 * This uses the blockdev(8) command.
1969 * @throws LibGuestFSException
1971 public long blockdev_getsz (String device)
1972 throws LibGuestFSException
1975 throw new LibGuestFSException ("blockdev_getsz: handle is closed");
1976 return _blockdev_getsz (g, device);
1978 private native long _blockdev_getsz (long g, String device)
1979 throws LibGuestFSException;
1982 * get total size of device in bytes
1984 * This returns the size of the device in bytes.
1986 * See also "g.blockdev_getsz".
1988 * This uses the blockdev(8) command.
1990 * @throws LibGuestFSException
1992 public long blockdev_getsize64 (String device)
1993 throws LibGuestFSException
1996 throw new LibGuestFSException ("blockdev_getsize64: handle is closed");
1997 return _blockdev_getsize64 (g, device);
1999 private native long _blockdev_getsize64 (long g, String device)
2000 throws LibGuestFSException;
2003 * flush device buffers
2005 * This tells the kernel to flush internal buffers
2006 * associated with "device".
2008 * This uses the blockdev(8) command.
2010 * @throws LibGuestFSException
2012 public void blockdev_flushbufs (String device)
2013 throws LibGuestFSException
2016 throw new LibGuestFSException ("blockdev_flushbufs: handle is closed");
2017 _blockdev_flushbufs (g, device);
2019 private native void _blockdev_flushbufs (long g, String device)
2020 throws LibGuestFSException;
2023 * reread partition table
2025 * Reread the partition table on "device".
2027 * This uses the blockdev(8) command.
2029 * @throws LibGuestFSException
2031 public void blockdev_rereadpt (String device)
2032 throws LibGuestFSException
2035 throw new LibGuestFSException ("blockdev_rereadpt: handle is closed");
2036 _blockdev_rereadpt (g, device);
2038 private native void _blockdev_rereadpt (long g, String device)
2039 throws LibGuestFSException;
2042 * upload a file from the local machine
2044 * Upload local file "filename" to "remotefilename" on the
2047 * "filename" can also be a named pipe.
2049 * See also "g.download".
2051 * @throws LibGuestFSException
2053 public void upload (String filename, String remotefilename)
2054 throws LibGuestFSException
2057 throw new LibGuestFSException ("upload: handle is closed");
2058 _upload (g, filename, remotefilename);
2060 private native void _upload (long g, String filename, String remotefilename)
2061 throws LibGuestFSException;
2064 * download a file to the local machine
2066 * Download file "remotefilename" and save it as "filename"
2067 * on the local machine.
2069 * "filename" can also be a named pipe.
2071 * See also "g.upload", "g.cat".
2073 * @throws LibGuestFSException
2075 public void download (String remotefilename, String filename)
2076 throws LibGuestFSException
2079 throw new LibGuestFSException ("download: handle is closed");
2080 _download (g, remotefilename, filename);
2082 private native void _download (long g, String remotefilename, String filename)
2083 throws LibGuestFSException;
2086 * compute MD5, SHAx or CRC checksum of file
2088 * This call computes the MD5, SHAx or CRC checksum of the
2089 * file named "path".
2091 * The type of checksum to compute is given by the
2092 * "csumtype" parameter which must have one of the
2096 * Compute the cyclic redundancy check (CRC) specified
2097 * by POSIX for the "cksum" command.
2100 * Compute the MD5 hash (using the "md5sum" program).
2103 * Compute the SHA1 hash (using the "sha1sum" program).
2106 * Compute the SHA224 hash (using the "sha224sum"
2110 * Compute the SHA256 hash (using the "sha256sum"
2114 * Compute the SHA384 hash (using the "sha384sum"
2118 * Compute the SHA512 hash (using the "sha512sum"
2121 * The checksum is returned as a printable string.
2123 * @throws LibGuestFSException
2125 public String checksum (String csumtype, String path)
2126 throws LibGuestFSException
2129 throw new LibGuestFSException ("checksum: handle is closed");
2130 return _checksum (g, csumtype, path);
2132 private native String _checksum (long g, String csumtype, String path)
2133 throws LibGuestFSException;
2136 * unpack tarfile to directory
2138 * This command uploads and unpacks local file "tarfile"
2139 * (an *uncompressed* tar file) into "directory".
2141 * To upload a compressed tarball, use "g.tgz_in".
2143 * @throws LibGuestFSException
2145 public void tar_in (String tarfile, String directory)
2146 throws LibGuestFSException
2149 throw new LibGuestFSException ("tar_in: handle is closed");
2150 _tar_in (g, tarfile, directory);
2152 private native void _tar_in (long g, String tarfile, String directory)
2153 throws LibGuestFSException;
2156 * pack directory into tarfile
2158 * This command packs the contents of "directory" and
2159 * downloads it to local file "tarfile".
2161 * To download a compressed tarball, use "g.tgz_out".
2163 * @throws LibGuestFSException
2165 public void tar_out (String directory, String tarfile)
2166 throws LibGuestFSException
2169 throw new LibGuestFSException ("tar_out: handle is closed");
2170 _tar_out (g, directory, tarfile);
2172 private native void _tar_out (long g, String directory, String tarfile)
2173 throws LibGuestFSException;
2176 * unpack compressed tarball to directory
2178 * This command uploads and unpacks local file "tarball" (a
2179 * *gzip compressed* tar file) into "directory".
2181 * To upload an uncompressed tarball, use "g.tar_in".
2183 * @throws LibGuestFSException
2185 public void tgz_in (String tarball, String directory)
2186 throws LibGuestFSException
2189 throw new LibGuestFSException ("tgz_in: handle is closed");
2190 _tgz_in (g, tarball, directory);
2192 private native void _tgz_in (long g, String tarball, String directory)
2193 throws LibGuestFSException;
2196 * pack directory into compressed tarball
2198 * This command packs the contents of "directory" and
2199 * downloads it to local file "tarball".
2201 * To download an uncompressed tarball, use "g.tar_out".
2203 * @throws LibGuestFSException
2205 public void tgz_out (String directory, String tarball)
2206 throws LibGuestFSException
2209 throw new LibGuestFSException ("tgz_out: handle is closed");
2210 _tgz_out (g, directory, tarball);
2212 private native void _tgz_out (long g, String directory, String tarball)
2213 throws LibGuestFSException;
2216 * mount a guest disk, read-only
2218 * This is the same as the "g.mount" command, but it mounts
2219 * the filesystem with the read-only (*-o ro*) flag.
2221 * @throws LibGuestFSException
2223 public void mount_ro (String device, String mountpoint)
2224 throws LibGuestFSException
2227 throw new LibGuestFSException ("mount_ro: handle is closed");
2228 _mount_ro (g, device, mountpoint);
2230 private native void _mount_ro (long g, String device, String mountpoint)
2231 throws LibGuestFSException;
2234 * mount a guest disk with mount options
2236 * This is the same as the "g.mount" command, but it allows
2237 * you to set the mount options as for the mount(8) *-o*
2240 * @throws LibGuestFSException
2242 public void mount_options (String options, String device, String mountpoint)
2243 throws LibGuestFSException
2246 throw new LibGuestFSException ("mount_options: handle is closed");
2247 _mount_options (g, options, device, mountpoint);
2249 private native void _mount_options (long g, String options, String device, String mountpoint)
2250 throws LibGuestFSException;
2253 * mount a guest disk with mount options and vfstype
2255 * This is the same as the "g.mount" command, but it allows
2256 * you to set both the mount options and the vfstype as for
2257 * the mount(8) *-o* and *-t* flags.
2259 * @throws LibGuestFSException
2261 public void mount_vfs (String options, String vfstype, String device, String mountpoint)
2262 throws LibGuestFSException
2265 throw new LibGuestFSException ("mount_vfs: handle is closed");
2266 _mount_vfs (g, options, vfstype, device, mountpoint);
2268 private native void _mount_vfs (long g, String options, String vfstype, String device, String mountpoint)
2269 throws LibGuestFSException;
2272 * debugging and internals
2274 * The "g.debug" command exposes some internals of
2275 * "guestfsd" (the guestfs daemon) that runs inside the
2278 * There is no comprehensive help for this command. You
2279 * have to look at the file "daemon/debug.c" in the
2280 * libguestfs source to find out what you can do.
2282 * @throws LibGuestFSException
2284 public String debug (String subcmd, String[] extraargs)
2285 throws LibGuestFSException
2288 throw new LibGuestFSException ("debug: handle is closed");
2289 return _debug (g, subcmd, extraargs);
2291 private native String _debug (long g, String subcmd, String[] extraargs)
2292 throws LibGuestFSException;
2295 * remove an LVM logical volume
2297 * Remove an LVM logical volume "device", where "device" is
2298 * the path to the LV, such as "/dev/VG/LV".
2300 * You can also remove all LVs in a volume group by
2301 * specifying the VG name, "/dev/VG".
2303 * @throws LibGuestFSException
2305 public void lvremove (String device)
2306 throws LibGuestFSException
2309 throw new LibGuestFSException ("lvremove: handle is closed");
2310 _lvremove (g, device);
2312 private native void _lvremove (long g, String device)
2313 throws LibGuestFSException;
2316 * remove an LVM volume group
2318 * Remove an LVM volume group "vgname", (for example "VG").
2320 * This also forcibly removes all logical volumes in the
2321 * volume group (if any).
2323 * @throws LibGuestFSException
2325 public void vgremove (String vgname)
2326 throws LibGuestFSException
2329 throw new LibGuestFSException ("vgremove: handle is closed");
2330 _vgremove (g, vgname);
2332 private native void _vgremove (long g, String vgname)
2333 throws LibGuestFSException;
2336 * remove an LVM physical volume
2338 * This wipes a physical volume "device" so that LVM will
2339 * no longer recognise it.
2341 * The implementation uses the "pvremove" command which
2342 * refuses to wipe physical volumes that contain any volume
2343 * groups, so you have to remove those first.
2345 * @throws LibGuestFSException
2347 public void pvremove (String device)
2348 throws LibGuestFSException
2351 throw new LibGuestFSException ("pvremove: handle is closed");
2352 _pvremove (g, device);
2354 private native void _pvremove (long g, String device)
2355 throws LibGuestFSException;
2358 * set the ext2/3/4 filesystem label
2360 * This sets the ext2/3/4 filesystem label of the
2361 * filesystem on "device" to "label". Filesystem labels are
2362 * limited to 16 characters.
2364 * You can use either "g.tune2fs_l" or "g.get_e2label" to
2365 * return the existing label on a filesystem.
2367 * @throws LibGuestFSException
2369 public void set_e2label (String device, String label)
2370 throws LibGuestFSException
2373 throw new LibGuestFSException ("set_e2label: handle is closed");
2374 _set_e2label (g, device, label);
2376 private native void _set_e2label (long g, String device, String label)
2377 throws LibGuestFSException;
2380 * get the ext2/3/4 filesystem label
2382 * This returns the ext2/3/4 filesystem label of the
2383 * filesystem on "device".
2385 * @throws LibGuestFSException
2387 public String get_e2label (String device)
2388 throws LibGuestFSException
2391 throw new LibGuestFSException ("get_e2label: handle is closed");
2392 return _get_e2label (g, device);
2394 private native String _get_e2label (long g, String device)
2395 throws LibGuestFSException;
2398 * set the ext2/3/4 filesystem UUID
2400 * This sets the ext2/3/4 filesystem UUID of the filesystem
2401 * on "device" to "uuid". The format of the UUID and
2402 * alternatives such as "clear", "random" and "time" are
2403 * described in the tune2fs(8) manpage.
2405 * You can use either "g.tune2fs_l" or "g.get_e2uuid" to
2406 * return the existing UUID of a filesystem.
2408 * @throws LibGuestFSException
2410 public void set_e2uuid (String device, String uuid)
2411 throws LibGuestFSException
2414 throw new LibGuestFSException ("set_e2uuid: handle is closed");
2415 _set_e2uuid (g, device, uuid);
2417 private native void _set_e2uuid (long g, String device, String uuid)
2418 throws LibGuestFSException;
2421 * get the ext2/3/4 filesystem UUID
2423 * This returns the ext2/3/4 filesystem UUID of the
2424 * filesystem on "device".
2426 * @throws LibGuestFSException
2428 public String get_e2uuid (String device)
2429 throws LibGuestFSException
2432 throw new LibGuestFSException ("get_e2uuid: handle is closed");
2433 return _get_e2uuid (g, device);
2435 private native String _get_e2uuid (long g, String device)
2436 throws LibGuestFSException;
2439 * run the filesystem checker
2441 * This runs the filesystem checker (fsck) on "device"
2442 * which should have filesystem type "fstype".
2444 * The returned integer is the status. See fsck(8) for the
2445 * list of status codes from "fsck".
2449 * * Multiple status codes can be summed together.
2451 * * A non-zero return code can mean "success", for
2452 * example if errors have been corrected on the
2455 * * Checking or repairing NTFS volumes is not supported
2458 * This command is entirely equivalent to running "fsck -a
2459 * -t fstype device".
2461 * @throws LibGuestFSException
2463 public int fsck (String fstype, String device)
2464 throws LibGuestFSException
2467 throw new LibGuestFSException ("fsck: handle is closed");
2468 return _fsck (g, fstype, device);
2470 private native int _fsck (long g, String fstype, String device)
2471 throws LibGuestFSException;
2474 * write zeroes to the device
2476 * This command writes zeroes over the first few blocks of
2479 * How many blocks are zeroed isn't specified (but it's
2480 * *not* enough to securely wipe the device). It should be
2481 * sufficient to remove any partition tables, filesystem
2482 * superblocks and so on.
2484 * @throws LibGuestFSException
2486 public void zero (String device)
2487 throws LibGuestFSException
2490 throw new LibGuestFSException ("zero: handle is closed");
2493 private native void _zero (long g, String device)
2494 throws LibGuestFSException;
2499 * This command installs GRUB (the Grand Unified
2500 * Bootloader) on "device", with the root directory being
2503 * @throws LibGuestFSException
2505 public void grub_install (String root, String device)
2506 throws LibGuestFSException
2509 throw new LibGuestFSException ("grub_install: handle is closed");
2510 _grub_install (g, root, device);
2512 private native void _grub_install (long g, String root, String device)
2513 throws LibGuestFSException;
2518 * This copies a file from "src" to "dest" where "dest" is
2519 * either a destination filename or destination directory.
2521 * @throws LibGuestFSException
2523 public void cp (String src, String dest)
2524 throws LibGuestFSException
2527 throw new LibGuestFSException ("cp: handle is closed");
2530 private native void _cp (long g, String src, String dest)
2531 throws LibGuestFSException;
2534 * copy a file or directory recursively
2536 * This copies a file or directory from "src" to "dest"
2537 * recursively using the "cp -a" command.
2539 * @throws LibGuestFSException
2541 public void cp_a (String src, String dest)
2542 throws LibGuestFSException
2545 throw new LibGuestFSException ("cp_a: handle is closed");
2546 _cp_a (g, src, dest);
2548 private native void _cp_a (long g, String src, String dest)
2549 throws LibGuestFSException;
2554 * This moves a file from "src" to "dest" where "dest" is
2555 * either a destination filename or destination directory.
2557 * @throws LibGuestFSException
2559 public void mv (String src, String dest)
2560 throws LibGuestFSException
2563 throw new LibGuestFSException ("mv: handle is closed");
2566 private native void _mv (long g, String src, String dest)
2567 throws LibGuestFSException;
2570 * drop kernel page cache, dentries and inodes
2572 * This instructs the guest kernel to drop its page cache,
2573 * and/or dentries and inode caches. The parameter
2574 * "whattodrop" tells the kernel what precisely to drop,
2575 * see <http://linux-mm.org/Drop_Caches>
2577 * Setting "whattodrop" to 3 should drop everything.
2579 * This automatically calls sync(2) before the operation,
2580 * so that the maximum guest memory is freed.
2582 * @throws LibGuestFSException
2584 public void drop_caches (int whattodrop)
2585 throws LibGuestFSException
2588 throw new LibGuestFSException ("drop_caches: handle is closed");
2589 _drop_caches (g, whattodrop);
2591 private native void _drop_caches (long g, int whattodrop)
2592 throws LibGuestFSException;
2595 * return kernel messages
2597 * This returns the kernel messages ("dmesg" output) from
2598 * the guest kernel. This is sometimes useful for extended
2599 * debugging of problems.
2601 * Another way to get the same information is to enable
2602 * verbose messages with "g.set_verbose" or by setting the
2603 * environment variable "LIBGUESTFS_DEBUG=1" before running
2606 * @throws LibGuestFSException
2608 public String dmesg ()
2609 throws LibGuestFSException
2612 throw new LibGuestFSException ("dmesg: handle is closed");
2615 private native String _dmesg (long g)
2616 throws LibGuestFSException;
2619 * ping the guest daemon
2621 * This is a test probe into the guestfs daemon running
2622 * inside the qemu subprocess. Calling this function checks
2623 * that the daemon responds to the ping message, without
2624 * affecting the daemon or attached block device(s) in any
2627 * @throws LibGuestFSException
2629 public void ping_daemon ()
2630 throws LibGuestFSException
2633 throw new LibGuestFSException ("ping_daemon: handle is closed");
2636 private native void _ping_daemon (long g)
2637 throws LibGuestFSException;
2640 * test if two files have equal contents
2642 * This compares the two files "file1" and "file2" and
2643 * returns true if their content is exactly equal, or false
2646 * The external cmp(1) program is used for the comparison.
2648 * @throws LibGuestFSException
2650 public boolean equal (String file1, String file2)
2651 throws LibGuestFSException
2654 throw new LibGuestFSException ("equal: handle is closed");
2655 return _equal (g, file1, file2);
2657 private native boolean _equal (long g, String file1, String file2)
2658 throws LibGuestFSException;
2661 * print the printable strings in a file
2663 * This runs the strings(1) command on a file and returns
2664 * the list of printable strings found.
2666 * Because of the message protocol, there is a transfer
2667 * limit of somewhere between 2MB and 4MB. To transfer
2668 * large files you should use FTP.
2670 * @throws LibGuestFSException
2672 public String[] strings (String path)
2673 throws LibGuestFSException
2676 throw new LibGuestFSException ("strings: handle is closed");
2677 return _strings (g, path);
2679 private native String[] _strings (long g, String path)
2680 throws LibGuestFSException;
2683 * print the printable strings in a file
2685 * This is like the "g.strings" command, but allows you to
2686 * specify the encoding.
2688 * See the strings(1) manpage for the full list of
2691 * Commonly useful encodings are "l" (lower case L) which
2692 * will show strings inside Windows/x86 files.
2694 * The returned strings are transcoded to UTF-8.
2696 * Because of the message protocol, there is a transfer
2697 * limit of somewhere between 2MB and 4MB. To transfer
2698 * large files you should use FTP.
2700 * @throws LibGuestFSException
2702 public String[] strings_e (String encoding, String path)
2703 throws LibGuestFSException
2706 throw new LibGuestFSException ("strings_e: handle is closed");
2707 return _strings_e (g, encoding, path);
2709 private native String[] _strings_e (long g, String encoding, String path)
2710 throws LibGuestFSException;
2713 * dump a file in hexadecimal
2715 * This runs "hexdump -C" on the given "path". The result
2716 * is the human-readable, canonical hex dump of the file.
2718 * Because of the message protocol, there is a transfer
2719 * limit of somewhere between 2MB and 4MB. To transfer
2720 * large files you should use FTP.
2722 * @throws LibGuestFSException
2724 public String hexdump (String path)
2725 throws LibGuestFSException
2728 throw new LibGuestFSException ("hexdump: handle is closed");
2729 return _hexdump (g, path);
2731 private native String _hexdump (long g, String path)
2732 throws LibGuestFSException;
2735 * zero unused inodes and disk blocks on ext2/3 filesystem
2737 * This runs the *zerofree* program on "device". This
2738 * program claims to zero unused inodes and disk blocks on
2739 * an ext2/3 filesystem, thus making it possible to
2740 * compress the filesystem more effectively.
2742 * You should not run this program if the filesystem is
2745 * It is possible that using this program can damage the
2746 * filesystem or data on the filesystem.
2748 * @throws LibGuestFSException
2750 public void zerofree (String device)
2751 throws LibGuestFSException
2754 throw new LibGuestFSException ("zerofree: handle is closed");
2755 _zerofree (g, device);
2757 private native void _zerofree (long g, String device)
2758 throws LibGuestFSException;
2761 * resize an LVM physical volume
2763 * This resizes (expands or shrinks) an existing LVM
2764 * physical volume to match the new size of the underlying
2767 * @throws LibGuestFSException
2769 public void pvresize (String device)
2770 throws LibGuestFSException
2773 throw new LibGuestFSException ("pvresize: handle is closed");
2774 _pvresize (g, device);
2776 private native void _pvresize (long g, String device)
2777 throws LibGuestFSException;
2780 * modify a single partition on a block device
2782 * This runs sfdisk(8) option to modify just the single
2783 * partition "n" (note: "n" counts from 1).
2785 * For other parameters, see "g.sfdisk". You should usually
2786 * pass 0 for the cyls/heads/sectors parameters.
2788 * This command is dangerous. Without careful use you can
2789 * easily destroy all your data.
2791 * @throws LibGuestFSException
2793 public void sfdisk_N (String device, int n, int cyls, int heads, int sectors, String line)
2794 throws LibGuestFSException
2797 throw new LibGuestFSException ("sfdisk_N: handle is closed");
2798 _sfdisk_N (g, device, n, cyls, heads, sectors, line);
2800 private native void _sfdisk_N (long g, String device, int n, int cyls, int heads, int sectors, String line)
2801 throws LibGuestFSException;
2804 * display the partition table
2806 * This displays the partition table on "device", in the
2807 * human-readable output of the sfdisk(8) command. It is
2808 * not intended to be parsed.
2810 * @throws LibGuestFSException
2812 public String sfdisk_l (String device)
2813 throws LibGuestFSException
2816 throw new LibGuestFSException ("sfdisk_l: handle is closed");
2817 return _sfdisk_l (g, device);
2819 private native String _sfdisk_l (long g, String device)
2820 throws LibGuestFSException;
2823 * display the kernel geometry
2825 * This displays the kernel's idea of the geometry of
2828 * The result is in human-readable format, and not designed
2831 * @throws LibGuestFSException
2833 public String sfdisk_kernel_geometry (String device)
2834 throws LibGuestFSException
2837 throw new LibGuestFSException ("sfdisk_kernel_geometry: handle is closed");
2838 return _sfdisk_kernel_geometry (g, device);
2840 private native String _sfdisk_kernel_geometry (long g, String device)
2841 throws LibGuestFSException;
2844 * display the disk geometry from the partition table
2846 * This displays the disk geometry of "device" read from
2847 * the partition table. Especially in the case where the
2848 * underlying block device has been resized, this can be
2849 * different from the kernel's idea of the geometry (see
2850 * "g.sfdisk_kernel_geometry").
2852 * The result is in human-readable format, and not designed
2855 * @throws LibGuestFSException
2857 public String sfdisk_disk_geometry (String device)
2858 throws LibGuestFSException
2861 throw new LibGuestFSException ("sfdisk_disk_geometry: handle is closed");
2862 return _sfdisk_disk_geometry (g, device);
2864 private native String _sfdisk_disk_geometry (long g, String device)
2865 throws LibGuestFSException;
2868 * activate or deactivate all volume groups
2870 * This command activates or (if "activate" is false)
2871 * deactivates all logical volumes in all volume groups. If
2872 * activated, then they are made known to the kernel, ie.
2873 * they appear as "/dev/mapper" devices. If deactivated,
2874 * then those devices disappear.
2876 * This command is the same as running "vgchange -a y|n"
2878 * @throws LibGuestFSException
2880 public void vg_activate_all (boolean activate)
2881 throws LibGuestFSException
2884 throw new LibGuestFSException ("vg_activate_all: handle is closed");
2885 _vg_activate_all (g, activate);
2887 private native void _vg_activate_all (long g, boolean activate)
2888 throws LibGuestFSException;
2891 * activate or deactivate some volume groups
2893 * This command activates or (if "activate" is false)
2894 * deactivates all logical volumes in the listed volume
2895 * groups "volgroups". If activated, then they are made
2896 * known to the kernel, ie. they appear as "/dev/mapper"
2897 * devices. If deactivated, then those devices disappear.
2899 * This command is the same as running "vgchange -a y|n
2902 * Note that if "volgroups" is an empty list then all
2903 * volume groups are activated or deactivated.
2905 * @throws LibGuestFSException
2907 public void vg_activate (boolean activate, String[] volgroups)
2908 throws LibGuestFSException
2911 throw new LibGuestFSException ("vg_activate: handle is closed");
2912 _vg_activate (g, activate, volgroups);
2914 private native void _vg_activate (long g, boolean activate, String[] volgroups)
2915 throws LibGuestFSException;
2918 * resize an LVM logical volume
2920 * This resizes (expands or shrinks) an existing LVM
2921 * logical volume to "mbytes". When reducing, data in the
2922 * reduced part is lost.
2924 * @throws LibGuestFSException
2926 public void lvresize (String device, int mbytes)
2927 throws LibGuestFSException
2930 throw new LibGuestFSException ("lvresize: handle is closed");
2931 _lvresize (g, device, mbytes);
2933 private native void _lvresize (long g, String device, int mbytes)
2934 throws LibGuestFSException;
2937 * resize an ext2/ext3 filesystem
2939 * This resizes an ext2 or ext3 filesystem to match the
2940 * size of the underlying device.
2942 * *Note:* It is sometimes required that you run
2943 * "g.e2fsck_f" on the "device" before calling this
2944 * command. For unknown reasons "resize2fs" sometimes gives
2945 * an error about this and sometimes not. In any case, it
2946 * is always safe to call "g.e2fsck_f" before calling this
2949 * @throws LibGuestFSException
2951 public void resize2fs (String device)
2952 throws LibGuestFSException
2955 throw new LibGuestFSException ("resize2fs: handle is closed");
2956 _resize2fs (g, device);
2958 private native void _resize2fs (long g, String device)
2959 throws LibGuestFSException;
2962 * find all files and directories
2964 * This command lists out all files and directories,
2965 * recursively, starting at "directory". It is essentially
2966 * equivalent to running the shell command "find directory
2967 * -print" but some post-processing happens on the output,
2970 * This returns a list of strings *without any prefix*.
2971 * Thus if the directory structure was:
2977 * then the returned list from "g.find" "/tmp" would be 4
2985 * If "directory" is not a directory, then this command
2988 * The returned list is sorted.
2990 * @throws LibGuestFSException
2992 public String[] find (String directory)
2993 throws LibGuestFSException
2996 throw new LibGuestFSException ("find: handle is closed");
2997 return _find (g, directory);
2999 private native String[] _find (long g, String directory)
3000 throws LibGuestFSException;
3003 * check an ext2/ext3 filesystem
3005 * This runs "e2fsck -p -f device", ie. runs the ext2/ext3
3006 * filesystem checker on "device", noninteractively ("-p"),
3007 * even if the filesystem appears to be clean ("-f").
3009 * This command is only needed because of "g.resize2fs"
3010 * (q.v.). Normally you should use "g.fsck".
3012 * @throws LibGuestFSException
3014 public void e2fsck_f (String device)
3015 throws LibGuestFSException
3018 throw new LibGuestFSException ("e2fsck_f: handle is closed");
3019 _e2fsck_f (g, device);
3021 private native void _e2fsck_f (long g, String device)
3022 throws LibGuestFSException;