* [PATCH] When dumping from file system show results in sane order
@ 2010-10-05 19:07 Matthew McClintock
[not found] ` <1286305641-23388-1-git-send-email-msm-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Matthew McClintock @ 2010-10-05 19:07 UTC (permalink / raw)
To: jdl-CYoMK+44s/E; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ
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
^ permalink raw reply related [flat|nested] 5+ messages in thread[parent not found: <1286305641-23388-1-git-send-email-msm-KZfg59tc24xl57MIdRCFDg@public.gmane.org>]
* Re: [PATCH] When dumping from file system show results in sane order [not found] ` <1286305641-23388-1-git-send-email-msm-KZfg59tc24xl57MIdRCFDg@public.gmane.org> @ 2010-10-11 5:54 ` Grant Likely [not found] ` <20101011055448.GL23588-MrY2KI0G/OVr83L8+7iqerDks+cytr/Z@public.gmane.org> 2010-10-11 23:55 ` David Gibson 1 sibling, 1 reply; 5+ messages in thread From: Grant Likely @ 2010-10-11 5:54 UTC (permalink / raw) To: Matthew McClintock; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ 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-KZfg59tc24xl57MIdRCFDg@public.gmane.org> 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-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org > https://lists.ozlabs.org/listinfo/devicetree-discuss ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <20101011055448.GL23588-MrY2KI0G/OVr83L8+7iqerDks+cytr/Z@public.gmane.org>]
* Re: [PATCH] When dumping from file system show results in sane order [not found] ` <20101011055448.GL23588-MrY2KI0G/OVr83L8+7iqerDks+cytr/Z@public.gmane.org> @ 2010-10-11 15:12 ` Matthew McClintock 0 siblings, 0 replies; 5+ messages in thread From: Matthew McClintock @ 2010-10-11 15:12 UTC (permalink / raw) To: Grant Likely; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ On Oct 11, 2010, at 12:54 AM, Grant Likely wrote: > 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-KZfg59tc24xl57MIdRCFDg@public.gmane.org> > > 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. I just noticed that, I suspect it will work. I will test it out and get back to everyone. -M ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] When dumping from file system show results in sane order [not found] ` <1286305641-23388-1-git-send-email-msm-KZfg59tc24xl57MIdRCFDg@public.gmane.org> 2010-10-11 5:54 ` Grant Likely @ 2010-10-11 23:55 ` David Gibson 2010-10-12 0:41 ` Matthew McClintock 1 sibling, 1 reply; 5+ messages in thread From: David Gibson @ 2010-10-11 23:55 UTC (permalink / raw) To: Matthew McClintock; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ 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 Reverse order from what? Directory entries are unordered for most intents and purposes - there's no guarantee that readdir() will return entries in a consistent order, and behaviour in practice will vary from one filesystem to another. Your patch doesn't reverse the order - it sorts the items. If that's what you actually want, then my general dtdiff and sorting patch will serve you better, as Grant suggests. -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] When dumping from file system show results in sane order 2010-10-11 23:55 ` David Gibson @ 2010-10-12 0:41 ` Matthew McClintock 0 siblings, 0 replies; 5+ messages in thread From: Matthew McClintock @ 2010-10-12 0:41 UTC (permalink / raw) To: David Gibson; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ On Tue, 2010-10-12 at 10:55 +1100, David Gibson wrote: > 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 > > Reverse order from what? Directory entries are unordered for most > intents and purposes - there's no guarantee that readdir() will return > entries in a consistent order, and behaviour in practice will vary > from one filesystem to another. Ok, maybe I should word it as now ordered. =) > > Your patch doesn't reverse the order - it sorts the items. If that's > what you actually want, then my general dtdiff and sorting patch will > serve you better, as Grant suggests. > Yep, I concur your version is better and I would like to see that accepted for my own reasons. Cheers, Matthew ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-10-12 0:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-05 19:07 [PATCH] When dumping from file system show results in sane order Matthew McClintock
[not found] ` <1286305641-23388-1-git-send-email-msm-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2010-10-11 5:54 ` 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
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.