aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-06-01 21:47:15 +0000
committerEric Andersen <andersen@codepoet.org>2001-06-01 21:47:15 +0000
commit8b113f93b9b9157ea1e013667eaaf00aed97a251 (patch)
treec833c8f3a72637660af61b061b90d69d987fed25
parent4f6753e586dba5e6c240e670d41fc8fd011034e1 (diff)
downloadbusybox-w32-8b113f93b9b9157ea1e013667eaaf00aed97a251.tar.gz
busybox-w32-8b113f93b9b9157ea1e013667eaaf00aed97a251.tar.bz2
busybox-w32-8b113f93b9b9157ea1e013667eaaf00aed97a251.zip
Vladimir's last_patch13, containing several bugfixes.
-rw-r--r--Makefile2
-rw-r--r--coreutils/du.c74
-rw-r--r--du.c74
-rw-r--r--include/libbb.h10
-rw-r--r--libbb/find_root_device.c67
-rw-r--r--libbb/interface.c45
-rw-r--r--libbb/libbb.h10
7 files changed, 218 insertions, 64 deletions
diff --git a/Makefile b/Makefile
index 16da9fd47..62786b9e8 100644
--- a/Makefile
+++ b/Makefile
@@ -241,7 +241,7 @@ concat_path_file.c copy_file.c copy_file_chunk.c create_path.c \
241daemon.c deb_extract.c device_open.c error_msg.c error_msg_and_die.c \ 241daemon.c deb_extract.c device_open.c error_msg.c error_msg_and_die.c \
242find_mount_point.c find_pid_by_name.c find_root_device.c full_read.c \ 242find_mount_point.c find_pid_by_name.c find_root_device.c full_read.c \
243full_write.c get_ar_headers.c get_console.c get_last_path_component.c \ 243full_write.c get_ar_headers.c get_console.c get_last_path_component.c \
244get_line_from_file.c gz_open.c human_readable.c inode_hash.c isdirectory.c \ 244get_line_from_file.c gz_open.c human_readable.c isdirectory.c \
245kernel_version.c loop.c mode_string.c module_syscalls.c mtab.c mtab_file.c \ 245kernel_version.c loop.c mode_string.c module_syscalls.c mtab.c mtab_file.c \
246my_getgrnam.c my_getgrgid.c my_getpwnam.c my_getpwnamegid.c my_getpwuid.c \ 246my_getgrnam.c my_getgrgid.c my_getpwnam.c my_getpwnamegid.c my_getpwuid.c \
247parse_mode.c parse_number.c perror_msg.c perror_msg_and_die.c print_file.c \ 247parse_mode.c parse_number.c perror_msg.c perror_msg_and_die.c print_file.c \
diff --git a/coreutils/du.c b/coreutils/du.c
index 3e4821a39..fd19855e1 100644
--- a/coreutils/du.c
+++ b/coreutils/du.c
@@ -71,6 +71,78 @@ static void print_summary(long size, char *filename)
71 } 71 }
72} 72}
73 73
74#define HASH_SIZE 311 /* Should be prime */
75#define hash_inode(i) ((i) % HASH_SIZE)
76
77typedef struct ino_dev_hash_bucket_struct {
78 struct ino_dev_hash_bucket_struct *next;
79 ino_t ino;
80 dev_t dev;
81 char name[1];
82} ino_dev_hashtable_bucket_t;
83
84static ino_dev_hashtable_bucket_t *ino_dev_hashtable[HASH_SIZE];
85
86/*
87 * Return 1 if statbuf->st_ino && statbuf->st_dev are recorded in
88 * `ino_dev_hashtable', else return 0
89 *
90 * If NAME is a non-NULL pointer to a character pointer, and there is
91 * a match, then set *NAME to the value of the name slot in that
92 * bucket.
93 */
94static int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name)
95{
96 ino_dev_hashtable_bucket_t *bucket;
97
98 bucket = ino_dev_hashtable[hash_inode(statbuf->st_ino)];
99 while (bucket != NULL) {
100 if ((bucket->ino == statbuf->st_ino) &&
101 (bucket->dev == statbuf->st_dev))
102 {
103 if (name) *name = bucket->name;
104 return 1;
105 }
106 bucket = bucket->next;
107 }
108 return 0;
109}
110
111/* Add statbuf to statbuf hash table */
112static void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name)
113{
114 int i;
115 size_t s;
116 ino_dev_hashtable_bucket_t *bucket;
117
118 i = hash_inode(statbuf->st_ino);
119 s = name ? strlen(name) : 0;
120 bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + s);
121 bucket->ino = statbuf->st_ino;
122 bucket->dev = statbuf->st_dev;
123 if (name)
124 strcpy(bucket->name, name);
125 else
126 bucket->name[0] = '\0';
127 bucket->next = ino_dev_hashtable[i];
128 ino_dev_hashtable[i] = bucket;
129}
130
131/* Clear statbuf hash table */
132static void reset_ino_dev_hashtable(void)
133{
134 int i;
135 ino_dev_hashtable_bucket_t *bucket;
136
137 for (i = 0; i < HASH_SIZE; i++) {
138 while (ino_dev_hashtable[i] != NULL) {
139 bucket = ino_dev_hashtable[i]->next;
140 free(ino_dev_hashtable[i]);
141 ino_dev_hashtable[i] = bucket;
142 }
143 }
144}
145
74/* tiny recursive du */ 146/* tiny recursive du */
75static long du(char *filename) 147static long du(char *filename)
76{ 148{
@@ -187,7 +259,7 @@ int du_main(int argc, char **argv)
187 return status; 259 return status;
188} 260}
189 261
190/* $Id: du.c,v 1.47 2001/05/07 22:49:43 andersen Exp $ */ 262/* $Id: du.c,v 1.48 2001/06/01 21:47:15 andersen Exp $ */
191/* 263/*
192Local Variables: 264Local Variables:
193c-file-style: "linux" 265c-file-style: "linux"
diff --git a/du.c b/du.c
index 3e4821a39..fd19855e1 100644
--- a/du.c
+++ b/du.c
@@ -71,6 +71,78 @@ static void print_summary(long size, char *filename)
71 } 71 }
72} 72}
73 73
74#define HASH_SIZE 311 /* Should be prime */
75#define hash_inode(i) ((i) % HASH_SIZE)
76
77typedef struct ino_dev_hash_bucket_struct {
78 struct ino_dev_hash_bucket_struct *next;
79 ino_t ino;
80 dev_t dev;
81 char name[1];
82} ino_dev_hashtable_bucket_t;
83
84static ino_dev_hashtable_bucket_t *ino_dev_hashtable[HASH_SIZE];
85
86/*
87 * Return 1 if statbuf->st_ino && statbuf->st_dev are recorded in
88 * `ino_dev_hashtable', else return 0
89 *
90 * If NAME is a non-NULL pointer to a character pointer, and there is
91 * a match, then set *NAME to the value of the name slot in that
92 * bucket.
93 */
94static int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name)
95{
96 ino_dev_hashtable_bucket_t *bucket;
97
98 bucket = ino_dev_hashtable[hash_inode(statbuf->st_ino)];
99 while (bucket != NULL) {
100 if ((bucket->ino == statbuf->st_ino) &&
101 (bucket->dev == statbuf->st_dev))
102 {
103 if (name) *name = bucket->name;
104 return 1;
105 }
106 bucket = bucket->next;
107 }
108 return 0;
109}
110
111/* Add statbuf to statbuf hash table */
112static void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name)
113{
114 int i;
115 size_t s;
116 ino_dev_hashtable_bucket_t *bucket;
117
118 i = hash_inode(statbuf->st_ino);
119 s = name ? strlen(name) : 0;
120 bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + s);
121 bucket->ino = statbuf->st_ino;
122 bucket->dev = statbuf->st_dev;
123 if (name)
124 strcpy(bucket->name, name);
125 else
126 bucket->name[0] = '\0';
127 bucket->next = ino_dev_hashtable[i];
128 ino_dev_hashtable[i] = bucket;
129}
130
131/* Clear statbuf hash table */
132static void reset_ino_dev_hashtable(void)
133{
134 int i;
135 ino_dev_hashtable_bucket_t *bucket;
136
137 for (i = 0; i < HASH_SIZE; i++) {
138 while (ino_dev_hashtable[i] != NULL) {
139 bucket = ino_dev_hashtable[i]->next;
140 free(ino_dev_hashtable[i]);
141 ino_dev_hashtable[i] = bucket;
142 }
143 }
144}
145
74/* tiny recursive du */ 146/* tiny recursive du */
75static long du(char *filename) 147static long du(char *filename)
76{ 148{
@@ -187,7 +259,7 @@ int du_main(int argc, char **argv)
187 return status; 259 return status;
188} 260}
189 261
190/* $Id: du.c,v 1.47 2001/05/07 22:49:43 andersen Exp $ */ 262/* $Id: du.c,v 1.48 2001/06/01 21:47:15 andersen Exp $ */
191/* 263/*
192Local Variables: 264Local Variables:
193c-file-style: "linux" 265c-file-style: "linux"
diff --git a/include/libbb.h b/include/libbb.h
index 4e324bf86..31bd97f2e 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -92,16 +92,6 @@ const char *time_string(time_t timeVal);
92int is_directory(const char *name, int followLinks, struct stat *statBuf); 92int is_directory(const char *name, int followLinks, struct stat *statBuf);
93int isDevice(const char *name); 93int isDevice(const char *name);
94 94
95typedef struct ino_dev_hash_bucket_struct {
96 struct ino_dev_hash_bucket_struct *next;
97 ino_t ino;
98 dev_t dev;
99 char name[1];
100} ino_dev_hashtable_bucket_t;
101int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name);
102void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
103void reset_ino_dev_hashtable(void);
104
105int remove_file(const char *path, int flags); 95int remove_file(const char *path, int flags);
106int copy_file(const char *source, const char *dest, int flags); 96int copy_file(const char *source, const char *dest, int flags);
107int copy_file_chunk(FILE *src_file, FILE *dst_file, unsigned long long chunksize); 97int copy_file_chunk(FILE *src_file, FILE *dst_file, unsigned long long chunksize);
diff --git a/libbb/find_root_device.c b/libbb/find_root_device.c
index edfd7085a..f8f68464d 100644
--- a/libbb/find_root_device.c
+++ b/libbb/find_root_device.c
@@ -1,10 +1,9 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* 2/*
3 * Utility routines. 3 * Copyright (C) 2000,2001 by Lineo, inc.
4 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
4 * 5 *
5 * Copyright (C) tons of folks. Tracking down who wrote what 6 * Patched by a bunch of people. Feel free to acknowledge your work.
6 * isn't something I'm going to worry about... If you wrote something
7 * here, please feel free to acknowledge your work.
8 * 7 *
9 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
@@ -20,9 +19,6 @@
20 * along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * 21 *
23 * Based in part on code from sash, Copyright (c) 1999 by David I. Bell
24 * Permission has been granted to redistribute this code under the GPL.
25 *
26 */ 22 */
27 23
28#include <stdio.h> 24#include <stdio.h>
@@ -38,45 +34,42 @@ extern char *find_real_root_device_name(const char* name)
38 DIR *dir; 34 DIR *dir;
39 struct dirent *entry; 35 struct dirent *entry;
40 struct stat statBuf, rootStat; 36 struct stat statBuf, rootStat;
41 char *fileName; 37 char *fileName = NULL;
42 dev_t dev; 38 dev_t dev;
43 39
44 if (stat("/", &rootStat) != 0) { 40 if (stat("/", &rootStat) != 0)
45 perror_msg("could not stat '/'"); 41 perror_msg("could not stat '/'");
46 return NULL; 42 else {
47 } 43 if ((dev = rootStat.st_rdev)==0)
48 if ((dev = rootStat.st_rdev)==0) dev=rootStat.st_dev; 44 dev=rootStat.st_dev;
49 45
50 dir = opendir("/dev"); 46 dir = opendir("/dev");
51 if (!dir) { 47 if (!dir)
52 perror_msg("could not open '/dev'"); 48 perror_msg("could not open '/dev'");
53 goto fallback; 49 else {
54 } 50 while((entry = readdir(dir)) != NULL) {
55 51
56 while((entry = readdir(dir)) != NULL) { 52 /* Must skip ".." since that is "/", and so we
53 * would get a false positive on ".." */
54 if (strcmp(entry->d_name, "..") == 0)
55 continue;
57 56
58 /* Must skip ".." since that is "/", and so we 57 fileName = concat_path_file("/dev", entry->d_name);
59 * would get a false positive on ".." */
60 if (strcmp(entry->d_name, "..") == 0)
61 continue;
62 58
63 fileName = concat_path_file("/dev/", entry->d_name); 59 /* Some char devices have the same dev_t as block
64 60 * devices, so make sure this is a block device */
65 /* Some char devices have the same dev_t as block 61 if (stat(fileName, &statBuf) == 0 &&
66 * devices, so make sure this is a block device */ 62 S_ISBLK(statBuf.st_mode)!=0 &&
67 if (stat(fileName, &statBuf) == 0 && 63 statBuf.st_rdev == dev)
68 S_ISBLK(statBuf.st_mode)!=0 && 64 break;
69 statBuf.st_rdev == dev) { 65 free(fileName);
70 return fileName; 66 fileName=NULL;
67 }
68 closedir(dir);
71 } 69 }
72 free(fileName);
73 } 70 }
74 closedir(dir); 71 if(fileName==NULL)
75 72 fileName=xstrdup("/dev/root");
76fallback:
77 /* don't use stack space, caller expects to free() result */
78 fileName=xmalloc(20);
79 sprintf(fileName,"(rdev %u)",(unsigned int) rootStat.st_rdev);
80 return fileName; 73 return fileName;
81} 74}
82 75
diff --git a/libbb/interface.c b/libbb/interface.c
index 1d36c13bb..8eb03a61c 100644
--- a/libbb/interface.c
+++ b/libbb/interface.c
@@ -3,7 +3,7 @@
3 * that either displays or sets the characteristics of 3 * that either displays or sets the characteristics of
4 * one or more of the system's networking interfaces. 4 * one or more of the system's networking interfaces.
5 * 5 *
6 * Version: $Id: interface.c,v 1.2 2001/05/05 03:19:12 bug1 Exp $ 6 * Version: $Id: interface.c,v 1.3 2001/06/01 21:47:15 andersen Exp $
7 * 7 *
8 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> 8 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
9 * and others. Copyright 1993 MicroWalt Corporation 9 * and others. Copyright 1993 MicroWalt Corporation
@@ -49,6 +49,7 @@
49#undef HAVE_AFNETROM 49#undef HAVE_AFNETROM
50#undef HAVE_AFX25 50#undef HAVE_AFX25
51#undef HAVE_AFECONET 51#undef HAVE_AFECONET
52#undef HAVE_AFASH
52 53
53/* 54/*
54 * 55 *
@@ -83,7 +84,7 @@
83#define _(x) x 84#define _(x) x
84#define _PATH_PROCNET_DEV "/proc/net/dev" 85#define _PATH_PROCNET_DEV "/proc/net/dev"
85#define new(p) ((p) = xcalloc(1,sizeof(*(p)))) 86#define new(p) ((p) = xcalloc(1,sizeof(*(p))))
86#define KRELEASE(maj,min,patch) ((maj) * 10000 + (min)*1000 + (patch)) 87#define KRELEASE(maj,min,patch) ((maj) * 65536 + (min)*256 + (patch))
87 88
88static int procnetdev_vsn = 1; 89static int procnetdev_vsn = 1;
89 90
@@ -174,15 +175,31 @@ static struct aftype *aftypes[];
174#ifdef KEEP_UNUSED 175#ifdef KEEP_UNUSED
175 176
176static int flag_unx; 177static int flag_unx;
178#ifdef HAVE_AFIPX
177static int flag_ipx; 179static int flag_ipx;
180#endif
181#ifdef HAVE_AFX25
178static int flag_ax25; 182static int flag_ax25;
183#endif
184#ifdef HAVE_AFATALK
179static int flag_ddp; 185static int flag_ddp;
186#endif
187#ifdef HAVE_AFNETROM
180static int flag_netrom; 188static int flag_netrom;
189#endif
181static int flag_inet; 190static int flag_inet;
191#ifdef HAVE_AFINET6
182static int flag_inet6; 192static int flag_inet6;
193#endif
194#ifdef HAVE_AFECONET
183static int flag_econet; 195static int flag_econet;
196#endif
197#ifdef HAVE_AFX25
184static int flag_x25 = 0; 198static int flag_x25 = 0;
199#endif
200#ifdef HAVE_AFASH
185static int flag_ash; 201static int flag_ash;
202#endif
186 203
187 204
188static struct aftrans_t { 205static struct aftrans_t {
@@ -191,48 +208,68 @@ static struct aftrans_t {
191 int *flag; 208 int *flag;
192} aftrans[] = { 209} aftrans[] = {
193 210
211#ifdef HAVE_AFX25
194 { 212 {
195 "ax25", "ax25", &flag_ax25 213 "ax25", "ax25", &flag_ax25
196 }, 214 },
215#endif
197 { 216 {
198 "ip", "inet", &flag_inet 217 "ip", "inet", &flag_inet
199 }, 218 },
219#ifdef HAVE_AFINET6
200 { 220 {
201 "ip6", "inet6", &flag_inet6 221 "ip6", "inet6", &flag_inet6
202 }, 222 },
223#endif
224#ifdef HAVE_AFIPX
203 { 225 {
204 "ipx", "ipx", &flag_ipx 226 "ipx", "ipx", &flag_ipx
205 }, 227 },
228#endif
229#ifdef HAVE_AFATALK
206 { 230 {
207 "appletalk", "ddp", &flag_ddp 231 "appletalk", "ddp", &flag_ddp
208 }, 232 },
233#endif
234#ifdef HAVE_AFNETROM
209 { 235 {
210 "netrom", "netrom", &flag_netrom 236 "netrom", "netrom", &flag_netrom
211 }, 237 },
238#endif
212 { 239 {
213 "inet", "inet", &flag_inet 240 "inet", "inet", &flag_inet
214 }, 241 },
242#ifdef HAVE_AFINET6
215 { 243 {
216 "inet6", "inet6", &flag_inet6 244 "inet6", "inet6", &flag_inet6
217 }, 245 },
246#endif
247#ifdef HAVE_AFATALK
218 { 248 {
219 "ddp", "ddp", &flag_ddp 249 "ddp", "ddp", &flag_ddp
220 }, 250 },
251#endif
221 { 252 {
222 "unix", "unix", &flag_unx 253 "unix", "unix", &flag_unx
223 }, 254 },
224 { 255 {
225 "tcpip", "inet", &flag_inet 256 "tcpip", "inet", &flag_inet
226 }, 257 },
258#ifdef HAVE_AFECONET
227 { 259 {
228 "econet", "ec", &flag_econet 260 "econet", "ec", &flag_econet
229 }, 261 },
262#endif
263#ifdef HAVE_AFX25
230 { 264 {
231 "x25", "x25", &flag_x25 265 "x25", "x25", &flag_x25
232 }, 266 },
267#endif
268#ifdef HAVE_AFASH
233 { 269 {
234 "ash", "ash", &flag_ash 270 "ash", "ash", &flag_ash
235 }, 271 },
272#endif
236 { 273 {
237 0, 0, 0 274 0, 0, 0
238 } 275 }
@@ -694,7 +731,7 @@ static int aftrans_opt(const char *arg)
694 731
695 while (tmp1) { 732 while (tmp1) {
696 733
697 tmp2 = index(tmp1, ','); 734 tmp2 = strchr(tmp1, ',');
698 735
699 if (tmp2) 736 if (tmp2)
700 *(tmp2++) = '\0'; 737 *(tmp2++) = '\0';
@@ -777,7 +814,7 @@ static struct aftype *get_aftype(const char *name)
777 return (*afp); 814 return (*afp);
778 afp++; 815 afp++;
779 } 816 }
780 if (index(name, ',')) 817 if (strchr(name, ','))
781 fprintf(stderr, _("Please don't supply more than one address family.\n")); 818 fprintf(stderr, _("Please don't supply more than one address family.\n"));
782 return (NULL); 819 return (NULL);
783} 820}
diff --git a/libbb/libbb.h b/libbb/libbb.h
index 4e324bf86..31bd97f2e 100644
--- a/libbb/libbb.h
+++ b/libbb/libbb.h
@@ -92,16 +92,6 @@ const char *time_string(time_t timeVal);
92int is_directory(const char *name, int followLinks, struct stat *statBuf); 92int is_directory(const char *name, int followLinks, struct stat *statBuf);
93int isDevice(const char *name); 93int isDevice(const char *name);
94 94
95typedef struct ino_dev_hash_bucket_struct {
96 struct ino_dev_hash_bucket_struct *next;
97 ino_t ino;
98 dev_t dev;
99 char name[1];
100} ino_dev_hashtable_bucket_t;
101int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name);
102void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
103void reset_ino_dev_hashtable(void);
104
105int remove_file(const char *path, int flags); 95int remove_file(const char *path, int flags);
106int copy_file(const char *source, const char *dest, int flags); 96int copy_file(const char *source, const char *dest, int flags);
107int copy_file_chunk(FILE *src_file, FILE *dst_file, unsigned long long chunksize); 97int copy_file_chunk(FILE *src_file, FILE *dst_file, unsigned long long chunksize);