Hello

Gorazd Golob wrote:
> 
> ;(
> 
> works ok if file is bigger than about 4000 bytes. Otherwise read failed.
> 
Yes, using O_DIRECT you should care about alignment to boundary of 512 bytes for
address of buffer you read to, size of that buffer and offset in a file to read
from.

Please try this version of test program and let us know how to make it to behave
differently for file in reiserfs and ext2.
What is version of kernel you use?
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <unistd.h>
#include <malloc.h>
#include <stdlib.h>
#include <fcntl.h>

#define O_DIRECT   040000

int main(int argc, char **argv)
{
	int fd;
	ssize_t rd;
	char *buf;
	size_t size;

	if (argc != 3) {
		printf("%s filename nr\n", argv[0]);
		return 0;
	}
	fd = open(argv[1], O_RDONLY | O_DIRECT);
	if (fd == -1) {
		perror("open failed");
		return 0;
	}
	size = atoi(argv[2]);

	if (posix_memalign((void **)&buf, 512, size)) {
		perror("malloc failed");
                return 0;
	}
	rd = read(fd, buf, size);
	if (rd != size) {
                perror("read failed");
                return 0;
	}
	free(buf);
	close(fd);
	return 0;
}

Reply via email to