[BusyBox-cvs] CVS update of busybox (archival/libunarchive/get_header_cpio.c archival/libunarchive/get_header_tar.c archival/tar.c coreutils/ls.c miscutils/makedevs.c)

Erik Andersen andersen at codepoet.org
Mon Jul 26 09:11:13 UTC 2004


    Date: Monday, July 26, 2004 @ 03:11:13
  Author: andersen
    Path: /var/cvs/busybox

Modified: archival/libunarchive/get_header_cpio.c (1.10 -> 1.11)
          archival/libunarchive/get_header_tar.c (1.37 -> 1.38)
          archival/tar.c (1.193 -> 1.194) coreutils/ls.c (1.109 -> 1.110)
          miscutils/makedevs.c (1.18 -> 1.19)

BusyBox has no business hard coding the number of major and minor bits for a
dev_t.  This is especially important now that the user space concept of a dev_t
and the kernel concept of a dev_t are divergant.  The only bit of user space
allowed to know the number of major and minor bits is include/sys/sysmacros.h
(i.e. part of libc).  When used with a current C library and a 2.6.x kernel,
this fix should allow BusyBox to support wide device major/minor numbers.
 -Erik


Index: busybox/archival/libunarchive/get_header_cpio.c
diff -u busybox/archival/libunarchive/get_header_cpio.c:1.10 busybox/archival/libunarchive/get_header_cpio.c:1.11
--- busybox/archival/libunarchive/get_header_cpio.c:1.10	Thu Apr 29 03:24:19 2004
+++ busybox/archival/libunarchive/get_header_cpio.c	Mon Jul 26 03:11:11 2004
@@ -18,6 +18,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <sys/sysmacros.h>     /* major() and minor() */
 #include "unarchive.h"
 #include "libbb.h"
 
@@ -143,7 +144,7 @@
 			}
 		}
 	}
-	file_header->device = (major << 8) | minor;
+	file_header->device = makedev(major, minor);
 
 	if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
 		archive_handle->action_data(archive_handle);
Index: busybox/archival/libunarchive/get_header_tar.c
diff -u busybox/archival/libunarchive/get_header_tar.c:1.37 busybox/archival/libunarchive/get_header_tar.c:1.38
--- busybox/archival/libunarchive/get_header_tar.c:1.37	Wed Apr 14 11:51:08 2004
+++ busybox/archival/libunarchive/get_header_tar.c	Mon Jul 26 03:11:11 2004
@@ -121,8 +121,8 @@
 	file_header->mtime = strtol(tar.formated.mtime, NULL, 8);
 	file_header->link_name = (tar.formated.linkname[0] != '\0') ?
 	    bb_xstrdup(tar.formated.linkname) : NULL;
-	file_header->device = (dev_t) ((strtol(tar.formated.devmajor, NULL, 8) << 8) +
-				 strtol(tar.formated.devminor, NULL, 8));
+	file_header->device = makedev(strtol(tar.formated.devmajor, NULL, 8),
+		strtol(tar.formated.devminor, NULL, 8));
 
 	/* Set bits 0-11 of the files mode */
 	file_header->mode = 07777 & strtol(tar.formated.mode, NULL, 8);
Index: busybox/archival/tar.c
diff -u busybox/archival/tar.c:1.193 busybox/archival/tar.c:1.194
--- busybox/archival/tar.c:1.193	Wed Jul 21 03:00:39 2004
+++ busybox/archival/tar.c	Mon Jul 26 03:11:11 2004
@@ -49,6 +49,7 @@
 #include <signal.h>
 #include <sys/wait.h>
 #include <sys/socket.h>
+#include <sys/sysmacros.h>     /* major() and minor() */
 #include "unarchive.h"
 #include "busybox.h"
 
@@ -58,11 +59,6 @@
 # define TAR_MAGIC          "ustar"	/* ustar and a null */
 # define TAR_VERSION        "  "	/* Be compatable with GNU tar format */
 
-# ifndef MAJOR
-#  define MAJOR(dev) (((dev)>>8)&0xff)
-#  define MINOR(dev) ((dev)&0xff)
-# endif
-
 static const int TAR_BLOCK_SIZE = 512;
 static const int TAR_MAGIC_LEN = 6;
 static const int TAR_VERSION_LEN = 2;
@@ -262,15 +258,15 @@
 	} else if (S_ISCHR(statbuf->st_mode)) {
 		header.typeflag = CHRTYPE;
 		putOctal(header.devmajor, sizeof(header.devmajor),
-				 MAJOR(statbuf->st_rdev));
+				 major(statbuf->st_rdev));
 		putOctal(header.devminor, sizeof(header.devminor),
-				 MINOR(statbuf->st_rdev));
+				 minor(statbuf->st_rdev));
 	} else if (S_ISBLK(statbuf->st_mode)) {
 		header.typeflag = BLKTYPE;
 		putOctal(header.devmajor, sizeof(header.devmajor),
-				 MAJOR(statbuf->st_rdev));
+				 major(statbuf->st_rdev));
 		putOctal(header.devminor, sizeof(header.devminor),
-				 MINOR(statbuf->st_rdev));
+				 minor(statbuf->st_rdev));
 	} else if (S_ISFIFO(statbuf->st_mode)) {
 		header.typeflag = FIFOTYPE;
 	} else if (S_ISREG(statbuf->st_mode)) {
Index: busybox/coreutils/ls.c
diff -u busybox/coreutils/ls.c:1.109 busybox/coreutils/ls.c:1.110
--- busybox/coreutils/ls.c:1.109	Sat Mar 27 03:02:42 2004
+++ busybox/coreutils/ls.c	Mon Jul 26 03:11:12 2004
@@ -61,6 +61,7 @@
 #include <signal.h>
 #include <termios.h>
 #include <sys/ioctl.h>
+#include <sys/sysmacros.h>     /* major() and minor() */
 #include "busybox.h"
 #ifdef CONFIG_SELINUX
 #include <fs_secure.h>
@@ -72,11 +73,6 @@
 #include <time.h>
 #endif
 
-#ifndef MAJOR
-#define MAJOR(dev) (((dev)>>8)&0xff)
-#define MINOR(dev) ((dev)&0xff)
-#endif
-
 /* what is the overall style of the listing */
 #define STYLE_AUTO      (0)
 #define STYLE_COLUMNS   (1U<<21)	/* fill columns */
@@ -700,8 +696,8 @@
 		case LIST_SIZE:
 		case LIST_DEV:
 			if (S_ISBLK(dn->dstat.st_mode) || S_ISCHR(dn->dstat.st_mode)) {
-				column += printf("%4d, %3d ", (int) MAJOR(dn->dstat.st_rdev),
-					   (int) MINOR(dn->dstat.st_rdev));
+				column += printf("%4d, %3d ", (int) major(dn->dstat.st_rdev),
+					   (int) minor(dn->dstat.st_rdev));
 			} else {
 #ifdef CONFIG_FEATURE_HUMAN_READABLE
 				if (all_fmt & LS_DISP_HR) {
Index: busybox/miscutils/makedevs.c
diff -u busybox/miscutils/makedevs.c:1.18 busybox/miscutils/makedevs.c:1.19
--- busybox/miscutils/makedevs.c:1.18	Sat Jun  5 01:58:18 2004
+++ busybox/miscutils/makedevs.c	Mon Jul 26 03:11:12 2004
@@ -13,21 +13,22 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/types.h>
+#include <sys/sysmacros.h>     /* major() and minor() */
 #include "busybox.h"
 
 int makedevs_main(int argc, char **argv)
 {
 	mode_t mode;
 	char *basedev, *type, *nodname, buf[255];
-	int major, Sminor, S, E;
+	int Smajor, Sminor, S, E;
 
 	if (argc < 7 || *argv[1]=='-')
 		bb_show_usage();
 
 	basedev = argv[1];
 	type = argv[2];
-	major = atoi(argv[3]) << 8;  /* correcting param to mknod() */
-	Sminor = atoi(argv[4]);
+	Smajor = major(atoi(argv[3]));
+	Sminor = minor(atoi(argv[4]));
 	S = atoi(argv[5]);
 	E = atoi(argv[6]);
 	nodname = argc == 8 ? basedev : buf;
@@ -57,7 +58,7 @@
 
 	/* if mode != S_IFCHR and != S_IFBLK third param in mknod() ignored */
 
-		if (mknod(nodname, mode, major | Sminor))
+		if (mknod(nodname, mode, Smajor | Sminor))
 			bb_error_msg("Failed to create: %s", nodname);
 
 		if (nodname == basedev) /* ex. /dev/hda - to /dev/hda1 ... */



More information about the busybox-cvs mailing list