From nobody Mon Feb 9 01:30:51 2026 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1568182892; cv=none; d=zoho.com; s=zohoarc; b=FxFIywJCdG3vpwAs5kCXtegf00wnRjSaHaxv9k8kfEM3nh/jhot4vyS/1SxH/Kh1UdIK3QcRmfSbmQJQrsNGNaDHH1QhobaiDwPJnbZbB4n3JST4KNYBCWo9Z0XVZ25C47GmYkVWn7O8mx2yKuD+Gr9okGT4W4cAE/KfxZ6GZ+c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568182892; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=tp1AHV9ZUJqCz2gy8jk5TH/RKbUC0uYPqBJvLSbbWMU=; b=cepcGQIl0TPR5StuwcKKpHr8F//XlhpyeexMx1709hdP/2CzhJSUp80OqcOkausSn6UdfsvtihaL69ykuWXljo/x4HFc961vTP83F4vU7elgX2fA8tU7XKC988fUpXyPXiJ30H+60vf4MM5UzlhI4lX7nptofw0YjbXEbD+8o4A= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1568182892685495.33117583077353; Tue, 10 Sep 2019 23:21:32 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i7vzN-0003ep-Az; Wed, 11 Sep 2019 06:20:25 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i7vzL-0003eK-QY for xen-devel@lists.xenproject.org; Wed, 11 Sep 2019 06:20:23 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 3217d646-d45c-11e9-b299-bc764e2007e4; Wed, 11 Sep 2019 06:20:05 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2176DB60A; Wed, 11 Sep 2019 06:20:05 +0000 (UTC) X-Inumbo-ID: 3217d646-d45c-11e9-b299-bc764e2007e4 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Wed, 11 Sep 2019 08:20:00 +0200 Message-Id: <20190911062001.25931-5-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190911062001.25931-1-jgross@suse.com> References: <20190911062001.25931-1-jgross@suse.com> Subject: [Xen-devel] [RFC PATCH 4/5] tools: add xenfs tool X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Ian Jackson , Wei Liu MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Add the xenfs tool for accessing the hypervisor filesystem. Signed-off-by: Juergen Gross --- 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) +=3D xen-lowmemd INSTALL_SBIN-$(CONFIG_X86) +=3D xen-mfndump INSTALL_SBIN-$(CONFIG_X86) +=3D xen-ucode INSTALL_SBIN +=3D xencov +INSTALL_SBIN +=3D xenfs INSTALL_SBIN +=3D xenlockprof INSTALL_SBIN +=3D xenperf INSTALL_SBIN +=3D xenpm @@ -86,6 +87,9 @@ xenperf: xenperf.o xenpm: xenpm.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) =20 +xenfs: xenfs.o + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenfs) $(APPEND_LDFLAGS) + xenlockprof: xenlockprof.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) =20 @@ -94,6 +98,8 @@ xen-hptool.o: CFLAGS +=3D -I$(XEN_ROOT)/tools/libxc $(CFL= AGS_libxencall) xen-hptool: xen-hptool.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(L= DLIBS_libxenguest) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS) =20 +xenfs.o: CFLAGS +=3D $(CFLAGS_libxenfs) + # xen-mfndump incorrectly uses libxc internals xen-mfndump.o: CFLAGS +=3D -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 +#include +#include +#include + +static struct xenfs_handle *hdl; + +static int xenfs_cat(char *path) +{ + int ret =3D 0; + char *result; + + result =3D xenfs_read(hdl, path); + if (!result) { + perror("could not read"); + ret =3D 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 =3D 0; + + ent =3D xenfs_readdir(hdl, path, &n); + if (!ent) { + perror("could not read dir"); + ret =3D 3; + } else { + for (i =3D 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 =3D 0; + char *p; + + ent =3D xenfs_readdir(hdl, path, &n); + if (!ent) + return 1; + + for (i =3D 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 =3D=3D 1) ? "" : "/", ent[= i].name); + if (xenfs_tree_sub(p, depth + 1)) + ret =3D 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 =3D xenfs_open(NULL, 0); + + if (!hdl) { + fprintf(stderr, "Could not open libxenfs\n"); + ret =3D 2; + } else if (argc =3D=3D 3 && !strcmp(argv[1], "--cat")) + ret =3D xenfs_cat(argv[2]); + else if (argc =3D=3D 3 && !strcmp(argv[1], "--ls")) + ret =3D xenfs_ls(argv[2]); + else if (argc =3D=3D 2 && !strcmp(argv[1], "--tree")) + ret =3D xenfs_tree(); + else { + fprintf(stderr, "usage: xenfs --ls \n"); + fprintf(stderr, " xenfs --cat \n"); + fprintf(stderr, " xenfs --tree\n"); + ret =3D 1; + } + + xenfs_close(hdl); + + return ret; +} --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel