diff options
author | Eric Andersen <andersen@codepoet.org> | 2004-07-26 09:11:12 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2004-07-26 09:11:12 +0000 |
commit | 4f807a84c5d936c931cd93c9e98d087305295a1c (patch) | |
tree | 46c3a59fa158ebbd7303454f2657c330abfc24fe | |
parent | 5dcf15e02de10e648ac8e8d86500678f2043d2e6 (diff) | |
download | busybox-w32-4f807a84c5d936c931cd93c9e98d087305295a1c.tar.gz busybox-w32-4f807a84c5d936c931cd93c9e98d087305295a1c.tar.bz2 busybox-w32-4f807a84c5d936c931cd93c9e98d087305295a1c.zip |
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
-rw-r--r-- | archival/libunarchive/get_header_cpio.c | 3 | ||||
-rw-r--r-- | archival/libunarchive/get_header_tar.c | 4 | ||||
-rw-r--r-- | archival/tar.c | 14 | ||||
-rw-r--r-- | coreutils/ls.c | 10 | ||||
-rw-r--r-- | miscutils/makedevs.c | 9 |
5 files changed, 17 insertions, 23 deletions
diff --git a/archival/libunarchive/get_header_cpio.c b/archival/libunarchive/get_header_cpio.c index f72c37634..11925c4e3 100644 --- a/archival/libunarchive/get_header_cpio.c +++ b/archival/libunarchive/get_header_cpio.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <stdlib.h> | 18 | #include <stdlib.h> |
19 | #include <string.h> | 19 | #include <string.h> |
20 | #include <unistd.h> | 20 | #include <unistd.h> |
21 | #include <sys/sysmacros.h> /* major() and minor() */ | ||
21 | #include "unarchive.h" | 22 | #include "unarchive.h" |
22 | #include "libbb.h" | 23 | #include "libbb.h" |
23 | 24 | ||
@@ -143,7 +144,7 @@ extern char get_header_cpio(archive_handle_t *archive_handle) | |||
143 | } | 144 | } |
144 | } | 145 | } |
145 | } | 146 | } |
146 | file_header->device = (major << 8) | minor; | 147 | file_header->device = makedev(major, minor); |
147 | 148 | ||
148 | if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) { | 149 | if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) { |
149 | archive_handle->action_data(archive_handle); | 150 | archive_handle->action_data(archive_handle); |
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c index 33f19c60a..1ad9ac5e5 100644 --- a/archival/libunarchive/get_header_tar.c +++ b/archival/libunarchive/get_header_tar.c | |||
@@ -121,8 +121,8 @@ extern char get_header_tar(archive_handle_t *archive_handle) | |||
121 | file_header->mtime = strtol(tar.formated.mtime, NULL, 8); | 121 | file_header->mtime = strtol(tar.formated.mtime, NULL, 8); |
122 | file_header->link_name = (tar.formated.linkname[0] != '\0') ? | 122 | file_header->link_name = (tar.formated.linkname[0] != '\0') ? |
123 | bb_xstrdup(tar.formated.linkname) : NULL; | 123 | bb_xstrdup(tar.formated.linkname) : NULL; |
124 | file_header->device = (dev_t) ((strtol(tar.formated.devmajor, NULL, 8) << 8) + | 124 | file_header->device = makedev(strtol(tar.formated.devmajor, NULL, 8), |
125 | strtol(tar.formated.devminor, NULL, 8)); | 125 | strtol(tar.formated.devminor, NULL, 8)); |
126 | 126 | ||
127 | /* Set bits 0-11 of the files mode */ | 127 | /* Set bits 0-11 of the files mode */ |
128 | file_header->mode = 07777 & strtol(tar.formated.mode, NULL, 8); | 128 | file_header->mode = 07777 & strtol(tar.formated.mode, NULL, 8); |
diff --git a/archival/tar.c b/archival/tar.c index 2de6454e7..689dd1424 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -49,6 +49,7 @@ | |||
49 | #include <signal.h> | 49 | #include <signal.h> |
50 | #include <sys/wait.h> | 50 | #include <sys/wait.h> |
51 | #include <sys/socket.h> | 51 | #include <sys/socket.h> |
52 | #include <sys/sysmacros.h> /* major() and minor() */ | ||
52 | #include "unarchive.h" | 53 | #include "unarchive.h" |
53 | #include "busybox.h" | 54 | #include "busybox.h" |
54 | 55 | ||
@@ -58,11 +59,6 @@ | |||
58 | # define TAR_MAGIC "ustar" /* ustar and a null */ | 59 | # define TAR_MAGIC "ustar" /* ustar and a null */ |
59 | # define TAR_VERSION " " /* Be compatable with GNU tar format */ | 60 | # define TAR_VERSION " " /* Be compatable with GNU tar format */ |
60 | 61 | ||
61 | # ifndef MAJOR | ||
62 | # define MAJOR(dev) (((dev)>>8)&0xff) | ||
63 | # define MINOR(dev) ((dev)&0xff) | ||
64 | # endif | ||
65 | |||
66 | static const int TAR_BLOCK_SIZE = 512; | 62 | static const int TAR_BLOCK_SIZE = 512; |
67 | static const int TAR_MAGIC_LEN = 6; | 63 | static const int TAR_MAGIC_LEN = 6; |
68 | static const int TAR_VERSION_LEN = 2; | 64 | static const int TAR_VERSION_LEN = 2; |
@@ -262,15 +258,15 @@ static inline int writeTarHeader(struct TarBallInfo *tbInfo, | |||
262 | } else if (S_ISCHR(statbuf->st_mode)) { | 258 | } else if (S_ISCHR(statbuf->st_mode)) { |
263 | header.typeflag = CHRTYPE; | 259 | header.typeflag = CHRTYPE; |
264 | putOctal(header.devmajor, sizeof(header.devmajor), | 260 | putOctal(header.devmajor, sizeof(header.devmajor), |
265 | MAJOR(statbuf->st_rdev)); | 261 | major(statbuf->st_rdev)); |
266 | putOctal(header.devminor, sizeof(header.devminor), | 262 | putOctal(header.devminor, sizeof(header.devminor), |
267 | MINOR(statbuf->st_rdev)); | 263 | minor(statbuf->st_rdev)); |
268 | } else if (S_ISBLK(statbuf->st_mode)) { | 264 | } else if (S_ISBLK(statbuf->st_mode)) { |
269 | header.typeflag = BLKTYPE; | 265 | header.typeflag = BLKTYPE; |
270 | putOctal(header.devmajor, sizeof(header.devmajor), | 266 | putOctal(header.devmajor, sizeof(header.devmajor), |
271 | MAJOR(statbuf->st_rdev)); | 267 | major(statbuf->st_rdev)); |
272 | putOctal(header.devminor, sizeof(header.devminor), | 268 | putOctal(header.devminor, sizeof(header.devminor), |
273 | MINOR(statbuf->st_rdev)); | 269 | minor(statbuf->st_rdev)); |
274 | } else if (S_ISFIFO(statbuf->st_mode)) { | 270 | } else if (S_ISFIFO(statbuf->st_mode)) { |
275 | header.typeflag = FIFOTYPE; | 271 | header.typeflag = FIFOTYPE; |
276 | } else if (S_ISREG(statbuf->st_mode)) { | 272 | } else if (S_ISREG(statbuf->st_mode)) { |
diff --git a/coreutils/ls.c b/coreutils/ls.c index 5fc60a347..a87f0ec2d 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -61,6 +61,7 @@ enum { | |||
61 | #include <signal.h> | 61 | #include <signal.h> |
62 | #include <termios.h> | 62 | #include <termios.h> |
63 | #include <sys/ioctl.h> | 63 | #include <sys/ioctl.h> |
64 | #include <sys/sysmacros.h> /* major() and minor() */ | ||
64 | #include "busybox.h" | 65 | #include "busybox.h" |
65 | #ifdef CONFIG_SELINUX | 66 | #ifdef CONFIG_SELINUX |
66 | #include <fs_secure.h> | 67 | #include <fs_secure.h> |
@@ -72,11 +73,6 @@ enum { | |||
72 | #include <time.h> | 73 | #include <time.h> |
73 | #endif | 74 | #endif |
74 | 75 | ||
75 | #ifndef MAJOR | ||
76 | #define MAJOR(dev) (((dev)>>8)&0xff) | ||
77 | #define MINOR(dev) ((dev)&0xff) | ||
78 | #endif | ||
79 | |||
80 | /* what is the overall style of the listing */ | 76 | /* what is the overall style of the listing */ |
81 | #define STYLE_AUTO (0) | 77 | #define STYLE_AUTO (0) |
82 | #define STYLE_COLUMNS (1U<<21) /* fill columns */ | 78 | #define STYLE_COLUMNS (1U<<21) /* fill columns */ |
@@ -700,8 +696,8 @@ static int list_single(struct dnode *dn) | |||
700 | case LIST_SIZE: | 696 | case LIST_SIZE: |
701 | case LIST_DEV: | 697 | case LIST_DEV: |
702 | if (S_ISBLK(dn->dstat.st_mode) || S_ISCHR(dn->dstat.st_mode)) { | 698 | if (S_ISBLK(dn->dstat.st_mode) || S_ISCHR(dn->dstat.st_mode)) { |
703 | column += printf("%4d, %3d ", (int) MAJOR(dn->dstat.st_rdev), | 699 | column += printf("%4d, %3d ", (int) major(dn->dstat.st_rdev), |
704 | (int) MINOR(dn->dstat.st_rdev)); | 700 | (int) minor(dn->dstat.st_rdev)); |
705 | } else { | 701 | } else { |
706 | #ifdef CONFIG_FEATURE_HUMAN_READABLE | 702 | #ifdef CONFIG_FEATURE_HUMAN_READABLE |
707 | if (all_fmt & LS_DISP_HR) { | 703 | if (all_fmt & LS_DISP_HR) { |
diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c index 45498bb1d..e4233330a 100644 --- a/miscutils/makedevs.c +++ b/miscutils/makedevs.c | |||
@@ -13,21 +13,22 @@ | |||
13 | #include <fcntl.h> | 13 | #include <fcntl.h> |
14 | #include <unistd.h> | 14 | #include <unistd.h> |
15 | #include <sys/types.h> | 15 | #include <sys/types.h> |
16 | #include <sys/sysmacros.h> /* major() and minor() */ | ||
16 | #include "busybox.h" | 17 | #include "busybox.h" |
17 | 18 | ||
18 | int makedevs_main(int argc, char **argv) | 19 | int makedevs_main(int argc, char **argv) |
19 | { | 20 | { |
20 | mode_t mode; | 21 | mode_t mode; |
21 | char *basedev, *type, *nodname, buf[255]; | 22 | char *basedev, *type, *nodname, buf[255]; |
22 | int major, Sminor, S, E; | 23 | int Smajor, Sminor, S, E; |
23 | 24 | ||
24 | if (argc < 7 || *argv[1]=='-') | 25 | if (argc < 7 || *argv[1]=='-') |
25 | bb_show_usage(); | 26 | bb_show_usage(); |
26 | 27 | ||
27 | basedev = argv[1]; | 28 | basedev = argv[1]; |
28 | type = argv[2]; | 29 | type = argv[2]; |
29 | major = atoi(argv[3]) << 8; /* correcting param to mknod() */ | 30 | Smajor = major(atoi(argv[3])); |
30 | Sminor = atoi(argv[4]); | 31 | Sminor = minor(atoi(argv[4])); |
31 | S = atoi(argv[5]); | 32 | S = atoi(argv[5]); |
32 | E = atoi(argv[6]); | 33 | E = atoi(argv[6]); |
33 | nodname = argc == 8 ? basedev : buf; | 34 | nodname = argc == 8 ? basedev : buf; |
@@ -57,7 +58,7 @@ int makedevs_main(int argc, char **argv) | |||
57 | 58 | ||
58 | /* if mode != S_IFCHR and != S_IFBLK third param in mknod() ignored */ | 59 | /* if mode != S_IFCHR and != S_IFBLK third param in mknod() ignored */ |
59 | 60 | ||
60 | if (mknod(nodname, mode, major | Sminor)) | 61 | if (mknod(nodname, mode, Smajor | Sminor)) |
61 | bb_error_msg("Failed to create: %s", nodname); | 62 | bb_error_msg("Failed to create: %s", nodname); |
62 | 63 | ||
63 | if (nodname == basedev) /* ex. /dev/hda - to /dev/hda1 ... */ | 64 | if (nodname == basedev) /* ex. /dev/hda - to /dev/hda1 ... */ |