summaryrefslogtreecommitdiffstats
path: root/test/sysfs/tree-dump.c
blob: bcf871b36f93d1ceecec636e4e23466c2918e6de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// SPDX-License-Identifier: LGPL-2.1-or-later
/**
 * This file is part of libnvme.
 * Copyright (c) 2024 Daniel Wagner, SUSE LLC
 */

#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <errno.h>

#include <libnvme.h>

static bool tree_dump(void)
{
	bool pass = false;
	nvme_root_t r;
	int err;

	r = nvme_create_root(stdout, LOG_ERR);
	if (!r)
		return false;

	err = nvme_scan_topology(r, NULL, NULL);
	if (err) {
		if (errno != ENOENT)
			goto out;
	}

	if (nvme_dump_tree(r))
		goto out;
	printf("\n");

	pass = true;

out:
	nvme_free_tree(r);
	return pass;
}

int main(int argc, char *argv[])
{
	bool pass = true;

	pass = tree_dump();
	fflush(stdout);

	exit(pass ? EXIT_SUCCESS : EXIT_FAILURE);
}