Skip to contentSkip to conversation

Fixes for makedevs

PATCH Superseded Peter Kjellerstedt 2 participants 8 messages May 30, 2013 – May 31, 2013

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#4 lore raw

PATCH v3 4/5 makedevs: Avoid unnecessary timestamp calculation

In reply to Peter Kjellerstedt
---
 meta/recipes-devtools/makedevs/makedevs-1.0.0/makedevs.c | 2 --
 1 file changed, 2 deletions(-)
meta/recipes-devtools/makedevs/makedevs-1.0.0/makedevs.c +0 -2
index 4cfb1d5..4bb316b 100644
@@ -116,7 +116,6 @@ static void add_new_device(char *name, char *path, unsigned long uid,
 {
 	int status;
 	struct stat sb;
-	time_t timestamp = time(NULL);
 
 	memset(&sb, 0, sizeof(struct stat));
 	status = lstat(path, &sb);
@@ -127,7 +126,6 @@ static void add_new_device(char *name, char *path, unsigned long uid,
 		 * better match the actual file or strange things will happen.... */
 		if ((mode & S_IFMT) != (sb.st_mode & S_IFMT))
 			error_msg_and_die("%s: file type does not match specified type!", path);
-		timestamp = sb.st_mtime;
 	}
 
 	mknod(path, mode, rdev);
Signature · 1 line
1.8.2.1
#3 lore raw

PATCH v3 3/5 makedevs: Make the mode number readable in debug messages

In reply to Peter Kjellerstedt
---
 meta/recipes-devtools/makedevs/makedevs-1.0.0/makedevs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
meta/recipes-devtools/makedevs/makedevs-1.0.0/makedevs.c +4 -4
index d58e891..4cfb1d5 100644
@@ -108,7 +108,7 @@ static void add_new_directory(char *name, char *path,
 {
 	mkdir(path, mode);
 	chown(path, uid, gid);
-//	printf("Directory: %s %s  UID: %ld  GID %ld  MODE: %ld\n", path, name, uid, gid, mode);
+//	printf("Directory: %s %s  UID: %ld  GID %ld  MODE: %04lo\n", path, name, uid, gid, mode);
 }
 
 static void add_new_device(char *name, char *path, unsigned long uid, 
@@ -132,7 +132,7 @@ static void add_new_device(char *name, char *path, unsigned long uid,
 
 	mknod(path, mode, rdev);
 	chown(path, uid, gid);
-//	printf("Device: %s %s  UID: %ld  GID: %ld  MODE: %ld  MAJOR: %d  MINOR: %d\n",
+//	printf("Device: %s %s  UID: %ld  GID: %ld  MODE: %04lo  MAJOR: %d  MINOR: %d\n",
 //			path, name, uid, gid, mode, (short)(rdev >> 8), (short)(rdev & 0xff));
 }
 
@@ -147,7 +147,7 @@ static void add_new_file(char *name, char *path, unsigned long uid,
 	} 
 	chmod(path, mode);
 	chown(path, uid, gid);
-//	printf("File: %s %s  UID: %ld  GID: %ld  MODE: %ld\n",
+//	printf("File: %s %s  UID: %ld  GID: %ld  MODE: %04lo\n",
 //			path, name, gid, uid, mode);
 }
 
@@ -158,7 +158,7 @@ static void add_new_fifo(char *name, char *path, unsigned long uid,
 	if (mknod(path, mode, 0))
 		error_msg_and_die("%s: file can not be created with mknod!", path);
 	chown(path, uid, gid);
-//	printf("File: %s %s  UID: %ld  GID: %ld  MODE: %ld\n",
+//	printf("File: %s %s  UID: %ld  GID: %ld  MODE: %04lo\n",
 //			path, name, gid, uid, mode);
 }
 
Signature · 1 line
1.8.2.1
#5 lore raw

PATCH v3 5/5 makedevs: Make count actually behave as a count for device blocks

In reply to Peter Kjellerstedt

Previously count actually behaved as end, and did not take start into account.

---
 meta/files/device_table-minimal.txt                      | 2 +-
 meta/recipes-devtools/makedevs/makedevs-1.0.0/makedevs.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
meta/files/device_table-minimal.txt +1 -1
index c6e5463..02ed534 100644
@@ -13,7 +13,7 @@
 /dev/apm_bios	c	660	0	46	10	134	-	-	-
 /dev/fb0	c	600	0	0	29	0	-	-	-
 /dev/hda	b	660	0	6	3	0	-	-	-
-/dev/hda	b	660	0	6	3	1	1	1	20
+/dev/hda	b	660	0	6	3	1	1	1	19
 /dev/kmem	c	640	0	15	1	2	-	-	-
 /dev/kmsg	c	600	0	0	1	11	-	-	-
 /dev/mem	c	640	0	15	1	1	-	-	-
meta/recipes-devtools/makedevs/makedevs-1.0.0/makedevs.c +1 -1
index 4bb316b..6c1f2fb 100644
@@ -219,7 +219,7 @@ static int interpret_table_entry(char *line)
 			dev_t rdev;
 			char buf[80];
 
-			for (i = start; i < count; i++) {
+			for (i = start; i < start + count; i++) {
 				sprintf(buf, "%s%d", name, i);
 				sprintf(path, "%s/%s%d", rootdir, name, i);
 				/* FIXME:  MKDEV uses illicit insider knowledge of kernel 
Signature · 1 line
1.8.2.1
#1 lore raw

PATCH v3 1/5 makedevs: Create blocks of devices with the correct uid/gid

In reply to Peter Kjellerstedt

When creating a block of devices (i.e., when count > 0), the wrong path was used with the call to chown(), effectively trying to change the owner of some (probably) non-existent file. Thus the created device nodes were always owned by root.

---
 meta/recipes-devtools/makedevs/makedevs-1.0.0/makedevs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
meta/recipes-devtools/makedevs/makedevs-1.0.0/makedevs.c +3 -2
index c7ad722..247d6c1 100644
@@ -130,7 +130,7 @@ static void add_new_device(char *name, char *path, unsigned long uid,
 		timestamp = sb.st_mtime;
 	}
 
-	mknod(name, mode, rdev);
+	mknod(path, mode, rdev);
 	chown(path, uid, gid);
 //	printf("Device: %s %s  UID: %ld  GID: %ld  MODE: %ld  MAJOR: %d  MINOR: %d\n",
 //			path, name, uid, gid, mode, (short)(rdev >> 8), (short)(rdev & 0xff));
@@ -198,7 +198,7 @@ static int interpret_table_entry(char *line)
 		error_msg_and_die("Device table entries require absolute paths");
 	}
 	name = xstrdup(path + 1);
-	sprintf(path, "%s/%s\0", rootdir, name);
+	sprintf(path, "%s/%s", rootdir, name);
 
 	switch (type) {
 	case 'd':
@@ -223,6 +223,7 @@ static int interpret_table_entry(char *line)
 
 			for (i = start; i < count; i++) {
 				sprintf(buf, "%s%d", name, i);
+				sprintf(path, "%s/%s%d", rootdir, name, i);
 				/* FIXME:  MKDEV uses illicit insider knowledge of kernel 
 				 * major/minor representation...  */
 				rdev = MKDEV(major, minor + (i * increment - start));
Signature · 1 line
1.8.2.1
#2 lore raw

PATCH v3 2/5 makedevs: Correct the device number calculation for blocks of devices

In reply to Peter Kjellerstedt

If the increment > 1 and the start > 0 then the calculation for the minor device number was incorrect.

---
 meta/recipes-devtools/makedevs/makedevs-1.0.0/makedevs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meta/recipes-devtools/makedevs/makedevs-1.0.0/makedevs.c +1 -1
index 247d6c1..d58e891 100644
@@ -226,7 +226,7 @@ static int interpret_table_entry(char *line)
 				sprintf(path, "%s/%s%d", rootdir, name, i);
 				/* FIXME:  MKDEV uses illicit insider knowledge of kernel 
 				 * major/minor representation...  */
-				rdev = MKDEV(major, minor + (i * increment - start));
+				rdev = MKDEV(major, minor + (i - start) * increment);
 				add_new_device(buf, path, uid, gid, mode, rdev);
 			}
 		} else {
Signature · 1 line
1.8.2.1
#0 lore raw

v3 cover Fixes for makedevs

When I wanted to create devices from a package I stumbled upon a couple of problems with the makedevs program. Most notable was that it failed to set the correct uid/gid for devices created as part of a block (i.e., with a count > 0).

PATCH v2: And now with Signed-off-by lines, as requested.

PATCH v3: Also made count for blocks of devices behave as a count rather than the end (noticed after looking a makedevs.c from BusyBox).

The following changes since commit efb8a460d2a977dbd481a0650fba8eb637c65bec:

package.bbclass: Fix sources contents (2013-05-14 08:52:47 +0300)

are available in the git repository at:

git://git.yoctoproject.org/poky-contrib pkj/makedevs
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=pkj/makedevs

Peter Kjellerstedt (5):
makedevs: Create blocks of devices with the correct uid/gid
makedevs: Correct the device number calculation for blocks of devices
makedevs: Make the mode number readable in debug messages
makedevs: Avoid unnecessary timestamp calculation
makedevs: Make count actually behave as a count for device blocks

 meta/files/device_table-minimal.txt                   |  2 +-
 .../makedevs/makedevs-1.0.0/makedevs.c                | 19 +++++++++----------
 2 files changed, 10 insertions(+), 11 deletions(-)
Signature · 1 line
1.8.2.1
#6 lore raw

Re: [PATCH v3 5/5] makedevs: Make count actually behave as a count for device blocks

In reply to Peter Kjellerstedt
Quoted 6 lines · Peter Kjellerstedt

Previously count actually behaved as end, and did not take start into account.

---
 meta/files/device_table-minimal.txt                      | 2 +-
 meta/recipes-devtools/makedevs/makedevs-1.0.0/makedevs.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

No signed-off-by line :(

I merged the others.

Cheers,

Richard

#7 lore raw

Re: [PATCH v3 5/5] makedevs: Make count actually behave as a count for device blocks

Quoted 16 lines

-----Original Message-----
From: Richard Purdie [mailto:[email protected]]
Sent: den 30 maj 2013 21:58
To: Peter Kjellerstedt
Cc: [email protected]
Subject: Re: [OE-core] [PATCH v3 5/5] makedevs: Make count actually behave as a count for device blocks

Quoted 6 lines · Peter Kjellerstedt

Previously count actually behaved as end, and did not take start into account.

---
 meta/files/device_table-minimal.txt                      | 2 +-
 meta/recipes-devtools/makedevs/makedevs-1.0.0/makedevs.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Quoted 7 lines

No signed-off-by line :(

I merged the others.

Cheers,

Richard

Argh. The fact that we are not using Signed-off-by lines internally is not helping me...

I have sent an updated version of the fifth patch.

//Peter