2019-06-20 23:19:38 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-06-08 09:18:34 +02:00
|
|
|
/*
|
|
|
|
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "dtc.h"
|
|
|
|
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2007-12-04 04:26:15 +01:00
|
|
|
static struct node *read_fstree(const char *dirname)
|
2005-06-08 09:18:34 +02:00
|
|
|
{
|
|
|
|
DIR *d;
|
|
|
|
struct dirent *de;
|
|
|
|
struct stat st;
|
|
|
|
struct node *tree;
|
|
|
|
|
|
|
|
d = opendir(dirname);
|
2008-03-06 02:16:55 +01:00
|
|
|
if (!d)
|
|
|
|
die("Couldn't opendir() \"%s\": %s\n", dirname, strerror(errno));
|
2005-06-08 09:18:34 +02:00
|
|
|
|
annotations: add positions
Extend the parser to record positions, in build_node,
build_node_delete, and build_property.
srcpos structures are added to the property and node types, and to the
parameter lists of the above functions that construct these types.
Nodes and properties that are created by the compiler rather than from
parsing source code have NULL as the srcpos value.
merge_nodes, defined in livetree.c, uses srcpos_extend to combine
multiple positions, resulting in a list of positions. srcpos_extend
is defined in srcpos.c. New elements are added at the end. This
requires the srcpos type, define in srcpos.h, to be a list structure
with a next field. This next field is initialized to NULL in
srcpos.h, in the macro YYLLOC_DEFAULT invoked implicitly by the
generated parser code.
Another change to srcpos.c is to make srcpos_copy always do a full
copy, including a copy of the file substructure. This is required
because when dtc is used on the output of cpp, the successive detected
file names overwrite the file name in the file structure. The next
field does not need to be deep copied, because it is always NULL when
srcpos_copy is called; an assert checks for this. File names are only
updated in uncopied position structures.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-16 17:29:59 +01:00
|
|
|
tree = build_node(NULL, NULL, NULL);
|
2005-06-08 09:18:34 +02:00
|
|
|
|
|
|
|
while ((de = readdir(d)) != NULL) {
|
2014-02-01 06:41:59 +01:00
|
|
|
char *tmpname;
|
2005-06-08 09:18:34 +02:00
|
|
|
|
|
|
|
if (streq(de->d_name, ".")
|
|
|
|
|| streq(de->d_name, ".."))
|
|
|
|
continue;
|
|
|
|
|
2014-02-01 06:41:59 +01:00
|
|
|
tmpname = join_path(dirname, de->d_name);
|
2007-09-18 03:44:04 +02:00
|
|
|
|
2019-10-09 12:20:21 +02:00
|
|
|
if (stat(tmpname, &st) < 0)
|
2014-02-01 06:41:59 +01:00
|
|
|
die("stat(%s): %s\n", tmpname, strerror(errno));
|
2005-06-08 09:18:34 +02:00
|
|
|
|
|
|
|
if (S_ISREG(st.st_mode)) {
|
|
|
|
struct property *prop;
|
|
|
|
FILE *pfile;
|
|
|
|
|
2014-06-19 13:12:27 +02:00
|
|
|
pfile = fopen(tmpname, "rb");
|
2005-06-08 09:18:34 +02:00
|
|
|
if (! pfile) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"WARNING: Cannot open %s: %s\n",
|
2014-02-01 06:41:59 +01:00
|
|
|
tmpname, strerror(errno));
|
2005-06-08 09:18:34 +02:00
|
|
|
} else {
|
2008-10-03 18:12:33 +02:00
|
|
|
prop = build_property(xstrdup(de->d_name),
|
2005-06-08 09:18:34 +02:00
|
|
|
data_copy_file(pfile,
|
annotations: add positions
Extend the parser to record positions, in build_node,
build_node_delete, and build_property.
srcpos structures are added to the property and node types, and to the
parameter lists of the above functions that construct these types.
Nodes and properties that are created by the compiler rather than from
parsing source code have NULL as the srcpos value.
merge_nodes, defined in livetree.c, uses srcpos_extend to combine
multiple positions, resulting in a list of positions. srcpos_extend
is defined in srcpos.c. New elements are added at the end. This
requires the srcpos type, define in srcpos.h, to be a list structure
with a next field. This next field is initialized to NULL in
srcpos.h, in the macro YYLLOC_DEFAULT invoked implicitly by the
generated parser code.
Another change to srcpos.c is to make srcpos_copy always do a full
copy, including a copy of the file substructure. This is required
because when dtc is used on the output of cpp, the successive detected
file names overwrite the file name in the file structure. The next
field does not need to be deep copied, because it is always NULL when
srcpos_copy is called; an assert checks for this. File names are only
updated in uncopied position structures.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-16 17:29:59 +01:00
|
|
|
st.st_size),
|
|
|
|
NULL);
|
2005-06-08 09:18:34 +02:00
|
|
|
add_property(tree, prop);
|
|
|
|
fclose(pfile);
|
|
|
|
}
|
|
|
|
} else if (S_ISDIR(st.st_mode)) {
|
|
|
|
struct node *newchild;
|
|
|
|
|
2014-02-01 06:41:59 +01:00
|
|
|
newchild = read_fstree(tmpname);
|
2010-02-24 08:22:17 +01:00
|
|
|
newchild = name_node(newchild, xstrdup(de->d_name));
|
2005-06-08 09:18:34 +02:00
|
|
|
add_child(tree, newchild);
|
|
|
|
}
|
|
|
|
|
2014-02-01 06:41:59 +01:00
|
|
|
free(tmpname);
|
2005-06-08 09:18:34 +02:00
|
|
|
}
|
|
|
|
|
2010-07-14 08:10:56 +02:00
|
|
|
closedir(d);
|
2005-06-08 09:18:34 +02:00
|
|
|
return tree;
|
|
|
|
}
|
|
|
|
|
2016-05-31 03:58:42 +02:00
|
|
|
struct dt_info *dt_from_fs(const char *dirname)
|
2005-06-08 09:18:34 +02:00
|
|
|
{
|
|
|
|
struct node *tree;
|
|
|
|
|
|
|
|
tree = read_fstree(dirname);
|
2010-02-24 08:22:17 +01:00
|
|
|
tree = name_node(tree, "");
|
2005-06-08 09:18:34 +02:00
|
|
|
|
2016-05-31 03:58:42 +02:00
|
|
|
return build_dt_info(DTSF_V1, NULL, tree, guess_boot_cpuid(tree));
|
2005-06-08 09:18:34 +02:00
|
|
|
}
|