summaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/dutmp.c47
-rw-r--r--miscutils/makedevs.c95
-rw-r--r--miscutils/mt.c98
-rw-r--r--miscutils/update.c48
4 files changed, 288 insertions, 0 deletions
diff --git a/miscutils/dutmp.c b/miscutils/dutmp.c
new file mode 100644
index 0000000..e92b670
--- /dev/null
+++ b/miscutils/dutmp.c
@@ -0,0 +1,47 @@
+/*
+ * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com>
+ *
+ * dutmp
+ * Takes utmp formated file on stdin and dumps it's contents
+ * out in colon delimited fields. Easy to 'cut' for shell based
+ * versions of 'who', 'last', etc. IP Addr is output in hex,
+ * little endian on x86.
+ *
+ * made against libc6
+ */
+
+#include "internal.h"
+#include <stdio.h>
+#include <utmp.h>
+
+const char dutmp_usage[] = "dutmp\n"
+"\n"
+"\tDump file or stdin utmp file format to stdout, pipe delimited.\n"
+"\tdutmp /var/run/utmp\n";
+
+extern int
+dutmp_fn(const struct FileInfo * i)
+{
+
+FILE * f = stdin;
+struct utmp * ut = (struct utmp *) malloc(sizeof(struct utmp) );
+
+ if ( i )
+ if (! (f = fopen(i->source, "r"))) {
+ name_and_error(i->source);
+ return 1;
+ }
+
+ while (fread (ut, 1, sizeof(struct utmp), f)) {
+ //printf("%d:%d:%s:%s:%s:%s:%d:%d:%ld:%ld:%ld:%x\n",
+ printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n",
+ ut->ut_type, ut->ut_pid, ut->ut_line,
+ ut->ut_id, ut->ut_user, ut->ut_host,
+ ut->ut_exit.e_termination, ut->ut_exit.e_exit,
+ ut->ut_session,
+ ut->ut_tv.tv_sec, ut->ut_tv.tv_usec,
+ ut->ut_addr);
+ }
+
+return 0;
+}
diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c
new file mode 100644
index 0000000..691236e
--- /dev/null
+++ b/miscutils/makedevs.c
@@ -0,0 +1,95 @@
+/*
+ * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com>
+ *
+ * makedevs
+ * Make ranges of device files quickly.
+ * known bugs: can't deal with alpha ranges
+ */
+
+#include "internal.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+const char makedevs_usage[] =
+"makedevs 0.01 -- Create an entire range of device files\n\n"
+"\tmakedevs /dev/ttyS c 4 64 0 63 (ttyS0-ttyS63)\n"
+"\tmakedevs /dev/hda b 3 0 0 8 s (hda,hda1-hda8)\n";
+
+int
+makedevs_main(struct FileInfo * i, int argc, char * * argv)
+{
+
+const char *basedev = argv[1];
+const char *type = argv[2];
+int major = atoi(argv[3]);
+int Sminor = atoi(argv[4]);
+int S = atoi(argv[5]);
+int E = atoi(argv[6]);
+int sbase = argc == 8 ? 1 : 0;
+
+mode_t mode = 0;
+dev_t dev = 0;
+char devname[255];
+char buf[255];
+
+ switch (type[0]) {
+ case 'c':
+ mode = S_IFCHR; break;
+ case 'b':
+ mode = S_IFBLK; break;
+ case 'f':
+ mode = S_IFIFO; break;
+ default:
+ usage(makedevs_usage);
+ return 2;
+ }
+ mode |= 0660;
+
+ while ( S <= E ) {
+
+ if (type[0] != 'f')
+ dev = (major << 8) | Sminor;
+ strcpy(devname, basedev);
+
+ if (sbase == 0) {
+ sprintf(buf, "%d", S);
+ strcat(devname, buf);
+ } else {
+ sbase = 0;
+ }
+
+ if (mknod (devname, mode, dev))
+ printf("Failed to create: %s\n", devname);
+
+ S++; Sminor++;
+ }
+
+return 0;
+}
+
+/*
+And this is what this program replaces. The shell is too slow!
+
+makedev () {
+local basedev=$1; local S=$2; local E=$3
+local major=$4; local Sminor=$5; local type=$6
+local sbase=$7
+
+ if [ ! "$sbase" = "" ]; then
+ mknod "$basedev" $type $major $Sminor
+ S=`expr $S + 1`
+ Sminor=`expr $Sminor + 1`
+ fi
+
+ while [ $S -le $E ]; do
+ mknod "$basedev$S" $type $major $Sminor
+ S=`expr $S + 1`
+ Sminor=`expr $Sminor + 1`
+ done
+}
+*/
diff --git a/miscutils/mt.c b/miscutils/mt.c
new file mode 100644
index 0000000..7d75fbd
--- /dev/null
+++ b/miscutils/mt.c
@@ -0,0 +1,98 @@
+#include "internal.h"
+#include <stdio.h>
+#include <sys/mtio.h>
+#include <sys/fcntl.h>
+
+const char mt_usage[] = "mt [-f device] opcode value\n";
+
+struct mt_opcodes {
+ char * name;
+ short value;
+};
+
+/* missing: eod/seod, stoptions, stwrthreshold, densities */
+static const struct mt_opcodes opcodes[] = {
+ { "bsf", MTBSF },
+ { "bsfm", MTBSFM },
+ { "bsr", MTBSR },
+ { "bss", MTBSS },
+ { "datacompression", MTCOMPRESSION },
+ { "eom", MTEOM },
+ { "erase", MTERASE },
+ { "fsf", MTFSF },
+ { "fsfm", MTFSFM },
+ { "fsr", MTFSR },
+ { "fss", MTFSS },
+ { "load", MTLOAD },
+ { "lock", MTLOCK },
+ { "mkpart", MTMKPART },
+ { "nop", MTNOP },
+ { "offline",MTOFFL },
+ { "rewoffline",MTOFFL },
+ { "ras1", MTRAS1 },
+ { "ras2", MTRAS2 },
+ { "ras3", MTRAS3 },
+ { "reset", MTRESET },
+ { "retension", MTRETEN },
+ { "rew", MTREW },
+ { "seek", MTSEEK },
+ { "setblk", MTSETBLK },
+ { "setdensity", MTSETDENSITY },
+ { "drvbuffer", MTSETDRVBUFFER },
+ { "setpart", MTSETPART },
+ { "tell", MTTELL },
+ { "wset", MTWSM },
+ { "unload", MTUNLOAD },
+ { "unlock", MTUNLOCK },
+ { "eof", MTWEOF },
+ { "weof", MTWEOF },
+ { 0, 0 }
+};
+
+extern int
+mt_main(struct FileInfo * i, int argc, char * * argv)
+{
+ const char * file = "/dev/tape";
+ const struct mt_opcodes * code = opcodes;
+ struct mtop op;
+ int fd;
+
+ if ( strcmp(argv[1], "-f") == 0 ) {
+ if ( argc < 4 ) {
+ usage(mt_usage);
+ return 1;
+ }
+ file = argv[2];
+ argv += 2;
+ argc -= 2;
+ }
+
+ while ( code->name != 0 ) {
+ if ( strcmp(code->name, argv[1]) == 0 )
+ break;
+ code++;
+ }
+
+ if ( code->name == 0 ) {
+ fprintf(stderr, "mt: unrecognized opcode %s.\n", argv[1]);
+ return 1;
+ }
+
+ op.mt_op = code->value;
+ if ( argc >= 3 )
+ op.mt_count = atoi(argv[2]);
+ else
+ op.mt_count = 1; /* One, not zero, right? */
+
+ if ( (fd = open(file, O_RDONLY, 0)) < 0 ) {
+ name_and_error(file);
+ return 1;
+ }
+
+ if ( ioctl(fd, MTIOCTOP, &op) != 0 ) {
+ name_and_error(file);
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/miscutils/update.c b/miscutils/update.c
new file mode 100644
index 0000000..f3b7fc0
--- /dev/null
+++ b/miscutils/update.c
@@ -0,0 +1,48 @@
+#include "internal.h"
+#include <linux/unistd.h>
+
+const char update_usage[] = "update\n"
+"\n"
+"\tFlush buffered data to the disk devices every 30 seconds.\n";
+
+#if defined(__GLIBC__)
+#include <sys/kdaemon.h>
+#else
+_syscall2(int, bdflush, int, func, int, data);
+#endif /* __GLIBC__ */
+
+extern int
+update_main(struct FileInfo * i, int argc, char * * argv)
+{
+ /*
+ * Update is actually two daemons, bdflush and update.
+ */
+ int pid;
+
+ pid = fork();
+ if ( pid < 0 )
+ return pid;
+ else if ( pid == 0 ) {
+ /*
+ * This is no longer necessary since 1.3.5x, but it will harmlessly
+ * exit if that is the case.
+ */
+ strcpy(argv[0], "bdflush (update)");
+ argv[1] = 0;
+ argv[2] = 0;
+ bdflush(1, 0);
+ _exit(0);
+ }
+ pid = fork();
+ if ( pid < 0 )
+ return pid;
+ else if ( pid == 0 ) {
+ argv[0] = "update";
+ for ( ; ; ) {
+ sync();
+ sleep(30);
+ }
+ }
+
+ return 0;
+}