USb: Break support for WinChipHead CH341 340 USB->Serial "chip"
[linux-2.6/next.git] / scripts / dtc / fstree.c
blob766b2694d93589fe39ea6313dbae7b1ce5a21daa
1 /*
2 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
21 #include "dtc.h"
23 #include <dirent.h>
24 #include <sys/stat.h>
26 static struct node *read_fstree(const char *dirname)
28 DIR *d;
29 struct dirent *de;
30 struct stat st;
31 struct node *tree;
33 d = opendir(dirname);
34 if (!d)
35 die("Couldn't opendir() \"%s\": %s\n", dirname, strerror(errno));
37 tree = build_node(NULL, NULL);
39 while ((de = readdir(d)) != NULL) {
40 char *tmpnam;
42 if (streq(de->d_name, ".")
43 || streq(de->d_name, ".."))
44 continue;
46 tmpnam = join_path(dirname, de->d_name);
48 if (lstat(tmpnam, &st) < 0)
49 die("stat(%s): %s\n", tmpnam, strerror(errno));
51 if (S_ISREG(st.st_mode)) {
52 struct property *prop;
53 FILE *pfile;
55 pfile = fopen(tmpnam, "r");
56 if (! pfile) {
57 fprintf(stderr,
58 "WARNING: Cannot open %s: %s\n",
59 tmpnam, strerror(errno));
60 } else {
61 prop = build_property(strdup(de->d_name),
62 data_copy_file(pfile,
63 st.st_size),
64 NULL);
65 add_property(tree, prop);
66 fclose(pfile);
68 } else if (S_ISDIR(st.st_mode)) {
69 struct node *newchild;
71 newchild = read_fstree(tmpnam);
72 newchild = name_node(newchild, strdup(de->d_name),
73 NULL);
74 add_child(tree, newchild);
77 free(tmpnam);
80 return tree;
83 struct boot_info *dt_from_fs(const char *dirname)
85 struct node *tree;
87 tree = read_fstree(dirname);
88 tree = name_node(tree, "", NULL);
90 return build_boot_info(NULL, tree, 0);