Replace O_DIRECT with posix_fadvise(). This is easier to compile

and does not draw Linus's ire http://lkml.org/lkml/2007/1/10/233.
This commit is contained in:
Dave Hansen 2009-02-05 12:50:25 -08:00
parent de5918a05d
commit e81e16ef8d
4 changed files with 25 additions and 24 deletions

View file

@ -185,7 +185,7 @@ static char *eyefi_file(enum eyefi_file file)
void read_from(enum eyefi_file __file)
{
int ret, retcntl;
int ret;
int fd;
char *file = eyefi_file(__file);
@ -195,11 +195,7 @@ retry:
fd = open(file, O_RDONLY);
if (fd < 0)
open_error(file, fd);
retcntl = fd_dont_cache(fd);
if (retcntl < 0) {
perror("bad fcntl");
exit(1);
}
fd_flush(fd);
ret = read(fd, eyefi_buf, EYEFI_BUF_SIZE);
if (eyefi_debug_level > 3)
dumpbuf(eyefi_buf, 128);
@ -209,7 +205,7 @@ retry:
goto retry;
exit(1);
}
debug_printf(4, "read '%s': bytes: %d fcntl: %d\n", file, ret, retcntl);
debug_printf(4, "read '%s': bytes: %d\n", file, ret);
/*
* There was a time when I was carefully recording how each response
* looked, and I counted the zeros in each response. I don't care
@ -253,12 +249,14 @@ void write_to(enum eyefi_file __file, void *stuff, int len)
fd = open(file, O_RDWR|O_CREAT, 0600);
if (fd < 0 )
open_error(file, fd);
ret = fd_dont_cache(fd);
if (ret < 0)
open_error(file, ret);
if (eyefi_debug_level > 3)
dumpbuf(eyefi_buf, 128);
ret = write(fd, eyefi_buf, EYEFI_BUF_SIZE);
if (ret < 0)
open_error(file, ret);
ret = fd_flush(fd);
if (ret < 0)
open_error(file, ret);
close(fd);
debug_printf(3, "wrote %d bytes to '%s' (string was %d bytes)\n", ret, file, len);
if (ret < 0) {
@ -522,11 +520,13 @@ void testit0(void)
perror("fdout");
if (fdin <= 0 || fdout <= 0)
exit(1);
fd_flush(fdin);
i = read(fdin, &fwbuf[0], 524288);
perror("read");
if (i != 524288)
exit(2);
i = write(fdout, &fwbuf[0], 524288);
fd_flush(fdout);
perror("write");
if (i != 524288)
exit(3);

View file

@ -27,7 +27,7 @@ extern int eyefi_debug_level;
#define exit(i) return
#define perror(i) do{}while(0)
#define system(i) do{}while(0)
#define fd_dont_cache(fd) (0)
#define fd_flush(fd) (0)
#define assert(x) do{}while(0)
#define output_flush() do{}while(0)
@ -65,7 +65,7 @@ extern int eyefi_printf(const char *fmt, ...);
/*
* These have to be created by the unix variants
*/
extern int fd_dont_cache(int);
extern int fd_flush(int);
/*
* Do some kernel-style types to make

View file

@ -1,12 +1,7 @@
#include "eyefi-config.h"
// Geez there has to be a better way to do this
#ifdef __i386
#define O_DIRECT 00040000 /* direct disk access hint */
#else
#define O_DIRECT 0200000 /* direct disk access hint - currently ignored */
#endif
#include <unistd.h>
#include <fcntl.h>
static int atoo(char o)
{
@ -59,9 +54,13 @@ static char *replace_escapes(char *str)
return str;
}
int fd_dont_cache(int fd)
int fd_flush(int fd)
{
return fcntl(fd, F_SETFL, O_DIRECT);
int ret;
ret = posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
if (ret)
perror("posix_fadvise() failed");
return ret;
}
@ -116,9 +115,10 @@ char *locate_eyefi_mount(void)
return &eyefi_mount[0];
debug_printf(0, "unable to locate Eye-Fi card\n");
if (eyefi_debug_level < 5)
debug_printf(0, "please run with '-d5' option and report the output\n");
else {
if (eyefi_debug_level < 5) {
debug_printf(0, "Please check that your card is inserted and mounted\n");
debug_printf(0, "If you still have issues, please re-run with the '-d5' option and report the output\n");
} else {
debug_printf(0, "----------------------------------------------\n");
debug_printf(0, "Debug information:\n");
system("cat /proc/mounts >&2");

View file

@ -119,6 +119,7 @@ int try_connection_to(char *essid, char *ascii_password)
u8 last_rsp = -1;
char rsp = '\0';
ret = -1;
for (i=0; i < 200; i++) {
struct byte_response *r;
issue_noarg_command('s');