Add 'readdir' call.
[libguestfs.git] / perl / lib / Sys / Guestfs.pm
index 8871b68..e624d55 100644 (file)
@@ -115,7 +115,8 @@ for whatever operations you want to perform (ie. read access if you
 just want to read the image or write access if you want to modify the
 image).
 
 just want to read the image or write access if you want to modify the
 image).
 
-This is equivalent to the qemu parameter C<-drive file=filename,cache=off>.
+This is equivalent to the qemu parameter
+C<-drive file=filename,cache=off,if=virtio>.
 
 Note that this call checks for the existence of C<filename>.  This
 stops you from specifying other types of drive which are supported
 
 Note that this call checks for the existence of C<filename>.  This
 stops you from specifying other types of drive which are supported
@@ -134,7 +135,7 @@ handle is closed.  We don't currently have any method to enable
 changes to be committed, although qemu can support this.
 
 This is equivalent to the qemu parameter
 changes to be committed, although qemu can support this.
 
 This is equivalent to the qemu parameter
-C<-drive file=filename,snapshot=on>.
+C<-drive file=filename,snapshot=on,if=virtio>.
 
 Note that this call checks for the existence of C<filename>.  This
 stops you from specifying other types of drive which are supported
 
 Note that this call checks for the existence of C<filename>.  This
 stops you from specifying other types of drive which are supported
@@ -500,6 +501,23 @@ There is no comprehensive help for this command.  You have
 to look at the file C<daemon/debug.c> in the libguestfs source
 to find out what you can do.
 
 to look at the file C<daemon/debug.c> in the libguestfs source
 to find out what you can do.
 
+=item $output = $h->df ();
+
+This command runs the C<df> command to report disk space used.
+
+This command is mostly useful for interactive sessions.  It
+is I<not> intended that you try to parse the output string.
+Use C<statvfs> from programs.
+
+=item $output = $h->df_h ();
+
+This command runs the C<df -h> command to report disk space used
+in human-readable format.
+
+This command is mostly useful for interactive sessions.  It
+is I<not> intended that you try to parse the output string.
+Use C<statvfs> from programs.
+
 =item $kmsgs = $h->dmesg ();
 
 This returns the kernel messages (C<dmesg> output) from
 =item $kmsgs = $h->dmesg ();
 
 This returns the kernel messages (C<dmesg> output) from
@@ -532,6 +550,18 @@ Setting C<whattodrop> to 3 should drop everything.
 This automatically calls L<sync(2)> before the operation,
 so that the maximum guest memory is freed.
 
 This automatically calls L<sync(2)> before the operation,
 so that the maximum guest memory is freed.
 
+=item $sizekb = $h->du ($path);
+
+This command runs the C<du -s> command to estimate file space
+usage for C<path>.
+
+C<path> can be a file or a directory.  If C<path> is a directory
+then the estimate includes the contents of the directory and all
+subdirectories (recursively).
+
+The result is the estimated size in I<kilobytes>
+(ie. units of 1024 bytes).
+
 =item $h->e2fsck_f ($device);
 
 This runs C<e2fsck -p -f device>, ie. runs the ext2/ext3
 =item $h->e2fsck_f ($device);
 
 This runs C<e2fsck -p -f device>, ie. runs the ext2/ext3
@@ -651,6 +681,18 @@ C<device>.
 This returns the ext2/3/4 filesystem UUID of the filesystem on
 C<device>.
 
 This returns the ext2/3/4 filesystem UUID of the filesystem on
 C<device>.
 
+=item $memsize = $h->get_memsize ();
+
+This gets the memory size in megabytes allocated to the
+qemu subprocess.
+
+If C<$h-E<gt>set_memsize> was not called
+on this handle, and if C<LIBGUESTFS_MEMSIZE> was not set,
+then this returns the compiled-in default value for memsize.
+
+For more information on the architecture of libguestfs,
+see L<guestfs(3)>.
+
 =item $path = $h->get_path ();
 
 Return the current search path.
 =item $path = $h->get_path ();
 
 Return the current search path.
@@ -694,6 +736,29 @@ See that manual page for more details.
 This command installs GRUB (the Grand Unified Bootloader) on
 C<device>, with the root directory being C<root>.
 
 This command installs GRUB (the Grand Unified Bootloader) on
 C<device>, with the root directory being C<root>.
 
+=item @lines = $h->head ($path);
+
+This command returns up to the first 10 lines of a file as
+a list of strings.
+
+Because of the message protocol, there is a transfer limit 
+of somewhere between 2MB and 4MB.  To transfer large files you should use
+FTP.
+
+=item @lines = $h->head_n ($nrlines, $path);
+
+If the parameter C<nrlines> is a positive number, this returns the first
+C<nrlines> lines of the file C<path>.
+
+If the parameter C<nrlines> is a negative number, this returns lines
+from the file C<path>, excluding the last C<nrlines> lines.
+
+If the parameter C<nrlines> is zero, this returns an empty list.
+
+Because of the message protocol, there is a transfer limit 
+of somewhere between 2MB and 4MB.  To transfer large files you should use
+FTP.
+
 =item $dump = $h->hexdump ($path);
 
 This runs C<hexdump -C> on the given C<path>.  The result is
 =item $dump = $h->hexdump ($path);
 
 This runs C<hexdump -C> on the given C<path>.  The result is
@@ -703,6 +768,18 @@ Because of the message protocol, there is a transfer limit
 of somewhere between 2MB and 4MB.  To transfer large files you should use
 FTP.
 
 of somewhere between 2MB and 4MB.  To transfer large files you should use
 FTP.
 
+=item @filenames = $h->initrd_list ($path);
+
+This command lists out files contained in an initrd.
+
+The files are listed without any initial C</> character.  The
+files are listed in the order they appear (not necessarily
+alphabetical).  Directory names are listed as separate items.
+
+Old Linux kernels (2.4 and earlier) used a compressed ext2
+filesystem as initrd.  We I<only> support the newer initramfs
+format (compressed cpio files).
+
 =item $busy = $h->is_busy ();
 
 This returns true iff this handle is busy processing a command
 =item $busy = $h->is_busy ();
 
 This returns true iff this handle is busy processing a command
@@ -873,12 +950,52 @@ directory and its contents after use.
 
 See also: L<mkdtemp(3)>
 
 
 See also: L<mkdtemp(3)>
 
+=item $h->mkfifo ($mode, $path);
+
+This call creates a FIFO (named pipe) called C<path> with
+mode C<mode>.  It is just a convenient wrapper around
+C<$h-E<gt>mknod>.
+
 =item $h->mkfs ($fstype, $device);
 
 This creates a filesystem on C<device> (usually a partition
 or LVM logical volume).  The filesystem type is C<fstype>, for
 example C<ext3>.
 
 =item $h->mkfs ($fstype, $device);
 
 This creates a filesystem on C<device> (usually a partition
 or LVM logical volume).  The filesystem type is C<fstype>, for
 example C<ext3>.
 
+=item $h->mknod ($mode, $devmajor, $devminor, $path);
+
+This call creates block or character special devices, or
+named pipes (FIFOs).
+
+The C<mode> parameter should be the mode, using the standard
+constants.  C<devmajor> and C<devminor> are the
+device major and minor numbers, only used when creating block
+and character special devices.
+
+=item $h->mknod_b ($mode, $devmajor, $devminor, $path);
+
+This call creates a block device node called C<path> with
+mode C<mode> and device major/minor C<devmajor> and C<devminor>.
+It is just a convenient wrapper around C<$h-E<gt>mknod>.
+
+=item $h->mknod_c ($mode, $devmajor, $devminor, $path);
+
+This call creates a char device node called C<path> with
+mode C<mode> and device major/minor C<devmajor> and C<devminor>.
+It is just a convenient wrapper around C<$h-E<gt>mknod>.
+
+=item $h->mkswap ($device);
+
+Create a swap partition on C<device>.
+
+=item $h->mkswap_L ($label, $device);
+
+Create a swap partition on C<device> with label C<label>.
+
+=item $h->mkswap_U ($uuid, $device);
+
+Create a swap partition on C<device> with UUID C<uuid>.
+
 =item $h->mount ($device, $mountpoint);
 
 Mount a guest disk at a position in the filesystem.  Block devices
 =item $h->mount ($device, $mountpoint);
 
 Mount a guest disk at a position in the filesystem.  Block devices
@@ -898,6 +1015,12 @@ on the underlying device.
 The filesystem options C<sync> and C<noatime> are set with this
 call, in order to improve reliability.
 
 The filesystem options C<sync> and C<noatime> are set with this
 call, in order to improve reliability.
 
+=item $h->mount_loop ($file, $mountpoint);
+
+This command lets you mount C<file> (a filesystem image
+in a file) on a mount point.  It is entirely equivalent to
+the command C<mount -o loop file mountpoint>.
+
 =item $h->mount_options ($options, $device, $mountpoint);
 
 This is the same as the C<$h-E<gt>mount> command, but it
 =item $h->mount_options ($options, $device, $mountpoint);
 
 This is the same as the C<$h-E<gt>mount> command, but it
@@ -995,6 +1118,18 @@ Note that this function cannot correctly handle binary files
 as end of line).  For those you need to use the C<$h-E<gt>read_file>
 function which has a more complex interface.
 
 as end of line).  For those you need to use the C<$h-E<gt>read_file>
 function which has a more complex interface.
 
+=item @entries = $h->readdir ($dir);
+
+This returns the list of directory entries in directory C<dir>.
+
+All entries in the directory are returned, including C<.> and
+C<..>.  The entries are I<not> sorted, but returned in the same
+order as the underlying filesystem.
+
+This function is primarily intended for use by programs.  To
+get a simple list of names, use C<$h-E<gt>ls>.  To get a printable
+directory for human consumption, use C<$h-E<gt>ll>.
+
 =item $h->resize2fs ($device);
 
 This resizes an ext2 or ext3 filesystem to match the size of
 =item $h->resize2fs ($device);
 
 This resizes an ext2 or ext3 filesystem to match the size of
@@ -1099,6 +1234,19 @@ L<tune2fs(8)> manpage.
 You can use either C<$h-E<gt>tune2fs_l> or C<$h-E<gt>get_e2uuid>
 to return the existing UUID of a filesystem.
 
 You can use either C<$h-E<gt>tune2fs_l> or C<$h-E<gt>get_e2uuid>
 to return the existing UUID of a filesystem.
 
+=item $h->set_memsize ($memsize);
+
+This sets the memory size in megabytes allocated to the
+qemu subprocess.  This only has any effect if called before
+C<$h-E<gt>launch>.
+
+You can also change this by setting the environment
+variable C<LIBGUESTFS_MEMSIZE> before the handle is
+created.
+
+For more information on the architecture of libguestfs,
+see L<guestfs(3)>.
+
 =item $h->set_path ($path);
 
 Set the path that libguestfs searches for kernel and initrd.img.
 =item $h->set_path ($path);
 
 Set the path that libguestfs searches for kernel and initrd.img.
@@ -1161,7 +1309,7 @@ See also: C<$h-E<gt>sfdisk_l>, C<$h-E<gt>sfdisk_N>
 B<This command is dangerous.  Without careful use you
 can easily destroy all your data>.
 
 B<This command is dangerous.  Without careful use you
 can easily destroy all your data>.
 
-=item $h->sfdisk_N ($device, $n, $cyls, $heads, $sectors, $line);
+=item $h->sfdisk_N ($device, $partnum, $cyls, $heads, $sectors, $line);
 
 This runs L<sfdisk(8)> option to modify just the single
 partition C<n> (note: C<n> counts from 1).
 
 This runs L<sfdisk(8)> option to modify just the single
 partition C<n> (note: C<n> counts from 1).
@@ -1268,6 +1416,29 @@ underlying disk image.
 You should always call this if you have modified a disk image, before
 closing the handle.
 
 You should always call this if you have modified a disk image, before
 closing the handle.
 
+=item @lines = $h->tail ($path);
+
+This command returns up to the last 10 lines of a file as
+a list of strings.
+
+Because of the message protocol, there is a transfer limit 
+of somewhere between 2MB and 4MB.  To transfer large files you should use
+FTP.
+
+=item @lines = $h->tail_n ($nrlines, $path);
+
+If the parameter C<nrlines> is a positive number, this returns the last
+C<nrlines> lines of the file C<path>.
+
+If the parameter C<nrlines> is a negative number, this returns lines
+from the file C<path>, starting with the C<-nrlines>th line.
+
+If the parameter C<nrlines> is zero, this returns an empty list.
+
+Because of the message protocol, there is a transfer limit 
+of somewhere between 2MB and 4MB.  To transfer large files you should use
+FTP.
+
 =item $h->tar_in ($tarfile, $directory);
 
 This command uploads and unpacks local file C<tarfile> (an
 =item $h->tar_in ($tarfile, $directory);
 
 This command uploads and unpacks local file C<tarfile> (an
@@ -1312,6 +1483,24 @@ manpage for more details.  The list of fields returned isn't
 clearly defined, and depends on both the version of C<tune2fs>
 that libguestfs was built against, and the filesystem itself.
 
 clearly defined, and depends on both the version of C<tune2fs>
 that libguestfs was built against, and the filesystem itself.
 
+=item $oldmask = $h->umask ($mask);
+
+This function sets the mask used for creating new files and
+device nodes to C<mask & 0777>.
+
+Typical umask values would be C<022> which creates new files
+with permissions like "-rw-r--r--" or "-rwxr-xr-x", and
+C<002> which creates new files with permissions like
+"-rw-rw-r--" or "-rwxrwxr-x".
+
+The default umask is C<022>.  This is important because it
+means that directories and device nodes will be created with
+C<0644> or C<0755> mode even if you specify C<0777>.
+
+See also L<umask(2)>, C<$h-E<gt>mknod>, C<$h-E<gt>mkdir>.
+
+This call returns the previous umask.
+
 =item $h->umount ($pathordevice);
 
 This unmounts the given filesystem.  The filesystem may be
 =item $h->umount ($pathordevice);
 
 This unmounts the given filesystem.  The filesystem may be