public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* read failed EINVAL with O_DIRECT flag
@ 2005-04-11 19:14 Yves Crespin
  2005-04-12  3:49 ` Randy.Dunlap
  0 siblings, 1 reply; 6+ messages in thread
From: Yves Crespin @ 2005-04-11 19:14 UTC (permalink / raw)
  To: linux-kernel

Hello,

Using O_DIRECT flag, read() failed and errno is EINVAL.
kernel 2.4.22
Filesystem Ext3 mount on /home
What's wrong ?
Thanks

Yves Crespin

#gcc -Wall -D_GNU_SOURCE direct.c -o direct
#cp direct d
#./direct d
#open failed [d] 040402 0666 errno 22
#

/* --- start code --- */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>

#define O_BINARY    0

int main(int argc,char *argv[])
{
    struct stat    sbuf;
    char    buf[8192];
    int    openFlags;
    int    fd;
    int    nb;
    int    size;

    if (argc!=2){
        printf("Missing file name\n");
        exit(2);
    }
    openFlags = O_RDWR|O_BINARY|O_NOCTTY;
    openFlags |= O_DIRECT;    /* Not POSIX */
    fd = open(argv[1],openFlags,0666);
    if (fd==-1){
        printf("open failed [%s] %#o %#o errno 
%d\n",argv[1],openFlags,0666,errno);
        exit(1);
    }
    if (fstat(fd,&sbuf)<0){
        printf("fstat failed\n");
        exit(1);
    }
    size = sbuf.st_blksize;
    if (size > sizeof(buf)){
        printf("Page size too big\n");
        exit(3);
    }
    if (size > sbuf.st_size){
        printf("File too small\n");
        exit(3);
    }
    nb = read(fd,buf,size);
    if (nb != size){
        printf("read failed fd %d size %d nb %d errno 
%d\n",fd,size,nb,errno);
        exit(1);
    }
    if (close(fd)){
        printf("close failed\n");
        exit(1);
    }
    return 0;
}
/* --- end code --- */



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-04-13 19:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-11 19:14 read failed EINVAL with O_DIRECT flag Yves Crespin
2005-04-12  3:49 ` Randy.Dunlap
2005-04-12 16:16   ` Yves Crespin
2005-04-12 16:47     ` Randy.Dunlap
2005-04-13 13:15       ` Yves Crespin
2005-04-13 19:26         ` Randy.Dunlap

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox