This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

posix_fadvise64()


Linus has merged the posix_fadvise64() implementation into 2.5.59++.  I'm not
sure what degree of support it really needs from glibc.  It would be good if
someone could wire it up sometime.  Thanks.

I used this test app:


#define _XOPEN_SOURCE	1000

#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>

#include <asm/unistd.h>

#ifndef __NR_fadvise64
#define __NR_fadvise64          250
#endif

_syscall5(int,fadvise64, int,fd, long,offset_lo,
		long,offset_hi, size_t,len, int,advice)

int posix_fadvise(int fd, off_t offset, size_t len, int advice)
{
	return fadvise64(fd, offset, 0, len, advice);
}

int posix_fadvise64(int fd, loff_t offset, size_t len, int advice)
{
	return fadvise64(fd, offset, offset >> 32, len, advice);
}

char *progname;

static void usage(void)
{
	fprintf(stderr, "Usage: %s filename offset length advice\n", progname);
	fprintf(stderr, "      advice: normal sequential willneed noreuse "
					"dontneed\n");
	exit(1);
}

int
main(int argc, char *argv[])
{
	int c;
	int fd;
	char *sadvice;
	char *filename;
	loff_t offset;
	unsigned long length;
	int advice = 0;
	int ret;

	progname = argv[0];

	while ((c = getopt(argc, argv, "")) != -1) {
		switch (c) {
		}
	}

	if (optind == argc)
		usage();
	filename = argv[optind++];

	if (optind == argc)
		usage();
	offset = strtoull(argv[optind++], NULL, 10);

	if (optind == argc)
		usage();
	length = strtol(argv[optind++], NULL, 10);

	if (optind == argc)
		usage();
	sadvice = argv[optind++];

	if (optind != argc)
		usage();

	if (!strcmp(sadvice, "normal"))
		advice = POSIX_FADV_NORMAL;
	else if (!strcmp(sadvice, "sequential"))
		advice = POSIX_FADV_SEQUENTIAL;
	else if (!strcmp(sadvice, "willneed"))
		advice = POSIX_FADV_WILLNEED;
	else if (!strcmp(sadvice, "noreuse"))
		advice = POSIX_FADV_NOREUSE;
	else if (!strcmp(sadvice, "dontneed"))
		advice = POSIX_FADV_DONTNEED;
	else
		usage();

	fd = open(filename, O_RDONLY|O_LARGEFILE);
	if (fd < 0) {
		fprintf(stderr, "%s: cannot open `%s': %s\n",
			progname, filename, strerror(errno));
		exit(1);
	}

	ret = posix_fadvise64(fd, offset, length, advice);
	if (ret) {
		fprintf(stderr, "%s: fadvise() failed: %s\n",
			progname, strerror(errno));
		exit(1);
	}
	close(fd);
	exit(0);
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]