Files
libguestfs/daemon/stubs.c
2009-04-13 23:58:33 +01:00

2248 lines
55 KiB
C

/* libguestfs generated file
* WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'.
* ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
*
* Copyright (C) 2009 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define _GNU_SOURCE // for strchrnul
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <ctype.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#include "daemon.h"
#include "../src/guestfs_protocol.h"
#include "actions.h"
static void mount_stub (XDR *xdr_in)
{
int r;
struct guestfs_mount_args args;
const char *device;
const char *mountpoint;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_mount_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "mount");
return;
}
device = args.device;
mountpoint = args.mountpoint;
r = do_mount (device, mountpoint);
if (r == -1)
/* do_mount has already called reply_with_error */
goto done;
reply (NULL, NULL);
done:
xdr_free ((xdrproc_t) xdr_guestfs_mount_args, (char *) &args);
}
static void sync_stub (XDR *xdr_in)
{
int r;
r = do_sync ();
if (r == -1)
/* do_sync has already called reply_with_error */
goto done;
reply (NULL, NULL);
done: ;
}
static void touch_stub (XDR *xdr_in)
{
int r;
struct guestfs_touch_args args;
const char *path;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_touch_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "touch");
return;
}
path = args.path;
r = do_touch (path);
if (r == -1)
/* do_touch has already called reply_with_error */
goto done;
reply (NULL, NULL);
done:
xdr_free ((xdrproc_t) xdr_guestfs_touch_args, (char *) &args);
}
static void cat_stub (XDR *xdr_in)
{
char *r;
struct guestfs_cat_args args;
const char *path;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_cat_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "cat");
return;
}
path = args.path;
r = do_cat (path);
if (r == NULL)
/* do_cat has already called reply_with_error */
goto done;
struct guestfs_cat_ret ret;
ret.content = r;
reply ((xdrproc_t) &xdr_guestfs_cat_ret, (char *) &ret);
free (r);
done:
xdr_free ((xdrproc_t) xdr_guestfs_cat_args, (char *) &args);
}
static void ll_stub (XDR *xdr_in)
{
char *r;
struct guestfs_ll_args args;
const char *directory;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_ll_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "ll");
return;
}
directory = args.directory;
r = do_ll (directory);
if (r == NULL)
/* do_ll has already called reply_with_error */
goto done;
struct guestfs_ll_ret ret;
ret.listing = r;
reply ((xdrproc_t) &xdr_guestfs_ll_ret, (char *) &ret);
free (r);
done:
xdr_free ((xdrproc_t) xdr_guestfs_ll_args, (char *) &args);
}
static void ls_stub (XDR *xdr_in)
{
char **r;
struct guestfs_ls_args args;
const char *directory;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_ls_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "ls");
return;
}
directory = args.directory;
r = do_ls (directory);
if (r == NULL)
/* do_ls has already called reply_with_error */
goto done;
struct guestfs_ls_ret ret;
ret.listing.listing_len = count_strings (r);
ret.listing.listing_val = r;
reply ((xdrproc_t) &xdr_guestfs_ls_ret, (char *) &ret);
free_strings (r);
done:
xdr_free ((xdrproc_t) xdr_guestfs_ls_args, (char *) &args);
}
static void list_devices_stub (XDR *xdr_in)
{
char **r;
r = do_list_devices ();
if (r == NULL)
/* do_list_devices has already called reply_with_error */
goto done;
struct guestfs_list_devices_ret ret;
ret.devices.devices_len = count_strings (r);
ret.devices.devices_val = r;
reply ((xdrproc_t) &xdr_guestfs_list_devices_ret, (char *) &ret);
free_strings (r);
done: ;
}
static void list_partitions_stub (XDR *xdr_in)
{
char **r;
r = do_list_partitions ();
if (r == NULL)
/* do_list_partitions has already called reply_with_error */
goto done;
struct guestfs_list_partitions_ret ret;
ret.partitions.partitions_len = count_strings (r);
ret.partitions.partitions_val = r;
reply ((xdrproc_t) &xdr_guestfs_list_partitions_ret, (char *) &ret);
free_strings (r);
done: ;
}
static void pvs_stub (XDR *xdr_in)
{
char **r;
r = do_pvs ();
if (r == NULL)
/* do_pvs has already called reply_with_error */
goto done;
struct guestfs_pvs_ret ret;
ret.physvols.physvols_len = count_strings (r);
ret.physvols.physvols_val = r;
reply ((xdrproc_t) &xdr_guestfs_pvs_ret, (char *) &ret);
free_strings (r);
done: ;
}
static void vgs_stub (XDR *xdr_in)
{
char **r;
r = do_vgs ();
if (r == NULL)
/* do_vgs has already called reply_with_error */
goto done;
struct guestfs_vgs_ret ret;
ret.volgroups.volgroups_len = count_strings (r);
ret.volgroups.volgroups_val = r;
reply ((xdrproc_t) &xdr_guestfs_vgs_ret, (char *) &ret);
free_strings (r);
done: ;
}
static void lvs_stub (XDR *xdr_in)
{
char **r;
r = do_lvs ();
if (r == NULL)
/* do_lvs has already called reply_with_error */
goto done;
struct guestfs_lvs_ret ret;
ret.logvols.logvols_len = count_strings (r);
ret.logvols.logvols_val = r;
reply ((xdrproc_t) &xdr_guestfs_lvs_ret, (char *) &ret);
free_strings (r);
done: ;
}
static void pvs_full_stub (XDR *xdr_in)
{
guestfs_lvm_int_pv_list *r;
r = do_pvs_full ();
if (r == NULL)
/* do_pvs_full has already called reply_with_error */
goto done;
struct guestfs_pvs_full_ret ret;
ret.physvols = *r;
reply ((xdrproc_t) xdr_guestfs_pvs_full_ret, (char *) &ret);
xdr_free ((xdrproc_t) xdr_guestfs_pvs_full_ret, (char *) &ret);
done: ;
}
static void vgs_full_stub (XDR *xdr_in)
{
guestfs_lvm_int_vg_list *r;
r = do_vgs_full ();
if (r == NULL)
/* do_vgs_full has already called reply_with_error */
goto done;
struct guestfs_vgs_full_ret ret;
ret.volgroups = *r;
reply ((xdrproc_t) xdr_guestfs_vgs_full_ret, (char *) &ret);
xdr_free ((xdrproc_t) xdr_guestfs_vgs_full_ret, (char *) &ret);
done: ;
}
static void lvs_full_stub (XDR *xdr_in)
{
guestfs_lvm_int_lv_list *r;
r = do_lvs_full ();
if (r == NULL)
/* do_lvs_full has already called reply_with_error */
goto done;
struct guestfs_lvs_full_ret ret;
ret.logvols = *r;
reply ((xdrproc_t) xdr_guestfs_lvs_full_ret, (char *) &ret);
xdr_free ((xdrproc_t) xdr_guestfs_lvs_full_ret, (char *) &ret);
done: ;
}
static void read_lines_stub (XDR *xdr_in)
{
char **r;
struct guestfs_read_lines_args args;
const char *path;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_read_lines_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "read_lines");
return;
}
path = args.path;
r = do_read_lines (path);
if (r == NULL)
/* do_read_lines has already called reply_with_error */
goto done;
struct guestfs_read_lines_ret ret;
ret.lines.lines_len = count_strings (r);
ret.lines.lines_val = r;
reply ((xdrproc_t) &xdr_guestfs_read_lines_ret, (char *) &ret);
free_strings (r);
done:
xdr_free ((xdrproc_t) xdr_guestfs_read_lines_args, (char *) &args);
}
static void aug_init_stub (XDR *xdr_in)
{
int r;
struct guestfs_aug_init_args args;
const char *root;
int flags;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_aug_init_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "aug_init");
return;
}
root = args.root;
flags = args.flags;
r = do_aug_init (root, flags);
if (r == -1)
/* do_aug_init has already called reply_with_error */
goto done;
reply (NULL, NULL);
done:
xdr_free ((xdrproc_t) xdr_guestfs_aug_init_args, (char *) &args);
}
static void aug_close_stub (XDR *xdr_in)
{
int r;
r = do_aug_close ();
if (r == -1)
/* do_aug_close has already called reply_with_error */
goto done;
reply (NULL, NULL);
done: ;
}
static void aug_defvar_stub (XDR *xdr_in)
{
int r;
struct guestfs_aug_defvar_args args;
const char *name;
const char *expr;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_aug_defvar_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "aug_defvar");
return;
}
name = args.name;
expr = args.expr ? *args.expr : NULL;
r = do_aug_defvar (name, expr);
if (r == -1)
/* do_aug_defvar has already called reply_with_error */
goto done;
struct guestfs_aug_defvar_ret ret;
ret.nrnodes = r;
reply ((xdrproc_t) &xdr_guestfs_aug_defvar_ret, (char *) &ret);
done:
xdr_free ((xdrproc_t) xdr_guestfs_aug_defvar_args, (char *) &args);
}
static void aug_defnode_stub (XDR *xdr_in)
{
guestfs_aug_defnode_ret *r;
struct guestfs_aug_defnode_args args;
const char *name;
const char *expr;
const char *val;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_aug_defnode_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "aug_defnode");
return;
}
name = args.name;
expr = args.expr;
val = args.val;
r = do_aug_defnode (name, expr, val);
if (r == NULL)
/* do_aug_defnode has already called reply_with_error */
goto done;
reply ((xdrproc_t) xdr_guestfs_aug_defnode_ret, (char *) r);
xdr_free ((xdrproc_t) xdr_guestfs_aug_defnode_ret, (char *) r);
done:
xdr_free ((xdrproc_t) xdr_guestfs_aug_defnode_args, (char *) &args);
}
static void aug_get_stub (XDR *xdr_in)
{
char *r;
struct guestfs_aug_get_args args;
const char *path;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_aug_get_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "aug_get");
return;
}
path = args.path;
r = do_aug_get (path);
if (r == NULL)
/* do_aug_get has already called reply_with_error */
goto done;
struct guestfs_aug_get_ret ret;
ret.val = r;
reply ((xdrproc_t) &xdr_guestfs_aug_get_ret, (char *) &ret);
free (r);
done:
xdr_free ((xdrproc_t) xdr_guestfs_aug_get_args, (char *) &args);
}
static void aug_set_stub (XDR *xdr_in)
{
int r;
struct guestfs_aug_set_args args;
const char *path;
const char *val;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_aug_set_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "aug_set");
return;
}
path = args.path;
val = args.val;
r = do_aug_set (path, val);
if (r == -1)
/* do_aug_set has already called reply_with_error */
goto done;
reply (NULL, NULL);
done:
xdr_free ((xdrproc_t) xdr_guestfs_aug_set_args, (char *) &args);
}
static void aug_insert_stub (XDR *xdr_in)
{
int r;
struct guestfs_aug_insert_args args;
const char *path;
const char *label;
int before;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_aug_insert_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "aug_insert");
return;
}
path = args.path;
label = args.label;
before = args.before;
r = do_aug_insert (path, label, before);
if (r == -1)
/* do_aug_insert has already called reply_with_error */
goto done;
reply (NULL, NULL);
done:
xdr_free ((xdrproc_t) xdr_guestfs_aug_insert_args, (char *) &args);
}
static void aug_rm_stub (XDR *xdr_in)
{
int r;
struct guestfs_aug_rm_args args;
const char *path;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_aug_rm_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "aug_rm");
return;
}
path = args.path;
r = do_aug_rm (path);
if (r == -1)
/* do_aug_rm has already called reply_with_error */
goto done;
struct guestfs_aug_rm_ret ret;
ret.nrnodes = r;
reply ((xdrproc_t) &xdr_guestfs_aug_rm_ret, (char *) &ret);
done:
xdr_free ((xdrproc_t) xdr_guestfs_aug_rm_args, (char *) &args);
}
static void aug_mv_stub (XDR *xdr_in)
{
int r;
struct guestfs_aug_mv_args args;
const char *src;
const char *dest;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_aug_mv_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "aug_mv");
return;
}
src = args.src;
dest = args.dest;
r = do_aug_mv (src, dest);
if (r == -1)
/* do_aug_mv has already called reply_with_error */
goto done;
reply (NULL, NULL);
done:
xdr_free ((xdrproc_t) xdr_guestfs_aug_mv_args, (char *) &args);
}
static void aug_match_stub (XDR *xdr_in)
{
char **r;
struct guestfs_aug_match_args args;
const char *path;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_aug_match_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "aug_match");
return;
}
path = args.path;
r = do_aug_match (path);
if (r == NULL)
/* do_aug_match has already called reply_with_error */
goto done;
struct guestfs_aug_match_ret ret;
ret.matches.matches_len = count_strings (r);
ret.matches.matches_val = r;
reply ((xdrproc_t) &xdr_guestfs_aug_match_ret, (char *) &ret);
free_strings (r);
done:
xdr_free ((xdrproc_t) xdr_guestfs_aug_match_args, (char *) &args);
}
static void aug_save_stub (XDR *xdr_in)
{
int r;
r = do_aug_save ();
if (r == -1)
/* do_aug_save has already called reply_with_error */
goto done;
reply (NULL, NULL);
done: ;
}
static void aug_load_stub (XDR *xdr_in)
{
int r;
r = do_aug_load ();
if (r == -1)
/* do_aug_load has already called reply_with_error */
goto done;
reply (NULL, NULL);
done: ;
}
static void aug_ls_stub (XDR *xdr_in)
{
char **r;
struct guestfs_aug_ls_args args;
const char *path;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_aug_ls_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "aug_ls");
return;
}
path = args.path;
r = do_aug_ls (path);
if (r == NULL)
/* do_aug_ls has already called reply_with_error */
goto done;
struct guestfs_aug_ls_ret ret;
ret.matches.matches_len = count_strings (r);
ret.matches.matches_val = r;
reply ((xdrproc_t) &xdr_guestfs_aug_ls_ret, (char *) &ret);
free_strings (r);
done:
xdr_free ((xdrproc_t) xdr_guestfs_aug_ls_args, (char *) &args);
}
static void rm_stub (XDR *xdr_in)
{
int r;
struct guestfs_rm_args args;
const char *path;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_rm_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "rm");
return;
}
path = args.path;
r = do_rm (path);
if (r == -1)
/* do_rm has already called reply_with_error */
goto done;
reply (NULL, NULL);
done:
xdr_free ((xdrproc_t) xdr_guestfs_rm_args, (char *) &args);
}
static void rmdir_stub (XDR *xdr_in)
{
int r;
struct guestfs_rmdir_args args;
const char *path;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_rmdir_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "rmdir");
return;
}
path = args.path;
r = do_rmdir (path);
if (r == -1)
/* do_rmdir has already called reply_with_error */
goto done;
reply (NULL, NULL);
done:
xdr_free ((xdrproc_t) xdr_guestfs_rmdir_args, (char *) &args);
}
static void rm_rf_stub (XDR *xdr_in)
{
int r;
struct guestfs_rm_rf_args args;
const char *path;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_rm_rf_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "rm_rf");
return;
}
path = args.path;
r = do_rm_rf (path);
if (r == -1)
/* do_rm_rf has already called reply_with_error */
goto done;
reply (NULL, NULL);
done:
xdr_free ((xdrproc_t) xdr_guestfs_rm_rf_args, (char *) &args);
}
static void mkdir_stub (XDR *xdr_in)
{
int r;
struct guestfs_mkdir_args args;
const char *path;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_mkdir_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "mkdir");
return;
}
path = args.path;
r = do_mkdir (path);
if (r == -1)
/* do_mkdir has already called reply_with_error */
goto done;
reply (NULL, NULL);
done:
xdr_free ((xdrproc_t) xdr_guestfs_mkdir_args, (char *) &args);
}
static void mkdir_p_stub (XDR *xdr_in)
{
int r;
struct guestfs_mkdir_p_args args;
const char *path;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_mkdir_p_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "mkdir_p");
return;
}
path = args.path;
r = do_mkdir_p (path);
if (r == -1)
/* do_mkdir_p has already called reply_with_error */
goto done;
reply (NULL, NULL);
done:
xdr_free ((xdrproc_t) xdr_guestfs_mkdir_p_args, (char *) &args);
}
static void chmod_stub (XDR *xdr_in)
{
int r;
struct guestfs_chmod_args args;
int mode;
const char *path;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_chmod_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "chmod");
return;
}
mode = args.mode;
path = args.path;
r = do_chmod (mode, path);
if (r == -1)
/* do_chmod has already called reply_with_error */
goto done;
reply (NULL, NULL);
done:
xdr_free ((xdrproc_t) xdr_guestfs_chmod_args, (char *) &args);
}
static void chown_stub (XDR *xdr_in)
{
int r;
struct guestfs_chown_args args;
int owner;
int group;
const char *path;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_chown_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "chown");
return;
}
owner = args.owner;
group = args.group;
path = args.path;
r = do_chown (owner, group, path);
if (r == -1)
/* do_chown has already called reply_with_error */
goto done;
reply (NULL, NULL);
done:
xdr_free ((xdrproc_t) xdr_guestfs_chown_args, (char *) &args);
}
static void exists_stub (XDR *xdr_in)
{
int r;
struct guestfs_exists_args args;
const char *path;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_exists_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "exists");
return;
}
path = args.path;
r = do_exists (path);
if (r == -1)
/* do_exists has already called reply_with_error */
goto done;
struct guestfs_exists_ret ret;
ret.existsflag = r;
reply ((xdrproc_t) &xdr_guestfs_exists_ret, (char *) &ret);
done:
xdr_free ((xdrproc_t) xdr_guestfs_exists_args, (char *) &args);
}
static void is_file_stub (XDR *xdr_in)
{
int r;
struct guestfs_is_file_args args;
const char *path;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_is_file_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "is_file");
return;
}
path = args.path;
r = do_is_file (path);
if (r == -1)
/* do_is_file has already called reply_with_error */
goto done;
struct guestfs_is_file_ret ret;
ret.fileflag = r;
reply ((xdrproc_t) &xdr_guestfs_is_file_ret, (char *) &ret);
done:
xdr_free ((xdrproc_t) xdr_guestfs_is_file_args, (char *) &args);
}
static void is_dir_stub (XDR *xdr_in)
{
int r;
struct guestfs_is_dir_args args;
const char *path;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_is_dir_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "is_dir");
return;
}
path = args.path;
r = do_is_dir (path);
if (r == -1)
/* do_is_dir has already called reply_with_error */
goto done;
struct guestfs_is_dir_ret ret;
ret.dirflag = r;
reply ((xdrproc_t) &xdr_guestfs_is_dir_ret, (char *) &ret);
done:
xdr_free ((xdrproc_t) xdr_guestfs_is_dir_args, (char *) &args);
}
static void pvcreate_stub (XDR *xdr_in)
{
int r;
struct guestfs_pvcreate_args args;
const char *device;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_pvcreate_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "pvcreate");
return;
}
device = args.device;
r = do_pvcreate (device);
if (r == -1)
/* do_pvcreate has already called reply_with_error */
goto done;
reply (NULL, NULL);
done:
xdr_free ((xdrproc_t) xdr_guestfs_pvcreate_args, (char *) &args);
}
static void vgcreate_stub (XDR *xdr_in)
{
int r;
struct guestfs_vgcreate_args args;
const char *volgroup;
char **physvols;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_vgcreate_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "vgcreate");
return;
}
volgroup = args.volgroup;
args.physvols.physvols_val = realloc (args.physvols.physvols_val, sizeof (char *) * (args.physvols.physvols_len+1));
args.physvols.physvols_val[args.physvols.physvols_len] = NULL;
physvols = args.physvols.physvols_val;
r = do_vgcreate (volgroup, physvols);
if (r == -1)
/* do_vgcreate has already called reply_with_error */
goto done;
reply (NULL, NULL);
done:
xdr_free ((xdrproc_t) xdr_guestfs_vgcreate_args, (char *) &args);
}
static void lvcreate_stub (XDR *xdr_in)
{
int r;
struct guestfs_lvcreate_args args;
const char *logvol;
const char *volgroup;
int mbytes;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_lvcreate_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "lvcreate");
return;
}
logvol = args.logvol;
volgroup = args.volgroup;
mbytes = args.mbytes;
r = do_lvcreate (logvol, volgroup, mbytes);
if (r == -1)
/* do_lvcreate has already called reply_with_error */
goto done;
reply (NULL, NULL);
done:
xdr_free ((xdrproc_t) xdr_guestfs_lvcreate_args, (char *) &args);
}
static void mkfs_stub (XDR *xdr_in)
{
int r;
struct guestfs_mkfs_args args;
const char *fstype;
const char *device;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_mkfs_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "mkfs");
return;
}
fstype = args.fstype;
device = args.device;
r = do_mkfs (fstype, device);
if (r == -1)
/* do_mkfs has already called reply_with_error */
goto done;
reply (NULL, NULL);
done:
xdr_free ((xdrproc_t) xdr_guestfs_mkfs_args, (char *) &args);
}
static void sfdisk_stub (XDR *xdr_in)
{
int r;
struct guestfs_sfdisk_args args;
const char *device;
int cyls;
int heads;
int sectors;
char **lines;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_sfdisk_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "sfdisk");
return;
}
device = args.device;
cyls = args.cyls;
heads = args.heads;
sectors = args.sectors;
args.lines.lines_val = realloc (args.lines.lines_val, sizeof (char *) * (args.lines.lines_len+1));
args.lines.lines_val[args.lines.lines_len] = NULL;
lines = args.lines.lines_val;
r = do_sfdisk (device, cyls, heads, sectors, lines);
if (r == -1)
/* do_sfdisk has already called reply_with_error */
goto done;
reply (NULL, NULL);
done:
xdr_free ((xdrproc_t) xdr_guestfs_sfdisk_args, (char *) &args);
}
static void write_file_stub (XDR *xdr_in)
{
int r;
struct guestfs_write_file_args args;
const char *path;
const char *content;
int size;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_write_file_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "write_file");
return;
}
path = args.path;
content = args.content;
size = args.size;
r = do_write_file (path, content, size);
if (r == -1)
/* do_write_file has already called reply_with_error */
goto done;
reply (NULL, NULL);
done:
xdr_free ((xdrproc_t) xdr_guestfs_write_file_args, (char *) &args);
}
static void umount_stub (XDR *xdr_in)
{
int r;
struct guestfs_umount_args args;
const char *pathordevice;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_umount_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "umount");
return;
}
pathordevice = args.pathordevice;
r = do_umount (pathordevice);
if (r == -1)
/* do_umount has already called reply_with_error */
goto done;
reply (NULL, NULL);
done:
xdr_free ((xdrproc_t) xdr_guestfs_umount_args, (char *) &args);
}
static void mounts_stub (XDR *xdr_in)
{
char **r;
r = do_mounts ();
if (r == NULL)
/* do_mounts has already called reply_with_error */
goto done;
struct guestfs_mounts_ret ret;
ret.devices.devices_len = count_strings (r);
ret.devices.devices_val = r;
reply ((xdrproc_t) &xdr_guestfs_mounts_ret, (char *) &ret);
free_strings (r);
done: ;
}
static void umount_all_stub (XDR *xdr_in)
{
int r;
r = do_umount_all ();
if (r == -1)
/* do_umount_all has already called reply_with_error */
goto done;
reply (NULL, NULL);
done: ;
}
static void lvm_remove_all_stub (XDR *xdr_in)
{
int r;
r = do_lvm_remove_all ();
if (r == -1)
/* do_lvm_remove_all has already called reply_with_error */
goto done;
reply (NULL, NULL);
done: ;
}
static void file_stub (XDR *xdr_in)
{
char *r;
struct guestfs_file_args args;
const char *path;
memset (&args, 0, sizeof args);
if (!xdr_guestfs_file_args (xdr_in, &args)) {
reply_with_error ("%s: daemon failed to decode procedure arguments", "file");
return;
}
path = args.path;
r = do_file (path);
if (r == NULL)
/* do_file has already called reply_with_error */
goto done;
struct guestfs_file_ret ret;
ret.description = r;
reply ((xdrproc_t) &xdr_guestfs_file_ret, (char *) &ret);
free (r);
done:
xdr_free ((xdrproc_t) xdr_guestfs_file_args, (char *) &args);
}
void dispatch_incoming_message (XDR *xdr_in)
{
switch (proc_nr) {
case GUESTFS_PROC_MOUNT:
mount_stub (xdr_in);
break;
case GUESTFS_PROC_SYNC:
sync_stub (xdr_in);
break;
case GUESTFS_PROC_TOUCH:
touch_stub (xdr_in);
break;
case GUESTFS_PROC_CAT:
cat_stub (xdr_in);
break;
case GUESTFS_PROC_LL:
ll_stub (xdr_in);
break;
case GUESTFS_PROC_LS:
ls_stub (xdr_in);
break;
case GUESTFS_PROC_LIST_DEVICES:
list_devices_stub (xdr_in);
break;
case GUESTFS_PROC_LIST_PARTITIONS:
list_partitions_stub (xdr_in);
break;
case GUESTFS_PROC_PVS:
pvs_stub (xdr_in);
break;
case GUESTFS_PROC_VGS:
vgs_stub (xdr_in);
break;
case GUESTFS_PROC_LVS:
lvs_stub (xdr_in);
break;
case GUESTFS_PROC_PVS_FULL:
pvs_full_stub (xdr_in);
break;
case GUESTFS_PROC_VGS_FULL:
vgs_full_stub (xdr_in);
break;
case GUESTFS_PROC_LVS_FULL:
lvs_full_stub (xdr_in);
break;
case GUESTFS_PROC_READ_LINES:
read_lines_stub (xdr_in);
break;
case GUESTFS_PROC_AUG_INIT:
aug_init_stub (xdr_in);
break;
case GUESTFS_PROC_AUG_CLOSE:
aug_close_stub (xdr_in);
break;
case GUESTFS_PROC_AUG_DEFVAR:
aug_defvar_stub (xdr_in);
break;
case GUESTFS_PROC_AUG_DEFNODE:
aug_defnode_stub (xdr_in);
break;
case GUESTFS_PROC_AUG_GET:
aug_get_stub (xdr_in);
break;
case GUESTFS_PROC_AUG_SET:
aug_set_stub (xdr_in);
break;
case GUESTFS_PROC_AUG_INSERT:
aug_insert_stub (xdr_in);
break;
case GUESTFS_PROC_AUG_RM:
aug_rm_stub (xdr_in);
break;
case GUESTFS_PROC_AUG_MV:
aug_mv_stub (xdr_in);
break;
case GUESTFS_PROC_AUG_MATCH:
aug_match_stub (xdr_in);
break;
case GUESTFS_PROC_AUG_SAVE:
aug_save_stub (xdr_in);
break;
case GUESTFS_PROC_AUG_LOAD:
aug_load_stub (xdr_in);
break;
case GUESTFS_PROC_AUG_LS:
aug_ls_stub (xdr_in);
break;
case GUESTFS_PROC_RM:
rm_stub (xdr_in);
break;
case GUESTFS_PROC_RMDIR:
rmdir_stub (xdr_in);
break;
case GUESTFS_PROC_RM_RF:
rm_rf_stub (xdr_in);
break;
case GUESTFS_PROC_MKDIR:
mkdir_stub (xdr_in);
break;
case GUESTFS_PROC_MKDIR_P:
mkdir_p_stub (xdr_in);
break;
case GUESTFS_PROC_CHMOD:
chmod_stub (xdr_in);
break;
case GUESTFS_PROC_CHOWN:
chown_stub (xdr_in);
break;
case GUESTFS_PROC_EXISTS:
exists_stub (xdr_in);
break;
case GUESTFS_PROC_IS_FILE:
is_file_stub (xdr_in);
break;
case GUESTFS_PROC_IS_DIR:
is_dir_stub (xdr_in);
break;
case GUESTFS_PROC_PVCREATE:
pvcreate_stub (xdr_in);
break;
case GUESTFS_PROC_VGCREATE:
vgcreate_stub (xdr_in);
break;
case GUESTFS_PROC_LVCREATE:
lvcreate_stub (xdr_in);
break;
case GUESTFS_PROC_MKFS:
mkfs_stub (xdr_in);
break;
case GUESTFS_PROC_SFDISK:
sfdisk_stub (xdr_in);
break;
case GUESTFS_PROC_WRITE_FILE:
write_file_stub (xdr_in);
break;
case GUESTFS_PROC_UMOUNT:
umount_stub (xdr_in);
break;
case GUESTFS_PROC_MOUNTS:
mounts_stub (xdr_in);
break;
case GUESTFS_PROC_UMOUNT_ALL:
umount_all_stub (xdr_in);
break;
case GUESTFS_PROC_LVM_REMOVE_ALL:
lvm_remove_all_stub (xdr_in);
break;
case GUESTFS_PROC_FILE:
file_stub (xdr_in);
break;
default:
reply_with_error ("dispatch_incoming_message: unknown procedure number %d", proc_nr);
}
}
static const char *lvm_pv_cols = "pv_name,pv_uuid,pv_fmt,pv_size,dev_size,pv_free,pv_used,pv_attr,pv_pe_count,pv_pe_alloc_count,pv_tags,pe_start,pv_mda_count,pv_mda_free";
static int lvm_tokenize_pv (char *str, struct guestfs_lvm_int_pv *r)
{
char *tok, *p, *next;
int i, j;
if (!str) {
fprintf (stderr, "%s: failed: passed a NULL string\n", __func__);
return -1;
}
if (!*str || isspace (*str)) {
fprintf (stderr, "%s: failed: passed a empty string or one beginning with whitespace\n", __func__);
return -1;
}
tok = str;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_name");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
r->pv_name = strdup (tok);
if (r->pv_name == NULL) {
perror ("strdup");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_uuid");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
for (i = j = 0; i < 32; ++j) {
if (tok[j] == '\0') {
fprintf (stderr, "%s: failed to parse UUID from '%s'\n", __func__, tok);
return -1;
} else if (tok[j] != '-')
r->pv_uuid[i++] = tok[j];
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_fmt");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
r->pv_fmt = strdup (tok);
if (r->pv_fmt == NULL) {
perror ("strdup");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_size");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNu64, &r->pv_size) != 1) {
fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "pv_size");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "dev_size");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNu64, &r->dev_size) != 1) {
fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "dev_size");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_free");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNu64, &r->pv_free) != 1) {
fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "pv_free");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_used");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNu64, &r->pv_used) != 1) {
fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "pv_used");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_attr");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
r->pv_attr = strdup (tok);
if (r->pv_attr == NULL) {
perror ("strdup");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_pe_count");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNi64, &r->pv_pe_count) != 1) {
fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "pv_pe_count");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_pe_alloc_count");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNi64, &r->pv_pe_alloc_count) != 1) {
fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "pv_pe_alloc_count");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_tags");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
r->pv_tags = strdup (tok);
if (r->pv_tags == NULL) {
perror ("strdup");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pe_start");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNu64, &r->pe_start) != 1) {
fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "pe_start");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_mda_count");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNi64, &r->pv_mda_count) != 1) {
fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "pv_mda_count");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_mda_free");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNu64, &r->pv_mda_free) != 1) {
fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "pv_mda_free");
return -1;
}
tok = next;
if (tok != NULL) {
fprintf (stderr, "%s: failed: extra tokens at end of string\n", __func__);
return -1;
}
return 0;
}
guestfs_lvm_int_pv_list *
parse_command_line_pvs (void)
{
char *out, *err;
char *p, *pend;
int r, i;
guestfs_lvm_int_pv_list *ret;
void *newp;
ret = malloc (sizeof *ret);
if (!ret) {
reply_with_perror ("malloc");
return NULL;
}
ret->guestfs_lvm_int_pv_list_len = 0;
ret->guestfs_lvm_int_pv_list_val = NULL;
r = command (&out, &err,
"/sbin/lvm", "pvs",
"-o", lvm_pv_cols, "--unbuffered", "--noheadings",
"--nosuffix", "--separator", ",", "--units", "b", NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
free (err);
return NULL;
}
free (err);
/* Tokenize each line of the output. */
p = out;
i = 0;
while (p) {
pend = strchr (p, '\n'); /* Get the next line of output. */
if (pend) {
*pend = '\0';
pend++;
}
while (*p && isspace (*p)) /* Skip any leading whitespace. */
p++;
if (!*p) { /* Empty line? Skip it. */
p = pend;
continue;
}
/* Allocate some space to store this next entry. */
newp = realloc (ret->guestfs_lvm_int_pv_list_val,
sizeof (guestfs_lvm_int_pv) * (i+1));
if (newp == NULL) {
reply_with_perror ("realloc");
free (ret->guestfs_lvm_int_pv_list_val);
free (ret);
free (out);
return NULL;
}
ret->guestfs_lvm_int_pv_list_val = newp;
/* Tokenize the next entry. */
r = lvm_tokenize_pv (p, &ret->guestfs_lvm_int_pv_list_val[i]);
if (r == -1) {
reply_with_error ("failed to parse output of 'pvs' command");
free (ret->guestfs_lvm_int_pv_list_val);
free (ret);
free (out);
return NULL;
}
++i;
p = pend;
}
ret->guestfs_lvm_int_pv_list_len = i;
free (out);
return ret;
}
static const char *lvm_vg_cols = "vg_name,vg_uuid,vg_fmt,vg_attr,vg_size,vg_free,vg_sysid,vg_extent_size,vg_extent_count,vg_free_count,max_lv,max_pv,pv_count,lv_count,snap_count,vg_seqno,vg_tags,vg_mda_count,vg_mda_free";
static int lvm_tokenize_vg (char *str, struct guestfs_lvm_int_vg *r)
{
char *tok, *p, *next;
int i, j;
if (!str) {
fprintf (stderr, "%s: failed: passed a NULL string\n", __func__);
return -1;
}
if (!*str || isspace (*str)) {
fprintf (stderr, "%s: failed: passed a empty string or one beginning with whitespace\n", __func__);
return -1;
}
tok = str;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_name");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
r->vg_name = strdup (tok);
if (r->vg_name == NULL) {
perror ("strdup");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_uuid");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
for (i = j = 0; i < 32; ++j) {
if (tok[j] == '\0') {
fprintf (stderr, "%s: failed to parse UUID from '%s'\n", __func__, tok);
return -1;
} else if (tok[j] != '-')
r->vg_uuid[i++] = tok[j];
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_fmt");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
r->vg_fmt = strdup (tok);
if (r->vg_fmt == NULL) {
perror ("strdup");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_attr");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
r->vg_attr = strdup (tok);
if (r->vg_attr == NULL) {
perror ("strdup");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_size");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNu64, &r->vg_size) != 1) {
fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "vg_size");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_free");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNu64, &r->vg_free) != 1) {
fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "vg_free");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_sysid");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
r->vg_sysid = strdup (tok);
if (r->vg_sysid == NULL) {
perror ("strdup");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_extent_size");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNu64, &r->vg_extent_size) != 1) {
fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "vg_extent_size");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_extent_count");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNi64, &r->vg_extent_count) != 1) {
fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "vg_extent_count");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_free_count");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNi64, &r->vg_free_count) != 1) {
fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "vg_free_count");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "max_lv");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNi64, &r->max_lv) != 1) {
fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "max_lv");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "max_pv");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNi64, &r->max_pv) != 1) {
fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "max_pv");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "pv_count");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNi64, &r->pv_count) != 1) {
fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "pv_count");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "lv_count");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNi64, &r->lv_count) != 1) {
fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "lv_count");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "snap_count");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNi64, &r->snap_count) != 1) {
fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "snap_count");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_seqno");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNi64, &r->vg_seqno) != 1) {
fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "vg_seqno");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_tags");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
r->vg_tags = strdup (tok);
if (r->vg_tags == NULL) {
perror ("strdup");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_mda_count");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNi64, &r->vg_mda_count) != 1) {
fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "vg_mda_count");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "vg_mda_free");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNu64, &r->vg_mda_free) != 1) {
fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "vg_mda_free");
return -1;
}
tok = next;
if (tok != NULL) {
fprintf (stderr, "%s: failed: extra tokens at end of string\n", __func__);
return -1;
}
return 0;
}
guestfs_lvm_int_vg_list *
parse_command_line_vgs (void)
{
char *out, *err;
char *p, *pend;
int r, i;
guestfs_lvm_int_vg_list *ret;
void *newp;
ret = malloc (sizeof *ret);
if (!ret) {
reply_with_perror ("malloc");
return NULL;
}
ret->guestfs_lvm_int_vg_list_len = 0;
ret->guestfs_lvm_int_vg_list_val = NULL;
r = command (&out, &err,
"/sbin/lvm", "vgs",
"-o", lvm_vg_cols, "--unbuffered", "--noheadings",
"--nosuffix", "--separator", ",", "--units", "b", NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
free (err);
return NULL;
}
free (err);
/* Tokenize each line of the output. */
p = out;
i = 0;
while (p) {
pend = strchr (p, '\n'); /* Get the next line of output. */
if (pend) {
*pend = '\0';
pend++;
}
while (*p && isspace (*p)) /* Skip any leading whitespace. */
p++;
if (!*p) { /* Empty line? Skip it. */
p = pend;
continue;
}
/* Allocate some space to store this next entry. */
newp = realloc (ret->guestfs_lvm_int_vg_list_val,
sizeof (guestfs_lvm_int_vg) * (i+1));
if (newp == NULL) {
reply_with_perror ("realloc");
free (ret->guestfs_lvm_int_vg_list_val);
free (ret);
free (out);
return NULL;
}
ret->guestfs_lvm_int_vg_list_val = newp;
/* Tokenize the next entry. */
r = lvm_tokenize_vg (p, &ret->guestfs_lvm_int_vg_list_val[i]);
if (r == -1) {
reply_with_error ("failed to parse output of 'vgs' command");
free (ret->guestfs_lvm_int_vg_list_val);
free (ret);
free (out);
return NULL;
}
++i;
p = pend;
}
ret->guestfs_lvm_int_vg_list_len = i;
free (out);
return ret;
}
static const char *lvm_lv_cols = "lv_name,lv_uuid,lv_attr,lv_major,lv_minor,lv_kernel_major,lv_kernel_minor,lv_size,seg_count,origin,snap_percent,copy_percent,move_pv,lv_tags,mirror_log,modules";
static int lvm_tokenize_lv (char *str, struct guestfs_lvm_int_lv *r)
{
char *tok, *p, *next;
int i, j;
if (!str) {
fprintf (stderr, "%s: failed: passed a NULL string\n", __func__);
return -1;
}
if (!*str || isspace (*str)) {
fprintf (stderr, "%s: failed: passed a empty string or one beginning with whitespace\n", __func__);
return -1;
}
tok = str;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "lv_name");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
r->lv_name = strdup (tok);
if (r->lv_name == NULL) {
perror ("strdup");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "lv_uuid");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
for (i = j = 0; i < 32; ++j) {
if (tok[j] == '\0') {
fprintf (stderr, "%s: failed to parse UUID from '%s'\n", __func__, tok);
return -1;
} else if (tok[j] != '-')
r->lv_uuid[i++] = tok[j];
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "lv_attr");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
r->lv_attr = strdup (tok);
if (r->lv_attr == NULL) {
perror ("strdup");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "lv_major");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNi64, &r->lv_major) != 1) {
fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "lv_major");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "lv_minor");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNi64, &r->lv_minor) != 1) {
fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "lv_minor");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "lv_kernel_major");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNi64, &r->lv_kernel_major) != 1) {
fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "lv_kernel_major");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "lv_kernel_minor");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNi64, &r->lv_kernel_minor) != 1) {
fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "lv_kernel_minor");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "lv_size");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNu64, &r->lv_size) != 1) {
fprintf (stderr, "%s: failed to parse size '%s' from token %s\n", __func__, tok, "lv_size");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "seg_count");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (sscanf (tok, "%"SCNi64, &r->seg_count) != 1) {
fprintf (stderr, "%s: failed to parse int '%s' from token %s\n", __func__, tok, "seg_count");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "origin");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
r->origin = strdup (tok);
if (r->origin == NULL) {
perror ("strdup");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "snap_percent");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (tok[0] == '\0')
r->snap_percent = -1;
else if (sscanf (tok, "%f", &r->snap_percent) != 1) {
fprintf (stderr, "%s: failed to parse float '%s' from token %s\n", __func__, tok, "snap_percent");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "copy_percent");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
if (tok[0] == '\0')
r->copy_percent = -1;
else if (sscanf (tok, "%f", &r->copy_percent) != 1) {
fprintf (stderr, "%s: failed to parse float '%s' from token %s\n", __func__, tok, "copy_percent");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "move_pv");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
r->move_pv = strdup (tok);
if (r->move_pv == NULL) {
perror ("strdup");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "lv_tags");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
r->lv_tags = strdup (tok);
if (r->lv_tags == NULL) {
perror ("strdup");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "mirror_log");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
r->mirror_log = strdup (tok);
if (r->mirror_log == NULL) {
perror ("strdup");
return -1;
}
tok = next;
if (!tok) {
fprintf (stderr, "%s: failed: string finished early, around token %s\n", __func__, "modules");
return -1;
}
p = strchrnul (tok, ',');
if (*p) next = p+1; else next = NULL;
*p = '\0';
r->modules = strdup (tok);
if (r->modules == NULL) {
perror ("strdup");
return -1;
}
tok = next;
if (tok != NULL) {
fprintf (stderr, "%s: failed: extra tokens at end of string\n", __func__);
return -1;
}
return 0;
}
guestfs_lvm_int_lv_list *
parse_command_line_lvs (void)
{
char *out, *err;
char *p, *pend;
int r, i;
guestfs_lvm_int_lv_list *ret;
void *newp;
ret = malloc (sizeof *ret);
if (!ret) {
reply_with_perror ("malloc");
return NULL;
}
ret->guestfs_lvm_int_lv_list_len = 0;
ret->guestfs_lvm_int_lv_list_val = NULL;
r = command (&out, &err,
"/sbin/lvm", "lvs",
"-o", lvm_lv_cols, "--unbuffered", "--noheadings",
"--nosuffix", "--separator", ",", "--units", "b", NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
free (err);
return NULL;
}
free (err);
/* Tokenize each line of the output. */
p = out;
i = 0;
while (p) {
pend = strchr (p, '\n'); /* Get the next line of output. */
if (pend) {
*pend = '\0';
pend++;
}
while (*p && isspace (*p)) /* Skip any leading whitespace. */
p++;
if (!*p) { /* Empty line? Skip it. */
p = pend;
continue;
}
/* Allocate some space to store this next entry. */
newp = realloc (ret->guestfs_lvm_int_lv_list_val,
sizeof (guestfs_lvm_int_lv) * (i+1));
if (newp == NULL) {
reply_with_perror ("realloc");
free (ret->guestfs_lvm_int_lv_list_val);
free (ret);
free (out);
return NULL;
}
ret->guestfs_lvm_int_lv_list_val = newp;
/* Tokenize the next entry. */
r = lvm_tokenize_lv (p, &ret->guestfs_lvm_int_lv_list_val[i]);
if (r == -1) {
reply_with_error ("failed to parse output of 'lvs' command");
free (ret->guestfs_lvm_int_lv_list_val);
free (ret);
free (out);
return NULL;
}
++i;
p = pend;
}
ret->guestfs_lvm_int_lv_list_len = i;
free (out);
return ret;
}