/* We need to rewrite the root path so it is based at /sysroot. */
int
-do_aug_init (char *root, int flags)
+do_aug_init (const char *root, int flags)
{
#ifdef HAVE_AUGEAS
char *buf;
- NEED_ROOT (return -1);
- ABS_PATH (root, return -1);
-
if (aug) {
aug_close (aug);
aug = NULL;
}
int
-do_aug_defvar (char *name, char *expr)
+do_aug_defvar (const char *name, const char *expr)
{
#ifdef HAVE_AUG_DEFVAR
int r;
}
guestfs_int_int_bool *
-do_aug_defnode (char *name, char *expr, char *val)
+do_aug_defnode (const char *name, const char *expr, const char *val)
{
#ifdef HAVE_AUG_DEFNODE
static guestfs_int_int_bool r;
}
char *
-do_aug_get (char *path)
+do_aug_get (const char *path)
{
#ifdef HAVE_AUGEAS
const char *value = NULL;
}
int
-do_aug_set (char *path, char *val)
+do_aug_set (const char *path, const char *val)
{
#ifdef HAVE_AUGEAS
int r;
}
int
-do_aug_insert (char *path, char *label, int before)
+do_aug_insert (const char *path, const char *label, int before)
{
#ifdef HAVE_AUGEAS
int r;
}
int
-do_aug_rm (char *path)
+do_aug_rm (const char *path)
{
#ifdef HAVE_AUGEAS
int r;
}
int
-do_aug_mv (char *src, char *dest)
+do_aug_mv (const char *src, const char *dest)
{
#ifdef HAVE_AUGEAS
int r;
}
char **
-do_aug_match (char *path)
+do_aug_match (const char *path)
{
#ifdef HAVE_AUGEAS
char **matches = NULL;
/* Simpler version of aug-match, which also sorts the output. */
char **
-do_aug_ls (char *path)
+do_aug_ls (const char *path)
{
#ifdef HAVE_AUGEAS
char **matches;
* we centralize it in one call.
*/
static int64_t
-call_blockdev (char *device, char *switc, int extraarg, int prints)
+call_blockdev (const char *device, char *switc, int extraarg, int prints)
{
int r;
int64_t rv;
}
int
-do_blockdev_setro (char *device)
+do_blockdev_setro (const char *device)
{
return (int) call_blockdev (device, "--setro", 0, 0);
}
int
-do_blockdev_setrw (char *device)
+do_blockdev_setrw (const char *device)
{
return (int) call_blockdev (device, "--setrw", 0, 0);
}
int
-do_blockdev_getro (char *device)
+do_blockdev_getro (const char *device)
{
return (int) call_blockdev (device, "--getro", 0, 1);
}
int
-do_blockdev_getss (char *device)
+do_blockdev_getss (const char *device)
{
return (int) call_blockdev (device, "--getss", 0, 1);
}
int
-do_blockdev_getbsz (char *device)
+do_blockdev_getbsz (const char *device)
{
return (int) call_blockdev (device, "--getbsz", 0, 1);
}
int
-do_blockdev_setbsz (char *device, int blocksize)
+do_blockdev_setbsz (const char *device, int blocksize)
{
if (blocksize <= 0 /* || blocksize >= what? */) {
reply_with_error ("blockdev_setbsz: blocksize must be > 0");
}
int64_t
-do_blockdev_getsz (char *device)
+do_blockdev_getsz (const char *device)
{
return call_blockdev (device, "--getsz", 0, 1);
}
int64_t
-do_blockdev_getsize64 (char *device)
+do_blockdev_getsize64 (const char *device)
{
return call_blockdev (device, "--getsize64", 0, 1);
}
int
-do_blockdev_flushbufs (char *device)
+do_blockdev_flushbufs (const char *device)
{
return call_blockdev (device, "--flushbufs", 0, 0);
}
int
-do_blockdev_rereadpt (char *device)
+do_blockdev_rereadpt (const char *device)
{
return call_blockdev (device, "--rereadpt", 0, 0);
}
#include "actions.h"
char *
-do_checksum (char *csumtype, char *path)
+do_checksum (const char *csumtype, const char *path)
{
const char *program;
char *buf;
int r;
int len;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
if (strcasecmp (csumtype, "crc") == 0)
program = "cksum";
else if (strcasecmp (csumtype, "md5") == 0)
#include "actions.h"
int
-do_equal (char *file1, char *file2)
+do_equal (const char *file1, const char *file2)
{
char *file1buf, *file2buf;
char *err;
}
char *
-do_sh (char *command)
+do_sh (const char *command)
{
char *argv[] = { "/bin/sh", "-c", command, NULL };
}
char **
-do_sh_lines (char *command)
+do_sh_lines (const char *command)
{
char *argv[] = { "/bin/sh", "-c", command, NULL };
static int cpmv_cmd (const char *cmd, const char *flags, const char *src, const char *dest);
int
-do_cp (char *src, char *dest)
+do_cp (const char *src, const char *dest)
{
return cpmv_cmd ("cp", NULL, src, dest);
}
int
-do_cp_a (char *src, char *dest)
+do_cp_a (const char *src, const char *dest)
{
return cpmv_cmd ("cp", "-a", src, dest);
}
int
-do_mv (char *src, char *dest)
+do_mv (const char *src, const char *dest)
{
return cpmv_cmd ("mv", NULL, src, dest);
}
#endif
char *
-do_debug (char *subcmd MAYBE_UNUSED, char **argv MAYBE_UNUSED)
+do_debug (const char *subcmd MAYBE_UNUSED, char **argv MAYBE_UNUSED)
{
#if ENABLE_DEBUG_COMMAND
int argc, i;
}
int
-do_mkfs (char *fstype, char *device)
+do_mkfs (const char *fstype, const char *device)
{
char *err;
int r;
#include "actions.h"
int
-do_rmdir (char *path)
+do_rmdir (const char *path)
{
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = rmdir (path);
CHROOT_OUT;
* do stupid stuff, who are we to try to stop them?
*/
int
-do_rm_rf (char *path)
+do_rm_rf (const char *path)
{
int r;
char *buf, *err;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
if (strcmp (path, "/") == 0) {
reply_with_error ("rm -rf: cannot remove root directory");
return -1;
}
int
-do_mkdir (char *path)
+do_mkdir (const char *path)
{
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = mkdir (path, 0777);
CHROOT_OUT;
}
int
-do_mkdir_p (char *path)
+do_mkdir_p (const char *path)
{
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = recursive_mkdir (path);
CHROOT_OUT;
}
int
-do_is_dir (char *path)
+do_is_dir (const char *path)
{
int r;
struct stat buf;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = lstat (path, &buf);
CHROOT_OUT;
#include "actions.h"
int64_t
-do_du (char *path)
+do_du (const char *path)
{
int r;
int64_t rv;
char *out, *err;
char *buf;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
/* Make the path relative to /sysroot. */
buf = sysroot_path (path);
if (!buf) {
#include "actions.h"
char **
-do_tune2fs_l (char *device)
+do_tune2fs_l (const char *device)
{
int r;
char *out, *err;
}
int
-do_set_e2label (char *device, char *label)
+do_set_e2label (const char *device, const char *label)
{
int r;
char *err;
}
char *
-do_get_e2label (char *device)
+do_get_e2label (const char *device)
{
int r, len;
char *out, *err;
}
int
-do_set_e2uuid (char *device, char *uuid)
+do_set_e2uuid (const char *device, const char *uuid)
{
int r;
char *err;
}
char *
-do_get_e2uuid (char *device)
+do_get_e2uuid (const char *device)
{
int r;
char *out, *err, *p, *q;
}
int
-do_resize2fs (char *device)
+do_resize2fs (const char *device)
{
char *err;
int r;
}
int
-do_e2fsck_f (char *device)
+do_e2fsck_f (const char *device)
{
char *err;
int r;
#include "actions.h"
int
-do_fallocate (char *path, int len)
+do_fallocate (const char *path, int len)
{
int fd, r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
fd = open (path, O_WRONLY | O_CREAT | O_TRUNC | O_NOCTTY, 0666);
CHROOT_OUT;
#include "actions.h"
int
-do_touch (char *path)
+do_touch (const char *path)
{
int fd;
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
fd = open (path, O_WRONLY | O_CREAT | O_NOCTTY, 0666);
CHROOT_OUT;
}
char *
-do_cat (char *path)
+do_cat (const char *path)
{
int fd;
int alloc, size, r, max;
char *buf, *buf2;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
CHROOT_IN;
fd = open (path, O_RDONLY);
CHROOT_OUT;
}
char **
-do_read_lines (char *path)
+do_read_lines (const char *path)
{
char **r = NULL;
int size = 0, alloc = 0;
size_t len = 0;
ssize_t n;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
CHROOT_IN;
fp = fopen (path, "r");
CHROOT_OUT;
}
int
-do_rm (char *path)
+do_rm (const char *path)
{
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = unlink (path);
CHROOT_OUT;
}
int
-do_chmod (int mode, char *path)
+do_chmod (int mode, const char *path)
{
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = chmod (path, mode);
CHROOT_OUT;
}
int
-do_chown (int owner, int group, char *path)
+do_chown (int owner, int group, const char *path)
{
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = chown (path, owner, group);
CHROOT_OUT;
}
int
-do_exists (char *path)
+do_exists (const char *path)
{
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = access (path, F_OK);
CHROOT_OUT;
}
int
-do_is_file (char *path)
+do_is_file (const char *path)
{
int r;
struct stat buf;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = lstat (path, &buf);
CHROOT_OUT;
}
int
-do_write_file (char *path, char *content, int size)
+do_write_file (const char *path, const char *content, int size)
{
int fd;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
if (size == 0)
size = strlen (content);
}
char *
-do_read_file (char *path, size_t *size_r)
+do_read_file (const char *path, size_t *size_r)
{
int fd;
struct stat statbuf;
char *r;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
CHROOT_IN;
fd = open (path, O_RDONLY);
CHROOT_OUT;
/* This runs the 'file' command. */
char *
-do_file (char *path)
+do_file (const char *path)
{
char *out, *err;
int r, freeit = 0;
/* zcat | file */
char *
-do_zfile (char *method, char *path)
+do_zfile (const char *method, const char *path)
{
int len;
const char *zcat;
FILE *fp;
char line[256];
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
if (strcmp (method, "gzip") == 0 || strcmp (method, "compress") == 0)
zcat = "zcat";
else if (strcmp (method, "bzip2") == 0)
}
char **
-do_find (char *dir)
+do_find (const char *dir)
{
struct stat statbuf;
int r, len, sysrootdirlen;
char *sysrootdir;
char str[PATH_MAX];
- NEED_ROOT (return NULL);
- ABS_PATH (dir, return NULL);
-
sysrootdir = sysroot_path (dir);
if (!sysrootdir) {
reply_with_perror ("malloc");
#include "actions.h"
int
-do_fsck (char *fstype, char *device)
+do_fsck (const char *fstype, const char *device)
{
char *err;
int r;
#include "actions.h"
char **
-do_glob_expand (char *pattern)
+do_glob_expand (const char *pattern)
{
int r;
glob_t buf;
- NEED_ROOT (return NULL);
- ABS_PATH (pattern, return NULL); /* Required so chroot can be used. */
-
/* glob(3) in glibc never calls chdir, so this seems to be safe: */
CHROOT_IN;
r = glob (pattern, GLOB_MARK|GLOB_BRACE, NULL, &buf);
#include "actions.h"
static char **
-grep (const char *prog, const char *flag, char *regex, char *path)
+grep (const char *prog, const char *flag, const char *regex, const char *path)
{
char *buf;
char *out, *err;
int r;
char **lines;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
/* Make the path relative to /sysroot. */
buf = sysroot_path (path);
if (!buf) {
}
char **
-do_grep (char *regex, char *path)
+do_grep (const char *regex, const char *path)
{
/* The "--" is not really needed, but it helps when we don't need a flag. */
return grep ("grep", "--", regex, path);
}
char **
-do_egrep (char *regex, char *path)
+do_egrep (const char *regex, const char *path)
{
return grep ("egrep", "--", regex, path);
}
char **
-do_fgrep (char *regex, char *path)
+do_fgrep (const char *regex, const char *path)
{
return grep ("fgrep", "--", regex, path);
}
char **
-do_grepi (char *regex, char *path)
+do_grepi (const char *regex, const char *path)
{
return grep ("grep", "-i", regex, path);
}
char **
-do_egrepi (char *regex, char *path)
+do_egrepi (const char *regex, const char *path)
{
return grep ("egrep", "-i", regex, path);
}
char **
-do_fgrepi (char *regex, char *path)
+do_fgrepi (const char *regex, const char *path)
{
return grep ("fgrep", "-i", regex, path);
}
char **
-do_zgrep (char *regex, char *path)
+do_zgrep (const char *regex, const char *path)
{
return grep ("zgrep", "--", regex, path);
}
char **
-do_zegrep (char *regex, char *path)
+do_zegrep (const char *regex, const char *path)
{
return grep ("zegrep", "--", regex, path);
}
char **
-do_zfgrep (char *regex, char *path)
+do_zfgrep (const char *regex, const char *path)
{
return grep ("zfgrep", "--", regex, path);
}
char **
-do_zgrepi (char *regex, char *path)
+do_zgrepi (const char *regex, const char *path)
{
return grep ("zgrep", "-i", regex, path);
}
char **
-do_zegrepi (char *regex, char *path)
+do_zegrepi (const char *regex, const char *path)
{
return grep ("zegrep", "-i", regex, path);
}
char **
-do_zfgrepi (char *regex, char *path)
+do_zfgrepi (const char *regex, const char *path)
{
return grep ("zfgrep", "-i", regex, path);
}
#include "actions.h"
int
-do_grub_install (char *root, char *device)
+do_grub_install (const char *root, const char *device)
{
int r;
char *err;
char *buf;
- NEED_ROOT (return -1);
- ABS_PATH (root, return -1);
-
if (asprintf_nowarn (&buf, "--root-directory=%R", root) == -1) {
reply_with_perror ("asprintf");
return -1;
#include "actions.h"
static char **
-headtail (const char *prog, const char *flag, const char *n, char *path)
+headtail (const char *prog, const char *flag, const char *n, const char *path)
{
char *buf;
char *out, *err;
int r;
char **lines;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
/* Make the path relative to /sysroot. */
buf = sysroot_path (path);
if (!buf) {
}
char **
-do_head (char *path)
+do_head (const char *path)
{
return headtail ("head", "-n", "10", path);
}
char **
-do_tail (char *path)
+do_tail (const char *path)
{
return headtail ("tail", "-n", "10", path);
}
char **
-do_head_n (int n, char *path)
+do_head_n (int n, const char *path)
{
char nbuf[16];
}
char **
-do_tail_n (int n, char *path)
+do_tail_n (int n, const char *path)
{
char nbuf[16];
#include "actions.h"
char *
-do_hexdump (char *path)
+do_hexdump (const char *path)
{
char *buf;
int r;
char *out, *err;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
buf = sysroot_path (path);
if (!buf) {
reply_with_perror ("malloc");
#include "actions.h"
char **
-do_initrd_list (char *path)
+do_initrd_list (const char *path)
{
FILE *fp;
char *cmd;
int size = 0, alloc = 0;
size_t len;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
/* "zcat /sysroot/<path> | cpio --quiet -it", but path must be quoted. */
if (asprintf_nowarn (&cmd, "zcat %R | cpio --quiet -it", path) == -1) {
reply_with_perror ("asprintf");
}
int64_t
-do_inotify_add_watch (char *path, int mask)
+do_inotify_add_watch (const char *path, int mask)
{
int64_t r;
char *buf;
#include "actions.h"
char *
-do_readlink (char *path)
+do_readlink (const char *path)
{
ssize_t r;
char *ret;
char link[PATH_MAX];
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
CHROOT_IN;
r = readlink (path, link, sizeof link);
CHROOT_OUT;
char *buf_linkname;
char *buf_target;
- NEED_ROOT (return -1);
- ABS_PATH (linkname, return -1);
- /* but target does not need to be absolute */
-
/* Prefix linkname with sysroot. */
buf_linkname = sysroot_path (linkname);
if (!buf_linkname) {
}
int
-do_ln (char *target, char *linkname)
+do_ln (const char *target, const char *linkname)
{
return _link (NULL, 0, target, linkname);
}
int
-do_ln_f (char *target, char *linkname)
+do_ln_f (const char *target, const char *linkname)
{
return _link ("-f", 0, target, linkname);
}
int
-do_ln_s (char *target, char *linkname)
+do_ln_s (const char *target, const char *linkname)
{
return _link ("-s", 1, target, linkname);
}
int
-do_ln_sf (char *target, char *linkname)
+do_ln_sf (const char *target, const char *linkname)
{
return _link ("-sf", 1, target, linkname);
}
#include "actions.h"
char **
-do_ls (char *path)
+do_ls (const char *path)
{
char **r = NULL;
int size = 0, alloc = 0;
DIR *dir;
struct dirent *d;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
CHROOT_IN;
dir = opendir (path);
CHROOT_OUT;
*/
char *
-do_ll (char *path)
+do_ll (const char *path)
{
int r;
char *out, *err;
char *spath;
- NEED_ROOT (NULL);
- ABS_PATH (path, NULL);
-
spath = sysroot_path (path);
if (!spath) {
reply_with_perror ("malloc");
*/
static char **
-convert_lvm_output (char *out, char *prefix)
+convert_lvm_output (char *out, const char *prefix)
{
char *p, *pend;
char **r = NULL;
}
int
-do_pvcreate (char *device)
+do_pvcreate (const char *device)
{
char *err;
int r;
}
int
-do_vgcreate (char *volgroup, char **physvols)
+do_vgcreate (const char *volgroup, char **physvols)
{
char *err;
int r, argc, i;
}
int
-do_lvcreate (char *logvol, char *volgroup, int mbytes)
+do_lvcreate (const char *logvol, const char *volgroup, int mbytes)
{
char *err;
int r;
}
int
-do_lvresize (char *logvol, int mbytes)
+do_lvresize (const char *logvol, int mbytes)
{
char *err;
int r;
char size[64];
- RESOLVE_DEVICE (logvol, return -1);
-
snprintf (size, sizeof size, "%d", mbytes);
r = command (NULL, &err,
}
int
-do_lvremove (char *device)
+do_lvremove (const char *device)
{
char *err;
int r;
}
int
-do_vgremove (char *device)
+do_vgremove (const char *device)
{
char *err;
int r;
}
int
-do_pvremove (char *device)
+do_pvremove (const char *device)
{
char *err;
int r;
}
int
-do_pvresize (char *device)
+do_pvresize (const char *device)
{
char *err;
int r;
#include "actions.h"
int
-do_mknod (int mode, int devmajor, int devminor, char *path)
+do_mknod (int mode, int devmajor, int devminor, const char *path)
{
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = mknod (path, mode, makedev (devmajor, devminor));
CHROOT_OUT;
}
int
-do_mkfifo (int mode, char *path)
+do_mkfifo (int mode, const char *path)
{
return do_mknod (mode | S_IFIFO, 0, 0, path);
}
int
-do_mknod_b (int mode, int devmajor, int devminor, char *path)
+do_mknod_b (int mode, int devmajor, int devminor, const char *path)
{
return do_mknod (mode | S_IFBLK, devmajor, devminor, path);
}
int
-do_mknod_c (int mode, int devmajor, int devminor, char *path)
+do_mknod_c (int mode, int devmajor, int devminor, const char *path)
{
return do_mknod (mode | S_IFCHR, devmajor, devminor, path);
}
*/
int
-do_mount_vfs (char *options, char *vfstype,
- char *device, char *mountpoint)
+do_mount_vfs (const char *options, const char *vfstype,
+ const char *device, const char *mountpoint)
{
int r, is_root;
char *mp;
}
int
-do_mount (char *device, char *mountpoint)
+do_mount (const char *device, const char *mountpoint)
{
return do_mount_vfs ("sync,noatime", NULL, device, mountpoint);
}
int
-do_mount_ro (char *device, char *mountpoint)
+do_mount_ro (const char *device, const char *mountpoint)
{
return do_mount_vfs ("ro", NULL, device, mountpoint);
}
int
-do_mount_options (char *options, char *device,
- char *mountpoint)
+do_mount_options (const char *options, const char *device,
+ const char *mountpoint)
{
return do_mount_vfs (options, NULL, device, mountpoint);
}
* is kept updated.
*/
int
-do_umount (char *pathordevice)
+do_umount (const char *pathordevice)
{
int freeit = 0, r;
char *buf;
* device.
*/
int
-do_mount_loop (char *file, char *mountpoint)
+do_mount_loop (const char *file, const char *mountpoint)
{
int r;
char *buf, *mp;
char *error;
- NEED_ROOT (return -1);
- ABS_PATH (file, return -1);
-
/* We have to prefix /sysroot on both the filename and the mountpoint. */
mp = sysroot_path (mountpoint);
if (!mp) {
* mkmountpoint case) set the root_mounted flag.
*/
int
-do_mkmountpoint (char *path)
+do_mkmountpoint (const char *path)
{
int r;
}
int
-do_rmmountpoint (char *path)
+do_rmmountpoint (const char *path)
{
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = rmdir (path);
CHROOT_OUT;
#include "actions.h"
int
-do_ntfs_3g_probe (int rw, char *device)
+do_ntfs_3g_probe (int rw, const char *device)
{
char *err;
int r;
#include "actions.h"
guestfs_int_dirent_list *
-do_readdir (char *path)
+do_readdir (const char *path)
{
guestfs_int_dirent_list *ret;
guestfs_int_dirent v;
struct dirent *d;
int i;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
ret = malloc (sizeof *ret);
if (ret == NULL) {
reply_with_perror ("malloc");
#include "actions.h"
char *
-do_realpath (char *path)
+do_realpath (const char *path)
{
char *ret;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
CHROOT_IN;
ret = realpath (path, NULL);
CHROOT_OUT;
#include "actions.h"
int
-do_scrub_device (char *device)
+do_scrub_device (const char *device)
{
char *err;
int r;
}
int
-do_scrub_file (char *file)
+do_scrub_file (const char *file)
{
char *buf;
char *err;
int r;
- NEED_ROOT (return -1);
- ABS_PATH (file, return -1);
-
/* Make the path relative to /sysroot. */
buf = sysroot_path (file);
if (!buf) {
}
int
-do_scrub_freespace (char *dir)
+do_scrub_freespace (const char *dir)
{
char *buf;
char *err;
int r;
- NEED_ROOT (return -1);
- ABS_PATH (dir, return -1);
-
/* Make the path relative to /sysroot. */
buf = sysroot_path (dir);
if (!buf) {
* - enforcing=0
*/
int
-do_setcon (char *context)
+do_setcon (const char *context)
{
#ifdef HAVE_SETCON
if (setcon ((char *) context) == -1) {
#include "actions.h"
static int
-sfdisk (char *device, int n, int cyls, int heads, int sectors,
+sfdisk (const char *device, int n, int cyls, int heads, int sectors,
const char *extra_flag,
char * const* const lines)
{
}
int
-do_sfdisk (char *device, int cyls, int heads, int sectors,
+do_sfdisk (const char *device, int cyls, int heads, int sectors,
char **lines)
{
return sfdisk (device, 0, cyls, heads, sectors, NULL, lines);
}
int
-do_sfdisk_N (char *device, int n, int cyls, int heads, int sectors,
- char *line)
+do_sfdisk_N (const char *device, int n, int cyls, int heads, int sectors,
+ const char *line)
{
const char *lines[2] = { line, NULL };
}
int
-do_sfdiskM (char *device, char **lines)
+do_sfdiskM (const char *device, char **lines)
{
return sfdisk (device, 0, 0, 0, 0, "-uM", lines);
}
static char *
-sfdisk_flag (char *device, const char *flag)
+sfdisk_flag (const char *device, const char *flag)
{
char *out, *err;
int r;
}
char *
-do_sfdisk_l (char *device)
+do_sfdisk_l (const char *device)
{
return sfdisk_flag (device, "-l");
}
char *
-do_sfdisk_kernel_geometry (char *device)
+do_sfdisk_kernel_geometry (const char *device)
{
return sfdisk_flag (device, "-g");
}
char *
-do_sfdisk_disk_geometry (char *device)
+do_sfdisk_disk_geometry (const char *device)
{
return sfdisk_flag (device, "-G");
}
#include "actions.h"
guestfs_int_stat *
-do_stat (char *path)
+do_stat (const char *path)
{
int r;
guestfs_int_stat *ret;
struct stat statbuf;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
CHROOT_IN;
r = stat (path, &statbuf);
CHROOT_OUT;
}
guestfs_int_stat *
-do_lstat (char *path)
+do_lstat (const char *path)
{
int r;
guestfs_int_stat *ret;
struct stat statbuf;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
CHROOT_IN;
r = lstat (path, &statbuf);
CHROOT_OUT;
}
guestfs_int_statvfs *
-do_statvfs (char *path)
+do_statvfs (const char *path)
{
int r;
guestfs_int_statvfs *ret;
struct statvfs statbuf;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
CHROOT_IN;
r = statvfs (path, &statbuf);
CHROOT_OUT;
#include "actions.h"
char **
-do_strings_e (char *encoding, char *path)
+do_strings_e (const char *encoding, const char *path)
{
char *buf;
int r;
char *out, *err;
char **lines;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
buf = sysroot_path (path);
if (!buf) {
reply_with_perror ("malloc");
}
char **
-do_strings (char *path)
+do_strings (const char *path)
{
return do_strings_e ("s", path);
}
#include "actions.h"
static int
-mkswap (char *device, const char *flag, const char *value)
+mkswap (const char *device, const char *flag, const char *value)
{
char *err;
int r;
}
int
-do_mkswap (char *device)
+do_mkswap (const char *device)
{
return mkswap (device, NULL, NULL);
}
int
-do_mkswap_L (char *label, char *device)
+do_mkswap_L (const char *label, const char *device)
{
return mkswap (device, "-L", label);
}
int
-do_mkswap_U (char *uuid, char *device)
+do_mkswap_U (const char *uuid, const char *device)
{
return mkswap (device, "-U", uuid);
}
int
-do_mkswap_file (char *path)
+do_mkswap_file (const char *path)
{
char *buf;
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
buf = sysroot_path (path);
if (!buf) {
reply_with_perror ("malloc");
}
int
-do_swapon_device (char *device)
+do_swapon_device (const char *device)
{
return swaponoff ("/sbin/swapon", NULL, device);
}
int
-do_swapoff_device (char *device)
+do_swapoff_device (const char *device)
{
return swaponoff ("/sbin/swapoff", NULL, device);
}
int
-do_swapon_file (char *path)
+do_swapon_file (const char *path)
{
char *buf;
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
buf = sysroot_path (path);
if (!buf) {
reply_with_perror ("malloc");
}
int
-do_swapoff_file (char *path)
+do_swapoff_file (const char *path)
{
char *buf;
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
buf = sysroot_path (path);
if (!buf) {
reply_with_perror ("malloc");
}
int
-do_swapon_label (char *label)
+do_swapon_label (const char *label)
{
return swaponoff ("/sbin/swapon", "-L", label);
}
int
-do_swapoff_label (char *label)
+do_swapoff_label (const char *label)
{
return swaponoff ("/sbin/swapoff", "-L", label);
}
int
-do_swapon_uuid (char *uuid)
+do_swapon_uuid (const char *uuid)
{
return swaponoff ("/sbin/swapon", "-U", uuid);
}
int
-do_swapoff_uuid (char *uuid)
+do_swapoff_uuid (const char *uuid)
{
return swaponoff ("/sbin/swapoff", "-U", uuid);
}
/* Has one FileIn parameter. */
int
-do_tar_in (char *dir)
+do_tar_in (const char *dir)
{
int err, r;
FILE *fp;
/* Has one FileOut parameter. */
int
-do_tar_out (char *dir)
+do_tar_out (const char *dir)
{
int r;
FILE *fp;
char *cmd;
char buf[GUESTFS_MAX_CHUNK_SIZE];
- NEED_ROOT (return -1);
- ABS_PATH (dir, return -1);
-
/* "tar -C /sysroot%s -cf - ." but we have to quote the dir. */
if (asprintf_nowarn (&cmd, "tar -C %R -cf - .", dir) == -1) {
reply_with_perror ("asprintf");
/* Has one FileIn parameter. */
int
-do_tgz_in (char *dir)
+do_tgz_in (const char *dir)
{
int err, r;
FILE *fp;
/* Has one FileOut parameter. */
int
-do_tgz_out (char *dir)
+do_tgz_out (const char *dir)
{
int r;
FILE *fp;
char *cmd;
char buf[GUESTFS_MAX_CHUNK_SIZE];
- NEED_ROOT (return -1);
- ABS_PATH (dir, return -1);
-
/* "tar -C /sysroot%s -zcf - ." but we have to quote the dir. */
if (asprintf_nowarn (&cmd, "tar -C %R -zcf - .", dir) == -1) {
reply_with_perror ("asprintf");
/* Has one FileIn parameter. */
int
-do_upload (char *filename)
+do_upload (const char *filename)
{
int err, fd, r, is_dev;
/* Has one FileOut parameter. */
int
-do_download (char *filename)
+do_download (const char *filename)
{
int fd, r, is_dev;
char buf[GUESTFS_MAX_CHUNK_SIZE];
#include "actions.h"
static int
-wc (char *flag, char *path)
+wc (char *flag, const char *path)
{
char *buf;
char *out, *err;
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
/* Make the path relative to /sysroot. */
buf = sysroot_path (path);
if (!buf) {
}
int
-do_wc_l (char *path)
+do_wc_l (const char *path)
{
return wc ("-l", path);
}
int
-do_wc_w (char *path)
+do_wc_w (const char *path)
{
return wc ("-w", path);
}
int
-do_wc_c (char *path)
+do_wc_c (const char *path)
{
return wc ("-c", path);
}
#endif
#endif
-static guestfs_int_xattr_list *getxattrs (char *path, ssize_t (*listxattr) (const char *path, char *list, size_t size), ssize_t (*getxattr) (const char *path, const char *name, void *value, size_t size));
-static int _setxattr (char *xattr, char *val, int vallen, char *path, int (*setxattr) (const char *path, const char *name, const void *value, size_t size, int flags));
-static int _removexattr (char *xattr, char *path, int (*removexattr) (const char *path, const char *name));
+static guestfs_int_xattr_list *getxattrs (const char *path, ssize_t (*listxattr) (const char *path, char *list, size_t size), ssize_t (*getxattr) (const char *path, const char *name, void *value, size_t size));
+static int _setxattr (const char *xattr, const char *val, int vallen, const char *path, int (*setxattr) (const char *path, const char *name, const void *value, size_t size, int flags));
+static int _removexattr (const char *xattr, const char *path, int (*removexattr) (const char *path, const char *name));
guestfs_int_xattr_list *
-do_getxattrs (char *path)
+do_getxattrs (const char *path)
{
#if defined(HAVE_LISTXATTR) && defined(HAVE_GETXATTR)
return getxattrs (path, listxattr, getxattr);
}
guestfs_int_xattr_list *
-do_lgetxattrs (char *path)
+do_lgetxattrs (const char *path)
{
#if defined(HAVE_LLISTXATTR) && defined(HAVE_LGETXATTR)
return getxattrs (path, llistxattr, lgetxattr);
}
int
-do_setxattr (char *xattr, char *val, int vallen, char *path)
+do_setxattr (const char *xattr, const char *val, int vallen, const char *path)
{
#if defined(HAVE_SETXATTR)
return _setxattr (xattr, val, vallen, path, setxattr);
}
int
-do_lsetxattr (char *xattr, char *val, int vallen, char *path)
+do_lsetxattr (const char *xattr, const char *val, int vallen, const char *path)
{
#if defined(HAVE_LSETXATTR)
return _setxattr (xattr, val, vallen, path, lsetxattr);
}
int
-do_removexattr (char *xattr, char *path)
+do_removexattr (const char *xattr, const char *path)
{
#if defined(HAVE_REMOVEXATTR)
return _removexattr (xattr, path, removexattr);
}
int
-do_lremovexattr (char *xattr, char *path)
+do_lremovexattr (const char *xattr, const char *path)
{
#if defined(HAVE_LREMOVEXATTR)
return _removexattr (xattr, path, lremovexattr);
}
static guestfs_int_xattr_list *
-getxattrs (char *path,
+getxattrs (const char *path,
ssize_t (*listxattr) (const char *path, char *list, size_t size),
ssize_t (*getxattr) (const char *path, const char *name,
void *value, size_t size))
int i, j;
guestfs_int_xattr_list *r = NULL;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
CHROOT_IN;
len = listxattr (path, NULL, 0);
CHROOT_OUT;
}
static int
-_setxattr (char *xattr, char *val, int vallen, char *path,
+_setxattr (const char *xattr, const char *val, int vallen, const char *path,
int (*setxattr) (const char *path, const char *name,
const void *value, size_t size, int flags))
{
}
static int
-_removexattr (char *xattr, char *path,
+_removexattr (const char *xattr, const char *path,
int (*removexattr) (const char *path, const char *name))
{
int r;
#else /* no xattr.h */
guestfs_int_xattr_list *
-do_getxattrs (char *path)
+do_getxattrs (const char *path)
{
reply_with_error ("getxattrs: no support for xattrs");
return NULL;
}
guestfs_int_xattr_list *
-do_lgetxattrs (char *path)
+do_lgetxattrs (const char *path)
{
reply_with_error ("lgetxattrs: no support for xattrs");
return NULL;
}
int
-do_setxattr (char *xattr, char *val, int vallen, char *path)
+do_setxattr (const char *xattr, const char *val, int vallen, const char *path)
{
reply_with_error ("setxattr: no support for xattrs");
return -1;
}
int
-do_lsetxattr (char *xattr, char *val, int vallen, char *path)
+do_lsetxattr (const char *xattr, const char *val, int vallen, const char *path)
{
reply_with_error ("lsetxattr: no support for xattrs");
return -1;
}
int
-do_removexattr (char *xattr, char *path)
+do_removexattr (const char *xattr, const char *path)
{
reply_with_error ("removexattr: no support for xattrs");
return -1;
}
int
-do_lremovexattr (char *xattr, char *path)
+do_lremovexattr (const char *xattr, const char *path)
{
reply_with_error ("lremovexattr: no support for xattrs");
return -1;
#include "actions.h"
int
-do_zero (char *device)
+do_zero (const char *device)
{
int fd, i;
char buf[4096];
#include "actions.h"
int
-do_zerofree (char *device)
+do_zerofree (const char *device)
{
char *err;
int r;
as end of line). For those you need to use the C<guestfs_read_file>
function which has a more complex interface.");
- ("aug_init", (RErr, [String "root"; Int "flags"]), 16, [],
+ ("aug_init", (RErr, [Pathname "root"; Int "flags"]), 16, [],
[], (* XXX Augeas code needs tests. *)
"create a new Augeas handle",
"\
See also: C<guestfs_scrub_device>.");
- ("grub_install", (RErr, [String "root"; Device "device"]), 86, [],
+ ("grub_install", (RErr, [Pathname "root"; Device "device"]), 86, [],
(* Test disabled because grub-install incompatible with virtio-blk driver.
* See also: https://bugzilla.redhat.com/show_bug.cgi?id=479760
*)
daemon responds to the ping message, without affecting the daemon
or attached block device(s) in any other way.");
- ("equal", (RBool "equality", [String "file1"; String "file2"]), 93, [],
+ ("equal", (RBool "equality", [Pathname "file1"; Pathname "file2"]), 93, [],
[InitBasicFS, Always, TestOutputTrue (
[["write_file"; "/file1"; "contents of a file"; "0"];
["cp"; "/file1"; "/file2"];
In any case, it is always safe to call C<guestfs_e2fsck_f> before
calling this function.");
- ("find", (RStringList "names", [String "directory"]), 107, [],
+ ("find", (RStringList "names", [Pathname "directory"]), 107, [],
[InitBasicFS, Always, TestOutputList (
[["find"; "/"]], ["lost+found"]);
InitBasicFS, Always, TestOutputList (
See also: C<guestfs_command_lines>");
- ("glob_expand", (RStringList "paths", [String "pattern"]), 113, [],
+ ("glob_expand", (RStringList "paths", [Pathname "pattern"]), 113, [],
+ (* Use Pathname here, and hence ABS_PATH (pattern,... in generated
+ * code in stubs.c, since all valid glob patterns must start with "/".
+ * There is no concept of "cwd" in libguestfs, hence no "."-relative names.
+ *)
[InitBasicFS, Always, TestOutputList (
[["mkdir_p"; "/a/b/c"];
["touch"; "/a/b/c/d"];
It is an interface to the L<scrub(1)> program. See that
manual page for more details.");
- ("mkdtemp", (RString "dir", [Pathname "template"]), 117, [],
+(* FIXME: make this a WritableString? *)
+ ("mkdtemp", (RString "dir", [String "template"]), 117, [],
[InitBasicFS, Always, TestRun (
[["mkdir"; "/tmp"];
["mkdtemp"; "/tmp/tmpXXXXXX"]])],
a list of devices. This one returns a hash table (map) of
device name to directory where the device is mounted.");
- ("mkmountpoint", (RErr, [Pathname "path"]), 148, [],
+ ("mkmountpoint", (RErr, [String "exemptpath"]), 148, [],
+ (* This is a special case: while you would expect a parameter
+ * of type "Pathname", that doesn't work, because it implies
+ * NEED_ROOT in the generated calling code in stubs.c, and
+ * this function cannot use NEED_ROOT.
+ *)
[],
"create a mountpoint",
"\
Return the canonicalized absolute pathname of C<path>. The
returned path has no C<.>, C<..> or symbolic link path elements.");
- ("ln", (RErr, [String "target"; String "linkname"]), 164, [],
+ ("ln", (RErr, [String "target"; Pathname "linkname"]), 164, [],
[InitBasicFS, Always, TestOutputStruct (
[["touch"; "/a"];
["ln"; "/a"; "/b"];
"\
This command creates a hard link using the C<ln> command.");
- ("ln_f", (RErr, [String "target"; String "linkname"]), 165, [],
+ ("ln_f", (RErr, [String "target"; Pathname "linkname"]), 165, [],
[InitBasicFS, Always, TestOutputStruct (
[["touch"; "/a"];
["touch"; "/b"];
This command creates a hard link using the C<ln -f> command.
The C<-f> option removes the link (C<linkname>) if it exists already.");
- ("ln_s", (RErr, [String "target"; String "linkname"]), 166, [],
+ ("ln_s", (RErr, [String "target"; Pathname "linkname"]), 166, [],
[InitBasicFS, Always, TestOutputStruct (
[["touch"; "/a"];
["ln_s"; "a"; "/b"];
"\
This command creates a symbolic link using the C<ln -s> command.");
- ("ln_sf", (RErr, [String "target"; String "linkname"]), 167, [],
+ ("ln_sf", (RErr, [String "target"; Pathname "linkname"]), 167, [],
[InitBasicFS, Always, TestOutput (
[["mkdir_p"; "/a/b"];
["touch"; "/a/b/c"];
pr " struct guestfs_%s_args args;\n" name;
List.iter (
function
- (* FIXME: eventually, make String "const", too *)
- | Pathname n | Device n -> pr " const char *%s;\n" n
+ | Device n -> pr " const char *%s;\n" n
+ | Pathname n
| String n
| OptString n -> pr " char *%s;\n" n
| StringList n -> pr " char **%s;\n" n
List.iter (
function
| Pathname n ->
- pr " NEED_ROOT (goto done);\n";
+ pr " %s = args.%s;\n" n n;
pr " ABS_PATH (%s, goto done);\n" n;
| Device n ->
pr " %s = args.%s;\n" n n;
pr "\n"
);
+ (* this is used at least for do_equal *)
+ if List.exists (function Pathname _ -> true | _ -> false) (snd style) then (
+ (* Emit NEED_ROOT just once, even when there are two or
+ more Pathname args *)
+ pr " NEED_ROOT (goto done);\n";
+ );
+
(* Don't want to call the impl with any FileIn or FileOut
* parameters, since these go "outside" the RPC protocol.
*)