#include #include #include #include #include #include #include #include void usage(void) { printf ("Usage: rawread [-s read size -n loop count -d raw device].\n"); printf ("-s N, where N is the size of the raw read (def=128K).\n"); printf ("-n N, where N is the number times to read (def=128).\n"); printf ("-d N, where N is the raw device number (def=1).\n"); } int main (int argc, char *argv[]) { int rc, i, c, rawdev, numreads; int recordsize = 65536*2; int loopcount = 128; int device = 1; char *p; char rawname[] = "/dev/raw/raw1\0\0\0"; while ((c = getopt(argc, argv, "d:s:n:?")) != -1) { switch (c) { case 'n': loopcount = atoi(optarg); break; case 's': recordsize = atoi(optarg); break; case 'd': device = atoi(optarg); break; case '?': default: usage(); return(1); } } /* raw io read size must be sector aligned */ if (recordsize & (512-1)) { printf("-s %d parm is not sector size aligned\n", recordsize); return(1); } /* loopcount must be positive */ if (loopcount < 1) { printf("-n %d parm must be > 0\n", loopcount); return(1); } /* check if default raw device overridden */ if (device != 1) { if (device < 1 || device > 256) { printf("-d %d parm must be > 0 and < 257\n", device); return(1); } sprintf(&rawname[12], "%d", device); } if ((p = (char*)malloc(recordsize+512)) == NULL) { perror("malloc of read buffer"); return(0); } /* raw io read buffer must be sector aligned */ p += (512-1); p = (char*) ((unsigned long)p & ~(512-1)); /* touch each page, do not want page faults for test */ for (i = 0; i < (recordsize >> 9) ; i++) { char * pp = p; *pp = 1; pp += 512; } rawdev = open(rawname,O_RDONLY); if (rawdev != -1) { numreads = loopcount; /* loop and read from raw device */ while (loopcount) { rc = read(rawdev, p, recordsize); if (rc == -1) { perror("raw read failed"); return(1); } loopcount--; }; printf("%d reads of %d bytes from %s (%d) OK\n", numreads, recordsize, rawname, numreads*recordsize); } else { printf("%s\n", rawname); perror("fopen failed on raw device"); return(1); } return(0); }