On Sunday 11 November 2001 11:53 am, Jeff Moyer wrote:
sgaede> I don't understand why the output says /dev/*raw*/raw1 is bound sgaede> when I said /dev/raw1?
buggy error message. Open /dev/raw1 in your case. Also, when doing IO to a raw device, the buffer you pass in needs to be aligned on an 512 byte boundary. Most likely this is your problem. If you would like I can send you some sample code to align your buffs.
- -Jeff
Folks, It works, and in case someone else wants to try it out ... NOTE: this is to an IOMEGA ATAPI ZIP 100 drive, not a "real" disk! --Skip /* * a simple program showing how to do raw character-based IO to a device, * bypassing the kernel's queueing algorithm. The data is not copied to * kernel space. Instead, the user pages are mapped instead. root:/home/skip# gcc -o rwtest rwtest.c root:/home/skip# time ./rwtest (/dev/hdc1, O_SYNC) real 0m25.084s user 0m0.000s sys 0m0.000s root:/home/skip# gcc -o rwtest rwtest.c root:/home/skip# time ./rwtest (/dev/raw1) real 0m20.558s // 20% performance boost user 0m0.000s sys 0m0.050s root:/home/skip# root:/home/skip# gcc -o rwtest rwtest.c root:/home/skip# time ./rwtest (/dev/hdc1, no O_SYNC) real 0m0.112s // this really helps measure performance, no! user 0m0.010s sys 0m0.000s root:/home/skip# Thanks to Jeff Moyer <moyer@missioncriticallinux.com> for pointing out the need to have the buffer page alligned. */ #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <sys/stat.h> #include <fcntl.h> #include <time.h> int main (void) { int fd1,fd2; static unsigned char block[8192]; void *bp = (void *)((long) &block & 0xfffff000); // allign on page boundary int reads=0, writes=0; int k; time_t ticks; fd1 = open("/dev/raw1",O_CREAT|O_RDWR); if (fd1 < 0) { printf("Can't open /dev/raw1\n"); perror("rwtest: "); return 1; } for(k=0;k<1000;k++) { int count; if (k) { lseek( fd1, 0, SEEK_SET); } if (k % 2) { /* write */ count = write( fd1, bp, 1024); } else { /* read */ count = read( fd1, bp, 1024); } if (count != 1024) { printf("k = %d, Count = %d\n", k, count); return 2; } } close(fd1); return 0; }