@ -704,59 +704,37 @@ static struct reserve_info *flat_read_mem_reserve(struct inbuf *inb)
static char *nodename_from_path(const char *ppath, const char *cpath)
static char *nodename_from_path(const char *ppath, const char *cpath)
{
{
const char *lslash;
int plen;
int plen;
lslash = strrchr(cpath, '/');
plen = strlen(ppath);
if (! lslash)
return NULL;
plen = lslash - cpath;
if (!strneq(ppath, cpath, plen))
die("Path \"%s\" is not valid as a child of \"%s\"\n",
cpath, ppath);
if (streq(cpath, "/") && streq(ppath, ""))
/* root node is a special case */
return "";
if (!streq(ppath, "/"))
plen++;
if ((plen == 0) && streq(ppath, "/"))
return strdup(cpath + plen);
return strdup(lslash+1);
if (! strneq(ppath, cpath, plen))
return NULL;
return strdup(lslash+1);
}
static int find_basenamelen(const char *name)
{
const char *atpos = strchr(name, '@');
if (atpos)
return atpos - name;
else
return strlen(name);
}
}
static struct node *unflatten_tree(struct inbuf *dtbuf,
static struct node *unflatten_tree(struct inbuf *dtbuf,
struct inbuf *strbuf,
struct inbuf *strbuf,
const char *parent_path, int flags)
const char *parent_flatname, int flags)
{
{
struct node *node;
struct node *node;
char *flatname;
u32 val;
u32 val;
node = build_node(NULL, NULL);
node = build_node(NULL, NULL);
if (flags & FTF_FULLPATH) {
flatname = flat_read_string(dtbuf);
node->fullpath = flat_read_string(dtbuf);
node->name = nodename_from_path(parent_path, node->fullpath);
if (! node->name)
if (flags & FTF_FULLPATH)
die("Path \"%s\" is not valid as a child of \"%s\"\n",
node->name = nodename_from_path(parent_flatname, flatname);
node->fullpath, parent_path);
else
} else {
node->name = flatname;
node->name = flat_read_string(dtbuf);
node->fullpath = join_path(parent_path, node->name);
}
node->basenamelen = find_basenamelen(node->name);
do {
do {
struct property *prop;
struct property *prop;
@ -773,8 +751,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
break;
break;
case FDT_BEGIN_NODE:
case FDT_BEGIN_NODE:
child = unflatten_tree(dtbuf,strbuf, node->fullpath,
child = unflatten_tree(dtbuf,strbuf, flatname, flags);
flags);
add_child(node, child);
add_child(node, child);
break;
break;