diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-02-08 22:58:47 +0300 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-02-08 22:58:47 +0300 |
commit | e49d5ecbbe51718fa925b6890a735e5937cc2aa2 (patch) | |
tree | c90bda10731ad9333ce3b404f993354c9fc104b8 /util-linux | |
parent | c0bf817bbc5c7867fbe8fb76d5c39f8ee802692f (diff) |
Some formatting updates (ran the code through indent)
-Erik
Diffstat (limited to 'util-linux')
-rw-r--r-- | util-linux/dmesg.c | 160 | ||||
-rw-r--r-- | util-linux/fbset.c | 360 | ||||
-rw-r--r-- | util-linux/fdflush.c | 36 | ||||
-rw-r--r-- | util-linux/fsck_minix.c | 716 | ||||
-rw-r--r-- | util-linux/mkfs_minix.c | 499 | ||||
-rw-r--r-- | util-linux/mkswap.c | 197 | ||||
-rw-r--r-- | util-linux/more.c | 199 | ||||
-rw-r--r-- | util-linux/mount.c | 581 | ||||
-rw-r--r-- | util-linux/nfsmount.c | 933 | ||||
-rw-r--r-- | util-linux/nfsmount.h | 1 | ||||
-rw-r--r-- | util-linux/swaponoff.c | 131 | ||||
-rw-r--r-- | util-linux/umount.c | 291 |
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 @@ +/* vi: set sw=4 ts=4: */ /* dmesg.c -- Print out the contents of the kernel ring buffer * Created: Sat Oct 9 16:19:47 1993 * Revised: Thu Oct 28 21:52:17 1993 by faith@cs.unc.edu @@ -24,8 +25,8 @@ #ifndef __alpha__ # define __NR_klogctl __NR_syslog - static inline _syscall3(int, klogctl, int, type, char *, b, int, len); -#else /* __alpha__ */ +static inline _syscall3(int, klogctl, int, type, char *, b, int, len); +#else /* __alpha__ */ #define klogctl syslog #endif @@ -35,90 +36,91 @@ static const char dmesg_usage[] = "dmesg [-c] [-n level] [-s bufsize]\n"; -int dmesg_main( int argc, char** argv ) +int dmesg_main(int argc, char **argv) { - char *buf; - int bufsize=8196; - int i; - int n; - int level = 0; - int lastc; - int cmd = 3; - int stopDoingThat; + char *buf; + int bufsize = 8196; + int i; + int n; + int level = 0; + int lastc; + int cmd = 3; + int stopDoingThat; - argc--; - argv++; + argc--; + argv++; - /* Parse any options */ - while (argc && **argv == '-') { - stopDoingThat = FALSE; - while (stopDoingThat == FALSE && *++(*argv)) { - switch (**argv) { - case 'c': - cmd = 4; - break; - case 'n': - cmd = 8; - if (--argc == 0) - goto end; - level = atoi (*(++argv)); - if (--argc > 0) - ++argv; - stopDoingThat = TRUE; - break; - case 's': - if (--argc == 0) - goto end; - bufsize = atoi (*(++argv)); - if (--argc > 0) - ++argv; - stopDoingThat = TRUE; - break; - default: + /* Parse any options */ + while (argc && **argv == '-') { + stopDoingThat = FALSE; + while (stopDoingThat == FALSE && *++(*argv)) { + switch (**argv) { + case 'c': + cmd = 4; + break; + case 'n': + cmd = 8; + if (--argc == 0) + goto end; + level = atoi(*(++argv)); + if (--argc > 0) + ++argv; + stopDoingThat = TRUE; + break; + case 's': + if (--argc == 0) + goto end; + bufsize = atoi(*(++argv)); + if (--argc > 0) + ++argv; + stopDoingThat = TRUE; + break; + default: + goto end; + } + } + } + + if (argc > 1) { goto end; - } } - } - - if (argc > 1) { - goto end; - } - if (cmd == 8) { - n = klogctl( cmd, NULL, level ); - if (n < 0) { - goto klogctl_error; - } - exit( TRUE ); - } + if (cmd == 8) { + n = klogctl(cmd, NULL, level); + if (n < 0) { + goto klogctl_error; + } + exit(TRUE); + } - if (bufsize < 4096) bufsize = 4096; - buf = (char*)malloc(bufsize); - n = klogctl( cmd, buf, bufsize ); - if (n < 0) { - goto klogctl_error; - } + if (bufsize < 4096) + bufsize = 4096; + buf = (char *) malloc(bufsize); + n = klogctl(cmd, buf, bufsize); + if (n < 0) { + goto klogctl_error; + } - lastc = '\n'; - for (i = 0; i < n; i++) { - if ((i == 0 || buf[i - 1] == '\n') && buf[i] == '<') { - i++; - while (buf[i] >= '0' && buf[i] <= '9') - i++; - if (buf[i] == '>') - i++; - } - lastc = buf[i]; - putchar( lastc ); - } - if (lastc != '\n') - putchar( '\n' ); - exit( TRUE); -end: - usage( dmesg_usage); - exit (FALSE); -klogctl_error: - perror( "klogctl" ); - exit( FALSE ); + lastc = '\n'; + for (i = 0; i < n; i++) { + if ((i == 0 || buf[i - 1] == '\n') && buf[i] == '<') { + i++; + while (buf[i] >= '0' && buf[i] <= '9') + i++; + if (buf[i] == '>') + i++; + } + lastc = buf[i]; + putchar(lastc); + } + if (lastc != '\n') + putchar('\n'); + exit(TRUE); + end: + usage(dmesg_usage); + exit(FALSE); + klogctl_error: + perror("klogctl"); + exit(FALSE); } 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 @@ +/* vi: set sw=4 ts=4: */ /* * Mini fbset implementation for busybox * @@ -48,7 +49,7 @@ #define OPT_READMODE (1 << 2) #define CMD_HELP 0 -#define CMD_FB 1 +#define CMD_FB 1 #define CMD_DB 2 #define CMD_GEOMETRY 3 #define CMD_TIMING 4 @@ -87,213 +88,242 @@ static unsigned int g_options = 0; struct cmdoptions_t { - char *name; - unsigned char param_count; - unsigned char code; + char *name; + unsigned char param_count; + unsigned char code; } g_cmdoptions[] = { - { "-h", 0, CMD_HELP }, - { "-fb", 1, CMD_FB }, - { "-db", 1, CMD_DB }, - { "-a", 0, CMD_ALL }, - { "-i", 0, CMD_INFO }, - { "-g", 5, CMD_GEOMETRY }, - { "-t", 7, CMD_TIMING }, - { "-accel", 1, CMD_ACCEL }, - { "-hsync", 1, CMD_HSYNC }, - { "-vsync", 1, CMD_VSYNC }, - { "-laced", 1, CMD_LACED }, - { "-double", 1, CMD_DOUBLE }, - + { + "-h", 0, CMD_HELP}, { + "-fb", 1, CMD_FB}, { + "-db", 1, CMD_DB}, { + "-a", 0, CMD_ALL}, { + "-i", 0, CMD_INFO}, { + "-g", 5, CMD_GEOMETRY}, { + "-t", 7, CMD_TIMING}, { + "-accel", 1, CMD_ACCEL}, { + "-hsync", 1, CMD_HSYNC}, { + "-vsync", 1, CMD_VSYNC}, { + "-laced", 1, CMD_LACED}, { + "-double", 1, CMD_DOUBLE}, #ifdef BB_FBSET_FANCY - { "--help", 0, CMD_HELP }, - { "-all", 0, CMD_ALL }, - { "-xres", 1, CMD_XRES }, - { "-yres", 1, CMD_YRES }, - { "-vxres", 1, CMD_VXRES }, - { "-vyres", 1, CMD_VYRES }, - { "-depth", 1, CMD_DEPTH }, - { "-match", 0, CMD_MATCH }, - { "--geometry", 5, CMD_GEOMETRY }, - - { "-pixclock", 1, CMD_PIXCLOCK }, - { "-left", 1, CMD_LEFT }, - { "-right", 1, CMD_RIGHT }, - { "-upper", 1, CMD_UPPER }, - { "-lower", 1, CMD_LOWER }, - { "-hslen", 1, CMD_HSLEN }, - { "-vslen", 1, CMD_VSLEN }, - { "--timings", 7, CMD_TIMING }, - - { "-csync", 1, CMD_CSYNC }, - { "-gsync", 1, CMD_GSYNC }, - { "-extsync", 1, CMD_EXTSYNC }, - { "-bcast", 1, CMD_BCAST }, - { "-rgba", 1, CMD_RGBA }, - { "-step", 1, CMD_STEP }, - { "-move", 1, CMD_MOVE }, + { + "--help", 0, CMD_HELP}, { + "-all", 0, CMD_ALL}, { + "-xres", 1, CMD_XRES}, { + "-yres", 1, CMD_YRES}, { + "-vxres", 1, CMD_VXRES}, { + "-vyres", 1, CMD_VYRES}, { + "-depth", 1, CMD_DEPTH}, { + "-match", 0, CMD_MATCH}, { + "--geometry", 5, CMD_GEOMETRY}, { + "-pixclock", 1, CMD_PIXCLOCK}, { + "-left", 1, CMD_LEFT}, { + "-right", 1, CMD_RIGHT}, { + "-upper", 1, CMD_UPPER}, { + "-lower", 1, CMD_LOWER}, { + "-hslen", 1, CMD_HSLEN}, { + "-vslen", 1, CMD_VSLEN}, { + "--timings", 7, CMD_TIMING}, { + "-csync", 1, CMD_CSYNC}, { + "-gsync", 1, CMD_GSYNC}, { + "-extsync", 1, CMD_EXTSYNC}, { + "-bcast", 1, CMD_BCAST}, { + "-rgba", 1, CMD_RGBA}, { + "-step", 1, CMD_STEP}, { + "-move", 1, CMD_MOVE}, #endif - { 0, 0, 0 } + { + 0, 0, 0} }; static int readmode(struct fb_var_screeninfo *base, const char *fn, - const char *mode) + const char *mode) { #ifdef BB_FBSET_READMODE - FILE *f; - char buf[256]; - char *p = buf; - - if ((f = fopen(fn, "r")) == NULL) PERROR("readmode(fopen)"); - while (!feof(f)) { - fgets(buf, sizeof(buf), f); - if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) { - p += 5; - if ((p = strstr(buf, mode))) { - p += strlen(mode); - if (!isspace(*p) && (*p != 0) && (*p != '"') && (*p != '\r') - && (*p != '\n')) continue; /* almost, but not quite */ - while (!feof(f)) { - fgets(buf, sizeof(buf), f); - if (!strstr(buf, "endmode")) return 1; + FILE *f; + char buf[256]; + char *p = buf; + + if ((f = fopen(fn, "r")) == NULL) + PERROR("readmode(fopen)"); + while (!feof(f)) { + fgets(buf, sizeof(buf), f); + if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) { + p += 5; + if ((p = strstr(buf, mode))) { + p += strlen(mode); + if (!isspace(*p) && (*p != 0) && (*p != '"') + && (*p != '\r') && (*p != '\n')) + continue; /* almost, but not quite */ + while (!feof(f)) { + fgets(buf, sizeof(buf), f); + if (!strstr(buf, "endmode")) + return 1; + } + } } - } } - } #else - fprintf(stderr, "W: mode reading was disabled on this copy of fbset; ignoring request\n"); + fprintf(stderr, + "W: mode reading was disabled on this copy of fbset; ignoring request\n"); #endif - return 0; + return 0; } -static void setmode(struct fb_var_screeninfo *base, - struct fb_var_screeninfo *set) +static void setmode(struct fb_var_screeninfo *base, + struct fb_var_screeninfo *set) { - if ((int)set->xres > 0) base->xres = set->xres; - if ((int)set->yres > 0) base->yres = set->yres; - if ((int)set->xres_virtual > 0) base->xres_virtual = set->xres_virtual; - if ((int)set->yres_virtual > 0) base->yres_virtual = set->yres_virtual; - if ((int)set->bits_per_pixel > 0) base->bits_per_pixel = set->bits_per_pixel; + if ((int) set->xres > 0) + base->xres = set->xres; + if ((int) set->yres > 0) + base->yres = set->yres; + if ((int) set->xres_virtual > 0) + base->xres_virtual = set->xres_virtual; + if ((int) set->yres_virtual > 0) + base->yres_virtual = set->yres_virtual; + if ((int) set->bits_per_pixel > 0) + base->bits_per_pixel = set->bits_per_pixel; } static void showmode(struct fb_var_screeninfo *v) { - double drate = 0, hrate = 0, vrate = 0; - if (v->pixclock) { - drate = 1e12 / v->pixclock; - hrate = drate / (v->left_margin+v->xres+v->right_margin+v->hsync_len); - vrate = hrate / (v->upper_margin+v->yres+v->lower_margin+v->vsync_len); - } - printf("\nmode \"%ux%u-%u\"\n", v->xres, v->yres, (int)(vrate+0.5)); + double drate = 0, hrate = 0, vrate = 0; + + if (v->pixclock) { + drate = 1e12 / v->pixclock; + hrate = + drate / (v->left_margin + v->xres + v->right_margin + + v->hsync_len); + vrate = + hrate / (v->upper_margin + v->yres + v->lower_margin + + v->vsync_len); + } + printf("\nmode \"%ux%u-%u\"\n", v->xres, v->yres, (int) (vrate + 0.5)); #ifdef BB_FBSET_FANCY - printf("\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n", drate/1e6, hrate/1e3, - vrate); + printf("\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n", drate / 1e6, + hrate / 1e3, vrate); #endif - printf("\tgeometry %u %u %u %u %u\n", v->xres, v->yres, - v->xres_virtual, v->yres_virtual, v->bits_per_pixel); + printf("\tgeometry %u %u %u %u %u\n", v->xres, v->yres, + v->xres_virtual, v->yres_virtual, v->bits_per_pixel); #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0) - printf("\ttimings %u %u %u %u %u %u %u\n", v->pixclock, v->left_margin, - v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len, - v->vsync_len); - printf("\taccel %s\n", (v->accel_flags > 0 ? "true" : "false")); + printf("\ttimings %u %u %u %u %u %u %u\n", v->pixclock, v->left_margin, + v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len, + v->vsync_len); + printf("\taccel %s\n", (v->accel_flags > 0 ? "true" : "false")); #else - printf("\ttimings %lu %lu %lu %lu %lu %lu %lu\n", v->pixclock, v->left_margin, - v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len, - v->vsync_len); + printf("\ttimings %lu %lu %lu %lu %lu %lu %lu\n", v->pixclock, + v->left_margin, v->right_margin, v->upper_margin, + v->lower_margin, v->hsync_len, v->vsync_len); #endif - printf("\trgba %u/%u,%u/%u,%u/%u,%u/%u\n", v->red.length, v->red.offset, - v->green.length, v->green.offset, v->blue.length, v->blue.offset, - v->transp.length, v->transp.offset); - printf("endmode\n"); + printf("\trgba %u/%u,%u/%u,%u/%u,%u/%u\n", v->red.length, + v->red.offset, v->green.length, v->green.offset, v->blue.length, + v->blue.offset, v->transp.length, v->transp.offset); + printf("endmode\n"); } static void fbset_usage(void) { - int i; + int i; + #ifndef STANDALONE - fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", BB_VER, BB_BT); + fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", + BB_VER, BB_BT); #endif - fprintf(stderr, "Usage: fbset [options] [mode]\n"); - fprintf(stderr, "\tThe following options are recognized:\n"); - for (i = 0; g_cmdoptions[i].name; i++) - fprintf(stderr, "\t\t%s\n", g_cmdoptions[i].name); - exit(-1); + fprintf(stderr, "Usage: fbset [options] [mode]\n"); + fprintf(stderr, "\tThe following options are recognized:\n"); + for (i = 0; g_cmdoptions[i].name; i++) + fprintf(stderr, "\t\t%s\n", g_cmdoptions[i].name); + exit(-1); } #ifdef STANDALONE int main(int argc, char **argv) -#else +#else extern int fbset_main(int argc, char **argv) #endif { - struct fb_var_screeninfo var, varset; - int fh, i; - char *fbdev = DEFAULTFBDEV; - char *modefile = DEFAULTFBMODE; - char *thisarg, *mode = NULL; + struct fb_var_screeninfo var, varset; + int fh, i; + char *fbdev = DEFAULTFBDEV; + char *modefile = DEFAULTFBMODE; + char *thisarg, *mode = NULL; + + memset(&varset, 0xFF, sizeof(varset)); - memset(&varset, 0xFF, sizeof(varset)); - - /* parse cmd args.... why do they have to make things so difficult? */ - argv++; argc--; - for (; argc > 0 && (thisarg = *argv); argc--, argv++) { - for (i = 0; g_cmdoptions[i].name; i++) { - if (!strcmp(thisarg, g_cmdoptions[i].name)) { - if (argc - 1 < g_cmdoptions[i].param_count) fbset_usage(); - switch (g_cmdoptions[i].code) { - case CMD_HELP: fbset_usage(); - case CMD_FB: fbdev = argv[1]; break; - case CMD_DB: modefile = argv[1]; break; - case CMD_GEOMETRY: - varset.xres = strtoul(argv[1],0,0); - varset.yres = strtoul(argv[2],0,0); - varset.xres_virtual = strtoul(argv[3],0,0); - varset.yres_virtual = strtoul(argv[4],0,0); - varset.bits_per_pixel = strtoul(argv[5],0,0); - break; - case CMD_TIMING: - varset.pixclock = strtoul(argv[1],0,0); - varset.left_margin = strtoul(argv[2],0,0); - varset.right_margin = strtoul(argv[3],0,0); - varset.upper_margin = strtoul(argv[4],0,0); - varset.lower_margin = strtoul(argv[5],0,0); - varset.hsync_len = strtoul(argv[6],0,0); - varset.vsync_len = strtoul(argv[7],0,0); - break; + /* parse cmd args.... why do they have to make things so difficult? */ + argv++; + argc--; + for (; argc > 0 && (thisarg = *argv); argc--, argv++) { + for (i = 0; g_cmdoptions[i].name; i++) { + if (!strcmp(thisarg, g_cmdoptions[i].name)) { + if (argc - 1 < g_cmdoptions[i].param_count) + fbset_usage(); + switch (g_cmdoptions[i].code) { + case CMD_HELP: + fbset_usage(); + case CMD_FB: + fbdev = argv[1]; + break; + case CMD_DB: + modefile = argv[1]; + break; + case CMD_GEOMETRY: + varset.xres = strtoul(argv[1], 0, 0); + varset.yres = strtoul(argv[2], 0, 0); + varset.xres_virtual = strtoul(argv[3], 0, 0); + varset.yres_virtual = strtoul(argv[4], 0, 0); + varset.bits_per_pixel = strtoul(argv[5], 0, 0); + break; + case CMD_TIMING: + varset.pixclock = strtoul(argv[1], 0, 0); + varset.left_margin = strtoul(argv[2], 0, 0); + varset.right_margin = strtoul(argv[3], 0, 0); + varset.upper_margin = strtoul(argv[4], 0, 0); + varset.lower_margin = strtoul(argv[5], 0, 0); + varset.hsync_len = strtoul(argv[6], 0, 0); + varset.vsync_len = strtoul(argv[7], 0, 0); + break; #ifdef BB_FBSET_FANCY - case CMD_XRES: varset.xres = strtoul(argv[1],0,0); break; - case CMD_YRES: varset.yres = strtoul(argv[1],0,0); break; + case CMD_XRES: + varset.xres = strtoul(argv[1], 0, 0); + break; + case CMD_YRES: + varset.yres = strtoul(argv[1], 0, 0); + break; #endif + } + argc -= g_cmdoptions[i].param_count; + argv += g_cmdoptions[i].param_count; + break; + } + } + if (!g_cmdoptions[i].name) { + if (argc == 1) { + mode = *argv; + g_options |= OPT_READMODE; + } else { + fbset_usage(); + } } - argc -= g_cmdoptions[i].param_count; - argv += g_cmdoptions[i].param_count; - break; - } - } - if (!g_cmdoptions[i].name) { - if (argc == 1) { - mode = *argv; - g_options |= OPT_READMODE; - } else { - fbset_usage(); - } } - } - if ((fh = open(fbdev, O_RDONLY)) < 0) PERROR("fbset(open)"); - if (ioctl(fh, FBIOGET_VSCREENINFO, &var)) PERROR("fbset(ioctl)"); - if (g_options & OPT_READMODE) { - if (!readmode(&var, modefile, mode)) { - fprintf(stderr, "Unknown video mode `%s'\n", mode); - exit(1); + if ((fh = open(fbdev, O_RDONLY)) < 0) + PERROR("fbset(open)"); + if (ioctl(fh, FBIOGET_VSCREENINFO, &var)) + PERROR("fbset(ioctl)"); + if (g_options & OPT_READMODE) { + if (!readmode(&var, modefile, mode)) { + fprintf(stderr, "Unknown video mode `%s'\n", mode); + exit(1); + } } - } - setmode(&var, &varset); - if (g_options & OPT_CHANGE) - if (ioctl(fh, FBIOPUT_VSCREENINFO, &var)) PERROR("fbset(ioctl)"); - showmode(&var); - close(fh); - - return(TRUE); -} + setmode(&var, &varset); + if (g_options & OPT_CHANGE) + if (ioctl(fh, FBIOPUT_VSCREENINFO, &var)) + PERROR("fbset(ioctl)"); + showmode(&var); + close(fh); + return (TRUE); +} 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 @@ +/* vi: set sw=4 ts=4: */ /* * Mini fdflush implementation for busybox * @@ -29,24 +30,25 @@ extern int fdflush_main(int argc, char **argv) { - int value; - int fd; - if ( argc <= 1 || **(argv++) == '-' ) { - usage( "fdflush device\n"); - } + int value; + int fd; - fd = open(*argv, 0); - if ( fd < 0 ) { - perror(*argv); - exit(FALSE); - } + if (argc <= 1 || **(argv++) == '-') { + usage("fdflush device\n"); + } - value = ioctl(fd, FDFLUSH, 0); - close(fd); + fd = open(*argv, 0); + if (fd < 0) { + perror(*argv); + exit(FALSE); + } - if ( value ) { - perror(*argv); - exit(FALSE); - } - exit (TRUE); + value = ioctl(fd, FDFLUSH, 0); + close(fd); + + if (value) { + perror(*argv); + exit(FALSE); + } + exit(TRUE); } 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 @@ +/* vi: set sw=4 ts=4: */ /* * fsck.c - a file system consistency checker for Linux. * @@ -96,7 +97,7 @@ #include <termios.h> #include <mntent.h> #include <sys/stat.h> -#include <sys/param.h> /* for PATH_MAX */ +#include <sys/param.h> /* for PATH_MAX */ #include <linux/fs.h> #include <linux/minix_fs.h> @@ -124,17 +125,17 @@ #define BITS_PER_BLOCK (BLOCK_SIZE<<3) -static char * program_name = "fsck.minix"; -static char * program_version = "1.2 - 11/11/96"; -static char * device_name = NULL; +static char *program_name = "fsck.minix"; +static char *program_version = "1.2 - 11/11/96"; +static char *device_name = NULL; static int IN; -static int repair=0, automatic=0, verbose=0, list=0, show=0, warn_mode=0, - force=0; -static int directory=0, regular=0, blockdev=0, chardev=0, links=0, - symlinks=0, total=0; +static int repair = 0, automatic = 0, verbose = 0, list = 0, show = + 0, warn_mode = 0, force = 0; +static int directory = 0, regular = 0, blockdev = 0, chardev = 0, links = + 0, symlinks = 0, total = 0; -static int changed = 0; /* flags if the filesystem has been changed */ -static int errors_uncorrected = 0; /* flag if some error was not corrected */ +static int changed = 0; /* flags if the filesystem has been changed */ +static int errors_uncorrected = 0; /* flag if some error was not corrected */ static int dirsize = 16; static int namelen = 14; static int version2 = 0; @@ -146,10 +147,12 @@ static int termios_set = 0; static int name_depth = 0; static char name_list[MAX_DEPTH][PATH_MAX + 1]; -static char * inode_buffer = NULL; +static char *inode_buffer = NULL; + #define Inode (((struct minix_inode *) inode_buffer)-1) #define Inode2 (((struct minix2_inode *) inode_buffer)-1) static char super_block_buffer[BLOCK_SIZE]; + #define Super (*(struct minix_super_block *)super_block_buffer) #define INODES ((unsigned long)Super.s_ninodes) #ifdef HAVE_MINIX2 @@ -168,8 +171,8 @@ static char super_block_buffer[BLOCK_SIZE]; static char *inode_map; static char *zone_map; -static unsigned char * inode_count = NULL; -static unsigned char * zone_count = NULL; +static unsigned char *inode_count = NULL; +static unsigned char *zone_count = NULL; static void recursive_check(unsigned int ino); static void recursive_check2(unsigned int ino); @@ -191,22 +194,27 @@ static void leave(int status) exit(status); } -static void show_usage(void) { - fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", BB_VER, BB_BT); +static void show_usage(void) +{ + fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", + BB_VER, BB_BT); fprintf(stderr, "Usage: %s [-larvsmf] /dev/name\n\n", program_name); - fprintf(stderr, "Performs a consistency check for MINIX filesystems.\n\n"); + fprintf(stderr, + "Performs a consistency check for MINIX filesystems.\n\n"); fprintf(stderr, "OPTIONS:\n"); fprintf(stderr, "\t-l\tLists all filenames\n"); fprintf(stderr, "\t-r\tPerform interactive repairs\n"); fprintf(stderr, "\t-a\tPerform automatic repairs\n"); fprintf(stderr, "\t-v\tverbose\n"); fprintf(stderr, "\t-s\tOutputs super-block information\n"); - fprintf(stderr, "\t-m\tActivates MINIX-like \"mode not cleared\" warnings\n"); + fprintf(stderr, + "\t-m\tActivates MINIX-like \"mode not cleared\" warnings\n"); fprintf(stderr, "\t-f\tForce file system check.\n\n"); leave(16); } -static void die(const char *str) { +static void die(const char *str) +{ fprintf(stderr, "%s: %s\n", program_name, str); leave(8); } @@ -217,15 +225,15 @@ static void die(const char *str) { */ static void print_current_name(void) { - int i=0; + int i = 0; - while (i<name_depth) - printf("/%.*s",namelen,name_list[i++]); + while (i < name_depth) + printf("/%.*s", namelen, name_list[i++]); if (i == 0) - printf ("/"); + printf("/"); } -static int ask(const char * string, int def) +static int ask(const char *string, int def) { int c; @@ -237,18 +245,18 @@ static int ask(const char * string, int def) if (automatic) { printf("\n"); if (!def) - errors_uncorrected = 1; + errors_uncorrected = 1; return def; } - printf(def?"%s (y/n)? ":"%s (n/y)? ",string); + printf(def ? "%s (y/n)? " : "%s (n/y)? ", string); for (;;) { fflush(stdout); - if ((c=getchar())==EOF) { - if (!def) - errors_uncorrected = 1; + if ((c = getchar()) == EOF) { + if (!def) + errors_uncorrected = 1; return def; } - c=toupper(c); + c = toupper(c); if (c == 'Y') { def = 1; break; @@ -263,7 +271,7 @@ static int ask(const char * string, int def) else { printf("n\n"); errors_uncorrected = 1; - } + } return def; } @@ -274,17 +282,17 @@ static int ask(const char * string, int def) */ static void check_mount(void) { - FILE * f; - struct mntent * mnt; + FILE *f; + struct mntent *mnt; int cont; int fd; - if ((f = setmntent (MOUNTED, "r")) == NULL) + if ((f = setmntent(MOUNTED, "r")) == NULL) return; - while ((mnt = getmntent (f)) != NULL) - if (strcmp (device_name, mnt->mnt_fsname) == 0) + while ((mnt = getmntent(f)) != NULL) + if (strcmp(device_name, mnt->mnt_fsname) == 0) break; - endmntent (f); + endmntent(f); if (!mnt) return; @@ -298,15 +306,15 @@ static void check_mount(void) return; else close(fd); - - printf ("%s is mounted. ", device_name); + + printf("%s is mounted. ", device_name); if (isatty(0) && isatty(1)) cont = ask("Do you really want to continue", 0); else cont = 0; if (!cont) { - printf ("check aborted.\n"); - exit (0); + printf("check aborted.\n"); + exit(0); } return; } @@ -317,7 +325,7 @@ static void check_mount(void) * if an error was corrected, and returns the zone (0 for no zone * or a bad zone-number). */ -static int check_zone_nr(unsigned short * nr, int * corrected) +static int check_zone_nr(unsigned short *nr, int *corrected) { if (!*nr) return 0; @@ -329,7 +337,7 @@ static int check_zone_nr(unsigned short * nr, int * corrected) return *nr; print_current_name(); printf("'."); - if (ask("Remove block",1)) { + if (ask("Remove block", 1)) { *nr = 0; *corrected = 1; } @@ -337,19 +345,19 @@ static int check_zone_nr(unsigned short * nr, int * corrected) } #ifdef HAVE_MINIX2 -static int check_zone_nr2 (unsigned int *nr, int *corrected) +static int check_zone_nr2(unsigned int *nr, int *corrected) { if (!*nr) return 0; if (*nr < FIRSTZONE) - printf ("Zone nr < FIRSTZONE in file `"); + printf("Zone nr < FIRSTZONE in file `"); else if (*nr >= ZONES) - printf ("Zone nr >= ZONES in file `"); + printf("Zone nr >= ZONES in file `"); else return *nr; - print_current_name (); - printf ("'."); - if (ask ("Remove block", 1)) { + print_current_name(); + printf("'."); + if (ask("Remove block", 1)) { *nr = 0; *corrected = 1; } @@ -360,23 +368,23 @@ static int check_zone_nr2 (unsigned int *nr, int *corrected) /* * read-block reads block nr into the buffer at addr. */ -static void read_block(unsigned int nr, char * addr) +static void read_block(unsigned int nr, char *addr) { if (!nr) { - memset(addr,0,BLOCK_SIZE); + memset(addr, 0, BLOCK_SIZE); return; } - if (BLOCK_SIZE*nr != lseek(IN, BLOCK_SIZE*nr, SEEK_SET)) { + if (BLOCK_SIZE * nr != lseek(IN, BLOCK_SIZE * nr, SEEK_SET)) { printf("Read error: unable to seek to block in file '"); print_current_name(); printf("'\n"); - memset(addr,0,BLOCK_SIZE); + memset(addr, 0, BLOCK_SIZE); errors_uncorrected = 1; } else if (BLOCK_SIZE != read(IN, addr, BLOCK_SIZE)) { printf("Read error: bad block in file '"); print_current_name(); printf("'\n"); - memset(addr,0,BLOCK_SIZE); + memset(addr, 0, BLOCK_SIZE); errors_uncorrected = 1; } } @@ -384,17 +392,17 @@ static void read_block(unsigned int nr, char * addr) /* * write_block writes block nr to disk. */ -static void write_block(unsigned int nr, char * addr) +static void write_block(unsigned int nr, char *addr) { if (!nr) return; if (nr < FIRSTZONE || nr >= ZONES) { printf("Internal error: trying to write bad block\n" - "Write request ignored\n"); + "Write request ignored\n"); errors_uncorrected = 1; return; } - if (BLOCK_SIZE*nr != lseek(IN, BLOCK_SIZE*nr, SEEK_SET)) + if (BLOCK_SIZE * nr != lseek(IN, BLOCK_SIZE * nr, SEEK_SET)) die("seek failed in write_block"); if (BLOCK_SIZE != write(IN, addr, BLOCK_SIZE)) { printf("Write error: bad block in file '"); @@ -409,16 +417,16 @@ static void write_block(unsigned int nr, char * addr) * It sets 'changed' if the inode has needed changing, and re-writes * any indirect blocks with errors. */ -static int map_block(struct minix_inode * inode, unsigned int blknr) +static int map_block(struct minix_inode *inode, unsigned int blknr) { - unsigned short ind[BLOCK_SIZE>>1]; - unsigned short dind[BLOCK_SIZE>>1]; + unsigned short ind[BLOCK_SIZE >> 1]; + unsigned short dind[BLOCK_SIZE >> 1]; int blk_chg, block, result; - if (blknr<7) + if (blknr < 7) return check_zone_nr(inode->i_zone + blknr, &changed); blknr -= 7; - if (blknr<512) { + if (blknr < 512) { block = check_zone_nr(inode->i_zone + 7, &changed); read_block(block, (char *) ind); blk_chg = 0; @@ -431,73 +439,73 @@ static int map_block(struct minix_inode * inode, unsigned int blknr) block = check_zone_nr(inode->i_zone + 8, &changed); read_block(block, (char *) dind); blk_chg = 0; - result = check_zone_nr(dind + (blknr/512), &blk_chg); + result = check_zone_nr(dind + (blknr / 512), &blk_chg); if (blk_chg) write_block(block, (char *) dind); block = result; read_block(block, (char *) ind); blk_chg = 0; - result = check_zone_nr(ind + (blknr%512), &blk_chg); + result = check_zone_nr(ind + (blknr % 512), &blk_chg); if (blk_chg) write_block(block, (char *) ind); return result; } #ifdef HAVE_MINIX2 -static int map_block2 (struct minix2_inode *inode, unsigned int blknr) +static int map_block2(struct minix2_inode *inode, unsigned int blknr) { - unsigned int ind[BLOCK_SIZE >> 2]; + unsigned int ind[BLOCK_SIZE >> 2]; unsigned int dind[BLOCK_SIZE >> 2]; unsigned int tind[BLOCK_SIZE >> 2]; int blk_chg, block, result; if (blknr < 7) - return check_zone_nr2 (inode->i_zone + blknr, &changed); + return check_zone_nr2(inode->i_zone + blknr, &changed); blknr -= 7; if (blknr < 256) { - block = check_zone_nr2 (inode->i_zone + 7, &changed); - read_block (block, (char *) ind); + block = check_zone_nr2(inode->i_zone + 7, &changed); + read_block(block, (char *) ind); blk_chg = 0; - result = check_zone_nr2 (blknr + ind, &blk_chg); + result = check_zone_nr2(blknr + ind, &blk_chg); if (blk_chg) - write_block (block, (char *) ind); + write_block(block, (char *) ind); return result; } blknr -= 256; if (blknr >= 256 * 256) { - block = check_zone_nr2 (inode->i_zone + 8, &changed); - read_block (block, (char *) dind); + block = check_zone_nr2(inode->i_zone + 8, &changed); + read_block(block, (char *) dind); blk_chg = 0; - result = check_zone_nr2 (dind + blknr / 256, &blk_chg); + result = check_zone_nr2(dind + blknr / 256, &blk_chg); if (blk_chg) - write_block (block, (char *) dind); + write_block(block, (char *) dind); block = result; - read_block (block, (char *) ind); + read_block(block, (char *) ind); blk_chg = 0; - result = check_zone_nr2 (ind + blknr % 256, &blk_chg); + result = check_zone_nr2(ind + blknr % 256, &blk_chg); if (blk_chg) - write_block (block, (char *) ind); + write_block(block, (char *) ind); return result; } blknr -= 256 * 256; - block = check_zone_nr2 (inode->i_zone + 9, &changed); - read_block (block, (char *) tind); + block = check_zone_nr2(inode->i_zone + 9, &changed); + read_block(block, (char *) tind); blk_chg = 0; - result = check_zone_nr2 (tind + blknr / (256 * 256), &blk_chg); + result = check_zone_nr2(tind + blknr / (256 * 256), &blk_chg); if (blk_chg) - write_block (block, (char *) tind); + write_block(block, (char *) tind); block = result; - read_block (block, (char *) dind); + read_block(block, (char *) dind); blk_chg = 0; - result = check_zone_nr2 (dind + (blknr / 256) % 256, &blk_chg); + result = check_zone_nr2(dind + (blknr / 256) % 256, &blk_chg); if (blk_chg) - write_block (block, (char *) dind); + write_block(block, (char *) dind); block = result; - read_block (block, (char *) ind); + read_block(block, (char *) ind); blk_chg = 0; - result = check_zone_nr2 (ind + blknr % 256, &blk_chg); + result = check_zone_nr2(ind + blknr % 256, &blk_chg); if (blk_chg) - write_block (block, (char *) ind); + write_block(block, (char *) ind); return result; } #endif @@ -510,11 +518,11 @@ static void write_super_block(void) * unconditionally set if we get this far. */ Super.s_state |= MINIX_VALID_FS; - if ( errors_uncorrected ) + if (errors_uncorrected) Super.s_state |= MINIX_ERROR_FS; else Super.s_state &= ~MINIX_ERROR_FS; - + if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET)) die("seek failed in write_super_block"); if (BLOCK_SIZE != write(IN, super_block_buffer, BLOCK_SIZE)) @@ -527,15 +535,15 @@ static void write_tables(void) { write_super_block(); - if (IMAPS*BLOCK_SIZE != write(IN,inode_map,IMAPS*BLOCK_SIZE)) + if (IMAPS * BLOCK_SIZE != write(IN, inode_map, IMAPS * BLOCK_SIZE)) die("Unable to write inode map"); - if (ZMAPS*BLOCK_SIZE != write(IN,zone_map,ZMAPS*BLOCK_SIZE)) + if (ZMAPS * BLOCK_SIZE != write(IN, zone_map, ZMAPS * BLOCK_SIZE)) die("Unable to write zone map"); - if (INODE_BUFFER_SIZE != write(IN,inode_buffer,INODE_BUFFER_SIZE)) + if (INODE_BUFFER_SIZE != write(IN, inode_buffer, INODE_BUFFER_SIZE)) die("Unable to write inodes"); } -static void get_dirsize (void) +static void get_dirsize(void) { int block; char blk[BLOCK_SIZE]; @@ -547,9 +555,9 @@ static void get_dirsize (void) else #endif block = Inode[ROOT_INO].i_zone[0]; - read_block (block, blk); + read_block(block, blk); for (size = 16; size < BLOCK_SIZE; size <<= 1) { - if (strcmp (blk + size + 2, "..") == 0) { + if (strcmp(blk + size + 2, "..") == 0) { dirsize = size; namelen = size - 2; return; @@ -600,8 +608,8 @@ static void read_tables(void) zone_map = malloc(ZMAPS * BLOCK_SIZE); if (!inode_map) die("Unable to allocate buffer for zone map"); - memset(inode_map,0,sizeof(inode_map)); - memset(zone_map,0,sizeof(zone_map)); + memset(inode_map, 0, sizeof(inode_map)); + memset(zone_map, 0, sizeof(zone_map)); inode_buffer = malloc(INODE_BUFFER_SIZE); if (!inode_buffer) die("Unable to allocate buffer for inodes"); @@ -611,31 +619,31 @@ static void read_tables(void) zone_count = malloc(ZONES); if (!zone_count) die("Unable to allocate buffer for zone count"); - if (IMAPS*BLOCK_SIZE != read(IN,inode_map,IMAPS*BLOCK_SIZE)) + if (IMAPS * BLOCK_SIZE != read(IN, inode_map, IMAPS * BLOCK_SIZE)) die("Unable to read inode map"); - if (ZMAPS*BLOCK_SIZE != read(IN,zone_map,ZMAPS*BLOCK_SIZE)) + if (ZMAPS * BLOCK_SIZE != read(IN, zone_map, ZMAPS * BLOCK_SIZE)) die("Unable to read zone map"); - if (INODE_BUFFER_SIZE != read(IN,inode_buffer,INODE_BUFFER_SIZE)) + if (INODE_BUFFER_SIZE != read(IN, inode_buffer, INODE_BUFFER_SIZE)) die("Unable to read inodes"); if (NORM_FIRSTZONE != FIRSTZONE) { printf("Warning: Firstzone != Norm_firstzone\n"); errors_uncorrected = 1; } - get_dirsize (); + get_dirsize(); if (show) { - printf("%ld inodes\n",INODES); - printf("%ld blocks\n",ZONES); - printf("Firstdatazone=%ld (%ld)\n",FIRSTZONE,NORM_FIRSTZONE); - printf("Zonesize=%d\n",BLOCK_SIZE<<ZONESIZE); - printf("Maxsize=%ld\n",MAXSIZE); + printf("%ld inodes\n", INODES); + printf("%ld blocks\n", ZONES); + printf("Firstdatazone=%ld (%ld)\n", FIRSTZONE, NORM_FIRSTZONE); + printf("Zonesize=%d\n", BLOCK_SIZE << ZONESIZE); + printf("Maxsize=%ld\n", MAXSIZE); printf("Filesystem state=%d\n", Super.s_state); - printf("namelen=%d\n\n",namelen); + printf("namelen=%d\n\n", namelen); } } -struct minix_inode * get_inode(unsigned int nr) +struct minix_inode *get_inode(unsigned int nr) { - struct minix_inode * inode; + struct minix_inode *inode; if (!nr || nr > INODES) return NULL; @@ -643,15 +651,14 @@ struct minix_inode * get_inode(unsigned int nr) inode = Inode + nr; if (!inode_count[nr]) { if (!inode_in_use(nr)) { - printf("Inode %d marked not used, but used for file '", - nr); + printf("Inode %d marked not used, but used for file '", nr); print_current_name(); printf("'\n"); if (repair) { - if (ask("Mark in use",1)) + if (ask("Mark in use", 1)) mark_inode(nr); } else { - errors_uncorrected = 1; + errors_uncorrected = 1; } } if (S_ISDIR(inode->i_mode)) @@ -664,14 +671,12 @@ struct minix_inode * get_inode(unsigned int nr) blockdev++; else if (S_ISLNK(inode->i_mode)) symlinks++; - else if (S_ISSOCK(inode->i_mode)) - ; - else if (S_ISFIFO(inode->i_mode)) - ; + else if (S_ISSOCK(inode->i_mode)); + else if (S_ISFIFO(inode->i_mode)); else { - print_current_name(); - printf(" has mode %05o\n",inode->i_mode); - } + print_current_name(); + printf(" has mode %05o\n", inode->i_mode); + } } else links++; @@ -684,8 +689,7 @@ struct minix_inode * get_inode(unsigned int nr) } #ifdef HAVE_MINIX2 -struct minix2_inode * -get_inode2 (unsigned int nr) +struct minix2_inode *get_inode2(unsigned int nr) { struct minix2_inode *inode; @@ -694,37 +698,37 @@ get_inode2 (unsigned int nr) total++; inode = Inode2 + nr; if (!inode_count[nr]) { - if (!inode_in_use (nr)) { - printf ("Inode %d marked not used, but used for file '", nr); - print_current_name (); - printf ("'\n"); + if (!inode_in_use(nr)) { + printf("Inode %d marked not used, but used for file '", nr); + print_current_name(); + printf("'\n"); if (repair) { - if (ask ("Mark in use", 1)) - mark_inode (nr); + if (ask("Mark in use", 1)) + mark_inode(nr); else errors_uncorrected = 1; } } - if (S_ISDIR (inode->i_mode)) + if (S_ISDIR(inode->i_mode)) directory++; - else if (S_ISREG (inode->i_mode)) + else if (S_ISREG(inode->i_mode)) regular++; - else if (S_ISCHR (inode->i_mode)) + else if (S_ISCHR(inode->i_mode)) chardev++; - else if (S_ISBLK (inode->i_mode)) + else if (S_ISBLK(inode->i_mode)) blockdev++; - else if (S_ISLNK (inode->i_mode)) + else if (S_ISLNK(inode->i_mode)) symlinks++; - else if (S_ISSOCK (inode->i_mode)); - else if (S_ISFIFO (inode->i_mode)); + else if (S_ISSOCK(inode->i_mode)); + else if (S_ISFIFO(inode->i_mode)); else { - print_current_name (); - printf (" has mode %05o\n", inode->i_mode); + print_current_name(); + printf(" has mode %05o\n", inode->i_mode); } } else links++; if (!++inode_count[nr]) { - printf ("Warning: inode count too big.\n"); + printf("Warning: inode count too big.\n"); inode_count[nr]--; errors_uncorrected = 1; } @@ -734,23 +738,23 @@ get_inode2 (unsigned int nr) static void check_root(void) { - struct minix_inode * inode = Inode + ROOT_INO; + struct minix_inode *inode = Inode + ROOT_INO; if (!inode || !S_ISDIR(inode->i_mode)) die("root inode isn't a directory"); } #ifdef HAVE_MINIX2 -static void check_root2 (void) +static void check_root2(void) { struct minix2_inode *inode = Inode2 + ROOT_INO; - if (!inode || !S_ISDIR (inode->i_mode)) - die ("root inode isn't a directory"); + if (!inode || !S_ISDIR(inode->i_mode)) + die("root inode isn't a directory"); } #endif -static int add_zone(unsigned short * znr, int * corrected) +static int add_zone(unsigned short *znr, int *corrected) { int result; int block; @@ -763,7 +767,7 @@ static int add_zone(unsigned short * znr, int * corrected) printf("Block has been used before. Now in file `"); print_current_name(); printf("'."); - if (ask("Clear",1)) { + if (ask("Clear", 1)) { *znr = 0; block = 0; *corrected = 1; @@ -772,10 +776,10 @@ static int add_zone(unsigned short * znr, int * corrected) if (!block) return 0; if (!zone_in_use(block)) { - printf("Block %d in file `",block); + printf("Block %d in file `", block); print_current_name(); printf("' is marked not in use."); - if (ask("Correct",1)) + if (ask("Correct", 1)) mark_zone(block); } if (!++zone_count[block]) @@ -784,20 +788,20 @@ static int add_zone(unsigned short * znr, int * corrected) } #ifdef HAVE_MINIX2 -static int add_zone2 (unsigned int *znr, int *corrected) +static int add_zone2(unsigned int *znr, int *corrected) { int result; int block; result = 0; - block = check_zone_nr2 (znr, corrected); + block = check_zone_nr2(znr, corrected); if (!block) return 0; if (zone_count[block]) { - printf ("Block has been used before. Now in file `"); - print_current_name (); - printf ("'."); - if (ask ("Clear", 1)) { + printf("Block has been used before. Now in file `"); + print_current_name(); + printf("'."); + if (ask("Clear", 1)) { *znr = 0; block = 0; *corrected = 1; @@ -805,12 +809,12 @@ static int add_zone2 (unsigned int *znr, int *corrected) } if (!block) return 0; - if (!zone_in_use (block)) { - printf ("Block %d in file `", block); - print_current_name (); - printf ("' is marked not in use."); - if (ask ("Correct", 1)) - mark_zone (block); + if (!zone_in_use(block)) { + printf("Block %d in file `", block); + print_current_name(); + printf("' is marked not in use."); + if (ask("Correct", 1)) + mark_zone(block); } if (!++zone_count[block]) zone_count[block]--; @@ -818,182 +822,179 @@ static int add_zone2 (unsigned int *znr, int *corrected) } #endif -static void add_zone_ind(unsigned short * znr, int * corrected) +static void add_zone_ind(unsigned short *znr, int *corrected) { static char blk[BLOCK_SIZE]; - int i, chg_blk=0; + int i, chg_blk = 0; int block; block = add_zone(znr, corrected); if (!block) return; read_block(block, blk); - for (i=0 ; i < (BLOCK_SIZE>>1) ; i++) + for (i = 0; i < (BLOCK_SIZE >> 1); i++) add_zone(i + (unsigned short *) blk, &chg_blk); if (chg_blk) write_block(block, blk); } #ifdef HAVE_MINIX2 -static void -add_zone_ind2 (unsigned int *znr, int *corrected) +static void add_zone_ind2(unsigned int *znr, int *corrected) { static char blk[BLOCK_SIZE]; int i, chg_blk = 0; int block; - block = add_zone2 (znr, corrected); + block = add_zone2(znr, corrected); if (!block) return; - read_block (block, blk); + read_block(block, blk); for (i = 0; i < BLOCK_SIZE >> 2; i++) - add_zone2 (i + (unsigned int *) blk, &chg_blk); + add_zone2(i + (unsigned int *) blk, &chg_blk); if (chg_blk) - write_block (block, blk); + write_block(block, blk); } #endif -static void add_zone_dind(unsigned short * znr, int * corrected) +static void add_zone_dind(unsigned short *znr, int *corrected) { static char blk[BLOCK_SIZE]; - int i, blk_chg=0; + int i, blk_chg = 0; int block; block = add_zone(znr, corrected); if (!block) return; read_block(block, blk); - for (i=0 ; i < (BLOCK_SIZE>>1) ; i++) + for (i = 0; i < (BLOCK_SIZE >> 1); i++) add_zone_ind(i + (unsigned short *) blk, &blk_chg); if (blk_chg) write_block(block, blk); } #ifdef HAVE_MINIX2 -static void -add_zone_dind2 (unsigned int *znr, int *corrected) +static void add_zone_dind2(unsigned int *znr, int *corrected) { static char blk[BLOCK_SIZE]; int i, blk_chg = 0; int block; - block = add_zone2 (znr, corrected); + block = add_zone2(znr, corrected); if (!block) return; - read_block (block, blk); + read_block(block, blk); for (i = 0; i < BLOCK_SIZE >> 2; i++) - add_zone_ind2 (i + (unsigned int *) blk, &blk_chg); + add_zone_ind2(i + (unsigned int *) blk, &blk_chg); if (blk_chg) - write_block (block, blk); + write_block(block, blk); } -static void -add_zone_tind2 (unsigned int *znr, int *corrected) +static void add_zone_tind2(unsigned int *znr, int *corrected) { static char blk[BLOCK_SIZE]; int i, blk_chg = 0; int block; - block = add_zone2 (znr, corrected); + block = add_zone2(znr, corrected); if (!block) return; - read_block (block, blk); + read_block(block, blk); for (i = 0; i < BLOCK_SIZE >> 2; i++) - add_zone_dind2 (i + (unsigned int *) blk, &blk_chg); + add_zone_dind2(i + (unsigned int *) blk, &blk_chg); if (blk_chg) - write_block (block, blk); + write_block(block, blk); } #endif static void check_zones(unsigned int i) { - struct minix_inode * inode; + struct minix_inode *inode; if (!i || i > INODES) return; - if (inode_count[i] > 1) /* have we counted this file already? */ + if (inode_count[i] > 1) /* have we counted this file already? */ return; inode = Inode + i; if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && - !S_ISLNK(inode->i_mode)) - return; - for (i=0 ; i<7 ; i++) + !S_ISLNK(inode->i_mode)) return; + for (i = 0; i < 7; i++) add_zone(i + inode->i_zone, &changed); add_zone_ind(7 + inode->i_zone, &changed); add_zone_dind(8 + inode->i_zone, &changed); } #ifdef HAVE_MINIX2 -static void -check_zones2 (unsigned int i) +static void check_zones2(unsigned int i) { struct minix2_inode *inode; if (!i || i > INODES) return; - if (inode_count[i] > 1) /* have we counted this file already? */ + if (inode_count[i] > 1) /* have we counted this file already? */ return; inode = Inode2 + i; - if (!S_ISDIR (inode->i_mode) && !S_ISREG (inode->i_mode) - && !S_ISLNK (inode->i_mode)) + if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) + && !S_ISLNK(inode->i_mode)) return; for (i = 0; i < 7; i++) - add_zone2 (i + inode->i_zone, &changed); - add_zone_ind2 (7 + inode->i_zone, &changed); - add_zone_dind2 (8 + inode->i_zone, &changed); - add_zone_tind2 (9 + inode->i_zone, &changed); + add_zone2(i + inode->i_zone, &changed); + add_zone_ind2(7 + inode->i_zone, &changed); + add_zone_dind2(8 + inode->i_zone, &changed); + add_zone_tind2(9 + inode->i_zone, &changed); } #endif -static void check_file(struct minix_inode * dir, unsigned int offset) +static void check_file(struct minix_inode *dir, unsigned int offset) { static char blk[BLOCK_SIZE]; - struct minix_inode * inode; + struct minix_inode *inode; int ino; - char * name; + char *name; int block; - block = map_block(dir,offset/BLOCK_SIZE); + block = map_block(dir, offset / BLOCK_SIZE); read_block(block, blk); name = blk + (offset % BLOCK_SIZE) + 2; - ino = * (unsigned short *) (name-2); + ino = *(unsigned short *) (name - 2); if (ino > INODES) { print_current_name(); printf(" contains a bad inode number for file '"); - printf("%.*s'.",namelen,name); - if (ask(" Remove",1)) { - *(unsigned short *)(name-2) = 0; + printf("%.*s'.", namelen, name); + if (ask(" Remove", 1)) { + *(unsigned short *) (name - 2) = 0; write_block(block, blk); } ino = 0; - } + } if (name_depth < MAX_DEPTH) - strncpy (name_list[name_depth], name, namelen); + strncpy(name_list[name_depth], name, namelen); name_depth++; inode = get_inode(ino); name_depth--; if (!offset) { - if (!inode || strcmp(".",name)) { + if (!inode || strcmp(".", name)) { print_current_name(); printf(": bad directory: '.' isn't first\n"); errors_uncorrected = 1; - } else return; + } else + return; } if (offset == dirsize) { - if (!inode || strcmp("..",name)) { + if (!inode || strcmp("..", name)) { print_current_name(); printf(": bad directory: '..' isn't second\n"); errors_uncorrected = 1; - } else return; + } else + return; } if (!inode) return; if (name_depth < MAX_DEPTH) - strncpy(name_list[name_depth],name,namelen); - name_depth++; + strncpy(name_list[name_depth], name, namelen); + name_depth++; if (list) { if (verbose) - printf("%6d %07o %3d ",ino,inode->i_mode,inode->i_nlinks); + printf("%6d %07o %3d ", ino, inode->i_mode, inode->i_nlinks); print_current_name(); if (S_ISDIR(inode->i_mode)) printf(":\n"); @@ -1008,8 +1009,7 @@ static void check_file(struct minix_inode * dir, unsigned int offset) } #ifdef HAVE_MINIX2 -static void -check_file2 (struct minix2_inode *dir, unsigned int offset) +static void check_file2(struct minix2_inode *dir, unsigned int offset) { static char blk[BLOCK_SIZE]; struct minix2_inode *inode; @@ -1017,37 +1017,37 @@ check_file2 (struct minix2_inode *dir, unsigned int offset) char *name; int block; - block = map_block2 (dir, offset / BLOCK_SIZE); - read_block (block, blk); + block = map_block2(dir, offset / BLOCK_SIZE); + read_block(block, blk); name = blk + (offset % BLOCK_SIZE) + 2; ino = *(unsigned short *) (name - 2); if (ino > INODES) { - print_current_name (); - printf (" contains a bad inode number for file '"); - printf ("%.*s'.", namelen, name); - if (ask (" Remove", 1)) { + print_current_name(); + printf(" contains a bad inode number for file '"); + printf("%.*s'.", namelen, name); + if (ask(" Remove", 1)) { *(unsigned short *) (name - 2) = 0; - write_block (block, blk); + write_block(block, blk); } ino = 0; } if (name_depth < MAX_DEPTH) - strncpy (name_list[name_depth], name, namelen); + strncpy(name_list[name_depth], name, namelen); name_depth++; - inode = get_inode2 (ino); + inode = get_inode2(ino); name_depth--; if (!offset) { - if (!inode || strcmp (".", name)) { - print_current_name (); - printf (": bad directory: '.' isn't first\n"); + if (!inode || strcmp(".", name)) { + print_current_name(); + printf(": bad directory: '.' isn't first\n"); errors_uncorrected = 1; } else return; } if (offset == dirsize) { - if (!inode || strcmp ("..", name)) { - print_current_name (); - printf (": bad directory: '..' isn't second\n"); + if (!inode || strcmp("..", name)) { + print_current_name(); + printf(": bad directory: '..' isn't second\n"); errors_uncorrected = 1; } else return; @@ -1057,16 +1057,16 @@ check_file2 (struct minix2_inode *dir, unsigned int offset) name_depth++; if (list) { if (verbose) - printf ("%6d %07o %3d ", ino, inode->i_mode, inode->i_nlinks); - print_current_name (); - if (S_ISDIR (inode->i_mode)) - printf (":\n"); + printf("%6d %07o %3d ", ino, inode->i_mode, inode->i_nlinks); + print_current_name(); + if (S_ISDIR(inode->i_mode)) + printf(":\n"); else - printf ("\n"); + printf("\n"); } - check_zones2 (ino); - if (inode && S_ISDIR (inode->i_mode)) - recursive_check2 (ino); + check_zones2(ino); + if (inode && S_ISDIR(inode->i_mode)) + recursive_check2(ino); name_depth--; return; } @@ -1074,7 +1074,7 @@ check_file2 (struct minix2_inode *dir, unsigned int offset) static void recursive_check(unsigned int ino) { - struct minix_inode * dir; + struct minix_inode *dir; unsigned int offset; dir = Inode + ino; @@ -1085,27 +1085,26 @@ static void recursive_check(unsigned int ino) printf(": bad directory: size<32"); errors_uncorrected = 1; } - for (offset = 0 ; offset < dir->i_size ; offset += dirsize) - check_file(dir,offset); + for (offset = 0; offset < dir->i_size; offset += dirsize) + check_file(dir, offset); } #ifdef HAVE_MINIX2 -static void -recursive_check2 (unsigned int ino) +static void recursive_check2(unsigned int ino) { struct minix2_inode *dir; unsigned int offset; dir = Inode2 + ino; - if (!S_ISDIR (dir->i_mode)) - die ("internal error"); + if (!S_ISDIR(dir->i_mode)) + die("internal error"); if (dir->i_size < 2 * dirsize) { - print_current_name (); - printf (": bad directory: size < 32"); + print_current_name(); + printf(": bad directory: size < 32"); errors_uncorrected = 1; } for (offset = 0; offset < dir->i_size; offset += dirsize) - check_file2 (dir, offset); + check_file2(dir, offset); } #endif @@ -1113,7 +1112,7 @@ static int bad_zone(int i) { char buffer[1024]; - if (BLOCK_SIZE*i != lseek(IN, BLOCK_SIZE*i, SEEK_SET)) + if (BLOCK_SIZE * i != lseek(IN, BLOCK_SIZE * i, SEEK_SET)) die("seek failed in bad_zone"); return (BLOCK_SIZE != read(IN, buffer, BLOCK_SIZE)); } @@ -1122,10 +1121,10 @@ static void check_counts(void) { int i; - for (i=1 ; i <= INODES ; i++) { + for (i = 1; i <= INODES; i++) { if (!inode_in_use(i) && Inode[i].i_mode && warn_mode) { - printf("Inode %d mode not cleared.",i); - if (ask("Clear",1)) { + printf("Inode %d mode not cleared.", i); + if (ask("Clear", 1)) { Inode[i].i_mode = 0; changed = 1; } @@ -1133,117 +1132,115 @@ static void check_counts(void) if (!inode_count[i]) { if (!inode_in_use(i)) continue; - printf("Inode %d not used, marked used in the bitmap.",i); - if (ask("Clear",1)) + printf("Inode %d not used, marked used in the bitmap.", i); + if (ask("Clear", 1)) unmark_inode(i); continue; } if (!inode_in_use(i)) { printf("Inode %d used, marked unused in the bitmap.", i); - if (ask("Set",1)) + if (ask("Set", 1)) mark_inode(i); } if (Inode[i].i_nlinks != inode_count[i]) { printf("Inode %d (mode = %07o), i_nlinks=%d, counted=%d.", - i,Inode[i].i_mode,Inode[i].i_nlinks,inode_count[i]); - if (ask("Set i_nlinks to count",1)) { - Inode[i].i_nlinks=inode_count[i]; - changed=1; + i, Inode[i].i_mode, Inode[i].i_nlinks, inode_count[i]); + if (ask("Set i_nlinks to count", 1)) { + Inode[i].i_nlinks = inode_count[i]; + changed = 1; } } } - for (i=FIRSTZONE ; i < ZONES ; i++) { + for (i = FIRSTZONE; i < ZONES; i++) { if (zone_in_use(i) == zone_count[i]) continue; if (!zone_count[i]) { if (bad_zone(i)) continue; - printf("Zone %d: marked in use, no file uses it.",i); - if (ask("Unmark",1)) + printf("Zone %d: marked in use, no file uses it.", i); + if (ask("Unmark", 1)) unmark_zone(i); continue; } - printf("Zone %d: %sin use, counted=%d\n", - i,zone_in_use(i)?"":"not ",zone_count[i]); + printf("Zone %d: %sin use, counted=%d\n", + i, zone_in_use(i) ? "" : "not ", zone_count[i]); } } #ifdef HAVE_MINIX2 -static void -check_counts2 (void) +static void check_counts2(void) { int i; for (i = 1; i <= INODES; i++) { - if (!inode_in_use (i) && Inode2[i].i_mode && warn_mode) { - printf ("Inode %d mode not cleared.", i); - if (ask ("Clear", 1)) { + if (!inode_in_use(i) && Inode2[i].i_mode && warn_mode) { + printf("Inode %d mode not cleared.", i); + if (ask("Clear", 1)) { Inode2[i].i_mode = 0; changed = 1; } } if (!inode_count[i]) { - if (!inode_in_use (i)) + if (!inode_in_use(i)) continue; - printf ("Inode %d not used, marked used in the bitmap.", i); - if (ask ("Clear", 1)) - unmark_inode (i); + printf("Inode %d not used, marked used in the bitmap.", i); + if (ask("Clear", 1)) + unmark_inode(i); continue; } - if (!inode_in_use (i)) { - printf ("Inode %d used, marked unused in the bitmap.", i); - if (ask ("Set", 1)) - mark_inode (i); + if (!inode_in_use(i)) { + printf("Inode %d used, marked unused in the bitmap.", i); + if (ask("Set", 1)) + mark_inode(i); } if (Inode2[i].i_nlinks != inode_count[i]) { - printf ("Inode %d (mode = %07o), i_nlinks=%d, counted=%d.", - i, Inode2[i].i_mode, Inode2[i].i_nlinks, inode_count[i]); - if (ask ("Set i_nlinks to count", 1)) { + printf("Inode %d (mode = %07o), i_nlinks=%d, counted=%d.", + i, Inode2[i].i_mode, Inode2[i].i_nlinks, + inode_count[i]); + if (ask("Set i_nlinks to count", 1)) { Inode2[i].i_nlinks = inode_count[i]; changed = 1; } } } for (i = FIRSTZONE; i < ZONES; i++) { - if (zone_in_use (i) == zone_count[i]) + if (zone_in_use(i) == zone_count[i]) continue; if (!zone_count[i]) { - if (bad_zone (i)) + if (bad_zone(i)) continue; - printf ("Zone %d: marked in use, no file uses it.", i); - if (ask ("Unmark", 1)) - unmark_zone (i); + printf("Zone %d: marked in use, no file uses it.", i); + if (ask("Unmark", 1)) + unmark_zone(i); continue; } - printf ("Zone %d: %sin use, counted=%d\n", - i, zone_in_use (i) ? "" : "not ", zone_count[i]); + printf("Zone %d: %sin use, counted=%d\n", + i, zone_in_use(i) ? "" : "not ", zone_count[i]); } } #endif static void check(void) { - memset(inode_count,0,(INODES + 1) * sizeof(*inode_count)); - memset(zone_count,0,ZONES*sizeof(*zone_count)); + memset(inode_count, 0, (INODES + 1) * sizeof(*inode_count)); + memset(zone_count, 0, ZONES * sizeof(*zone_count)); check_zones(ROOT_INO); recursive_check(ROOT_INO); check_counts(); } #ifdef HAVE_MINIX2 -static void -check2 (void) +static void check2(void) { - memset (inode_count, 0, (INODES + 1) * sizeof (*inode_count)); - memset (zone_count, 0, ZONES * sizeof (*zone_count)); - check_zones2 (ROOT_INO); - recursive_check2 (ROOT_INO); - check_counts2 (); + memset(inode_count, 0, (INODES + 1) * sizeof(*inode_count)); + memset(zone_count, 0, ZONES * sizeof(*zone_count)); + check_zones2(ROOT_INO); + recursive_check2(ROOT_INO); + check_counts2(); } #endif -extern int -fsck_minix_main(int argc, char ** argv) +extern int fsck_minix_main(int argc, char **argv) { struct termios tmp; int count; @@ -1264,29 +1261,47 @@ fsck_minix_main(int argc, char ** argv) show_usage(); else device_name = argv[0]; - } else while (*++argv[0]) - switch (argv[0][0]) { - case 'l': list=1; break; - case 'a': automatic=1; repair=1; break; - case 'r': automatic=0; repair=1; break; - case 'v': verbose=1; break; - case 's': show=1; break; - case 'm': warn_mode=1; break; - case 'f': force=1; break; - default: show_usage(); - } + } else + while (*++argv[0]) + switch (argv[0][0]) { + case 'l': + list = 1; + break; + case 'a': + automatic = 1; + repair = 1; + break; + case 'r': + automatic = 0; + repair = 1; + break; + case 'v': + verbose = 1; + break; + case 's': + show = 1; + break; + case 'm': + warn_mode = 1; + break; + case 'f': + force = 1; + break; + default: + show_usage(); + } } if (!device_name) show_usage(); - check_mount(); /* trying to check a mounted filesystem? */ + check_mount(); /* trying to check a mounted filesystem? */ if (repair && !automatic) { if (!isatty(0) || !isatty(1)) die("need terminal for interactive repairs"); } - IN = open(device_name,repair?O_RDWR:O_RDONLY); + IN = open(device_name, repair ? O_RDWR : O_RDONLY); if (IN < 0) die("unable to open '%s'"); - for (count=0 ; count<3 ; count++) + for (count = 0; count < 3; count++) sync(); read_superblock(); @@ -1297,80 +1312,77 @@ fsck_minix_main(int argc, char ** argv) * command line. */ printf("%s, %s\n", program_name, program_version); - if ( !(Super.s_state & MINIX_ERROR_FS) && - (Super.s_state & MINIX_VALID_FS) && - !force ) { + if (!(Super.s_state & MINIX_ERROR_FS) && + (Super.s_state & MINIX_VALID_FS) && !force) { if (repair) printf("%s is clean, no check.\n", device_name); return retcode; - } - else if (force) + } else if (force) printf("Forcing filesystem check on %s.\n", device_name); else if (repair) - printf("Filesystem on %s is dirty, needs checking.\n",\ - device_name); + printf("Filesystem on %s is dirty, needs checking.\n", + device_name); read_tables(); if (repair && !automatic) { - tcgetattr(0,&termios); + tcgetattr(0, &termios); tmp = termios; - tmp.c_lflag &= ~(ICANON|ECHO); - tcsetattr(0,TCSANOW,&tmp); + tmp.c_lflag &= ~(ICANON | ECHO); + tcsetattr(0, TCSANOW, &tmp); termios_set = 1; } - #if HAVE_MINIX2 if (version2) { - check_root2 (); - check2 (); - } else + check_root2(); + check2(); + } else #endif - { + { check_root(); check(); } if (verbose) { int i, free; - for (i=1,free=0 ; i <= INODES ; i++) + for (i = 1, free = 0; i <= INODES; i++) if (!inode_in_use(i)) free++; - printf("\n%6ld inodes used (%ld%%)\n",(INODES-free), - 100*(INODES-free)/INODES); - for (i=FIRSTZONE,free=0 ; i < ZONES ; i++) + printf("\n%6ld inodes used (%ld%%)\n", (INODES - free), + 100 * (INODES - free) / INODES); + for (i = FIRSTZONE, free = 0; i < ZONES; i++) if (!zone_in_use(i)) free++; - printf("%6ld zones used (%ld%%)\n",(ZONES-free), - 100*(ZONES-free)/ZONES); + printf("%6ld zones used (%ld%%)\n", (ZONES - free), + 100 * (ZONES - free) / ZONES); printf("\n%6d regular files\n" - "%6d directories\n" - "%6d character device files\n" - "%6d block device files\n" - "%6d links\n" - "%6d symbolic links\n" - "------\n" - "%6d files\n", - regular,directory,chardev,blockdev, - links-2*directory+1,symlinks,total-2*directory+1); + "%6d directories\n" + "%6d character device files\n" + "%6d block device files\n" + "%6d links\n" + "%6d symbolic links\n" + "------\n" + "%6d files\n", + regular, directory, chardev, blockdev, + links - 2 * directory + 1, symlinks, + total - 2 * directory + 1); } if (changed) { write_tables(); - printf( "----------------------------\n" - "FILE SYSTEM HAS BEEN CHANGED\n" - "----------------------------\n"); - for (count=0 ; count<3 ; count++) + printf("----------------------------\n" + "FILE SYSTEM HAS BEEN CHANGED\n" + "----------------------------\n"); + for (count = 0; count < 3; count++) sync(); - } - else if ( repair ) + } else if (repair) write_super_block(); - + if (repair && !automatic) - tcsetattr(0,TCSANOW,&termios); + tcsetattr(0, TCSANOW, &termios); if (changed) - retcode += 3; + retcode += 3; if (errors_uncorrected) - retcode += 4; + retcode += 4; return retcode; } 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 @@ +/* vi: set sw=4 ts=4: */ /* * mkfs.c - make a linux (minix) file-system. * @@ -107,27 +108,30 @@ #define BITS_PER_BLOCK (BLOCK_SIZE<<3) -static char * program_name = "mkfs"; -static char * device_name = NULL; +static char *program_name = "mkfs"; +static char *device_name = NULL; static int DEV = -1; static long BLOCKS = 0; static int check = 0; static int badblocks = 0; -static int namelen = 30; /* default (changed to 30, per Linus's - suggestion, Sun Nov 21 08:05:07 1993) */ +static int namelen = 30; /* default (changed to 30, per Linus's + + suggestion, Sun Nov 21 08:05:07 1993) */ static int dirsize = 32; static int magic = MINIX_SUPER_MAGIC2; static int version2 = 0; static char root_block[BLOCK_SIZE] = "\0"; -static char * inode_buffer = NULL; +static char *inode_buffer = NULL; + #define Inode (((struct minix_inode *) inode_buffer)-1) #ifdef HAVE_MINIX2 #define Inode2 (((struct minix2_inode *) inode_buffer)-1) #endif static char super_block_buffer[BLOCK_SIZE]; static char boot_block_buffer[512]; + #define Super (*(struct minix_super_block *)super_block_buffer) #define INODES ((unsigned long)Super.s_ninodes) #ifdef HAVE_MINIX2 @@ -164,21 +168,28 @@ static unsigned long req_nr_inodes = 0; * to compile this under minix, volatile gives a warning, as * exit() isn't defined as volatile under minix. */ -static volatile void die(char *str) { +static volatile void die(char *str) +{ fprintf(stderr, "%s: %s\n", program_name, str); exit(8); } static volatile void show_usage() { - fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", BB_VER, BB_BT); - fprintf(stderr, "Usage: %s [-c | -l filename] [-nXX] [-iXX] /dev/name [blocks]\n\n", program_name); + fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", + BB_VER, BB_BT); + fprintf(stderr, + "Usage: %s [-c | -l filename] [-nXX] [-iXX] /dev/name [blocks]\n\n", + program_name); fprintf(stderr, "Make a MINIX filesystem.\n\n"); fprintf(stderr, "OPTIONS:\n"); fprintf(stderr, "\t-c\t\tCheck the device for bad blocks\n"); - fprintf(stderr, "\t-n [14|30]\tSpecify the maximum length of filenames\n"); - fprintf(stderr, "\t-i\t\tSpecify the number of inodes for the filesystem\n"); - fprintf(stderr, "\t-l FILENAME\tRead the bad blocks list from FILENAME\n"); + fprintf(stderr, + "\t-n [14|30]\tSpecify the maximum length of filenames\n"); + fprintf(stderr, + "\t-i\t\tSpecify the number of inodes for the filesystem\n"); + fprintf(stderr, + "\t-l FILENAME\tRead the bad blocks list from FILENAME\n"); fprintf(stderr, "\t-v\t\tMake a Minix version 2 filesystem\n\n"); exit(16); } @@ -190,56 +201,55 @@ static volatile void show_usage() */ static void check_mount(void) { - FILE * f; - struct mntent * mnt; + FILE *f; + struct mntent *mnt; - if ((f = setmntent (MOUNTED, "r")) == NULL) + if ((f = setmntent(MOUNTED, "r")) == NULL) return; - while ((mnt = getmntent (f)) != NULL) - if (strcmp (device_name, mnt->mnt_fsname) == 0) + while ((mnt = getmntent(f)) != NULL) + if (strcmp(device_name, mnt->mnt_fsname) == 0) break; - endmntent (f); + endmntent(f); if (!mnt) return; die("%s is mounted; will not make a filesystem here!"); } -static long valid_offset (int fd, int offset) +static long valid_offset(int fd, int offset) { char ch; - if (lseek (fd, offset, 0) < 0) + if (lseek(fd, offset, 0) < 0) return 0; - if (read (fd, &ch, 1) < 1) + if (read(fd, &ch, 1) < 1) return 0; return 1; } -static int count_blocks (int fd) +static int count_blocks(int fd) { int high, low; low = 0; - for (high = 1; valid_offset (fd, high); high *= 2) + for (high = 1; valid_offset(fd, high); high *= 2) low = high; - while (low < high - 1) - { + while (low < high - 1) { const int mid = (low + high) / 2; - if (valid_offset (fd, mid)) + if (valid_offset(fd, mid)) low = mid; else high = mid; } - valid_offset (fd, 0); + valid_offset(fd, 0); return (low + 1); } -static int get_size(const char *file) +static int get_size(const char *file) { - int fd; - long size; + int fd; + long size; fd = open(file, O_RDWR); if (fd < 0) { @@ -250,7 +260,7 @@ static int get_size(const char *file) close(fd); return (size * 512); } - + size = count_blocks(fd); close(fd); return size; @@ -270,18 +280,18 @@ static void write_tables(void) die("seek failed in write_tables"); if (BLOCK_SIZE != write(DEV, super_block_buffer, BLOCK_SIZE)) die("unable to write super-block"); - if (IMAPS*BLOCK_SIZE != write(DEV,inode_map,IMAPS*BLOCK_SIZE)) + if (IMAPS * BLOCK_SIZE != write(DEV, inode_map, IMAPS * BLOCK_SIZE)) die("unable to write inode map"); - if (ZMAPS*BLOCK_SIZE != write(DEV,zone_map,ZMAPS*BLOCK_SIZE)) + if (ZMAPS * BLOCK_SIZE != write(DEV, zone_map, ZMAPS * BLOCK_SIZE)) die("unable to write zone map"); - if (INODE_BUFFER_SIZE != write(DEV,inode_buffer,INODE_BUFFER_SIZE)) + if (INODE_BUFFER_SIZE != write(DEV, inode_buffer, INODE_BUFFER_SIZE)) die("unable to write inodes"); - + } -static void write_block(int blk, char * buffer) +static void write_block(int blk, char *buffer) { - if (blk*BLOCK_SIZE != lseek(DEV, blk*BLOCK_SIZE, SEEK_SET)) + if (blk * BLOCK_SIZE != lseek(DEV, blk * BLOCK_SIZE, SEEK_SET)) die("seek failed in write_block"); if (BLOCK_SIZE != write(DEV, buffer, BLOCK_SIZE)) die("write failed in write_block"); @@ -291,10 +301,10 @@ static int get_free_block(void) { int blk; - if (used_good_blocks+1 >= MAX_GOOD_BLOCKS) + if (used_good_blocks + 1 >= MAX_GOOD_BLOCKS) die("too many bad blocks"); if (used_good_blocks) - blk = good_blocks_table[used_good_blocks-1]+1; + blk = good_blocks_table[used_good_blocks - 1] + 1; else blk = FIRSTZONE; while (blk < ZONES && zone_in_use(blk)) @@ -310,14 +320,14 @@ static void mark_good_blocks(void) { int blk; - for (blk=0 ; blk < used_good_blocks ; blk++) + for (blk = 0; blk < used_good_blocks; blk++) mark_zone(good_blocks_table[blk]); } inline int next(int zone) { if (!zone) - zone = FIRSTZONE-1; + zone = FIRSTZONE - 1; while (++zone < ZONES) if (zone_in_use(zone)) return zone; @@ -326,11 +336,11 @@ inline int next(int zone) static void make_bad_inode(void) { - struct minix_inode * inode = &Inode[MINIX_BAD_INO]; - int i,j,zone; - int ind=0,dind=0; - unsigned short ind_block[BLOCK_SIZE>>1]; - unsigned short dind_block[BLOCK_SIZE>>1]; + struct minix_inode *inode = &Inode[MINIX_BAD_INO]; + int i, j, zone; + int ind = 0, dind = 0; + unsigned short ind_block[BLOCK_SIZE >> 1]; + unsigned short dind_block[BLOCK_SIZE >> 1]; #define NEXT_BAD (zone = next(zone)) @@ -340,34 +350,34 @@ static void make_bad_inode(void) inode->i_nlinks = 1; inode->i_time = time(NULL); inode->i_mode = S_IFREG + 0000; - inode->i_size = badblocks*BLOCK_SIZE; + inode->i_size = badblocks * BLOCK_SIZE; zone = next(0); - for (i=0 ; i<7 ; i++) { + for (i = 0; i < 7; i++) { inode->i_zone[i] = zone; if (!NEXT_BAD) goto end_bad; } inode->i_zone[7] = ind = get_free_block(); - memset(ind_block,0,BLOCK_SIZE); - for (i=0 ; i<512 ; i++) { + memset(ind_block, 0, BLOCK_SIZE); + for (i = 0; i < 512; i++) { ind_block[i] = zone; if (!NEXT_BAD) goto end_bad; } inode->i_zone[8] = dind = get_free_block(); - memset(dind_block,0,BLOCK_SIZE); - for (i=0 ; i<512 ; i++) { - write_block(ind,(char *) ind_block); + memset(dind_block, 0, BLOCK_SIZE); + for (i = 0; i < 512; i++) { + write_block(ind, (char *) ind_block); dind_block[i] = ind = get_free_block(); - memset(ind_block,0,BLOCK_SIZE); - for (j=0 ; j<512 ; j++) { + memset(ind_block, 0, BLOCK_SIZE); + for (j = 0; j < 512; j++) { ind_block[j] = zone; if (!NEXT_BAD) goto end_bad; } } die("too many bad blocks"); -end_bad: + end_bad: if (ind) write_block(ind, (char *) ind_block); if (dind) @@ -375,8 +385,7 @@ end_bad: } #ifdef HAVE_MINIX2 -static void -make_bad_inode2 (void) +static void make_bad_inode2(void) { struct minix2_inode *inode = &Inode2[MINIX_BAD_INO]; int i, j, zone; @@ -386,30 +395,30 @@ make_bad_inode2 (void) if (!badblocks) return; - mark_inode (MINIX_BAD_INO); + mark_inode(MINIX_BAD_INO); inode->i_nlinks = 1; - inode->i_atime = inode->i_mtime = inode->i_ctime = time (NULL); + inode->i_atime = inode->i_mtime = inode->i_ctime = time(NULL); inode->i_mode = S_IFREG + 0000; inode->i_size = badblocks * BLOCK_SIZE; - zone = next (0); + zone = next(0); for (i = 0; i < 7; i++) { inode->i_zone[i] = zone; if (!NEXT_BAD) goto end_bad; } - inode->i_zone[7] = ind = get_free_block (); - memset (ind_block, 0, BLOCK_SIZE); + inode->i_zone[7] = ind = get_free_block(); + memset(ind_block, 0, BLOCK_SIZE); for (i = 0; i < 256; i++) { ind_block[i] = zone; if (!NEXT_BAD) goto end_bad; } - inode->i_zone[8] = dind = get_free_block (); - memset (dind_block, 0, BLOCK_SIZE); + inode->i_zone[8] = dind = get_free_block(); + memset(dind_block, 0, BLOCK_SIZE); for (i = 0; i < 256; i++) { - write_block (ind, (char *) ind_block); - dind_block[i] = ind = get_free_block (); - memset (ind_block, 0, BLOCK_SIZE); + write_block(ind, (char *) ind_block); + dind_block[i] = ind = get_free_block(); + memset(ind_block, 0, BLOCK_SIZE); for (j = 0; j < 256; j++) { ind_block[j] = zone; if (!NEXT_BAD) @@ -417,47 +426,46 @@ make_bad_inode2 (void) } } /* Could make triple indirect block here */ - die ("too many bad blocks"); - end_bad: + die("too many bad blocks"); + end_bad: if (ind) - write_block (ind, (char *) ind_block); + write_block(ind, (char *) ind_block); if (dind) - write_block (dind, (char *) dind_block); + write_block(dind, (char *) dind_block); } #endif static void make_root_inode(void) { - struct minix_inode * inode = &Inode[MINIX_ROOT_INO]; + struct minix_inode *inode = &Inode[MINIX_ROOT_INO]; mark_inode(MINIX_ROOT_INO); inode->i_zone[0] = get_free_block(); inode->i_nlinks = 2; inode->i_time = time(NULL); if (badblocks) - inode->i_size = 3*dirsize; + inode->i_size = 3 * dirsize; else { - root_block[2*dirsize] = '\0'; - root_block[2*dirsize+1] = '\0'; - inode->i_size = 2*dirsize; + root_block[2 * dirsize] = '\0'; + root_block[2 * dirsize + 1] = '\0'; + inode->i_size = 2 * dirsize; } inode->i_mode = S_IFDIR + 0755; inode->i_uid = getuid(); if (inode->i_uid) inode->i_gid = getgid(); - write_block(inode->i_zone[0],root_block); + write_block(inode->i_zone[0], root_block); } #ifdef HAVE_MINIX2 -static void -make_root_inode2 (void) +static void make_root_inode2(void) { struct minix2_inode *inode = &Inode2[MINIX_ROOT_INO]; - mark_inode (MINIX_ROOT_INO); - inode->i_zone[0] = get_free_block (); + mark_inode(MINIX_ROOT_INO); + inode->i_zone[0] = get_free_block(); inode->i_nlinks = 2; - inode->i_atime = inode->i_mtime = inode->i_ctime = time (NULL); + inode->i_atime = inode->i_mtime = inode->i_ctime = time(NULL); if (badblocks) inode->i_size = 3 * dirsize; else { @@ -469,7 +477,7 @@ make_root_inode2 (void) inode->i_uid = getuid(); if (inode->i_uid) inode->i_gid = getgid(); - write_block (inode->i_zone[0], root_block); + write_block(inode->i_zone[0], root_block); } #endif @@ -478,34 +486,38 @@ static void setup_tables(void) int i; unsigned long inodes; - memset(super_block_buffer,0,BLOCK_SIZE); - memset(boot_block_buffer,0,512); + memset(super_block_buffer, 0, BLOCK_SIZE); + memset(boot_block_buffer, 0, 512); MAGIC = magic; ZONESIZE = 0; - MAXSIZE = version2 ? 0x7fffffff : (7+512+512*512)*1024; + MAXSIZE = version2 ? 0x7fffffff : (7 + 512 + 512 * 512) * 1024; ZONES = BLOCKS; /* some magic nrs: 1 inode / 3 blocks */ - if ( req_nr_inodes == 0 ) - inodes = BLOCKS/3; + if (req_nr_inodes == 0) + inodes = BLOCKS / 3; else inodes = req_nr_inodes; /* Round up inode count to fill block size */ #ifdef HAVE_MINIX2 if (version2) inodes = ((inodes + MINIX2_INODES_PER_BLOCK - 1) & - ~(MINIX2_INODES_PER_BLOCK - 1)); + ~(MINIX2_INODES_PER_BLOCK - 1)); else #endif inodes = ((inodes + MINIX_INODES_PER_BLOCK - 1) & - ~(MINIX_INODES_PER_BLOCK - 1)); + ~(MINIX_INODES_PER_BLOCK - 1)); if (inodes > 65535) inodes = 65535; INODES = inodes; - IMAPS = UPPER(INODES + 1,BITS_PER_BLOCK); + IMAPS = UPPER(INODES + 1, BITS_PER_BLOCK); ZMAPS = 0; - i=0; - while (ZMAPS != UPPER(BLOCKS - (2+IMAPS+ZMAPS+INODE_BLOCKS) + 1,BITS_PER_BLOCK) && i<1000) { - ZMAPS = UPPER(BLOCKS - (2+IMAPS+ZMAPS+INODE_BLOCKS) + 1,BITS_PER_BLOCK); + i = 0; + while (ZMAPS != + UPPER(BLOCKS - (2 + IMAPS + ZMAPS + INODE_BLOCKS) + 1, + BITS_PER_BLOCK) && i < 1000) { + ZMAPS = + UPPER(BLOCKS - (2 + IMAPS + ZMAPS + INODE_BLOCKS) + 1, + BITS_PER_BLOCK); i++; } /* Real bad hack but overwise mkfs.minix can be thrown @@ -514,50 +526,51 @@ static void setup_tables(void) * dd if=/dev/zero of=test.fs count=10 bs=1024 * /sbin/mkfs.minix -i 200 test.fs * */ - if (i>=999) { - die ("unable to allocate buffers for maps"); + if (i >= 999) { + die("unable to allocate buffers for maps"); } FIRSTZONE = NORM_FIRSTZONE; inode_map = malloc(IMAPS * BLOCK_SIZE); zone_map = malloc(ZMAPS * BLOCK_SIZE); if (!inode_map || !zone_map) die("unable to allocate buffers for maps"); - memset(inode_map,0xff,IMAPS * BLOCK_SIZE); - memset(zone_map,0xff,ZMAPS * BLOCK_SIZE); - for (i = FIRSTZONE ; i<ZONES ; i++) + memset(inode_map, 0xff, IMAPS * BLOCK_SIZE); + memset(zone_map, 0xff, ZMAPS * BLOCK_SIZE); + for (i = FIRSTZONE; i < ZONES; i++) unmark_zone(i); - for (i = MINIX_ROOT_INO ; i<=INODES ; i++) + for (i = MINIX_ROOT_INO; i <= INODES; i++) unmark_inode(i); inode_buffer = malloc(INODE_BUFFER_SIZE); if (!inode_buffer) die("unable to allocate buffer for inodes"); - memset(inode_buffer,0,INODE_BUFFER_SIZE); - printf("%ld inodes\n",INODES); - printf("%ld blocks\n",ZONES); - printf("Firstdatazone=%ld (%ld)\n",FIRSTZONE,NORM_FIRSTZONE); - printf("Zonesize=%d\n",BLOCK_SIZE<<ZONESIZE); - printf("Maxsize=%ld\n\n",MAXSIZE); + memset(inode_buffer, 0, INODE_BUFFER_SIZE); + printf("%ld inodes\n", INODES); + printf("%ld blocks\n", ZONES); + printf("Firstdatazone=%ld (%ld)\n", FIRSTZONE, NORM_FIRSTZONE); + printf("Zonesize=%d\n", BLOCK_SIZE << ZONESIZE); + printf("Maxsize=%ld\n\n", MAXSIZE); } /* * Perform a test of a block; return the number of * blocks readable/writeable. */ -long do_check(char * buffer, int try, unsigned int current_block) +long do_check(char *buffer, int try, unsigned int current_block) { long got; - + /* Seek to the correct loc. */ if (lseek(DEV, current_block * BLOCK_SIZE, SEEK_SET) != - current_block * BLOCK_SIZE ) { - die("seek failed during testing of blocks"); + current_block * BLOCK_SIZE) { + die("seek failed during testing of blocks"); } /* Try the read */ got = read(DEV, buffer, try * BLOCK_SIZE); - if (got < 0) got = 0; - if (got & (BLOCK_SIZE - 1 )) { + if (got < 0) + got = 0; + if (got & (BLOCK_SIZE - 1)) { printf("Weird values in do_check: probably bugs\n"); } got /= BLOCK_SIZE; @@ -570,7 +583,7 @@ static void alarm_intr(int alnum) { if (currently_testing >= ZONES) return; - signal(SIGALRM,alarm_intr); + signal(SIGALRM, alarm_intr); alarm(5); if (!currently_testing) return; @@ -580,19 +593,19 @@ static void alarm_intr(int alnum) static void check_blocks(void) { - int try,got; + int try, got; static char buffer[BLOCK_SIZE * TEST_BUFFER_BLOCKS]; - currently_testing=0; - signal(SIGALRM,alarm_intr); + currently_testing = 0; + signal(SIGALRM, alarm_intr); alarm(5); while (currently_testing < ZONES) { - if (lseek(DEV,currently_testing*BLOCK_SIZE,SEEK_SET) != - currently_testing*BLOCK_SIZE) + if (lseek(DEV, currently_testing * BLOCK_SIZE, SEEK_SET) != + currently_testing * BLOCK_SIZE) die("seek failed in check_blocks"); try = TEST_BUFFER_BLOCKS; if (currently_testing + try > ZONES) - try = ZONES-currently_testing; + try = ZONES - currently_testing; got = do_check(buffer, try, currently_testing); currently_testing += got; if (got == try) @@ -613,139 +626,141 @@ static void get_list_blocks(filename) char *filename; { - FILE *listfile; - unsigned long blockno; - - listfile=fopen(filename,"r"); - if(listfile == (FILE *)NULL) { - die("can't open file of bad blocks"); - } - while(!feof(listfile)) { - fscanf(listfile,"%ld\n", &blockno); - mark_zone(blockno); - badblocks++; - } - if(badblocks > 1) - printf("%d bad blocks\n", badblocks); - else if (badblocks == 1) - printf("one bad block\n"); + FILE *listfile; + unsigned long blockno; + + listfile = fopen(filename, "r"); + if (listfile == (FILE *) NULL) { + die("can't open file of bad blocks"); + } + while (!feof(listfile)) { + fscanf(listfile, "%ld\n", &blockno); + mark_zone(blockno); + badblocks++; + } + if (badblocks > 1) + printf("%d bad blocks\n", badblocks); + else if (badblocks == 1) + printf("one bad block\n"); } -extern int -mkfs_minix_main(int argc, char ** argv) +extern int mkfs_minix_main(int argc, char **argv) { - int i; - char * tmp; - struct stat statbuf; - char * listfile = NULL; - - if (argc && *argv) - program_name = *argv; - if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE) - die("bad inode size"); + int i; + char *tmp; + struct stat statbuf; + char *listfile = NULL; + + if (argc && *argv) + program_name = *argv; + if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE) + die("bad inode size"); #ifdef HAVE_MINIX2 - if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) - die("bad inode size"); + if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) + die("bad inode size"); #endif - opterr = 0; - while ((i = getopt(argc, argv, "ci:l:n:v")) != EOF) - switch (i) { - case 'c': - check=1; break; - case 'i': - req_nr_inodes = (unsigned long) atol(optarg); - break; - case 'l': - listfile = optarg; break; - case 'n': - i = strtoul(optarg,&tmp,0); - if (*tmp) - show_usage(); - if (i == 14) - magic = MINIX_SUPER_MAGIC; - else if (i == 30) - magic = MINIX_SUPER_MAGIC2; - else - show_usage(); - namelen = i; - dirsize = i+2; - break; - case 'v': + opterr = 0; + while ((i = getopt(argc, argv, "ci:l:n:v")) != EOF) + switch (i) { + case 'c': + check = 1; + break; + case 'i': + req_nr_inodes = (unsigned long) atol(optarg); + break; + case 'l': + listfile = optarg; + break; + case 'n': + i = strtoul(optarg, &tmp, 0); + if (*tmp) + show_usage(); + if (i == 14) + magic = MINIX_SUPER_MAGIC; + else if (i == 30) + magic = MINIX_SUPER_MAGIC2; + else + show_usage(); + namelen = i; + dirsize = i + 2; + break; + case 'v': #ifdef HAVE_MINIX2 - version2 = 1; + version2 = 1; #else - fprintf(stderr,"%s: not compiled with minix v2 support\n",program_name,device_name); - exit(-1); + fprintf(stderr, "%s: not compiled with minix v2 support\n", + program_name, device_name); + exit(-1); #endif - break; - default: - show_usage(); - } - argc -= optind; - argv += optind; - if (argc > 0 && !device_name) { - device_name = argv[0]; - argc--; - argv++; - } - if (argc > 0) { - BLOCKS = strtol(argv[0],&tmp,0); - if (*tmp) { - printf("strtol error: number of blocks not specified"); - show_usage(); - } - } - - if (device_name && !BLOCKS) - BLOCKS = get_size (device_name) / 1024; - if (!device_name || BLOCKS<10) { - show_usage(); - } + break; + default: + show_usage(); + } + argc -= optind; + argv += optind; + if (argc > 0 && !device_name) { + device_name = argv[0]; + argc--; + argv++; + } + if (argc > 0) { + BLOCKS = strtol(argv[0], &tmp, 0); + if (*tmp) { + printf("strtol error: number of blocks not specified"); + show_usage(); + } + } + + if (device_name && !BLOCKS) + BLOCKS = get_size(device_name) / 1024; + if (!device_name || BLOCKS < 10) { + show_usage(); + } #ifdef HAVE_MINIX2 - if (version2) { - if (namelen == 14) - magic = MINIX2_SUPER_MAGIC; - else - magic = MINIX2_SUPER_MAGIC2; - } else + if (version2) { + if (namelen == 14) + magic = MINIX2_SUPER_MAGIC; + else + magic = MINIX2_SUPER_MAGIC2; + } else #endif - if (BLOCKS > 65535) - BLOCKS = 65535; - check_mount(); /* is it already mounted? */ - tmp = root_block; - *(short *)tmp = 1; - strcpy(tmp+2,"."); - tmp += dirsize; - *(short *)tmp = 1; - strcpy(tmp+2,".."); - tmp += dirsize; - *(short *)tmp = 2; - strcpy(tmp+2,".badblocks"); - DEV = open(device_name,O_RDWR ); - if (DEV<0) - die("unable to open %s"); - if (fstat(DEV,&statbuf)<0) - die("unable to stat %s"); - if (!S_ISBLK(statbuf.st_mode)) - check=0; - else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) - die("will not try to make filesystem on '%s'"); - setup_tables(); - if (check) - check_blocks(); - else if (listfile) - get_list_blocks(listfile); + if (BLOCKS > 65535) + BLOCKS = 65535; + check_mount(); /* is it already mounted? */ + tmp = root_block; + *(short *) tmp = 1; + strcpy(tmp + 2, "."); + tmp += dirsize; + *(short *) tmp = 1; + strcpy(tmp + 2, ".."); + tmp += dirsize; + *(short *) tmp = 2; + strcpy(tmp + 2, ".badblocks"); + DEV = open(device_name, O_RDWR); + if (DEV < 0) + die("unable to open %s"); + if (fstat(DEV, &statbuf) < 0) + die("unable to stat %s"); + if (!S_ISBLK(statbuf.st_mode)) + check = 0; + else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) + die("will not try to make filesystem on '%s'"); + setup_tables(); + if (check) + check_blocks(); + else if (listfile) + get_list_blocks(listfile); #ifdef HAVE_MINIX2 - if (version2) { - make_root_inode2 (); - make_bad_inode2 (); - } else + if (version2) { + make_root_inode2(); + make_bad_inode2(); + } else #endif - { - make_root_inode(); - make_bad_inode(); - } - mark_good_blocks(); - write_tables(); - return 0; + { + make_root_inode(); + make_bad_inode(); + } + mark_good_blocks(); + write_tables(); + return 0; } 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 @@ +/* vi: set sw=4 ts=4: */ /* * mkswap.c - set up a linux swap device * @@ -40,20 +41,21 @@ #include <string.h> #include <fcntl.h> #include <stdlib.h> -#include <sys/ioctl.h> /* for _IO */ +#include <sys/ioctl.h> /* for _IO */ #include <sys/utsname.h> #include <sys/stat.h> -#include <asm/page.h> /* for PAGE_SIZE and PAGE_SHIFT */ +#include <asm/page.h> /* for PAGE_SIZE and PAGE_SHIFT */ /* we also get PAGE_SIZE via getpagesize() */ -static const char mkswap_usage[] = "mkswap [-c] [-v0|-v1] device [block-count]\n\n" -"Prepare a disk partition to be used as a swap partition.\n\n" -"Options:\n" -"\t-c\t\tCheck for read-ability.\n" -"\t-v0\t\tMake version 0 swap [max 128 Megs].\n" -"\t-v1\t\tMake version 1 swap [big!] (default for kernels > 2.1.117).\n" -"\tblock-count\tNumber of block to use (default is entire partition).\n"; +static const char mkswap_usage[] = + "mkswap [-c] [-v0|-v1] device [block-count]\n\n" + "Prepare a disk partition to be used as a swap partition.\n\n" + "Options:\n" "\t-c\t\tCheck for read-ability.\n" + "\t-v0\t\tMake version 0 swap [max 128 Megs].\n" + "\t-v1\t\tMake version 1 swap [big!] (default for kernels > 2.1.117).\n" + + "\tblock-count\tNumber of block to use (default is entire partition).\n"; #ifndef _IO @@ -64,8 +66,8 @@ static const char mkswap_usage[] = "mkswap [-c] [-v0|-v1] device [block-count]\n #define BLKGETSIZE _IO(0x12,96) #endif -static char * program_name = "mkswap"; -static char * device_name = NULL; +static char *program_name = "mkswap"; +static char *device_name = NULL; static int DEV = -1; static long PAGES = 0; static int check = 0; @@ -74,8 +76,8 @@ static int version = -1; #define MAKE_VERSION(p,q,r) (65536*(p) + 256*(q) + (r)) -static int -linux_version_code(void) { +static int linux_version_code(void) +{ struct utsname my_utsname; int p, q, r; @@ -83,7 +85,7 @@ linux_version_code(void) { p = atoi(strtok(my_utsname.release, ".")); q = atoi(strtok(NULL, ".")); r = atoi(strtok(NULL, ".")); - return MAKE_VERSION(p,q,r); + return MAKE_VERSION(p, q, r); } return 0; } @@ -98,7 +100,7 @@ static int pagesize; static int *signature_page; struct swap_header_v1 { - char bootbits[1024]; /* Space for disklabel etc. */ + char bootbits[1024]; /* Space for disklabel etc. */ unsigned int version; unsigned int last_page; unsigned int nr_badpages; @@ -106,8 +108,8 @@ struct swap_header_v1 { unsigned int badpages[1]; } *p; -static void -init_signature_page() { +static void init_signature_page() +{ pagesize = getpagesize(); #ifdef PAGE_SIZE @@ -115,15 +117,15 @@ init_signature_page() { fprintf(stderr, "Assuming pages of size %d\n", pagesize); #endif signature_page = (int *) malloc(pagesize); - memset(signature_page,0,pagesize); + memset(signature_page, 0, pagesize); p = (struct swap_header_v1 *) signature_page; } -static void -write_signature(char *sig) { +static void write_signature(char *sig) +{ char *sp = (char *) signature_page; - strncpy(sp+pagesize-10, sig, 10); + strncpy(sp + pagesize - 10, sig, 10); } #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, #define MAX_BADPAGES ((pagesize-1024-128*sizeof(int)-10)/sizeof(int)) -static void bit_set (unsigned int *addr, unsigned int nr) +static void bit_set(unsigned int *addr, unsigned int nr) { unsigned int r, m; addr += nr / (8 * sizeof(int)); + r = *addr; m = 1 << (nr & (8 * sizeof(int) - 1)); + *addr = r | m; } -static int bit_test_and_clear (unsigned int *addr, unsigned int nr) +static int bit_test_and_clear(unsigned int *addr, unsigned int nr) { unsigned int r, m; addr += nr / (8 * sizeof(int)); + r = *addr; m = 1 << (nr & (8 * sizeof(int) - 1)); + *addr = r & ~m; return (r & m) != 0; } -void -die(const char *str) { +void die(const char *str) +{ fprintf(stderr, "%s: %s\n", program_name, str); - exit( FALSE); + exit(FALSE); } -void -page_ok(int page) { - if (version==0) +void page_ok(int page) +{ + if (version == 0) bit_set(signature_page, page); } -void -page_bad(int page) { +void page_bad(int page) +{ if (version == 0) bit_test_and_clear(signature_page, page); else { @@ -218,8 +224,8 @@ page_bad(int page) { badpages++; } -void -check_blocks(void) { +void check_blocks(void) +{ unsigned int current_page; int do_seek = 1; char *buffer; @@ -233,8 +239,8 @@ check_blocks(void) { page_ok(current_page++); continue; } - if (do_seek && lseek(DEV,current_page*pagesize,SEEK_SET) != - current_page*pagesize) + if (do_seek && lseek(DEV, current_page * pagesize, SEEK_SET) != + current_page * pagesize) die("seek failed in check_blocks"); if ((do_seek = (pagesize != read(DEV, buffer, pagesize)))) { page_bad(current_page++); @@ -248,30 +254,28 @@ check_blocks(void) { printf("%d bad pages\n", badpages); } -static long valid_offset (int fd, int offset) +static long valid_offset(int fd, int offset) { char ch; - if (lseek (fd, offset, 0) < 0) + if (lseek(fd, offset, 0) < 0) return 0; - if (read (fd, &ch, 1) < 1) + if (read(fd, &ch, 1) < 1) return 0; return 1; } -static int -find_size (int fd) +static int find_size(int fd) { unsigned int high, low; low = 0; - for (high = 1; high > 0 && valid_offset (fd, high); high *= 2) + for (high = 1; high > 0 && valid_offset(fd, high); high *= 2) low = high; - while (low < high - 1) - { + while (low < high - 1) { const int mid = (low + high) / 2; - if (valid_offset (fd, mid)) + if (valid_offset(fd, mid)) low = mid; else high = mid; @@ -280,11 +284,10 @@ find_size (int fd) } /* return size in pages, to avoid integer overflow */ -static long -get_size(const char *file) +static long get_size(const char *file) { - int fd; - long size; + int fd; + long size; fd = open(file, O_RDONLY); if (fd < 0) { @@ -292,7 +295,8 @@ get_size(const char *file) exit(1); } if (ioctl(fd, BLKGETSIZE, &size) >= 0) { - int sectors_per_page = pagesize/512; + int sectors_per_page = pagesize / 512; + size /= sectors_per_page; } else { size = find_size(fd) / pagesize; @@ -301,9 +305,9 @@ get_size(const char *file) return size; } -int mkswap_main(int argc, char ** argv) +int mkswap_main(int argc, char **argv) { - char * tmp; + char *tmp; struct stat statbuf; int sz; int maxpages; @@ -314,56 +318,56 @@ int mkswap_main(int argc, char ** argv) if (argc && *argv) program_name = *argv; - init_signature_page(); /* get pagesize */ + init_signature_page(); /* get pagesize */ while (argc-- > 1) { argv++; if (argv[0][0] != '-') { if (device_name) { - int blocks_per_page = pagesize/1024; - PAGES = strtol(argv[0],&tmp,0)/blocks_per_page; + int blocks_per_page = pagesize / 1024; + + PAGES = strtol(argv[0], &tmp, 0) / blocks_per_page; if (*tmp) - usage( mkswap_usage); + usage(mkswap_usage); } else device_name = argv[0]; } else { switch (argv[0][1]) { - case 'c': - check=1; - break; - case 'f': - force=1; - break; - case 'v': - version=atoi(argv[0]+2); - break; - default: - usage( mkswap_usage); + case 'c': + check = 1; + break; + case 'f': + force = 1; + break; + case 'v': + version = atoi(argv[0] + 2); + break; + default: + usage(mkswap_usage); } } } if (!device_name) { fprintf(stderr, - "%s: error: Nowhere to set up swap on?\n", - program_name); - usage( mkswap_usage); + "%s: error: Nowhere to set up swap on?\n", program_name); + usage(mkswap_usage); } sz = get_size(device_name); if (!PAGES) { PAGES = sz; } else if (PAGES > sz && !force) { fprintf(stderr, - "%s: error: " - "size %ld is larger than device size %d\n", - program_name, - PAGES*(pagesize/1024), sz*(pagesize/1024)); - exit( FALSE); + "%s: error: " + "size %ld is larger than device size %d\n", + program_name, + PAGES * (pagesize / 1024), sz * (pagesize / 1024)); + exit(FALSE); } if (version == -1) { if (PAGES <= V0_MAX_PAGES) version = 0; - else if (linux_version_code() < MAKE_VERSION(2,1,117)) + else if (linux_version_code() < MAKE_VERSION(2, 1, 117)) version = 0; else if (pagesize < 2048) version = 0; @@ -372,21 +376,21 @@ int mkswap_main(int argc, char ** argv) } if (version != 0 && version != 1) { fprintf(stderr, "%s: error: unknown version %d\n", - program_name, version); - usage( mkswap_usage); + program_name, version); + usage(mkswap_usage); } if (PAGES < 10) { fprintf(stderr, - "%s: error: swap area needs to be at least %ldkB\n", - program_name, (long)(10 * pagesize / 1024)); - usage( mkswap_usage); + "%s: error: swap area needs to be at least %ldkB\n", + program_name, (long) (10 * pagesize / 1024)); + usage(mkswap_usage); } #if 0 maxpages = ((version == 0) ? V0_MAX_PAGES : V1_MAX_PAGES); #else if (!version) maxpages = V0_MAX_PAGES; - else if (linux_version_code() >= MAKE_VERSION(2,2,1)) + else if (linux_version_code() >= MAKE_VERSION(2, 2, 1)) maxpages = V1_MAX_PAGES; else { maxpages = V1_OLD_MAX_PAGES; @@ -397,29 +401,29 @@ int mkswap_main(int argc, char ** argv) if (PAGES > maxpages) { PAGES = maxpages; fprintf(stderr, "%s: warning: truncating swap area to %ldkB\n", - program_name, PAGES * pagesize / 1024); + program_name, PAGES * pagesize / 1024); } - DEV = open(device_name,O_RDWR); + DEV = open(device_name, O_RDWR); if (DEV < 0 || fstat(DEV, &statbuf) < 0) { perror(device_name); - exit( FALSE); + exit(FALSE); } if (!S_ISBLK(statbuf.st_mode)) - check=0; + check = 0; else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) die("Will not try to make swapdevice on '%s'"); #ifdef __sparc__ if (!force && version == 0) { /* Don't overwrite partition table unless forced */ - unsigned char *buffer = (unsigned char *)signature_page; + unsigned char *buffer = (unsigned char *) signature_page; unsigned short *q, sum; if (read(DEV, buffer, 512) != 512) die("fatal: first page unreadable"); if (buffer[508] == 0xDA && buffer[509] == 0xBE) { - q = (unsigned short *)(buffer + 510); + q = (unsigned short *) (buffer + 510); for (sum = 0; q >= (unsigned short *) buffer;) sum ^= *q--; if (!sum) { @@ -427,9 +431,8 @@ int mkswap_main(int argc, char ** argv) %s: Device '%s' contains a valid Sun disklabel.\n\ This probably means creating v0 swap would destroy your partition table\n\ No swap created. If you really want to create swap v0 on that device, use\n\ -the -f option to force it.\n", - program_name, device_name); - exit( FALSE); +the -f option to force it.\n", program_name, device_name); + exit(FALSE); } } } @@ -437,11 +440,11 @@ the -f option to force it.\n", if (version == 0 || check) check_blocks(); - if (version == 0 && !bit_test_and_clear(signature_page,0)) + if (version == 0 && !bit_test_and_clear(signature_page, 0)) die("fatal: first page unreadable"); if (version == 1) { p->version = version; - p->last_page = PAGES-1; + p->last_page = PAGES - 1; p->nr_badpages = badpages; } @@ -449,14 +452,14 @@ the -f option to force it.\n", if (goodpages <= 0) die("Unable to set up swap-space: unreadable"); printf("Setting up swapspace version %d, size = %ld bytes\n", - version, (long)(goodpages*pagesize)); + version, (long) (goodpages * pagesize)); write_signature((version == 0) ? "SWAP-SPACE" : "SWAPSPACE2"); offset = ((version == 0) ? 0 : 1024); if (lseek(DEV, offset, SEEK_SET) != offset) die("unable to rewind swap-device"); - if (write(DEV,(char*)signature_page+offset, pagesize-offset) - != pagesize-offset) + if (write(DEV, (char *) signature_page + offset, pagesize - offset) + != pagesize - offset) die("unable to write signature page"); /* @@ -464,6 +467,6 @@ the -f option to force it.\n", * is not actually on disk. (This is a kernel bug.) */ if (fsync(DEV)) - die("fsync failed"); - exit ( TRUE); + die("fsync failed"); + exit(TRUE); } 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 @@ +/* vi: set sw=4 ts=4: */ /* * Mini more implementation for busybox * @@ -45,19 +46,20 @@ static const char more_usage[] = "more [file ...]\n"; # define stty(fd,argp) tcsetattr(fd,TCSANOW,argp) #endif - FILE *cin; - struct termios initial_settings, new_settings; +FILE *cin; +struct termios initial_settings, new_settings; - void gotsig(int sig) { - stty(fileno(cin), &initial_settings); - fprintf(stdout, "\n"); - exit( TRUE); - } +void gotsig(int sig) +{ + stty(fileno(cin), &initial_settings); + fprintf(stdout, "\n"); + exit(TRUE); +} #endif -#define TERMINAL_WIDTH 79 /* not 80 in case terminal has linefold bug */ +#define TERMINAL_WIDTH 79 /* not 80 in case terminal has linefold bug */ #define TERMINAL_HEIGHT 24 @@ -72,118 +74,121 @@ static int terminal_width = 0, terminal_height = 0; extern int more_main(int argc, char **argv) { - int c, lines=0, input=0; - int next_page=0; - struct stat st; - FILE *file; + int c, lines = 0, input = 0; + int next_page = 0; + struct stat st; + FILE *file; + #ifdef BB_FEATURE_AUTOWIDTH - struct winsize win = {0,0}; + struct winsize win = { 0, 0 }; #endif - argc--; - argv++; - - if ( argc > 0 && (strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0) ) { - usage (more_usage); - } - do { - if (argc==0) { - file = stdin; - } - else - file = fopen(*argv, "r"); + argc--; + argv++; - if (file == NULL) { - perror(*argv); - exit(FALSE); + if (argc > 0 + && (strcmp(*argv, "--help") == 0 || strcmp(*argv, "-h") == 0)) { + usage(more_usage); } - fstat(fileno(file), &st); + do { + if (argc == 0) { + file = stdin; + } else + file = fopen(*argv, "r"); + + if (file == NULL) { + perror(*argv); + exit(FALSE); + } + fstat(fileno(file), &st); #ifdef BB_FEATURE_USE_TERMIOS - cin = fopen("/dev/tty", "r"); - if (!cin) - cin = fopen("/dev/console", "r"); + cin = fopen("/dev/tty", "r"); + if (!cin) + cin = fopen("/dev/console", "r"); #ifdef USE_OLD_TERMIO - ioctl(fileno(cin),TCGETA,&initial_settings); + ioctl(fileno(cin), TCGETA, &initial_settings); #else - tcgetattr(fileno(cin),&initial_settings); + tcgetattr(fileno(cin), &initial_settings); #endif - new_settings = initial_settings; - new_settings.c_lflag &= ~ICANON; - new_settings.c_lflag &= ~ECHO; - stty(fileno(cin), &new_settings); - -#ifdef BB_FEATURE_AUTOWIDTH - ioctl(fileno(stdout), TIOCGWINSZ, &win); - if (win.ws_row > 4) - terminal_height = win.ws_row - 2; - if (win.ws_col > 0) - terminal_width = win.ws_col - 1; + new_settings = initial_settings; + new_settings.c_lflag &= ~ICANON; + new_settings.c_lflag &= ~ECHO; + stty(fileno(cin), &new_settings); + +#ifdef BB_FEATURE_AUTOWIDTH + ioctl(fileno(stdout), TIOCGWINSZ, &win); + if (win.ws_row > 4) + terminal_height = win.ws_row - 2; + if (win.ws_col > 0) + terminal_width = win.ws_col - 1; #endif - (void) signal(SIGINT, gotsig); - (void) signal(SIGQUIT, gotsig); - (void) signal(SIGTERM, gotsig); + (void) signal(SIGINT, gotsig); + (void) signal(SIGQUIT, gotsig); + (void) signal(SIGTERM, gotsig); #endif - while ((c = getc(file)) != EOF) { - if ( next_page ) { - int len=0; - next_page = 0; - lines=0; - len = fprintf(stdout, "--More-- "); - if (file != stdin) { - len += fprintf(stdout, "(%d%% of %ld bytes)", - (int) (100*( (double) ftell(file) / (double) st.st_size )), - st.st_size); - } - len += fprintf(stdout, "%s", + while ((c = getc(file)) != EOF) { + if (next_page) { + int len = 0; + + next_page = 0; + lines = 0; + len = fprintf(stdout, "--More-- "); + if (file != stdin) { + len += fprintf(stdout, "(%d%% of %ld bytes)", + (int) (100 * + ((double) ftell(file) / + (double) st.st_size)), + st.st_size); + } + len += fprintf(stdout, "%s", #ifdef BB_FEATURE_USE_TERMIOS - "" + "" #else - "\n" + "\n" #endif - ); + ); - fflush(stdout); - input = getc( cin); + fflush(stdout); + input = getc(cin); #ifdef BB_FEATURE_USE_TERMIOS - /* Erase the "More" message */ - while(--len >= 0) - putc('\b', stdout); - while(++len <= terminal_width) - putc(' ', stdout); - while(--len >= 0) - putc('\b', stdout); - fflush(stdout); + /* Erase the "More" message */ + while (--len >= 0) + putc('\b', stdout); + while (++len <= terminal_width) + putc(' ', stdout); + while (--len >= 0) + putc('\b', stdout); + fflush(stdout); #endif - } - if (c == '\n' ) { - switch(input) { - case 'q': - goto end; - case '\n': - /* increment by just one line if we are at - * the end of this line*/ - next_page = 1; - break; + } + if (c == '\n') { + switch (input) { + case 'q': + goto end; + case '\n': + /* increment by just one line if we are at + * the end of this line*/ + next_page = 1; + break; + } + if (++lines == terminal_height) + next_page = 1; + } + putc(c, stdout); } - if ( ++lines == terminal_height ) - next_page = 1; - } - putc(c, stdout); - } - fclose(file); - fflush(stdout); + fclose(file); + fflush(stdout); - argv++; - } while (--argc > 0); -end: + argv++; + } while (--argc > 0); + end: #ifdef BB_FEATURE_USE_TERMIOS - gotsig(0); -#endif - exit(TRUE); + gotsig(0); +#endif + exit(TRUE); } - 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 @@ +/* vi: set sw=4 ts=4: */ /* * Mini mount implementation for busybox * @@ -55,357 +56,371 @@ static int use_loop = 0; #endif -extern const char mtab_file[]; /* Defined in utility.c */ +extern const char mtab_file[]; /* Defined in utility.c */ static const char mount_usage[] = "\tmount [flags]\n" - "\tmount [flags] device directory [-o options,more-options]\n" - "\n" - "Flags:\n" - "\t-a:\tMount all file systems in fstab.\n" + "\tmount [flags] device directory [-o options,more-options]\n" + "\n" "Flags:\n" "\t-a:\tMount all file systems in fstab.\n" #ifdef BB_MTAB - "\t-f:\t\"Fake\" mount. Add entry to mount table but don't mount it.\n" - "\t-n:\tDon't write a mount table entry.\n" + "\t-f:\t\"Fake\" mount. Add entry to mount table but don't mount it.\n" + "\t-n:\tDon't write a mount table entry.\n" #endif - "\t-o option:\tOne of many filesystem options, listed below.\n" - "\t-r:\tMount the filesystem read-only.\n" - "\t-t filesystem-type:\tSpecify the filesystem type.\n" - "\t-w:\tMount for reading and writing (default).\n" - "\n" - "Options for use with the \"-o\" flag:\n" - "\tasync / sync:\tWrites are asynchronous / synchronous.\n" - "\tdev / nodev:\tAllow use of special device files / disallow them.\n" - "\texec / noexec:\tAllow use of executable files / disallow them.\n" + "\t-o option:\tOne of many filesystem options, listed below.\n" + "\t-r:\tMount the filesystem read-only.\n" + "\t-t filesystem-type:\tSpecify the filesystem type.\n" + "\t-w:\tMount for reading and writing (default).\n" + "\n" + "Options for use with the \"-o\" flag:\n" + "\tasync / sync:\tWrites are asynchronous / synchronous.\n" + "\tdev / nodev:\tAllow use of special device files / disallow them.\n" + "\texec / noexec:\tAllow use of executable files / disallow them.\n" #if defined BB_FEATURE_MOUNT_LOOP - "\tloop: Mounts a file via loop device.\n" + "\tloop: Mounts a file via loop device.\n" #endif - "\tsuid / nosuid:\tAllow set-user-id-root programs / disallow them.\n" - "\tremount: Re-mount a currently-mounted filesystem, changing its flags.\n" - "\tro / rw: Mount for read-only / read-write.\n" - "\t" - "There are EVEN MORE flags that are specific to each filesystem.\n" - "You'll have to see the written documentation for those.\n"; + "\tsuid / nosuid:\tAllow set-user-id-root programs / disallow them.\n" + "\tremount: Re-mount a currently-mounted filesystem, changing its flags.\n" + "\tro / rw: Mount for read-only / read-write.\n" + "\t" + + "There are EVEN MORE flags that are specific to each filesystem.\n" + "You'll have to see the written documentation for those.\n"; struct mount_options { - const char *name; - unsigned long and; - unsigned long or; + const char *name; + unsigned long and; + unsigned long or; }; static const struct mount_options mount_options[] = { - {"async", ~MS_SYNCHRONOUS, 0}, - {"defaults", ~0, 0}, - {"dev", ~MS_NODEV, 0}, - {"exec", ~MS_NOEXEC, 0}, - {"nodev", ~0, MS_NODEV}, - {"noexec", ~0, MS_NOEXEC}, - {"nosuid", ~0, MS_NOSUID}, - {"remount", ~0, MS_REMOUNT}, - {"ro", ~0, MS_RDONLY}, - {"rw", ~MS_RDONLY, 0}, - {"suid", ~MS_NOSUID, 0}, - {"sync", ~0, MS_SYNCHRONOUS}, - {0, 0, 0} + {"async", ~MS_SYNCHRONOUS, 0}, + {"defaults", ~0, 0}, + {"dev", ~MS_NODEV, 0}, + {"exec", ~MS_NOEXEC, 0}, + {"nodev", ~0, MS_NODEV}, + {"noexec", ~0, MS_NOEXEC}, + {"nosuid", ~0, MS_NOSUID}, + {"remount", ~0, MS_REMOUNT}, + {"ro", ~0, MS_RDONLY}, + {"rw", ~MS_RDONLY, 0}, + {"suid", ~MS_NOSUID, 0}, + {"sync", ~0, MS_SYNCHRONOUS}, + {0, 0, 0} }; static int -do_mount(char* specialfile, char* dir, char* filesystemtype, - long flags, void* string_flags, int useMtab, int fakeIt, char* mtab_opts) +do_mount(char *specialfile, char *dir, char *filesystemtype, + long flags, void *string_flags, int useMtab, int fakeIt, + char *mtab_opts) { - int status=0; + int status = 0; #if defined BB_MTAB - if (fakeIt==FALSE) + if (fakeIt == FALSE) #endif - { + { #if defined BB_FEATURE_MOUNT_LOOP - if (use_loop) { - int loro = flags & MS_RDONLY; - char *lofile = specialfile; - specialfile = find_unused_loop_device(); - if (specialfile == NULL) { - fprintf(stderr, "Could not find a spare loop device\n"); - return( FALSE); - } - if (set_loop (specialfile, lofile, 0, &loro)) { - fprintf(stderr, "Could not setup loop device\n"); - return( FALSE); - } - if (!(flags & MS_RDONLY) && loro) { /* loop is ro, but wanted rw */ - fprintf(stderr, "WARNING: loop device is read-only\n"); - flags &= ~MS_RDONLY; - } - } + if (use_loop) { + int loro = flags & MS_RDONLY; + char *lofile = specialfile; + + specialfile = find_unused_loop_device(); + if (specialfile == NULL) { + fprintf(stderr, "Could not find a spare loop device\n"); + return (FALSE); + } + if (set_loop(specialfile, lofile, 0, &loro)) { + fprintf(stderr, "Could not setup loop device\n"); + return (FALSE); + } + if (!(flags & MS_RDONLY) && loro) { /* loop is ro, but wanted rw */ + fprintf(stderr, "WARNING: loop device is read-only\n"); + flags &= ~MS_RDONLY; + } + } #endif - status=mount(specialfile, dir, filesystemtype, flags, string_flags); - } + status = + mount(specialfile, dir, filesystemtype, flags, string_flags); + } - /* If the mount was sucessful, do anything needed, then return TRUE */ - if (status == 0) { + /* If the mount was sucessful, do anything needed, then return TRUE */ + if (status == 0) { #if defined BB_MTAB - if (useMtab==TRUE) { - write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts); - } + if (useMtab == TRUE) { + write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts); + } #endif - return( TRUE); - } + return (TRUE); + } - /* Bummer. mount failed. Clean up */ + /* Bummer. mount failed. Clean up */ #if defined BB_FEATURE_MOUNT_LOOP - if (specialfile != NULL) { - del_loop(specialfile); - } + if (specialfile != NULL) { + del_loop(specialfile); + } #endif - return( FALSE); + return (FALSE); } #if defined BB_MTAB -#define whine_if_fstab_is_missing() {} +#define whine_if_fstab_is_missing() {} #else extern void whine_if_fstab_is_missing() { - struct stat statBuf; - if (stat("/etc/fstab", &statBuf) < 0) - fprintf(stderr, "/etc/fstab file missing -- install one to name /dev/root.\n\n"); + struct stat statBuf; + + if (stat("/etc/fstab", &statBuf) < 0) + fprintf(stderr, + "/etc/fstab file missing -- install one to name /dev/root.\n\n"); } #endif /* Seperate standard mount options from the nonstandard string options */ static void -parse_mount_options ( char *options, unsigned long *flags, char *strflags) +parse_mount_options(char *options, unsigned long *flags, char *strflags) { - while (options) { - int gotone=FALSE; - char *comma = strchr (options, ','); - const struct mount_options* f = mount_options; - if (comma) - *comma = '\0'; - - while (f->name != 0) { - if (strcasecmp (f->name, options) == 0) { - - *flags &= f->and; - *flags |= f->or; - gotone=TRUE; - break; - } - f++; - } + while (options) { + int gotone = FALSE; + char *comma = strchr(options, ','); + const struct mount_options *f = mount_options; + + if (comma) + *comma = '\0'; + + while (f->name != 0) { + if (strcasecmp(f->name, options) == 0) { + + *flags &= f->and; + *flags |= f->or; + gotone = TRUE; + break; + } + f++; + } #if defined BB_FEATURE_MOUNT_LOOP - if (gotone==FALSE && !strcasecmp ("loop", options)) { /* loop device support */ - use_loop = 1; - gotone=TRUE; - } + if (gotone == FALSE && !strcasecmp("loop", options)) { /* loop device support */ + use_loop = 1; + gotone = TRUE; + } #endif - if (*strflags && strflags!= '\0' && gotone==FALSE) { - char *temp=strflags; - temp += strlen (strflags); - *temp++ = ','; - *temp++ = '\0'; - } - if (gotone==FALSE) - strcat (strflags, options); - if (comma) { - *comma = ','; - options = ++comma; - } else { - break; + if (*strflags && strflags != '\0' && gotone == FALSE) { + char *temp = strflags; + + temp += strlen(strflags); + *temp++ = ','; + *temp++ = '\0'; + } + if (gotone == FALSE) + strcat(strflags, options); + if (comma) { + *comma = ','; + options = ++comma; + } else { + break; + } } - } } int mount_one(char *blockDevice, char *directory, char *filesystemType, - unsigned long flags, char *string_flags, int useMtab, int fakeIt, char *mtab_opts) + unsigned long flags, char *string_flags, int useMtab, int fakeIt, + char *mtab_opts) { - int status = 0; + int status = 0; - char buf[255]; + char buf[255]; #if defined BB_FEATURE_USE_PROCFS - if (strcmp(filesystemType, "auto") == 0) { - FILE *f = fopen ("/proc/filesystems", "r"); - - if (f == NULL) - return( FALSE); - - while (fgets (buf, sizeof (buf), f) != NULL) { - filesystemType = buf; - if (*filesystemType == '\t') { // Not a nodev filesystem - - // Add NULL termination to each line - while (*filesystemType && *filesystemType != '\n') - filesystemType++; - *filesystemType = '\0'; - - filesystemType = buf; - filesystemType++; // hop past tab - - status = do_mount (blockDevice, directory, filesystemType, - flags | MS_MGC_VAL, string_flags, useMtab, - fakeIt, mtab_opts); - if (status == TRUE) - break; - } - } - fclose (f); - } else + if (strcmp(filesystemType, "auto") == 0) { + FILE *f = fopen("/proc/filesystems", "r"); + + if (f == NULL) + return (FALSE); + + while (fgets(buf, sizeof(buf), f) != NULL) { + filesystemType = buf; + if (*filesystemType == '\t') { // Not a nodev filesystem + + // Add NULL termination to each line + while (*filesystemType && *filesystemType != '\n') + filesystemType++; + *filesystemType = '\0'; + + filesystemType = buf; + filesystemType++; // hop past tab + + status = do_mount(blockDevice, directory, filesystemType, + flags | MS_MGC_VAL, string_flags, + useMtab, fakeIt, mtab_opts); + if (status == TRUE) + break; + } + } + fclose(f); + } else #endif - { - status = do_mount (blockDevice, directory, filesystemType, - flags | MS_MGC_VAL, string_flags, useMtab, - fakeIt, mtab_opts); - } - - if (status==FALSE) { - fprintf (stderr, "Mounting %s on %s failed: %s\n", - blockDevice, directory, strerror(errno)); - return (FALSE); - } - return (TRUE); + { + status = do_mount(blockDevice, directory, filesystemType, + flags | MS_MGC_VAL, string_flags, useMtab, + fakeIt, mtab_opts); + } + + if (status == FALSE) { + fprintf(stderr, "Mounting %s on %s failed: %s\n", + blockDevice, directory, strerror(errno)); + return (FALSE); + } + return (TRUE); } -extern int mount_main (int argc, char **argv) +extern int mount_main(int argc, char **argv) { - char string_flags_buf[1024]=""; - char *string_flags = string_flags_buf; - char *extra_opts = string_flags_buf; - unsigned long flags = 0; - char *filesystemType = "auto"; - char *device = NULL; - char *directory = NULL; - int all = FALSE; - int fakeIt = FALSE; - int useMtab = TRUE; - int i; - - /* Only compiled in if BB_MTAB is not defined */ - whine_if_fstab_is_missing(); - - if (argc == 1) { - FILE *mountTable = setmntent (mtab_file, "r"); - if (mountTable) { - struct mntent *m; - while ((m = getmntent (mountTable)) != 0) { - struct fstab* fstabItem; - char *blockDevice = m->mnt_fsname; - /* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */ - if (strcmp (blockDevice, "/dev/root") == 0) { - fstabItem = getfsfile ("/"); - if (fstabItem != NULL) - blockDevice = fstabItem->fs_spec; + char string_flags_buf[1024] = ""; + char *string_flags = string_flags_buf; + char *extra_opts = string_flags_buf; + unsigned long flags = 0; + char *filesystemType = "auto"; + char *device = NULL; + char *directory = NULL; + int all = FALSE; + int fakeIt = FALSE; + int useMtab = TRUE; + int i; + + /* Only compiled in if BB_MTAB is not defined */ + whine_if_fstab_is_missing(); + + if (argc == 1) { + FILE *mountTable = setmntent(mtab_file, "r"); + + if (mountTable) { + struct mntent *m; + + while ((m = getmntent(mountTable)) != 0) { + struct fstab *fstabItem; + char *blockDevice = m->mnt_fsname; + + /* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */ + if (strcmp(blockDevice, "/dev/root") == 0) { + fstabItem = getfsfile("/"); + if (fstabItem != NULL) + blockDevice = fstabItem->fs_spec; + } + printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir, + m->mnt_type, m->mnt_opts); + } + endmntent(mountTable); + } else { + perror(mtab_file); } - printf ("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir, - m->mnt_type, m->mnt_opts); - } - endmntent (mountTable); - } else { - perror(mtab_file); + exit(TRUE); } - exit( TRUE); - } - - - /* Parse options */ - i = --argc; - argv++; - while (i > 0 && **argv) { - if (**argv == '-') { - char *opt = *argv; - while (i>0 && *++opt) switch (*opt) { - case 'o': - if (--i == 0) { - goto goodbye; - } - parse_mount_options (*(++argv), &flags, string_flags); - break; - case 'r': - flags |= MS_RDONLY; - break; - case 't': - if (--i == 0) { - goto goodbye; - } - filesystemType = *(++argv); - break; - case 'w': - flags &= ~MS_RDONLY; - break; - case 'a': - all = TRUE; - break; + + + /* Parse options */ + i = --argc; + argv++; + while (i > 0 && **argv) { + if (**argv == '-') { + char *opt = *argv; + + while (i > 0 && *++opt) + switch (*opt) { + case 'o': + if (--i == 0) { + goto goodbye; + } + parse_mount_options(*(++argv), &flags, string_flags); + break; + case 'r': + flags |= MS_RDONLY; + break; + case 't': + if (--i == 0) { + goto goodbye; + } + filesystemType = *(++argv); + break; + case 'w': + flags &= ~MS_RDONLY; + break; + case 'a': + all = TRUE; + break; #ifdef BB_MTAB - case 'f': - fakeIt = TRUE; - break; - case 'n': - useMtab = FALSE; - break; + case 'f': + fakeIt = TRUE; + break; + case 'n': + useMtab = FALSE; + break; #endif - case 'v': - case 'h': - case '-': - goto goodbye; - } - } else { - if (device == NULL) - device = *argv; - else if (directory == NULL) - directory = *argv; - else { - goto goodbye; - } + case 'v': + case 'h': + case '-': + goto goodbye; + } + } else { + if (device == NULL) + device = *argv; + else if (directory == NULL) + directory = *argv; + else { + goto goodbye; + } + } + i--; + argv++; } - i--; - argv++; - } - if (all == TRUE) { - struct mntent *m; - FILE *f = setmntent ("/etc/fstab", "r"); + if (all == TRUE) { + struct mntent *m; + FILE *f = setmntent("/etc/fstab", "r"); - if (f == NULL) { - perror("/etc/fstab"); - exit( FALSE); - } - while ((m = getmntent (f)) != NULL) { - // If the file system isn't noauto, and isn't mounted on /, - // and isn't swap or nfs, then mount it - if ((!strstr (m->mnt_opts, "noauto")) && - (m->mnt_dir[1] != '\0') && - (!strstr (m->mnt_type, "swap")) && - (!strstr (m->mnt_type, "nfs"))) - { - flags = 0; - *string_flags = '\0'; - parse_mount_options(m->mnt_opts, &flags, string_flags); - mount_one (m->mnt_fsname, m->mnt_dir, m->mnt_type, - flags, string_flags, useMtab, fakeIt, extra_opts); - } - } - endmntent (f); - } else { - if (device && directory) { + if (f == NULL) { + perror("/etc/fstab"); + exit(FALSE); + } + while ((m = getmntent(f)) != NULL) { + // If the file system isn't noauto, and isn't mounted on /, + // and isn't swap or nfs, then mount it + if ((!strstr(m->mnt_opts, "noauto")) && + (m->mnt_dir[1] != '\0') && + (!strstr(m->mnt_type, "swap")) && + (!strstr(m->mnt_type, "nfs"))) { + flags = 0; + *string_flags = '\0'; + parse_mount_options(m->mnt_opts, &flags, string_flags); + mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type, + flags, string_flags, useMtab, fakeIt, + extra_opts); + } + } + endmntent(f); + } else { + if (device && directory) { #ifdef BB_NFSMOUNT - if (strcmp(filesystemType, "nfs") == 0) { - if (nfsmount(device, directory, &flags, &extra_opts, &string_flags, 1) != 0) - exit(FALSE); - } + if (strcmp(filesystemType, "nfs") == 0) { + if (nfsmount + (device, directory, &flags, &extra_opts, &string_flags, + 1) != 0) + exit(FALSE); + } #endif - exit (mount_one (device, directory, filesystemType, - flags, string_flags, useMtab, fakeIt, extra_opts)); - } else { - goto goodbye; + exit(mount_one(device, directory, filesystemType, + flags, string_flags, useMtab, fakeIt, + extra_opts)); + } else { + goto goodbye; + } } - } - exit( TRUE); + exit(TRUE); -goodbye: - usage( mount_usage); + goodbye: + usage(mount_usage); } - 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 @@ +/* vi: set sw=4 ts=4: */ /* * nfsmount.c -- Linux NFS mount * Copyright (C) 1993 Rick Sladkey <jrs@world.std.com> @@ -53,7 +54,7 @@ #define _ #define HAVE_inet_aton -#define MS_REMOUNT 32 /* Alter flags of a mounted FS */ +#define MS_REMOUNT 32 /* Alter flags of a mounted FS */ #define sloppy 0 #define EX_FAIL 1 #define EX_BG 1 @@ -65,8 +66,8 @@ static char *nfs_strerror(int stat); #define MAKE_VERSION(p,q,r) (65536*(p) + 256*(q) + (r)) -static int -linux_version_code(void) { +static int linux_version_code(void) +{ struct utsname my_utsname; int p, q, r; @@ -74,7 +75,7 @@ linux_version_code(void) { p = atoi(strtok(my_utsname.release, ".")); q = atoi(strtok(NULL, ".")); r = atoi(strtok(NULL, ".")); - return MAKE_VERSION(p,q,r); + return MAKE_VERSION(p, q, r); } return 0; } @@ -95,22 +96,22 @@ static int nfs_mount_version = NFS_MOUNT_VERSION; * NFS_MOUNT_VERSION: these nfsmount sources at compile time * nfs_mount_version: version this source and running kernel can handle */ -static void -find_kernel_nfs_mount_version(void) { +static void find_kernel_nfs_mount_version(void) +{ int kernel_version = linux_version_code(); if (kernel_version) { - if (kernel_version < MAKE_VERSION(2,1,32)) - nfs_mount_version = 1; - else - nfs_mount_version = 3; + if (kernel_version < MAKE_VERSION(2, 1, 32)) + nfs_mount_version = 1; + else + nfs_mount_version = 3; } if (nfs_mount_version > NFS_MOUNT_VERSION) - nfs_mount_version = NFS_MOUNT_VERSION; + nfs_mount_version = NFS_MOUNT_VERSION; } int nfsmount(const char *spec, const char *node, unsigned long *flags, - char **extra_opts, char **mount_opts, int running_bg) + char **extra_opts, char **mount_opts, int running_bg) { static char *prev_bg_host; char hostdir[1024]; @@ -118,7 +119,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, char *hostname; char *dirname; char *old_opts; - char *mounthost=NULL; + char *mounthost = NULL; char new_opts[1024]; fhandle root_fhandle; struct timeval total_timeout; @@ -161,7 +162,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, mclient = NULL; if (strlen(spec) >= sizeof(hostdir)) { fprintf(stderr, _("mount: " - "excessively long host:dir argument\n")); + "excessively long host:dir argument\n")); goto fail; } strcpy(hostdir, spec); @@ -174,11 +175,11 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, if ((s = strchr(hostdir, ','))) { *s = '\0'; fprintf(stderr, _("mount: warning: " - "multiple hostnames not supported\n")); + "multiple hostnames not supported\n")); } } else { fprintf(stderr, _("mount: " - "directory to mount not in host:dir format\n")); + "directory to mount not in host:dir format\n")); goto fail; } @@ -189,20 +190,18 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, { if ((hp = gethostbyname(hostname)) == NULL) { fprintf(stderr, _("mount: can't get address for %s\n"), - hostname); + hostname); goto fail; } else { if (hp->h_length > sizeof(struct in_addr)) { - fprintf(stderr, - _("mount: got bad hp->h_length\n")); + fprintf(stderr, _("mount: got bad hp->h_length\n")); hp->h_length = sizeof(struct in_addr); } - memcpy(&server_addr.sin_addr, - hp->h_addr, hp->h_length); + memcpy(&server_addr.sin_addr, hp->h_addr, hp->h_length); } } - memcpy (&mount_server_addr, &server_addr, sizeof (mount_server_addr)); + memcpy(&mount_server_addr, &server_addr, sizeof(mount_server_addr)); /* add IP address to mtab options for use when unmounting */ @@ -211,12 +210,10 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, if (!old_opts) old_opts = ""; if (strlen(old_opts) + strlen(s) + 10 >= sizeof(new_opts)) { - fprintf(stderr, _("mount: " - "excessively long option argument\n")); + fprintf(stderr, _("mount: " "excessively long option argument\n")); goto fail; } - sprintf(new_opts, "%s%saddr=%s", - old_opts, *old_opts ? "," : "", s); + sprintf(new_opts, "%s%saddr=%s", old_opts, *old_opts ? "," : "", s); *extra_opts = xstrdup(new_opts); /* Set default options. @@ -224,13 +221,13 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, * let the kernel decide. * timeo is filled in after we know whether it'll be TCP or UDP. */ memset(&data, 0, sizeof(data)); - data.retrans = 3; - data.acregmin = 3; - data.acregmax = 60; - data.acdirmin = 30; - data.acdirmax = 60; + data.retrans = 3; + data.acregmin = 3; + data.acregmax = 60; + data.acdirmin = 30; + data.acdirmax = 60; #if NFS_MOUNT_VERSION >= 2 - data.namlen = NAME_MAX; + data.namlen = NAME_MAX; #endif bg = 0; @@ -240,7 +237,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, nocto = 0; nolock = 0; noac = 0; - retry = 10000; /* 10000 minutes ~ 1 week */ + retry = 10000; /* 10000 minutes ~ 1 week */ tcp = 0; mountprog = MOUNTPROG; @@ -254,7 +251,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, for (opt = strtok(old_opts, ","); opt; opt = strtok(NULL, ",")) { if ((opteq = strchr(opt, '='))) { - val = atoi(opteq + 1); + val = atoi(opteq + 1); *opteq = '\0'; if (!strcmp(opt, "rsize")) data.rsize = val; @@ -277,29 +274,27 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, data.acregmax = val; data.acdirmin = val; data.acdirmax = val; - } - else if (!strcmp(opt, "retry")) + } else if (!strcmp(opt, "retry")) retry = val; else if (!strcmp(opt, "port")) port = val; else if (!strcmp(opt, "mountport")) - mountport = val; + mountport = val; else if (!strcmp(opt, "mounthost")) - mounthost=xstrndup(opteq+1, - strcspn(opteq+1," \t\n\r,")); + mounthost = xstrndup(opteq + 1, + strcspn(opteq + 1, " \t\n\r,")); else if (!strcmp(opt, "mountprog")) mountprog = val; else if (!strcmp(opt, "mountvers")) mountvers = val; else if (!strcmp(opt, "nfsprog")) nfsprog = val; - else if (!strcmp(opt, "nfsvers") || - !strcmp(opt, "vers")) + else if (!strcmp(opt, "nfsvers") || !strcmp(opt, "vers")) nfsvers = val; else if (!strcmp(opt, "proto")) { - if (!strncmp(opteq+1, "tcp", 3)) + if (!strncmp(opteq + 1, "tcp", 3)) tcp = 1; - else if (!strncmp(opteq+1, "udp", 3)) + else if (!strncmp(opteq + 1, "udp", 3)) tcp = 0; else printf(_("Warning: Unrecognized proto= option.\n")); @@ -309,24 +304,24 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, data.namlen = val; else #endif - printf(_("Warning: Option namlen is not supported.\n")); + printf(_ + ("Warning: Option namlen is not supported.\n")); } else if (!strcmp(opt, "addr")) - /* ignore */; + /* ignore */ ; else { printf(_("unknown nfs mount parameter: " - "%s=%d\n"), opt, val); + "%s=%d\n"), opt, val); goto fail; } - } - else { + } else { val = 1; if (!strncmp(opt, "no", 2)) { val = 0; opt += 2; } - if (!strcmp(opt, "bg")) + if (!strcmp(opt, "bg")) bg = val; - else if (!strcmp(opt, "fg")) + else if (!strcmp(opt, "fg")) bg = !val; else if (!strcmp(opt, "soft")) soft = val; @@ -348,11 +343,12 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, if (nfs_mount_version >= 3) nolock = !val; else - printf(_("Warning: option nolock is not supported.\n")); + printf(_ + ("Warning: option nolock is not supported.\n")); } else { if (!sloppy) { printf(_("unknown nfs mount option: " - "%s%s\n"), val ? "" : "no", opt); + "%s%s\n"), val ? "" : "no", opt); goto fail; } } @@ -378,22 +374,21 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, #ifdef NFS_MOUNT_DEBUG printf("rsize = %d, wsize = %d, timeo = %d, retrans = %d\n", - data.rsize, data.wsize, data.timeo, data.retrans); + data.rsize, data.wsize, data.timeo, data.retrans); printf("acreg (min, max) = (%d, %d), acdir (min, max) = (%d, %d)\n", - data.acregmin, data.acregmax, data.acdirmin, data.acdirmax); + data.acregmin, data.acregmax, data.acdirmin, data.acdirmax); printf("port = %d, bg = %d, retry = %d, flags = %.8x\n", - port, bg, retry, data.flags); + port, bg, retry, data.flags); printf("mountprog = %d, mountvers = %d, nfsprog = %d, nfsvers = %d\n", - mountprog, mountvers, nfsprog, nfsvers); + mountprog, mountvers, nfsprog, nfsvers); printf("soft = %d, intr = %d, posix = %d, nocto = %d, noac = %d\n", - (data.flags & NFS_MOUNT_SOFT) != 0, - (data.flags & NFS_MOUNT_INTR) != 0, - (data.flags & NFS_MOUNT_POSIX) != 0, - (data.flags & NFS_MOUNT_NOCTO) != 0, - (data.flags & NFS_MOUNT_NOAC) != 0); + (data.flags & NFS_MOUNT_SOFT) != 0, + (data.flags & NFS_MOUNT_INTR) != 0, + (data.flags & NFS_MOUNT_POSIX) != 0, + (data.flags & NFS_MOUNT_NOCTO) != 0, + (data.flags & NFS_MOUNT_NOAC) != 0); #if NFS_MOUNT_VERSION >= 2 - printf("tcp = %d\n", - (data.flags & NFS_MOUNT_TCP) != 0); + printf("tcp = %d\n", (data.flags & NFS_MOUNT_TCP) != 0); #endif #endif @@ -409,7 +404,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, * give up immediately, to avoid the initial timeout. */ if (bg && !running_bg && - prev_bg_host && strcmp(hostname, prev_bg_host) == 0) { + prev_bg_host && strcmp(hostname, prev_bg_host) == 0) { if (retry > 0) retval = EX_BG; return retval; @@ -418,25 +413,24 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, /* create mount deamon client */ /* See if the nfs host = mount host. */ if (mounthost) { - if (mounthost[0] >= '0' && mounthost[0] <= '9') { - mount_server_addr.sin_family = AF_INET; - mount_server_addr.sin_addr.s_addr = inet_addr(hostname); - } else { - if ((hp = gethostbyname(mounthost)) == NULL) { - fprintf(stderr, _("mount: can't get address for %s\n"), - hostname); - goto fail; - } else { - if (hp->h_length > sizeof(struct in_addr)) { - fprintf(stderr, - _("mount: got bad hp->h_length?\n")); - hp->h_length = sizeof(struct in_addr); - } - mount_server_addr.sin_family = AF_INET; - memcpy(&mount_server_addr.sin_addr, - hp->h_addr, hp->h_length); - } - } + if (mounthost[0] >= '0' && mounthost[0] <= '9') { + mount_server_addr.sin_family = AF_INET; + mount_server_addr.sin_addr.s_addr = inet_addr(hostname); + } else { + if ((hp = gethostbyname(mounthost)) == NULL) { + fprintf(stderr, _("mount: can't get address for %s\n"), + hostname); + goto fail; + } else { + if (hp->h_length > sizeof(struct in_addr)) { + fprintf(stderr, _("mount: got bad hp->h_length?\n")); + hp->h_length = sizeof(struct in_addr); + } + mount_server_addr.sin_family = AF_INET; + memcpy(&mount_server_addr.sin_addr, + hp->h_addr, hp->h_length); + } + } } /* @@ -466,7 +460,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, for (;;) { if (bg && stat(node, &statbuf) == -1) { if (running_bg) { - sleep(val); /* 1, 2, 4, 8, 16, 30, ... */ + sleep(val); /* 1, 2, 4, 8, 16, 30, ... */ val *= 2; if (val > 30) val = 30; @@ -480,24 +474,24 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, mount_server_addr.sin_port = htons(mountport); msock = RPC_ANYSOCK; mclient = clnttcp_create(&mount_server_addr, - mountprog, mountvers, - &msock, 0, 0); + mountprog, mountvers, &msock, 0, 0); /* if this fails, contact the mount daemon via UDP */ if (!mclient) { mount_server_addr.sin_port = htons(mountport); msock = RPC_ANYSOCK; mclient = clntudp_create(&mount_server_addr, - mountprog, mountvers, - retry_timeout, &msock); + mountprog, mountvers, + retry_timeout, &msock); } if (mclient) { /* try to mount hostname:dirname */ mclient->cl_auth = authunix_create_default(); clnt_stat = clnt_call(mclient, MOUNTPROC_MNT, - (xdrproc_t) xdr_dirpath, (caddr_t) &dirname, - (xdrproc_t) xdr_fhstatus, (caddr_t) &status, - total_timeout); + (xdrproc_t) xdr_dirpath, + (caddr_t) & dirname, + (xdrproc_t) xdr_fhstatus, + (caddr_t) & status, total_timeout); if (clnt_stat == RPC_SUCCESS) break; /* we're done */ if (errno != ECONNREFUSED) { @@ -517,7 +511,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, prevt = t; } if (!bg) - goto fail; + goto fail; if (!running_bg) { prev_bg_host = xstrdup(hostname); if (retry > 0) @@ -531,18 +525,18 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, if (status.fhs_status != 0) { fprintf(stderr, - _("mount: %s:%s failed, reason given by server: %s\n"), - hostname, dirname, nfs_strerror(status.fhs_status)); + _("mount: %s:%s failed, reason given by server: %s\n"), + hostname, dirname, nfs_strerror(status.fhs_status)); goto fail; } memcpy((char *) &root_fhandle, (char *) status.fhstatus_u.fhs_fhandle, - sizeof (root_fhandle)); + sizeof(root_fhandle)); /* create nfs socket for kernel */ if (tcp) { if (nfs_mount_version < 3) { - printf(_("NFS over TCP is not supported.\n")); + printf(_("NFS over TCP is not supported.\n")); goto fail; } fsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); @@ -559,7 +553,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, if (port == 0) { server_addr.sin_port = PMAPPORT; port = pmap_getport(&server_addr, nfsprog, nfsvers, - tcp ? IPPROTO_TCP : IPPROTO_UDP); + tcp ? IPPROTO_TCP : IPPROTO_UDP); if (port == 0) port = NFS_PORT; #ifdef NFS_MOUNT_DEBUG @@ -571,14 +565,14 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, printf(_("using port %d for nfs deamon\n"), port); #endif server_addr.sin_port = htons(port); - /* - * connect() the socket for kernels 1.3.10 and below only, - * to avoid problems with multihomed hosts. - * --Swen - */ + /* + * connect() the socket for kernels 1.3.10 and below only, + * to avoid problems with multihomed hosts. + * --Swen + */ if (linux_version_code() <= 66314 - && connect(fsock, (struct sockaddr *) &server_addr, - sizeof (server_addr)) < 0) { + && connect(fsock, (struct sockaddr *) &server_addr, + sizeof(server_addr)) < 0) { perror(_("nfs connect")); goto fail; } @@ -587,7 +581,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, data.fd = fsock; memcpy((char *) &data.root, (char *) &root_fhandle, - sizeof (root_fhandle)); + sizeof(root_fhandle)); memcpy((char *) &data.addr, (char *) &server_addr, sizeof(data.addr)); strncpy(data.hostname, hostname, sizeof(data.hostname)); @@ -600,7 +594,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags, /* abort */ -fail: + fail: if (msock != -1) { if (mclient) { auth_destroy(mclient->cl_auth); @@ -611,7 +605,7 @@ fail: if (fsock != -1) close(fsock); return retval; -} +} /* * We need to translate between nfs status return values and @@ -630,33 +624,37 @@ static struct { enum nfs_stat stat; int errnum; } nfs_errtbl[] = { - { NFS_OK, 0 }, - { NFSERR_PERM, EPERM }, - { NFSERR_NOENT, ENOENT }, - { NFSERR_IO, EIO }, - { NFSERR_NXIO, ENXIO }, - { NFSERR_ACCES, EACCES }, - { NFSERR_EXIST, EEXIST }, - { NFSERR_NODEV, ENODEV }, - { NFSERR_NOTDIR, ENOTDIR }, - { NFSERR_ISDIR, EISDIR }, + { + NFS_OK, 0}, { + NFSERR_PERM, EPERM}, { + NFSERR_NOENT, ENOENT}, { + NFSERR_IO, EIO}, { + NFSERR_NXIO, ENXIO}, { + NFSERR_ACCES, EACCES}, { + NFSERR_EXIST, EEXIST}, { + NFSERR_NODEV, ENODEV}, { + NFSERR_NOTDIR, ENOTDIR}, { + NFSERR_ISDIR, EISDIR}, #ifdef NFSERR_INVAL - { NFSERR_INVAL, EINVAL }, /* that Sun forgot */ + { + NFSERR_INVAL, EINVAL}, /* that Sun forgot */ #endif - { NFSERR_FBIG, EFBIG }, - { NFSERR_NOSPC, ENOSPC }, - { NFSERR_ROFS, EROFS }, - { NFSERR_NAMETOOLONG, ENAMETOOLONG }, - { NFSERR_NOTEMPTY, ENOTEMPTY }, - { NFSERR_DQUOT, EDQUOT }, - { NFSERR_STALE, ESTALE }, + { + NFSERR_FBIG, EFBIG}, { + NFSERR_NOSPC, ENOSPC}, { + NFSERR_ROFS, EROFS}, { + NFSERR_NAMETOOLONG, ENAMETOOLONG}, { + NFSERR_NOTEMPTY, ENOTEMPTY}, { + NFSERR_DQUOT, EDQUOT}, { + NFSERR_STALE, ESTALE}, #ifdef EWFLUSH - { NFSERR_WFLUSH, EWFLUSH }, + { + NFSERR_WFLUSH, EWFLUSH}, #endif - /* Throw in some NFSv3 values for even more fun (HP returns these) */ - { 71, EREMOTE }, - - { -1, EIO } + /* Throw in some NFSv3 values for even more fun (HP returns these) */ + { + 71, EREMOTE}, { + -1, EIO} }; static char *nfs_strerror(int stat) @@ -673,33 +671,32 @@ static char *nfs_strerror(int stat) } #if 0 -int -my_getport(struct in_addr server, struct timeval *timeo, ...) +int my_getport(struct in_addr server, struct timeval *timeo, ...) { - struct sockaddr_in sin; - struct pmap pmap; - CLIENT *clnt; - int sock = RPC_ANYSOCK, port; - - pmap.pm_prog = prog; - pmap.pm_vers = vers; - pmap.pm_prot = prot; - pmap.pm_port = 0; - sin.sin_family = AF_INET; - sin.sin_addr = server; - sin.sin_port = htons(111); - clnt = clntudp_create(&sin, 100000, 2, *timeo, &sock); - status = clnt_call(clnt, PMAP_GETPORT, - &pmap, (xdrproc_t) xdr_pmap, - &port, (xdrproc_t) xdr_uint); - if (status != SUCCESS) { - /* natter */ - port = 0; - } - - clnt_destroy(clnt); - close(sock); - return port; + struct sockaddr_in sin; + struct pmap pmap; + CLIENT *clnt; + int sock = RPC_ANYSOCK, port; + + pmap.pm_prog = prog; + pmap.pm_vers = vers; + pmap.pm_prot = prot; + pmap.pm_port = 0; + sin.sin_family = AF_INET; + sin.sin_addr = server; + sin.sin_port = htons(111); + clnt = clntudp_create(&sin, 100000, 2, *timeo, &sock); + status = clnt_call(clnt, PMAP_GETPORT, + &pmap, (xdrproc_t) xdr_pmap, + &port, (xdrproc_t) xdr_uint); + if (status != SUCCESS) { + /* natter */ + port = 0; + } + + clnt_destroy(clnt); + close(sock); + return port; } #endif @@ -756,28 +753,26 @@ my_getport(struct in_addr server, struct timeval *timeo, ...) /* from @(#)mount.x 1.3 91/03/11 TIRPC 1.0 */ -bool_t -xdr_fhandle(XDR *xdrs, fhandle objp) +bool_t xdr_fhandle(XDR * xdrs, fhandle objp) { - if (!xdr_opaque(xdrs, objp, FHSIZE)) { - return (FALSE); - } + if (!xdr_opaque(xdrs, objp, FHSIZE)) { + return (FALSE); + } return (TRUE); } -bool_t -xdr_fhstatus(XDR *xdrs, fhstatus *objp) +bool_t xdr_fhstatus(XDR * xdrs, fhstatus * objp) { - if (!xdr_u_int(xdrs, &objp->fhs_status)) { - return (FALSE); - } + if (!xdr_u_int(xdrs, &objp->fhs_status)) { + return (FALSE); + } switch (objp->fhs_status) { case 0: - if (!xdr_fhandle(xdrs, objp->fhstatus_u.fhs_fhandle)) { - return (FALSE); - } + if (!xdr_fhandle(xdrs, objp->fhstatus_u.fhs_fhandle)) { + return (FALSE); + } break; default: break; @@ -785,245 +780,246 @@ xdr_fhstatus(XDR *xdrs, fhstatus *objp) return (TRUE); } -bool_t -xdr_dirpath(XDR *xdrs, dirpath *objp) +bool_t xdr_dirpath(XDR * xdrs, dirpath * objp) { - if (!xdr_string(xdrs, objp, MNTPATHLEN)) { - return (FALSE); - } + if (!xdr_string(xdrs, objp, MNTPATHLEN)) { + return (FALSE); + } return (TRUE); } -bool_t -xdr_name(XDR *xdrs, name *objp) +bool_t xdr_name(XDR * xdrs, name * objp) { - if (!xdr_string(xdrs, objp, MNTNAMLEN)) { - return (FALSE); - } + if (!xdr_string(xdrs, objp, MNTNAMLEN)) { + return (FALSE); + } return (TRUE); } -bool_t -xdr_mountlist(XDR *xdrs, mountlist *objp) +bool_t xdr_mountlist(XDR * xdrs, mountlist * objp) { - if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct mountbody), (xdrproc_t)xdr_mountbody)) { - return (FALSE); - } + if (!xdr_pointer + (xdrs, (char **) objp, sizeof(struct mountbody), + (xdrproc_t) xdr_mountbody)) { + return (FALSE); + } return (TRUE); } -bool_t -xdr_mountbody(XDR *xdrs, mountbody *objp) +bool_t xdr_mountbody(XDR * xdrs, mountbody * objp) { - if (!xdr_name(xdrs, &objp->ml_hostname)) { - return (FALSE); - } - if (!xdr_dirpath(xdrs, &objp->ml_directory)) { - return (FALSE); - } - if (!xdr_mountlist(xdrs, &objp->ml_next)) { - return (FALSE); - } + if (!xdr_name(xdrs, &objp->ml_hostname)) { + return (FALSE); + } + if (!xdr_dirpath(xdrs, &objp->ml_directory)) { + return (FALSE); + } + if (!xdr_mountlist(xdrs, &objp->ml_next)) { + return (FALSE); + } return (TRUE); } -bool_t -xdr_groups(XDR *xdrs, groups *objp) +bool_t xdr_groups(XDR * xdrs, groups * objp) { - if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct groupnode), (xdrproc_t)xdr_groupnode)) { - return (FALSE); - } + if (!xdr_pointer + (xdrs, (char **) objp, sizeof(struct groupnode), + (xdrproc_t) xdr_groupnode)) { + return (FALSE); + } return (TRUE); } -bool_t -xdr_groupnode(XDR *xdrs, groupnode *objp) +bool_t xdr_groupnode(XDR * xdrs, groupnode * objp) { - if (!xdr_name(xdrs, &objp->gr_name)) { - return (FALSE); - } - if (!xdr_groups(xdrs, &objp->gr_next)) { - return (FALSE); - } + if (!xdr_name(xdrs, &objp->gr_name)) { + return (FALSE); + } + if (!xdr_groups(xdrs, &objp->gr_next)) { + return (FALSE); + } return (TRUE); } -bool_t -xdr_exports(XDR *xdrs, exports *objp) +bool_t xdr_exports(XDR * xdrs, exports * objp) { - if (!xdr_pointer(xdrs, (char **)objp, sizeof(struct exportnode), (xdrproc_t)xdr_exportnode)) { - return (FALSE); - } + if (!xdr_pointer + (xdrs, (char **) objp, sizeof(struct exportnode), + (xdrproc_t) xdr_exportnode)) { + return (FALSE); + } return (TRUE); } -bool_t -xdr_exportnode(XDR *xdrs, exportnode *objp) +bool_t xdr_exportnode(XDR * xdrs, exportnode * objp) { - if (!xdr_dirpath(xdrs, &objp->ex_dir)) { - return (FALSE); - } - if (!xdr_groups(xdrs, &objp->ex_groups)) { - return (FALSE); - } - if (!xdr_exports(xdrs, &objp->ex_next)) { - return (FALSE); - } + if (!xdr_dirpath(xdrs, &objp->ex_dir)) { + return (FALSE); + } + if (!xdr_groups(xdrs, &objp->ex_groups)) { + return (FALSE); + } + if (!xdr_exports(xdrs, &objp->ex_next)) { + return (FALSE); + } return (TRUE); } -bool_t -xdr_ppathcnf(XDR *xdrs, ppathcnf *objp) +bool_t xdr_ppathcnf(XDR * xdrs, ppathcnf * objp) { - register long *buf; - - int i; - - if (xdrs->x_op == XDR_ENCODE) { - buf = (long*)XDR_INLINE(xdrs,6 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_int(xdrs, &objp->pc_link_max)) { - return (FALSE); - } - if (!xdr_short(xdrs, &objp->pc_max_canon)) { - return (FALSE); - } - if (!xdr_short(xdrs, &objp->pc_max_input)) { - return (FALSE); - } - if (!xdr_short(xdrs, &objp->pc_name_max)) { - return (FALSE); - } - if (!xdr_short(xdrs, &objp->pc_path_max)) { - return (FALSE); - } - if (!xdr_short(xdrs, &objp->pc_pipe_buf)) { - return (FALSE); - } - - } - else { - IXDR_PUT_LONG(buf,objp->pc_link_max); - IXDR_PUT_SHORT(buf,objp->pc_max_canon); - IXDR_PUT_SHORT(buf,objp->pc_max_input); - IXDR_PUT_SHORT(buf,objp->pc_name_max); - IXDR_PUT_SHORT(buf,objp->pc_path_max); - IXDR_PUT_SHORT(buf,objp->pc_pipe_buf); - } - if (!xdr_u_char(xdrs, &objp->pc_vdisable)) { - return (FALSE); - } - if (!xdr_char(xdrs, &objp->pc_xxx)) { - return (FALSE); - } - buf = (long*)XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT); + register long *buf; + + int i; + + if (xdrs->x_op == XDR_ENCODE) { + buf = (long *) XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT); if (buf == NULL) { - if (!xdr_vector(xdrs, (char *)objp->pc_mask, 2, sizeof(short), (xdrproc_t)xdr_short)) { - return (FALSE); - } - - } - else { - { register short *genp; - for ( i = 0,genp=objp->pc_mask; - i < 2; i++){ - IXDR_PUT_SHORT(buf,*genp++); - } - }; - } - - return (TRUE); + if (!xdr_int(xdrs, &objp->pc_link_max)) { + return (FALSE); + } + if (!xdr_short(xdrs, &objp->pc_max_canon)) { + return (FALSE); + } + if (!xdr_short(xdrs, &objp->pc_max_input)) { + return (FALSE); + } + if (!xdr_short(xdrs, &objp->pc_name_max)) { + return (FALSE); + } + if (!xdr_short(xdrs, &objp->pc_path_max)) { + return (FALSE); + } + if (!xdr_short(xdrs, &objp->pc_pipe_buf)) { + return (FALSE); + } + + } else { + IXDR_PUT_LONG(buf, objp->pc_link_max); + IXDR_PUT_SHORT(buf, objp->pc_max_canon); + IXDR_PUT_SHORT(buf, objp->pc_max_input); + IXDR_PUT_SHORT(buf, objp->pc_name_max); + IXDR_PUT_SHORT(buf, objp->pc_path_max); + IXDR_PUT_SHORT(buf, objp->pc_pipe_buf); + } + if (!xdr_u_char(xdrs, &objp->pc_vdisable)) { + return (FALSE); + } + if (!xdr_char(xdrs, &objp->pc_xxx)) { + return (FALSE); + } + buf = (long *) XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT); + if (buf == NULL) { + if (!xdr_vector + (xdrs, (char *) objp->pc_mask, 2, sizeof(short), + (xdrproc_t) xdr_short)) { + return (FALSE); + } + + } else { + { + register short *genp; + + for (i = 0, genp = objp->pc_mask; i < 2; i++) { + IXDR_PUT_SHORT(buf, *genp++); + } + }; + } + + return (TRUE); } else if (xdrs->x_op == XDR_DECODE) { - buf = (long*)XDR_INLINE(xdrs,6 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_int(xdrs, &objp->pc_link_max)) { - return (FALSE); - } - if (!xdr_short(xdrs, &objp->pc_max_canon)) { - return (FALSE); - } - if (!xdr_short(xdrs, &objp->pc_max_input)) { - return (FALSE); - } - if (!xdr_short(xdrs, &objp->pc_name_max)) { - return (FALSE); - } - if (!xdr_short(xdrs, &objp->pc_path_max)) { - return (FALSE); - } - if (!xdr_short(xdrs, &objp->pc_pipe_buf)) { - return (FALSE); - } - - } - else { - objp->pc_link_max = IXDR_GET_LONG(buf); - objp->pc_max_canon = IXDR_GET_SHORT(buf); - objp->pc_max_input = IXDR_GET_SHORT(buf); - objp->pc_name_max = IXDR_GET_SHORT(buf); - objp->pc_path_max = IXDR_GET_SHORT(buf); - objp->pc_pipe_buf = IXDR_GET_SHORT(buf); - } - if (!xdr_u_char(xdrs, &objp->pc_vdisable)) { - return (FALSE); - } - if (!xdr_char(xdrs, &objp->pc_xxx)) { - return (FALSE); - } - buf = (long*)XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT); + buf = (long *) XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT); + if (buf == NULL) { + if (!xdr_int(xdrs, &objp->pc_link_max)) { + return (FALSE); + } + if (!xdr_short(xdrs, &objp->pc_max_canon)) { + return (FALSE); + } + if (!xdr_short(xdrs, &objp->pc_max_input)) { + return (FALSE); + } + if (!xdr_short(xdrs, &objp->pc_name_max)) { + return (FALSE); + } + if (!xdr_short(xdrs, &objp->pc_path_max)) { + return (FALSE); + } + if (!xdr_short(xdrs, &objp->pc_pipe_buf)) { + return (FALSE); + } + + } else { + objp->pc_link_max = IXDR_GET_LONG(buf); + objp->pc_max_canon = IXDR_GET_SHORT(buf); + objp->pc_max_input = IXDR_GET_SHORT(buf); + objp->pc_name_max = IXDR_GET_SHORT(buf); + objp->pc_path_max = IXDR_GET_SHORT(buf); + objp->pc_pipe_buf = IXDR_GET_SHORT(buf); + } + if (!xdr_u_char(xdrs, &objp->pc_vdisable)) { + return (FALSE); + } + if (!xdr_char(xdrs, &objp->pc_xxx)) { + return (FALSE); + } + buf = (long *) XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT); if (buf == NULL) { - if (!xdr_vector(xdrs, (char *)objp->pc_mask, 2, sizeof(short), (xdrproc_t)xdr_short)) { - return (FALSE); - } - - } - else { - { register short *genp; - for ( i = 0,genp=objp->pc_mask; - i < 2; i++){ - *genp++ = IXDR_GET_SHORT(buf); - } - }; - } - return(TRUE); + if (!xdr_vector + (xdrs, (char *) objp->pc_mask, 2, sizeof(short), + (xdrproc_t) xdr_short)) { + return (FALSE); + } + + } else { + { + register short *genp; + + for (i = 0, genp = objp->pc_mask; i < 2; i++) { + *genp++ = IXDR_GET_SHORT(buf); + } + }; + } + return (TRUE); } - if (!xdr_int(xdrs, &objp->pc_link_max)) { - return (FALSE); - } - if (!xdr_short(xdrs, &objp->pc_max_canon)) { - return (FALSE); - } - if (!xdr_short(xdrs, &objp->pc_max_input)) { - return (FALSE); - } - if (!xdr_short(xdrs, &objp->pc_name_max)) { - return (FALSE); - } - if (!xdr_short(xdrs, &objp->pc_path_max)) { - return (FALSE); - } - if (!xdr_short(xdrs, &objp->pc_pipe_buf)) { - return (FALSE); - } - if (!xdr_u_char(xdrs, &objp->pc_vdisable)) { - return (FALSE); - } - if (!xdr_char(xdrs, &objp->pc_xxx)) { - return (FALSE); - } - if (!xdr_vector(xdrs, (char *)objp->pc_mask, 2, sizeof(short), (xdrproc_t)xdr_short)) { - return (FALSE); - } + if (!xdr_int(xdrs, &objp->pc_link_max)) { + return (FALSE); + } + if (!xdr_short(xdrs, &objp->pc_max_canon)) { + return (FALSE); + } + if (!xdr_short(xdrs, &objp->pc_max_input)) { + return (FALSE); + } + if (!xdr_short(xdrs, &objp->pc_name_max)) { + return (FALSE); + } + if (!xdr_short(xdrs, &objp->pc_path_max)) { + return (FALSE); + } + if (!xdr_short(xdrs, &objp->pc_pipe_buf)) { + return (FALSE); + } + if (!xdr_u_char(xdrs, &objp->pc_vdisable)) { + return (FALSE); + } + if (!xdr_char(xdrs, &objp->pc_xxx)) { + return (FALSE); + } + if (!xdr_vector + (xdrs, (char *) objp->pc_mask, 2, sizeof(short), + (xdrproc_t) xdr_short)) { + return (FALSE); + } return (TRUE); } @@ -1063,247 +1059,232 @@ xdr_ppathcnf(XDR *xdrs, ppathcnf *objp) /* from @(#)mount.x 1.3 91/03/11 TIRPC 1.0 */ -#include <string.h> /* for memset() */ +#include <string.h> /* for memset() */ /* Default timeout can be changed using clnt_control() */ static struct timeval TIMEOUT = { 25, 0 }; -void * -mountproc_null_1(argp, clnt) - void *argp; - CLIENT *clnt; +void *mountproc_null_1(argp, clnt) +void *argp; +CLIENT *clnt; { static char clnt_res; - memset((char *)&clnt_res, 0, sizeof(clnt_res)); - if (clnt_call(clnt, MOUNTPROC_NULL, (xdrproc_t) xdr_void, argp, (xdrproc_t) xdr_void, &clnt_res, TIMEOUT) != RPC_SUCCESS) { + memset((char *) &clnt_res, 0, sizeof(clnt_res)); + if (clnt_call + (clnt, MOUNTPROC_NULL, (xdrproc_t) xdr_void, argp, + (xdrproc_t) xdr_void, &clnt_res, TIMEOUT) != RPC_SUCCESS) { return (NULL); } - return ((void *)&clnt_res); + return ((void *) &clnt_res); } -fhstatus * -mountproc_mnt_1(argp, clnt) - dirpath *argp; - CLIENT *clnt; +fhstatus *mountproc_mnt_1(argp, clnt) +dirpath *argp; +CLIENT *clnt; { static fhstatus clnt_res; - memset((char *)&clnt_res, 0, sizeof(clnt_res)); + memset((char *) &clnt_res, 0, sizeof(clnt_res)); if (clnt_call(clnt, MOUNTPROC_MNT, (xdrproc_t) xdr_dirpath, - (caddr_t) argp, (xdrproc_t) xdr_fhstatus, - (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { + (caddr_t) argp, (xdrproc_t) xdr_fhstatus, + (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) { return (NULL); } return (&clnt_res); } -mountlist * -mountproc_dump_1(argp, clnt) - void *argp; - CLIENT *clnt; +mountlist *mountproc_dump_1(argp, clnt) +void *argp; +CLIENT *clnt; { static mountlist clnt_res; - memset((char *)&clnt_res, 0, sizeof(clnt_res)); + memset((char *) &clnt_res, 0, sizeof(clnt_res)); if (clnt_call(clnt, MOUNTPROC_DUMP, (xdrproc_t) xdr_void, - (caddr_t) argp, (xdrproc_t) xdr_mountlist, - (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { + (caddr_t) argp, (xdrproc_t) xdr_mountlist, + (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) { return (NULL); } return (&clnt_res); } -void * -mountproc_umnt_1(argp, clnt) - dirpath *argp; - CLIENT *clnt; +void *mountproc_umnt_1(argp, clnt) +dirpath *argp; +CLIENT *clnt; { static char clnt_res; - memset((char *)&clnt_res, 0, sizeof(clnt_res)); + memset((char *) &clnt_res, 0, sizeof(clnt_res)); if (clnt_call(clnt, MOUNTPROC_UMNT, (xdrproc_t) xdr_dirpath, - (caddr_t) argp, (xdrproc_t) xdr_void, - (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { + (caddr_t) argp, (xdrproc_t) xdr_void, + (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) { return (NULL); } - return ((void *)&clnt_res); + return ((void *) &clnt_res); } -void * -mountproc_umntall_1(argp, clnt) - void *argp; - CLIENT *clnt; +void *mountproc_umntall_1(argp, clnt) +void *argp; +CLIENT *clnt; { static char clnt_res; - memset((char *)&clnt_res, 0, sizeof(clnt_res)); + memset((char *) &clnt_res, 0, sizeof(clnt_res)); if (clnt_call(clnt, MOUNTPROC_UMNTALL, (xdrproc_t) xdr_void, - (caddr_t) argp, (xdrproc_t) xdr_void, - (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { + (caddr_t) argp, (xdrproc_t) xdr_void, + (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) { return (NULL); } - return ((void *)&clnt_res); + return ((void *) &clnt_res); } -exports * -mountproc_export_1(argp, clnt) - void *argp; - CLIENT *clnt; +exports *mountproc_export_1(argp, clnt) +void *argp; +CLIENT *clnt; { static exports clnt_res; - memset((char *)&clnt_res, 0, sizeof(clnt_res)); + memset((char *) &clnt_res, 0, sizeof(clnt_res)); if (clnt_call(clnt, MOUNTPROC_EXPORT, (xdrproc_t) xdr_void, - (caddr_t) argp, (xdrproc_t) xdr_exports, - (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { + (caddr_t) argp, (xdrproc_t) xdr_exports, + (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) { return (NULL); } return (&clnt_res); } -exports * -mountproc_exportall_1(argp, clnt) - void *argp; - CLIENT *clnt; +exports *mountproc_exportall_1(argp, clnt) +void *argp; +CLIENT *clnt; { static exports clnt_res; - memset((char *)&clnt_res, 0, sizeof(clnt_res)); + memset((char *) &clnt_res, 0, sizeof(clnt_res)); if (clnt_call(clnt, MOUNTPROC_EXPORTALL, (xdrproc_t) xdr_void, - (caddr_t) argp, (xdrproc_t) xdr_exports, - (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { - return (NULL); + (caddr_t) argp, (xdrproc_t) xdr_exports, + (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) { + return (NULL); } return (&clnt_res); } -void * -mountproc_null_2(argp, clnt) - void *argp; - CLIENT *clnt; +void *mountproc_null_2(argp, clnt) +void *argp; +CLIENT *clnt; { static char clnt_res; - memset((char *)&clnt_res, 0, sizeof(clnt_res)); - if (clnt_call(clnt, MOUNTPROC_NULL, (xdrproc_t) xdr_void, argp, (xdrproc_t) xdr_void, &clnt_res, TIMEOUT) != RPC_SUCCESS) { + memset((char *) &clnt_res, 0, sizeof(clnt_res)); + if (clnt_call + (clnt, MOUNTPROC_NULL, (xdrproc_t) xdr_void, argp, + (xdrproc_t) xdr_void, &clnt_res, TIMEOUT) != RPC_SUCCESS) { return (NULL); } - return ((void *)&clnt_res); + return ((void *) &clnt_res); } -fhstatus * -mountproc_mnt_2(argp, clnt) - dirpath *argp; - CLIENT *clnt; +fhstatus *mountproc_mnt_2(argp, clnt) +dirpath *argp; +CLIENT *clnt; { static fhstatus clnt_res; - memset((char *)&clnt_res, 0, sizeof(clnt_res)); + memset((char *) &clnt_res, 0, sizeof(clnt_res)); if (clnt_call(clnt, MOUNTPROC_MNT, (xdrproc_t) xdr_dirpath, - (caddr_t) argp, (xdrproc_t) xdr_fhstatus, - (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { + (caddr_t) argp, (xdrproc_t) xdr_fhstatus, + (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) { return (NULL); } return (&clnt_res); } -mountlist * -mountproc_dump_2(argp, clnt) - void *argp; - CLIENT *clnt; +mountlist *mountproc_dump_2(argp, clnt) +void *argp; +CLIENT *clnt; { static mountlist clnt_res; - memset((char *)&clnt_res, 0, sizeof(clnt_res)); + memset((char *) &clnt_res, 0, sizeof(clnt_res)); if (clnt_call(clnt, MOUNTPROC_DUMP, (xdrproc_t) xdr_void, argp, - (xdrproc_t) xdr_mountlist, (caddr_t) &clnt_res, - TIMEOUT) != RPC_SUCCESS) { + (xdrproc_t) xdr_mountlist, (caddr_t) & clnt_res, + TIMEOUT) != RPC_SUCCESS) { return (NULL); } return (&clnt_res); } -void * -mountproc_umnt_2(argp, clnt) - dirpath *argp; - CLIENT *clnt; +void *mountproc_umnt_2(argp, clnt) +dirpath *argp; +CLIENT *clnt; { static char clnt_res; - memset((char *)&clnt_res, 0, sizeof(clnt_res)); + memset((char *) &clnt_res, 0, sizeof(clnt_res)); if (clnt_call(clnt, MOUNTPROC_UMNT, (xdrproc_t) xdr_dirpath, - (caddr_t) argp, (xdrproc_t) xdr_void, - (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { + (caddr_t) argp, (xdrproc_t) xdr_void, + (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) { return (NULL); } - return ((void *)&clnt_res); + return ((void *) &clnt_res); } -void * -mountproc_umntall_2(argp, clnt) - void *argp; - CLIENT *clnt; +void *mountproc_umntall_2(argp, clnt) +void *argp; +CLIENT *clnt; { static char clnt_res; - memset((char *)&clnt_res, 0, sizeof(clnt_res)); + memset((char *) &clnt_res, 0, sizeof(clnt_res)); if (clnt_call(clnt, MOUNTPROC_UMNTALL, (xdrproc_t) xdr_void, - (caddr_t) argp, (xdrproc_t) xdr_void, - (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { + (caddr_t) argp, (xdrproc_t) xdr_void, + (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) { return (NULL); } - return ((void *)&clnt_res); + return ((void *) &clnt_res); } -exports * -mountproc_export_2(argp, clnt) - void *argp; - CLIENT *clnt; +exports *mountproc_export_2(argp, clnt) +void *argp; +CLIENT *clnt; { static exports clnt_res; - memset((char *)&clnt_res, 0, sizeof(clnt_res)); + memset((char *) &clnt_res, 0, sizeof(clnt_res)); if (clnt_call(clnt, MOUNTPROC_EXPORT, (xdrproc_t) xdr_void, - argp, (xdrproc_t) xdr_exports, (caddr_t) &clnt_res, - TIMEOUT) != RPC_SUCCESS) { + argp, (xdrproc_t) xdr_exports, (caddr_t) & clnt_res, + TIMEOUT) != RPC_SUCCESS) { return (NULL); } return (&clnt_res); } -exports * -mountproc_exportall_2(argp, clnt) - void *argp; - CLIENT *clnt; +exports *mountproc_exportall_2(argp, clnt) +void *argp; +CLIENT *clnt; { static exports clnt_res; - memset((char *)&clnt_res, 0, sizeof(clnt_res)); + memset((char *) &clnt_res, 0, sizeof(clnt_res)); if (clnt_call(clnt, MOUNTPROC_EXPORTALL, (xdrproc_t) xdr_void, argp, - (xdrproc_t) xdr_exports, (caddr_t) &clnt_res, - TIMEOUT) != RPC_SUCCESS) { + (xdrproc_t) xdr_exports, (caddr_t) & clnt_res, + TIMEOUT) != RPC_SUCCESS) { return (NULL); } return (&clnt_res); } -ppathcnf * -mountproc_pathconf_2(argp, clnt) - dirpath *argp; - CLIENT *clnt; +ppathcnf *mountproc_pathconf_2(argp, clnt) +dirpath *argp; +CLIENT *clnt; { static ppathcnf clnt_res; - memset((char *)&clnt_res, 0, sizeof(clnt_res)); + memset((char *) &clnt_res, 0, sizeof(clnt_res)); if (clnt_call(clnt, MOUNTPROC_PATHCONF, (xdrproc_t) xdr_dirpath, - (caddr_t) argp, (xdrproc_t) xdr_ppathcnf, - (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { + (caddr_t) argp, (xdrproc_t) xdr_ppathcnf, + (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) { return (NULL); } return (&clnt_res); } - - - - 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 @@ +/* vi: set sw=4 ts=4: */ /* * Please do not edit this file. * 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 @@ +/* vi: set sw=4 ts=4: */ /* * Mini swapon/swapoff implementation for busybox * @@ -32,91 +33,93 @@ static int whichApp; -static const char* appName; +static const char *appName; -static const char swapoff_usage[] = -"swapoff device\n" -"\nStop swapping virtual memory pages on the given device.\n"; -static const char swapon_usage[] = -"swapon device\n" -"\nStart swapping virtual memory pages on the given device.\n"; +static const char swapoff_usage[] = + + "swapoff device\n" + "\nStop swapping virtual memory pages on the given device.\n"; +static const char swapon_usage[] = + + "swapon device\n" + "\nStart swapping virtual memory pages on the given device.\n"; #define SWAPON_APP 1 #define SWAPOFF_APP 2 -static void -swap_enable_disable( char *device) +static void swap_enable_disable(char *device) { - int status; - if ( whichApp == SWAPON_APP ) - status = swapon(device, 0); - else - status = swapoff(device); - - if ( status != 0 ) { - perror(appName); - exit( FALSE); - } + int status; + + if (whichApp == SWAPON_APP) + status = swapon(device, 0); + else + status = swapoff(device); + + if (status != 0) { + perror(appName); + exit(FALSE); + } } -static void -do_em_all() +static void do_em_all() { struct mntent *m; - FILE *f = setmntent ("/etc/fstab", "r"); + FILE *f = setmntent("/etc/fstab", "r"); if (f == NULL) { - perror("/etc/fstab"); - exit( FALSE); + perror("/etc/fstab"); + exit(FALSE); } - while ((m = getmntent (f)) != NULL) { - if (!strstr (m->mnt_type, MNTTYPE_SWAP)) { - swap_enable_disable( m->mnt_fsname); - } + while ((m = getmntent(f)) != NULL) { + if (!strstr(m->mnt_type, MNTTYPE_SWAP)) { + swap_enable_disable(m->mnt_fsname); + } } - endmntent (f); - exit( TRUE); + endmntent(f); + exit(TRUE); } -extern int -swap_on_off_main(int argc, char * * argv) +extern int swap_on_off_main(int argc, char **argv) { - struct stat statBuf; - if (stat("/etc/fstab", &statBuf) < 0) - fprintf(stderr, "/etc/fstab file missing -- Please install one.\n\n"); - - if (strcmp(*argv, "swapon")==0) { - appName = *argv; - whichApp = SWAPON_APP; - - } else { - appName = *argv; - whichApp = SWAPOFF_APP; - } - - if (argc < 2) - goto usage_and_exit; - argc--; - argv++; - - /* Parse any options */ - while (**argv == '-') { - while (*++(*argv)) switch (**argv) { - case 'a': - do_em_all(); - break; - default: + struct stat statBuf; + + if (stat("/etc/fstab", &statBuf) < 0) + fprintf(stderr, + "/etc/fstab file missing -- Please install one.\n\n"); + + if (strcmp(*argv, "swapon") == 0) { + appName = *argv; + whichApp = SWAPON_APP; + + } else { + appName = *argv; + whichApp = SWAPOFF_APP; + } + + if (argc < 2) goto usage_and_exit; + argc--; + argv++; + + /* Parse any options */ + while (**argv == '-') { + while (*++(*argv)) + switch (**argv) { + case 'a': + do_em_all(); + break; + default: + goto usage_and_exit; + } } - } - swap_enable_disable(*argv); - exit( TRUE); + swap_enable_disable(*argv); + exit(TRUE); -usage_and_exit: - usage( (whichApp==SWAPON_APP)? swapon_usage : swapoff_usage); - exit( FALSE); + usage_and_exit: + usage((whichApp == SWAPON_APP) ? swapon_usage : swapoff_usage); + exit(FALSE); } - 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 @@ +/* vi: set sw=4 ts=4: */ /* * Mini umount implementation for busybox * @@ -28,24 +29,23 @@ #include <fstab.h> #include <errno.h> -static const char umount_usage[] = -"umount [flags] filesystem|directory\n\n" -"Flags:\n" -"\t-a:\tUnmount all file systems" +static const char umount_usage[] = + "umount [flags] filesystem|directory\n\n" + "Flags:\n" "\t-a:\tUnmount all file systems" #ifdef BB_MTAB -" in /etc/mtab\n\t-n:\tDon't erase /etc/mtab entries\n" + " in /etc/mtab\n\t-n:\tDon't erase /etc/mtab entries\n" #else -"\n" + "\n" #endif #ifdef BB_FEATURE_REMOUNT -"\t-r:\tTry to remount devices as read-only if mount is busy\n" + "\t-r:\tTry to remount devices as read-only if mount is busy\n" #endif ; struct _mtab_entry_t { - char *device; - char *mountpt; - struct _mtab_entry_t *next; + char *device; + char *mountpt; + struct _mtab_entry_t *next; }; static struct _mtab_entry_t *mtab_cache = NULL; @@ -55,113 +55,112 @@ static struct _mtab_entry_t *mtab_cache = NULL; static int useMtab = TRUE; static int umountAll = FALSE; static int doRemount = FALSE; -extern const char mtab_file[]; /* Defined in utility.c */ +extern const char mtab_file[]; /* Defined in utility.c */ #define MIN(x,y) (x > y ? x : y) -static int -do_umount(const char* name, int useMtab) +static int do_umount(const char *name, int useMtab) { - int status; - char *blockDevice = mtab_getinfo(name, MTAB_GETDEVICE); + int status; + char *blockDevice = mtab_getinfo(name, MTAB_GETDEVICE); - if (blockDevice && strcmp(blockDevice, name) == 0) - name = mtab_getinfo(blockDevice, MTAB_GETMOUNTPT); + if (blockDevice && strcmp(blockDevice, name) == 0) + name = mtab_getinfo(blockDevice, MTAB_GETMOUNTPT); - status = umount(name); + status = umount(name); #if defined BB_FEATURE_MOUNT_LOOP - if (blockDevice != NULL && !strncmp("/dev/loop", blockDevice, 9)) - /* this was a loop device, delete it */ - del_loop(blockDevice); + if (blockDevice != NULL && !strncmp("/dev/loop", blockDevice, 9)) + /* this was a loop device, delete it */ + del_loop(blockDevice); #endif #if defined BB_FEATURE_REMOUNT - if ( status != 0 && doRemount == TRUE && errno == EBUSY ) { - status = mount(blockDevice, name, NULL, - MS_MGC_VAL | MS_REMOUNT | MS_RDONLY, NULL); - if (status == 0) { - fprintf(stderr, "umount: %s busy - remounted read-only\n", - blockDevice); - /* TODO: update mtab if BB_MTAB is defined */ - } else { - fprintf(stderr, "umount: Cannot remount %s read-only\n", - blockDevice); + if (status != 0 && doRemount == TRUE && errno == EBUSY) { + status = mount(blockDevice, name, NULL, + MS_MGC_VAL | MS_REMOUNT | MS_RDONLY, NULL); + if (status == 0) { + fprintf(stderr, "umount: %s busy - remounted read-only\n", + blockDevice); + /* TODO: update mtab if BB_MTAB is defined */ + } else { + fprintf(stderr, "umount: Cannot remount %s read-only\n", + blockDevice); + } } - } #endif - if ( status == 0 ) { + if (status == 0) { #if defined BB_MTAB - if ( useMtab==TRUE ) - erase_mtab(name); + if (useMtab == TRUE) + erase_mtab(name); #endif - return( TRUE); - } - return(FALSE); + return (TRUE); + } + return (FALSE); } -static int -umount_all(int useMtab) +static int umount_all(int useMtab) { int status = TRUE; char *mountpt; void *iter; for (mountpt = mtab_first(&iter); mountpt; mountpt = mtab_next(&iter)) { - status=do_umount (mountpt, useMtab); - if (status != 0) { - /* Don't bother retrying the umount on busy devices */ - if (errno == EBUSY) { - perror(mountpt); - continue; - } - status = do_umount (mountpt, useMtab); + status = do_umount(mountpt, useMtab); if (status != 0) { - printf ("Couldn't umount %s on %s: %s\n", - mountpt, mtab_getinfo(mountpt, MTAB_GETDEVICE), strerror(errno)); + /* Don't bother retrying the umount on busy devices */ + if (errno == EBUSY) { + perror(mountpt); + continue; + } + status = do_umount(mountpt, useMtab); + if (status != 0) { + printf("Couldn't umount %s on %s: %s\n", + mountpt, mtab_getinfo(mountpt, MTAB_GETDEVICE), + strerror(errno)); + } } - } - } - return (status); + } + return (status); } -extern int -umount_main(int argc, char** argv) +extern int umount_main(int argc, char **argv) { - if (argc < 2) { - usage( umount_usage); - } - - /* Parse any options */ - while (--argc > 0 && **(++argv) == '-') { - while (*++(*argv)) switch (**argv) { - case 'a': - umountAll = TRUE; - break; + if (argc < 2) { + usage(umount_usage); + } + + /* Parse any options */ + while (--argc > 0 && **(++argv) == '-') { + while (*++(*argv)) + switch (**argv) { + case 'a': + umountAll = TRUE; + break; #ifdef BB_MTAB - case 'n': - useMtab = FALSE; - break; + case 'n': + useMtab = FALSE; + break; #endif #ifdef BB_FEATURE_REMOUNT - case 'r': - doRemount = TRUE; - break; + case 'r': + doRemount = TRUE; + break; #endif - default: - usage( umount_usage); + default: + usage(umount_usage); + } + } + + mtab_read(); + if (umountAll == TRUE) { + exit(umount_all(useMtab)); + } + if (do_umount(*argv, useMtab) == 0) + exit(TRUE); + else { + perror("umount"); + exit(FALSE); } - } - - mtab_read(); - if (umountAll==TRUE) { - exit(umount_all(useMtab)); - } - if ( do_umount(*argv,useMtab) == 0 ) - exit (TRUE); - else { - perror("umount"); - exit(FALSE); - } } @@ -172,79 +171,89 @@ umount_main(int argc, char** argv) */ void mtab_read(void) { - struct _mtab_entry_t *entry = NULL; - struct mntent *e; - FILE *fp; - - if (mtab_cache != NULL) return; - - if ((fp = setmntent(mtab_file, "r")) == NULL) { - fprintf(stderr, "Cannot open %s\n", mtab_file); - return; - } - while ((e = getmntent(fp))) { - entry = malloc(sizeof(struct _mtab_entry_t)); - entry->device = strdup(e->mnt_fsname); - entry->mountpt = strdup(e->mnt_dir); - entry->next = mtab_cache; - mtab_cache = entry; - } - endmntent(fp); + struct _mtab_entry_t *entry = NULL; + struct mntent *e; + FILE *fp; + + if (mtab_cache != NULL) + return; + + if ((fp = setmntent(mtab_file, "r")) == NULL) { + fprintf(stderr, "Cannot open %s\n", mtab_file); + return; + } + while ((e = getmntent(fp))) { + entry = malloc(sizeof(struct _mtab_entry_t)); + + entry->device = strdup(e->mnt_fsname); + entry->mountpt = strdup(e->mnt_dir); + entry->next = mtab_cache; + mtab_cache = entry; + } + endmntent(fp); } char *mtab_getinfo(const char *match, const char which) { - struct _mtab_entry_t *cur = mtab_cache; - while (cur) { - if (strcmp(cur->mountpt, match) == 0 || - strcmp(cur->device, match) == 0) { - if (which == MTAB_GETMOUNTPT) { - return cur->mountpt; - } else { + struct _mtab_entry_t *cur = mtab_cache; + + while (cur) { + if (strcmp(cur->mountpt, match) == 0 || + strcmp(cur->device, match) == 0) { + if (which == MTAB_GETMOUNTPT) { + return cur->mountpt; + } else { #if !defined BB_MTAB - if (strcmp(cur->device, "/dev/root") == 0) { - struct fstab* fstabItem; - fstabItem = getfsfile ("/"); - if (fstabItem != NULL) return fstabItem->fs_spec; - } + if (strcmp(cur->device, "/dev/root") == 0) { + struct fstab *fstabItem; + + fstabItem = getfsfile("/"); + if (fstabItem != NULL) + return fstabItem->fs_spec; + } #endif - return cur->device; - } + return cur->device; + } + } + cur = cur->next; } - cur = cur->next; - } - return NULL; + return NULL; } char *mtab_first(void **iter) { - struct _mtab_entry_t *mtab_iter; - if (!iter) return NULL; - mtab_iter = mtab_cache; - *iter = (void *)mtab_iter; - return mtab_next(iter); + struct _mtab_entry_t *mtab_iter; + + if (!iter) + return NULL; + mtab_iter = mtab_cache; + *iter = (void *) mtab_iter; + return mtab_next(iter); } char *mtab_next(void **iter) { - char *mp; - if (iter == NULL || *iter == NULL) return NULL; - mp = ((struct _mtab_entry_t *)(*iter))->mountpt; - *iter = (void *)((struct _mtab_entry_t *)(*iter))->next; - return mp; + char *mp; + + if (iter == NULL || *iter == NULL) + return NULL; + mp = ((struct _mtab_entry_t *) (*iter))->mountpt; + *iter = (void *) ((struct _mtab_entry_t *) (*iter))->next; + return mp; } void mtab_free(void) { - struct _mtab_entry_t *this, *next; - - this = mtab_cache; - while (this) { - next = this->next; - if (this->device) free(this->device); - if (this->mountpt) free(this->mountpt); - free(this); - this = next; - } -} + struct _mtab_entry_t *this, *next; + this = mtab_cache; + while (this) { + next = this->next; + if (this->device) + free(this->device); + if (this->mountpt) + free(this->mountpt); + free(this); + this = next; + } +} |