summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2018-07-12 14:46:46 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2018-07-12 14:46:46 +0000
commit91e840875c75a463ccaf4e4f347fe57cc749ff83 (patch)
tree206e209d3b957ff1e5f732ca9826e2beb4dc45d2
parent42d909379ea992d56daee2621f940ba24bf4a370 (diff)
Add a function to delete all nodes with a specific name.
Add a function to determine the size of a machine description.
-rw-r--r--usr.sbin/ldomctl/mdesc.c28
-rw-r--r--usr.sbin/ldomctl/mdesc.h4
2 files changed, 30 insertions, 2 deletions
diff --git a/usr.sbin/ldomctl/mdesc.c b/usr.sbin/ldomctl/mdesc.c
index babdd821641..cb6a0445b4f 100644
--- a/usr.sbin/ldomctl/mdesc.c
+++ b/usr.sbin/ldomctl/mdesc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdesc.c,v 1.9 2015/05/23 14:26:06 jsg Exp $ */
+/* $OpenBSD: mdesc.c,v 1.10 2018/07/12 14:46:45 kettenis Exp $ */
/*
* Copyright (c) 2012 Mark Kettenis
@@ -315,6 +315,15 @@ md_find_delete_node(struct md *md, const char *name)
md_delete_node(md, node);
}
+void
+md_find_delete_nodes(struct md *md, const char *name)
+{
+ struct md_node *node;
+
+ while ((node = md_find_node(md, name)))
+ md_delete_node(md, node);
+}
+
struct md *
md_alloc(void)
{
@@ -649,3 +658,20 @@ md_write(struct md *md, const char *path)
fclose(fp);
}
+
+uint32_t
+md_size(const char *path)
+{
+ uint32_t size;
+ FILE *fp;
+
+ fp = fopen(path, "r");
+ if (fp == NULL)
+ err(1, "fopen");
+
+ fseek(fp, 0, SEEK_END);
+ size = ftell(fp);
+ fclose(fp);
+
+ return size;
+}
diff --git a/usr.sbin/ldomctl/mdesc.h b/usr.sbin/ldomctl/mdesc.h
index 4e509b764c2..ec78d951c66 100644
--- a/usr.sbin/ldomctl/mdesc.h
+++ b/usr.sbin/ldomctl/mdesc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdesc.h,v 1.5 2012/11/26 20:08:16 kettenis Exp $ */
+/* $OpenBSD: mdesc.h,v 1.6 2018/07/12 14:46:45 kettenis Exp $ */
/*
* Copyright (c) 2012 Mark Kettenis
@@ -125,6 +125,7 @@ bool md_get_prop_data(struct md *, struct md_node *, const char *,
void md_delete_node(struct md *, struct md_node *);
void md_find_delete_node(struct md *, const char *);
+void md_find_delete_nodes(struct md *, const char *);
void md_collect_garbage(struct md *);
@@ -135,3 +136,4 @@ struct md *md_copy(struct md *);
struct md *md_read(const char *);
void md_write(struct md *, const char *);
+uint32_t md_size(const char *);