tools: add xenfs tool

Add the xenfs tool for accessing the hypervisor filesystem.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Wei Liu <wl@xen.org>
This commit is contained in:
Juergen Gross authored and Jan Beulich committed 2020-05-29 10:25:02 +02:00
1 parent 86234eafb9
commit ef716e1dc6
4 files changed
+259

No files matched your search

+1
View File
@@ -368,6 +368,7 @@ tools/libxl/test_timedereg
tools/libxl/test_fdderegrace
tools/firmware/etherboot/eb-roms.h
tools/firmware/etherboot/gpxe-git-snapshot.tar.gz
tools/misc/xenhypfs
tools/misc/xenwatchdogd
tools/misc/xen-hvmcrash
tools/misc/xen-lowmemd
+60
View File
@@ -0,0 +1,60 @@
=head1 NAME
xenhypfs - Xen tool to access Xen hypervisor file system
=head1 SYNOPSIS
B<xenhypfs> I<subcommand> [I<options>] [I<args>]
=head1 DESCRIPTION
The B<xenhypfs> program is used to access the Xen hypervisor file system.
It can be used to show the available entries, to show their contents and
(if allowed) to modify their contents.
=head1 SUBCOMMANDS
=over 4
=item B<ls> I<path>
List the available entries below I<path>.
=item B<cat> [I<-b>] I<path>
Show the contents of the entry specified by I<path>. Non-printable characters
other than white space characters (like tab, new line) will be shown as
B<\xnn> (B<nn> being a two digit hex number) unless the option B<-b> is
specified.
=item B<write> I<path> I<value>
Set the contents of the entry specified by I<path> to I<value>.
=item B<tree>
Show all the entries of the file system as a tree.
=back
=head1 RETURN CODES
=over 4
=item B<0>
Success
=item B<1>
Invalid usage (e.g. unknown subcommand, unknown option, missing parameter).
=item B<2>
Entry not found while traversing the tree.
=item B<3>
Access right violation.
=back
+6
View File
@@ -24,6 +24,7 @@ INSTALL_SBIN-$(CONFIG_X86) += xen-lowmemd
INSTALL_SBIN-$(CONFIG_X86) += xen-mfndump
INSTALL_SBIN-$(CONFIG_X86) += xen-ucode
INSTALL_SBIN += xencov
INSTALL_SBIN += xenhypfs
INSTALL_SBIN += xenlockprof
INSTALL_SBIN += xenperf
INSTALL_SBIN += xenpm
@@ -86,6 +87,9 @@ xenperf: xenperf.o
xenpm: xenpm.o
$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
xenhypfs: xenhypfs.o
$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenhypfs) $(APPEND_LDFLAGS)
xenlockprof: xenlockprof.o
$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
@@ -94,6 +98,8 @@ xen-hptool.o: CFLAGS += -I$(XEN_ROOT)/tools/libxc $(CFLAGS_libxencall)
xen-hptool: xen-hptool.o
$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS)
xenhypfs.o: CFLAGS += $(CFLAGS_libxenhypfs)
# xen-mfndump incorrectly uses libxc internals
xen-mfndump.o: CFLAGS += -I$(XEN_ROOT)/tools/libxc $(CFLAGS_libxencall)
xen-mfndump: xen-mfndump.o
+192
View File
@@ -0,0 +1,192 @@
#define _GNU_SOURCE
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <xenhypfs.h>
static struct xenhypfs_handle *hdl;
static int usage(void)
{
fprintf(stderr, "usage: xenhypfs ls <path>\n");
fprintf(stderr, " xenhypfs cat [-b] <path>\n");
fprintf(stderr, " xenhypfs write <path> <val>\n");
fprintf(stderr, " xenhypfs tree\n");
return 1;
}
static void xenhypfs_print_escaped(char *string)
{
char *c;
for (c = string; *c; c++) {
if (isgraph(*c) || isspace(*c))
printf("%c", *c);
else
printf("\\x%02x", *c);
}
printf("\n");
}
static int xenhypfs_cat(int argc, char *argv[])
{
int ret = 0;
char *result;
char *path;
bool bin = false;
switch (argc) {
case 1:
path = argv[0];
break;
case 2:
if (strcmp(argv[0], "-b"))
return usage();
bin = true;
path = argv[1];
break;
default:
return usage();
}
result = xenhypfs_read(hdl, path);
if (!result) {
perror("could not read");
ret = 3;
} else {
if (!bin)
printf("%s\n", result);
else
xenhypfs_print_escaped(result);
free(result);
}
return ret;
}
static int xenhypfs_wr(char *path, char *val)
{
int ret;
ret = xenhypfs_write(hdl, path, val);
if (ret) {
perror("could not write");
ret = 3;
}
return ret;
}
static char *xenhypfs_type(struct xenhypfs_dirent *ent)
{
char *res;
switch (ent->type) {
case xenhypfs_type_dir:
res = "<dir> ";
break;
case xenhypfs_type_blob:
res = "<blob> ";
break;
case xenhypfs_type_string:
res = "<string>";
break;
case xenhypfs_type_uint:
res = "<uint> ";
break;
case xenhypfs_type_int:
res = "<int> ";
break;
case xenhypfs_type_bool:
res = "<bool> ";
break;
default:
res = "<\?\?\?> ";
break;
}
return res;
}
static int xenhypfs_ls(char *path)
{
struct xenhypfs_dirent *ent;
unsigned int n, i;
int ret = 0;
ent = xenhypfs_readdir(hdl, path, &n);
if (!ent) {
perror("could not read dir");
ret = 3;
} else {
for (i = 0; i < n; i++)
printf("%s r%c %s\n", xenhypfs_type(ent + i),
ent[i].is_writable ? 'w' : '-', ent[i].name);
free(ent);
}
return ret;
}
static int xenhypfs_tree_sub(char *path, unsigned int depth)
{
struct xenhypfs_dirent *ent;
unsigned int n, i;
int ret = 0;
char *p;
ent = xenhypfs_readdir(hdl, path, &n);
if (!ent)
return 2;
for (i = 0; i < n; i++) {
printf("%*s%s%s\n", depth * 2, "", ent[i].name,
ent[i].type == xenhypfs_type_dir ? "/" : "");
if (ent[i].type == xenhypfs_type_dir) {
asprintf(&p, "%s%s%s", path, (depth == 1) ? "" : "/", ent[i].name);
if (xenhypfs_tree_sub(p, depth + 1))
ret = 2;
}
}
free(ent);
return ret;
}
static int xenhypfs_tree(void)
{
printf("/\n");
return xenhypfs_tree_sub("/", 1);
}
int main(int argc, char *argv[])
{
int ret;
hdl = xenhypfs_open(NULL, 0);
if (!hdl) {
fprintf(stderr, "Could not open libxenhypfs\n");
ret = 2;
} else if (argc >= 3 && !strcmp(argv[1], "cat"))
ret = xenhypfs_cat(argc - 2, argv + 2);
else if (argc == 3 && !strcmp(argv[1], "ls"))
ret = xenhypfs_ls(argv[2]);
else if (argc == 4 && !strcmp(argv[1], "write"))
ret = xenhypfs_wr(argv[2], argv[3]);
else if (argc == 2 && !strcmp(argv[1], "tree"))
ret = xenhypfs_tree();
else
ret = usage();
xenhypfs_close(hdl);
return ret;
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.