[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [RFC PATCH 4/5] tools: add xenfs tool
Add the xenfs tool for accessing the hypervisor filesystem. Signed-off-by: Juergen Gross <jgross@xxxxxxxx> --- tools/misc/Makefile | 6 ++++ tools/misc/xenfs.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 tools/misc/xenfs.c diff --git a/tools/misc/Makefile b/tools/misc/Makefile index 63947bfadc..9f3abd5bcf 100644 --- a/tools/misc/Makefile +++ b/tools/misc/Makefile @@ -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 += xenfs 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) +xenfs: xenfs.o + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenfs) $(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) +xenfs.o: CFLAGS += $(CFLAGS_libxenfs) + # xen-mfndump incorrectly uses libxc internals xen-mfndump.o: CFLAGS += -I$(XEN_ROOT)/tools/libxc $(CFLAGS_libxencall) xen-mfndump: xen-mfndump.o diff --git a/tools/misc/xenfs.c b/tools/misc/xenfs.c new file mode 100644 index 0000000000..ecaa4ccb0a --- /dev/null +++ b/tools/misc/xenfs.c @@ -0,0 +1,102 @@ +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <xenfs.h> + +static struct xenfs_handle *hdl; + +static int xenfs_cat(char *path) +{ + int ret = 0; + char *result; + + result = xenfs_read(hdl, path); + if (!result) { + perror("could not read"); + ret = 3; + } else { + printf("%s\n", result); + free(result); + } + return ret; +} + +static int xenfs_ls(char *path) +{ + struct xenfs_dirent *ent; + unsigned int n, i; + int ret = 0; + + ent = xenfs_readdir(hdl, path, &n); + if (!ent) { + perror("could not read dir"); + ret = 3; + } else { + for (i = 0; i < n; i++) + printf("%c %s\n", ent[i].is_dir ? 'd' : '-', ent[i].name); + + free(ent); + } + return ret; +} + +static int xenfs_tree_sub(char *path, unsigned int depth) +{ + struct xenfs_dirent *ent; + unsigned int n, i; + int ret = 0; + char *p; + + ent = xenfs_readdir(hdl, path, &n); + if (!ent) + return 1; + + for (i = 0; i < n; i++) { + printf("%*s%s%s\n", depth * 2, "", ent[i].name, + ent[i].is_dir ? "/" : ""); + if (ent[i].is_dir) { + asprintf(&p, "%s%s%s", path, (depth == 1) ? "" : "/", ent[i].name); + if (xenfs_tree_sub(p, depth + 1)) + ret = 1; + } + } + + free(ent); + + return ret; +} + +static int xenfs_tree(void) +{ + printf("/\n"); + + return xenfs_tree_sub("/", 1); +} + +int main(int argc, char *argv[]) +{ + int ret; + + hdl = xenfs_open(NULL, 0); + + if (!hdl) { + fprintf(stderr, "Could not open libxenfs\n"); + ret = 2; + } else if (argc == 3 && !strcmp(argv[1], "--cat")) + ret = xenfs_cat(argv[2]); + else if (argc == 3 && !strcmp(argv[1], "--ls")) + ret = xenfs_ls(argv[2]); + else if (argc == 2 && !strcmp(argv[1], "--tree")) + ret = xenfs_tree(); + else { + fprintf(stderr, "usage: xenfs --ls <path>\n"); + fprintf(stderr, " xenfs --cat <path>\n"); + fprintf(stderr, " xenfs --tree\n"); + ret = 1; + } + + xenfs_close(hdl); + + return ret; +} -- 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |