aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorerik <erik@69ca8d6d-28ef-0310-b511-8ec308f3f277>2000-02-08 19:58:47 +0000
committererik <erik@69ca8d6d-28ef-0310-b511-8ec308f3f277>2000-02-08 19:58:47 +0000
commita18125005d67c38a8ad7fb454571bb996664ad96 (patch)
treec90bda10731ad9333ce3b404f993354c9fc104b8 /util-linux
parent8ef3b44285a8ce5b83bed9cf32ce5f40b30ba72f (diff)
downloadbusybox-w32-a18125005d67c38a8ad7fb454571bb996664ad96.tar.gz
busybox-w32-a18125005d67c38a8ad7fb454571bb996664ad96.tar.bz2
busybox-w32-a18125005d67c38a8ad7fb454571bb996664ad96.zip
Some formatting updates (ran the code through indent)
-Erik git-svn-id: svn://busybox.net/trunk/busybox@357 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/dmesg.c160
-rw-r--r--util-linux/fbset.c360
-rw-r--r--util-linux/fdflush.c36
-rw-r--r--util-linux/fsck_minix.c716
-rw-r--r--util-linux/mkfs_minix.c499
-rw-r--r--util-linux/mkswap.c197
-rw-r--r--util-linux/more.c199
-rw-r--r--util-linux/mount.c581
-rw-r--r--util-linux/nfsmount.c933
-rw-r--r--util-linux/nfsmount.h1
-rw-r--r--util-linux/swaponoff.c131
-rw-r--r--util-linux/umount.c291
12 files changed, 2091 insertions, 2013 deletions
diff --git a/util-linux/dmesg.c b/util-linux/dmesg.c
index e38fd5555..bbed8221a 100644
--- a/util-linux/dmesg.c
+++ b/util-linux/dmesg.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* dmesg.c -- Print out the contents of the kernel ring buffer 2/* dmesg.c -- Print out the contents of the kernel ring buffer
2 * Created: Sat Oct 9 16:19:47 1993 3 * Created: Sat Oct 9 16:19:47 1993
3 * Revised: Thu Oct 28 21:52:17 1993 by faith@cs.unc.edu 4 * Revised: Thu Oct 28 21:52:17 1993 by faith@cs.unc.edu
@@ -24,8 +25,8 @@
24 25
25#ifndef __alpha__ 26#ifndef __alpha__
26# define __NR_klogctl __NR_syslog 27# define __NR_klogctl __NR_syslog
27 static inline _syscall3(int, klogctl, int, type, char *, b, int, len); 28static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
28#else /* __alpha__ */ 29#else /* __alpha__ */
29#define klogctl syslog 30#define klogctl syslog
30#endif 31#endif
31 32
@@ -35,90 +36,91 @@
35 36
36static const char dmesg_usage[] = "dmesg [-c] [-n level] [-s bufsize]\n"; 37static const char dmesg_usage[] = "dmesg [-c] [-n level] [-s bufsize]\n";
37 38
38int dmesg_main( int argc, char** argv ) 39int dmesg_main(int argc, char **argv)
39{ 40{
40 char *buf; 41 char *buf;
41 int bufsize=8196; 42 int bufsize = 8196;
42 int i; 43 int i;
43 int n; 44 int n;
44 int level = 0; 45 int level = 0;
45 int lastc; 46 int lastc;
46 int cmd = 3; 47 int cmd = 3;
47 int stopDoingThat; 48 int stopDoingThat;
48 49
49 argc--; 50 argc--;
50 argv++; 51 argv++;
51 52
52 /* Parse any options */ 53 /* Parse any options */
53 while (argc && **argv == '-') { 54 while (argc && **argv == '-') {
54 stopDoingThat = FALSE; 55 stopDoingThat = FALSE;
55 while (stopDoingThat == FALSE && *++(*argv)) { 56 while (stopDoingThat == FALSE && *++(*argv)) {
56 switch (**argv) { 57 switch (**argv) {
57 case 'c': 58 case 'c':
58 cmd = 4; 59 cmd = 4;
59 break; 60 break;
60 case 'n': 61 case 'n':
61 cmd = 8; 62 cmd = 8;
62 if (--argc == 0) 63 if (--argc == 0)
63 goto end; 64 goto end;
64 level = atoi (*(++argv)); 65 level = atoi(*(++argv));
65 if (--argc > 0) 66 if (--argc > 0)
66 ++argv; 67 ++argv;
67 stopDoingThat = TRUE; 68 stopDoingThat = TRUE;
68 break; 69 break;
69 case 's': 70 case 's':
70 if (--argc == 0) 71 if (--argc == 0)
71 goto end; 72 goto end;
72 bufsize = atoi (*(++argv)); 73 bufsize = atoi(*(++argv));
73 if (--argc > 0) 74 if (--argc > 0)
74 ++argv; 75 ++argv;
75 stopDoingThat = TRUE; 76 stopDoingThat = TRUE;
76 break; 77 break;
77 default: 78 default:
79 goto end;
80 }
81 }
82 }
83
84 if (argc > 1) {
78 goto end; 85 goto end;
79 }
80 } 86 }
81 }
82
83 if (argc > 1) {
84 goto end;
85 }
86 87
87 if (cmd == 8) { 88 if (cmd == 8) {
88 n = klogctl( cmd, NULL, level ); 89 n = klogctl(cmd, NULL, level);
89 if (n < 0) { 90 if (n < 0) {
90 goto klogctl_error; 91 goto klogctl_error;
91 } 92 }
92 exit( TRUE ); 93 exit(TRUE);
93 } 94 }
94 95
95 if (bufsize < 4096) bufsize = 4096; 96 if (bufsize < 4096)
96 buf = (char*)malloc(bufsize); 97 bufsize = 4096;
97 n = klogctl( cmd, buf, bufsize ); 98 buf = (char *) malloc(bufsize);
98 if (n < 0) { 99 n = klogctl(cmd, buf, bufsize);
99 goto klogctl_error; 100 if (n < 0) {
100 } 101 goto klogctl_error;
102 }
101 103
102 lastc = '\n'; 104 lastc = '\n';
103 for (i = 0; i < n; i++) { 105 for (i = 0; i < n; i++) {
104 if ((i == 0 || buf[i - 1] == '\n') && buf[i] == '<') { 106 if ((i == 0 || buf[i - 1] == '\n') && buf[i] == '<') {
105 i++; 107 i++;
106 while (buf[i] >= '0' && buf[i] <= '9') 108 while (buf[i] >= '0' && buf[i] <= '9')
107 i++; 109 i++;
108 if (buf[i] == '>') 110 if (buf[i] == '>')
109 i++; 111 i++;
110 } 112 }
111 lastc = buf[i]; 113 lastc = buf[i];
112 putchar( lastc ); 114 putchar(lastc);
113 } 115 }
114 if (lastc != '\n') 116 if (lastc != '\n')
115 putchar( '\n' ); 117 putchar('\n');
116 exit( TRUE); 118 exit(TRUE);
117end: 119 end:
118 usage( dmesg_usage); 120 usage(dmesg_usage);
119 exit (FALSE); 121 exit(FALSE);
120klogctl_error: 122 klogctl_error:
121 perror( "klogctl" ); 123 perror("klogctl");
122 exit( FALSE ); 124 exit(FALSE);
123 125
124} 126}
diff --git a/util-linux/fbset.c b/util-linux/fbset.c
index c29145e51..a75e431db 100644
--- a/util-linux/fbset.c
+++ b/util-linux/fbset.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * Mini fbset implementation for busybox 3 * Mini fbset implementation for busybox
3 * 4 *
@@ -48,7 +49,7 @@
48#define OPT_READMODE (1 << 2) 49#define OPT_READMODE (1 << 2)
49 50
50#define CMD_HELP 0 51#define CMD_HELP 0
51#define CMD_FB 1 52#define CMD_FB 1
52#define CMD_DB 2 53#define CMD_DB 2
53#define CMD_GEOMETRY 3 54#define CMD_GEOMETRY 3
54#define CMD_TIMING 4 55#define CMD_TIMING 4
@@ -87,213 +88,242 @@
87static unsigned int g_options = 0; 88static unsigned int g_options = 0;
88 89
89struct cmdoptions_t { 90struct cmdoptions_t {
90 char *name; 91 char *name;
91 unsigned char param_count; 92 unsigned char param_count;
92 unsigned char code; 93 unsigned char code;
93} g_cmdoptions[] = { 94} g_cmdoptions[] = {
94 { "-h", 0, CMD_HELP }, 95 {
95 { "-fb", 1, CMD_FB }, 96 "-h", 0, CMD_HELP}, {
96 { "-db", 1, CMD_DB }, 97 "-fb", 1, CMD_FB}, {
97 { "-a", 0, CMD_ALL }, 98 "-db", 1, CMD_DB}, {
98 { "-i", 0, CMD_INFO }, 99 "-a", 0, CMD_ALL}, {
99 { "-g", 5, CMD_GEOMETRY }, 100 "-i", 0, CMD_INFO}, {
100 { "-t", 7, CMD_TIMING }, 101 "-g", 5, CMD_GEOMETRY}, {
101 { "-accel", 1, CMD_ACCEL }, 102 "-t", 7, CMD_TIMING}, {
102 { "-hsync", 1, CMD_HSYNC }, 103 "-accel", 1, CMD_ACCEL}, {
103 { "-vsync", 1, CMD_VSYNC }, 104 "-hsync", 1, CMD_HSYNC}, {
104 { "-laced", 1, CMD_LACED }, 105 "-vsync", 1, CMD_VSYNC}, {
105 { "-double", 1, CMD_DOUBLE }, 106 "-laced", 1, CMD_LACED}, {
106 107 "-double", 1, CMD_DOUBLE},
107#ifdef BB_FBSET_FANCY 108#ifdef BB_FBSET_FANCY
108 { "--help", 0, CMD_HELP }, 109 {
109 { "-all", 0, CMD_ALL }, 110 "--help", 0, CMD_HELP}, {
110 { "-xres", 1, CMD_XRES }, 111 "-all", 0, CMD_ALL}, {
111 { "-yres", 1, CMD_YRES }, 112 "-xres", 1, CMD_XRES}, {
112 { "-vxres", 1, CMD_VXRES }, 113 "-yres", 1, CMD_YRES}, {
113 { "-vyres", 1, CMD_VYRES }, 114 "-vxres", 1, CMD_VXRES}, {
114 { "-depth", 1, CMD_DEPTH }, 115 "-vyres", 1, CMD_VYRES}, {
115 { "-match", 0, CMD_MATCH }, 116 "-depth", 1, CMD_DEPTH}, {
116 { "--geometry", 5, CMD_GEOMETRY }, 117 "-match", 0, CMD_MATCH}, {
117 118 "--geometry", 5, CMD_GEOMETRY}, {
118 { "-pixclock", 1, CMD_PIXCLOCK }, 119 "-pixclock", 1, CMD_PIXCLOCK}, {
119 { "-left", 1, CMD_LEFT }, 120 "-left", 1, CMD_LEFT}, {
120 { "-right", 1, CMD_RIGHT }, 121 "-right", 1, CMD_RIGHT}, {
121 { "-upper", 1, CMD_UPPER }, 122 "-upper", 1, CMD_UPPER}, {
122 { "-lower", 1, CMD_LOWER }, 123 "-lower", 1, CMD_LOWER}, {
123 { "-hslen", 1, CMD_HSLEN }, 124 "-hslen", 1, CMD_HSLEN}, {
124 { "-vslen", 1, CMD_VSLEN }, 125 "-vslen", 1, CMD_VSLEN}, {
125 { "--timings", 7, CMD_TIMING }, 126 "--timings", 7, CMD_TIMING}, {
126 127 "-csync", 1, CMD_CSYNC}, {
127 { "-csync", 1, CMD_CSYNC }, 128 "-gsync", 1, CMD_GSYNC}, {
128 { "-gsync", 1, CMD_GSYNC }, 129 "-extsync", 1, CMD_EXTSYNC}, {
129 { "-extsync", 1, CMD_EXTSYNC }, 130 "-bcast", 1, CMD_BCAST}, {
130 { "-bcast", 1, CMD_BCAST }, 131 "-rgba", 1, CMD_RGBA}, {
131 { "-rgba", 1, CMD_RGBA }, 132 "-step", 1, CMD_STEP}, {
132 { "-step", 1, CMD_STEP }, 133 "-move", 1, CMD_MOVE},
133 { "-move", 1, CMD_MOVE },
134#endif 134#endif
135 { 0, 0, 0 } 135 {
136 0, 0, 0}
136}; 137};
137 138
138static int readmode(struct fb_var_screeninfo *base, const char *fn, 139static int readmode(struct fb_var_screeninfo *base, const char *fn,
139 const char *mode) 140 const char *mode)
140{ 141{
141#ifdef BB_FBSET_READMODE 142#ifdef BB_FBSET_READMODE
142 FILE *f; 143 FILE *f;
143 char buf[256]; 144 char buf[256];
144 char *p = buf; 145 char *p = buf;
145 146
146 if ((f = fopen(fn, "r")) == NULL) PERROR("readmode(fopen)"); 147 if ((f = fopen(fn, "r")) == NULL)
147 while (!feof(f)) { 148 PERROR("readmode(fopen)");
148 fgets(buf, sizeof(buf), f); 149 while (!feof(f)) {
149 if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) { 150 fgets(buf, sizeof(buf), f);
150 p += 5; 151 if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) {
151 if ((p = strstr(buf, mode))) { 152 p += 5;
152 p += strlen(mode); 153 if ((p = strstr(buf, mode))) {
153 if (!isspace(*p) && (*p != 0) && (*p != '"') && (*p != '\r') 154 p += strlen(mode);
154 && (*p != '\n')) continue; /* almost, but not quite */ 155 if (!isspace(*p) && (*p != 0) && (*p != '"')
155 while (!feof(f)) { 156 && (*p != '\r') && (*p != '\n'))
156 fgets(buf, sizeof(buf), f); 157 continue; /* almost, but not quite */
157 if (!strstr(buf, "endmode")) return 1; 158 while (!feof(f)) {
159 fgets(buf, sizeof(buf), f);
160 if (!strstr(buf, "endmode"))
161 return 1;
162 }
163 }
158 } 164 }
159 }
160 } 165 }
161 }
162#else 166#else
163 fprintf(stderr, "W: mode reading was disabled on this copy of fbset; ignoring request\n"); 167 fprintf(stderr,
168 "W: mode reading was disabled on this copy of fbset; ignoring request\n");
164#endif 169#endif
165 return 0; 170 return 0;
166} 171}
167 172
168static void setmode(struct fb_var_screeninfo *base, 173static void setmode(struct fb_var_screeninfo *base,
169 struct fb_var_screeninfo *set) 174 struct fb_var_screeninfo *set)
170{ 175{
171 if ((int)set->xres > 0) base->xres = set->xres; 176 if ((int) set->xres > 0)
172 if ((int)set->yres > 0) base->yres = set->yres; 177 base->xres = set->xres;
173 if ((int)set->xres_virtual > 0) base->xres_virtual = set->xres_virtual; 178 if ((int) set->yres > 0)
174 if ((int)set->yres_virtual > 0) base->yres_virtual = set->yres_virtual; 179 base->yres = set->yres;
175 if ((int)set->bits_per_pixel > 0) base->bits_per_pixel = set->bits_per_pixel; 180 if ((int) set->xres_virtual > 0)
181 base->xres_virtual = set->xres_virtual;
182 if ((int) set->yres_virtual > 0)
183 base->yres_virtual = set->yres_virtual;
184 if ((int) set->bits_per_pixel > 0)
185 base->bits_per_pixel = set->bits_per_pixel;
176} 186}
177 187
178static void showmode(struct fb_var_screeninfo *v) 188static void showmode(struct fb_var_screeninfo *v)
179{ 189{
180 double drate = 0, hrate = 0, vrate = 0; 190 double drate = 0, hrate = 0, vrate = 0;
181 if (v->pixclock) { 191
182 drate = 1e12 / v->pixclock; 192 if (v->pixclock) {
183 hrate = drate / (v->left_margin+v->xres+v->right_margin+v->hsync_len); 193 drate = 1e12 / v->pixclock;
184 vrate = hrate / (v->upper_margin+v->yres+v->lower_margin+v->vsync_len); 194 hrate =
185 } 195 drate / (v->left_margin + v->xres + v->right_margin +
186 printf("\nmode \"%ux%u-%u\"\n", v->xres, v->yres, (int)(vrate+0.5)); 196 v->hsync_len);
197 vrate =
198 hrate / (v->upper_margin + v->yres + v->lower_margin +
199 v->vsync_len);
200 }
201 printf("\nmode \"%ux%u-%u\"\n", v->xres, v->yres, (int) (vrate + 0.5));
187#ifdef BB_FBSET_FANCY 202#ifdef BB_FBSET_FANCY
188 printf("\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n", drate/1e6, hrate/1e3, 203 printf("\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n", drate / 1e6,
189 vrate); 204 hrate / 1e3, vrate);
190#endif 205#endif
191 printf("\tgeometry %u %u %u %u %u\n", v->xres, v->yres, 206 printf("\tgeometry %u %u %u %u %u\n", v->xres, v->yres,
192 v->xres_virtual, v->yres_virtual, v->bits_per_pixel); 207 v->xres_virtual, v->yres_virtual, v->bits_per_pixel);
193#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0) 208#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
194 printf("\ttimings %u %u %u %u %u %u %u\n", v->pixclock, v->left_margin, 209 printf("\ttimings %u %u %u %u %u %u %u\n", v->pixclock, v->left_margin,
195 v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len, 210 v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len,
196 v->vsync_len); 211 v->vsync_len);
197 printf("\taccel %s\n", (v->accel_flags > 0 ? "true" : "false")); 212 printf("\taccel %s\n", (v->accel_flags > 0 ? "true" : "false"));
198#else 213#else
199 printf("\ttimings %lu %lu %lu %lu %lu %lu %lu\n", v->pixclock, v->left_margin, 214 printf("\ttimings %lu %lu %lu %lu %lu %lu %lu\n", v->pixclock,
200 v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len, 215 v->left_margin, v->right_margin, v->upper_margin,
201 v->vsync_len); 216 v->lower_margin, v->hsync_len, v->vsync_len);
202#endif 217#endif
203 printf("\trgba %u/%u,%u/%u,%u/%u,%u/%u\n", v->red.length, v->red.offset, 218 printf("\trgba %u/%u,%u/%u,%u/%u,%u/%u\n", v->red.length,
204 v->green.length, v->green.offset, v->blue.length, v->blue.offset, 219 v->red.offset, v->green.length, v->green.offset, v->blue.length,
205 v->transp.length, v->transp.offset); 220 v->blue.offset, v->transp.length, v->transp.offset);
206 printf("endmode\n"); 221 printf("endmode\n");
207} 222}
208 223
209static void fbset_usage(void) 224static void fbset_usage(void)
210{ 225{
211 int i; 226 int i;
227
212#ifndef STANDALONE 228#ifndef STANDALONE
213 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", BB_VER, BB_BT); 229 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
230 BB_VER, BB_BT);
214#endif 231#endif
215 fprintf(stderr, "Usage: fbset [options] [mode]\n"); 232 fprintf(stderr, "Usage: fbset [options] [mode]\n");
216 fprintf(stderr, "\tThe following options are recognized:\n"); 233 fprintf(stderr, "\tThe following options are recognized:\n");
217 for (i = 0; g_cmdoptions[i].name; i++) 234 for (i = 0; g_cmdoptions[i].name; i++)
218 fprintf(stderr, "\t\t%s\n", g_cmdoptions[i].name); 235 fprintf(stderr, "\t\t%s\n", g_cmdoptions[i].name);
219 exit(-1); 236 exit(-1);
220} 237}
221 238
222#ifdef STANDALONE 239#ifdef STANDALONE
223int main(int argc, char **argv) 240int main(int argc, char **argv)
224#else 241#else
225extern int fbset_main(int argc, char **argv) 242extern int fbset_main(int argc, char **argv)
226#endif 243#endif
227{ 244{
228 struct fb_var_screeninfo var, varset; 245 struct fb_var_screeninfo var, varset;
229 int fh, i; 246 int fh, i;
230 char *fbdev = DEFAULTFBDEV; 247 char *fbdev = DEFAULTFBDEV;
231 char *modefile = DEFAULTFBMODE; 248 char *modefile = DEFAULTFBMODE;
232 char *thisarg, *mode = NULL; 249 char *thisarg, *mode = NULL;
250
251 memset(&varset, 0xFF, sizeof(varset));
233 252
234 memset(&varset, 0xFF, sizeof(varset)); 253 /* parse cmd args.... why do they have to make things so difficult? */
235 254 argv++;
236 /* parse cmd args.... why do they have to make things so difficult? */ 255 argc--;
237 argv++; argc--; 256 for (; argc > 0 && (thisarg = *argv); argc--, argv++) {
238 for (; argc > 0 && (thisarg = *argv); argc--, argv++) { 257 for (i = 0; g_cmdoptions[i].name; i++) {
239 for (i = 0; g_cmdoptions[i].name; i++) { 258 if (!strcmp(thisarg, g_cmdoptions[i].name)) {
240 if (!strcmp(thisarg, g_cmdoptions[i].name)) { 259 if (argc - 1 < g_cmdoptions[i].param_count)
241 if (argc - 1 < g_cmdoptions[i].param_count) fbset_usage(); 260 fbset_usage();
242 switch (g_cmdoptions[i].code) { 261 switch (g_cmdoptions[i].code) {
243 case CMD_HELP: fbset_usage(); 262 case CMD_HELP:
244 case CMD_FB: fbdev = argv[1]; break; 263 fbset_usage();
245 case CMD_DB: modefile = argv[1]; break; 264 case CMD_FB:
246 case CMD_GEOMETRY: 265 fbdev = argv[1];
247 varset.xres = strtoul(argv[1],0,0); 266 break;
248 varset.yres = strtoul(argv[2],0,0); 267 case CMD_DB:
249 varset.xres_virtual = strtoul(argv[3],0,0); 268 modefile = argv[1];
250 varset.yres_virtual = strtoul(argv[4],0,0); 269 break;
251 varset.bits_per_pixel = strtoul(argv[5],0,0); 270 case CMD_GEOMETRY:
252 break; 271 varset.xres = strtoul(argv[1], 0, 0);
253 case CMD_TIMING: 272 varset.yres = strtoul(argv[2], 0, 0);
254 varset.pixclock = strtoul(argv[1],0,0); 273 varset.xres_virtual = strtoul(argv[3], 0, 0);
255 varset.left_margin = strtoul(argv[2],0,0); 274 varset.yres_virtual = strtoul(argv[4], 0, 0);
256 varset.right_margin = strtoul(argv[3],0,0); 275 varset.bits_per_pixel = strtoul(argv[5], 0, 0);
257 varset.upper_margin = strtoul(argv[4],0,0); 276 break;
258 varset.lower_margin = strtoul(argv[5],0,0); 277 case CMD_TIMING:
259 varset.hsync_len = strtoul(argv[6],0,0); 278 varset.pixclock = strtoul(argv[1], 0, 0);
260 varset.vsync_len = strtoul(argv[7],0,0); 279 varset.left_margin = strtoul(argv[2], 0, 0);
261 break; 280 varset.right_margin = strtoul(argv[3], 0, 0);
281 varset.upper_margin = strtoul(argv[4], 0, 0);
282 varset.lower_margin = strtoul(argv[5], 0, 0);
283 varset.hsync_len = strtoul(argv[6], 0, 0);
284 varset.vsync_len = strtoul(argv[7], 0, 0);
285 break;
262#ifdef BB_FBSET_FANCY 286#ifdef BB_FBSET_FANCY
263 case CMD_XRES: varset.xres = strtoul(argv[1],0,0); break; 287 case CMD_XRES:
264 case CMD_YRES: varset.yres = strtoul(argv[1],0,0); break; 288 varset.xres = strtoul(argv[1], 0, 0);
289 break;
290 case CMD_YRES:
291 varset.yres = strtoul(argv[1], 0, 0);
292 break;
265#endif 293#endif
294 }
295 argc -= g_cmdoptions[i].param_count;
296 argv += g_cmdoptions[i].param_count;
297 break;
298 }
299 }
300 if (!g_cmdoptions[i].name) {
301 if (argc == 1) {
302 mode = *argv;
303 g_options |= OPT_READMODE;
304 } else {
305 fbset_usage();
306 }
266 } 307 }
267 argc -= g_cmdoptions[i].param_count;
268 argv += g_cmdoptions[i].param_count;
269 break;
270 }
271 }
272 if (!g_cmdoptions[i].name) {
273 if (argc == 1) {
274 mode = *argv;
275 g_options |= OPT_READMODE;
276 } else {
277 fbset_usage();
278 }
279 } 308 }
280 }
281 309
282 if ((fh = open(fbdev, O_RDONLY)) < 0) PERROR("fbset(open)"); 310 if ((fh = open(fbdev, O_RDONLY)) < 0)
283 if (ioctl(fh, FBIOGET_VSCREENINFO, &var)) PERROR("fbset(ioctl)"); 311 PERROR("fbset(open)");
284 if (g_options & OPT_READMODE) { 312 if (ioctl(fh, FBIOGET_VSCREENINFO, &var))
285 if (!readmode(&var, modefile, mode)) { 313 PERROR("fbset(ioctl)");
286 fprintf(stderr, "Unknown video mode `%s'\n", mode); 314 if (g_options & OPT_READMODE) {
287 exit(1); 315 if (!readmode(&var, modefile, mode)) {
316 fprintf(stderr, "Unknown video mode `%s'\n", mode);
317 exit(1);
318 }
288 } 319 }
289 }
290 320
291 setmode(&var, &varset); 321 setmode(&var, &varset);
292 if (g_options & OPT_CHANGE) 322 if (g_options & OPT_CHANGE)
293 if (ioctl(fh, FBIOPUT_VSCREENINFO, &var)) PERROR("fbset(ioctl)"); 323 if (ioctl(fh, FBIOPUT_VSCREENINFO, &var))
294 showmode(&var); 324 PERROR("fbset(ioctl)");
295 close(fh); 325 showmode(&var);
296 326 close(fh);
297 return(TRUE);
298}
299 327
328 return (TRUE);
329}
diff --git a/util-linux/fdflush.c b/util-linux/fdflush.c
index a244e8def..0b154c8a6 100644
--- a/util-linux/fdflush.c
+++ b/util-linux/fdflush.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * Mini fdflush implementation for busybox 3 * Mini fdflush implementation for busybox
3 * 4 *
@@ -29,24 +30,25 @@
29 30
30extern int fdflush_main(int argc, char **argv) 31extern int fdflush_main(int argc, char **argv)
31{ 32{
32 int value; 33 int value;
33 int fd; 34 int fd;
34 if ( argc <= 1 || **(argv++) == '-' ) {
35 usage( "fdflush device\n");
36 }
37 35
38 fd = open(*argv, 0); 36 if (argc <= 1 || **(argv++) == '-') {
39 if ( fd < 0 ) { 37 usage("fdflush device\n");
40 perror(*argv); 38 }
41 exit(FALSE);
42 }
43 39
44 value = ioctl(fd, FDFLUSH, 0); 40 fd = open(*argv, 0);
45 close(fd); 41 if (fd < 0) {
42 perror(*argv);
43 exit(FALSE);
44 }
46 45
47 if ( value ) { 46 value = ioctl(fd, FDFLUSH, 0);
48 perror(*argv); 47 close(fd);
49 exit(FALSE); 48
50 } 49 if (value) {
51 exit (TRUE); 50 perror(*argv);
51 exit(FALSE);
52 }
53 exit(TRUE);
52} 54}
diff --git a/util-linux/fsck_minix.c b/util-linux/fsck_minix.c
index 09111c5dc..084c76d36 100644
--- a/util-linux/fsck_minix.c
+++ b/util-linux/fsck_minix.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * fsck.c - a file system consistency checker for Linux. 3 * fsck.c - a file system consistency checker for Linux.
3 * 4 *
@@ -96,7 +97,7 @@
96#include <termios.h> 97#include <termios.h>
97#include <mntent.h> 98#include <mntent.h>
98#include <sys/stat.h> 99#include <sys/stat.h>
99#include <sys/param.h> /* for PATH_MAX */ 100#include <sys/param.h> /* for PATH_MAX */
100 101
101#include <linux/fs.h> 102#include <linux/fs.h>
102#include <linux/minix_fs.h> 103#include <linux/minix_fs.h>
@@ -124,17 +125,17 @@
124 125
125#define BITS_PER_BLOCK (BLOCK_SIZE<<3) 126#define BITS_PER_BLOCK (BLOCK_SIZE<<3)
126 127
127static char * program_name = "fsck.minix"; 128static char *program_name = "fsck.minix";
128static char * program_version = "1.2 - 11/11/96"; 129static char *program_version = "1.2 - 11/11/96";
129static char * device_name = NULL; 130static char *device_name = NULL;
130static int IN; 131static int IN;
131static int repair=0, automatic=0, verbose=0, list=0, show=0, warn_mode=0, 132static int repair = 0, automatic = 0, verbose = 0, list = 0, show =
132 force=0; 133 0, warn_mode = 0, force = 0;
133static int directory=0, regular=0, blockdev=0, chardev=0, links=0, 134static int directory = 0, regular = 0, blockdev = 0, chardev = 0, links =
134 symlinks=0, total=0; 135 0, symlinks = 0, total = 0;
135 136
136static int changed = 0; /* flags if the filesystem has been changed */ 137static int changed = 0; /* flags if the filesystem has been changed */
137static int errors_uncorrected = 0; /* flag if some error was not corrected */ 138static int errors_uncorrected = 0; /* flag if some error was not corrected */
138static int dirsize = 16; 139static int dirsize = 16;
139static int namelen = 14; 140static int namelen = 14;
140static int version2 = 0; 141static int version2 = 0;
@@ -146,10 +147,12 @@ static int termios_set = 0;
146static int name_depth = 0; 147static int name_depth = 0;
147static char name_list[MAX_DEPTH][PATH_MAX + 1]; 148static char name_list[MAX_DEPTH][PATH_MAX + 1];
148 149
149static char * inode_buffer = NULL; 150static char *inode_buffer = NULL;
151
150#define Inode (((struct minix_inode *) inode_buffer)-1) 152#define Inode (((struct minix_inode *) inode_buffer)-1)
151#define Inode2 (((struct minix2_inode *) inode_buffer)-1) 153#define Inode2 (((struct minix2_inode *) inode_buffer)-1)
152static char super_block_buffer[BLOCK_SIZE]; 154static char super_block_buffer[BLOCK_SIZE];
155
153#define Super (*(struct minix_super_block *)super_block_buffer) 156#define Super (*(struct minix_super_block *)super_block_buffer)
154#define INODES ((unsigned long)Super.s_ninodes) 157#define INODES ((unsigned long)Super.s_ninodes)
155#ifdef HAVE_MINIX2 158#ifdef HAVE_MINIX2
@@ -168,8 +171,8 @@ static char super_block_buffer[BLOCK_SIZE];
168static char *inode_map; 171static char *inode_map;
169static char *zone_map; 172static char *zone_map;
170 173
171static unsigned char * inode_count = NULL; 174static unsigned char *inode_count = NULL;
172static unsigned char * zone_count = NULL; 175static unsigned char *zone_count = NULL;
173 176
174static void recursive_check(unsigned int ino); 177static void recursive_check(unsigned int ino);
175static void recursive_check2(unsigned int ino); 178static void recursive_check2(unsigned int ino);
@@ -191,22 +194,27 @@ static void leave(int status)
191 exit(status); 194 exit(status);
192} 195}
193 196
194static void show_usage(void) { 197static void show_usage(void)
195 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", BB_VER, BB_BT); 198{
199 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
200 BB_VER, BB_BT);
196 fprintf(stderr, "Usage: %s [-larvsmf] /dev/name\n\n", program_name); 201 fprintf(stderr, "Usage: %s [-larvsmf] /dev/name\n\n", program_name);
197 fprintf(stderr, "Performs a consistency check for MINIX filesystems.\n\n"); 202 fprintf(stderr,
203 "Performs a consistency check for MINIX filesystems.\n\n");
198 fprintf(stderr, "OPTIONS:\n"); 204 fprintf(stderr, "OPTIONS:\n");
199 fprintf(stderr, "\t-l\tLists all filenames\n"); 205 fprintf(stderr, "\t-l\tLists all filenames\n");
200 fprintf(stderr, "\t-r\tPerform interactive repairs\n"); 206 fprintf(stderr, "\t-r\tPerform interactive repairs\n");
201 fprintf(stderr, "\t-a\tPerform automatic repairs\n"); 207 fprintf(stderr, "\t-a\tPerform automatic repairs\n");
202 fprintf(stderr, "\t-v\tverbose\n"); 208 fprintf(stderr, "\t-v\tverbose\n");
203 fprintf(stderr, "\t-s\tOutputs super-block information\n"); 209 fprintf(stderr, "\t-s\tOutputs super-block information\n");
204 fprintf(stderr, "\t-m\tActivates MINIX-like \"mode not cleared\" warnings\n"); 210 fprintf(stderr,
211 "\t-m\tActivates MINIX-like \"mode not cleared\" warnings\n");
205 fprintf(stderr, "\t-f\tForce file system check.\n\n"); 212 fprintf(stderr, "\t-f\tForce file system check.\n\n");
206 leave(16); 213 leave(16);
207} 214}
208 215
209static void die(const char *str) { 216static void die(const char *str)
217{
210 fprintf(stderr, "%s: %s\n", program_name, str); 218 fprintf(stderr, "%s: %s\n", program_name, str);
211 leave(8); 219 leave(8);
212} 220}
@@ -217,15 +225,15 @@ static void die(const char *str) {
217 */ 225 */
218static void print_current_name(void) 226static void print_current_name(void)
219{ 227{
220 int i=0; 228 int i = 0;
221 229
222 while (i<name_depth) 230 while (i < name_depth)
223 printf("/%.*s",namelen,name_list[i++]); 231 printf("/%.*s", namelen, name_list[i++]);
224 if (i == 0) 232 if (i == 0)
225 printf ("/"); 233 printf("/");
226} 234}
227 235
228static int ask(const char * string, int def) 236static int ask(const char *string, int def)
229{ 237{
230 int c; 238 int c;
231 239
@@ -237,18 +245,18 @@ static int ask(const char * string, int def)
237 if (automatic) { 245 if (automatic) {
238 printf("\n"); 246 printf("\n");
239 if (!def) 247 if (!def)
240 errors_uncorrected = 1; 248 errors_uncorrected = 1;
241 return def; 249 return def;
242 } 250 }
243 printf(def?"%s (y/n)? ":"%s (n/y)? ",string); 251 printf(def ? "%s (y/n)? " : "%s (n/y)? ", string);
244 for (;;) { 252 for (;;) {
245 fflush(stdout); 253 fflush(stdout);
246 if ((c=getchar())==EOF) { 254 if ((c = getchar()) == EOF) {
247 if (!def) 255 if (!def)
248 errors_uncorrected = 1; 256 errors_uncorrected = 1;
249 return def; 257 return def;
250 } 258 }
251 c=toupper(c); 259 c = toupper(c);
252 if (c == 'Y') { 260 if (c == 'Y') {
253 def = 1; 261 def = 1;
254 break; 262 break;
@@ -263,7 +271,7 @@ static int ask(const char * string, int def)
263 else { 271 else {
264 printf("n\n"); 272 printf("n\n");
265 errors_uncorrected = 1; 273 errors_uncorrected = 1;
266 } 274 }
267 return def; 275 return def;
268} 276}
269 277
@@ -274,17 +282,17 @@ static int ask(const char * string, int def)
274 */ 282 */
275static void check_mount(void) 283static void check_mount(void)
276{ 284{
277 FILE * f; 285 FILE *f;
278 struct mntent * mnt; 286 struct mntent *mnt;
279 int cont; 287 int cont;
280 int fd; 288 int fd;
281 289
282 if ((f = setmntent (MOUNTED, "r")) == NULL) 290 if ((f = setmntent(MOUNTED, "r")) == NULL)
283 return; 291 return;
284 while ((mnt = getmntent (f)) != NULL) 292 while ((mnt = getmntent(f)) != NULL)
285 if (strcmp (device_name, mnt->mnt_fsname) == 0) 293 if (strcmp(device_name, mnt->mnt_fsname) == 0)
286 break; 294 break;
287 endmntent (f); 295 endmntent(f);
288 if (!mnt) 296 if (!mnt)
289 return; 297 return;
290 298
@@ -298,15 +306,15 @@ static void check_mount(void)
298 return; 306 return;
299 else 307 else
300 close(fd); 308 close(fd);
301 309
302 printf ("%s is mounted. ", device_name); 310 printf("%s is mounted. ", device_name);
303 if (isatty(0) && isatty(1)) 311 if (isatty(0) && isatty(1))
304 cont = ask("Do you really want to continue", 0); 312 cont = ask("Do you really want to continue", 0);
305 else 313 else
306 cont = 0; 314 cont = 0;
307 if (!cont) { 315 if (!cont) {
308 printf ("check aborted.\n"); 316 printf("check aborted.\n");
309 exit (0); 317 exit(0);
310 } 318 }
311 return; 319 return;
312} 320}
@@ -317,7 +325,7 @@ static void check_mount(void)
317 * if an error was corrected, and returns the zone (0 for no zone 325 * if an error was corrected, and returns the zone (0 for no zone
318 * or a bad zone-number). 326 * or a bad zone-number).
319 */ 327 */
320static int check_zone_nr(unsigned short * nr, int * corrected) 328static int check_zone_nr(unsigned short *nr, int *corrected)
321{ 329{
322 if (!*nr) 330 if (!*nr)
323 return 0; 331 return 0;
@@ -329,7 +337,7 @@ static int check_zone_nr(unsigned short * nr, int * corrected)
329 return *nr; 337 return *nr;
330 print_current_name(); 338 print_current_name();
331 printf("'."); 339 printf("'.");
332 if (ask("Remove block",1)) { 340 if (ask("Remove block", 1)) {
333 *nr = 0; 341 *nr = 0;
334 *corrected = 1; 342 *corrected = 1;
335 } 343 }
@@ -337,19 +345,19 @@ static int check_zone_nr(unsigned short * nr, int * corrected)
337} 345}
338 346
339#ifdef HAVE_MINIX2 347#ifdef HAVE_MINIX2
340static int check_zone_nr2 (unsigned int *nr, int *corrected) 348static int check_zone_nr2(unsigned int *nr, int *corrected)
341{ 349{
342 if (!*nr) 350 if (!*nr)
343 return 0; 351 return 0;
344 if (*nr < FIRSTZONE) 352 if (*nr < FIRSTZONE)
345 printf ("Zone nr < FIRSTZONE in file `"); 353 printf("Zone nr < FIRSTZONE in file `");
346 else if (*nr >= ZONES) 354 else if (*nr >= ZONES)
347 printf ("Zone nr >= ZONES in file `"); 355 printf("Zone nr >= ZONES in file `");
348 else 356 else
349 return *nr; 357 return *nr;
350 print_current_name (); 358 print_current_name();
351 printf ("'."); 359 printf("'.");
352 if (ask ("Remove block", 1)) { 360 if (ask("Remove block", 1)) {
353 *nr = 0; 361 *nr = 0;
354 *corrected = 1; 362 *corrected = 1;
355 } 363 }
@@ -360,23 +368,23 @@ static int check_zone_nr2 (unsigned int *nr, int *corrected)
360/* 368/*
361 * read-block reads block nr into the buffer at addr. 369 * read-block reads block nr into the buffer at addr.
362 */ 370 */
363static void read_block(unsigned int nr, char * addr) 371static void read_block(unsigned int nr, char *addr)
364{ 372{
365 if (!nr) { 373 if (!nr) {
366 memset(addr,0,BLOCK_SIZE); 374 memset(addr, 0, BLOCK_SIZE);
367 return; 375 return;
368 } 376 }
369 if (BLOCK_SIZE*nr != lseek(IN, BLOCK_SIZE*nr, SEEK_SET)) { 377 if (BLOCK_SIZE * nr != lseek(IN, BLOCK_SIZE * nr, SEEK_SET)) {
370 printf("Read error: unable to seek to block in file '"); 378 printf("Read error: unable to seek to block in file '");
371 print_current_name(); 379 print_current_name();
372 printf("'\n"); 380 printf("'\n");
373 memset(addr,0,BLOCK_SIZE); 381 memset(addr, 0, BLOCK_SIZE);
374 errors_uncorrected = 1; 382 errors_uncorrected = 1;
375 } else if (BLOCK_SIZE != read(IN, addr, BLOCK_SIZE)) { 383 } else if (BLOCK_SIZE != read(IN, addr, BLOCK_SIZE)) {
376 printf("Read error: bad block in file '"); 384 printf("Read error: bad block in file '");
377 print_current_name(); 385 print_current_name();
378 printf("'\n"); 386 printf("'\n");
379 memset(addr,0,BLOCK_SIZE); 387 memset(addr, 0, BLOCK_SIZE);
380 errors_uncorrected = 1; 388 errors_uncorrected = 1;
381 } 389 }
382} 390}
@@ -384,17 +392,17 @@ static void read_block(unsigned int nr, char * addr)
384/* 392/*
385 * write_block writes block nr to disk. 393 * write_block writes block nr to disk.
386 */ 394 */
387static void write_block(unsigned int nr, char * addr) 395static void write_block(unsigned int nr, char *addr)
388{ 396{
389 if (!nr) 397 if (!nr)
390 return; 398 return;
391 if (nr < FIRSTZONE || nr >= ZONES) { 399 if (nr < FIRSTZONE || nr >= ZONES) {
392 printf("Internal error: trying to write bad block\n" 400 printf("Internal error: trying to write bad block\n"
393 "Write request ignored\n"); 401 "Write request ignored\n");
394 errors_uncorrected = 1; 402 errors_uncorrected = 1;
395 return; 403 return;
396 } 404 }
397 if (BLOCK_SIZE*nr != lseek(IN, BLOCK_SIZE*nr, SEEK_SET)) 405 if (BLOCK_SIZE * nr != lseek(IN, BLOCK_SIZE * nr, SEEK_SET))
398 die("seek failed in write_block"); 406 die("seek failed in write_block");
399 if (BLOCK_SIZE != write(IN, addr, BLOCK_SIZE)) { 407 if (BLOCK_SIZE != write(IN, addr, BLOCK_SIZE)) {
400 printf("Write error: bad block in file '"); 408 printf("Write error: bad block in file '");
@@ -409,16 +417,16 @@ static void write_block(unsigned int nr, char * addr)
409 * It sets 'changed' if the inode has needed changing, and re-writes 417 * It sets 'changed' if the inode has needed changing, and re-writes
410 * any indirect blocks with errors. 418 * any indirect blocks with errors.
411 */ 419 */
412static int map_block(struct minix_inode * inode, unsigned int blknr) 420static int map_block(struct minix_inode *inode, unsigned int blknr)
413{ 421{
414 unsigned short ind[BLOCK_SIZE>>1]; 422 unsigned short ind[BLOCK_SIZE >> 1];
415 unsigned short dind[BLOCK_SIZE>>1]; 423 unsigned short dind[BLOCK_SIZE >> 1];
416 int blk_chg, block, result; 424 int blk_chg, block, result;
417 425
418 if (blknr<7) 426 if (blknr < 7)
419 return check_zone_nr(inode->i_zone + blknr, &changed); 427 return check_zone_nr(inode->i_zone + blknr, &changed);
420 blknr -= 7; 428 blknr -= 7;
421 if (blknr<512) { 429 if (blknr < 512) {
422 block = check_zone_nr(inode->i_zone + 7, &changed); 430 block = check_zone_nr(inode->i_zone + 7, &changed);
423 read_block(block, (char *) ind); 431 read_block(block, (char *) ind);
424 blk_chg = 0; 432 blk_chg = 0;
@@ -431,73 +439,73 @@ static int map_block(struct minix_inode * inode, unsigned int blknr)
431 block = check_zone_nr(inode->i_zone + 8, &changed); 439 block = check_zone_nr(inode->i_zone + 8, &changed);
432 read_block(block, (char *) dind); 440 read_block(block, (char *) dind);
433 blk_chg = 0; 441 blk_chg = 0;
434 result = check_zone_nr(dind + (blknr/512), &blk_chg); 442 result = check_zone_nr(dind + (blknr / 512), &blk_chg);
435 if (blk_chg) 443 if (blk_chg)
436 write_block(block, (char *) dind); 444 write_block(block, (char *) dind);
437 block = result; 445 block = result;
438 read_block(block, (char *) ind); 446 read_block(block, (char *) ind);
439 blk_chg = 0; 447 blk_chg = 0;
440 result = check_zone_nr(ind + (blknr%512), &blk_chg); 448 result = check_zone_nr(ind + (blknr % 512), &blk_chg);
441 if (blk_chg) 449 if (blk_chg)
442 write_block(block, (char *) ind); 450 write_block(block, (char *) ind);
443 return result; 451 return result;
444} 452}
445 453
446#ifdef HAVE_MINIX2 454#ifdef HAVE_MINIX2
447static int map_block2 (struct minix2_inode *inode, unsigned int blknr) 455static int map_block2(struct minix2_inode *inode, unsigned int blknr)
448{ 456{
449 unsigned int ind[BLOCK_SIZE >> 2]; 457 unsigned int ind[BLOCK_SIZE >> 2];
450 unsigned int dind[BLOCK_SIZE >> 2]; 458 unsigned int dind[BLOCK_SIZE >> 2];
451 unsigned int tind[BLOCK_SIZE >> 2]; 459 unsigned int tind[BLOCK_SIZE >> 2];
452 int blk_chg, block, result; 460 int blk_chg, block, result;
453 461
454 if (blknr < 7) 462 if (blknr < 7)
455 return check_zone_nr2 (inode->i_zone + blknr, &changed); 463 return check_zone_nr2(inode->i_zone + blknr, &changed);
456 blknr -= 7; 464 blknr -= 7;
457 if (blknr < 256) { 465 if (blknr < 256) {
458 block = check_zone_nr2 (inode->i_zone + 7, &changed); 466 block = check_zone_nr2(inode->i_zone + 7, &changed);
459 read_block (block, (char *) ind); 467 read_block(block, (char *) ind);
460 blk_chg = 0; 468 blk_chg = 0;
461 result = check_zone_nr2 (blknr + ind, &blk_chg); 469 result = check_zone_nr2(blknr + ind, &blk_chg);
462 if (blk_chg) 470 if (blk_chg)
463 write_block (block, (char *) ind); 471 write_block(block, (char *) ind);
464 return result; 472 return result;
465 } 473 }
466 blknr -= 256; 474 blknr -= 256;
467 if (blknr >= 256 * 256) { 475 if (blknr >= 256 * 256) {
468 block = check_zone_nr2 (inode->i_zone + 8, &changed); 476 block = check_zone_nr2(inode->i_zone + 8, &changed);
469 read_block (block, (char *) dind); 477 read_block(block, (char *) dind);
470 blk_chg = 0; 478 blk_chg = 0;
471 result = check_zone_nr2 (dind + blknr / 256, &blk_chg); 479 result = check_zone_nr2(dind + blknr / 256, &blk_chg);
472 if (blk_chg) 480 if (blk_chg)
473 write_block (block, (char *) dind); 481 write_block(block, (char *) dind);
474 block = result; 482 block = result;
475 read_block (block, (char *) ind); 483 read_block(block, (char *) ind);
476 blk_chg = 0; 484 blk_chg = 0;
477 result = check_zone_nr2 (ind + blknr % 256, &blk_chg); 485 result = check_zone_nr2(ind + blknr % 256, &blk_chg);
478 if (blk_chg) 486 if (blk_chg)
479 write_block (block, (char *) ind); 487 write_block(block, (char *) ind);
480 return result; 488 return result;
481 } 489 }
482 blknr -= 256 * 256; 490 blknr -= 256 * 256;
483 block = check_zone_nr2 (inode->i_zone + 9, &changed); 491 block = check_zone_nr2(inode->i_zone + 9, &changed);
484 read_block (block, (char *) tind); 492 read_block(block, (char *) tind);
485 blk_chg = 0; 493 blk_chg = 0;
486 result = check_zone_nr2 (tind + blknr / (256 * 256), &blk_chg); 494 result = check_zone_nr2(tind + blknr / (256 * 256), &blk_chg);
487 if (blk_chg) 495 if (blk_chg)
488 write_block (block, (char *) tind); 496 write_block(block, (char *) tind);
489 block = result; 497 block = result;
490 read_block (block, (char *) dind); 498 read_block(block, (char *) dind);
491 blk_chg = 0; 499 blk_chg = 0;
492 result = check_zone_nr2 (dind + (blknr / 256) % 256, &blk_chg); 500 result = check_zone_nr2(dind + (blknr / 256) % 256, &blk_chg);
493 if (blk_chg) 501 if (blk_chg)
494 write_block (block, (char *) dind); 502 write_block(block, (char *) dind);
495 block = result; 503 block = result;
496 read_block (block, (char *) ind); 504 read_block(block, (char *) ind);
497 blk_chg = 0; 505 blk_chg = 0;
498 result = check_zone_nr2 (ind + blknr % 256, &blk_chg); 506 result = check_zone_nr2(ind + blknr % 256, &blk_chg);
499 if (blk_chg) 507 if (blk_chg)
500 write_block (block, (char *) ind); 508 write_block(block, (char *) ind);
501 return result; 509 return result;
502} 510}
503#endif 511#endif
@@ -510,11 +518,11 @@ static void write_super_block(void)
510 * unconditionally set if we get this far. 518 * unconditionally set if we get this far.
511 */ 519 */
512 Super.s_state |= MINIX_VALID_FS; 520 Super.s_state |= MINIX_VALID_FS;
513 if ( errors_uncorrected ) 521 if (errors_uncorrected)
514 Super.s_state |= MINIX_ERROR_FS; 522 Super.s_state |= MINIX_ERROR_FS;
515 else 523 else
516 Super.s_state &= ~MINIX_ERROR_FS; 524 Super.s_state &= ~MINIX_ERROR_FS;
517 525
518 if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET)) 526 if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET))
519 die("seek failed in write_super_block"); 527 die("seek failed in write_super_block");
520 if (BLOCK_SIZE != write(IN, super_block_buffer, BLOCK_SIZE)) 528 if (BLOCK_SIZE != write(IN, super_block_buffer, BLOCK_SIZE))
@@ -527,15 +535,15 @@ static void write_tables(void)
527{ 535{
528 write_super_block(); 536 write_super_block();
529 537
530 if (IMAPS*BLOCK_SIZE != write(IN,inode_map,IMAPS*BLOCK_SIZE)) 538 if (IMAPS * BLOCK_SIZE != write(IN, inode_map, IMAPS * BLOCK_SIZE))
531 die("Unable to write inode map"); 539 die("Unable to write inode map");
532 if (ZMAPS*BLOCK_SIZE != write(IN,zone_map,ZMAPS*BLOCK_SIZE)) 540 if (ZMAPS * BLOCK_SIZE != write(IN, zone_map, ZMAPS * BLOCK_SIZE))
533 die("Unable to write zone map"); 541 die("Unable to write zone map");
534 if (INODE_BUFFER_SIZE != write(IN,inode_buffer,INODE_BUFFER_SIZE)) 542 if (INODE_BUFFER_SIZE != write(IN, inode_buffer, INODE_BUFFER_SIZE))
535 die("Unable to write inodes"); 543 die("Unable to write inodes");
536} 544}
537 545
538static void get_dirsize (void) 546static void get_dirsize(void)
539{ 547{
540 int block; 548 int block;
541 char blk[BLOCK_SIZE]; 549 char blk[BLOCK_SIZE];
@@ -547,9 +555,9 @@ static void get_dirsize (void)
547 else 555 else
548#endif 556#endif
549 block = Inode[ROOT_INO].i_zone[0]; 557 block = Inode[ROOT_INO].i_zone[0];
550 read_block (block, blk); 558 read_block(block, blk);
551 for (size = 16; size < BLOCK_SIZE; size <<= 1) { 559 for (size = 16; size < BLOCK_SIZE; size <<= 1) {
552 if (strcmp (blk + size + 2, "..") == 0) { 560 if (strcmp(blk + size + 2, "..") == 0) {
553 dirsize = size; 561 dirsize = size;
554 namelen = size - 2; 562 namelen = size - 2;
555 return; 563 return;
@@ -600,8 +608,8 @@ static void read_tables(void)
600 zone_map = malloc(ZMAPS * BLOCK_SIZE); 608 zone_map = malloc(ZMAPS * BLOCK_SIZE);
601 if (!inode_map) 609 if (!inode_map)
602 die("Unable to allocate buffer for zone map"); 610 die("Unable to allocate buffer for zone map");
603 memset(inode_map,0,sizeof(inode_map)); 611 memset(inode_map, 0, sizeof(inode_map));
604 memset(zone_map,0,sizeof(zone_map)); 612 memset(zone_map, 0, sizeof(zone_map));
605 inode_buffer = malloc(INODE_BUFFER_SIZE); 613 inode_buffer = malloc(INODE_BUFFER_SIZE);
606 if (!inode_buffer) 614 if (!inode_buffer)
607 die("Unable to allocate buffer for inodes"); 615 die("Unable to allocate buffer for inodes");
@@ -611,31 +619,31 @@ static void read_tables(void)
611 zone_count = malloc(ZONES); 619 zone_count = malloc(ZONES);
612 if (!zone_count) 620 if (!zone_count)
613 die("Unable to allocate buffer for zone count"); 621 die("Unable to allocate buffer for zone count");
614 if (IMAPS*BLOCK_SIZE != read(IN,inode_map,IMAPS*BLOCK_SIZE)) 622 if (IMAPS * BLOCK_SIZE != read(IN, inode_map, IMAPS * BLOCK_SIZE))
615 die("Unable to read inode map"); 623 die("Unable to read inode map");
616 if (ZMAPS*BLOCK_SIZE != read(IN,zone_map,ZMAPS*BLOCK_SIZE)) 624 if (ZMAPS * BLOCK_SIZE != read(IN, zone_map, ZMAPS * BLOCK_SIZE))
617 die("Unable to read zone map"); 625 die("Unable to read zone map");
618 if (INODE_BUFFER_SIZE != read(IN,inode_buffer,INODE_BUFFER_SIZE)) 626 if (INODE_BUFFER_SIZE != read(IN, inode_buffer, INODE_BUFFER_SIZE))
619 die("Unable to read inodes"); 627 die("Unable to read inodes");
620 if (NORM_FIRSTZONE != FIRSTZONE) { 628 if (NORM_FIRSTZONE != FIRSTZONE) {
621 printf("Warning: Firstzone != Norm_firstzone\n"); 629 printf("Warning: Firstzone != Norm_firstzone\n");
622 errors_uncorrected = 1; 630 errors_uncorrected = 1;
623 } 631 }
624 get_dirsize (); 632 get_dirsize();
625 if (show) { 633 if (show) {
626 printf("%ld inodes\n",INODES); 634 printf("%ld inodes\n", INODES);
627 printf("%ld blocks\n",ZONES); 635 printf("%ld blocks\n", ZONES);
628 printf("Firstdatazone=%ld (%ld)\n",FIRSTZONE,NORM_FIRSTZONE); 636 printf("Firstdatazone=%ld (%ld)\n", FIRSTZONE, NORM_FIRSTZONE);
629 printf("Zonesize=%d\n",BLOCK_SIZE<<ZONESIZE); 637 printf("Zonesize=%d\n", BLOCK_SIZE << ZONESIZE);
630 printf("Maxsize=%ld\n",MAXSIZE); 638 printf("Maxsize=%ld\n", MAXSIZE);
631 printf("Filesystem state=%d\n", Super.s_state); 639 printf("Filesystem state=%d\n", Super.s_state);
632 printf("namelen=%d\n\n",namelen); 640 printf("namelen=%d\n\n", namelen);
633 } 641 }
634} 642}
635 643
636struct minix_inode * get_inode(unsigned int nr) 644struct minix_inode *get_inode(unsigned int nr)
637{ 645{
638 struct minix_inode * inode; 646 struct minix_inode *inode;
639 647
640 if (!nr || nr > INODES) 648 if (!nr || nr > INODES)
641 return NULL; 649 return NULL;
@@ -643,15 +651,14 @@ struct minix_inode * get_inode(unsigned int nr)
643 inode = Inode + nr; 651 inode = Inode + nr;
644 if (!inode_count[nr]) { 652 if (!inode_count[nr]) {
645 if (!inode_in_use(nr)) { 653 if (!inode_in_use(nr)) {
646 printf("Inode %d marked not used, but used for file '", 654 printf("Inode %d marked not used, but used for file '", nr);
647 nr);
648 print_current_name(); 655 print_current_name();
649 printf("'\n"); 656 printf("'\n");
650 if (repair) { 657 if (repair) {
651 if (ask("Mark in use",1)) 658 if (ask("Mark in use", 1))
652 mark_inode(nr); 659 mark_inode(nr);
653 } else { 660 } else {
654 errors_uncorrected = 1; 661 errors_uncorrected = 1;
655 } 662 }
656 } 663 }
657 if (S_ISDIR(inode->i_mode)) 664 if (S_ISDIR(inode->i_mode))
@@ -664,14 +671,12 @@ struct minix_inode * get_inode(unsigned int nr)
664 blockdev++; 671 blockdev++;
665 else if (S_ISLNK(inode->i_mode)) 672 else if (S_ISLNK(inode->i_mode))
666 symlinks++; 673 symlinks++;
667 else if (S_ISSOCK(inode->i_mode)) 674 else if (S_ISSOCK(inode->i_mode));
668 ; 675 else if (S_ISFIFO(inode->i_mode));
669 else if (S_ISFIFO(inode->i_mode))
670 ;
671 else { 676 else {
672 print_current_name(); 677 print_current_name();
673 printf(" has mode %05o\n",inode->i_mode); 678 printf(" has mode %05o\n", inode->i_mode);
674 } 679 }
675 680
676 } else 681 } else
677 links++; 682 links++;
@@ -684,8 +689,7 @@ struct minix_inode * get_inode(unsigned int nr)
684} 689}
685 690
686#ifdef HAVE_MINIX2 691#ifdef HAVE_MINIX2
687struct minix2_inode * 692struct minix2_inode *get_inode2(unsigned int nr)
688get_inode2 (unsigned int nr)
689{ 693{
690 struct minix2_inode *inode; 694 struct minix2_inode *inode;
691 695
@@ -694,37 +698,37 @@ get_inode2 (unsigned int nr)
694 total++; 698 total++;
695 inode = Inode2 + nr; 699 inode = Inode2 + nr;
696 if (!inode_count[nr]) { 700 if (!inode_count[nr]) {
697 if (!inode_in_use (nr)) { 701 if (!inode_in_use(nr)) {
698 printf ("Inode %d marked not used, but used for file '", nr); 702 printf("Inode %d marked not used, but used for file '", nr);
699 print_current_name (); 703 print_current_name();
700 printf ("'\n"); 704 printf("'\n");
701 if (repair) { 705 if (repair) {
702 if (ask ("Mark in use", 1)) 706 if (ask("Mark in use", 1))
703 mark_inode (nr); 707 mark_inode(nr);
704 else 708 else
705 errors_uncorrected = 1; 709 errors_uncorrected = 1;
706 } 710 }
707 } 711 }
708 if (S_ISDIR (inode->i_mode)) 712 if (S_ISDIR(inode->i_mode))
709 directory++; 713 directory++;
710 else if (S_ISREG (inode->i_mode)) 714 else if (S_ISREG(inode->i_mode))
711 regular++; 715 regular++;
712 else if (S_ISCHR (inode->i_mode)) 716 else if (S_ISCHR(inode->i_mode))
713 chardev++; 717 chardev++;
714 else if (S_ISBLK (inode->i_mode)) 718 else if (S_ISBLK(inode->i_mode))
715 blockdev++; 719 blockdev++;
716 else if (S_ISLNK (inode->i_mode)) 720 else if (S_ISLNK(inode->i_mode))
717 symlinks++; 721 symlinks++;
718 else if (S_ISSOCK (inode->i_mode)); 722 else if (S_ISSOCK(inode->i_mode));
719 else if (S_ISFIFO (inode->i_mode)); 723 else if (S_ISFIFO(inode->i_mode));
720 else { 724 else {
721 print_current_name (); 725 print_current_name();
722 printf (" has mode %05o\n", inode->i_mode); 726 printf(" has mode %05o\n", inode->i_mode);
723 } 727 }
724 } else 728 } else
725 links++; 729 links++;
726 if (!++inode_count[nr]) { 730 if (!++inode_count[nr]) {
727 printf ("Warning: inode count too big.\n"); 731 printf("Warning: inode count too big.\n");
728 inode_count[nr]--; 732 inode_count[nr]--;
729 errors_uncorrected = 1; 733 errors_uncorrected = 1;
730 } 734 }
@@ -734,23 +738,23 @@ get_inode2 (unsigned int nr)
734 738
735static void check_root(void) 739static void check_root(void)
736{ 740{
737 struct minix_inode * inode = Inode + ROOT_INO; 741 struct minix_inode *inode = Inode + ROOT_INO;
738 742
739 if (!inode || !S_ISDIR(inode->i_mode)) 743 if (!inode || !S_ISDIR(inode->i_mode))
740 die("root inode isn't a directory"); 744 die("root inode isn't a directory");
741} 745}
742 746
743#ifdef HAVE_MINIX2 747#ifdef HAVE_MINIX2
744static void check_root2 (void) 748static void check_root2(void)
745{ 749{
746 struct minix2_inode *inode = Inode2 + ROOT_INO; 750 struct minix2_inode *inode = Inode2 + ROOT_INO;
747 751
748 if (!inode || !S_ISDIR (inode->i_mode)) 752 if (!inode || !S_ISDIR(inode->i_mode))
749 die ("root inode isn't a directory"); 753 die("root inode isn't a directory");
750} 754}
751#endif 755#endif
752 756
753static int add_zone(unsigned short * znr, int * corrected) 757static int add_zone(unsigned short *znr, int *corrected)
754{ 758{
755 int result; 759 int result;
756 int block; 760 int block;
@@ -763,7 +767,7 @@ static int add_zone(unsigned short * znr, int * corrected)
763 printf("Block has been used before. Now in file `"); 767 printf("Block has been used before. Now in file `");
764 print_current_name(); 768 print_current_name();
765 printf("'."); 769 printf("'.");
766 if (ask("Clear",1)) { 770 if (ask("Clear", 1)) {
767 *znr = 0; 771 *znr = 0;
768 block = 0; 772 block = 0;
769 *corrected = 1; 773 *corrected = 1;
@@ -772,10 +776,10 @@ static int add_zone(unsigned short * znr, int * corrected)
772 if (!block) 776 if (!block)
773 return 0; 777 return 0;
774 if (!zone_in_use(block)) { 778 if (!zone_in_use(block)) {
775 printf("Block %d in file `",block); 779 printf("Block %d in file `", block);
776 print_current_name(); 780 print_current_name();
777 printf("' is marked not in use."); 781 printf("' is marked not in use.");
778 if (ask("Correct",1)) 782 if (ask("Correct", 1))
779 mark_zone(block); 783 mark_zone(block);
780 } 784 }
781 if (!++zone_count[block]) 785 if (!++zone_count[block])
@@ -784,20 +788,20 @@ static int add_zone(unsigned short * znr, int * corrected)
784} 788}
785 789
786#ifdef HAVE_MINIX2 790#ifdef HAVE_MINIX2
787static int add_zone2 (unsigned int *znr, int *corrected) 791static int add_zone2(unsigned int *znr, int *corrected)
788{ 792{
789 int result; 793 int result;
790 int block; 794 int block;
791 795
792 result = 0; 796 result = 0;
793 block = check_zone_nr2 (znr, corrected); 797 block = check_zone_nr2(znr, corrected);
794 if (!block) 798 if (!block)
795 return 0; 799 return 0;
796 if (zone_count[block]) { 800 if (zone_count[block]) {
797 printf ("Block has been used before. Now in file `"); 801 printf("Block has been used before. Now in file `");
798 print_current_name (); 802 print_current_name();
799 printf ("'."); 803 printf("'.");
800 if (ask ("Clear", 1)) { 804 if (ask("Clear", 1)) {
801 *znr = 0; 805 *znr = 0;
802 block = 0; 806 block = 0;
803 *corrected = 1; 807 *corrected = 1;
@@ -805,12 +809,12 @@ static int add_zone2 (unsigned int *znr, int *corrected)
805 } 809 }
806 if (!block) 810 if (!block)
807 return 0; 811 return 0;
808 if (!zone_in_use (block)) { 812 if (!zone_in_use(block)) {
809 printf ("Block %d in file `", block); 813 printf("Block %d in file `", block);
810 print_current_name (); 814 print_current_name();
811 printf ("' is marked not in use."); 815 printf("' is marked not in use.");
812 if (ask ("Correct", 1)) 816 if (ask("Correct", 1))
813 mark_zone (block); 817 mark_zone(block);
814 } 818 }
815 if (!++zone_count[block]) 819 if (!++zone_count[block])
816 zone_count[block]--; 820 zone_count[block]--;
@@ -818,182 +822,179 @@ static int add_zone2 (unsigned int *znr, int *corrected)
818} 822}
819#endif 823#endif
820 824
821static void add_zone_ind(unsigned short * znr, int * corrected) 825static void add_zone_ind(unsigned short *znr, int *corrected)
822{ 826{
823 static char blk[BLOCK_SIZE]; 827 static char blk[BLOCK_SIZE];
824 int i, chg_blk=0; 828 int i, chg_blk = 0;
825 int block; 829 int block;
826 830
827 block = add_zone(znr, corrected); 831 block = add_zone(znr, corrected);
828 if (!block) 832 if (!block)
829 return; 833 return;
830 read_block(block, blk); 834 read_block(block, blk);
831 for (i=0 ; i < (BLOCK_SIZE>>1) ; i++) 835 for (i = 0; i < (BLOCK_SIZE >> 1); i++)
832 add_zone(i + (unsigned short *) blk, &chg_blk); 836 add_zone(i + (unsigned short *) blk, &chg_blk);
833 if (chg_blk) 837 if (chg_blk)
834 write_block(block, blk); 838 write_block(block, blk);
835} 839}
836 840
837#ifdef HAVE_MINIX2 841#ifdef HAVE_MINIX2
838static void 842static void add_zone_ind2(unsigned int *znr, int *corrected)
839add_zone_ind2 (unsigned int *znr, int *corrected)
840{ 843{
841 static char blk[BLOCK_SIZE]; 844 static char blk[BLOCK_SIZE];
842 int i, chg_blk = 0; 845 int i, chg_blk = 0;
843 int block; 846 int block;
844 847
845 block = add_zone2 (znr, corrected); 848 block = add_zone2(znr, corrected);
846 if (!block) 849 if (!block)
847 return; 850 return;
848 read_block (block, blk); 851 read_block(block, blk);
849 for (i = 0; i < BLOCK_SIZE >> 2; i++) 852 for (i = 0; i < BLOCK_SIZE >> 2; i++)
850 add_zone2 (i + (unsigned int *) blk, &chg_blk); 853 add_zone2(i + (unsigned int *) blk, &chg_blk);
851 if (chg_blk) 854 if (chg_blk)
852 write_block (block, blk); 855 write_block(block, blk);
853} 856}
854#endif 857#endif
855 858
856static void add_zone_dind(unsigned short * znr, int * corrected) 859static void add_zone_dind(unsigned short *znr, int *corrected)
857{ 860{
858 static char blk[BLOCK_SIZE]; 861 static char blk[BLOCK_SIZE];
859 int i, blk_chg=0; 862 int i, blk_chg = 0;
860 int block; 863 int block;
861 864
862 block = add_zone(znr, corrected); 865 block = add_zone(znr, corrected);
863 if (!block) 866 if (!block)
864 return; 867 return;
865 read_block(block, blk); 868 read_block(block, blk);
866 for (i=0 ; i < (BLOCK_SIZE>>1) ; i++) 869 for (i = 0; i < (BLOCK_SIZE >> 1); i++)
867 add_zone_ind(i + (unsigned short *) blk, &blk_chg); 870 add_zone_ind(i + (unsigned short *) blk, &blk_chg);
868 if (blk_chg) 871 if (blk_chg)
869 write_block(block, blk); 872 write_block(block, blk);
870} 873}
871 874
872#ifdef HAVE_MINIX2 875#ifdef HAVE_MINIX2
873static void 876static void add_zone_dind2(unsigned int *znr, int *corrected)
874add_zone_dind2 (unsigned int *znr, int *corrected)
875{ 877{
876 static char blk[BLOCK_SIZE]; 878 static char blk[BLOCK_SIZE];
877 int i, blk_chg = 0; 879 int i, blk_chg = 0;
878 int block; 880 int block;
879 881
880 block = add_zone2 (znr, corrected); 882 block = add_zone2(znr, corrected);
881 if (!block) 883 if (!block)
882 return; 884 return;
883 read_block (block, blk); 885 read_block(block, blk);
884 for (i = 0; i < BLOCK_SIZE >> 2; i++) 886 for (i = 0; i < BLOCK_SIZE >> 2; i++)
885 add_zone_ind2 (i + (unsigned int *) blk, &blk_chg); 887 add_zone_ind2(i + (unsigned int *) blk, &blk_chg);
886 if (blk_chg) 888 if (blk_chg)
887 write_block (block, blk); 889 write_block(block, blk);
888} 890}
889 891
890static void 892static void add_zone_tind2(unsigned int *znr, int *corrected)
891add_zone_tind2 (unsigned int *znr, int *corrected)
892{ 893{
893 static char blk[BLOCK_SIZE]; 894 static char blk[BLOCK_SIZE];
894 int i, blk_chg = 0; 895 int i, blk_chg = 0;
895 int block; 896 int block;
896 897
897 block = add_zone2 (znr, corrected); 898 block = add_zone2(znr, corrected);
898 if (!block) 899 if (!block)
899 return; 900 return;
900 read_block (block, blk); 901 read_block(block, blk);
901 for (i = 0; i < BLOCK_SIZE >> 2; i++) 902 for (i = 0; i < BLOCK_SIZE >> 2; i++)
902 add_zone_dind2 (i + (unsigned int *) blk, &blk_chg); 903 add_zone_dind2(i + (unsigned int *) blk, &blk_chg);
903 if (blk_chg) 904 if (blk_chg)
904 write_block (block, blk); 905 write_block(block, blk);
905} 906}
906#endif 907#endif
907 908
908static void check_zones(unsigned int i) 909static void check_zones(unsigned int i)
909{ 910{
910 struct minix_inode * inode; 911 struct minix_inode *inode;
911 912
912 if (!i || i > INODES) 913 if (!i || i > INODES)
913 return; 914 return;
914 if (inode_count[i] > 1) /* have we counted this file already? */ 915 if (inode_count[i] > 1) /* have we counted this file already? */
915 return; 916 return;
916 inode = Inode + i; 917 inode = Inode + i;
917 if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 918 if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
918 !S_ISLNK(inode->i_mode)) 919 !S_ISLNK(inode->i_mode)) return;
919 return; 920 for (i = 0; i < 7; i++)
920 for (i=0 ; i<7 ; i++)
921 add_zone(i + inode->i_zone, &changed); 921 add_zone(i + inode->i_zone, &changed);
922 add_zone_ind(7 + inode->i_zone, &changed); 922 add_zone_ind(7 + inode->i_zone, &changed);
923 add_zone_dind(8 + inode->i_zone, &changed); 923 add_zone_dind(8 + inode->i_zone, &changed);
924} 924}
925 925
926#ifdef HAVE_MINIX2 926#ifdef HAVE_MINIX2
927static void 927static void check_zones2(unsigned int i)
928check_zones2 (unsigned int i)
929{ 928{
930 struct minix2_inode *inode; 929 struct minix2_inode *inode;
931 930
932 if (!i || i > INODES) 931 if (!i || i > INODES)
933 return; 932 return;
934 if (inode_count[i] > 1) /* have we counted this file already? */ 933 if (inode_count[i] > 1) /* have we counted this file already? */
935 return; 934 return;
936 inode = Inode2 + i; 935 inode = Inode2 + i;
937 if (!S_ISDIR (inode->i_mode) && !S_ISREG (inode->i_mode) 936 if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode)
938 && !S_ISLNK (inode->i_mode)) 937 && !S_ISLNK(inode->i_mode))
939 return; 938 return;
940 for (i = 0; i < 7; i++) 939 for (i = 0; i < 7; i++)
941 add_zone2 (i + inode->i_zone, &changed); 940 add_zone2(i + inode->i_zone, &changed);
942 add_zone_ind2 (7 + inode->i_zone, &changed); 941 add_zone_ind2(7 + inode->i_zone, &changed);
943 add_zone_dind2 (8 + inode->i_zone, &changed); 942 add_zone_dind2(8 + inode->i_zone, &changed);
944 add_zone_tind2 (9 + inode->i_zone, &changed); 943 add_zone_tind2(9 + inode->i_zone, &changed);
945} 944}
946#endif 945#endif
947 946
948static void check_file(struct minix_inode * dir, unsigned int offset) 947static void check_file(struct minix_inode *dir, unsigned int offset)
949{ 948{
950 static char blk[BLOCK_SIZE]; 949 static char blk[BLOCK_SIZE];
951 struct minix_inode * inode; 950 struct minix_inode *inode;
952 int ino; 951 int ino;
953 char * name; 952 char *name;
954 int block; 953 int block;
955 954
956 block = map_block(dir,offset/BLOCK_SIZE); 955 block = map_block(dir, offset / BLOCK_SIZE);
957 read_block(block, blk); 956 read_block(block, blk);
958 name = blk + (offset % BLOCK_SIZE) + 2; 957 name = blk + (offset % BLOCK_SIZE) + 2;
959 ino = * (unsigned short *) (name-2); 958 ino = *(unsigned short *) (name - 2);
960 if (ino > INODES) { 959 if (ino > INODES) {
961 print_current_name(); 960 print_current_name();
962 printf(" contains a bad inode number for file '"); 961 printf(" contains a bad inode number for file '");
963 printf("%.*s'.",namelen,name); 962 printf("%.*s'.", namelen, name);
964 if (ask(" Remove",1)) { 963 if (ask(" Remove", 1)) {
965 *(unsigned short *)(name-2) = 0; 964 *(unsigned short *) (name - 2) = 0;
966 write_block(block, blk); 965 write_block(block, blk);
967 } 966 }
968 ino = 0; 967 ino = 0;
969 } 968 }
970 if (name_depth < MAX_DEPTH) 969 if (name_depth < MAX_DEPTH)
971 strncpy (name_list[name_depth], name, namelen); 970 strncpy(name_list[name_depth], name, namelen);
972 name_depth++; 971 name_depth++;
973 inode = get_inode(ino); 972 inode = get_inode(ino);
974 name_depth--; 973 name_depth--;
975 if (!offset) { 974 if (!offset) {
976 if (!inode || strcmp(".",name)) { 975 if (!inode || strcmp(".", name)) {
977 print_current_name(); 976 print_current_name();
978 printf(": bad directory: '.' isn't first\n"); 977 printf(": bad directory: '.' isn't first\n");
979 errors_uncorrected = 1; 978 errors_uncorrected = 1;
980 } else return; 979 } else
980 return;
981 } 981 }
982 if (offset == dirsize) { 982 if (offset == dirsize) {
983 if (!inode || strcmp("..",name)) { 983 if (!inode || strcmp("..", name)) {
984 print_current_name(); 984 print_current_name();
985 printf(": bad directory: '..' isn't second\n"); 985 printf(": bad directory: '..' isn't second\n");
986 errors_uncorrected = 1; 986 errors_uncorrected = 1;
987 } else return; 987 } else
988 return;
988 } 989 }
989 if (!inode) 990 if (!inode)
990 return; 991 return;
991 if (name_depth < MAX_DEPTH) 992 if (name_depth < MAX_DEPTH)
992 strncpy(name_list[name_depth],name,namelen); 993 strncpy(name_list[name_depth], name, namelen);
993 name_depth++; 994 name_depth++;
994 if (list) { 995 if (list) {
995 if (verbose) 996 if (verbose)
996 printf("%6d %07o %3d ",ino,inode->i_mode,inode->i_nlinks); 997 printf("%6d %07o %3d ", ino, inode->i_mode, inode->i_nlinks);
997 print_current_name(); 998 print_current_name();
998 if (S_ISDIR(inode->i_mode)) 999 if (S_ISDIR(inode->i_mode))
999 printf(":\n"); 1000 printf(":\n");
@@ -1008,8 +1009,7 @@ static void check_file(struct minix_inode * dir, unsigned int offset)
1008} 1009}
1009 1010
1010#ifdef HAVE_MINIX2 1011#ifdef HAVE_MINIX2
1011static void 1012static void check_file2(struct minix2_inode *dir, unsigned int offset)
1012check_file2 (struct minix2_inode *dir, unsigned int offset)
1013{ 1013{
1014 static char blk[BLOCK_SIZE]; 1014 static char blk[BLOCK_SIZE];
1015 struct minix2_inode *inode; 1015 struct minix2_inode *inode;
@@ -1017,37 +1017,37 @@ check_file2 (struct minix2_inode *dir, unsigned int offset)
1017 char *name; 1017 char *name;
1018 int block; 1018 int block;
1019 1019
1020 block = map_block2 (dir, offset / BLOCK_SIZE); 1020 block = map_block2(dir, offset / BLOCK_SIZE);
1021 read_block (block, blk); 1021 read_block(block, blk);
1022 name = blk + (offset % BLOCK_SIZE) + 2; 1022 name = blk + (offset % BLOCK_SIZE) + 2;
1023 ino = *(unsigned short *) (name - 2); 1023 ino = *(unsigned short *) (name - 2);
1024 if (ino > INODES) { 1024 if (ino > INODES) {
1025 print_current_name (); 1025 print_current_name();
1026 printf (" contains a bad inode number for file '"); 1026 printf(" contains a bad inode number for file '");
1027 printf ("%.*s'.", namelen, name); 1027 printf("%.*s'.", namelen, name);
1028 if (ask (" Remove", 1)) { 1028 if (ask(" Remove", 1)) {
1029 *(unsigned short *) (name - 2) = 0; 1029 *(unsigned short *) (name - 2) = 0;
1030 write_block (block, blk); 1030 write_block(block, blk);
1031 } 1031 }
1032 ino = 0; 1032 ino = 0;
1033 } 1033 }
1034 if (name_depth < MAX_DEPTH) 1034 if (name_depth < MAX_DEPTH)
1035 strncpy (name_list[name_depth], name, namelen); 1035 strncpy(name_list[name_depth], name, namelen);
1036 name_depth++; 1036 name_depth++;
1037 inode = get_inode2 (ino); 1037 inode = get_inode2(ino);
1038 name_depth--; 1038 name_depth--;
1039 if (!offset) { 1039 if (!offset) {
1040 if (!inode || strcmp (".", name)) { 1040 if (!inode || strcmp(".", name)) {
1041 print_current_name (); 1041 print_current_name();
1042 printf (": bad directory: '.' isn't first\n"); 1042 printf(": bad directory: '.' isn't first\n");
1043 errors_uncorrected = 1; 1043 errors_uncorrected = 1;
1044 } else 1044 } else
1045 return; 1045 return;
1046 } 1046 }
1047 if (offset == dirsize) { 1047 if (offset == dirsize) {
1048 if (!inode || strcmp ("..", name)) { 1048 if (!inode || strcmp("..", name)) {
1049 print_current_name (); 1049 print_current_name();
1050 printf (": bad directory: '..' isn't second\n"); 1050 printf(": bad directory: '..' isn't second\n");
1051 errors_uncorrected = 1; 1051 errors_uncorrected = 1;
1052 } else 1052 } else
1053 return; 1053 return;
@@ -1057,16 +1057,16 @@ check_file2 (struct minix2_inode *dir, unsigned int offset)
1057 name_depth++; 1057 name_depth++;
1058 if (list) { 1058 if (list) {
1059 if (verbose) 1059 if (verbose)
1060 printf ("%6d %07o %3d ", ino, inode->i_mode, inode->i_nlinks); 1060 printf("%6d %07o %3d ", ino, inode->i_mode, inode->i_nlinks);
1061 print_current_name (); 1061 print_current_name();
1062 if (S_ISDIR (inode->i_mode)) 1062 if (S_ISDIR(inode->i_mode))
1063 printf (":\n"); 1063 printf(":\n");
1064 else 1064 else
1065 printf ("\n"); 1065 printf("\n");
1066 } 1066 }
1067 check_zones2 (ino); 1067 check_zones2(ino);
1068 if (inode && S_ISDIR (inode->i_mode)) 1068 if (inode && S_ISDIR(inode->i_mode))
1069 recursive_check2 (ino); 1069 recursive_check2(ino);
1070 name_depth--; 1070 name_depth--;
1071 return; 1071 return;
1072} 1072}
@@ -1074,7 +1074,7 @@ check_file2 (struct minix2_inode *dir, unsigned int offset)
1074 1074
1075static void recursive_check(unsigned int ino) 1075static void recursive_check(unsigned int ino)
1076{ 1076{
1077 struct minix_inode * dir; 1077 struct minix_inode *dir;
1078 unsigned int offset; 1078 unsigned int offset;
1079 1079
1080 dir = Inode + ino; 1080 dir = Inode + ino;
@@ -1085,27 +1085,26 @@ static void recursive_check(unsigned int ino)
1085 printf(": bad directory: size<32"); 1085 printf(": bad directory: size<32");
1086 errors_uncorrected = 1; 1086 errors_uncorrected = 1;
1087 } 1087 }
1088 for (offset = 0 ; offset < dir->i_size ; offset += dirsize) 1088 for (offset = 0; offset < dir->i_size; offset += dirsize)
1089 check_file(dir,offset); 1089 check_file(dir, offset);
1090} 1090}
1091 1091
1092#ifdef HAVE_MINIX2 1092#ifdef HAVE_MINIX2
1093static void 1093static void recursive_check2(unsigned int ino)
1094recursive_check2 (unsigned int ino)
1095{ 1094{
1096 struct minix2_inode *dir; 1095 struct minix2_inode *dir;
1097 unsigned int offset; 1096 unsigned int offset;
1098 1097
1099 dir = Inode2 + ino; 1098 dir = Inode2 + ino;
1100 if (!S_ISDIR (dir->i_mode)) 1099 if (!S_ISDIR(dir->i_mode))
1101 die ("internal error"); 1100 die("internal error");
1102 if (dir->i_size < 2 * dirsize) { 1101 if (dir->i_size < 2 * dirsize) {
1103 print_current_name (); 1102 print_current_name();
1104 printf (": bad directory: size < 32"); 1103 printf(": bad directory: size < 32");
1105 errors_uncorrected = 1; 1104 errors_uncorrected = 1;
1106 } 1105 }
1107 for (offset = 0; offset < dir->i_size; offset += dirsize) 1106 for (offset = 0; offset < dir->i_size; offset += dirsize)
1108 check_file2 (dir, offset); 1107 check_file2(dir, offset);
1109} 1108}
1110#endif 1109#endif
1111 1110
@@ -1113,7 +1112,7 @@ static int bad_zone(int i)
1113{ 1112{
1114 char buffer[1024]; 1113 char buffer[1024];
1115 1114
1116 if (BLOCK_SIZE*i != lseek(IN, BLOCK_SIZE*i, SEEK_SET)) 1115 if (BLOCK_SIZE * i != lseek(IN, BLOCK_SIZE * i, SEEK_SET))
1117 die("seek failed in bad_zone"); 1116 die("seek failed in bad_zone");
1118 return (BLOCK_SIZE != read(IN, buffer, BLOCK_SIZE)); 1117 return (BLOCK_SIZE != read(IN, buffer, BLOCK_SIZE));
1119} 1118}
@@ -1122,10 +1121,10 @@ static void check_counts(void)
1122{ 1121{
1123 int i; 1122 int i;
1124 1123
1125 for (i=1 ; i <= INODES ; i++) { 1124 for (i = 1; i <= INODES; i++) {
1126 if (!inode_in_use(i) && Inode[i].i_mode && warn_mode) { 1125 if (!inode_in_use(i) && Inode[i].i_mode && warn_mode) {
1127 printf("Inode %d mode not cleared.",i); 1126 printf("Inode %d mode not cleared.", i);
1128 if (ask("Clear",1)) { 1127 if (ask("Clear", 1)) {
1129 Inode[i].i_mode = 0; 1128 Inode[i].i_mode = 0;
1130 changed = 1; 1129 changed = 1;
1131 } 1130 }
@@ -1133,117 +1132,115 @@ static void check_counts(void)
1133 if (!inode_count[i]) { 1132 if (!inode_count[i]) {
1134 if (!inode_in_use(i)) 1133 if (!inode_in_use(i))
1135 continue; 1134 continue;
1136 printf("Inode %d not used, marked used in the bitmap.",i); 1135 printf("Inode %d not used, marked used in the bitmap.", i);
1137 if (ask("Clear",1)) 1136 if (ask("Clear", 1))
1138 unmark_inode(i); 1137 unmark_inode(i);
1139 continue; 1138 continue;
1140 } 1139 }
1141 if (!inode_in_use(i)) { 1140 if (!inode_in_use(i)) {
1142 printf("Inode %d used, marked unused in the bitmap.", i); 1141 printf("Inode %d used, marked unused in the bitmap.", i);
1143 if (ask("Set",1)) 1142 if (ask("Set", 1))
1144 mark_inode(i); 1143 mark_inode(i);
1145 } 1144 }
1146 if (Inode[i].i_nlinks != inode_count[i]) { 1145 if (Inode[i].i_nlinks != inode_count[i]) {
1147 printf("Inode %d (mode = %07o), i_nlinks=%d, counted=%d.", 1146 printf("Inode %d (mode = %07o), i_nlinks=%d, counted=%d.",
1148 i,Inode[i].i_mode,Inode[i].i_nlinks,inode_count[i]); 1147 i, Inode[i].i_mode, Inode[i].i_nlinks, inode_count[i]);
1149 if (ask("Set i_nlinks to count",1)) { 1148 if (ask("Set i_nlinks to count", 1)) {
1150 Inode[i].i_nlinks=inode_count[i]; 1149 Inode[i].i_nlinks = inode_count[i];
1151 changed=1; 1150 changed = 1;
1152 } 1151 }
1153 } 1152 }
1154 } 1153 }
1155 for (i=FIRSTZONE ; i < ZONES ; i++) { 1154 for (i = FIRSTZONE; i < ZONES; i++) {
1156 if (zone_in_use(i) == zone_count[i]) 1155 if (zone_in_use(i) == zone_count[i])
1157 continue; 1156 continue;
1158 if (!zone_count[i]) { 1157 if (!zone_count[i]) {
1159 if (bad_zone(i)) 1158 if (bad_zone(i))
1160 continue; 1159 continue;
1161 printf("Zone %d: marked in use, no file uses it.",i); 1160 printf("Zone %d: marked in use, no file uses it.", i);
1162 if (ask("Unmark",1)) 1161 if (ask("Unmark", 1))
1163 unmark_zone(i); 1162 unmark_zone(i);
1164 continue; 1163 continue;
1165 } 1164 }
1166 printf("Zone %d: %sin use, counted=%d\n", 1165 printf("Zone %d: %sin use, counted=%d\n",
1167 i,zone_in_use(i)?"":"not ",zone_count[i]); 1166 i, zone_in_use(i) ? "" : "not ", zone_count[i]);
1168 } 1167 }
1169} 1168}
1170 1169
1171#ifdef HAVE_MINIX2 1170#ifdef HAVE_MINIX2
1172static void 1171static void check_counts2(void)
1173check_counts2 (void)
1174{ 1172{
1175 int i; 1173 int i;
1176 1174
1177 for (i = 1; i <= INODES; i++) { 1175 for (i = 1; i <= INODES; i++) {
1178 if (!inode_in_use (i) && Inode2[i].i_mode && warn_mode) { 1176 if (!inode_in_use(i) && Inode2[i].i_mode && warn_mode) {
1179 printf ("Inode %d mode not cleared.", i); 1177 printf("Inode %d mode not cleared.", i);
1180 if (ask ("Clear", 1)) { 1178 if (ask("Clear", 1)) {
1181 Inode2[i].i_mode = 0; 1179 Inode2[i].i_mode = 0;
1182 changed = 1; 1180 changed = 1;
1183 } 1181 }
1184 } 1182 }
1185 if (!inode_count[i]) { 1183 if (!inode_count[i]) {
1186 if (!inode_in_use (i)) 1184 if (!inode_in_use(i))
1187 continue; 1185 continue;
1188 printf ("Inode %d not used, marked used in the bitmap.", i); 1186 printf("Inode %d not used, marked used in the bitmap.", i);
1189 if (ask ("Clear", 1)) 1187 if (ask("Clear", 1))
1190 unmark_inode (i); 1188 unmark_inode(i);
1191 continue; 1189 continue;
1192 } 1190 }
1193 if (!inode_in_use (i)) { 1191 if (!inode_in_use(i)) {
1194 printf ("Inode %d used, marked unused in the bitmap.", i); 1192 printf("Inode %d used, marked unused in the bitmap.", i);
1195 if (ask ("Set", 1)) 1193 if (ask("Set", 1))
1196 mark_inode (i); 1194 mark_inode(i);
1197 } 1195 }
1198 if (Inode2[i].i_nlinks != inode_count[i]) { 1196 if (Inode2[i].i_nlinks != inode_count[i]) {
1199 printf ("Inode %d (mode = %07o), i_nlinks=%d, counted=%d.", 1197 printf("Inode %d (mode = %07o), i_nlinks=%d, counted=%d.",
1200 i, Inode2[i].i_mode, Inode2[i].i_nlinks, inode_count[i]); 1198 i, Inode2[i].i_mode, Inode2[i].i_nlinks,
1201 if (ask ("Set i_nlinks to count", 1)) { 1199 inode_count[i]);
1200 if (ask("Set i_nlinks to count", 1)) {
1202 Inode2[i].i_nlinks = inode_count[i]; 1201 Inode2[i].i_nlinks = inode_count[i];
1203 changed = 1; 1202 changed = 1;
1204 } 1203 }
1205 } 1204 }
1206 } 1205 }
1207 for (i = FIRSTZONE; i < ZONES; i++) { 1206 for (i = FIRSTZONE; i < ZONES; i++) {
1208 if (zone_in_use (i) == zone_count[i]) 1207 if (zone_in_use(i) == zone_count[i])
1209 continue; 1208 continue;
1210 if (!zone_count[i]) { 1209 if (!zone_count[i]) {
1211 if (bad_zone (i)) 1210 if (bad_zone(i))
1212 continue; 1211 continue;
1213 printf ("Zone %d: marked in use, no file uses it.", i); 1212 printf("Zone %d: marked in use, no file uses it.", i);
1214 if (ask ("Unmark", 1)) 1213 if (ask("Unmark", 1))
1215 unmark_zone (i); 1214 unmark_zone(i);
1216 continue; 1215 continue;
1217 } 1216 }
1218 printf ("Zone %d: %sin use, counted=%d\n", 1217 printf("Zone %d: %sin use, counted=%d\n",
1219 i, zone_in_use (i) ? "" : "not ", zone_count[i]); 1218 i, zone_in_use(i) ? "" : "not ", zone_count[i]);
1220 } 1219 }
1221} 1220}
1222#endif 1221#endif
1223 1222
1224static void check(void) 1223static void check(void)
1225{ 1224{
1226 memset(inode_count,0,(INODES + 1) * sizeof(*inode_count)); 1225 memset(inode_count, 0, (INODES + 1) * sizeof(*inode_count));
1227 memset(zone_count,0,ZONES*sizeof(*zone_count)); 1226 memset(zone_count, 0, ZONES * sizeof(*zone_count));
1228 check_zones(ROOT_INO); 1227 check_zones(ROOT_INO);
1229 recursive_check(ROOT_INO); 1228 recursive_check(ROOT_INO);
1230 check_counts(); 1229 check_counts();
1231} 1230}
1232 1231
1233#ifdef HAVE_MINIX2 1232#ifdef HAVE_MINIX2
1234static void 1233static void check2(void)
1235check2 (void)
1236{ 1234{
1237 memset (inode_count, 0, (INODES + 1) * sizeof (*inode_count)); 1235 memset(inode_count, 0, (INODES + 1) * sizeof(*inode_count));
1238 memset (zone_count, 0, ZONES * sizeof (*zone_count)); 1236 memset(zone_count, 0, ZONES * sizeof(*zone_count));
1239 check_zones2 (ROOT_INO); 1237 check_zones2(ROOT_INO);
1240 recursive_check2 (ROOT_INO); 1238 recursive_check2(ROOT_INO);
1241 check_counts2 (); 1239 check_counts2();
1242} 1240}
1243#endif 1241#endif
1244 1242
1245extern int 1243extern int fsck_minix_main(int argc, char **argv)
1246fsck_minix_main(int argc, char ** argv)
1247{ 1244{
1248 struct termios tmp; 1245 struct termios tmp;
1249 int count; 1246 int count;
@@ -1264,29 +1261,47 @@ fsck_minix_main(int argc, char ** argv)
1264 show_usage(); 1261 show_usage();
1265 else 1262 else
1266 device_name = argv[0]; 1263 device_name = argv[0];
1267 } else while (*++argv[0]) 1264 } else
1268 switch (argv[0][0]) { 1265 while (*++argv[0])
1269 case 'l': list=1; break; 1266 switch (argv[0][0]) {
1270 case 'a': automatic=1; repair=1; break; 1267 case 'l':
1271 case 'r': automatic=0; repair=1; break; 1268 list = 1;
1272 case 'v': verbose=1; break; 1269 break;
1273 case 's': show=1; break; 1270 case 'a':
1274 case 'm': warn_mode=1; break; 1271 automatic = 1;
1275 case 'f': force=1; break; 1272 repair = 1;
1276 default: show_usage(); 1273 break;
1277 } 1274 case 'r':
1275 automatic = 0;
1276 repair = 1;
1277 break;
1278 case 'v':
1279 verbose = 1;
1280 break;
1281 case 's':
1282 show = 1;
1283 break;
1284 case 'm':
1285 warn_mode = 1;
1286 break;
1287 case 'f':
1288 force = 1;
1289 break;
1290 default:
1291 show_usage();
1292 }
1278 } 1293 }
1279 if (!device_name) 1294 if (!device_name)
1280 show_usage(); 1295 show_usage();
1281 check_mount(); /* trying to check a mounted filesystem? */ 1296 check_mount(); /* trying to check a mounted filesystem? */
1282 if (repair && !automatic) { 1297 if (repair && !automatic) {
1283 if (!isatty(0) || !isatty(1)) 1298 if (!isatty(0) || !isatty(1))
1284 die("need terminal for interactive repairs"); 1299 die("need terminal for interactive repairs");
1285 } 1300 }
1286 IN = open(device_name,repair?O_RDWR:O_RDONLY); 1301 IN = open(device_name, repair ? O_RDWR : O_RDONLY);
1287 if (IN < 0) 1302 if (IN < 0)
1288 die("unable to open '%s'"); 1303 die("unable to open '%s'");
1289 for (count=0 ; count<3 ; count++) 1304 for (count = 0; count < 3; count++)
1290 sync(); 1305 sync();
1291 read_superblock(); 1306 read_superblock();
1292 1307
@@ -1297,80 +1312,77 @@ fsck_minix_main(int argc, char ** argv)
1297 * command line. 1312 * command line.
1298 */ 1313 */
1299 printf("%s, %s\n", program_name, program_version); 1314 printf("%s, %s\n", program_name, program_version);
1300 if ( !(Super.s_state & MINIX_ERROR_FS) && 1315 if (!(Super.s_state & MINIX_ERROR_FS) &&
1301 (Super.s_state & MINIX_VALID_FS) && 1316 (Super.s_state & MINIX_VALID_FS) && !force) {
1302 !force ) {
1303 if (repair) 1317 if (repair)
1304 printf("%s is clean, no check.\n", device_name); 1318 printf("%s is clean, no check.\n", device_name);
1305 return retcode; 1319 return retcode;
1306 } 1320 } else if (force)
1307 else if (force)
1308 printf("Forcing filesystem check on %s.\n", device_name); 1321 printf("Forcing filesystem check on %s.\n", device_name);
1309 else if (repair) 1322 else if (repair)
1310 printf("Filesystem on %s is dirty, needs checking.\n",\ 1323 printf("Filesystem on %s is dirty, needs checking.\n",
1311 device_name); 1324 device_name);
1312 1325
1313 read_tables(); 1326 read_tables();
1314 1327
1315 if (repair && !automatic) { 1328 if (repair && !automatic) {
1316 tcgetattr(0,&termios); 1329 tcgetattr(0, &termios);
1317 tmp = termios; 1330 tmp = termios;
1318 tmp.c_lflag &= ~(ICANON|ECHO); 1331 tmp.c_lflag &= ~(ICANON | ECHO);
1319 tcsetattr(0,TCSANOW,&tmp); 1332 tcsetattr(0, TCSANOW, &tmp);
1320 termios_set = 1; 1333 termios_set = 1;
1321 } 1334 }
1322
1323#if HAVE_MINIX2 1335#if HAVE_MINIX2
1324 if (version2) { 1336 if (version2) {
1325 check_root2 (); 1337 check_root2();
1326 check2 (); 1338 check2();
1327 } else 1339 } else
1328#endif 1340#endif
1329 { 1341 {
1330 check_root(); 1342 check_root();
1331 check(); 1343 check();
1332 } 1344 }
1333 if (verbose) { 1345 if (verbose) {
1334 int i, free; 1346 int i, free;
1335 1347
1336 for (i=1,free=0 ; i <= INODES ; i++) 1348 for (i = 1, free = 0; i <= INODES; i++)
1337 if (!inode_in_use(i)) 1349 if (!inode_in_use(i))
1338 free++; 1350 free++;
1339 printf("\n%6ld inodes used (%ld%%)\n",(INODES-free), 1351 printf("\n%6ld inodes used (%ld%%)\n", (INODES - free),
1340 100*(INODES-free)/INODES); 1352 100 * (INODES - free) / INODES);
1341 for (i=FIRSTZONE,free=0 ; i < ZONES ; i++) 1353 for (i = FIRSTZONE, free = 0; i < ZONES; i++)
1342 if (!zone_in_use(i)) 1354 if (!zone_in_use(i))
1343 free++; 1355 free++;
1344 printf("%6ld zones used (%ld%%)\n",(ZONES-free), 1356 printf("%6ld zones used (%ld%%)\n", (ZONES - free),
1345 100*(ZONES-free)/ZONES); 1357 100 * (ZONES - free) / ZONES);
1346 printf("\n%6d regular files\n" 1358 printf("\n%6d regular files\n"
1347 "%6d directories\n" 1359 "%6d directories\n"
1348 "%6d character device files\n" 1360 "%6d character device files\n"
1349 "%6d block device files\n" 1361 "%6d block device files\n"
1350 "%6d links\n" 1362 "%6d links\n"
1351 "%6d symbolic links\n" 1363 "%6d symbolic links\n"
1352 "------\n" 1364 "------\n"
1353 "%6d files\n", 1365 "%6d files\n",
1354 regular,directory,chardev,blockdev, 1366 regular, directory, chardev, blockdev,
1355 links-2*directory+1,symlinks,total-2*directory+1); 1367 links - 2 * directory + 1, symlinks,
1368 total - 2 * directory + 1);
1356 } 1369 }
1357 if (changed) { 1370 if (changed) {
1358 write_tables(); 1371 write_tables();
1359 printf( "----------------------------\n" 1372 printf("----------------------------\n"
1360 "FILE SYSTEM HAS BEEN CHANGED\n" 1373 "FILE SYSTEM HAS BEEN CHANGED\n"
1361 "----------------------------\n"); 1374 "----------------------------\n");
1362 for (count=0 ; count<3 ; count++) 1375 for (count = 0; count < 3; count++)
1363 sync(); 1376 sync();
1364 } 1377 } else if (repair)
1365 else if ( repair )
1366 write_super_block(); 1378 write_super_block();
1367 1379
1368 if (repair && !automatic) 1380 if (repair && !automatic)
1369 tcsetattr(0,TCSANOW,&termios); 1381 tcsetattr(0, TCSANOW, &termios);
1370 1382
1371 if (changed) 1383 if (changed)
1372 retcode += 3; 1384 retcode += 3;
1373 if (errors_uncorrected) 1385 if (errors_uncorrected)
1374 retcode += 4; 1386 retcode += 4;
1375 return retcode; 1387 return retcode;
1376} 1388}
diff --git a/util-linux/mkfs_minix.c b/util-linux/mkfs_minix.c
index b90d3a700..4435cb64a 100644
--- a/util-linux/mkfs_minix.c
+++ b/util-linux/mkfs_minix.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * mkfs.c - make a linux (minix) file-system. 3 * mkfs.c - make a linux (minix) file-system.
3 * 4 *
@@ -107,27 +108,30 @@
107 108
108#define BITS_PER_BLOCK (BLOCK_SIZE<<3) 109#define BITS_PER_BLOCK (BLOCK_SIZE<<3)
109 110
110static char * program_name = "mkfs"; 111static char *program_name = "mkfs";
111static char * device_name = NULL; 112static char *device_name = NULL;
112static int DEV = -1; 113static int DEV = -1;
113static long BLOCKS = 0; 114static long BLOCKS = 0;
114static int check = 0; 115static int check = 0;
115static int badblocks = 0; 116static int badblocks = 0;
116static int namelen = 30; /* default (changed to 30, per Linus's 117static int namelen = 30; /* default (changed to 30, per Linus's
117 suggestion, Sun Nov 21 08:05:07 1993) */ 118
119 suggestion, Sun Nov 21 08:05:07 1993) */
118static int dirsize = 32; 120static int dirsize = 32;
119static int magic = MINIX_SUPER_MAGIC2; 121static int magic = MINIX_SUPER_MAGIC2;
120static int version2 = 0; 122static int version2 = 0;
121 123
122static char root_block[BLOCK_SIZE] = "\0"; 124static char root_block[BLOCK_SIZE] = "\0";
123 125
124static char * inode_buffer = NULL; 126static char *inode_buffer = NULL;
127
125#define Inode (((struct minix_inode *) inode_buffer)-1) 128#define Inode (((struct minix_inode *) inode_buffer)-1)
126#ifdef HAVE_MINIX2 129#ifdef HAVE_MINIX2
127#define Inode2 (((struct minix2_inode *) inode_buffer)-1) 130#define Inode2 (((struct minix2_inode *) inode_buffer)-1)
128#endif 131#endif
129static char super_block_buffer[BLOCK_SIZE]; 132static char super_block_buffer[BLOCK_SIZE];
130static char boot_block_buffer[512]; 133static char boot_block_buffer[512];
134
131#define Super (*(struct minix_super_block *)super_block_buffer) 135#define Super (*(struct minix_super_block *)super_block_buffer)
132#define INODES ((unsigned long)Super.s_ninodes) 136#define INODES ((unsigned long)Super.s_ninodes)
133#ifdef HAVE_MINIX2 137#ifdef HAVE_MINIX2
@@ -164,21 +168,28 @@ static unsigned long req_nr_inodes = 0;
164 * to compile this under minix, volatile gives a warning, as 168 * to compile this under minix, volatile gives a warning, as
165 * exit() isn't defined as volatile under minix. 169 * exit() isn't defined as volatile under minix.
166 */ 170 */
167static volatile void die(char *str) { 171static volatile void die(char *str)
172{
168 fprintf(stderr, "%s: %s\n", program_name, str); 173 fprintf(stderr, "%s: %s\n", program_name, str);
169 exit(8); 174 exit(8);
170} 175}
171 176
172static volatile void show_usage() 177static volatile void show_usage()
173{ 178{
174 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", BB_VER, BB_BT); 179 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
175 fprintf(stderr, "Usage: %s [-c | -l filename] [-nXX] [-iXX] /dev/name [blocks]\n\n", program_name); 180 BB_VER, BB_BT);
181 fprintf(stderr,
182 "Usage: %s [-c | -l filename] [-nXX] [-iXX] /dev/name [blocks]\n\n",
183 program_name);
176 fprintf(stderr, "Make a MINIX filesystem.\n\n"); 184 fprintf(stderr, "Make a MINIX filesystem.\n\n");
177 fprintf(stderr, "OPTIONS:\n"); 185 fprintf(stderr, "OPTIONS:\n");
178 fprintf(stderr, "\t-c\t\tCheck the device for bad blocks\n"); 186 fprintf(stderr, "\t-c\t\tCheck the device for bad blocks\n");
179 fprintf(stderr, "\t-n [14|30]\tSpecify the maximum length of filenames\n"); 187 fprintf(stderr,
180 fprintf(stderr, "\t-i\t\tSpecify the number of inodes for the filesystem\n"); 188 "\t-n [14|30]\tSpecify the maximum length of filenames\n");
181 fprintf(stderr, "\t-l FILENAME\tRead the bad blocks list from FILENAME\n"); 189 fprintf(stderr,
190 "\t-i\t\tSpecify the number of inodes for the filesystem\n");
191 fprintf(stderr,
192 "\t-l FILENAME\tRead the bad blocks list from FILENAME\n");
182 fprintf(stderr, "\t-v\t\tMake a Minix version 2 filesystem\n\n"); 193 fprintf(stderr, "\t-v\t\tMake a Minix version 2 filesystem\n\n");
183 exit(16); 194 exit(16);
184} 195}
@@ -190,56 +201,55 @@ static volatile void show_usage()
190 */ 201 */
191static void check_mount(void) 202static void check_mount(void)
192{ 203{
193 FILE * f; 204 FILE *f;
194 struct mntent * mnt; 205 struct mntent *mnt;
195 206
196 if ((f = setmntent (MOUNTED, "r")) == NULL) 207 if ((f = setmntent(MOUNTED, "r")) == NULL)
197 return; 208 return;
198 while ((mnt = getmntent (f)) != NULL) 209 while ((mnt = getmntent(f)) != NULL)
199 if (strcmp (device_name, mnt->mnt_fsname) == 0) 210 if (strcmp(device_name, mnt->mnt_fsname) == 0)
200 break; 211 break;
201 endmntent (f); 212 endmntent(f);
202 if (!mnt) 213 if (!mnt)
203 return; 214 return;
204 215
205 die("%s is mounted; will not make a filesystem here!"); 216 die("%s is mounted; will not make a filesystem here!");
206} 217}
207 218
208static long valid_offset (int fd, int offset) 219static long valid_offset(int fd, int offset)
209{ 220{
210 char ch; 221 char ch;
211 222
212 if (lseek (fd, offset, 0) < 0) 223 if (lseek(fd, offset, 0) < 0)
213 return 0; 224 return 0;
214 if (read (fd, &ch, 1) < 1) 225 if (read(fd, &ch, 1) < 1)
215 return 0; 226 return 0;
216 return 1; 227 return 1;
217} 228}
218 229
219static int count_blocks (int fd) 230static int count_blocks(int fd)
220{ 231{
221 int high, low; 232 int high, low;
222 233
223 low = 0; 234 low = 0;
224 for (high = 1; valid_offset (fd, high); high *= 2) 235 for (high = 1; valid_offset(fd, high); high *= 2)
225 low = high; 236 low = high;
226 while (low < high - 1) 237 while (low < high - 1) {
227 {
228 const int mid = (low + high) / 2; 238 const int mid = (low + high) / 2;
229 239
230 if (valid_offset (fd, mid)) 240 if (valid_offset(fd, mid))
231 low = mid; 241 low = mid;
232 else 242 else
233 high = mid; 243 high = mid;
234 } 244 }
235 valid_offset (fd, 0); 245 valid_offset(fd, 0);
236 return (low + 1); 246 return (low + 1);
237} 247}
238 248
239static int get_size(const char *file) 249static int get_size(const char *file)
240{ 250{
241 int fd; 251 int fd;
242 long size; 252 long size;
243 253
244 fd = open(file, O_RDWR); 254 fd = open(file, O_RDWR);
245 if (fd < 0) { 255 if (fd < 0) {
@@ -250,7 +260,7 @@ static int get_size(const char *file)
250 close(fd); 260 close(fd);
251 return (size * 512); 261 return (size * 512);
252 } 262 }
253 263
254 size = count_blocks(fd); 264 size = count_blocks(fd);
255 close(fd); 265 close(fd);
256 return size; 266 return size;
@@ -270,18 +280,18 @@ static void write_tables(void)
270 die("seek failed in write_tables"); 280 die("seek failed in write_tables");
271 if (BLOCK_SIZE != write(DEV, super_block_buffer, BLOCK_SIZE)) 281 if (BLOCK_SIZE != write(DEV, super_block_buffer, BLOCK_SIZE))
272 die("unable to write super-block"); 282 die("unable to write super-block");
273 if (IMAPS*BLOCK_SIZE != write(DEV,inode_map,IMAPS*BLOCK_SIZE)) 283 if (IMAPS * BLOCK_SIZE != write(DEV, inode_map, IMAPS * BLOCK_SIZE))
274 die("unable to write inode map"); 284 die("unable to write inode map");
275 if (ZMAPS*BLOCK_SIZE != write(DEV,zone_map,ZMAPS*BLOCK_SIZE)) 285 if (ZMAPS * BLOCK_SIZE != write(DEV, zone_map, ZMAPS * BLOCK_SIZE))
276 die("unable to write zone map"); 286 die("unable to write zone map");
277 if (INODE_BUFFER_SIZE != write(DEV,inode_buffer,INODE_BUFFER_SIZE)) 287 if (INODE_BUFFER_SIZE != write(DEV, inode_buffer, INODE_BUFFER_SIZE))
278 die("unable to write inodes"); 288 die("unable to write inodes");
279 289
280} 290}
281 291
282static void write_block(int blk, char * buffer) 292static void write_block(int blk, char *buffer)
283{ 293{
284 if (blk*BLOCK_SIZE != lseek(DEV, blk*BLOCK_SIZE, SEEK_SET)) 294 if (blk * BLOCK_SIZE != lseek(DEV, blk * BLOCK_SIZE, SEEK_SET))
285 die("seek failed in write_block"); 295 die("seek failed in write_block");
286 if (BLOCK_SIZE != write(DEV, buffer, BLOCK_SIZE)) 296 if (BLOCK_SIZE != write(DEV, buffer, BLOCK_SIZE))
287 die("write failed in write_block"); 297 die("write failed in write_block");
@@ -291,10 +301,10 @@ static int get_free_block(void)
291{ 301{
292 int blk; 302 int blk;
293 303
294 if (used_good_blocks+1 >= MAX_GOOD_BLOCKS) 304 if (used_good_blocks + 1 >= MAX_GOOD_BLOCKS)
295 die("too many bad blocks"); 305 die("too many bad blocks");
296 if (used_good_blocks) 306 if (used_good_blocks)
297 blk = good_blocks_table[used_good_blocks-1]+1; 307 blk = good_blocks_table[used_good_blocks - 1] + 1;
298 else 308 else
299 blk = FIRSTZONE; 309 blk = FIRSTZONE;
300 while (blk < ZONES && zone_in_use(blk)) 310 while (blk < ZONES && zone_in_use(blk))
@@ -310,14 +320,14 @@ static void mark_good_blocks(void)
310{ 320{
311 int blk; 321 int blk;
312 322
313 for (blk=0 ; blk < used_good_blocks ; blk++) 323 for (blk = 0; blk < used_good_blocks; blk++)
314 mark_zone(good_blocks_table[blk]); 324 mark_zone(good_blocks_table[blk]);
315} 325}
316 326
317inline int next(int zone) 327inline int next(int zone)
318{ 328{
319 if (!zone) 329 if (!zone)
320 zone = FIRSTZONE-1; 330 zone = FIRSTZONE - 1;
321 while (++zone < ZONES) 331 while (++zone < ZONES)
322 if (zone_in_use(zone)) 332 if (zone_in_use(zone))
323 return zone; 333 return zone;
@@ -326,11 +336,11 @@ inline int next(int zone)
326 336
327static void make_bad_inode(void) 337static void make_bad_inode(void)
328{ 338{
329 struct minix_inode * inode = &Inode[MINIX_BAD_INO]; 339 struct minix_inode *inode = &Inode[MINIX_BAD_INO];
330 int i,j,zone; 340 int i, j, zone;
331 int ind=0,dind=0; 341 int ind = 0, dind = 0;
332 unsigned short ind_block[BLOCK_SIZE>>1]; 342 unsigned short ind_block[BLOCK_SIZE >> 1];
333 unsigned short dind_block[BLOCK_SIZE>>1]; 343 unsigned short dind_block[BLOCK_SIZE >> 1];
334 344
335#define NEXT_BAD (zone = next(zone)) 345#define NEXT_BAD (zone = next(zone))
336 346
@@ -340,34 +350,34 @@ static void make_bad_inode(void)
340 inode->i_nlinks = 1; 350 inode->i_nlinks = 1;
341 inode->i_time = time(NULL); 351 inode->i_time = time(NULL);
342 inode->i_mode = S_IFREG + 0000; 352 inode->i_mode = S_IFREG + 0000;
343 inode->i_size = badblocks*BLOCK_SIZE; 353 inode->i_size = badblocks * BLOCK_SIZE;
344 zone = next(0); 354 zone = next(0);
345 for (i=0 ; i<7 ; i++) { 355 for (i = 0; i < 7; i++) {
346 inode->i_zone[i] = zone; 356 inode->i_zone[i] = zone;
347 if (!NEXT_BAD) 357 if (!NEXT_BAD)
348 goto end_bad; 358 goto end_bad;
349 } 359 }
350 inode->i_zone[7] = ind = get_free_block(); 360 inode->i_zone[7] = ind = get_free_block();
351 memset(ind_block,0,BLOCK_SIZE); 361 memset(ind_block, 0, BLOCK_SIZE);
352 for (i=0 ; i<512 ; i++) { 362 for (i = 0; i < 512; i++) {
353 ind_block[i] = zone; 363 ind_block[i] = zone;
354 if (!NEXT_BAD) 364 if (!NEXT_BAD)
355 goto end_bad; 365 goto end_bad;
356 } 366 }
357 inode->i_zone[8] = dind = get_free_block(); 367 inode->i_zone[8] = dind = get_free_block();
358 memset(dind_block,0,BLOCK_SIZE); 368 memset(dind_block, 0, BLOCK_SIZE);
359 for (i=0 ; i<512 ; i++) { 369 for (i = 0; i < 512; i++) {
360 write_block(ind,(char *) ind_block); 370 write_block(ind, (char *) ind_block);
361 dind_block[i] = ind = get_free_block(); 371 dind_block[i] = ind = get_free_block();
362 memset(ind_block,0,BLOCK_SIZE); 372 memset(ind_block, 0, BLOCK_SIZE);
363 for (j=0 ; j<512 ; j++) { 373 for (j = 0; j < 512; j++) {
364 ind_block[j] = zone; 374 ind_block[j] = zone;
365 if (!NEXT_BAD) 375 if (!NEXT_BAD)
366 goto end_bad; 376 goto end_bad;
367 } 377 }
368 } 378 }
369 die("too many bad blocks"); 379 die("too many bad blocks");
370end_bad: 380 end_bad:
371 if (ind) 381 if (ind)
372 write_block(ind, (char *) ind_block); 382 write_block(ind, (char *) ind_block);
373 if (dind) 383 if (dind)
@@ -375,8 +385,7 @@ end_bad:
375} 385}
376 386
377#ifdef HAVE_MINIX2 387#ifdef HAVE_MINIX2
378static void 388static void make_bad_inode2(void)
379make_bad_inode2 (void)
380{ 389{
381 struct minix2_inode *inode = &Inode2[MINIX_BAD_INO]; 390 struct minix2_inode *inode = &Inode2[MINIX_BAD_INO];
382 int i, j, zone; 391 int i, j, zone;
@@ -386,30 +395,30 @@ make_bad_inode2 (void)
386 395
387 if (!badblocks) 396 if (!badblocks)
388 return; 397 return;
389 mark_inode (MINIX_BAD_INO); 398 mark_inode(MINIX_BAD_INO);
390 inode->i_nlinks = 1; 399 inode->i_nlinks = 1;
391 inode->i_atime = inode->i_mtime = inode->i_ctime = time (NULL); 400 inode->i_atime = inode->i_mtime = inode->i_ctime = time(NULL);
392 inode->i_mode = S_IFREG + 0000; 401 inode->i_mode = S_IFREG + 0000;
393 inode->i_size = badblocks * BLOCK_SIZE; 402 inode->i_size = badblocks * BLOCK_SIZE;
394 zone = next (0); 403 zone = next(0);
395 for (i = 0; i < 7; i++) { 404 for (i = 0; i < 7; i++) {
396 inode->i_zone[i] = zone; 405 inode->i_zone[i] = zone;
397 if (!NEXT_BAD) 406 if (!NEXT_BAD)
398 goto end_bad; 407 goto end_bad;
399 } 408 }
400 inode->i_zone[7] = ind = get_free_block (); 409 inode->i_zone[7] = ind = get_free_block();
401 memset (ind_block, 0, BLOCK_SIZE); 410 memset(ind_block, 0, BLOCK_SIZE);
402 for (i = 0; i < 256; i++) { 411 for (i = 0; i < 256; i++) {
403 ind_block[i] = zone; 412 ind_block[i] = zone;
404 if (!NEXT_BAD) 413 if (!NEXT_BAD)
405 goto end_bad; 414 goto end_bad;
406 } 415 }
407 inode->i_zone[8] = dind = get_free_block (); 416 inode->i_zone[8] = dind = get_free_block();
408 memset (dind_block, 0, BLOCK_SIZE); 417 memset(dind_block, 0, BLOCK_SIZE);
409 for (i = 0; i < 256; i++) { 418 for (i = 0; i < 256; i++) {
410 write_block (ind, (char *) ind_block); 419 write_block(ind, (char *) ind_block);
411 dind_block[i] = ind = get_free_block (); 420 dind_block[i] = ind = get_free_block();
412 memset (ind_block, 0, BLOCK_SIZE); 421 memset(ind_block, 0, BLOCK_SIZE);
413 for (j = 0; j < 256; j++) { 422 for (j = 0; j < 256; j++) {
414 ind_block[j] = zone; 423 ind_block[j] = zone;
415 if (!NEXT_BAD) 424 if (!NEXT_BAD)
@@ -417,47 +426,46 @@ make_bad_inode2 (void)
417 } 426 }
418 } 427 }
419 /* Could make triple indirect block here */ 428 /* Could make triple indirect block here */
420 die ("too many bad blocks"); 429 die("too many bad blocks");
421 end_bad: 430 end_bad:
422 if (ind) 431 if (ind)
423 write_block (ind, (char *) ind_block); 432 write_block(ind, (char *) ind_block);
424 if (dind) 433 if (dind)
425 write_block (dind, (char *) dind_block); 434 write_block(dind, (char *) dind_block);
426} 435}
427#endif 436#endif
428 437
429static void make_root_inode(void) 438static void make_root_inode(void)
430{ 439{
431 struct minix_inode * inode = &Inode[MINIX_ROOT_INO]; 440 struct minix_inode *inode = &Inode[MINIX_ROOT_INO];
432 441
433 mark_inode(MINIX_ROOT_INO); 442 mark_inode(MINIX_ROOT_INO);
434 inode->i_zone[0] = get_free_block(); 443 inode->i_zone[0] = get_free_block();
435 inode->i_nlinks = 2; 444 inode->i_nlinks = 2;
436 inode->i_time = time(NULL); 445 inode->i_time = time(NULL);
437 if (badblocks) 446 if (badblocks)
438 inode->i_size = 3*dirsize; 447 inode->i_size = 3 * dirsize;
439 else { 448 else {
440 root_block[2*dirsize] = '\0'; 449 root_block[2 * dirsize] = '\0';
441 root_block[2*dirsize+1] = '\0'; 450 root_block[2 * dirsize + 1] = '\0';
442 inode->i_size = 2*dirsize; 451 inode->i_size = 2 * dirsize;
443 } 452 }
444 inode->i_mode = S_IFDIR + 0755; 453 inode->i_mode = S_IFDIR + 0755;
445 inode->i_uid = getuid(); 454 inode->i_uid = getuid();
446 if (inode->i_uid) 455 if (inode->i_uid)
447 inode->i_gid = getgid(); 456 inode->i_gid = getgid();
448 write_block(inode->i_zone[0],root_block); 457 write_block(inode->i_zone[0], root_block);
449} 458}
450 459
451#ifdef HAVE_MINIX2 460#ifdef HAVE_MINIX2
452static void 461static void make_root_inode2(void)
453make_root_inode2 (void)
454{ 462{
455 struct minix2_inode *inode = &Inode2[MINIX_ROOT_INO]; 463 struct minix2_inode *inode = &Inode2[MINIX_ROOT_INO];
456 464
457 mark_inode (MINIX_ROOT_INO); 465 mark_inode(MINIX_ROOT_INO);
458 inode->i_zone[0] = get_free_block (); 466 inode->i_zone[0] = get_free_block();
459 inode->i_nlinks = 2; 467 inode->i_nlinks = 2;
460 inode->i_atime = inode->i_mtime = inode->i_ctime = time (NULL); 468 inode->i_atime = inode->i_mtime = inode->i_ctime = time(NULL);
461 if (badblocks) 469 if (badblocks)
462 inode->i_size = 3 * dirsize; 470 inode->i_size = 3 * dirsize;
463 else { 471 else {
@@ -469,7 +477,7 @@ make_root_inode2 (void)
469 inode->i_uid = getuid(); 477 inode->i_uid = getuid();
470 if (inode->i_uid) 478 if (inode->i_uid)
471 inode->i_gid = getgid(); 479 inode->i_gid = getgid();
472 write_block (inode->i_zone[0], root_block); 480 write_block(inode->i_zone[0], root_block);
473} 481}
474#endif 482#endif
475 483
@@ -478,34 +486,38 @@ static void setup_tables(void)
478 int i; 486 int i;
479 unsigned long inodes; 487 unsigned long inodes;
480 488
481 memset(super_block_buffer,0,BLOCK_SIZE); 489 memset(super_block_buffer, 0, BLOCK_SIZE);
482 memset(boot_block_buffer,0,512); 490 memset(boot_block_buffer, 0, 512);
483 MAGIC = magic; 491 MAGIC = magic;
484 ZONESIZE = 0; 492 ZONESIZE = 0;
485 MAXSIZE = version2 ? 0x7fffffff : (7+512+512*512)*1024; 493 MAXSIZE = version2 ? 0x7fffffff : (7 + 512 + 512 * 512) * 1024;
486 ZONES = BLOCKS; 494 ZONES = BLOCKS;
487/* some magic nrs: 1 inode / 3 blocks */ 495/* some magic nrs: 1 inode / 3 blocks */
488 if ( req_nr_inodes == 0 ) 496 if (req_nr_inodes == 0)
489 inodes = BLOCKS/3; 497 inodes = BLOCKS / 3;
490 else 498 else
491 inodes = req_nr_inodes; 499 inodes = req_nr_inodes;
492 /* Round up inode count to fill block size */ 500 /* Round up inode count to fill block size */
493#ifdef HAVE_MINIX2 501#ifdef HAVE_MINIX2
494 if (version2) 502 if (version2)
495 inodes = ((inodes + MINIX2_INODES_PER_BLOCK - 1) & 503 inodes = ((inodes + MINIX2_INODES_PER_BLOCK - 1) &
496 ~(MINIX2_INODES_PER_BLOCK - 1)); 504 ~(MINIX2_INODES_PER_BLOCK - 1));
497 else 505 else
498#endif 506#endif
499 inodes = ((inodes + MINIX_INODES_PER_BLOCK - 1) & 507 inodes = ((inodes + MINIX_INODES_PER_BLOCK - 1) &
500 ~(MINIX_INODES_PER_BLOCK - 1)); 508 ~(MINIX_INODES_PER_BLOCK - 1));
501 if (inodes > 65535) 509 if (inodes > 65535)
502 inodes = 65535; 510 inodes = 65535;
503 INODES = inodes; 511 INODES = inodes;
504 IMAPS = UPPER(INODES + 1,BITS_PER_BLOCK); 512 IMAPS = UPPER(INODES + 1, BITS_PER_BLOCK);
505 ZMAPS = 0; 513 ZMAPS = 0;
506 i=0; 514 i = 0;
507 while (ZMAPS != UPPER(BLOCKS - (2+IMAPS+ZMAPS+INODE_BLOCKS) + 1,BITS_PER_BLOCK) && i<1000) { 515 while (ZMAPS !=
508 ZMAPS = UPPER(BLOCKS - (2+IMAPS+ZMAPS+INODE_BLOCKS) + 1,BITS_PER_BLOCK); 516 UPPER(BLOCKS - (2 + IMAPS + ZMAPS + INODE_BLOCKS) + 1,
517 BITS_PER_BLOCK) && i < 1000) {
518 ZMAPS =
519 UPPER(BLOCKS - (2 + IMAPS + ZMAPS + INODE_BLOCKS) + 1,
520 BITS_PER_BLOCK);
509 i++; 521 i++;
510 } 522 }
511 /* Real bad hack but overwise mkfs.minix can be thrown 523 /* Real bad hack but overwise mkfs.minix can be thrown
@@ -514,50 +526,51 @@ static void setup_tables(void)
514 * dd if=/dev/zero of=test.fs count=10 bs=1024 526 * dd if=/dev/zero of=test.fs count=10 bs=1024
515 * /sbin/mkfs.minix -i 200 test.fs 527 * /sbin/mkfs.minix -i 200 test.fs
516 * */ 528 * */
517 if (i>=999) { 529 if (i >= 999) {
518 die ("unable to allocate buffers for maps"); 530 die("unable to allocate buffers for maps");
519 } 531 }
520 FIRSTZONE = NORM_FIRSTZONE; 532 FIRSTZONE = NORM_FIRSTZONE;
521 inode_map = malloc(IMAPS * BLOCK_SIZE); 533 inode_map = malloc(IMAPS * BLOCK_SIZE);
522 zone_map = malloc(ZMAPS * BLOCK_SIZE); 534 zone_map = malloc(ZMAPS * BLOCK_SIZE);
523 if (!inode_map || !zone_map) 535 if (!inode_map || !zone_map)
524 die("unable to allocate buffers for maps"); 536 die("unable to allocate buffers for maps");
525 memset(inode_map,0xff,IMAPS * BLOCK_SIZE); 537 memset(inode_map, 0xff, IMAPS * BLOCK_SIZE);
526 memset(zone_map,0xff,ZMAPS * BLOCK_SIZE); 538 memset(zone_map, 0xff, ZMAPS * BLOCK_SIZE);
527 for (i = FIRSTZONE ; i<ZONES ; i++) 539 for (i = FIRSTZONE; i < ZONES; i++)
528 unmark_zone(i); 540 unmark_zone(i);
529 for (i = MINIX_ROOT_INO ; i<=INODES ; i++) 541 for (i = MINIX_ROOT_INO; i <= INODES; i++)
530 unmark_inode(i); 542 unmark_inode(i);
531 inode_buffer = malloc(INODE_BUFFER_SIZE); 543 inode_buffer = malloc(INODE_BUFFER_SIZE);
532 if (!inode_buffer) 544 if (!inode_buffer)
533 die("unable to allocate buffer for inodes"); 545 die("unable to allocate buffer for inodes");
534 memset(inode_buffer,0,INODE_BUFFER_SIZE); 546 memset(inode_buffer, 0, INODE_BUFFER_SIZE);
535 printf("%ld inodes\n",INODES); 547 printf("%ld inodes\n", INODES);
536 printf("%ld blocks\n",ZONES); 548 printf("%ld blocks\n", ZONES);
537 printf("Firstdatazone=%ld (%ld)\n",FIRSTZONE,NORM_FIRSTZONE); 549 printf("Firstdatazone=%ld (%ld)\n", FIRSTZONE, NORM_FIRSTZONE);
538 printf("Zonesize=%d\n",BLOCK_SIZE<<ZONESIZE); 550 printf("Zonesize=%d\n", BLOCK_SIZE << ZONESIZE);
539 printf("Maxsize=%ld\n\n",MAXSIZE); 551 printf("Maxsize=%ld\n\n", MAXSIZE);
540} 552}
541 553
542/* 554/*
543 * Perform a test of a block; return the number of 555 * Perform a test of a block; return the number of
544 * blocks readable/writeable. 556 * blocks readable/writeable.
545 */ 557 */
546long do_check(char * buffer, int try, unsigned int current_block) 558long do_check(char *buffer, int try, unsigned int current_block)
547{ 559{
548 long got; 560 long got;
549 561
550 /* Seek to the correct loc. */ 562 /* Seek to the correct loc. */
551 if (lseek(DEV, current_block * BLOCK_SIZE, SEEK_SET) != 563 if (lseek(DEV, current_block * BLOCK_SIZE, SEEK_SET) !=
552 current_block * BLOCK_SIZE ) { 564 current_block * BLOCK_SIZE) {
553 die("seek failed during testing of blocks"); 565 die("seek failed during testing of blocks");
554 } 566 }
555 567
556 568
557 /* Try the read */ 569 /* Try the read */
558 got = read(DEV, buffer, try * BLOCK_SIZE); 570 got = read(DEV, buffer, try * BLOCK_SIZE);
559 if (got < 0) got = 0; 571 if (got < 0)
560 if (got & (BLOCK_SIZE - 1 )) { 572 got = 0;
573 if (got & (BLOCK_SIZE - 1)) {
561 printf("Weird values in do_check: probably bugs\n"); 574 printf("Weird values in do_check: probably bugs\n");
562 } 575 }
563 got /= BLOCK_SIZE; 576 got /= BLOCK_SIZE;
@@ -570,7 +583,7 @@ static void alarm_intr(int alnum)
570{ 583{
571 if (currently_testing >= ZONES) 584 if (currently_testing >= ZONES)
572 return; 585 return;
573 signal(SIGALRM,alarm_intr); 586 signal(SIGALRM, alarm_intr);
574 alarm(5); 587 alarm(5);
575 if (!currently_testing) 588 if (!currently_testing)
576 return; 589 return;
@@ -580,19 +593,19 @@ static void alarm_intr(int alnum)
580 593
581static void check_blocks(void) 594static void check_blocks(void)
582{ 595{
583 int try,got; 596 int try, got;
584 static char buffer[BLOCK_SIZE * TEST_BUFFER_BLOCKS]; 597 static char buffer[BLOCK_SIZE * TEST_BUFFER_BLOCKS];
585 598
586 currently_testing=0; 599 currently_testing = 0;
587 signal(SIGALRM,alarm_intr); 600 signal(SIGALRM, alarm_intr);
588 alarm(5); 601 alarm(5);
589 while (currently_testing < ZONES) { 602 while (currently_testing < ZONES) {
590 if (lseek(DEV,currently_testing*BLOCK_SIZE,SEEK_SET) != 603 if (lseek(DEV, currently_testing * BLOCK_SIZE, SEEK_SET) !=
591 currently_testing*BLOCK_SIZE) 604 currently_testing * BLOCK_SIZE)
592 die("seek failed in check_blocks"); 605 die("seek failed in check_blocks");
593 try = TEST_BUFFER_BLOCKS; 606 try = TEST_BUFFER_BLOCKS;
594 if (currently_testing + try > ZONES) 607 if (currently_testing + try > ZONES)
595 try = ZONES-currently_testing; 608 try = ZONES - currently_testing;
596 got = do_check(buffer, try, currently_testing); 609 got = do_check(buffer, try, currently_testing);
597 currently_testing += got; 610 currently_testing += got;
598 if (got == try) 611 if (got == try)
@@ -613,139 +626,141 @@ static void get_list_blocks(filename)
613char *filename; 626char *filename;
614 627
615{ 628{
616 FILE *listfile; 629 FILE *listfile;
617 unsigned long blockno; 630 unsigned long blockno;
618 631
619 listfile=fopen(filename,"r"); 632 listfile = fopen(filename, "r");
620 if(listfile == (FILE *)NULL) { 633 if (listfile == (FILE *) NULL) {
621 die("can't open file of bad blocks"); 634 die("can't open file of bad blocks");
622 } 635 }
623 while(!feof(listfile)) { 636 while (!feof(listfile)) {
624 fscanf(listfile,"%ld\n", &blockno); 637 fscanf(listfile, "%ld\n", &blockno);
625 mark_zone(blockno); 638 mark_zone(blockno);
626 badblocks++; 639 badblocks++;
627 } 640 }
628 if(badblocks > 1) 641 if (badblocks > 1)
629 printf("%d bad blocks\n", badblocks); 642 printf("%d bad blocks\n", badblocks);
630 else if (badblocks == 1) 643 else if (badblocks == 1)
631 printf("one bad block\n"); 644 printf("one bad block\n");
632} 645}
633 646
634extern int 647extern int mkfs_minix_main(int argc, char **argv)
635mkfs_minix_main(int argc, char ** argv)
636{ 648{
637 int i; 649 int i;
638 char * tmp; 650 char *tmp;
639 struct stat statbuf; 651 struct stat statbuf;
640 char * listfile = NULL; 652 char *listfile = NULL;
641 653
642 if (argc && *argv) 654 if (argc && *argv)
643 program_name = *argv; 655 program_name = *argv;
644 if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE) 656 if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE)
645 die("bad inode size"); 657 die("bad inode size");
646#ifdef HAVE_MINIX2 658#ifdef HAVE_MINIX2
647 if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) 659 if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE)
648 die("bad inode size"); 660 die("bad inode size");
649#endif 661#endif
650 opterr = 0; 662 opterr = 0;
651 while ((i = getopt(argc, argv, "ci:l:n:v")) != EOF) 663 while ((i = getopt(argc, argv, "ci:l:n:v")) != EOF)
652 switch (i) { 664 switch (i) {
653 case 'c': 665 case 'c':
654 check=1; break; 666 check = 1;
655 case 'i': 667 break;
656 req_nr_inodes = (unsigned long) atol(optarg); 668 case 'i':
657 break; 669 req_nr_inodes = (unsigned long) atol(optarg);
658 case 'l': 670 break;
659 listfile = optarg; break; 671 case 'l':
660 case 'n': 672 listfile = optarg;
661 i = strtoul(optarg,&tmp,0); 673 break;
662 if (*tmp) 674 case 'n':
663 show_usage(); 675 i = strtoul(optarg, &tmp, 0);
664 if (i == 14) 676 if (*tmp)
665 magic = MINIX_SUPER_MAGIC; 677 show_usage();
666 else if (i == 30) 678 if (i == 14)
667 magic = MINIX_SUPER_MAGIC2; 679 magic = MINIX_SUPER_MAGIC;
668 else 680 else if (i == 30)
669 show_usage(); 681 magic = MINIX_SUPER_MAGIC2;
670 namelen = i; 682 else
671 dirsize = i+2; 683 show_usage();
672 break; 684 namelen = i;
673 case 'v': 685 dirsize = i + 2;
686 break;
687 case 'v':
674#ifdef HAVE_MINIX2 688#ifdef HAVE_MINIX2
675 version2 = 1; 689 version2 = 1;
676#else 690#else
677 fprintf(stderr,"%s: not compiled with minix v2 support\n",program_name,device_name); 691 fprintf(stderr, "%s: not compiled with minix v2 support\n",
678 exit(-1); 692 program_name, device_name);
693 exit(-1);
679#endif 694#endif
680 break; 695 break;
681 default: 696 default:
682 show_usage(); 697 show_usage();
683 } 698 }
684 argc -= optind; 699 argc -= optind;
685 argv += optind; 700 argv += optind;
686 if (argc > 0 && !device_name) { 701 if (argc > 0 && !device_name) {
687 device_name = argv[0]; 702 device_name = argv[0];
688 argc--; 703 argc--;
689 argv++; 704 argv++;
690 } 705 }
691 if (argc > 0) { 706 if (argc > 0) {
692 BLOCKS = strtol(argv[0],&tmp,0); 707 BLOCKS = strtol(argv[0], &tmp, 0);
693 if (*tmp) { 708 if (*tmp) {
694 printf("strtol error: number of blocks not specified"); 709 printf("strtol error: number of blocks not specified");
695 show_usage(); 710 show_usage();
696 } 711 }
697 } 712 }
698 713
699 if (device_name && !BLOCKS) 714 if (device_name && !BLOCKS)
700 BLOCKS = get_size (device_name) / 1024; 715 BLOCKS = get_size(device_name) / 1024;
701 if (!device_name || BLOCKS<10) { 716 if (!device_name || BLOCKS < 10) {
702 show_usage(); 717 show_usage();
703 } 718 }
704#ifdef HAVE_MINIX2 719#ifdef HAVE_MINIX2
705 if (version2) { 720 if (version2) {
706 if (namelen == 14) 721 if (namelen == 14)
707 magic = MINIX2_SUPER_MAGIC; 722 magic = MINIX2_SUPER_MAGIC;
708 else 723 else
709 magic = MINIX2_SUPER_MAGIC2; 724 magic = MINIX2_SUPER_MAGIC2;
710 } else 725 } else
711#endif 726#endif
712 if (BLOCKS > 65535) 727 if (BLOCKS > 65535)
713 BLOCKS = 65535; 728 BLOCKS = 65535;
714 check_mount(); /* is it already mounted? */ 729 check_mount(); /* is it already mounted? */
715 tmp = root_block; 730 tmp = root_block;
716 *(short *)tmp = 1; 731 *(short *) tmp = 1;
717 strcpy(tmp+2,"."); 732 strcpy(tmp + 2, ".");
718 tmp += dirsize; 733 tmp += dirsize;
719 *(short *)tmp = 1; 734 *(short *) tmp = 1;
720 strcpy(tmp+2,".."); 735 strcpy(tmp + 2, "..");
721 tmp += dirsize; 736 tmp += dirsize;
722 *(short *)tmp = 2; 737 *(short *) tmp = 2;
723 strcpy(tmp+2,".badblocks"); 738 strcpy(tmp + 2, ".badblocks");
724 DEV = open(device_name,O_RDWR ); 739 DEV = open(device_name, O_RDWR);
725 if (DEV<0) 740 if (DEV < 0)
726 die("unable to open %s"); 741 die("unable to open %s");
727 if (fstat(DEV,&statbuf)<0) 742 if (fstat(DEV, &statbuf) < 0)
728 die("unable to stat %s"); 743 die("unable to stat %s");
729 if (!S_ISBLK(statbuf.st_mode)) 744 if (!S_ISBLK(statbuf.st_mode))
730 check=0; 745 check = 0;
731 else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) 746 else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
732 die("will not try to make filesystem on '%s'"); 747 die("will not try to make filesystem on '%s'");
733 setup_tables(); 748 setup_tables();
734 if (check) 749 if (check)
735 check_blocks(); 750 check_blocks();
736 else if (listfile) 751 else if (listfile)
737 get_list_blocks(listfile); 752 get_list_blocks(listfile);
738#ifdef HAVE_MINIX2 753#ifdef HAVE_MINIX2
739 if (version2) { 754 if (version2) {
740 make_root_inode2 (); 755 make_root_inode2();
741 make_bad_inode2 (); 756 make_bad_inode2();
742 } else 757 } else
743#endif 758#endif
744 { 759 {
745 make_root_inode(); 760 make_root_inode();
746 make_bad_inode(); 761 make_bad_inode();
747 } 762 }
748 mark_good_blocks(); 763 mark_good_blocks();
749 write_tables(); 764 write_tables();
750 return 0; 765 return 0;
751} 766}
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c
index 601188f86..130d24162 100644
--- a/util-linux/mkswap.c
+++ b/util-linux/mkswap.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * mkswap.c - set up a linux swap device 3 * mkswap.c - set up a linux swap device
3 * 4 *
@@ -40,20 +41,21 @@
40#include <string.h> 41#include <string.h>
41#include <fcntl.h> 42#include <fcntl.h>
42#include <stdlib.h> 43#include <stdlib.h>
43#include <sys/ioctl.h> /* for _IO */ 44#include <sys/ioctl.h> /* for _IO */
44#include <sys/utsname.h> 45#include <sys/utsname.h>
45#include <sys/stat.h> 46#include <sys/stat.h>
46#include <asm/page.h> /* for PAGE_SIZE and PAGE_SHIFT */ 47#include <asm/page.h> /* for PAGE_SIZE and PAGE_SHIFT */
47 /* we also get PAGE_SIZE via getpagesize() */ 48 /* we also get PAGE_SIZE via getpagesize() */
48 49
49 50
50static const char mkswap_usage[] = "mkswap [-c] [-v0|-v1] device [block-count]\n\n" 51static const char mkswap_usage[] =
51"Prepare a disk partition to be used as a swap partition.\n\n" 52 "mkswap [-c] [-v0|-v1] device [block-count]\n\n"
52"Options:\n" 53 "Prepare a disk partition to be used as a swap partition.\n\n"
53"\t-c\t\tCheck for read-ability.\n" 54 "Options:\n" "\t-c\t\tCheck for read-ability.\n"
54"\t-v0\t\tMake version 0 swap [max 128 Megs].\n" 55 "\t-v0\t\tMake version 0 swap [max 128 Megs].\n"
55"\t-v1\t\tMake version 1 swap [big!] (default for kernels > 2.1.117).\n" 56 "\t-v1\t\tMake version 1 swap [big!] (default for kernels > 2.1.117).\n"
56"\tblock-count\tNumber of block to use (default is entire partition).\n"; 57
58 "\tblock-count\tNumber of block to use (default is entire partition).\n";
57 59
58 60
59#ifndef _IO 61#ifndef _IO
@@ -64,8 +66,8 @@ static const char mkswap_usage[] = "mkswap [-c] [-v0|-v1] device [block-count]\n
64#define BLKGETSIZE _IO(0x12,96) 66#define BLKGETSIZE _IO(0x12,96)
65#endif 67#endif
66 68
67static char * program_name = "mkswap"; 69static char *program_name = "mkswap";
68static char * device_name = NULL; 70static char *device_name = NULL;
69static int DEV = -1; 71static int DEV = -1;
70static long PAGES = 0; 72static long PAGES = 0;
71static int check = 0; 73static int check = 0;
@@ -74,8 +76,8 @@ static int version = -1;
74 76
75#define MAKE_VERSION(p,q,r) (65536*(p) + 256*(q) + (r)) 77#define MAKE_VERSION(p,q,r) (65536*(p) + 256*(q) + (r))
76 78
77static int 79static int linux_version_code(void)
78linux_version_code(void) { 80{
79 struct utsname my_utsname; 81 struct utsname my_utsname;
80 int p, q, r; 82 int p, q, r;
81 83
@@ -83,7 +85,7 @@ linux_version_code(void) {
83 p = atoi(strtok(my_utsname.release, ".")); 85 p = atoi(strtok(my_utsname.release, "."));
84 q = atoi(strtok(NULL, ".")); 86 q = atoi(strtok(NULL, "."));
85 r = atoi(strtok(NULL, ".")); 87 r = atoi(strtok(NULL, "."));
86 return MAKE_VERSION(p,q,r); 88 return MAKE_VERSION(p, q, r);
87 } 89 }
88 return 0; 90 return 0;
89} 91}
@@ -98,7 +100,7 @@ static int pagesize;
98static int *signature_page; 100static int *signature_page;
99 101
100struct swap_header_v1 { 102struct swap_header_v1 {
101 char bootbits[1024]; /* Space for disklabel etc. */ 103 char bootbits[1024]; /* Space for disklabel etc. */
102 unsigned int version; 104 unsigned int version;
103 unsigned int last_page; 105 unsigned int last_page;
104 unsigned int nr_badpages; 106 unsigned int nr_badpages;
@@ -106,8 +108,8 @@ struct swap_header_v1 {
106 unsigned int badpages[1]; 108 unsigned int badpages[1];
107} *p; 109} *p;
108 110
109static void 111static void init_signature_page()
110init_signature_page() { 112{
111 pagesize = getpagesize(); 113 pagesize = getpagesize();
112 114
113#ifdef PAGE_SIZE 115#ifdef PAGE_SIZE
@@ -115,15 +117,15 @@ init_signature_page() {
115 fprintf(stderr, "Assuming pages of size %d\n", pagesize); 117 fprintf(stderr, "Assuming pages of size %d\n", pagesize);
116#endif 118#endif
117 signature_page = (int *) malloc(pagesize); 119 signature_page = (int *) malloc(pagesize);
118 memset(signature_page,0,pagesize); 120 memset(signature_page, 0, pagesize);
119 p = (struct swap_header_v1 *) signature_page; 121 p = (struct swap_header_v1 *) signature_page;
120} 122}
121 123
122static void 124static void write_signature(char *sig)
123write_signature(char *sig) { 125{
124 char *sp = (char *) signature_page; 126 char *sp = (char *) signature_page;
125 127
126 strncpy(sp+pagesize-10, sig, 10); 128 strncpy(sp + pagesize - 10, sig, 10);
127} 129}
128 130
129#define V0_MAX_PAGES (8 * (pagesize - 10)) 131#define V0_MAX_PAGES (8 * (pagesize - 10))
@@ -172,42 +174,46 @@ It is roughly 2GB on i386, PPC, m68k, ARM, 1GB on sparc, 512MB on mips,
172 174
173#define MAX_BADPAGES ((pagesize-1024-128*sizeof(int)-10)/sizeof(int)) 175#define MAX_BADPAGES ((pagesize-1024-128*sizeof(int)-10)/sizeof(int))
174 176
175static void bit_set (unsigned int *addr, unsigned int nr) 177static void bit_set(unsigned int *addr, unsigned int nr)
176{ 178{
177 unsigned int r, m; 179 unsigned int r, m;
178 180
179 addr += nr / (8 * sizeof(int)); 181 addr += nr / (8 * sizeof(int));
182
180 r = *addr; 183 r = *addr;
181 m = 1 << (nr & (8 * sizeof(int) - 1)); 184 m = 1 << (nr & (8 * sizeof(int) - 1));
185
182 *addr = r | m; 186 *addr = r | m;
183} 187}
184 188
185static int bit_test_and_clear (unsigned int *addr, unsigned int nr) 189static int bit_test_and_clear(unsigned int *addr, unsigned int nr)
186{ 190{
187 unsigned int r, m; 191 unsigned int r, m;
188 192
189 addr += nr / (8 * sizeof(int)); 193 addr += nr / (8 * sizeof(int));
194
190 r = *addr; 195 r = *addr;
191 m = 1 << (nr & (8 * sizeof(int) - 1)); 196 m = 1 << (nr & (8 * sizeof(int) - 1));
197
192 *addr = r & ~m; 198 *addr = r & ~m;
193 return (r & m) != 0; 199 return (r & m) != 0;
194} 200}
195 201
196 202
197void 203void die(const char *str)
198die(const char *str) { 204{
199 fprintf(stderr, "%s: %s\n", program_name, str); 205 fprintf(stderr, "%s: %s\n", program_name, str);
200 exit( FALSE); 206 exit(FALSE);
201} 207}
202 208
203void 209void page_ok(int page)
204page_ok(int page) { 210{
205 if (version==0) 211 if (version == 0)
206 bit_set(signature_page, page); 212 bit_set(signature_page, page);
207} 213}
208 214
209void 215void page_bad(int page)
210page_bad(int page) { 216{
211 if (version == 0) 217 if (version == 0)
212 bit_test_and_clear(signature_page, page); 218 bit_test_and_clear(signature_page, page);
213 else { 219 else {
@@ -218,8 +224,8 @@ page_bad(int page) {
218 badpages++; 224 badpages++;
219} 225}
220 226
221void 227void check_blocks(void)
222check_blocks(void) { 228{
223 unsigned int current_page; 229 unsigned int current_page;
224 int do_seek = 1; 230 int do_seek = 1;
225 char *buffer; 231 char *buffer;
@@ -233,8 +239,8 @@ check_blocks(void) {
233 page_ok(current_page++); 239 page_ok(current_page++);
234 continue; 240 continue;
235 } 241 }
236 if (do_seek && lseek(DEV,current_page*pagesize,SEEK_SET) != 242 if (do_seek && lseek(DEV, current_page * pagesize, SEEK_SET) !=
237 current_page*pagesize) 243 current_page * pagesize)
238 die("seek failed in check_blocks"); 244 die("seek failed in check_blocks");
239 if ((do_seek = (pagesize != read(DEV, buffer, pagesize)))) { 245 if ((do_seek = (pagesize != read(DEV, buffer, pagesize)))) {
240 page_bad(current_page++); 246 page_bad(current_page++);
@@ -248,30 +254,28 @@ check_blocks(void) {
248 printf("%d bad pages\n", badpages); 254 printf("%d bad pages\n", badpages);
249} 255}
250 256
251static long valid_offset (int fd, int offset) 257static long valid_offset(int fd, int offset)
252{ 258{
253 char ch; 259 char ch;
254 260
255 if (lseek (fd, offset, 0) < 0) 261 if (lseek(fd, offset, 0) < 0)
256 return 0; 262 return 0;
257 if (read (fd, &ch, 1) < 1) 263 if (read(fd, &ch, 1) < 1)
258 return 0; 264 return 0;
259 return 1; 265 return 1;
260} 266}
261 267
262static int 268static int find_size(int fd)
263find_size (int fd)
264{ 269{
265 unsigned int high, low; 270 unsigned int high, low;
266 271
267 low = 0; 272 low = 0;
268 for (high = 1; high > 0 && valid_offset (fd, high); high *= 2) 273 for (high = 1; high > 0 && valid_offset(fd, high); high *= 2)
269 low = high; 274 low = high;
270 while (low < high - 1) 275 while (low < high - 1) {
271 {
272 const int mid = (low + high) / 2; 276 const int mid = (low + high) / 2;
273 277
274 if (valid_offset (fd, mid)) 278 if (valid_offset(fd, mid))
275 low = mid; 279 low = mid;
276 else 280 else
277 high = mid; 281 high = mid;
@@ -280,11 +284,10 @@ find_size (int fd)
280} 284}
281 285
282/* return size in pages, to avoid integer overflow */ 286/* return size in pages, to avoid integer overflow */
283static long 287static long get_size(const char *file)
284get_size(const char *file)
285{ 288{
286 int fd; 289 int fd;
287 long size; 290 long size;
288 291
289 fd = open(file, O_RDONLY); 292 fd = open(file, O_RDONLY);
290 if (fd < 0) { 293 if (fd < 0) {
@@ -292,7 +295,8 @@ get_size(const char *file)
292 exit(1); 295 exit(1);
293 } 296 }
294 if (ioctl(fd, BLKGETSIZE, &size) >= 0) { 297 if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
295 int sectors_per_page = pagesize/512; 298 int sectors_per_page = pagesize / 512;
299
296 size /= sectors_per_page; 300 size /= sectors_per_page;
297 } else { 301 } else {
298 size = find_size(fd) / pagesize; 302 size = find_size(fd) / pagesize;
@@ -301,9 +305,9 @@ get_size(const char *file)
301 return size; 305 return size;
302} 306}
303 307
304int mkswap_main(int argc, char ** argv) 308int mkswap_main(int argc, char **argv)
305{ 309{
306 char * tmp; 310 char *tmp;
307 struct stat statbuf; 311 struct stat statbuf;
308 int sz; 312 int sz;
309 int maxpages; 313 int maxpages;
@@ -314,56 +318,56 @@ int mkswap_main(int argc, char ** argv)
314 if (argc && *argv) 318 if (argc && *argv)
315 program_name = *argv; 319 program_name = *argv;
316 320
317 init_signature_page(); /* get pagesize */ 321 init_signature_page(); /* get pagesize */
318 322
319 while (argc-- > 1) { 323 while (argc-- > 1) {
320 argv++; 324 argv++;
321 if (argv[0][0] != '-') { 325 if (argv[0][0] != '-') {
322 if (device_name) { 326 if (device_name) {
323 int blocks_per_page = pagesize/1024; 327 int blocks_per_page = pagesize / 1024;
324 PAGES = strtol(argv[0],&tmp,0)/blocks_per_page; 328
329 PAGES = strtol(argv[0], &tmp, 0) / blocks_per_page;
325 if (*tmp) 330 if (*tmp)
326 usage( mkswap_usage); 331 usage(mkswap_usage);
327 } else 332 } else
328 device_name = argv[0]; 333 device_name = argv[0];
329 } else { 334 } else {
330 switch (argv[0][1]) { 335 switch (argv[0][1]) {
331 case 'c': 336 case 'c':
332 check=1; 337 check = 1;
333 break; 338 break;
334 case 'f': 339 case 'f':
335 force=1; 340 force = 1;
336 break; 341 break;
337 case 'v': 342 case 'v':
338 version=atoi(argv[0]+2); 343 version = atoi(argv[0] + 2);
339 break; 344 break;
340 default: 345 default:
341 usage( mkswap_usage); 346 usage(mkswap_usage);
342 } 347 }
343 } 348 }
344 } 349 }
345 if (!device_name) { 350 if (!device_name) {
346 fprintf(stderr, 351 fprintf(stderr,
347 "%s: error: Nowhere to set up swap on?\n", 352 "%s: error: Nowhere to set up swap on?\n", program_name);
348 program_name); 353 usage(mkswap_usage);
349 usage( mkswap_usage);
350 } 354 }
351 sz = get_size(device_name); 355 sz = get_size(device_name);
352 if (!PAGES) { 356 if (!PAGES) {
353 PAGES = sz; 357 PAGES = sz;
354 } else if (PAGES > sz && !force) { 358 } else if (PAGES > sz && !force) {
355 fprintf(stderr, 359 fprintf(stderr,
356 "%s: error: " 360 "%s: error: "
357 "size %ld is larger than device size %d\n", 361 "size %ld is larger than device size %d\n",
358 program_name, 362 program_name,
359 PAGES*(pagesize/1024), sz*(pagesize/1024)); 363 PAGES * (pagesize / 1024), sz * (pagesize / 1024));
360 exit( FALSE); 364 exit(FALSE);
361 } 365 }
362 366
363 if (version == -1) { 367 if (version == -1) {
364 if (PAGES <= V0_MAX_PAGES) 368 if (PAGES <= V0_MAX_PAGES)
365 version = 0; 369 version = 0;
366 else if (linux_version_code() < MAKE_VERSION(2,1,117)) 370 else if (linux_version_code() < MAKE_VERSION(2, 1, 117))
367 version = 0; 371 version = 0;
368 else if (pagesize < 2048) 372 else if (pagesize < 2048)
369 version = 0; 373 version = 0;
@@ -372,21 +376,21 @@ int mkswap_main(int argc, char ** argv)
372 } 376 }
373 if (version != 0 && version != 1) { 377 if (version != 0 && version != 1) {
374 fprintf(stderr, "%s: error: unknown version %d\n", 378 fprintf(stderr, "%s: error: unknown version %d\n",
375 program_name, version); 379 program_name, version);
376 usage( mkswap_usage); 380 usage(mkswap_usage);
377 } 381 }
378 if (PAGES < 10) { 382 if (PAGES < 10) {
379 fprintf(stderr, 383 fprintf(stderr,
380 "%s: error: swap area needs to be at least %ldkB\n", 384 "%s: error: swap area needs to be at least %ldkB\n",
381 program_name, (long)(10 * pagesize / 1024)); 385 program_name, (long) (10 * pagesize / 1024));
382 usage( mkswap_usage); 386 usage(mkswap_usage);
383 } 387 }
384#if 0 388#if 0
385 maxpages = ((version == 0) ? V0_MAX_PAGES : V1_MAX_PAGES); 389 maxpages = ((version == 0) ? V0_MAX_PAGES : V1_MAX_PAGES);
386#else 390#else
387 if (!version) 391 if (!version)
388 maxpages = V0_MAX_PAGES; 392 maxpages = V0_MAX_PAGES;
389 else if (linux_version_code() >= MAKE_VERSION(2,2,1)) 393 else if (linux_version_code() >= MAKE_VERSION(2, 2, 1))
390 maxpages = V1_MAX_PAGES; 394 maxpages = V1_MAX_PAGES;
391 else { 395 else {
392 maxpages = V1_OLD_MAX_PAGES; 396 maxpages = V1_OLD_MAX_PAGES;
@@ -397,29 +401,29 @@ int mkswap_main(int argc, char ** argv)
397 if (PAGES > maxpages) { 401 if (PAGES > maxpages) {
398 PAGES = maxpages; 402 PAGES = maxpages;
399 fprintf(stderr, "%s: warning: truncating swap area to %ldkB\n", 403 fprintf(stderr, "%s: warning: truncating swap area to %ldkB\n",
400 program_name, PAGES * pagesize / 1024); 404 program_name, PAGES * pagesize / 1024);
401 } 405 }
402 406
403 DEV = open(device_name,O_RDWR); 407 DEV = open(device_name, O_RDWR);
404 if (DEV < 0 || fstat(DEV, &statbuf) < 0) { 408 if (DEV < 0 || fstat(DEV, &statbuf) < 0) {
405 perror(device_name); 409 perror(device_name);
406 exit( FALSE); 410 exit(FALSE);
407 } 411 }
408 if (!S_ISBLK(statbuf.st_mode)) 412 if (!S_ISBLK(statbuf.st_mode))
409 check=0; 413 check = 0;
410 else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) 414 else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
411 die("Will not try to make swapdevice on '%s'"); 415 die("Will not try to make swapdevice on '%s'");
412 416
413#ifdef __sparc__ 417#ifdef __sparc__
414 if (!force && version == 0) { 418 if (!force && version == 0) {
415 /* Don't overwrite partition table unless forced */ 419 /* Don't overwrite partition table unless forced */
416 unsigned char *buffer = (unsigned char *)signature_page; 420 unsigned char *buffer = (unsigned char *) signature_page;
417 unsigned short *q, sum; 421 unsigned short *q, sum;
418 422
419 if (read(DEV, buffer, 512) != 512) 423 if (read(DEV, buffer, 512) != 512)
420 die("fatal: first page unreadable"); 424 die("fatal: first page unreadable");
421 if (buffer[508] == 0xDA && buffer[509] == 0xBE) { 425 if (buffer[508] == 0xDA && buffer[509] == 0xBE) {
422 q = (unsigned short *)(buffer + 510); 426 q = (unsigned short *) (buffer + 510);
423 for (sum = 0; q >= (unsigned short *) buffer;) 427 for (sum = 0; q >= (unsigned short *) buffer;)
424 sum ^= *q--; 428 sum ^= *q--;
425 if (!sum) { 429 if (!sum) {
@@ -427,9 +431,8 @@ int mkswap_main(int argc, char ** argv)
427%s: Device '%s' contains a valid Sun disklabel.\n\ 431%s: Device '%s' contains a valid Sun disklabel.\n\
428This probably means creating v0 swap would destroy your partition table\n\ 432This probably means creating v0 swap would destroy your partition table\n\
429No swap created. If you really want to create swap v0 on that device, use\n\ 433No swap created. If you really want to create swap v0 on that device, use\n\
430the -f option to force it.\n", 434the -f option to force it.\n", program_name, device_name);
431 program_name, device_name); 435 exit(FALSE);
432 exit( FALSE);
433 } 436 }
434 } 437 }
435 } 438 }
@@ -437,11 +440,11 @@ the -f option to force it.\n",
437 440
438 if (version == 0 || check) 441 if (version == 0 || check)
439 check_blocks(); 442 check_blocks();
440 if (version == 0 && !bit_test_and_clear(signature_page,0)) 443 if (version == 0 && !bit_test_and_clear(signature_page, 0))
441 die("fatal: first page unreadable"); 444 die("fatal: first page unreadable");
442 if (version == 1) { 445 if (version == 1) {
443 p->version = version; 446 p->version = version;
444 p->last_page = PAGES-1; 447 p->last_page = PAGES - 1;
445 p->nr_badpages = badpages; 448 p->nr_badpages = badpages;
446 } 449 }
447 450
@@ -449,14 +452,14 @@ the -f option to force it.\n",
449 if (goodpages <= 0) 452 if (goodpages <= 0)
450 die("Unable to set up swap-space: unreadable"); 453 die("Unable to set up swap-space: unreadable");
451 printf("Setting up swapspace version %d, size = %ld bytes\n", 454 printf("Setting up swapspace version %d, size = %ld bytes\n",
452 version, (long)(goodpages*pagesize)); 455 version, (long) (goodpages * pagesize));
453 write_signature((version == 0) ? "SWAP-SPACE" : "SWAPSPACE2"); 456 write_signature((version == 0) ? "SWAP-SPACE" : "SWAPSPACE2");
454 457
455 offset = ((version == 0) ? 0 : 1024); 458 offset = ((version == 0) ? 0 : 1024);
456 if (lseek(DEV, offset, SEEK_SET) != offset) 459 if (lseek(DEV, offset, SEEK_SET) != offset)
457 die("unable to rewind swap-device"); 460 die("unable to rewind swap-device");
458 if (write(DEV,(char*)signature_page+offset, pagesize-offset) 461 if (write(DEV, (char *) signature_page + offset, pagesize - offset)
459 != pagesize-offset) 462 != pagesize - offset)
460 die("unable to write signature page"); 463 die("unable to write signature page");
461 464
462 /* 465 /*
@@ -464,6 +467,6 @@ the -f option to force it.\n",
464 * is not actually on disk. (This is a kernel bug.) 467 * is not actually on disk. (This is a kernel bug.)
465 */ 468 */
466 if (fsync(DEV)) 469 if (fsync(DEV))
467 die("fsync failed"); 470 die("fsync failed");
468 exit ( TRUE); 471 exit(TRUE);
469} 472}
diff --git a/util-linux/more.c b/util-linux/more.c
index 821427dda..d5711aa2f 100644
--- a/util-linux/more.c
+++ b/util-linux/more.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * Mini more implementation for busybox 3 * Mini more implementation for busybox
3 * 4 *
@@ -45,19 +46,20 @@ static const char more_usage[] = "more [file ...]\n";
45# define stty(fd,argp) tcsetattr(fd,TCSANOW,argp) 46# define stty(fd,argp) tcsetattr(fd,TCSANOW,argp)
46#endif 47#endif
47 48
48 FILE *cin; 49FILE *cin;
49 struct termios initial_settings, new_settings; 50struct termios initial_settings, new_settings;
50 51
51 void gotsig(int sig) { 52void gotsig(int sig)
52 stty(fileno(cin), &initial_settings); 53{
53 fprintf(stdout, "\n"); 54 stty(fileno(cin), &initial_settings);
54 exit( TRUE); 55 fprintf(stdout, "\n");
55 } 56 exit(TRUE);
57}
56#endif 58#endif
57 59
58 60
59 61
60#define TERMINAL_WIDTH 79 /* not 80 in case terminal has linefold bug */ 62#define TERMINAL_WIDTH 79 /* not 80 in case terminal has linefold bug */
61#define TERMINAL_HEIGHT 24 63#define TERMINAL_HEIGHT 24
62 64
63 65
@@ -72,118 +74,121 @@ static int terminal_width = 0, terminal_height = 0;
72 74
73extern int more_main(int argc, char **argv) 75extern int more_main(int argc, char **argv)
74{ 76{
75 int c, lines=0, input=0; 77 int c, lines = 0, input = 0;
76 int next_page=0; 78 int next_page = 0;
77 struct stat st; 79 struct stat st;
78 FILE *file; 80 FILE *file;
81
79#ifdef BB_FEATURE_AUTOWIDTH 82#ifdef BB_FEATURE_AUTOWIDTH
80 struct winsize win = {0,0}; 83 struct winsize win = { 0, 0 };
81#endif 84#endif
82 85
83 argc--; 86 argc--;
84 argv++; 87 argv++;
85
86 if ( argc > 0 && (strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0) ) {
87 usage (more_usage);
88 }
89 do {
90 if (argc==0) {
91 file = stdin;
92 }
93 else
94 file = fopen(*argv, "r");
95 88
96 if (file == NULL) { 89 if (argc > 0
97 perror(*argv); 90 && (strcmp(*argv, "--help") == 0 || strcmp(*argv, "-h") == 0)) {
98 exit(FALSE); 91 usage(more_usage);
99 } 92 }
100 fstat(fileno(file), &st); 93 do {
94 if (argc == 0) {
95 file = stdin;
96 } else
97 file = fopen(*argv, "r");
98
99 if (file == NULL) {
100 perror(*argv);
101 exit(FALSE);
102 }
103 fstat(fileno(file), &st);
101 104
102#ifdef BB_FEATURE_USE_TERMIOS 105#ifdef BB_FEATURE_USE_TERMIOS
103 cin = fopen("/dev/tty", "r"); 106 cin = fopen("/dev/tty", "r");
104 if (!cin) 107 if (!cin)
105 cin = fopen("/dev/console", "r"); 108 cin = fopen("/dev/console", "r");
106#ifdef USE_OLD_TERMIO 109#ifdef USE_OLD_TERMIO
107 ioctl(fileno(cin),TCGETA,&initial_settings); 110 ioctl(fileno(cin), TCGETA, &initial_settings);
108#else 111#else
109 tcgetattr(fileno(cin),&initial_settings); 112 tcgetattr(fileno(cin), &initial_settings);
110#endif 113#endif
111 new_settings = initial_settings; 114 new_settings = initial_settings;
112 new_settings.c_lflag &= ~ICANON; 115 new_settings.c_lflag &= ~ICANON;
113 new_settings.c_lflag &= ~ECHO; 116 new_settings.c_lflag &= ~ECHO;
114 stty(fileno(cin), &new_settings); 117 stty(fileno(cin), &new_settings);
115 118
116#ifdef BB_FEATURE_AUTOWIDTH 119#ifdef BB_FEATURE_AUTOWIDTH
117 ioctl(fileno(stdout), TIOCGWINSZ, &win); 120 ioctl(fileno(stdout), TIOCGWINSZ, &win);
118 if (win.ws_row > 4) 121 if (win.ws_row > 4)
119 terminal_height = win.ws_row - 2; 122 terminal_height = win.ws_row - 2;
120 if (win.ws_col > 0) 123 if (win.ws_col > 0)
121 terminal_width = win.ws_col - 1; 124 terminal_width = win.ws_col - 1;
122#endif 125#endif
123 126
124 (void) signal(SIGINT, gotsig); 127 (void) signal(SIGINT, gotsig);
125 (void) signal(SIGQUIT, gotsig); 128 (void) signal(SIGQUIT, gotsig);
126 (void) signal(SIGTERM, gotsig); 129 (void) signal(SIGTERM, gotsig);
127 130
128#endif 131#endif
129 while ((c = getc(file)) != EOF) { 132 while ((c = getc(file)) != EOF) {
130 if ( next_page ) { 133 if (next_page) {
131 int len=0; 134 int len = 0;
132 next_page = 0; 135
133 lines=0; 136 next_page = 0;
134 len = fprintf(stdout, "--More-- "); 137 lines = 0;
135 if (file != stdin) { 138 len = fprintf(stdout, "--More-- ");
136 len += fprintf(stdout, "(%d%% of %ld bytes)", 139 if (file != stdin) {
137 (int) (100*( (double) ftell(file) / (double) st.st_size )), 140 len += fprintf(stdout, "(%d%% of %ld bytes)",
138 st.st_size); 141 (int) (100 *
139 } 142 ((double) ftell(file) /
140 len += fprintf(stdout, "%s", 143 (double) st.st_size)),
144 st.st_size);
145 }
146 len += fprintf(stdout, "%s",
141#ifdef BB_FEATURE_USE_TERMIOS 147#ifdef BB_FEATURE_USE_TERMIOS
142 "" 148 ""
143#else 149#else
144 "\n" 150 "\n"
145#endif 151#endif
146 ); 152 );
147 153
148 fflush(stdout); 154 fflush(stdout);
149 input = getc( cin); 155 input = getc(cin);
150 156
151#ifdef BB_FEATURE_USE_TERMIOS 157#ifdef BB_FEATURE_USE_TERMIOS
152 /* Erase the "More" message */ 158 /* Erase the "More" message */
153 while(--len >= 0) 159 while (--len >= 0)
154 putc('\b', stdout); 160 putc('\b', stdout);
155 while(++len <= terminal_width) 161 while (++len <= terminal_width)
156 putc(' ', stdout); 162 putc(' ', stdout);
157 while(--len >= 0) 163 while (--len >= 0)
158 putc('\b', stdout); 164 putc('\b', stdout);
159 fflush(stdout); 165 fflush(stdout);
160#endif 166#endif
161 167
162 } 168 }
163 if (c == '\n' ) { 169 if (c == '\n') {
164 switch(input) { 170 switch (input) {
165 case 'q': 171 case 'q':
166 goto end; 172 goto end;
167 case '\n': 173 case '\n':
168 /* increment by just one line if we are at 174 /* increment by just one line if we are at
169 * the end of this line*/ 175 * the end of this line*/
170 next_page = 1; 176 next_page = 1;
171 break; 177 break;
178 }
179 if (++lines == terminal_height)
180 next_page = 1;
181 }
182 putc(c, stdout);
172 } 183 }
173 if ( ++lines == terminal_height ) 184 fclose(file);
174 next_page = 1; 185 fflush(stdout);
175 }
176 putc(c, stdout);
177 }
178 fclose(file);
179 fflush(stdout);
180 186
181 argv++; 187 argv++;
182 } while (--argc > 0); 188 } while (--argc > 0);
183end: 189 end:
184#ifdef BB_FEATURE_USE_TERMIOS 190#ifdef BB_FEATURE_USE_TERMIOS
185 gotsig(0); 191 gotsig(0);
186#endif 192#endif
187 exit(TRUE); 193 exit(TRUE);
188} 194}
189
diff --git a/util-linux/mount.c b/util-linux/mount.c
index 4c9e77be0..c3e3bbd75 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * Mini mount implementation for busybox 3 * Mini mount implementation for busybox
3 * 4 *
@@ -55,357 +56,371 @@
55static int use_loop = 0; 56static int use_loop = 0;
56#endif 57#endif
57 58
58extern const char mtab_file[]; /* Defined in utility.c */ 59extern const char mtab_file[]; /* Defined in utility.c */
59 60
60static const char mount_usage[] = "\tmount [flags]\n" 61static const char mount_usage[] = "\tmount [flags]\n"
61 "\tmount [flags] device directory [-o options,more-options]\n" 62 "\tmount [flags] device directory [-o options,more-options]\n"
62 "\n" 63 "\n" "Flags:\n" "\t-a:\tMount all file systems in fstab.\n"
63 "Flags:\n"
64 "\t-a:\tMount all file systems in fstab.\n"
65#ifdef BB_MTAB 64#ifdef BB_MTAB
66 "\t-f:\t\"Fake\" mount. Add entry to mount table but don't mount it.\n" 65 "\t-f:\t\"Fake\" mount. Add entry to mount table but don't mount it.\n"
67 "\t-n:\tDon't write a mount table entry.\n" 66 "\t-n:\tDon't write a mount table entry.\n"
68#endif 67#endif
69 "\t-o option:\tOne of many filesystem options, listed below.\n" 68 "\t-o option:\tOne of many filesystem options, listed below.\n"
70 "\t-r:\tMount the filesystem read-only.\n" 69 "\t-r:\tMount the filesystem read-only.\n"
71 "\t-t filesystem-type:\tSpecify the filesystem type.\n" 70 "\t-t filesystem-type:\tSpecify the filesystem type.\n"
72 "\t-w:\tMount for reading and writing (default).\n" 71 "\t-w:\tMount for reading and writing (default).\n"
73 "\n" 72 "\n"
74 "Options for use with the \"-o\" flag:\n" 73 "Options for use with the \"-o\" flag:\n"
75 "\tasync / sync:\tWrites are asynchronous / synchronous.\n" 74 "\tasync / sync:\tWrites are asynchronous / synchronous.\n"
76 "\tdev / nodev:\tAllow use of special device files / disallow them.\n" 75 "\tdev / nodev:\tAllow use of special device files / disallow them.\n"
77 "\texec / noexec:\tAllow use of executable files / disallow them.\n" 76 "\texec / noexec:\tAllow use of executable files / disallow them.\n"
78#if defined BB_FEATURE_MOUNT_LOOP 77#if defined BB_FEATURE_MOUNT_LOOP
79 "\tloop: Mounts a file via loop device.\n" 78 "\tloop: Mounts a file via loop device.\n"
80#endif 79#endif
81 "\tsuid / nosuid:\tAllow set-user-id-root programs / disallow them.\n" 80 "\tsuid / nosuid:\tAllow set-user-id-root programs / disallow them.\n"
82 "\tremount: Re-mount a currently-mounted filesystem, changing its flags.\n" 81 "\tremount: Re-mount a currently-mounted filesystem, changing its flags.\n"
83 "\tro / rw: Mount for read-only / read-write.\n" 82 "\tro / rw: Mount for read-only / read-write.\n"
84 "\t" 83 "\t"
85 "There are EVEN MORE flags that are specific to each filesystem.\n" 84
86 "You'll have to see the written documentation for those.\n"; 85 "There are EVEN MORE flags that are specific to each filesystem.\n"
86 "You'll have to see the written documentation for those.\n";
87 87
88 88
89struct mount_options { 89struct mount_options {
90 const char *name; 90 const char *name;
91 unsigned long and; 91 unsigned long and;
92 unsigned long or; 92 unsigned long or;
93}; 93};
94 94
95static const struct mount_options mount_options[] = { 95static const struct mount_options mount_options[] = {
96 {"async", ~MS_SYNCHRONOUS, 0}, 96 {"async", ~MS_SYNCHRONOUS, 0},
97 {"defaults", ~0, 0}, 97 {"defaults", ~0, 0},
98 {"dev", ~MS_NODEV, 0}, 98 {"dev", ~MS_NODEV, 0},
99 {"exec", ~MS_NOEXEC, 0}, 99 {"exec", ~MS_NOEXEC, 0},
100 {"nodev", ~0, MS_NODEV}, 100 {"nodev", ~0, MS_NODEV},
101 {"noexec", ~0, MS_NOEXEC}, 101 {"noexec", ~0, MS_NOEXEC},
102 {"nosuid", ~0, MS_NOSUID}, 102 {"nosuid", ~0, MS_NOSUID},
103 {"remount", ~0, MS_REMOUNT}, 103 {"remount", ~0, MS_REMOUNT},
104 {"ro", ~0, MS_RDONLY}, 104 {"ro", ~0, MS_RDONLY},
105 {"rw", ~MS_RDONLY, 0}, 105 {"rw", ~MS_RDONLY, 0},
106 {"suid", ~MS_NOSUID, 0}, 106 {"suid", ~MS_NOSUID, 0},
107 {"sync", ~0, MS_SYNCHRONOUS}, 107 {"sync", ~0, MS_SYNCHRONOUS},
108 {0, 0, 0} 108 {0, 0, 0}
109}; 109};
110 110
111static int 111static int
112do_mount(char* specialfile, char* dir, char* filesystemtype, 112do_mount(char *specialfile, char *dir, char *filesystemtype,
113 long flags, void* string_flags, int useMtab, int fakeIt, char* mtab_opts) 113 long flags, void *string_flags, int useMtab, int fakeIt,
114 char *mtab_opts)
114{ 115{
115 int status=0; 116 int status = 0;
116 117
117#if defined BB_MTAB 118#if defined BB_MTAB
118 if (fakeIt==FALSE) 119 if (fakeIt == FALSE)
119#endif 120#endif
120 { 121 {
121#if defined BB_FEATURE_MOUNT_LOOP 122#if defined BB_FEATURE_MOUNT_LOOP
122 if (use_loop) { 123 if (use_loop) {
123 int loro = flags & MS_RDONLY; 124 int loro = flags & MS_RDONLY;
124 char *lofile = specialfile; 125 char *lofile = specialfile;
125 specialfile = find_unused_loop_device(); 126
126 if (specialfile == NULL) { 127 specialfile = find_unused_loop_device();
127 fprintf(stderr, "Could not find a spare loop device\n"); 128 if (specialfile == NULL) {
128 return( FALSE); 129 fprintf(stderr, "Could not find a spare loop device\n");
129 } 130 return (FALSE);
130 if (set_loop (specialfile, lofile, 0, &loro)) { 131 }
131 fprintf(stderr, "Could not setup loop device\n"); 132 if (set_loop(specialfile, lofile, 0, &loro)) {
132 return( FALSE); 133 fprintf(stderr, "Could not setup loop device\n");
133 } 134 return (FALSE);
134 if (!(flags & MS_RDONLY) && loro) { /* loop is ro, but wanted rw */ 135 }
135 fprintf(stderr, "WARNING: loop device is read-only\n"); 136 if (!(flags & MS_RDONLY) && loro) { /* loop is ro, but wanted rw */
136 flags &= ~MS_RDONLY; 137 fprintf(stderr, "WARNING: loop device is read-only\n");
137 } 138 flags &= ~MS_RDONLY;
138 } 139 }
140 }
139#endif 141#endif
140 status=mount(specialfile, dir, filesystemtype, flags, string_flags); 142 status =
141 } 143 mount(specialfile, dir, filesystemtype, flags, string_flags);
144 }
142 145
143 146
144 /* If the mount was sucessful, do anything needed, then return TRUE */ 147 /* If the mount was sucessful, do anything needed, then return TRUE */
145 if (status == 0) { 148 if (status == 0) {
146 149
147#if defined BB_MTAB 150#if defined BB_MTAB
148 if (useMtab==TRUE) { 151 if (useMtab == TRUE) {
149 write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts); 152 write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts);
150 } 153 }
151#endif 154#endif
152 return( TRUE); 155 return (TRUE);
153 } 156 }
154 157
155 /* Bummer. mount failed. Clean up */ 158 /* Bummer. mount failed. Clean up */
156#if defined BB_FEATURE_MOUNT_LOOP 159#if defined BB_FEATURE_MOUNT_LOOP
157 if (specialfile != NULL) { 160 if (specialfile != NULL) {
158 del_loop(specialfile); 161 del_loop(specialfile);
159 } 162 }
160#endif 163#endif
161 return( FALSE); 164 return (FALSE);
162} 165}
163 166
164 167
165 168
166#if defined BB_MTAB 169#if defined BB_MTAB
167#define whine_if_fstab_is_missing() {} 170#define whine_if_fstab_is_missing() {}
168#else 171#else
169extern void whine_if_fstab_is_missing() 172extern void whine_if_fstab_is_missing()
170{ 173{
171 struct stat statBuf; 174 struct stat statBuf;
172 if (stat("/etc/fstab", &statBuf) < 0) 175
173 fprintf(stderr, "/etc/fstab file missing -- install one to name /dev/root.\n\n"); 176 if (stat("/etc/fstab", &statBuf) < 0)
177 fprintf(stderr,
178 "/etc/fstab file missing -- install one to name /dev/root.\n\n");
174} 179}
175#endif 180#endif
176 181
177 182
178/* Seperate standard mount options from the nonstandard string options */ 183/* Seperate standard mount options from the nonstandard string options */
179static void 184static void
180parse_mount_options ( char *options, unsigned long *flags, char *strflags) 185parse_mount_options(char *options, unsigned long *flags, char *strflags)
181{ 186{
182 while (options) { 187 while (options) {
183 int gotone=FALSE; 188 int gotone = FALSE;
184 char *comma = strchr (options, ','); 189 char *comma = strchr(options, ',');
185 const struct mount_options* f = mount_options; 190 const struct mount_options *f = mount_options;
186 if (comma) 191
187 *comma = '\0'; 192 if (comma)
188 193 *comma = '\0';
189 while (f->name != 0) { 194
190 if (strcasecmp (f->name, options) == 0) { 195 while (f->name != 0) {
191 196 if (strcasecmp(f->name, options) == 0) {
192 *flags &= f->and; 197
193 *flags |= f->or; 198 *flags &= f->and;
194 gotone=TRUE; 199 *flags |= f->or;
195 break; 200 gotone = TRUE;
196 } 201 break;
197 f++; 202 }
198 } 203 f++;
204 }
199#if defined BB_FEATURE_MOUNT_LOOP 205#if defined BB_FEATURE_MOUNT_LOOP
200 if (gotone==FALSE && !strcasecmp ("loop", options)) { /* loop device support */ 206 if (gotone == FALSE && !strcasecmp("loop", options)) { /* loop device support */
201 use_loop = 1; 207 use_loop = 1;
202 gotone=TRUE; 208 gotone = TRUE;
203 } 209 }
204#endif 210#endif
205 if (*strflags && strflags!= '\0' && gotone==FALSE) { 211 if (*strflags && strflags != '\0' && gotone == FALSE) {
206 char *temp=strflags; 212 char *temp = strflags;
207 temp += strlen (strflags); 213
208 *temp++ = ','; 214 temp += strlen(strflags);
209 *temp++ = '\0'; 215 *temp++ = ',';
210 } 216 *temp++ = '\0';
211 if (gotone==FALSE) 217 }
212 strcat (strflags, options); 218 if (gotone == FALSE)
213 if (comma) { 219 strcat(strflags, options);
214 *comma = ','; 220 if (comma) {
215 options = ++comma; 221 *comma = ',';
216 } else { 222 options = ++comma;
217 break; 223 } else {
224 break;
225 }
218 } 226 }
219 }
220} 227}
221 228
222int 229int
223mount_one(char *blockDevice, char *directory, char *filesystemType, 230mount_one(char *blockDevice, char *directory, char *filesystemType,
224 unsigned long flags, char *string_flags, int useMtab, int fakeIt, char *mtab_opts) 231 unsigned long flags, char *string_flags, int useMtab, int fakeIt,
232 char *mtab_opts)
225{ 233{
226 int status = 0; 234 int status = 0;
227 235
228 char buf[255]; 236 char buf[255];
229 237
230#if defined BB_FEATURE_USE_PROCFS 238#if defined BB_FEATURE_USE_PROCFS
231 if (strcmp(filesystemType, "auto") == 0) { 239 if (strcmp(filesystemType, "auto") == 0) {
232 FILE *f = fopen ("/proc/filesystems", "r"); 240 FILE *f = fopen("/proc/filesystems", "r");
233 241
234 if (f == NULL) 242 if (f == NULL)
235 return( FALSE); 243 return (FALSE);
236 244
237 while (fgets (buf, sizeof (buf), f) != NULL) { 245 while (fgets(buf, sizeof(buf), f) != NULL) {
238 filesystemType = buf; 246 filesystemType = buf;
239 if (*filesystemType == '\t') { // Not a nodev filesystem 247 if (*filesystemType == '\t') { // Not a nodev filesystem
240 248
241 // Add NULL termination to each line 249 // Add NULL termination to each line
242 while (*filesystemType && *filesystemType != '\n') 250 while (*filesystemType && *filesystemType != '\n')
243 filesystemType++; 251 filesystemType++;
244 *filesystemType = '\0'; 252 *filesystemType = '\0';
245 253
246 filesystemType = buf; 254 filesystemType = buf;
247 filesystemType++; // hop past tab 255 filesystemType++; // hop past tab
248 256
249 status = do_mount (blockDevice, directory, filesystemType, 257 status = do_mount(blockDevice, directory, filesystemType,
250 flags | MS_MGC_VAL, string_flags, useMtab, 258 flags | MS_MGC_VAL, string_flags,
251 fakeIt, mtab_opts); 259 useMtab, fakeIt, mtab_opts);
252 if (status == TRUE) 260 if (status == TRUE)
253 break; 261 break;
254 } 262 }
255 } 263 }
256 fclose (f); 264 fclose(f);
257 } else 265 } else
258#endif 266#endif
259 { 267 {
260 status = do_mount (blockDevice, directory, filesystemType, 268 status = do_mount(blockDevice, directory, filesystemType,
261 flags | MS_MGC_VAL, string_flags, useMtab, 269 flags | MS_MGC_VAL, string_flags, useMtab,
262 fakeIt, mtab_opts); 270 fakeIt, mtab_opts);
263 } 271 }
264 272
265 if (status==FALSE) { 273 if (status == FALSE) {
266 fprintf (stderr, "Mounting %s on %s failed: %s\n", 274 fprintf(stderr, "Mounting %s on %s failed: %s\n",
267 blockDevice, directory, strerror(errno)); 275 blockDevice, directory, strerror(errno));
268 return (FALSE); 276 return (FALSE);
269 } 277 }
270 return (TRUE); 278 return (TRUE);
271} 279}
272 280
273extern int mount_main (int argc, char **argv) 281extern int mount_main(int argc, char **argv)
274{ 282{
275 char string_flags_buf[1024]=""; 283 char string_flags_buf[1024] = "";
276 char *string_flags = string_flags_buf; 284 char *string_flags = string_flags_buf;
277 char *extra_opts = string_flags_buf; 285 char *extra_opts = string_flags_buf;
278 unsigned long flags = 0; 286 unsigned long flags = 0;
279 char *filesystemType = "auto"; 287 char *filesystemType = "auto";
280 char *device = NULL; 288 char *device = NULL;
281 char *directory = NULL; 289 char *directory = NULL;
282 int all = FALSE; 290 int all = FALSE;
283 int fakeIt = FALSE; 291 int fakeIt = FALSE;
284 int useMtab = TRUE; 292 int useMtab = TRUE;
285 int i; 293 int i;
286 294
287 /* Only compiled in if BB_MTAB is not defined */ 295 /* Only compiled in if BB_MTAB is not defined */
288 whine_if_fstab_is_missing(); 296 whine_if_fstab_is_missing();
289 297
290 if (argc == 1) { 298 if (argc == 1) {
291 FILE *mountTable = setmntent (mtab_file, "r"); 299 FILE *mountTable = setmntent(mtab_file, "r");
292 if (mountTable) { 300
293 struct mntent *m; 301 if (mountTable) {
294 while ((m = getmntent (mountTable)) != 0) { 302 struct mntent *m;
295 struct fstab* fstabItem; 303
296 char *blockDevice = m->mnt_fsname; 304 while ((m = getmntent(mountTable)) != 0) {
297 /* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */ 305 struct fstab *fstabItem;
298 if (strcmp (blockDevice, "/dev/root") == 0) { 306 char *blockDevice = m->mnt_fsname;
299 fstabItem = getfsfile ("/"); 307
300 if (fstabItem != NULL) 308 /* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
301 blockDevice = fstabItem->fs_spec; 309 if (strcmp(blockDevice, "/dev/root") == 0) {
310 fstabItem = getfsfile("/");
311 if (fstabItem != NULL)
312 blockDevice = fstabItem->fs_spec;
313 }
314 printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir,
315 m->mnt_type, m->mnt_opts);
316 }
317 endmntent(mountTable);
318 } else {
319 perror(mtab_file);
302 } 320 }
303 printf ("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir, 321 exit(TRUE);
304 m->mnt_type, m->mnt_opts);
305 }
306 endmntent (mountTable);
307 } else {
308 perror(mtab_file);
309 } 322 }
310 exit( TRUE); 323
311 } 324
312 325 /* Parse options */
313 326 i = --argc;
314 /* Parse options */ 327 argv++;
315 i = --argc; 328 while (i > 0 && **argv) {
316 argv++; 329 if (**argv == '-') {
317 while (i > 0 && **argv) { 330 char *opt = *argv;
318 if (**argv == '-') { 331
319 char *opt = *argv; 332 while (i > 0 && *++opt)
320 while (i>0 && *++opt) switch (*opt) { 333 switch (*opt) {
321 case 'o': 334 case 'o':
322 if (--i == 0) { 335 if (--i == 0) {
323 goto goodbye; 336 goto goodbye;
324 } 337 }
325 parse_mount_options (*(++argv), &flags, string_flags); 338 parse_mount_options(*(++argv), &flags, string_flags);
326 break; 339 break;
327 case 'r': 340 case 'r':
328 flags |= MS_RDONLY; 341 flags |= MS_RDONLY;
329 break; 342 break;
330 case 't': 343 case 't':
331 if (--i == 0) { 344 if (--i == 0) {
332 goto goodbye; 345 goto goodbye;
333 } 346 }
334 filesystemType = *(++argv); 347 filesystemType = *(++argv);
335 break; 348 break;
336 case 'w': 349 case 'w':
337 flags &= ~MS_RDONLY; 350 flags &= ~MS_RDONLY;
338 break; 351 break;
339 case 'a': 352 case 'a':
340 all = TRUE; 353 all = TRUE;
341 break; 354 break;
342#ifdef BB_MTAB 355#ifdef BB_MTAB
343 case 'f': 356 case 'f':
344 fakeIt = TRUE; 357 fakeIt = TRUE;
345 break; 358 break;
346 case 'n': 359 case 'n':
347 useMtab = FALSE; 360 useMtab = FALSE;
348 break; 361 break;
349#endif 362#endif
350 case 'v': 363 case 'v':
351 case 'h': 364 case 'h':
352 case '-': 365 case '-':
353 goto goodbye; 366 goto goodbye;
354 } 367 }
355 } else { 368 } else {
356 if (device == NULL) 369 if (device == NULL)
357 device = *argv; 370 device = *argv;
358 else if (directory == NULL) 371 else if (directory == NULL)
359 directory = *argv; 372 directory = *argv;
360 else { 373 else {
361 goto goodbye; 374 goto goodbye;
362 } 375 }
376 }
377 i--;
378 argv++;
363 } 379 }
364 i--;
365 argv++;
366 }
367 380
368 if (all == TRUE) { 381 if (all == TRUE) {
369 struct mntent *m; 382 struct mntent *m;
370 FILE *f = setmntent ("/etc/fstab", "r"); 383 FILE *f = setmntent("/etc/fstab", "r");
371 384
372 if (f == NULL) { 385 if (f == NULL) {
373 perror("/etc/fstab"); 386 perror("/etc/fstab");
374 exit( FALSE); 387 exit(FALSE);
375 } 388 }
376 while ((m = getmntent (f)) != NULL) { 389 while ((m = getmntent(f)) != NULL) {
377 // If the file system isn't noauto, and isn't mounted on /, 390 // If the file system isn't noauto, and isn't mounted on /,
378 // and isn't swap or nfs, then mount it 391 // and isn't swap or nfs, then mount it
379 if ((!strstr (m->mnt_opts, "noauto")) && 392 if ((!strstr(m->mnt_opts, "noauto")) &&
380 (m->mnt_dir[1] != '\0') && 393 (m->mnt_dir[1] != '\0') &&
381 (!strstr (m->mnt_type, "swap")) && 394 (!strstr(m->mnt_type, "swap")) &&
382 (!strstr (m->mnt_type, "nfs"))) 395 (!strstr(m->mnt_type, "nfs"))) {
383 { 396 flags = 0;
384 flags = 0; 397 *string_flags = '\0';
385 *string_flags = '\0'; 398 parse_mount_options(m->mnt_opts, &flags, string_flags);
386 parse_mount_options(m->mnt_opts, &flags, string_flags); 399 mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type,
387 mount_one (m->mnt_fsname, m->mnt_dir, m->mnt_type, 400 flags, string_flags, useMtab, fakeIt,
388 flags, string_flags, useMtab, fakeIt, extra_opts); 401 extra_opts);
389 } 402 }
390 } 403 }
391 endmntent (f); 404 endmntent(f);
392 } else { 405 } else {
393 if (device && directory) { 406 if (device && directory) {
394#ifdef BB_NFSMOUNT 407#ifdef BB_NFSMOUNT
395 if (strcmp(filesystemType, "nfs") == 0) { 408 if (strcmp(filesystemType, "nfs") == 0) {
396 if (nfsmount(device, directory, &flags, &extra_opts, &string_flags, 1) != 0) 409 if (nfsmount
397 exit(FALSE); 410 (device, directory, &flags, &extra_opts, &string_flags,
398 } 411 1) != 0)
412 exit(FALSE);
413 }
399#endif 414#endif
400 exit (mount_one (device, directory, filesystemType, 415 exit(mount_one(device, directory, filesystemType,
401 flags, string_flags, useMtab, fakeIt, extra_opts)); 416 flags, string_flags, useMtab, fakeIt,
402 } else { 417 extra_opts));
403 goto goodbye; 418 } else {
419 goto goodbye;
420 }
404 } 421 }
405 } 422 exit(TRUE);
406 exit( TRUE);
407 423
408goodbye: 424 goodbye:
409 usage( mount_usage); 425 usage(mount_usage);
410} 426}
411
diff --git a/util-linux/nfsmount.c b/util-linux/nfsmount.c
index f2bd2f49c..03ce58447 100644
--- a/util-linux/nfsmount.c
+++ b/util-linux/nfsmount.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * nfsmount.c -- Linux NFS mount 3 * nfsmount.c -- Linux NFS mount
3 * Copyright (C) 1993 Rick Sladkey <jrs@world.std.com> 4 * Copyright (C) 1993 Rick Sladkey <jrs@world.std.com>
@@ -53,7 +54,7 @@
53 54
54#define _ 55#define _
55#define HAVE_inet_aton 56#define HAVE_inet_aton
56#define MS_REMOUNT 32 /* Alter flags of a mounted FS */ 57#define MS_REMOUNT 32 /* Alter flags of a mounted FS */
57#define sloppy 0 58#define sloppy 0
58#define EX_FAIL 1 59#define EX_FAIL 1
59#define EX_BG 1 60#define EX_BG 1
@@ -65,8 +66,8 @@ static char *nfs_strerror(int stat);
65 66
66#define MAKE_VERSION(p,q,r) (65536*(p) + 256*(q) + (r)) 67#define MAKE_VERSION(p,q,r) (65536*(p) + 256*(q) + (r))
67 68
68static int 69static int linux_version_code(void)
69linux_version_code(void) { 70{
70 struct utsname my_utsname; 71 struct utsname my_utsname;
71 int p, q, r; 72 int p, q, r;
72 73
@@ -74,7 +75,7 @@ linux_version_code(void) {
74 p = atoi(strtok(my_utsname.release, ".")); 75 p = atoi(strtok(my_utsname.release, "."));
75 q = atoi(strtok(NULL, ".")); 76 q = atoi(strtok(NULL, "."));
76 r = atoi(strtok(NULL, ".")); 77 r = atoi(strtok(NULL, "."));
77 return MAKE_VERSION(p,q,r); 78 return MAKE_VERSION(p, q, r);
78 } 79 }
79 return 0; 80 return 0;
80} 81}
@@ -95,22 +96,22 @@ static int nfs_mount_version = NFS_MOUNT_VERSION;
95 * NFS_MOUNT_VERSION: these nfsmount sources at compile time 96 * NFS_MOUNT_VERSION: these nfsmount sources at compile time
96 * nfs_mount_version: version this source and running kernel can handle 97 * nfs_mount_version: version this source and running kernel can handle
97 */ 98 */
98static void 99static void find_kernel_nfs_mount_version(void)
99find_kernel_nfs_mount_version(void) { 100{
100 int kernel_version = linux_version_code(); 101 int kernel_version = linux_version_code();
101 102
102 if (kernel_version) { 103 if (kernel_version) {
103 if (kernel_version < MAKE_VERSION(2,1,32)) 104 if (kernel_version < MAKE_VERSION(2, 1, 32))
104 nfs_mount_version = 1; 105 nfs_mount_version = 1;
105 else 106 else
106 nfs_mount_version = 3; 107 nfs_mount_version = 3;
107 } 108 }
108 if (nfs_mount_version > NFS_MOUNT_VERSION) 109 if (nfs_mount_version > NFS_MOUNT_VERSION)
109 nfs_mount_version = NFS_MOUNT_VERSION; 110 nfs_mount_version = NFS_MOUNT_VERSION;
110} 111}
111 112
112int nfsmount(const char *spec, const char *node, unsigned long *flags, 113int nfsmount(const char *spec, const char *node, unsigned long *flags,
113 char **extra_opts, char **mount_opts, int running_bg) 114 char **extra_opts, char **mount_opts, int running_bg)
114{ 115{
115 static char *prev_bg_host; 116 static char *prev_bg_host;
116 char hostdir[1024]; 117 char hostdir[1024];
@@ -118,7 +119,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
118 char *hostname; 119 char *hostname;
119 char *dirname; 120 char *dirname;
120 char *old_opts; 121 char *old_opts;
121 char *mounthost=NULL; 122 char *mounthost = NULL;
122 char new_opts[1024]; 123 char new_opts[1024];
123 fhandle root_fhandle; 124 fhandle root_fhandle;
124 struct timeval total_timeout; 125 struct timeval total_timeout;
@@ -161,7 +162,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
161 mclient = NULL; 162 mclient = NULL;
162 if (strlen(spec) >= sizeof(hostdir)) { 163 if (strlen(spec) >= sizeof(hostdir)) {
163 fprintf(stderr, _("mount: " 164 fprintf(stderr, _("mount: "
164 "excessively long host:dir argument\n")); 165 "excessively long host:dir argument\n"));
165 goto fail; 166 goto fail;
166 } 167 }
167 strcpy(hostdir, spec); 168 strcpy(hostdir, spec);
@@ -174,11 +175,11 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
174 if ((s = strchr(hostdir, ','))) { 175 if ((s = strchr(hostdir, ','))) {
175 *s = '\0'; 176 *s = '\0';
176 fprintf(stderr, _("mount: warning: " 177 fprintf(stderr, _("mount: warning: "
177 "multiple hostnames not supported\n")); 178 "multiple hostnames not supported\n"));
178 } 179 }
179 } else { 180 } else {
180 fprintf(stderr, _("mount: " 181 fprintf(stderr, _("mount: "
181 "directory to mount not in host:dir format\n")); 182 "directory to mount not in host:dir format\n"));
182 goto fail; 183 goto fail;
183 } 184 }
184 185
@@ -189,20 +190,18 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
189 { 190 {
190 if ((hp = gethostbyname(hostname)) == NULL) { 191 if ((hp = gethostbyname(hostname)) == NULL) {
191 fprintf(stderr, _("mount: can't get address for %s\n"), 192 fprintf(stderr, _("mount: can't get address for %s\n"),
192 hostname); 193 hostname);
193 goto fail; 194 goto fail;
194 } else { 195 } else {
195 if (hp->h_length > sizeof(struct in_addr)) { 196 if (hp->h_length > sizeof(struct in_addr)) {
196 fprintf(stderr, 197 fprintf(stderr, _("mount: got bad hp->h_length\n"));
197 _("mount: got bad hp->h_length\n"));
198 hp->h_length = sizeof(struct in_addr); 198 hp->h_length = sizeof(struct in_addr);
199 } 199 }
200 memcpy(&server_addr.sin_addr, 200 memcpy(&server_addr.sin_addr, hp->h_addr, hp->h_length);
201 hp->h_addr, hp->h_length);
202 } 201 }
203 } 202 }
204 203
205 memcpy (&mount_server_addr, &server_addr, sizeof (mount_server_addr)); 204 memcpy(&mount_server_addr, &server_addr, sizeof(mount_server_addr));
206 205
207 /* add IP address to mtab options for use when unmounting */ 206 /* add IP address to mtab options for use when unmounting */
208 207
@@ -211,12 +210,10 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
211 if (!old_opts) 210 if (!old_opts)
212 old_opts = ""; 211 old_opts = "";
213 if (strlen(old_opts) + strlen(s) + 10 >= sizeof(new_opts)) { 212 if (strlen(old_opts) + strlen(s) + 10 >= sizeof(new_opts)) {
214 fprintf(stderr, _("mount: " 213 fprintf(stderr, _("mount: " "excessively long option argument\n"));
215 "excessively long option argument\n"));
216 goto fail; 214 goto fail;
217 } 215 }
218 sprintf(new_opts, "%s%saddr=%s", 216 sprintf(new_opts, "%s%saddr=%s", old_opts, *old_opts ? "," : "", s);
219 old_opts, *old_opts ? "," : "", s);
220 *extra_opts = xstrdup(new_opts); 217 *extra_opts = xstrdup(new_opts);
221 218
222 /* Set default options. 219 /* Set default options.
@@ -224,13 +221,13 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
224 * let the kernel decide. 221 * let the kernel decide.
225 * timeo is filled in after we know whether it'll be TCP or UDP. */ 222 * timeo is filled in after we know whether it'll be TCP or UDP. */
226 memset(&data, 0, sizeof(data)); 223 memset(&data, 0, sizeof(data));
227 data.retrans = 3; 224 data.retrans = 3;
228 data.acregmin = 3; 225 data.acregmin = 3;
229 data.acregmax = 60; 226 data.acregmax = 60;
230 data.acdirmin = 30; 227 data.acdirmin = 30;
231 data.acdirmax = 60; 228 data.acdirmax = 60;
232#if NFS_MOUNT_VERSION >= 2 229#if NFS_MOUNT_VERSION >= 2
233 data.namlen = NAME_MAX; 230 data.namlen = NAME_MAX;
234#endif 231#endif
235 232
236 bg = 0; 233 bg = 0;
@@ -240,7 +237,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
240 nocto = 0; 237 nocto = 0;
241 nolock = 0; 238 nolock = 0;
242 noac = 0; 239 noac = 0;
243 retry = 10000; /* 10000 minutes ~ 1 week */ 240 retry = 10000; /* 10000 minutes ~ 1 week */
244 tcp = 0; 241 tcp = 0;
245 242
246 mountprog = MOUNTPROG; 243 mountprog = MOUNTPROG;
@@ -254,7 +251,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
254 251
255 for (opt = strtok(old_opts, ","); opt; opt = strtok(NULL, ",")) { 252 for (opt = strtok(old_opts, ","); opt; opt = strtok(NULL, ",")) {
256 if ((opteq = strchr(opt, '='))) { 253 if ((opteq = strchr(opt, '='))) {
257 val = atoi(opteq + 1); 254 val = atoi(opteq + 1);
258 *opteq = '\0'; 255 *opteq = '\0';
259 if (!strcmp(opt, "rsize")) 256 if (!strcmp(opt, "rsize"))
260 data.rsize = val; 257 data.rsize = val;
@@ -277,29 +274,27 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
277 data.acregmax = val; 274 data.acregmax = val;
278 data.acdirmin = val; 275 data.acdirmin = val;
279 data.acdirmax = val; 276 data.acdirmax = val;
280 } 277 } else if (!strcmp(opt, "retry"))
281 else if (!strcmp(opt, "retry"))
282 retry = val; 278 retry = val;
283 else if (!strcmp(opt, "port")) 279 else if (!strcmp(opt, "port"))
284 port = val; 280 port = val;
285 else if (!strcmp(opt, "mountport")) 281 else if (!strcmp(opt, "mountport"))
286 mountport = val; 282 mountport = val;
287 else if (!strcmp(opt, "mounthost")) 283 else if (!strcmp(opt, "mounthost"))
288 mounthost=xstrndup(opteq+1, 284 mounthost = xstrndup(opteq + 1,
289 strcspn(opteq+1," \t\n\r,")); 285 strcspn(opteq + 1, " \t\n\r,"));
290 else if (!strcmp(opt, "mountprog")) 286 else if (!strcmp(opt, "mountprog"))
291 mountprog = val; 287 mountprog = val;
292 else if (!strcmp(opt, "mountvers")) 288 else if (!strcmp(opt, "mountvers"))
293 mountvers = val; 289 mountvers = val;
294 else if (!strcmp(opt, "nfsprog")) 290 else if (!strcmp(opt, "nfsprog"))
295 nfsprog = val; 291 nfsprog = val;
296 else if (!strcmp(opt, "nfsvers") || 292 else if (!strcmp(opt, "nfsvers") || !strcmp(opt, "vers"))
297 !strcmp(opt, "vers"))
298 nfsvers = val; 293 nfsvers = val;
299 else if (!strcmp(opt, "proto")) { 294 else if (!strcmp(opt, "proto")) {
300 if (!strncmp(opteq+1, "tcp", 3)) 295 if (!strncmp(opteq + 1, "tcp", 3))
301 tcp = 1; 296 tcp = 1;
302 else if (!strncmp(opteq+1, "udp", 3)) 297 else if (!strncmp(opteq + 1, "udp", 3))
303 tcp = 0; 298 tcp = 0;
304 else 299 else
305 printf(_("Warning: Unrecognized proto= option.\n")); 300 printf(_("Warning: Unrecognized proto= option.\n"));
@@ -309,24 +304,24 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
309 data.namlen = val; 304 data.namlen = val;
310 else 305 else
311#endif 306#endif
312 printf(_("Warning: Option namlen is not supported.\n")); 307 printf(_
308 ("Warning: Option namlen is not supported.\n"));
313 } else if (!strcmp(opt, "addr")) 309 } else if (!strcmp(opt, "addr"))
314 /* ignore */; 310 /* ignore */ ;
315 else { 311 else {
316 printf(_("unknown nfs mount parameter: " 312 printf(_("unknown nfs mount parameter: "
317 "%s=%d\n"), opt, val); 313 "%s=%d\n"), opt, val);
318 goto fail; 314 goto fail;
319 } 315 }
320 } 316 } else {
321 else {
322 val = 1; 317 val = 1;
323 if (!strncmp(opt, "no", 2)) { 318 if (!strncmp(opt, "no", 2)) {
324 val = 0; 319 val = 0;
325 opt += 2; 320 opt += 2;
326 } 321 }
327 if (!strcmp(opt, "bg")) 322 if (!strcmp(opt, "bg"))
328 bg = val; 323 bg = val;
329 else if (!strcmp(opt, "fg")) 324 else if (!strcmp(opt, "fg"))
330 bg = !val; 325 bg = !val;
331 else if (!strcmp(opt, "soft")) 326 else if (!strcmp(opt, "soft"))
332 soft = val; 327 soft = val;
@@ -348,11 +343,12 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
348 if (nfs_mount_version >= 3) 343 if (nfs_mount_version >= 3)
349 nolock = !val; 344 nolock = !val;
350 else 345 else
351 printf(_("Warning: option nolock is not supported.\n")); 346 printf(_
347 ("Warning: option nolock is not supported.\n"));
352 } else { 348 } else {
353 if (!sloppy) { 349 if (!sloppy) {
354 printf(_("unknown nfs mount option: " 350 printf(_("unknown nfs mount option: "
355 "%s%s\n"), val ? "" : "no", opt); 351 "%s%s\n"), val ? "" : "no", opt);
356 goto fail; 352 goto fail;
357 } 353 }
358 } 354 }
@@ -378,22 +374,21 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
378 374
379#ifdef NFS_MOUNT_DEBUG 375#ifdef NFS_MOUNT_DEBUG
380 printf("rsize = %d, wsize = %d, timeo = %d, retrans = %d\n", 376 printf("rsize = %d, wsize = %d, timeo = %d, retrans = %d\n",
381 data.rsize, data.wsize, data.timeo, data.retrans); 377 data.rsize, data.wsize, data.timeo, data.retrans);
382 printf("acreg (min, max) = (%d, %d), acdir (min, max) = (%d, %d)\n", 378 printf("acreg (min, max) = (%d, %d), acdir (min, max) = (%d, %d)\n",
383 data.acregmin, data.acregmax, data.acdirmin, data.acdirmax); 379 data.acregmin, data.acregmax, data.acdirmin, data.acdirmax);
384 printf("port = %d, bg = %d, retry = %d, flags = %.8x\n", 380 printf("port = %d, bg = %d, retry = %d, flags = %.8x\n",
385 port, bg, retry, data.flags); 381 port, bg, retry, data.flags);
386 printf("mountprog = %d, mountvers = %d, nfsprog = %d, nfsvers = %d\n", 382 printf("mountprog = %d, mountvers = %d, nfsprog = %d, nfsvers = %d\n",
387 mountprog, mountvers, nfsprog, nfsvers); 383 mountprog, mountvers, nfsprog, nfsvers);
388 printf("soft = %d, intr = %d, posix = %d, nocto = %d, noac = %d\n", 384 printf("soft = %d, intr = %d, posix = %d, nocto = %d, noac = %d\n",
389 (data.flags & NFS_MOUNT_SOFT) != 0, 385 (data.flags & NFS_MOUNT_SOFT) != 0,
390 (data.flags & NFS_MOUNT_INTR) != 0, 386 (data.flags & NFS_MOUNT_INTR) != 0,
391 (data.flags & NFS_MOUNT_POSIX) != 0, 387 (data.flags & NFS_MOUNT_POSIX) != 0,
392 (data.flags & NFS_MOUNT_NOCTO) != 0, 388 (data.flags & NFS_MOUNT_NOCTO) != 0,
393 (data.flags & NFS_MOUNT_NOAC) != 0); 389 (data.flags & NFS_MOUNT_NOAC) != 0);
394#if NFS_MOUNT_VERSION >= 2 390#if NFS_MOUNT_VERSION >= 2
395 printf("tcp = %d\n", 391 printf("tcp = %d\n", (data.flags & NFS_MOUNT_TCP) != 0);
396 (data.flags & NFS_MOUNT_TCP) != 0);
397#endif 392#endif
398#endif 393#endif
399 394
@@ -409,7 +404,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
409 * give up immediately, to avoid the initial timeout. 404 * give up immediately, to avoid the initial timeout.
410 */ 405 */
411 if (bg && !running_bg && 406 if (bg && !running_bg &&
412 prev_bg_host && strcmp(hostname, prev_bg_host) == 0) { 407 prev_bg_host && strcmp(hostname, prev_bg_host) == 0) {
413 if (retry > 0) 408 if (retry > 0)
414 retval = EX_BG; 409 retval = EX_BG;
415 return retval; 410 return retval;
@@ -418,25 +413,24 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
418 /* create mount deamon client */ 413 /* create mount deamon client */
419 /* See if the nfs host = mount host. */ 414 /* See if the nfs host = mount host. */
420 if (mounthost) { 415 if (mounthost) {
421 if (mounthost[0] >= '0' && mounthost[0] <= '9') { 416 if (mounthost[0] >= '0' && mounthost[0] <= '9') {
422 mount_server_addr.sin_family = AF_INET; 417 mount_server_addr.sin_family = AF_INET;
423 mount_server_addr.sin_addr.s_addr = inet_addr(hostname); 418 mount_server_addr.sin_addr.s_addr = inet_addr(hostname);
424 } else { 419 } else {
425 if ((hp = gethostbyname(mounthost)) == NULL) { 420 if ((hp = gethostbyname(mounthost)) == NULL) {
426 fprintf(stderr, _("mount: can't get address for %s\n"), 421 fprintf(stderr, _("mount: can't get address for %s\n"),
427 hostname); 422 hostname);
428 goto fail; 423 goto fail;
429 } else { 424 } else {
430 if (hp->h_length > sizeof(struct in_addr)) { 425 if (hp->h_length > sizeof(struct in_addr)) {
431 fprintf(stderr, 426 fprintf(stderr, _("mount: got bad hp->h_length?\n"));
432 _("mount: got bad hp->h_length?\n")); 427 hp->h_length = sizeof(struct in_addr);
433 hp->h_length = sizeof(struct in_addr); 428 }
434 } 429 mount_server_addr.sin_family = AF_INET;
435 mount_server_addr.sin_family = AF_INET; 430 memcpy(&mount_server_addr.sin_addr,
436 memcpy(&mount_server_addr.sin_addr, 431 hp->h_addr, hp->h_length);
437 hp->h_addr, hp->h_length); 432 }
438 } 433 }
439 }
440 } 434 }
441 435
442 /* 436 /*
@@ -466,7 +460,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
466 for (;;) { 460 for (;;) {
467 if (bg && stat(node, &statbuf) == -1) { 461 if (bg && stat(node, &statbuf) == -1) {
468 if (running_bg) { 462 if (running_bg) {
469 sleep(val); /* 1, 2, 4, 8, 16, 30, ... */ 463 sleep(val); /* 1, 2, 4, 8, 16, 30, ... */
470 val *= 2; 464 val *= 2;
471 if (val > 30) 465 if (val > 30)
472 val = 30; 466 val = 30;
@@ -480,24 +474,24 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
480 mount_server_addr.sin_port = htons(mountport); 474 mount_server_addr.sin_port = htons(mountport);
481 msock = RPC_ANYSOCK; 475 msock = RPC_ANYSOCK;
482 mclient = clnttcp_create(&mount_server_addr, 476 mclient = clnttcp_create(&mount_server_addr,
483 mountprog, mountvers, 477 mountprog, mountvers, &msock, 0, 0);
484 &msock, 0, 0);
485 478
486 /* if this fails, contact the mount daemon via UDP */ 479 /* if this fails, contact the mount daemon via UDP */
487 if (!mclient) { 480 if (!mclient) {
488 mount_server_addr.sin_port = htons(mountport); 481 mount_server_addr.sin_port = htons(mountport);
489 msock = RPC_ANYSOCK; 482 msock = RPC_ANYSOCK;
490 mclient = clntudp_create(&mount_server_addr, 483 mclient = clntudp_create(&mount_server_addr,
491 mountprog, mountvers, 484 mountprog, mountvers,
492 retry_timeout, &msock); 485 retry_timeout, &msock);
493 } 486 }
494 if (mclient) { 487 if (mclient) {
495 /* try to mount hostname:dirname */ 488 /* try to mount hostname:dirname */
496 mclient->cl_auth = authunix_create_default(); 489 mclient->cl_auth = authunix_create_default();
497 clnt_stat = clnt_call(mclient, MOUNTPROC_MNT, 490 clnt_stat = clnt_call(mclient, MOUNTPROC_MNT,
498 (xdrproc_t) xdr_dirpath, (caddr_t) &dirname, 491 (xdrproc_t) xdr_dirpath,
499 (xdrproc_t) xdr_fhstatus, (caddr_t) &status, 492 (caddr_t) & dirname,
500 total_timeout); 493 (xdrproc_t) xdr_fhstatus,
494 (caddr_t) & status, total_timeout);
501 if (clnt_stat == RPC_SUCCESS) 495 if (clnt_stat == RPC_SUCCESS)
502 break; /* we're done */ 496 break; /* we're done */
503 if (errno != ECONNREFUSED) { 497 if (errno != ECONNREFUSED) {
@@ -517,7 +511,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
517 prevt = t; 511 prevt = t;
518 } 512 }
519 if (!bg) 513 if (!bg)
520 goto fail; 514 goto fail;
521 if (!running_bg) { 515 if (!running_bg) {
522 prev_bg_host = xstrdup(hostname); 516 prev_bg_host = xstrdup(hostname);
523 if (retry > 0) 517 if (retry > 0)
@@ -531,18 +525,18 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
531 525
532 if (status.fhs_status != 0) { 526 if (status.fhs_status != 0) {
533 fprintf(stderr, 527 fprintf(stderr,
534 _("mount: %s:%s failed, reason given by server: %s\n"), 528 _("mount: %s:%s failed, reason given by server: %s\n"),
535 hostname, dirname, nfs_strerror(status.fhs_status)); 529 hostname, dirname, nfs_strerror(status.fhs_status));
536 goto fail; 530 goto fail;
537 } 531 }
538 memcpy((char *) &root_fhandle, (char *) status.fhstatus_u.fhs_fhandle, 532 memcpy((char *) &root_fhandle, (char *) status.fhstatus_u.fhs_fhandle,
539 sizeof (root_fhandle)); 533 sizeof(root_fhandle));
540 534
541 /* create nfs socket for kernel */ 535 /* create nfs socket for kernel */
542 536
543 if (tcp) { 537 if (tcp) {
544 if (nfs_mount_version < 3) { 538 if (nfs_mount_version < 3) {
545 printf(_("NFS over TCP is not supported.\n")); 539 printf(_("NFS over TCP is not supported.\n"));
546 goto fail; 540 goto fail;
547 } 541 }
548 fsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 542 fsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
@@ -559,7 +553,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
559 if (port == 0) { 553 if (port == 0) {
560 server_addr.sin_port = PMAPPORT; 554 server_addr.sin_port = PMAPPORT;
561 port = pmap_getport(&server_addr, nfsprog, nfsvers, 555 port = pmap_getport(&server_addr, nfsprog, nfsvers,
562 tcp ? IPPROTO_TCP : IPPROTO_UDP); 556 tcp ? IPPROTO_TCP : IPPROTO_UDP);
563 if (port == 0) 557 if (port == 0)
564 port = NFS_PORT; 558 port = NFS_PORT;
565#ifdef NFS_MOUNT_DEBUG 559#ifdef NFS_MOUNT_DEBUG
@@ -571,14 +565,14 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
571 printf(_("using port %d for nfs deamon\n"), port); 565 printf(_("using port %d for nfs deamon\n"), port);
572#endif 566#endif
573 server_addr.sin_port = htons(port); 567 server_addr.sin_port = htons(port);
574 /* 568 /*
575 * connect() the socket for kernels 1.3.10 and below only, 569 * connect() the socket for kernels 1.3.10 and below only,
576 * to avoid problems with multihomed hosts. 570 * to avoid problems with multihomed hosts.
577 * --Swen 571 * --Swen
578 */ 572 */
579 if (linux_version_code() <= 66314 573 if (linux_version_code() <= 66314
580 && connect(fsock, (struct sockaddr *) &server_addr, 574 && connect(fsock, (struct sockaddr *) &server_addr,
581 sizeof (server_addr)) < 0) { 575 sizeof(server_addr)) < 0) {
582 perror(_("nfs connect")); 576 perror(_("nfs connect"));
583 goto fail; 577 goto fail;
584 } 578 }
@@ -587,7 +581,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
587 581
588 data.fd = fsock; 582 data.fd = fsock;
589 memcpy((char *) &data.root, (char *) &root_fhandle, 583 memcpy((char *) &data.root, (char *) &root_fhandle,
590 sizeof (root_fhandle)); 584 sizeof(root_fhandle));
591 memcpy((char *) &data.addr, (char *) &server_addr, sizeof(data.addr)); 585 memcpy((char *) &data.addr, (char *) &server_addr, sizeof(data.addr));
592 strncpy(data.hostname, hostname, sizeof(data.hostname)); 586 strncpy(data.hostname, hostname, sizeof(data.hostname));
593 587
@@ -600,7 +594,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
600 594
601 /* abort */ 595 /* abort */
602 596
603fail: 597 fail:
604 if (msock != -1) { 598 if (msock != -1) {
605 if (mclient) { 599 if (mclient) {
606 auth_destroy(mclient->cl_auth); 600 auth_destroy(mclient->cl_auth);
@@ -611,7 +605,7 @@ fail:
611 if (fsock != -1) 605 if (fsock != -1)
612 close(fsock); 606 close(fsock);
613 return retval; 607 return retval;
614} 608}
615 609
616/* 610/*
617 * We need to translate between nfs status return values and 611 * We need to translate between nfs status return values and
@@ -630,33 +624,37 @@ static struct {
630 enum nfs_stat stat; 624 enum nfs_stat stat;
631 int errnum; 625 int errnum;
632} nfs_errtbl[] = { 626} nfs_errtbl[] = {
633 { NFS_OK, 0 }, 627 {
634 { NFSERR_PERM, EPERM }, 628 NFS_OK, 0}, {
635 { NFSERR_NOENT, ENOENT }, 629 NFSERR_PERM, EPERM}, {
636 { NFSERR_IO, EIO }, 630 NFSERR_NOENT, ENOENT}, {
637 { NFSERR_NXIO, ENXIO }, 631 NFSERR_IO, EIO}, {
638 { NFSERR_ACCES, EACCES }, 632 NFSERR_NXIO, ENXIO}, {
639 { NFSERR_EXIST, EEXIST }, 633 NFSERR_ACCES, EACCES}, {
640 { NFSERR_NODEV, ENODEV }, 634 NFSERR_EXIST, EEXIST}, {
641 { NFSERR_NOTDIR, ENOTDIR }, 635 NFSERR_NODEV, ENODEV}, {
642 { NFSERR_ISDIR, EISDIR }, 636 NFSERR_NOTDIR, ENOTDIR}, {
637 NFSERR_ISDIR, EISDIR},
643#ifdef NFSERR_INVAL 638#ifdef NFSERR_INVAL
644 { NFSERR_INVAL, EINVAL }, /* that Sun forgot */ 639 {
640 NFSERR_INVAL, EINVAL}, /* that Sun forgot */
645#endif 641#endif
646 { NFSERR_FBIG, EFBIG }, 642 {
647 { NFSERR_NOSPC, ENOSPC }, 643 NFSERR_FBIG, EFBIG}, {
648 { NFSERR_ROFS, EROFS }, 644 NFSERR_NOSPC, ENOSPC}, {
649 { NFSERR_NAMETOOLONG, ENAMETOOLONG }, 645 NFSERR_ROFS, EROFS}, {
650 { NFSERR_NOTEMPTY, ENOTEMPTY }, 646 NFSERR_NAMETOOLONG, ENAMETOOLONG}, {
651 { NFSERR_DQUOT, EDQUOT }, 647 NFSERR_NOTEMPTY, ENOTEMPTY}, {
652 { NFSERR_STALE, ESTALE }, 648 NFSERR_DQUOT, EDQUOT}, {
649 NFSERR_STALE, ESTALE},
653#ifdef EWFLUSH 650#ifdef EWFLUSH
654 { NFSERR_WFLUSH, EWFLUSH }, 651 {
652 NFSERR_WFLUSH, EWFLUSH},
655#endif 653#endif
656 /* Throw in some NFSv3 values for even more fun (HP returns these) */ 654 /* Throw in some NFSv3 values for even more fun (HP returns these) */
657 { 71, EREMOTE }, 655 {
658 656 71, EREMOTE}, {
659 { -1, EIO } 657 -1, EIO}
660}; 658};
661 659
662static char *nfs_strerror(int stat) 660static char *nfs_strerror(int stat)
@@ -673,33 +671,32 @@ static char *nfs_strerror(int stat)
673} 671}
674 672
675#if 0 673#if 0
676int 674int my_getport(struct in_addr server, struct timeval *timeo, ...)
677my_getport(struct in_addr server, struct timeval *timeo, ...)
678{ 675{
679 struct sockaddr_in sin; 676 struct sockaddr_in sin;
680 struct pmap pmap; 677 struct pmap pmap;
681 CLIENT *clnt; 678 CLIENT *clnt;
682 int sock = RPC_ANYSOCK, port; 679 int sock = RPC_ANYSOCK, port;
683 680
684 pmap.pm_prog = prog; 681 pmap.pm_prog = prog;
685 pmap.pm_vers = vers; 682 pmap.pm_vers = vers;
686 pmap.pm_prot = prot; 683 pmap.pm_prot = prot;
687 pmap.pm_port = 0; 684 pmap.pm_port = 0;
688 sin.sin_family = AF_INET; 685 sin.sin_family = AF_INET;
689 sin.sin_addr = server; 686 sin.sin_addr = server;
690 sin.sin_port = htons(111); 687 sin.sin_port = htons(111);
691 clnt = clntudp_create(&sin, 100000, 2, *timeo, &sock); 688 clnt = clntudp_create(&sin, 100000, 2, *timeo, &sock);
692 status = clnt_call(clnt, PMAP_GETPORT, 689 status = clnt_call(clnt, PMAP_GETPORT,
693 &pmap, (xdrproc_t) xdr_pmap, 690 &pmap, (xdrproc_t) xdr_pmap,
694 &port, (xdrproc_t) xdr_uint); 691 &port, (xdrproc_t) xdr_uint);
695 if (status != SUCCESS) { 692 if (status != SUCCESS) {
696 /* natter */ 693 /* natter */
697 port = 0; 694 port = 0;
698 } 695 }
699 696
700 clnt_destroy(clnt); 697 clnt_destroy(clnt);
701 close(sock); 698 close(sock);
702 return port; 699 return port;
703} 700}
704#endif 701#endif
705 702
@@ -756,28 +753,26 @@ my_getport(struct in_addr server, struct timeval *timeo, ...)
756 753
757/* from @(#)mount.x 1.3 91/03/11 TIRPC 1.0 */ 754/* from @(#)mount.x 1.3 91/03/11 TIRPC 1.0 */
758 755
759bool_t 756bool_t xdr_fhandle(XDR * xdrs, fhandle objp)
760xdr_fhandle(XDR *xdrs, fhandle objp)
761{ 757{
762 758
763 if (!xdr_opaque(xdrs, objp, FHSIZE)) { 759 if (!xdr_opaque(xdrs, objp, FHSIZE)) {
764 return (FALSE); 760 return (FALSE);
765 } 761 }
766 return (TRUE); 762 return (TRUE);
767} 763}
768 764
769bool_t 765bool_t xdr_fhstatus(XDR * xdrs, fhstatus * objp)
770xdr_fhstatus(XDR *xdrs, fhstatus *objp)
771{ 766{
772 767
773 if (!xdr_u_int(xdrs, &objp->fhs_status)) { 768 if (!xdr_u_int(xdrs, &objp->fhs_status)) {
774 return (FALSE); 769 return (FALSE);
775 } 770 }
776 switch (objp->fhs_status) { 771 switch (objp->fhs_status) {
777 case 0: 772 case 0:
778 if (!xdr_fhandle(xdrs, objp->fhstatus_u.fhs_fhandle)) { 773 if (!xdr_fhandle(xdrs, objp->fhstatus_u.fhs_fhandle)) {
779 return (FALSE); 774 return (FALSE);
780 } 775 }
781 break; 776 break;
782 default: 777 default:
783 break; 778 break;
@@ -785,245 +780,246 @@ xdr_fhstatus(XDR *xdrs, fhstatus *objp)
785 return (TRUE); 780 return (TRUE);
786} 781}
787 782
788bool_t 783bool_t xdr_dirpath(XDR * xdrs, dirpath * objp)
789xdr_dirpath(XDR *xdrs, dirpath *objp)
790{ 784{
791 785
792 if (!xdr_string(xdrs, objp, MNTPATHLEN)) { 786 if (!xdr_string(xdrs, objp, MNTPATHLEN)) {
793 return (FALSE); 787 return (FALSE);
794 } 788 }
795 return (TRUE); 789 return (TRUE);
796} 790}
797 791
798bool_t 792bool_t xdr_name(XDR * xdrs, name * objp)
799xdr_name(XDR *xdrs, name *objp)
800{ 793{
801 794
802 if (!xdr_string(xdrs, objp, MNTNAMLEN)) { 795 if (!xdr_string(xdrs, objp, MNTNAMLEN)) {
803 return (FALSE); 796 return (FALSE);
804 } 797 }
805 return (TRUE); 798 return (TRUE);
806} 799}
807 800
808bool_t 801bool_t xdr_mountlist(XDR * xdrs, mountlist * objp)
809xdr_mountlist(XDR *xdrs, mountlist *objp)
810{ 802{
811 803
812 if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct mountbody), (xdrproc_t)xdr_mountbody)) { 804 if (!xdr_pointer
813 return (FALSE); 805 (xdrs, (char **) objp, sizeof(struct mountbody),
814 } 806 (xdrproc_t) xdr_mountbody)) {
807 return (FALSE);
808 }
815 return (TRUE); 809 return (TRUE);
816} 810}
817 811
818bool_t 812bool_t xdr_mountbody(XDR * xdrs, mountbody * objp)
819xdr_mountbody(XDR *xdrs, mountbody *objp)
820{ 813{
821 814
822 if (!xdr_name(xdrs, &objp->ml_hostname)) { 815 if (!xdr_name(xdrs, &objp->ml_hostname)) {
823 return (FALSE); 816 return (FALSE);
824 } 817 }
825 if (!xdr_dirpath(xdrs, &objp->ml_directory)) { 818 if (!xdr_dirpath(xdrs, &objp->ml_directory)) {
826 return (FALSE); 819 return (FALSE);
827 } 820 }
828 if (!xdr_mountlist(xdrs, &objp->ml_next)) { 821 if (!xdr_mountlist(xdrs, &objp->ml_next)) {
829 return (FALSE); 822 return (FALSE);
830 } 823 }
831 return (TRUE); 824 return (TRUE);
832} 825}
833 826
834bool_t 827bool_t xdr_groups(XDR * xdrs, groups * objp)
835xdr_groups(XDR *xdrs, groups *objp)
836{ 828{
837 829
838 if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct groupnode), (xdrproc_t)xdr_groupnode)) { 830 if (!xdr_pointer
839 return (FALSE); 831 (xdrs, (char **) objp, sizeof(struct groupnode),
840 } 832 (xdrproc_t) xdr_groupnode)) {
833 return (FALSE);
834 }
841 return (TRUE); 835 return (TRUE);
842} 836}
843 837
844bool_t 838bool_t xdr_groupnode(XDR * xdrs, groupnode * objp)
845xdr_groupnode(XDR *xdrs, groupnode *objp)
846{ 839{
847 840
848 if (!xdr_name(xdrs, &objp->gr_name)) { 841 if (!xdr_name(xdrs, &objp->gr_name)) {
849 return (FALSE); 842 return (FALSE);
850 } 843 }
851 if (!xdr_groups(xdrs, &objp->gr_next)) { 844 if (!xdr_groups(xdrs, &objp->gr_next)) {
852 return (FALSE); 845 return (FALSE);
853 } 846 }
854 return (TRUE); 847 return (TRUE);
855} 848}
856 849
857bool_t 850bool_t xdr_exports(XDR * xdrs, exports * objp)
858xdr_exports(XDR *xdrs, exports *objp)
859{ 851{
860 852
861 if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct exportnode), (xdrproc_t)xdr_exportnode)) { 853 if (!xdr_pointer
862 return (FALSE); 854 (xdrs, (char **) objp, sizeof(struct exportnode),
863 } 855 (xdrproc_t) xdr_exportnode)) {
856 return (FALSE);
857 }
864 return (TRUE); 858 return (TRUE);
865} 859}
866 860
867bool_t 861bool_t xdr_exportnode(XDR * xdrs, exportnode * objp)
868xdr_exportnode(XDR *xdrs, exportnode *objp)
869{ 862{
870 863
871 if (!xdr_dirpath(xdrs, &objp->ex_dir)) { 864 if (!xdr_dirpath(xdrs, &objp->ex_dir)) {
872 return (FALSE); 865 return (FALSE);
873 } 866 }
874 if (!xdr_groups(xdrs, &objp->ex_groups)) { 867 if (!xdr_groups(xdrs, &objp->ex_groups)) {
875 return (FALSE); 868 return (FALSE);
876 } 869 }
877 if (!xdr_exports(xdrs, &objp->ex_next)) { 870 if (!xdr_exports(xdrs, &objp->ex_next)) {
878 return (FALSE); 871 return (FALSE);
879 } 872 }
880 return (TRUE); 873 return (TRUE);
881} 874}
882 875
883bool_t 876bool_t xdr_ppathcnf(XDR * xdrs, ppathcnf * objp)
884xdr_ppathcnf(XDR *xdrs, ppathcnf *objp)
885{ 877{
886 878
887 register long *buf; 879 register long *buf;
888 880
889 int i; 881 int i;
890 882
891 if (xdrs->x_op == XDR_ENCODE) { 883 if (xdrs->x_op == XDR_ENCODE) {
892 buf = (long*)XDR_INLINE(xdrs,6 * BYTES_PER_XDR_UNIT); 884 buf = (long *) XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT);
893 if (buf == NULL) {
894 if (!xdr_int(xdrs, &objp->pc_link_max)) {
895 return (FALSE);
896 }
897 if (!xdr_short(xdrs, &objp->pc_max_canon)) {
898 return (FALSE);
899 }
900 if (!xdr_short(xdrs, &objp->pc_max_input)) {
901 return (FALSE);
902 }
903 if (!xdr_short(xdrs, &objp->pc_name_max)) {
904 return (FALSE);
905 }
906 if (!xdr_short(xdrs, &objp->pc_path_max)) {
907 return (FALSE);
908 }
909 if (!xdr_short(xdrs, &objp->pc_pipe_buf)) {
910 return (FALSE);
911 }
912
913 }
914 else {
915 IXDR_PUT_LONG(buf,objp->pc_link_max);
916 IXDR_PUT_SHORT(buf,objp->pc_max_canon);
917 IXDR_PUT_SHORT(buf,objp->pc_max_input);
918 IXDR_PUT_SHORT(buf,objp->pc_name_max);
919 IXDR_PUT_SHORT(buf,objp->pc_path_max);
920 IXDR_PUT_SHORT(buf,objp->pc_pipe_buf);
921 }
922 if (!xdr_u_char(xdrs, &objp->pc_vdisable)) {
923 return (FALSE);
924 }
925 if (!xdr_char(xdrs, &objp->pc_xxx)) {
926 return (FALSE);
927 }
928 buf = (long*)XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
929 if (buf == NULL) { 885 if (buf == NULL) {
930 if (!xdr_vector(xdrs, (char *)objp->pc_mask, 2, sizeof(short), (xdrproc_t)xdr_short)) { 886 if (!xdr_int(xdrs, &objp->pc_link_max)) {
931 return (FALSE); 887 return (FALSE);
932 } 888 }
933 889 if (!xdr_short(xdrs, &objp->pc_max_canon)) {
934 } 890 return (FALSE);
935 else { 891 }
936 { register short *genp; 892 if (!xdr_short(xdrs, &objp->pc_max_input)) {
937 for ( i = 0,genp=objp->pc_mask; 893 return (FALSE);
938 i < 2; i++){ 894 }
939 IXDR_PUT_SHORT(buf,*genp++); 895 if (!xdr_short(xdrs, &objp->pc_name_max)) {
940 } 896 return (FALSE);
941 }; 897 }
942 } 898 if (!xdr_short(xdrs, &objp->pc_path_max)) {
943 899 return (FALSE);
944 return (TRUE); 900 }
901 if (!xdr_short(xdrs, &objp->pc_pipe_buf)) {
902 return (FALSE);
903 }
904
905 } else {
906 IXDR_PUT_LONG(buf, objp->pc_link_max);
907 IXDR_PUT_SHORT(buf, objp->pc_max_canon);
908 IXDR_PUT_SHORT(buf, objp->pc_max_input);
909 IXDR_PUT_SHORT(buf, objp->pc_name_max);
910 IXDR_PUT_SHORT(buf, objp->pc_path_max);
911 IXDR_PUT_SHORT(buf, objp->pc_pipe_buf);
912 }
913 if (!xdr_u_char(xdrs, &objp->pc_vdisable)) {
914 return (FALSE);
915 }
916 if (!xdr_char(xdrs, &objp->pc_xxx)) {
917 return (FALSE);
918 }
919 buf = (long *) XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
920 if (buf == NULL) {
921 if (!xdr_vector
922 (xdrs, (char *) objp->pc_mask, 2, sizeof(short),
923 (xdrproc_t) xdr_short)) {
924 return (FALSE);
925 }
926
927 } else {
928 {
929 register short *genp;
930
931 for (i = 0, genp = objp->pc_mask; i < 2; i++) {
932 IXDR_PUT_SHORT(buf, *genp++);
933 }
934 };
935 }
936
937 return (TRUE);
945 } else if (xdrs->x_op == XDR_DECODE) { 938 } else if (xdrs->x_op == XDR_DECODE) {
946 buf = (long*)XDR_INLINE(xdrs,6 * BYTES_PER_XDR_UNIT); 939 buf = (long *) XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT);
947 if (buf == NULL) { 940 if (buf == NULL) {
948 if (!xdr_int(xdrs, &objp->pc_link_max)) { 941 if (!xdr_int(xdrs, &objp->pc_link_max)) {
949 return (FALSE); 942 return (FALSE);
950 } 943 }
951 if (!xdr_short(xdrs, &objp->pc_max_canon)) { 944 if (!xdr_short(xdrs, &objp->pc_max_canon)) {
952 return (FALSE); 945 return (FALSE);
953 } 946 }
954 if (!xdr_short(xdrs, &objp->pc_max_input)) { 947 if (!xdr_short(xdrs, &objp->pc_max_input)) {
955 return (FALSE); 948 return (FALSE);
956 } 949 }
957 if (!xdr_short(xdrs, &objp->pc_name_max)) { 950 if (!xdr_short(xdrs, &objp->pc_name_max)) {
958 return (FALSE); 951 return (FALSE);
959 } 952 }
960 if (!xdr_short(xdrs, &objp->pc_path_max)) { 953 if (!xdr_short(xdrs, &objp->pc_path_max)) {
961 return (FALSE); 954 return (FALSE);
962 } 955 }
963 if (!xdr_short(xdrs, &objp->pc_pipe_buf)) { 956 if (!xdr_short(xdrs, &objp->pc_pipe_buf)) {
964 return (FALSE); 957 return (FALSE);
965 } 958 }
966 959
967 } 960 } else {
968 else { 961 objp->pc_link_max = IXDR_GET_LONG(buf);
969 objp->pc_link_max = IXDR_GET_LONG(buf); 962 objp->pc_max_canon = IXDR_GET_SHORT(buf);
970 objp->pc_max_canon = IXDR_GET_SHORT(buf); 963 objp->pc_max_input = IXDR_GET_SHORT(buf);
971 objp->pc_max_input = IXDR_GET_SHORT(buf); 964 objp->pc_name_max = IXDR_GET_SHORT(buf);
972 objp->pc_name_max = IXDR_GET_SHORT(buf); 965 objp->pc_path_max = IXDR_GET_SHORT(buf);
973 objp->pc_path_max = IXDR_GET_SHORT(buf); 966 objp->pc_pipe_buf = IXDR_GET_SHORT(buf);
974 objp->pc_pipe_buf = IXDR_GET_SHORT(buf); 967 }
975 } 968 if (!xdr_u_char(xdrs, &objp->pc_vdisable)) {
976 if (!xdr_u_char(xdrs, &objp->pc_vdisable)) { 969 return (FALSE);
977 return (FALSE); 970 }
978 } 971 if (!xdr_char(xdrs, &objp->pc_xxx)) {
979 if (!xdr_char(xdrs, &objp->pc_xxx)) { 972 return (FALSE);
980 return (FALSE); 973 }
981 } 974 buf = (long *) XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
982 buf = (long*)XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
983 if (buf == NULL) { 975 if (buf == NULL) {
984 if (!xdr_vector(xdrs, (char *)objp->pc_mask, 2, sizeof(short), (xdrproc_t)xdr_short)) { 976 if (!xdr_vector
985 return (FALSE); 977 (xdrs, (char *) objp->pc_mask, 2, sizeof(short),
986 } 978 (xdrproc_t) xdr_short)) {
987 979 return (FALSE);
988 } 980 }
989 else { 981
990 { register short *genp; 982 } else {
991 for ( i = 0,genp=objp->pc_mask; 983 {
992 i < 2; i++){ 984 register short *genp;
993 *genp++ = IXDR_GET_SHORT(buf); 985
994 } 986 for (i = 0, genp = objp->pc_mask; i < 2; i++) {
995 }; 987 *genp++ = IXDR_GET_SHORT(buf);
996 } 988 }
997 return(TRUE); 989 };
990 }
991 return (TRUE);
998 } 992 }
999 993
1000 if (!xdr_int(xdrs, &objp->pc_link_max)) { 994 if (!xdr_int(xdrs, &objp->pc_link_max)) {
1001 return (FALSE); 995 return (FALSE);
1002 } 996 }
1003 if (!xdr_short(xdrs, &objp->pc_max_canon)) { 997 if (!xdr_short(xdrs, &objp->pc_max_canon)) {
1004 return (FALSE); 998 return (FALSE);
1005 } 999 }
1006 if (!xdr_short(xdrs, &objp->pc_max_input)) { 1000 if (!xdr_short(xdrs, &objp->pc_max_input)) {
1007 return (FALSE); 1001 return (FALSE);
1008 } 1002 }
1009 if (!xdr_short(xdrs, &objp->pc_name_max)) { 1003 if (!xdr_short(xdrs, &objp->pc_name_max)) {
1010 return (FALSE); 1004 return (FALSE);
1011 } 1005 }
1012 if (!xdr_short(xdrs, &objp->pc_path_max)) { 1006 if (!xdr_short(xdrs, &objp->pc_path_max)) {
1013 return (FALSE); 1007 return (FALSE);
1014 } 1008 }
1015 if (!xdr_short(xdrs, &objp->pc_pipe_buf)) { 1009 if (!xdr_short(xdrs, &objp->pc_pipe_buf)) {
1016 return (FALSE); 1010 return (FALSE);
1017 } 1011 }
1018 if (!xdr_u_char(xdrs, &objp->pc_vdisable)) { 1012 if (!xdr_u_char(xdrs, &objp->pc_vdisable)) {
1019 return (FALSE); 1013 return (FALSE);
1020 } 1014 }
1021 if (!xdr_char(xdrs, &objp->pc_xxx)) { 1015 if (!xdr_char(xdrs, &objp->pc_xxx)) {
1022 return (FALSE); 1016 return (FALSE);
1023 } 1017 }
1024 if (!xdr_vector(xdrs, (char *)objp->pc_mask, 2, sizeof(short), (xdrproc_t)xdr_short)) { 1018 if (!xdr_vector
1025 return (FALSE); 1019 (xdrs, (char *) objp->pc_mask, 2, sizeof(short),
1026 } 1020 (xdrproc_t) xdr_short)) {
1021 return (FALSE);
1022 }
1027 return (TRUE); 1023 return (TRUE);
1028} 1024}
1029 1025
@@ -1063,247 +1059,232 @@ xdr_ppathcnf(XDR *xdrs, ppathcnf *objp)
1063 1059
1064/* from @(#)mount.x 1.3 91/03/11 TIRPC 1.0 */ 1060/* from @(#)mount.x 1.3 91/03/11 TIRPC 1.0 */
1065 1061
1066#include <string.h> /* for memset() */ 1062#include <string.h> /* for memset() */
1067 1063
1068/* Default timeout can be changed using clnt_control() */ 1064/* Default timeout can be changed using clnt_control() */
1069static struct timeval TIMEOUT = { 25, 0 }; 1065static struct timeval TIMEOUT = { 25, 0 };
1070 1066
1071void * 1067void *mountproc_null_1(argp, clnt)
1072mountproc_null_1(argp, clnt) 1068void *argp;
1073 void *argp; 1069CLIENT *clnt;
1074 CLIENT *clnt;
1075{ 1070{
1076 static char clnt_res; 1071 static char clnt_res;
1077 1072
1078 memset((char *)&clnt_res, 0, sizeof(clnt_res)); 1073 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1079 if (clnt_call(clnt, MOUNTPROC_NULL, (xdrproc_t) xdr_void, argp, (xdrproc_t) xdr_void, &clnt_res, TIMEOUT) != RPC_SUCCESS) { 1074 if (clnt_call
1075 (clnt, MOUNTPROC_NULL, (xdrproc_t) xdr_void, argp,
1076 (xdrproc_t) xdr_void, &clnt_res, TIMEOUT) != RPC_SUCCESS) {
1080 return (NULL); 1077 return (NULL);
1081 } 1078 }
1082 return ((void *)&clnt_res); 1079 return ((void *) &clnt_res);
1083} 1080}
1084 1081
1085fhstatus * 1082fhstatus *mountproc_mnt_1(argp, clnt)
1086mountproc_mnt_1(argp, clnt) 1083dirpath *argp;
1087 dirpath *argp; 1084CLIENT *clnt;
1088 CLIENT *clnt;
1089{ 1085{
1090 static fhstatus clnt_res; 1086 static fhstatus clnt_res;
1091 1087
1092 memset((char *)&clnt_res, 0, sizeof(clnt_res)); 1088 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1093 if (clnt_call(clnt, MOUNTPROC_MNT, (xdrproc_t) xdr_dirpath, 1089 if (clnt_call(clnt, MOUNTPROC_MNT, (xdrproc_t) xdr_dirpath,
1094 (caddr_t) argp, (xdrproc_t) xdr_fhstatus, 1090 (caddr_t) argp, (xdrproc_t) xdr_fhstatus,
1095 (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { 1091 (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) {
1096 return (NULL); 1092 return (NULL);
1097 } 1093 }
1098 return (&clnt_res); 1094 return (&clnt_res);
1099} 1095}
1100 1096
1101mountlist * 1097mountlist *mountproc_dump_1(argp, clnt)
1102mountproc_dump_1(argp, clnt) 1098void *argp;
1103 void *argp; 1099CLIENT *clnt;
1104 CLIENT *clnt;
1105{ 1100{
1106 static mountlist clnt_res; 1101 static mountlist clnt_res;
1107 1102
1108 memset((char *)&clnt_res, 0, sizeof(clnt_res)); 1103 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1109 if (clnt_call(clnt, MOUNTPROC_DUMP, (xdrproc_t) xdr_void, 1104 if (clnt_call(clnt, MOUNTPROC_DUMP, (xdrproc_t) xdr_void,
1110 (caddr_t) argp, (xdrproc_t) xdr_mountlist, 1105 (caddr_t) argp, (xdrproc_t) xdr_mountlist,
1111 (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { 1106 (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) {
1112 return (NULL); 1107 return (NULL);
1113 } 1108 }
1114 return (&clnt_res); 1109 return (&clnt_res);
1115} 1110}
1116 1111
1117void * 1112void *mountproc_umnt_1(argp, clnt)
1118mountproc_umnt_1(argp, clnt) 1113dirpath *argp;
1119 dirpath *argp; 1114CLIENT *clnt;
1120 CLIENT *clnt;
1121{ 1115{
1122 static char clnt_res; 1116 static char clnt_res;
1123 1117
1124 memset((char *)&clnt_res, 0, sizeof(clnt_res)); 1118 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1125 if (clnt_call(clnt, MOUNTPROC_UMNT, (xdrproc_t) xdr_dirpath, 1119 if (clnt_call(clnt, MOUNTPROC_UMNT, (xdrproc_t) xdr_dirpath,
1126 (caddr_t) argp, (xdrproc_t) xdr_void, 1120 (caddr_t) argp, (xdrproc_t) xdr_void,
1127 (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { 1121 (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) {
1128 return (NULL); 1122 return (NULL);
1129 } 1123 }
1130 return ((void *)&clnt_res); 1124 return ((void *) &clnt_res);
1131} 1125}
1132 1126
1133void * 1127void *mountproc_umntall_1(argp, clnt)
1134mountproc_umntall_1(argp, clnt) 1128void *argp;
1135 void *argp; 1129CLIENT *clnt;
1136 CLIENT *clnt;
1137{ 1130{
1138 static char clnt_res; 1131 static char clnt_res;
1139 1132
1140 memset((char *)&clnt_res, 0, sizeof(clnt_res)); 1133 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1141 if (clnt_call(clnt, MOUNTPROC_UMNTALL, (xdrproc_t) xdr_void, 1134 if (clnt_call(clnt, MOUNTPROC_UMNTALL, (xdrproc_t) xdr_void,
1142 (caddr_t) argp, (xdrproc_t) xdr_void, 1135 (caddr_t) argp, (xdrproc_t) xdr_void,
1143 (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { 1136 (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) {
1144 return (NULL); 1137 return (NULL);
1145 } 1138 }
1146 return ((void *)&clnt_res); 1139 return ((void *) &clnt_res);
1147} 1140}
1148 1141
1149exports * 1142exports *mountproc_export_1(argp, clnt)
1150mountproc_export_1(argp, clnt) 1143void *argp;
1151 void *argp; 1144CLIENT *clnt;
1152 CLIENT *clnt;
1153{ 1145{
1154 static exports clnt_res; 1146 static exports clnt_res;
1155 1147
1156 memset((char *)&clnt_res, 0, sizeof(clnt_res)); 1148 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1157 if (clnt_call(clnt, MOUNTPROC_EXPORT, (xdrproc_t) xdr_void, 1149 if (clnt_call(clnt, MOUNTPROC_EXPORT, (xdrproc_t) xdr_void,
1158 (caddr_t) argp, (xdrproc_t) xdr_exports, 1150 (caddr_t) argp, (xdrproc_t) xdr_exports,
1159 (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { 1151 (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) {
1160 return (NULL); 1152 return (NULL);
1161 } 1153 }
1162 return (&clnt_res); 1154 return (&clnt_res);
1163} 1155}
1164 1156
1165exports * 1157exports *mountproc_exportall_1(argp, clnt)
1166mountproc_exportall_1(argp, clnt) 1158void *argp;
1167 void *argp; 1159CLIENT *clnt;
1168 CLIENT *clnt;
1169{ 1160{
1170 static exports clnt_res; 1161 static exports clnt_res;
1171 1162
1172 memset((char *)&clnt_res, 0, sizeof(clnt_res)); 1163 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1173 if (clnt_call(clnt, MOUNTPROC_EXPORTALL, (xdrproc_t) xdr_void, 1164 if (clnt_call(clnt, MOUNTPROC_EXPORTALL, (xdrproc_t) xdr_void,
1174 (caddr_t) argp, (xdrproc_t) xdr_exports, 1165 (caddr_t) argp, (xdrproc_t) xdr_exports,
1175 (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { 1166 (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) {
1176 return (NULL); 1167 return (NULL);
1177 } 1168 }
1178 return (&clnt_res); 1169 return (&clnt_res);
1179} 1170}
1180 1171
1181void * 1172void *mountproc_null_2(argp, clnt)
1182mountproc_null_2(argp, clnt) 1173void *argp;
1183 void *argp; 1174CLIENT *clnt;
1184 CLIENT *clnt;
1185{ 1175{
1186 static char clnt_res; 1176 static char clnt_res;
1187 1177
1188 memset((char *)&clnt_res, 0, sizeof(clnt_res)); 1178 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1189 if (clnt_call(clnt, MOUNTPROC_NULL, (xdrproc_t) xdr_void, argp, (xdrproc_t) xdr_void, &clnt_res, TIMEOUT) != RPC_SUCCESS) { 1179 if (clnt_call
1180 (clnt, MOUNTPROC_NULL, (xdrproc_t) xdr_void, argp,
1181 (xdrproc_t) xdr_void, &clnt_res, TIMEOUT) != RPC_SUCCESS) {
1190 return (NULL); 1182 return (NULL);
1191 } 1183 }
1192 return ((void *)&clnt_res); 1184 return ((void *) &clnt_res);
1193} 1185}
1194 1186
1195fhstatus * 1187fhstatus *mountproc_mnt_2(argp, clnt)
1196mountproc_mnt_2(argp, clnt) 1188dirpath *argp;
1197 dirpath *argp; 1189CLIENT *clnt;
1198 CLIENT *clnt;
1199{ 1190{
1200 static fhstatus clnt_res; 1191 static fhstatus clnt_res;
1201 1192
1202 memset((char *)&clnt_res, 0, sizeof(clnt_res)); 1193 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1203 if (clnt_call(clnt, MOUNTPROC_MNT, (xdrproc_t) xdr_dirpath, 1194 if (clnt_call(clnt, MOUNTPROC_MNT, (xdrproc_t) xdr_dirpath,
1204 (caddr_t) argp, (xdrproc_t) xdr_fhstatus, 1195 (caddr_t) argp, (xdrproc_t) xdr_fhstatus,
1205 (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { 1196 (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) {
1206 return (NULL); 1197 return (NULL);
1207 } 1198 }
1208 return (&clnt_res); 1199 return (&clnt_res);
1209} 1200}
1210 1201
1211mountlist * 1202mountlist *mountproc_dump_2(argp, clnt)
1212mountproc_dump_2(argp, clnt) 1203void *argp;
1213 void *argp; 1204CLIENT *clnt;
1214 CLIENT *clnt;
1215{ 1205{
1216 static mountlist clnt_res; 1206 static mountlist clnt_res;
1217 1207
1218 memset((char *)&clnt_res, 0, sizeof(clnt_res)); 1208 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1219 if (clnt_call(clnt, MOUNTPROC_DUMP, (xdrproc_t) xdr_void, argp, 1209 if (clnt_call(clnt, MOUNTPROC_DUMP, (xdrproc_t) xdr_void, argp,
1220 (xdrproc_t) xdr_mountlist, (caddr_t) &clnt_res, 1210 (xdrproc_t) xdr_mountlist, (caddr_t) & clnt_res,
1221 TIMEOUT) != RPC_SUCCESS) { 1211 TIMEOUT) != RPC_SUCCESS) {
1222 return (NULL); 1212 return (NULL);
1223 } 1213 }
1224 return (&clnt_res); 1214 return (&clnt_res);
1225} 1215}
1226 1216
1227void * 1217void *mountproc_umnt_2(argp, clnt)
1228mountproc_umnt_2(argp, clnt) 1218dirpath *argp;
1229 dirpath *argp; 1219CLIENT *clnt;
1230 CLIENT *clnt;
1231{ 1220{
1232 static char clnt_res; 1221 static char clnt_res;
1233 1222
1234 memset((char *)&clnt_res, 0, sizeof(clnt_res)); 1223 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1235 if (clnt_call(clnt, MOUNTPROC_UMNT, (xdrproc_t) xdr_dirpath, 1224 if (clnt_call(clnt, MOUNTPROC_UMNT, (xdrproc_t) xdr_dirpath,
1236 (caddr_t) argp, (xdrproc_t) xdr_void, 1225 (caddr_t) argp, (xdrproc_t) xdr_void,
1237 (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { 1226 (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) {
1238 return (NULL); 1227 return (NULL);
1239 } 1228 }
1240 return ((void *)&clnt_res); 1229 return ((void *) &clnt_res);
1241} 1230}
1242 1231
1243void * 1232void *mountproc_umntall_2(argp, clnt)
1244mountproc_umntall_2(argp, clnt) 1233void *argp;
1245 void *argp; 1234CLIENT *clnt;
1246 CLIENT *clnt;
1247{ 1235{
1248 static char clnt_res; 1236 static char clnt_res;
1249 1237
1250 memset((char *)&clnt_res, 0, sizeof(clnt_res)); 1238 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1251 if (clnt_call(clnt, MOUNTPROC_UMNTALL, (xdrproc_t) xdr_void, 1239 if (clnt_call(clnt, MOUNTPROC_UMNTALL, (xdrproc_t) xdr_void,
1252 (caddr_t) argp, (xdrproc_t) xdr_void, 1240 (caddr_t) argp, (xdrproc_t) xdr_void,
1253 (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { 1241 (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) {
1254 return (NULL); 1242 return (NULL);
1255 } 1243 }
1256 return ((void *)&clnt_res); 1244 return ((void *) &clnt_res);
1257} 1245}
1258 1246
1259exports * 1247exports *mountproc_export_2(argp, clnt)
1260mountproc_export_2(argp, clnt) 1248void *argp;
1261 void *argp; 1249CLIENT *clnt;
1262 CLIENT *clnt;
1263{ 1250{
1264 static exports clnt_res; 1251 static exports clnt_res;
1265 1252
1266 memset((char *)&clnt_res, 0, sizeof(clnt_res)); 1253 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1267 if (clnt_call(clnt, MOUNTPROC_EXPORT, (xdrproc_t) xdr_void, 1254 if (clnt_call(clnt, MOUNTPROC_EXPORT, (xdrproc_t) xdr_void,
1268 argp, (xdrproc_t) xdr_exports, (caddr_t) &clnt_res, 1255 argp, (xdrproc_t) xdr_exports, (caddr_t) & clnt_res,
1269 TIMEOUT) != RPC_SUCCESS) { 1256 TIMEOUT) != RPC_SUCCESS) {
1270 return (NULL); 1257 return (NULL);
1271 } 1258 }
1272 return (&clnt_res); 1259 return (&clnt_res);
1273} 1260}
1274 1261
1275exports * 1262exports *mountproc_exportall_2(argp, clnt)
1276mountproc_exportall_2(argp, clnt) 1263void *argp;
1277 void *argp; 1264CLIENT *clnt;
1278 CLIENT *clnt;
1279{ 1265{
1280 static exports clnt_res; 1266 static exports clnt_res;
1281 1267
1282 memset((char *)&clnt_res, 0, sizeof(clnt_res)); 1268 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1283 if (clnt_call(clnt, MOUNTPROC_EXPORTALL, (xdrproc_t) xdr_void, argp, 1269 if (clnt_call(clnt, MOUNTPROC_EXPORTALL, (xdrproc_t) xdr_void, argp,
1284 (xdrproc_t) xdr_exports, (caddr_t) &clnt_res, 1270 (xdrproc_t) xdr_exports, (caddr_t) & clnt_res,
1285 TIMEOUT) != RPC_SUCCESS) { 1271 TIMEOUT) != RPC_SUCCESS) {
1286 return (NULL); 1272 return (NULL);
1287 } 1273 }
1288 return (&clnt_res); 1274 return (&clnt_res);
1289} 1275}
1290 1276
1291ppathcnf * 1277ppathcnf *mountproc_pathconf_2(argp, clnt)
1292mountproc_pathconf_2(argp, clnt) 1278dirpath *argp;
1293 dirpath *argp; 1279CLIENT *clnt;
1294 CLIENT *clnt;
1295{ 1280{
1296 static ppathcnf clnt_res; 1281 static ppathcnf clnt_res;
1297 1282
1298 memset((char *)&clnt_res, 0, sizeof(clnt_res)); 1283 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1299 if (clnt_call(clnt, MOUNTPROC_PATHCONF, (xdrproc_t) xdr_dirpath, 1284 if (clnt_call(clnt, MOUNTPROC_PATHCONF, (xdrproc_t) xdr_dirpath,
1300 (caddr_t) argp, (xdrproc_t) xdr_ppathcnf, 1285 (caddr_t) argp, (xdrproc_t) xdr_ppathcnf,
1301 (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { 1286 (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) {
1302 return (NULL); 1287 return (NULL);
1303 } 1288 }
1304 return (&clnt_res); 1289 return (&clnt_res);
1305} 1290}
1306
1307
1308
1309
diff --git a/util-linux/nfsmount.h b/util-linux/nfsmount.h
index 73c71fc68..64ac617c0 100644
--- a/util-linux/nfsmount.h
+++ b/util-linux/nfsmount.h
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * Please do not edit this file. 3 * Please do not edit this file.
3 * It was generated using rpcgen. 4 * It was generated using rpcgen.
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c
index 3c02bdd42..6bda22277 100644
--- a/util-linux/swaponoff.c
+++ b/util-linux/swaponoff.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * Mini swapon/swapoff implementation for busybox 3 * Mini swapon/swapoff implementation for busybox
3 * 4 *
@@ -32,91 +33,93 @@
32 33
33 34
34static int whichApp; 35static int whichApp;
35static const char* appName; 36static const char *appName;
36 37
37static const char swapoff_usage[] = 38static const char swapoff_usage[] =
38"swapoff device\n" 39
39"\nStop swapping virtual memory pages on the given device.\n"; 40 "swapoff device\n"
40static const char swapon_usage[] = 41 "\nStop swapping virtual memory pages on the given device.\n";
41"swapon device\n" 42static const char swapon_usage[] =
42"\nStart swapping virtual memory pages on the given device.\n"; 43
44 "swapon device\n"
45 "\nStart swapping virtual memory pages on the given device.\n";
43 46
44 47
45#define SWAPON_APP 1 48#define SWAPON_APP 1
46#define SWAPOFF_APP 2 49#define SWAPOFF_APP 2
47 50
48 51
49static void 52static void swap_enable_disable(char *device)
50swap_enable_disable( char *device)
51{ 53{
52 int status; 54 int status;
53 if ( whichApp == SWAPON_APP ) 55
54 status = swapon(device, 0); 56 if (whichApp == SWAPON_APP)
55 else 57 status = swapon(device, 0);
56 status = swapoff(device); 58 else
57 59 status = swapoff(device);
58 if ( status != 0 ) { 60
59 perror(appName); 61 if (status != 0) {
60 exit( FALSE); 62 perror(appName);
61 } 63 exit(FALSE);
64 }
62} 65}
63 66
64static void 67static void do_em_all()
65do_em_all()
66{ 68{
67 struct mntent *m; 69 struct mntent *m;
68 FILE *f = setmntent ("/etc/fstab", "r"); 70 FILE *f = setmntent("/etc/fstab", "r");
69 71
70 if (f == NULL) { 72 if (f == NULL) {
71 perror("/etc/fstab"); 73 perror("/etc/fstab");
72 exit( FALSE); 74 exit(FALSE);
73 } 75 }
74 while ((m = getmntent (f)) != NULL) { 76 while ((m = getmntent(f)) != NULL) {
75 if (!strstr (m->mnt_type, MNTTYPE_SWAP)) { 77 if (!strstr(m->mnt_type, MNTTYPE_SWAP)) {
76 swap_enable_disable( m->mnt_fsname); 78 swap_enable_disable(m->mnt_fsname);
77 } 79 }
78 } 80 }
79 endmntent (f); 81 endmntent(f);
80 exit( TRUE); 82 exit(TRUE);
81} 83}
82 84
83 85
84extern int 86extern int swap_on_off_main(int argc, char **argv)
85swap_on_off_main(int argc, char * * argv)
86{ 87{
87 struct stat statBuf; 88 struct stat statBuf;
88 if (stat("/etc/fstab", &statBuf) < 0) 89
89 fprintf(stderr, "/etc/fstab file missing -- Please install one.\n\n"); 90 if (stat("/etc/fstab", &statBuf) < 0)
90 91 fprintf(stderr,
91 if (strcmp(*argv, "swapon")==0) { 92 "/etc/fstab file missing -- Please install one.\n\n");
92 appName = *argv; 93
93 whichApp = SWAPON_APP; 94 if (strcmp(*argv, "swapon") == 0) {
94 95 appName = *argv;
95 } else { 96 whichApp = SWAPON_APP;
96 appName = *argv; 97
97 whichApp = SWAPOFF_APP; 98 } else {
98 } 99 appName = *argv;
99 100 whichApp = SWAPOFF_APP;
100 if (argc < 2) 101 }
101 goto usage_and_exit; 102
102 argc--; 103 if (argc < 2)
103 argv++;
104
105 /* Parse any options */
106 while (**argv == '-') {
107 while (*++(*argv)) switch (**argv) {
108 case 'a':
109 do_em_all();
110 break;
111 default:
112 goto usage_and_exit; 104 goto usage_and_exit;
105 argc--;
106 argv++;
107
108 /* Parse any options */
109 while (**argv == '-') {
110 while (*++(*argv))
111 switch (**argv) {
112 case 'a':
113 do_em_all();
114 break;
115 default:
116 goto usage_and_exit;
117 }
113 } 118 }
114 } 119 swap_enable_disable(*argv);
115 swap_enable_disable(*argv); 120 exit(TRUE);
116 exit( TRUE);
117 121
118usage_and_exit: 122 usage_and_exit:
119 usage( (whichApp==SWAPON_APP)? swapon_usage : swapoff_usage); 123 usage((whichApp == SWAPON_APP) ? swapon_usage : swapoff_usage);
120 exit( FALSE); 124 exit(FALSE);
121} 125}
122
diff --git a/util-linux/umount.c b/util-linux/umount.c
index b65caf76e..a2ca8c74a 100644
--- a/util-linux/umount.c
+++ b/util-linux/umount.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * Mini umount implementation for busybox 3 * Mini umount implementation for busybox
3 * 4 *
@@ -28,24 +29,23 @@
28#include <fstab.h> 29#include <fstab.h>
29#include <errno.h> 30#include <errno.h>
30 31
31static const char umount_usage[] = 32static const char umount_usage[] =
32"umount [flags] filesystem|directory\n\n" 33 "umount [flags] filesystem|directory\n\n"
33"Flags:\n" 34 "Flags:\n" "\t-a:\tUnmount all file systems"
34"\t-a:\tUnmount all file systems"
35#ifdef BB_MTAB 35#ifdef BB_MTAB
36" in /etc/mtab\n\t-n:\tDon't erase /etc/mtab entries\n" 36 " in /etc/mtab\n\t-n:\tDon't erase /etc/mtab entries\n"
37#else 37#else
38"\n" 38 "\n"
39#endif 39#endif
40#ifdef BB_FEATURE_REMOUNT 40#ifdef BB_FEATURE_REMOUNT
41"\t-r:\tTry to remount devices as read-only if mount is busy\n" 41 "\t-r:\tTry to remount devices as read-only if mount is busy\n"
42#endif 42#endif
43; 43;
44 44
45struct _mtab_entry_t { 45struct _mtab_entry_t {
46 char *device; 46 char *device;
47 char *mountpt; 47 char *mountpt;
48 struct _mtab_entry_t *next; 48 struct _mtab_entry_t *next;
49}; 49};
50 50
51static struct _mtab_entry_t *mtab_cache = NULL; 51static struct _mtab_entry_t *mtab_cache = NULL;
@@ -55,113 +55,112 @@ static struct _mtab_entry_t *mtab_cache = NULL;
55static int useMtab = TRUE; 55static int useMtab = TRUE;
56static int umountAll = FALSE; 56static int umountAll = FALSE;
57static int doRemount = FALSE; 57static int doRemount = FALSE;
58extern const char mtab_file[]; /* Defined in utility.c */ 58extern const char mtab_file[]; /* Defined in utility.c */
59 59
60#define MIN(x,y) (x > y ? x : y) 60#define MIN(x,y) (x > y ? x : y)
61 61
62static int 62static int do_umount(const char *name, int useMtab)
63do_umount(const char* name, int useMtab)
64{ 63{
65 int status; 64 int status;
66 char *blockDevice = mtab_getinfo(name, MTAB_GETDEVICE); 65 char *blockDevice = mtab_getinfo(name, MTAB_GETDEVICE);
67 66
68 if (blockDevice && strcmp(blockDevice, name) == 0) 67 if (blockDevice && strcmp(blockDevice, name) == 0)
69 name = mtab_getinfo(blockDevice, MTAB_GETMOUNTPT); 68 name = mtab_getinfo(blockDevice, MTAB_GETMOUNTPT);
70 69
71 status = umount(name); 70 status = umount(name);
72 71
73#if defined BB_FEATURE_MOUNT_LOOP 72#if defined BB_FEATURE_MOUNT_LOOP
74 if (blockDevice != NULL && !strncmp("/dev/loop", blockDevice, 9)) 73 if (blockDevice != NULL && !strncmp("/dev/loop", blockDevice, 9))
75 /* this was a loop device, delete it */ 74 /* this was a loop device, delete it */
76 del_loop(blockDevice); 75 del_loop(blockDevice);
77#endif 76#endif
78#if defined BB_FEATURE_REMOUNT 77#if defined BB_FEATURE_REMOUNT
79 if ( status != 0 && doRemount == TRUE && errno == EBUSY ) { 78 if (status != 0 && doRemount == TRUE && errno == EBUSY) {
80 status = mount(blockDevice, name, NULL, 79 status = mount(blockDevice, name, NULL,
81 MS_MGC_VAL | MS_REMOUNT | MS_RDONLY, NULL); 80 MS_MGC_VAL | MS_REMOUNT | MS_RDONLY, NULL);
82 if (status == 0) { 81 if (status == 0) {
83 fprintf(stderr, "umount: %s busy - remounted read-only\n", 82 fprintf(stderr, "umount: %s busy - remounted read-only\n",
84 blockDevice); 83 blockDevice);
85 /* TODO: update mtab if BB_MTAB is defined */ 84 /* TODO: update mtab if BB_MTAB is defined */
86 } else { 85 } else {
87 fprintf(stderr, "umount: Cannot remount %s read-only\n", 86 fprintf(stderr, "umount: Cannot remount %s read-only\n",
88 blockDevice); 87 blockDevice);
88 }
89 } 89 }
90 }
91#endif 90#endif
92 if ( status == 0 ) { 91 if (status == 0) {
93#if defined BB_MTAB 92#if defined BB_MTAB
94 if ( useMtab==TRUE ) 93 if (useMtab == TRUE)
95 erase_mtab(name); 94 erase_mtab(name);
96#endif 95#endif
97 return( TRUE); 96 return (TRUE);
98 } 97 }
99 return(FALSE); 98 return (FALSE);
100} 99}
101 100
102static int 101static int umount_all(int useMtab)
103umount_all(int useMtab)
104{ 102{
105 int status = TRUE; 103 int status = TRUE;
106 char *mountpt; 104 char *mountpt;
107 void *iter; 105 void *iter;
108 106
109 for (mountpt = mtab_first(&iter); mountpt; mountpt = mtab_next(&iter)) { 107 for (mountpt = mtab_first(&iter); mountpt; mountpt = mtab_next(&iter)) {
110 status=do_umount (mountpt, useMtab); 108 status = do_umount(mountpt, useMtab);
111 if (status != 0) {
112 /* Don't bother retrying the umount on busy devices */
113 if (errno == EBUSY) {
114 perror(mountpt);
115 continue;
116 }
117 status = do_umount (mountpt, useMtab);
118 if (status != 0) { 109 if (status != 0) {
119 printf ("Couldn't umount %s on %s: %s\n", 110 /* Don't bother retrying the umount on busy devices */
120 mountpt, mtab_getinfo(mountpt, MTAB_GETDEVICE), strerror(errno)); 111 if (errno == EBUSY) {
112 perror(mountpt);
113 continue;
114 }
115 status = do_umount(mountpt, useMtab);
116 if (status != 0) {
117 printf("Couldn't umount %s on %s: %s\n",
118 mountpt, mtab_getinfo(mountpt, MTAB_GETDEVICE),
119 strerror(errno));
120 }
121 } 121 }
122 } 122 }
123 } 123 return (status);
124 return (status);
125} 124}
126 125
127extern int 126extern int umount_main(int argc, char **argv)
128umount_main(int argc, char** argv)
129{ 127{
130 if (argc < 2) { 128 if (argc < 2) {
131 usage( umount_usage); 129 usage(umount_usage);
132 } 130 }
133 131
134 /* Parse any options */ 132 /* Parse any options */
135 while (--argc > 0 && **(++argv) == '-') { 133 while (--argc > 0 && **(++argv) == '-') {
136 while (*++(*argv)) switch (**argv) { 134 while (*++(*argv))
137 case 'a': 135 switch (**argv) {
138 umountAll = TRUE; 136 case 'a':
139 break; 137 umountAll = TRUE;
138 break;
140#ifdef BB_MTAB 139#ifdef BB_MTAB
141 case 'n': 140 case 'n':
142 useMtab = FALSE; 141 useMtab = FALSE;
143 break; 142 break;
144#endif 143#endif
145#ifdef BB_FEATURE_REMOUNT 144#ifdef BB_FEATURE_REMOUNT
146 case 'r': 145 case 'r':
147 doRemount = TRUE; 146 doRemount = TRUE;
148 break; 147 break;
149#endif 148#endif
150 default: 149 default:
151 usage( umount_usage); 150 usage(umount_usage);
151 }
152 }
153
154 mtab_read();
155 if (umountAll == TRUE) {
156 exit(umount_all(useMtab));
157 }
158 if (do_umount(*argv, useMtab) == 0)
159 exit(TRUE);
160 else {
161 perror("umount");
162 exit(FALSE);
152 } 163 }
153 }
154
155 mtab_read();
156 if (umountAll==TRUE) {
157 exit(umount_all(useMtab));
158 }
159 if ( do_umount(*argv,useMtab) == 0 )
160 exit (TRUE);
161 else {
162 perror("umount");
163 exit(FALSE);
164 }
165} 164}
166 165
167 166
@@ -172,79 +171,89 @@ umount_main(int argc, char** argv)
172 */ 171 */
173void mtab_read(void) 172void mtab_read(void)
174{ 173{
175 struct _mtab_entry_t *entry = NULL; 174 struct _mtab_entry_t *entry = NULL;
176 struct mntent *e; 175 struct mntent *e;
177 FILE *fp; 176 FILE *fp;
178 177
179 if (mtab_cache != NULL) return; 178 if (mtab_cache != NULL)
180 179 return;
181 if ((fp = setmntent(mtab_file, "r")) == NULL) { 180
182 fprintf(stderr, "Cannot open %s\n", mtab_file); 181 if ((fp = setmntent(mtab_file, "r")) == NULL) {
183 return; 182 fprintf(stderr, "Cannot open %s\n", mtab_file);
184 } 183 return;
185 while ((e = getmntent(fp))) { 184 }
186 entry = malloc(sizeof(struct _mtab_entry_t)); 185 while ((e = getmntent(fp))) {
187 entry->device = strdup(e->mnt_fsname); 186 entry = malloc(sizeof(struct _mtab_entry_t));
188 entry->mountpt = strdup(e->mnt_dir); 187
189 entry->next = mtab_cache; 188 entry->device = strdup(e->mnt_fsname);
190 mtab_cache = entry; 189 entry->mountpt = strdup(e->mnt_dir);
191 } 190 entry->next = mtab_cache;
192 endmntent(fp); 191 mtab_cache = entry;
192 }
193 endmntent(fp);
193} 194}
194 195
195char *mtab_getinfo(const char *match, const char which) 196char *mtab_getinfo(const char *match, const char which)
196{ 197{
197 struct _mtab_entry_t *cur = mtab_cache; 198 struct _mtab_entry_t *cur = mtab_cache;
198 while (cur) { 199
199 if (strcmp(cur->mountpt, match) == 0 || 200 while (cur) {
200 strcmp(cur->device, match) == 0) { 201 if (strcmp(cur->mountpt, match) == 0 ||
201 if (which == MTAB_GETMOUNTPT) { 202 strcmp(cur->device, match) == 0) {
202 return cur->mountpt; 203 if (which == MTAB_GETMOUNTPT) {
203 } else { 204 return cur->mountpt;
205 } else {
204#if !defined BB_MTAB 206#if !defined BB_MTAB
205 if (strcmp(cur->device, "/dev/root") == 0) { 207 if (strcmp(cur->device, "/dev/root") == 0) {
206 struct fstab* fstabItem; 208 struct fstab *fstabItem;
207 fstabItem = getfsfile ("/"); 209
208 if (fstabItem != NULL) return fstabItem->fs_spec; 210 fstabItem = getfsfile("/");
209 } 211 if (fstabItem != NULL)
212 return fstabItem->fs_spec;
213 }
210#endif 214#endif
211 return cur->device; 215 return cur->device;
212 } 216 }
217 }
218 cur = cur->next;
213 } 219 }
214 cur = cur->next; 220 return NULL;
215 }
216 return NULL;
217} 221}
218 222
219char *mtab_first(void **iter) 223char *mtab_first(void **iter)
220{ 224{
221 struct _mtab_entry_t *mtab_iter; 225 struct _mtab_entry_t *mtab_iter;
222 if (!iter) return NULL; 226
223 mtab_iter = mtab_cache; 227 if (!iter)
224 *iter = (void *)mtab_iter; 228 return NULL;
225 return mtab_next(iter); 229 mtab_iter = mtab_cache;
230 *iter = (void *) mtab_iter;
231 return mtab_next(iter);
226} 232}
227 233
228char *mtab_next(void **iter) 234char *mtab_next(void **iter)
229{ 235{
230 char *mp; 236 char *mp;
231 if (iter == NULL || *iter == NULL) return NULL; 237
232 mp = ((struct _mtab_entry_t *)(*iter))->mountpt; 238 if (iter == NULL || *iter == NULL)
233 *iter = (void *)((struct _mtab_entry_t *)(*iter))->next; 239 return NULL;
234 return mp; 240 mp = ((struct _mtab_entry_t *) (*iter))->mountpt;
241 *iter = (void *) ((struct _mtab_entry_t *) (*iter))->next;
242 return mp;
235} 243}
236 244
237void mtab_free(void) 245void mtab_free(void)
238{ 246{
239 struct _mtab_entry_t *this, *next; 247 struct _mtab_entry_t *this, *next;
240
241 this = mtab_cache;
242 while (this) {
243 next = this->next;
244 if (this->device) free(this->device);
245 if (this->mountpt) free(this->mountpt);
246 free(this);
247 this = next;
248 }
249}
250 248
249 this = mtab_cache;
250 while (this) {
251 next = this->next;
252 if (this->device)
253 free(this->device);
254 if (this->mountpt)
255 free(this->mountpt);
256 free(this);
257 this = next;
258 }
259}