From: kettenis Date: Thu, 12 Jul 2018 14:46:45 +0000 (+0000) Subject: Add a function to delete all nodes with a specific name. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=c994384a4c10850fcc00250074bad256909dc009;p=openbsd Add a function to delete all nodes with a specific name. Add a function to determine the size of a machine description. --- 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 *);