Lennert Buytenhek wrote:
> (Not on the list, please CC on replies)
page aligned memory is necessary
This isn't complete obviously but it is the basic code
to get a buffer that starts on a page boundary.
struct dioattr finfo;
ioctl(fd, XFS_IOC_DIOINFO, &finfo)
buf = (char *)malloc(<buffer size> +finfo.d_mem);
if( ((long)buf % finfo.d_mem != 0) ) {
buf += finfo.d_mem - ((long)buf % finfo.d_mem);
}
>
>
> Hi,
>
> Doing O_DIRECT I/O to a buffer which is not on an appropriate block boundary
> seem to fail with return code 22 instead of -22 (EINVAL). This is on 2.4.2
> with an XFS tree checkout from 20010329.
>
> tia,
> Lennert
>
> -- test.c
> #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("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;
> }
> -- actual output
> [buytenh@mara test]$ ./test
> write returns 22
> write returns 22
--
Russell Cattelan
cattelan@xxxxxxxxxxx
|