1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
11 static struct node *read_fstree(const char *dirname)
20 die("Couldn't opendir() \"%s\": %s\n", dirname, strerror(errno));
22 tree = build_node(NULL, NULL, NULL);
24 while ((de = readdir(d)) != NULL) {
27 if (streq(de->d_name, ".")
28 || streq(de->d_name, ".."))
31 tmpname = join_path(dirname, de->d_name);
33 if (stat(tmpname, &st) < 0)
34 die("stat(%s): %s\n", tmpname, strerror(errno));
36 if (S_ISREG(st.st_mode)) {
37 struct property *prop;
40 pfile = fopen(tmpname, "rb");
43 "WARNING: Cannot open %s: %s\n",
44 tmpname, strerror(errno));
46 prop = build_property(xstrdup(de->d_name),
50 add_property(tree, prop);
53 } else if (S_ISDIR(st.st_mode)) {
54 struct node *newchild;
56 newchild = read_fstree(tmpname);
57 newchild = name_node(newchild, xstrdup(de->d_name));
58 add_child(tree, newchild);
68 struct dt_info *dt_from_fs(const char *dirname)
72 tree = read_fstree(dirname);
73 tree = name_node(tree, "");
75 return build_dt_info(DTSF_V1, NULL, tree, guess_boot_cpuid(tree));