diff options
| author | Erik Andersen <andersen@codepoet.org> | 2000-02-08 19:58:47 +0000 |
|---|---|---|
| committer | Erik Andersen <andersen@codepoet.org> | 2000-02-08 19:58:47 +0000 |
| commit | e49d5ecbbe51718fa925b6890a735e5937cc2aa2 (patch) | |
| tree | c90bda10731ad9333ce3b404f993354c9fc104b8 /miscutils | |
| parent | c0bf817bbc5c7867fbe8fb76d5c39f8ee802692f (diff) | |
| download | busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.gz busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.bz2 busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.zip | |
Some formatting updates (ran the code through indent)
-Erik
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/dutmp.c | 62 | ||||
| -rw-r--r-- | miscutils/makedevs.c | 83 | ||||
| -rw-r--r-- | miscutils/mt.c | 122 | ||||
| -rw-r--r-- | miscutils/update.c | 18 |
4 files changed, 146 insertions, 139 deletions
diff --git a/miscutils/dutmp.c b/miscutils/dutmp.c index a9e879daf..45eab8ae7 100644 --- a/miscutils/dutmp.c +++ b/miscutils/dutmp.c | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 1 | /* | 2 | /* |
| 2 | * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com> | 3 | * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com> |
| 3 | * | 4 | * |
| @@ -15,37 +16,38 @@ | |||
| 15 | #include <utmp.h> | 16 | #include <utmp.h> |
| 16 | 17 | ||
| 17 | static const char dutmp_usage[] = "dutmp\n" | 18 | static const char dutmp_usage[] = "dutmp\n" |
| 18 | "\n" | 19 | "\n" |
| 19 | "\tDump file or stdin utmp file format to stdout, pipe delimited.\n" | ||
| 20 | "\tdutmp /var/run/utmp\n"; | ||
| 21 | 20 | ||
| 22 | extern int dutmp_main (int argc, char **argv) | 21 | "\tDump file or stdin utmp file format to stdout, pipe delimited.\n" |
| 22 | "\tdutmp /var/run/utmp\n"; | ||
| 23 | |||
| 24 | extern int dutmp_main(int argc, char **argv) | ||
| 23 | { | 25 | { |
| 24 | 26 | ||
| 25 | FILE *f = stdin; | 27 | FILE *f = stdin; |
| 26 | struct utmp ut; | 28 | struct utmp ut; |
| 27 | 29 | ||
| 28 | if ((argc < 2) || (**(argv + 1) == '-')) { | 30 | if ((argc < 2) || (**(argv + 1) == '-')) { |
| 29 | usage( dutmp_usage); | 31 | usage(dutmp_usage); |
| 30 | } | 32 | } |
| 31 | 33 | ||
| 32 | if ( **(++argv) == 0 ) { | 34 | if (**(++argv) == 0) { |
| 33 | f = fopen (*(++argv), "r"); | 35 | f = fopen(*(++argv), "r"); |
| 34 | if (f < 0 ) { | 36 | if (f < 0) { |
| 35 | perror (*argv); | 37 | perror(*argv); |
| 36 | exit (FALSE); | 38 | exit(FALSE); |
| 37 | } | 39 | } |
| 38 | } | 40 | } |
| 39 | 41 | ||
| 40 | while (fread (&ut, 1, sizeof (struct utmp), f)) { | 42 | while (fread(&ut, 1, sizeof(struct utmp), f)) { |
| 41 | // printf("%d:%d:%s:%s:%s:%s:%d:%d:%ld:%ld:%ld:%x\n", | 43 | // printf("%d:%d:%s:%s:%s:%s:%d:%d:%ld:%ld:%ld:%x\n", |
| 42 | printf ("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n", | 44 | printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n", |
| 43 | ut.ut_type, ut.ut_pid, ut.ut_line, | 45 | ut.ut_type, ut.ut_pid, ut.ut_line, |
| 44 | ut.ut_id, ut.ut_user, ut.ut_host, | 46 | ut.ut_id, ut.ut_user, ut.ut_host, |
| 45 | ut.ut_exit.e_termination, ut.ut_exit.e_exit, | 47 | ut.ut_exit.e_termination, ut.ut_exit.e_exit, |
| 46 | ut.ut_session, | 48 | ut.ut_session, |
| 47 | ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, ut.ut_addr); | 49 | ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, ut.ut_addr); |
| 48 | } | 50 | } |
| 49 | 51 | ||
| 50 | exit (TRUE); | 52 | exit(TRUE); |
| 51 | } | 53 | } |
diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c index f7fbeb2fe..5948bacc8 100644 --- a/miscutils/makedevs.c +++ b/miscutils/makedevs.c | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 1 | /* | 2 | /* |
| 2 | * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com> | 3 | * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com> |
| 3 | * | 4 | * |
| @@ -5,7 +6,7 @@ | |||
| 5 | * Make ranges of device files quickly. | 6 | * Make ranges of device files quickly. |
| 6 | * known bugs: can't deal with alpha ranges | 7 | * known bugs: can't deal with alpha ranges |
| 7 | */ | 8 | */ |
| 8 | 9 | ||
| 9 | #include "internal.h" | 10 | #include "internal.h" |
| 10 | #include <stdio.h> | 11 | #include <stdio.h> |
| 11 | #include <stdlib.h> | 12 | #include <stdlib.h> |
| @@ -15,60 +16,64 @@ | |||
| 15 | #include <sys/types.h> | 16 | #include <sys/types.h> |
| 16 | #include <sys/stat.h> | 17 | #include <sys/stat.h> |
| 17 | 18 | ||
| 18 | static const char makedevs_usage[] = | 19 | static const char makedevs_usage[] = |
| 19 | "makedevs 0.01 -- Create an entire range of device files\n\n" | 20 | "makedevs 0.01 -- Create an entire range of device files\n\n" |
| 20 | "\tmakedevs /dev/ttyS c 4 64 0 63 (ttyS0-ttyS63)\n" | 21 | "\tmakedevs /dev/ttyS c 4 64 0 63 (ttyS0-ttyS63)\n" |
| 21 | "\tmakedevs /dev/hda b 3 0 0 8 s (hda,hda1-hda8)\n"; | 22 | |
| 23 | "\tmakedevs /dev/hda b 3 0 0 8 s (hda,hda1-hda8)\n"; | ||
| 22 | 24 | ||
| 23 | int | 25 | int makedevs_main(int argc, char **argv) |
| 24 | makedevs_main(int argc, char * * argv) | ||
| 25 | { | 26 | { |
| 26 | 27 | ||
| 27 | const char *basedev = argv[1]; | 28 | const char *basedev = argv[1]; |
| 28 | const char *type = argv[2]; | 29 | const char *type = argv[2]; |
| 29 | int major = atoi(argv[3]); | 30 | int major = atoi(argv[3]); |
| 30 | int Sminor = atoi(argv[4]); | 31 | int Sminor = atoi(argv[4]); |
| 31 | int S = atoi(argv[5]); | 32 | int S = atoi(argv[5]); |
| 32 | int E = atoi(argv[6]); | 33 | int E = atoi(argv[6]); |
| 33 | int sbase = argc == 8 ? 1 : 0; | 34 | int sbase = argc == 8 ? 1 : 0; |
| 34 | 35 | ||
| 35 | mode_t mode = 0; | 36 | mode_t mode = 0; |
| 36 | dev_t dev = 0; | 37 | dev_t dev = 0; |
| 37 | char devname[255]; | 38 | char devname[255]; |
| 38 | char buf[255]; | 39 | char buf[255]; |
| 39 | 40 | ||
| 40 | switch (type[0]) { | 41 | switch (type[0]) { |
| 41 | case 'c': | 42 | case 'c': |
| 42 | mode = S_IFCHR; break; | 43 | mode = S_IFCHR; |
| 43 | case 'b': | 44 | break; |
| 44 | mode = S_IFBLK; break; | 45 | case 'b': |
| 45 | case 'f': | 46 | mode = S_IFBLK; |
| 46 | mode = S_IFIFO; break; | 47 | break; |
| 47 | default: | 48 | case 'f': |
| 48 | usage( makedevs_usage); | 49 | mode = S_IFIFO; |
| 49 | } | 50 | break; |
| 50 | mode |= 0660; | 51 | default: |
| 51 | 52 | usage(makedevs_usage); | |
| 52 | while ( S <= E ) { | 53 | } |
| 53 | 54 | mode |= 0660; | |
| 55 | |||
| 56 | while (S <= E) { | ||
| 57 | |||
| 54 | if (type[0] != 'f') | 58 | if (type[0] != 'f') |
| 55 | dev = (major << 8) | Sminor; | 59 | dev = (major << 8) | Sminor; |
| 56 | strcpy(devname, basedev); | 60 | strcpy(devname, basedev); |
| 57 | 61 | ||
| 58 | if (sbase == 0) { | 62 | if (sbase == 0) { |
| 59 | sprintf(buf, "%d", S); | 63 | sprintf(buf, "%d", S); |
| 60 | strcat(devname, buf); | 64 | strcat(devname, buf); |
| 61 | } else { | 65 | } else { |
| 62 | sbase = 0; | 66 | sbase = 0; |
| 63 | } | 67 | } |
| 64 | 68 | ||
| 65 | if (mknod (devname, mode, dev)) | 69 | if (mknod(devname, mode, dev)) |
| 66 | printf("Failed to create: %s\n", devname); | 70 | printf("Failed to create: %s\n", devname); |
| 67 | 71 | ||
| 68 | S++; Sminor++; | 72 | S++; |
| 73 | Sminor++; | ||
| 69 | } | 74 | } |
| 70 | 75 | ||
| 71 | return 0; | 76 | return 0; |
| 72 | } | 77 | } |
| 73 | 78 | ||
| 74 | /* | 79 | /* |
diff --git a/miscutils/mt.c b/miscutils/mt.c index 7168ef7ac..9791b64b2 100644 --- a/miscutils/mt.c +++ b/miscutils/mt.c | |||
| @@ -1,97 +1,97 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 1 | #include "internal.h" | 2 | #include "internal.h" |
| 2 | #include <stdio.h> | 3 | #include <stdio.h> |
| 3 | #include <sys/mtio.h> | 4 | #include <sys/mtio.h> |
| 4 | #include <sys/fcntl.h> | 5 | #include <sys/fcntl.h> |
| 5 | 6 | ||
| 6 | static const char mt_usage[] = "mt [-f device] opcode value\n"; | 7 | static const char mt_usage[] = "mt [-f device] opcode value\n"; |
| 7 | 8 | ||
| 8 | struct mt_opcodes { | 9 | struct mt_opcodes { |
| 9 | char * name; | 10 | char *name; |
| 10 | short value; | 11 | short value; |
| 11 | }; | 12 | }; |
| 12 | 13 | ||
| 13 | /* missing: eod/seod, stoptions, stwrthreshold, densities */ | 14 | /* missing: eod/seod, stoptions, stwrthreshold, densities */ |
| 14 | static const struct mt_opcodes opcodes[] = { | 15 | static const struct mt_opcodes opcodes[] = { |
| 15 | { "bsf", MTBSF }, | 16 | {"bsf", MTBSF}, |
| 16 | { "bsfm", MTBSFM }, | 17 | {"bsfm", MTBSFM}, |
| 17 | { "bsr", MTBSR }, | 18 | {"bsr", MTBSR}, |
| 18 | { "bss", MTBSS }, | 19 | {"bss", MTBSS}, |
| 19 | { "datacompression", MTCOMPRESSION }, | 20 | {"datacompression", MTCOMPRESSION}, |
| 20 | { "eom", MTEOM }, | 21 | {"eom", MTEOM}, |
| 21 | { "erase", MTERASE }, | 22 | {"erase", MTERASE}, |
| 22 | { "fsf", MTFSF }, | 23 | {"fsf", MTFSF}, |
| 23 | { "fsfm", MTFSFM }, | 24 | {"fsfm", MTFSFM}, |
| 24 | { "fsr", MTFSR }, | 25 | {"fsr", MTFSR}, |
| 25 | { "fss", MTFSS }, | 26 | {"fss", MTFSS}, |
| 26 | { "load", MTLOAD }, | 27 | {"load", MTLOAD}, |
| 27 | { "lock", MTLOCK }, | 28 | {"lock", MTLOCK}, |
| 28 | { "mkpart", MTMKPART }, | 29 | {"mkpart", MTMKPART}, |
| 29 | { "nop", MTNOP }, | 30 | {"nop", MTNOP}, |
| 30 | { "offline",MTOFFL }, | 31 | {"offline", MTOFFL}, |
| 31 | { "rewoffline",MTOFFL }, | 32 | {"rewoffline", MTOFFL}, |
| 32 | { "ras1", MTRAS1 }, | 33 | {"ras1", MTRAS1}, |
| 33 | { "ras2", MTRAS2 }, | 34 | {"ras2", MTRAS2}, |
| 34 | { "ras3", MTRAS3 }, | 35 | {"ras3", MTRAS3}, |
| 35 | { "reset", MTRESET }, | 36 | {"reset", MTRESET}, |
| 36 | { "retension", MTRETEN }, | 37 | {"retension", MTRETEN}, |
| 37 | { "rew", MTREW }, | 38 | {"rew", MTREW}, |
| 38 | { "seek", MTSEEK }, | 39 | {"seek", MTSEEK}, |
| 39 | { "setblk", MTSETBLK }, | 40 | {"setblk", MTSETBLK}, |
| 40 | { "setdensity", MTSETDENSITY }, | 41 | {"setdensity", MTSETDENSITY}, |
| 41 | { "drvbuffer", MTSETDRVBUFFER }, | 42 | {"drvbuffer", MTSETDRVBUFFER}, |
| 42 | { "setpart", MTSETPART }, | 43 | {"setpart", MTSETPART}, |
| 43 | { "tell", MTTELL }, | 44 | {"tell", MTTELL}, |
| 44 | { "wset", MTWSM }, | 45 | {"wset", MTWSM}, |
| 45 | { "unload", MTUNLOAD }, | 46 | {"unload", MTUNLOAD}, |
| 46 | { "unlock", MTUNLOCK }, | 47 | {"unlock", MTUNLOCK}, |
| 47 | { "eof", MTWEOF }, | 48 | {"eof", MTWEOF}, |
| 48 | { "weof", MTWEOF }, | 49 | {"weof", MTWEOF}, |
| 49 | { 0, 0 } | 50 | {0, 0} |
| 50 | }; | 51 | }; |
| 51 | 52 | ||
| 52 | extern int | 53 | extern int mt_main(int argc, char **argv) |
| 53 | mt_main(int argc, char** argv) | ||
| 54 | { | 54 | { |
| 55 | const char * file = "/dev/tape"; | 55 | const char *file = "/dev/tape"; |
| 56 | const struct mt_opcodes * code = opcodes; | 56 | const struct mt_opcodes *code = opcodes; |
| 57 | struct mtop op; | 57 | struct mtop op; |
| 58 | int fd; | 58 | int fd; |
| 59 | 59 | ||
| 60 | if ( strcmp(argv[1], "-f") == 0 ) { | 60 | if (strcmp(argv[1], "-f") == 0) { |
| 61 | if ( argc < 4 ) { | 61 | if (argc < 4) { |
| 62 | usage (mt_usage); | 62 | usage(mt_usage); |
| 63 | } | 63 | } |
| 64 | file = argv[2]; | 64 | file = argv[2]; |
| 65 | argv += 2; | 65 | argv += 2; |
| 66 | argc -= 2; | 66 | argc -= 2; |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | while ( code->name != 0 ) { | 69 | while (code->name != 0) { |
| 70 | if ( strcmp(code->name, argv[1]) == 0 ) | 70 | if (strcmp(code->name, argv[1]) == 0) |
| 71 | break; | 71 | break; |
| 72 | code++; | 72 | code++; |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | if ( code->name == 0 ) { | 75 | if (code->name == 0) { |
| 76 | fprintf(stderr, "mt: unrecognized opcode %s.\n", argv[1]); | 76 | fprintf(stderr, "mt: unrecognized opcode %s.\n", argv[1]); |
| 77 | return( FALSE); | 77 | return (FALSE); |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | op.mt_op = code->value; | 80 | op.mt_op = code->value; |
| 81 | if ( argc >= 3 ) | 81 | if (argc >= 3) |
| 82 | op.mt_count = atoi(argv[2]); | 82 | op.mt_count = atoi(argv[2]); |
| 83 | else | 83 | else |
| 84 | op.mt_count = 1; /* One, not zero, right? */ | 84 | op.mt_count = 1; /* One, not zero, right? */ |
| 85 | 85 | ||
| 86 | if ( (fd = open(file, O_RDONLY, 0)) < 0 ) { | 86 | if ((fd = open(file, O_RDONLY, 0)) < 0) { |
| 87 | perror(file); | 87 | perror(file); |
| 88 | return( FALSE); | 88 | return (FALSE); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | if ( ioctl(fd, MTIOCTOP, &op) != 0 ) { | 91 | if (ioctl(fd, MTIOCTOP, &op) != 0) { |
| 92 | perror(file); | 92 | perror(file); |
| 93 | return( FALSE); | 93 | return (FALSE); |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | return( TRUE); | 96 | return (TRUE); |
| 97 | } | 97 | } |
diff --git a/miscutils/update.c b/miscutils/update.c index 5a7c755ff..fef188bba 100644 --- a/miscutils/update.c +++ b/miscutils/update.c | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 1 | /* | 2 | /* |
| 2 | * Mini update implementation for busybox | 3 | * Mini update implementation for busybox |
| 3 | * | 4 | * |
| @@ -27,20 +28,19 @@ | |||
| 27 | #include <sys/kdaemon.h> | 28 | #include <sys/kdaemon.h> |
| 28 | #else | 29 | #else |
| 29 | _syscall2(int, bdflush, int, func, int, data); | 30 | _syscall2(int, bdflush, int, func, int, data); |
| 30 | #endif /* __GLIBC__ */ | 31 | #endif /* __GLIBC__ */ |
| 31 | 32 | ||
| 32 | extern int | 33 | extern int update_main(int argc, char **argv) |
| 33 | update_main(int argc, char** argv) | ||
| 34 | { | 34 | { |
| 35 | /* | 35 | /* |
| 36 | * Update is actually two daemons, bdflush and update. | 36 | * Update is actually two daemons, bdflush and update. |
| 37 | */ | 37 | */ |
| 38 | int pid; | 38 | int pid; |
| 39 | 39 | ||
| 40 | pid = fork(); | 40 | pid = fork(); |
| 41 | if ( pid < 0 ) | 41 | if (pid < 0) |
| 42 | return pid; | 42 | return pid; |
| 43 | else if ( pid == 0 ) { | 43 | else if (pid == 0) { |
| 44 | /* | 44 | /* |
| 45 | * This is no longer necessary since 1.3.5x, but it will harmlessly | 45 | * This is no longer necessary since 1.3.5x, but it will harmlessly |
| 46 | * exit if that is the case. | 46 | * exit if that is the case. |
| @@ -52,11 +52,11 @@ update_main(int argc, char** argv) | |||
| 52 | _exit(0); | 52 | _exit(0); |
| 53 | } | 53 | } |
| 54 | pid = fork(); | 54 | pid = fork(); |
| 55 | if ( pid < 0 ) | 55 | if (pid < 0) |
| 56 | return pid; | 56 | return pid; |
| 57 | else if ( pid == 0 ) { | 57 | else if (pid == 0) { |
| 58 | argv[0] = "update"; | 58 | argv[0] = "update"; |
| 59 | for ( ; ; ) { | 59 | for (;;) { |
| 60 | sync(); | 60 | sync(); |
| 61 | sleep(30); | 61 | sleep(30); |
| 62 | } | 62 | } |
