Devicetree
 help / color / mirror / Atom feed
From: Matthew McClintock <msm-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
To: jdl-CYoMK+44s/E@public.gmane.org
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
Subject: [PATCH] When dumping from file system show results in sane order
Date: Tue, 5 Oct 2010 14:07:21 -0500	[thread overview]
Message-ID: <1286305641-23388-1-git-send-email-msm@freescale.com> (raw)

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-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 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

             reply	other threads:[~2010-10-05 19:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-05 19:07 Matthew McClintock [this message]
     [not found] ` <1286305641-23388-1-git-send-email-msm-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2010-10-11  5:54   ` [PATCH] When dumping from file system show results in sane order Grant Likely
     [not found]     ` <20101011055448.GL23588-MrY2KI0G/OVr83L8+7iqerDks+cytr/Z@public.gmane.org>
2010-10-11 15:12       ` Matthew McClintock
2010-10-11 23:55   ` David Gibson
2010-10-12  0:41     ` Matthew McClintock

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1286305641-23388-1-git-send-email-msm@freescale.com \
    --to=msm-kzfg59tc24xl57midrcfdg@public.gmane.org \
    --cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
    --cc=jdl-CYoMK+44s/E@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox