On Sat, 15 Dec 2001 19:18:55 -0500 (EST),
Suresh Gopalakrishnan <gsuresh@xxxxxxxxxxxxxx> wrote:
>I tried this small piece of code from an old post in the archive:
>
>#include <stdio.h>
>#include <stdlib.h>
>#include <fcntl.h>
>#include <sys/stat.h>
>#include <sys/types.h>
>#include <unistd.h>
>
>#define O_DIRECT 040000 /* direct disk access hint */
>
>int main()
>{
> char buf[16384];
> int fd;
> char *p;
>
> p = (char *)((((unsigned long)buf) + 8191) & ~8191L);
> fd = open("/tmp/blah", O_CREAT | O_RDWR | O_DIRECT);
>
> printf("write returns %i\n", write(fd, buf, 8192));
> printf("write returns %i\n", write(fd, p, 1));
>
> return 0;
>}
Works for me using gcc 2.96, glibc 2.2.2.
write returns 8192
write returns 1
Different architectures have different bit values and they have changed
since 2.4.2. Does O_DIRECT match the value of O_DIRECT in
include/asm-$(ARCH)/fcntl.h?
You omitted the mode on open, when O_CREAT is specified you must add a
mode.
fd = open("/tmp/blah", O_CREAT | O_RDWR | O_DIRECT, 0777);
|