Skip to contentSkip to conversation

makedevs: fix cases where (start != 0)

PATCH New Thomas De Schampheleire 2 participants 5 messages Feb 22, 2011 – Feb 23, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 makedevs: fix cases where (start != 0)

The makedevs script did not always generate the requested set of device names / minor number series.
* If start != 0, then requesting (count) devices would generate only (count - start)
* If start != 0 && increment != 1, then requesting minors starting with (minor) would generate minors starting with (minor + (start * (increment - 1)))

This patch fixes the code and updates the usage text with extra examples.

package/makedevs/makedevs.c +12 -4
@@ -345,14 +345,22 @@
 	fprintf(stderr, "/dev/null    c    666    0    0     1       3       0       0     -\n");
 	fprintf(stderr, "/dev/zero    c    666    0    0     1       5       0       0     -\n");
 	fprintf(stderr, "/dev/hda     b    640    0    0     3       0       0       0     -\n");
-	fprintf(stderr, "/dev/hda     b    640    0    0     3       1       1       1     15\n\n");
+	fprintf(stderr, "/dev/hda     b    640    0    0     3       1       1       1     15\n");
+	fprintf(stderr, "/dev/rtp     b    640    0    0     250     0       0       1     5\n");
+	fprintf(stderr, "/dev/gps     b    640    0    0     251     0       1       1     5\n");
+	fprintf(stderr, "/dev/uio     b    640    0    0     252     0       1       2     5\n");
+	fprintf(stderr, "/dev/uio     b    640    0    0     252     1       6       2     5\n\n");
 	fprintf(stderr, "Will Produce:\n");
 	fprintf(stderr, "/dev\n");
 	fprintf(stderr, "/dev/console\n");
 	fprintf(stderr, "/dev/null\n");
 	fprintf(stderr, "/dev/zero\n");
 	fprintf(stderr, "/dev/hda\n");
-	fprintf(stderr, "/dev/hda[0-15]\n");
+	fprintf(stderr, "/dev/hda[1-15] with minor numbers [1-15]\n");
+	fprintf(stderr, "/dev/rtp[0-4]  with minor numbers [0-4]\n");
+	fprintf(stderr, "/dev/gps[1-5]  with minor numbers [0-4]\n");
+	fprintf(stderr, "/dev/uio[1-5]  with minor numbers 0,2,4,6,8\n");
+	fprintf(stderr, "/dev/uio[6-10] with minor numbers 1,3,5,7,9\n");
 	exit(1);
 }
 
@@ -489,9 +497,9 @@
 				char *full_name_inc;
 
 				full_name_inc = xmalloc(strlen(full_name) + 8);
-				for (i = start; i < count; i++) {
+				for (i = start; i < start + count; i++) {
 					sprintf(full_name_inc, "%s%d", full_name, i);
-					rdev = makedev(major, minor + (i * increment - start));
+					rdev = makedev(major, minor + ((i - start) * increment));
 					if (mknod(full_name_inc, mode, rdev) == -1) {
 						bb_perror_msg("line %d: Couldnt create node %s", linenum, full_name_inc);
 						ret = EXIT_FAILURE;
#1 lore raw

PATCH 1/1 makedevs: fix cases where (start != 0)

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Thomas" == Thomas De Schampheleire <[email protected]> writes:

Thomas> The makedevs script did not always generate the requested set of device names / minor number series.
Thomas> * If start != 0, then requesting (count) devices would generate only (count - start)
Thomas> * If start != 0 && increment != 1, then requesting minors starting with (minor) would generate minors starting with (minor + (start * (increment - 1)))

Thomas> This patch fixes the code and updates the usage text with extra examples.

Good catch, thanks!

Thomas> full_name_inc = xmalloc(strlen(full_name) + 8);
Thomas> - for (i = start; i < count; i++) {
Thomas> + for (i = start; i < start + count; i++) {
Thomas> sprintf(full_name_inc, "%s%d", full_name, i);
Thomas> - rdev = makedev(major, minor + (i * increment - start));
Thomas> + rdev = makedev(major, minor + ((i - start) * increment));

It looks like the logic would be simplified some by using:

   for (i=0; i < count; i++) {

Care to rework the patch to do that instead?

You could argue if it makes more sense to use start or minor in the makedevs call - They should be the same, but perhaps it would be cleaner to use the same everywhere instead of this mix.

Signature · 1 line
Bye, Peter Korsgaard
#2 lore raw

PATCH 1/1 makedevs: fix cases where (start != 0)

Hi Peter,

Quoted 9 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Thomas" == Thomas De Schampheleire <[email protected]> writes:

?Thomas> The makedevs script did not always generate the requested set of device names / minor number series.
?Thomas> * If start != 0, then requesting (count) devices would generate only (count - start)
?Thomas> * If start != 0 && increment != 1, then requesting minors starting with (minor) would generate minors starting with (minor + (start * (increment - 1)))

?Thomas> This patch fixes the code and updates the usage text with extra examples.

Good catch, thanks!

I should point out that the first problem was reported by Andy Kennedy.

Quoted 8 lines

?Thomas> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?full_name_inc = xmalloc(strlen(full_name) + 8); ?Thomas> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?for (i = start; i < count; i++) {
?Thomas> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?for (i = start; i < start + count; i++) { ?Thomas> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?sprintf(full_name_inc, "%s%d", full_name, i); ?Thomas> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?rdev = makedev(major, minor + (i * increment - start)); ?Thomas> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?rdev = makedev(major, minor + ((i - start) * increment));

Quoted 5 lines

It looks like the logic would be simplified some by using:

? for (i=0; i < count; i++) {

Care to rework the patch to do that instead?

Not at all. I'll send the updated patch tonight. You're right that it will make the logic cleaner.

Quoted 4 lines

You could argue if it makes more sense to use start or minor in the makedevs call - They should be the same, but perhaps it would be cleaner to use the same everywhere instead of this mix.

start relates to the start of the device names
minor relates to the start of the minor numbers

The updated patch will show this distinction more clearly. The makedevs call will only use minor then.

Note that increment only refers to the minor number, and its position in the device table file is somewhat confusing (placed between start and count). Currently, there is no possibility to have an increment other than 1 for the device names, except when listing each combination explicitly.

Best regards,
Thomas

#3 lore raw

PATCH v2 1/1 makedevs: fix cases where (start != 0)

The makedevs script did not always generate the requested set of device names / minor number series.
* If start != 0, then requesting (count) devices would generate only (count - start)
* If start != 0 && increment != 1, then requesting minors starting with (minor) would generate minors starting with (minor + (start * (increment - 1)))

This patch fixes the code and updates the usage text with extra examples.

package/makedevs/makedevs.c +13 -5
@@ -345,14 +345,22 @@
 	fprintf(stderr, "/dev/null    c    666    0    0     1       3       0       0     -\n");
 	fprintf(stderr, "/dev/zero    c    666    0    0     1       5       0       0     -\n");
 	fprintf(stderr, "/dev/hda     b    640    0    0     3       0       0       0     -\n");
-	fprintf(stderr, "/dev/hda     b    640    0    0     3       1       1       1     15\n\n");
+	fprintf(stderr, "/dev/hda     b    640    0    0     3       1       1       1     15\n");
+	fprintf(stderr, "/dev/rtp     b    640    0    0     250     0       0       1     5\n");
+	fprintf(stderr, "/dev/gps     b    640    0    0     251     0       1       1     5\n");
+	fprintf(stderr, "/dev/uio     b    640    0    0     252     0       1       2     5\n");
+	fprintf(stderr, "/dev/uio     b    640    0    0     252     1       6       2     5\n\n");
 	fprintf(stderr, "Will Produce:\n");
 	fprintf(stderr, "/dev\n");
 	fprintf(stderr, "/dev/console\n");
 	fprintf(stderr, "/dev/null\n");
 	fprintf(stderr, "/dev/zero\n");
 	fprintf(stderr, "/dev/hda\n");
-	fprintf(stderr, "/dev/hda[0-15]\n");
+	fprintf(stderr, "/dev/hda[1-15] with minor numbers [1-15]\n");
+	fprintf(stderr, "/dev/rtp[0-4]  with minor numbers [0-4]\n");
+	fprintf(stderr, "/dev/gps[1-5]  with minor numbers [0-4]\n");
+	fprintf(stderr, "/dev/uio[1-5]  with minor numbers 0,2,4,6,8\n");
+	fprintf(stderr, "/dev/uio[6-10] with minor numbers 1,3,5,7,9\n");
 	exit(1);
 }
 
@@ -489,9 +497,9 @@
 				char *full_name_inc;
 
 				full_name_inc = xmalloc(strlen(full_name) + 8);
-				for (i = start; i < count; i++) {
-					sprintf(full_name_inc, "%s%d", full_name, i);
-					rdev = makedev(major, minor + (i * increment - start));
+				for (i = 0; i < count; i++) {
+					sprintf(full_name_inc, "%s%d", full_name, start + i);
+					rdev = makedev(major, minor + i * increment);
 					if (mknod(full_name_inc, mode, rdev) == -1) {
 						bb_perror_msg("line %d: Couldnt create node %s", linenum, full_name_inc);
 						ret = EXIT_FAILURE;
#4 lore raw

PATCH v2 1/1 makedevs: fix cases where (start != 0)

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Thomas" == Thomas De Schampheleire <[email protected]> writes:

Thomas> The makedevs script did not always generate the requested set Thomas> of device names / minor number series. * If start != 0, then Thomas> requesting (count) devices would generate only (count - start) Thomas> * If start != 0 && increment != 1, then requesting minors Thomas> starting with (minor) would generate minors starting with Thomas> (minor + (start * (increment - 1)))

Thomas> This patch fixes the code and updates the usage text with extra Thomas> examples.

Committed, thanks.

Signature · 1 line
Bye, Peter Korsgaard