Some formatting updates (ran the code through indent)
-Erik
This commit is contained in:
@@ -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:
|
||||
goto end;
|
||||
}
|
||||
/* 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 (cmd == 8) {
|
||||
n = klogctl( cmd, NULL, level );
|
||||
if (n < 0) {
|
||||
goto klogctl_error;
|
||||
}
|
||||
exit( TRUE );
|
||||
}
|
||||
if (argc > 1) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (bufsize < 4096) bufsize = 4096;
|
||||
buf = (char*)malloc(bufsize);
|
||||
n = klogctl( cmd, buf, bufsize );
|
||||
if (n < 0) {
|
||||
goto klogctl_error;
|
||||
}
|
||||
if (cmd == 8) {
|
||||
n = klogctl(cmd, NULL, level);
|
||||
if (n < 0) {
|
||||
goto klogctl_error;
|
||||
}
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
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 );
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
/* 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;
|
||||
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;
|
||||
#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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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,23 @@ 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;
|
||||
else {
|
||||
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);
|
||||
}
|
||||
|
||||
#ifdef HAVE_MINIX2
|
||||
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 ();
|
||||
inode->i_nlinks = 2;
|
||||
inode->i_atime = inode->i_mtime = inode->i_ctime = time (NULL);
|
||||
if (badblocks)
|
||||
inode->i_size = 3 * dirsize;
|
||||
else {
|
||||
@@ -469,7 +454,30 @@ 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);
|
||||
}
|
||||
|
||||
#ifdef HAVE_MINIX2
|
||||
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();
|
||||
inode->i_nlinks = 2;
|
||||
inode->i_atime = inode->i_mtime = inode->i_ctime = time(NULL);
|
||||
if (badblocks)
|
||||
inode->i_size = 3 * dirsize;
|
||||
else {
|
||||
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);
|
||||
}
|
||||
#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;
|
||||
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");
|
||||
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;
|
||||
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");
|
||||
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();
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
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");
|
||||
#ifdef USE_OLD_TERMIO
|
||||
ioctl(fileno(cin),TCGETA,&initial_settings);
|
||||
#else
|
||||
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;
|
||||
#endif
|
||||
|
||||
(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",
|
||||
#ifdef BB_FEATURE_USE_TERMIOS
|
||||
""
|
||||
#else
|
||||
"\n"
|
||||
#endif
|
||||
);
|
||||
|
||||
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);
|
||||
#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 ( ++lines == terminal_height )
|
||||
next_page = 1;
|
||||
}
|
||||
putc(c, stdout);
|
||||
}
|
||||
fclose(file);
|
||||
fflush(stdout);
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
} while (--argc > 0);
|
||||
end:
|
||||
#ifdef BB_FEATURE_USE_TERMIOS
|
||||
gotsig(0);
|
||||
#endif
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
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");
|
||||
#ifdef USE_OLD_TERMIO
|
||||
ioctl(fileno(cin), TCGETA, &initial_settings);
|
||||
#else
|
||||
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;
|
||||
#endif
|
||||
|
||||
(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",
|
||||
#ifdef BB_FEATURE_USE_TERMIOS
|
||||
""
|
||||
#else
|
||||
"\n"
|
||||
#endif
|
||||
);
|
||||
|
||||
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);
|
||||
#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 (++lines == terminal_height)
|
||||
next_page = 1;
|
||||
}
|
||||
putc(c, stdout);
|
||||
}
|
||||
fclose(file);
|
||||
fflush(stdout);
|
||||
|
||||
argv++;
|
||||
} while (--argc > 0);
|
||||
end:
|
||||
#ifdef BB_FEATURE_USE_TERMIOS
|
||||
gotsig(0);
|
||||
#endif
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/* Bummer. mount failed. Clean up */
|
||||
#if defined BB_FEATURE_MOUNT_LOOP
|
||||
if (specialfile != NULL) {
|
||||
del_loop(specialfile);
|
||||
}
|
||||
#endif
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
/* Bummer. mount failed. Clean up */
|
||||
#if defined BB_FEATURE_MOUNT_LOOP
|
||||
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 (options) {
|
||||
int gotone = FALSE;
|
||||
char *comma = strchr(options, ',');
|
||||
const struct mount_options *f = mount_options;
|
||||
|
||||
while (f->name != 0) {
|
||||
if (strcasecmp (f->name, options) == 0) {
|
||||
if (comma)
|
||||
*comma = '\0';
|
||||
|
||||
*flags &= f->and;
|
||||
*flags |= f->or;
|
||||
gotone=TRUE;
|
||||
break;
|
||||
}
|
||||
f++;
|
||||
}
|
||||
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 (*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 (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 (strcmp(filesystemType, "auto") == 0) {
|
||||
FILE *f = fopen("/proc/filesystems", "r");
|
||||
|
||||
if (f == NULL)
|
||||
return( FALSE);
|
||||
if (f == NULL)
|
||||
return (FALSE);
|
||||
|
||||
while (fgets (buf, sizeof (buf), f) != NULL) {
|
||||
filesystemType = buf;
|
||||
if (*filesystemType == '\t') { // Not a nodev filesystem
|
||||
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';
|
||||
// Add NULL termination to each line
|
||||
while (*filesystemType && *filesystemType != '\n')
|
||||
filesystemType++;
|
||||
*filesystemType = '\0';
|
||||
|
||||
filesystemType = buf;
|
||||
filesystemType++; // hop past tab
|
||||
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
|
||||
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);
|
||||
}
|
||||
{
|
||||
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);
|
||||
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;
|
||||
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();
|
||||
/* 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;
|
||||
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;
|
||||
#ifdef BB_MTAB
|
||||
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;
|
||||
}
|
||||
}
|
||||
i--;
|
||||
/* Parse options */
|
||||
i = --argc;
|
||||
argv++;
|
||||
}
|
||||
while (i > 0 && **argv) {
|
||||
if (**argv == '-') {
|
||||
char *opt = *argv;
|
||||
|
||||
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) {
|
||||
#ifdef BB_NFSMOUNT
|
||||
if (strcmp(filesystemType, "nfs") == 0) {
|
||||
if (nfsmount(device, directory, &flags, &extra_opts, &string_flags, 1) != 0)
|
||||
exit(FALSE);
|
||||
}
|
||||
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;
|
||||
#endif
|
||||
exit (mount_one (device, directory, filesystemType,
|
||||
flags, string_flags, useMtab, fakeIt, extra_opts));
|
||||
} 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++;
|
||||
}
|
||||
}
|
||||
exit( TRUE);
|
||||
|
||||
goodbye:
|
||||
usage( mount_usage);
|
||||
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) {
|
||||
#ifdef BB_NFSMOUNT
|
||||
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(TRUE);
|
||||
|
||||
goodbye:
|
||||
usage(mount_usage);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Please do not edit this file.
|
||||
* It was generated using rpcgen.
|
||||
|
||||
@@ -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);
|
||||
int status;
|
||||
|
||||
if ( status != 0 ) {
|
||||
perror(appName);
|
||||
exit( FALSE);
|
||||
}
|
||||
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");
|
||||
struct stat statBuf;
|
||||
|
||||
if (strcmp(*argv, "swapon")==0) {
|
||||
appName = *argv;
|
||||
whichApp = SWAPON_APP;
|
||||
if (stat("/etc/fstab", &statBuf) < 0)
|
||||
fprintf(stderr,
|
||||
"/etc/fstab file missing -- Please install one.\n\n");
|
||||
|
||||
} else {
|
||||
appName = *argv;
|
||||
whichApp = SWAPOFF_APP;
|
||||
}
|
||||
if (strcmp(*argv, "swapon") == 0) {
|
||||
appName = *argv;
|
||||
whichApp = SWAPON_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;
|
||||
} else {
|
||||
appName = *argv;
|
||||
whichApp = SWAPOFF_APP;
|
||||
}
|
||||
}
|
||||
swap_enable_disable(*argv);
|
||||
exit( TRUE);
|
||||
|
||||
usage_and_exit:
|
||||
usage( (whichApp==SWAPON_APP)? swapon_usage : swapoff_usage);
|
||||
exit( FALSE);
|
||||
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);
|
||||
|
||||
usage_and_exit:
|
||||
usage((whichApp == SWAPON_APP) ? swapon_usage : swapoff_usage);
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
if (argc < 2) {
|
||||
usage(umount_usage);
|
||||
}
|
||||
|
||||
/* Parse any options */
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
while (*++(*argv)) switch (**argv) {
|
||||
case 'a':
|
||||
umountAll = TRUE;
|
||||
break;
|
||||
/* 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;
|
||||
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;
|
||||
}
|
||||
this = mtab_cache;
|
||||
while (this) {
|
||||
next = this->next;
|
||||
if (this->device)
|
||||
free(this->device);
|
||||
if (this->mountpt)
|
||||
free(this->mountpt);
|
||||
free(this);
|
||||
this = next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user