Generated code for mknod, mkfifo, mknod_b, mknod_c, umask.
[libguestfs.git] / fish / cmds.c
index 6067eed..15df267 100644 (file)
@@ -72,6 +72,7 @@ void list_commands (void)
   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", "du", "estimate file space usage");
   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");
@@ -82,6 +83,7 @@ void list_commands (void)
   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-memsize", "get memory allocated to the qemu subprocess");
   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");
@@ -91,6 +93,7 @@ void list_commands (void)
   printf ("%-20s %s\n", "head", "return first 10 lines of a file");
   printf ("%-20s %s\n", "head-n", "return first N lines of a file");
   printf ("%-20s %s\n", "hexdump", "dump a file in hexadecimal");
+  printf ("%-20s %s\n", "initrd-list", "list files in an initrd");
   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");
@@ -113,8 +116,16 @@ void list_commands (void)
   printf ("%-20s %s\n", "mkdir", "create a directory");
   printf ("%-20s %s\n", "mkdir-p", "create a directory and parents");
   printf ("%-20s %s\n", "mkdtemp", "create a temporary directory");
+  printf ("%-20s %s\n", "mkfifo", "make FIFO (named pipe)");
   printf ("%-20s %s\n", "mkfs", "make a filesystem");
+  printf ("%-20s %s\n", "mknod", "make block, character or FIFO devices");
+  printf ("%-20s %s\n", "mknod-b", "make block device node");
+  printf ("%-20s %s\n", "mknod-c", "make char device node");
+  printf ("%-20s %s\n", "mkswap", "create a swap partition");
+  printf ("%-20s %s\n", "mkswap-L", "create a swap partition with a label");
+  printf ("%-20s %s\n", "mkswap-U", "create a swap partition with an explicit UUID");
   printf ("%-20s %s\n", "mount", "mount a guest disk at a position in the filesystem");
+  printf ("%-20s %s\n", "mount-loop", "mount a file using the loop device");
   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");
@@ -139,6 +150,7 @@ void list_commands (void)
   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-memsize", "set memory allocated to the qemu subprocess");
   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");
@@ -163,6 +175,7 @@ void list_commands (void)
   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", "umask", "set file mode creation mask (umask)");
   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");
@@ -246,6 +259,12 @@ void display_command (const char *cmd)
   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<guestfs(3)>.");
   else
+  if (strcasecmp (cmd, "set_memsize") == 0 || strcasecmp (cmd, "set-memsize") == 0 || strcasecmp (cmd, "memsize") == 0)
+    pod2text ("set-memsize - set memory allocated to the qemu subprocess", " set-memsize <memsize>\n\nThis sets the memory size in megabytes allocated to the\nqemu subprocess.  This only has any effect if called before\nC<launch>.\n\nYou can also change this by setting the environment\nvariable C<LIBGUESTFS_MEMSIZE> before the handle is\ncreated.\n\nFor more information on the architecture of libguestfs,\nsee L<guestfs(3)>.\n\nYou can use 'memsize' as an alias for this command.");
+  else
+  if (strcasecmp (cmd, "get_memsize") == 0 || strcasecmp (cmd, "get-memsize") == 0)
+    pod2text ("get-memsize - get memory allocated to the qemu subprocess", " get-memsize\n\nThis gets the memory size in megabytes allocated to the\nqemu subprocess.\n\nIf C<set_memsize> was not called\non this handle, and if C<LIBGUESTFS_MEMSIZE> was not set,\nthen this returns the compiled-in default value for memsize.\n\nFor more information on the architecture of libguestfs,\nsee L<guestfs(3)>.");
+  else
   if (strcasecmp (cmd, "mount") == 0)
     pod2text ("mount - mount a guest disk at a position in the filesystem", " mount <device> <mountpoint>\n\nMount a guest disk at a position in the filesystem.  Block devices\nare named C</dev/sda>, C</dev/sdb> and so on, as they were added to\nthe guest.  If those block devices contain partitions, they will have\nthe usual names (eg. C</dev/sda1>).  Also LVM C</dev/VG/LV>-style\nnames can be used.\n\nThe rules are the same as for L<mount(2)>:  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<sync> and C<noatime> are set with this\ncall, in order to improve reliability.");
   else
@@ -624,6 +643,39 @@ void display_command (const char *cmd)
   if (strcasecmp (cmd, "df_h") == 0 || strcasecmp (cmd, "df-h") == 0)
     pod2text ("df-h - report file system disk space usage (human readable)", " df-h\n\nThis command runs the C<df -h> command to report disk space used\nin human-readable format.\n\nThis command is mostly useful for interactive sessions.  It\nis I<not> intended that you try to parse the output string.\nUse C<statvfs> from programs.");
   else
+  if (strcasecmp (cmd, "du") == 0)
+    pod2text ("du - estimate file space usage", " du <path>\n\nThis command runs the C<du -s> command to estimate file space\nusage for C<path>.\n\nC<path> can be a file or a directory.  If C<path> is a directory\nthen the estimate includes the contents of the directory and all\nsubdirectories (recursively).\n\nThe result is the estimated size in I<kilobytes>\n(ie. units of 1024 bytes).");
+  else
+  if (strcasecmp (cmd, "initrd_list") == 0 || strcasecmp (cmd, "initrd-list") == 0)
+    pod2text ("initrd-list - list files in an initrd", " initrd-list <path>\n\nThis command lists out files contained in an initrd.\n\nThe files are listed without any initial C</> character.  The\nfiles are listed in the order they appear (not necessarily\nalphabetical).  Directory names are listed as separate items.\n\nOld Linux kernels (2.4 and earlier) used a compressed ext2\nfilesystem as initrd.  We I<only> support the newer initramfs\nformat (compressed cpio files).");
+  else
+  if (strcasecmp (cmd, "mount_loop") == 0 || strcasecmp (cmd, "mount-loop") == 0)
+    pod2text ("mount-loop - mount a file using the loop device", " mount-loop <file> <mountpoint>\n\nThis command lets you mount C<file> (a filesystem image\nin a file) on a mount point.  It is entirely equivalent to\nthe command C<mount -o loop file mountpoint>.");
+  else
+  if (strcasecmp (cmd, "mkswap") == 0)
+    pod2text ("mkswap - create a swap partition", " mkswap <device>\n\nCreate a swap partition on C<device>.");
+  else
+  if (strcasecmp (cmd, "mkswap_L") == 0 || strcasecmp (cmd, "mkswap-L") == 0)
+    pod2text ("mkswap-L - create a swap partition with a label", " mkswap-L <label> <device>\n\nCreate a swap partition on C<device> with label C<label>.");
+  else
+  if (strcasecmp (cmd, "mkswap_U") == 0 || strcasecmp (cmd, "mkswap-U") == 0)
+    pod2text ("mkswap-U - create a swap partition with an explicit UUID", " mkswap-U <uuid> <device>\n\nCreate a swap partition on C<device> with UUID C<uuid>.");
+  else
+  if (strcasecmp (cmd, "mknod") == 0)
+    pod2text ("mknod - make block, character or FIFO devices", " mknod <mode> <devmajor> <devminor> <path>\n\nThis call creates block or character special devices, or\nnamed pipes (FIFOs).\n\nThe C<mode> parameter should be the mode, using the standard\nconstants.  C<devmajor> and C<devminor> are the\ndevice major and minor numbers, only used when creating block\nand character special devices.");
+  else
+  if (strcasecmp (cmd, "mkfifo") == 0)
+    pod2text ("mkfifo - make FIFO (named pipe)", " mkfifo <mode> <path>\n\nThis call creates a FIFO (named pipe) called C<path> with\nmode C<mode>.  It is just a convenient wrapper around\nC<mknod>.");
+  else
+  if (strcasecmp (cmd, "mknod_b") == 0 || strcasecmp (cmd, "mknod-b") == 0)
+    pod2text ("mknod-b - make block device node", " mknod-b <mode> <devmajor> <devminor> <path>\n\nThis call creates a block device node called C<path> with\nmode C<mode> and device major/minor C<devmajor> and C<devminor>.\nIt is just a convenient wrapper around C<mknod>.");
+  else
+  if (strcasecmp (cmd, "mknod_c") == 0 || strcasecmp (cmd, "mknod-c") == 0)
+    pod2text ("mknod-c - make char device node", " mknod-c <mode> <devmajor> <devminor> <path>\n\nThis call creates a char device node called C<path> with\nmode C<mode> and device major/minor C<devmajor> and C<devminor>.\nIt is just a convenient wrapper around C<mknod>.");
+  else
+  if (strcasecmp (cmd, "umask") == 0)
+    pod2text ("umask - set file mode creation mask (umask)", " umask <mask>\n\nThis function sets the mask used for creating new files and\ndevice nodes to C<mask & 0777>.\n\nTypical umask values would be C<022> which creates new files\nwith permissions like \"-rw-r--r--\" or \"-rwxr-xr-x\", and\nC<002> which creates new files with permissions like\n\"-rw-rw-r--\" or \"-rwxrwxr-x\".\n\nSee also L<umask(2)>, C<mknod>, C<mkdir>.\n\nThis call returns the previous umask.");
+  else
     display_builtin_command (cmd);
 }
 
@@ -1053,6 +1105,34 @@ static int run_get_state (const char *cmd, int argc, char *argv[])
   return 0;
 }
 
+static int run_set_memsize (const char *cmd, int argc, char *argv[])
+{
+  int r;
+  int memsize;
+  if (argc != 1) {
+    fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
+    fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+    return -1;
+  }
+  memsize = atoi (argv[0]);
+  r = guestfs_set_memsize (g, memsize);
+  return r;
+}
+
+static int run_get_memsize (const char *cmd, int argc, char *argv[])
+{
+  int r;
+  if (argc != 0) {
+    fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
+    fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+    return -1;
+  }
+  r = guestfs_get_memsize (g);
+  if (r == -1) return -1;
+  printf ("%d\n", r);
+  return 0;
+}
+
 static int run_mount (const char *cmd, int argc, char *argv[])
 {
   int r;
@@ -3062,6 +3142,193 @@ static int run_df_h (const char *cmd, int argc, char *argv[])
   return 0;
 }
 
+static int run_du (const char *cmd, int argc, char *argv[])
+{
+  int64_t r;
+  const char *path;
+  if (argc != 1) {
+    fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
+    fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+    return -1;
+  }
+  path = argv[0];
+  r = guestfs_du (g, path);
+  if (r == -1) return -1;
+  printf ("%" PRIi64 "\n", r);
+  return 0;
+}
+
+static int run_initrd_list (const char *cmd, int argc, char *argv[])
+{
+  char **r;
+  const char *path;
+  if (argc != 1) {
+    fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
+    fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+    return -1;
+  }
+  path = argv[0];
+  r = guestfs_initrd_list (g, path);
+  if (r == NULL) return -1;
+  print_strings (r);
+  free_strings (r);
+  return 0;
+}
+
+static int run_mount_loop (const char *cmd, int argc, char *argv[])
+{
+  int r;
+  const char *file;
+  const char *mountpoint;
+  if (argc != 2) {
+    fprintf (stderr, "%s should have 2 parameter(s)\n", cmd);
+    fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+    return -1;
+  }
+  file = argv[0];
+  mountpoint = argv[1];
+  r = guestfs_mount_loop (g, file, mountpoint);
+  return r;
+}
+
+static int run_mkswap (const char *cmd, int argc, char *argv[])
+{
+  int r;
+  const char *device;
+  if (argc != 1) {
+    fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
+    fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+    return -1;
+  }
+  device = argv[0];
+  r = guestfs_mkswap (g, device);
+  return r;
+}
+
+static int run_mkswap_L (const char *cmd, int argc, char *argv[])
+{
+  int r;
+  const char *label;
+  const char *device;
+  if (argc != 2) {
+    fprintf (stderr, "%s should have 2 parameter(s)\n", cmd);
+    fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+    return -1;
+  }
+  label = argv[0];
+  device = argv[1];
+  r = guestfs_mkswap_L (g, label, device);
+  return r;
+}
+
+static int run_mkswap_U (const char *cmd, int argc, char *argv[])
+{
+  int r;
+  const char *uuid;
+  const char *device;
+  if (argc != 2) {
+    fprintf (stderr, "%s should have 2 parameter(s)\n", cmd);
+    fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+    return -1;
+  }
+  uuid = argv[0];
+  device = argv[1];
+  r = guestfs_mkswap_U (g, uuid, device);
+  return r;
+}
+
+static int run_mknod (const char *cmd, int argc, char *argv[])
+{
+  int r;
+  int mode;
+  int devmajor;
+  int devminor;
+  const char *path;
+  if (argc != 4) {
+    fprintf (stderr, "%s should have 4 parameter(s)\n", cmd);
+    fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+    return -1;
+  }
+  mode = atoi (argv[0]);
+  devmajor = atoi (argv[1]);
+  devminor = atoi (argv[2]);
+  path = argv[3];
+  r = guestfs_mknod (g, mode, devmajor, devminor, path);
+  return r;
+}
+
+static int run_mkfifo (const char *cmd, int argc, char *argv[])
+{
+  int r;
+  int mode;
+  const char *path;
+  if (argc != 2) {
+    fprintf (stderr, "%s should have 2 parameter(s)\n", cmd);
+    fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+    return -1;
+  }
+  mode = atoi (argv[0]);
+  path = argv[1];
+  r = guestfs_mkfifo (g, mode, path);
+  return r;
+}
+
+static int run_mknod_b (const char *cmd, int argc, char *argv[])
+{
+  int r;
+  int mode;
+  int devmajor;
+  int devminor;
+  const char *path;
+  if (argc != 4) {
+    fprintf (stderr, "%s should have 4 parameter(s)\n", cmd);
+    fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+    return -1;
+  }
+  mode = atoi (argv[0]);
+  devmajor = atoi (argv[1]);
+  devminor = atoi (argv[2]);
+  path = argv[3];
+  r = guestfs_mknod_b (g, mode, devmajor, devminor, path);
+  return r;
+}
+
+static int run_mknod_c (const char *cmd, int argc, char *argv[])
+{
+  int r;
+  int mode;
+  int devmajor;
+  int devminor;
+  const char *path;
+  if (argc != 4) {
+    fprintf (stderr, "%s should have 4 parameter(s)\n", cmd);
+    fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+    return -1;
+  }
+  mode = atoi (argv[0]);
+  devmajor = atoi (argv[1]);
+  devminor = atoi (argv[2]);
+  path = argv[3];
+  r = guestfs_mknod_c (g, mode, devmajor, devminor, path);
+  return r;
+}
+
+static int run_umask (const char *cmd, int argc, char *argv[])
+{
+  int r;
+  int mask;
+  if (argc != 1) {
+    fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
+    fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+    return -1;
+  }
+  mask = atoi (argv[0]);
+  r = guestfs_umask (g, mask);
+  if (r == -1) return -1;
+  printf ("%d\n", r);
+  return 0;
+}
+
 int run_action (const char *cmd, int argc, char *argv[])
 {
   if (strcasecmp (cmd, "launch") == 0 || strcasecmp (cmd, "run") == 0)
@@ -3127,6 +3394,12 @@ int run_action (const char *cmd, int argc, char *argv[])
   if (strcasecmp (cmd, "get_state") == 0 || strcasecmp (cmd, "get-state") == 0)
     return run_get_state (cmd, argc, argv);
   else
+  if (strcasecmp (cmd, "set_memsize") == 0 || strcasecmp (cmd, "set-memsize") == 0 || strcasecmp (cmd, "memsize") == 0)
+    return run_set_memsize (cmd, argc, argv);
+  else
+  if (strcasecmp (cmd, "get_memsize") == 0 || strcasecmp (cmd, "get-memsize") == 0)
+    return run_get_memsize (cmd, argc, argv);
+  else
   if (strcasecmp (cmd, "mount") == 0)
     return run_mount (cmd, argc, argv);
   else
@@ -3505,6 +3778,39 @@ int run_action (const char *cmd, int argc, char *argv[])
   if (strcasecmp (cmd, "df_h") == 0 || strcasecmp (cmd, "df-h") == 0)
     return run_df_h (cmd, argc, argv);
   else
+  if (strcasecmp (cmd, "du") == 0)
+    return run_du (cmd, argc, argv);
+  else
+  if (strcasecmp (cmd, "initrd_list") == 0 || strcasecmp (cmd, "initrd-list") == 0)
+    return run_initrd_list (cmd, argc, argv);
+  else
+  if (strcasecmp (cmd, "mount_loop") == 0 || strcasecmp (cmd, "mount-loop") == 0)
+    return run_mount_loop (cmd, argc, argv);
+  else
+  if (strcasecmp (cmd, "mkswap") == 0)
+    return run_mkswap (cmd, argc, argv);
+  else
+  if (strcasecmp (cmd, "mkswap_L") == 0 || strcasecmp (cmd, "mkswap-L") == 0)
+    return run_mkswap_L (cmd, argc, argv);
+  else
+  if (strcasecmp (cmd, "mkswap_U") == 0 || strcasecmp (cmd, "mkswap-U") == 0)
+    return run_mkswap_U (cmd, argc, argv);
+  else
+  if (strcasecmp (cmd, "mknod") == 0)
+    return run_mknod (cmd, argc, argv);
+  else
+  if (strcasecmp (cmd, "mkfifo") == 0)
+    return run_mkfifo (cmd, argc, argv);
+  else
+  if (strcasecmp (cmd, "mknod_b") == 0 || strcasecmp (cmd, "mknod-b") == 0)
+    return run_mknod_b (cmd, argc, argv);
+  else
+  if (strcasecmp (cmd, "mknod_c") == 0 || strcasecmp (cmd, "mknod-c") == 0)
+    return run_mknod_c (cmd, argc, argv);
+  else
+  if (strcasecmp (cmd, "umask") == 0)
+    return run_umask (cmd, argc, argv);
+  else
     {
       fprintf (stderr, "%s: unknown command\n", cmd);
       return -1;