/* * rw2.c * * Dieses Programm liest die ISA-Zufallswort-Karte der zweiten Generation * staendig aus (wenn einkompilerte und gejumperte Adresse uebereinstimmen) * und erstellt standarmaessig aus diesen random short die * 1457152 Byte grosse Datei /usr/local/ftp/pub/rw2.out, die zyklisch mit * den neuesten Zufallsworten ueberschrieben wird. * * Falls das Programm ohne Parameter gestartet wird und /usr/local/ftp/pub/ * nicht existiert, termiert das Programm (mit Signal 11). * * Die Nummer des aktuellen Zyklus seit dem Programmstart (und nicht mehr) * enthaelt die Datei /usr/local/ftp/pub/randw.log in Form eines unsigned * long long int. * * This Program won't work on the sparc, where there's no concept of I/O space. * Tested with 2.0 and 2.2 on the x86 * * Important: this program won't work without the compiler-option -O or -02 ... * and this program can only be run by a superuser (or another user after * "chown root.root rw2; chmod 4755 rw2"). * * Dieses user space Programm und das Modul können problemlos * gleichzeitig benutzt werden; dabei kann eine Zufallszahl von nur einen Prozess gelesen werden. * Falls die Jumper geändert werden (nicht empfohlen und mit an Sicherheit grenzender Wahrscheinlichkeit * nicht erforderlich), sollten die Adressen (pa, pb) entsprechend richtig geändert werden, * denn ansonsten werken irgendwelche Bytes eingelesen (meistens 0xff oder 0x00). 2000 Rolf Freitag, rolf.freiag at email.de This Program is free software; you can redistribute it and/od modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at yout option) any later version. This Program is distributed in the hope that it will be useful, but WITHOUT ANY WARRENTY; without even the implied warrenty of MERCHANTABILITY of FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this Program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifdef __sparc__ # error "This Program can't run on the Sparc platform" #endif #include /* error codes */ #include /* ioperm ... */ #include /* File Characteristics */ #include /* iostream/stdio */ #include /* Signals */ #include #include #include // simple version number #define SOFTWARE_VERSION_NUMBER 1.0 #define pa ((unsigned) 0x1A0) /* erste ISA-Karten-Adresse, default J1=0, J2=1 : 0x1A0=416 */ /* J1=0, J2=0 : 0x120=288 */ /* J1=1, J2=0 : 0x160=352 */ #define pb ((unsigned) 0x1A8) /* zweite ISA-Karten-Adresse, default J1=0, J2=1 : 0x1A8=422 */ /* J1=0, J2=0 : 0x128=296 */ /* J1=1, J2=0 : 0x168=360 */ static FILE *ofp1 = NULL; /* Zufallsbit-Ausgabedatei (Output-File-Pointer) */ static FILE *ofp2 = NULL; /* log-Datei (Nr. der Ausgabe-Datei ofp1) */ static long long int i = 0; static unsigned long long int intanz = 364288; /* 5 1/4 " - Disc-Groesse : 1457152 Byte */ static unsigned long long int ll = 0; /* Zahl von ofp2 */ static int ssm = 0; /* single-shot or continuous mode */ static unsigned short us = 0; /* z. Zwischenspeichern der eingelesenen 16-Bit-Werte (Words) */ void sig_handler () __attribute__ ((noreturn)); int main () __attribute__ ((noreturn)); void sig_handler (int sig) /* Signal-Handler */ { printf ("\aSignal %d - program exiting... \r\n", sig); if (ofp1 != NULL) fclose (ofp1); if (ofp2 != NULL) fclose (ofp2); ioperm (pa, 16, 0); exit (0); } /* sig_handler */ void direct () /* direktes Auslesen der Karte */ { for (;;) { rewind (ofp2); fprintf (ofp2, "%llu \n", ll); fflush (ofp2); rewind (ofp1); for (i = 1; i <= intanz; i++) { us = inw (pb); /* direktes Einlesen: letzte 16 Bit zuerst */ /* direktes Schreiben ohne die Reihenfolge zu aendern */ fwrite (&us, sizeof (unsigned short), 1, ofp1); us = inw (pa); /* direktes Schreiben ohne die Reihenfolge zu aendern */ fwrite (&us, sizeof (unsigned short), 1, ofp1); fflush (ofp1); /* Puffer leeren. Ohne die obige Einlese-Reihenfolge oder fflush */ } /* koennten einige Bits aus der Karte zweimal eingelesen werden. */ ll++; if (ssm) break; } } /* direct */ int main (const int argc, const char * const argv[]) { int chm = 1; /* f. chmod */ char line[0xffff] = { '\0' }; // for SuSE example FTP environment char outname1[0x7fff] = "/usr/local/ftp/pub/rw2.out"; // for SuSE example FTP environment char outname2[0x7fff] = "/usr/local/ftp/pub/rw2.log"; signal (SIGHUP, sig_handler); signal (SIGINT, sig_handler); signal (SIGQUIT, sig_handler); signal (SIGILL, sig_handler); signal (SIGTRAP, sig_handler); signal (SIGIOT, sig_handler); /* signal(SIGEMT, sig_handler); */ signal (SIGFPE, sig_handler); signal (SIGKILL, sig_handler); signal (SIGBUS, sig_handler); signal (SIGSEGV, sig_handler); /* signal(SIGSYS, sig_handler); */ signal (SIGPIPE, sig_handler); signal (SIGALRM, sig_handler); signal (SIGTERM, sig_handler); signal (SIGABRT, sig_handler); if ( (argc>1) and not strncmp (argv[1], "-V", 123) ) { fprintf (stdout, "%s version %.1f\n", argv[0], SOFTWARE_VERSION_NUMBER); exit ( (2 == argc) ? 0 : -1); } ioperm (pa, 16, 1); /* fuer die beide Ports der Karte (belegen je 8 Bit Adressraum) */ if ((argc > 3) or (argc < 2)) { fprintf (stderr, "\aUsage: rw2 [output file size in 4*(n/4) Byte] [output file name]\n"); fprintf (stderr, "or: %s -V\n", argv[0]); fprintf (stderr, "[] = Optional <> = Parameter Requirement. 1 or 2 parameters required.\n"); exit (-1); } if (argc >= 2) { sscanf (argv[1], "%s", line); if (sscanf (line, "%lld", &i) == 0) // if argv[1] is no number if (sscanf (line, "%s", outname1)) chm = 0; } if (i) intanz = i / 4; if (argc == 3) { sscanf (argv[2], "%s", line); if (sscanf (line, "%s", outname1)) chm = 0; } if (!(chm)) strcpy (outname2, "/dev/null"); if (chm == 0) ssm = 1; // single shot mode ofp1 = fopen (outname1, "w"); if (ferror (ofp1)) { perror ("\a output-random-file-error "); if (ofp1 != NULL) fclose (ofp1); exit (errno); } if (chm) { sprintf (line, "chmod 01644 %s", outname1); system (line); /* lesen f. alle, schreiben nur f. superuser */ } ofp2 = fopen (outname2, "w"); if (ferror (ofp2)) { perror ("\a output-log-file-error "); if (ofp1 != NULL) fclose (ofp1); if (ofp2 != NULL) fclose (ofp2); exit (errno); } if (chm) { sprintf (line, "chmod 01644 %s", outname2); system (line); /* lesen f. alle, schreiben nur f. superuser */ } direct (); if (ofp1 != NULL) fclose (ofp1); if (ofp2 != NULL) fclose (ofp2); ioperm (pa, 16, 0); exit (0); } /* main */