Skip to contentSkip to conversation

Fixes for makedevs

PATCH Superseded Peter Kjellerstedt 2 participants 7 messages May 30, 2013

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#2 lore raw

PATCH v2 2/4 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
#4 lore raw

PATCH v2 4/4 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
#0 lore raw

v2 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).

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

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 (4):
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

 .../recipes-devtools/makedevs/makedevs-1.0.0/makedevs.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
Signature · 1 line
1.8.2.1
#3 lore raw

PATCH v2 3/4 makedevs: Make the mode number readable in debug messages

---
 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
#1 lore raw

PATCH v2 1/4 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
#5 lore raw
In reply to Peter Kjellerstedt
Quoted 6 lines · On 30 May 2013 09:19:54 Peter Kjellerstedt <[email protected]> wrote:

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).

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

Are these appropriate for or fixed already in upstream, I.e. Busybox?

Thanks,

Quoted 19 lines

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 (4):
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

 .../recipes-devtools/makedevs/makedevs-1.0.0/makedevs.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
Quoted 7 lines

--
1.8.2.1

_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core

Sent with AquaMail for Android
http://www.aqua-mail.com

#6 lore raw
Quoted 11 lines

-----Original Message-----
From: Bernhard Reutner-Fischer [mailto:[email protected]]
Sent: den 30 maj 2013 11:02
To: Peter Kjellerstedt; [email protected]
Subject: Re: [OE-core] [PATCH v2 0/4] Fixes for makedevs

Quoted 1 line · On 30 May 2013 09:19:54 Peter Kjellerstedt <[email protected]> wrote:

When I wanted to create devices from a package I stumbled upon a

couple

Quoted 1 line

of problems with the makedevs program. Most notable was that it

Quoted 8 lines

failed

Quoted 1 line

to set the correct uid/gid for devices created as part of a block

(i.e.,

Quoted 3 lines

with a count > 0).

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

Are these appropriate for or fixed already in upstream, I.e. Busybox?

I took a look at makdevs.c in BusyBox, and as far as I can tell that version already has the relevant fixes.

It also made me notice another mistake in the current OE version (it loops from start to count-1 rather than start to start+count-1)... I will send an updated version of the patch series that fixes this.

//Peter