Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Direct I/O questions
Hello James,
eventually I was able to make O_DIRECT work even on x86_64 (kernel
2.6.5-7.97-smp and 2.6.9 vanilla).
Unfortunately I haven't got any itanium where to test it.
I had to create a file named xxx in the same directory of the executable with:
dd if=3D/dev/zero of=3Dxxx bs=3D4196 count=3D100
I tested on ext2, ext3, reiserfs.
Regards
Fabrizio
The code (Thanks to Andrea Arcangeli for the revision):
#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#define O_DIRECT 040000 /* direct disk access hint */
int main(int argc, char *argv[])
{
int fd =3D open("xxx", O_RDWR|O_DIRECT); int len, pagesize =3D getpagesize(); char *message; printf("Pagesize: %d\n", pagesize); posix_memalign((void **)&message, pagesize, pagesize); memset(message, 0xff, pagesize); printf("%p\n", message); if(fd < 0) { printf("Unable to open file, errno is %d.\n", errno); } else { if((len =3D read(fd, message, pagesize)) < 0) { perror("read"); } else { printf("%d bytes read from file.\n", len); printf("Message: %s", message); }
return 0;
}
-- http://www.freelists.org/webpage/oracle-lReceived on Mon Dec 13 2004 - 09:20:13 CST
![]() |
![]() |