[PATCH] When dumping from file system show results in sane order

Grant Likely grant.likely at secretlab.ca
Mon Oct 11 16:54:48 EST 2010


On Tue, Oct 05, 2010 at 02:07:21PM -0500, Matthew McClintock wrote:
> Currently, when we run the following
> 
> $> dtc -I fs -O dts /proc/device-tree
> 
> We get the output in a "reverse order", this patch will reverse that
> output order and should resemble your initial device more closely
> 
> Code copied over from kexec-tools
> 
> Signed-off-by: Matthew McClintock <msm at freescale.com>

Hi Matthew.  David just posted a patch implementing a generic search
option when outputting a tree in dts format which would be applicable
to more use cases than just sucking up the fstree.  Would that do the
job for you?

g.

> ---
>  fstree.c |   29 ++++++++++++++++++++++-------
>  1 files changed, 22 insertions(+), 7 deletions(-)
> 
> diff --git a/fstree.c b/fstree.c
> index f377453..fd2658d 100644
> --- a/fstree.c
> +++ b/fstree.c
> @@ -23,21 +23,35 @@
>  #include <dirent.h>
>  #include <sys/stat.h>
>  
> +static int comparefunc(const void *dentry1, const void *dentry2)
> +{
> +	const char *str1 = (*(struct dirent * const *)dentry1)->d_name;
> +	const char *str2 = (*(struct dirent * const *)dentry2)->d_name;
> +
> +	if (strchr(str1, '@') && strchr(str2, '@') &&
> +		(strlen(str1) > strlen(str2)))
> +		return 1;
> +
> +	return strcmp(str1, str2);
> +}
> +
>  static struct node *read_fstree(const char *dirname)
>  {
> -	DIR *d;
> -	struct dirent *de;
>  	struct stat st;
>  	struct node *tree;
> +	struct dirent **namelist;
> +	int numlist, i;
>  
> -	d = opendir(dirname);
> -	if (!d)
> -		die("Couldn't opendir() \"%s\": %s\n", dirname, strerror(errno));
> +	numlist = scandir(dirname, &namelist, 0, comparefunc);
> +	if (numlist <= 0)
> +		die("unrecoverable error: could not scan \"%s\": %s\n",
> +                    dirname, strerror(errno));
>  
>  	tree = build_node(NULL, NULL);
>  
> -	while ((de = readdir(d)) != NULL) {
> +	for (i = 0; i < numlist; i++) {
>  		char *tmpnam;
> +		struct dirent *de = namelist[i];
>  
>  		if (streq(de->d_name, ".")
>  		    || streq(de->d_name, ".."))
> @@ -72,10 +86,11 @@ static struct node *read_fstree(const char *dirname)
>  			add_child(tree, newchild);
>  		}
>  
> +		free(de);
>  		free(tmpnam);
>  	}
> +	free(namelist);
>  
> -	closedir(d);
>  	return tree;
>  }
>  
> -- 
> 1.6.0.6
> 
> 
> _______________________________________________
> devicetree-discuss mailing list
> devicetree-discuss at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/devicetree-discuss


More information about the devicetree-discuss mailing list