From: Yves Crespin <crespin.quartz@wanadoo.fr>
To: "Randy.Dunlap" <rddunlap@osdl.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: read failed EINVAL with O_DIRECT flag
Date: Tue, 12 Apr 2005 18:16:40 +0200 [thread overview]
Message-ID: <425BF468.1040403@wanadoo.fr> (raw)
In-Reply-To: <20050411204948.26ab87f0.rddunlap@osdl.org>
I've got compilation error when I call vmalloc() from a user program
(w/o defined __KENEL).
How can I obtains an buffer alignement from a "user program" ?
Randy.Dunlap wrote:
>On Mon, 11 Apr 2005 21:14:17 +0200 Yves Crespin wrote:
>
>| Hello,
>|
>| Using O_DIRECT flag, read() failed and errno is EINVAL.
>| kernel 2.4.22
>| Filesystem Ext3 mount on /home
>| What's wrong ?
>| Thanks
>
>In fs/buffer.c, it wants the buffer & the length (size) to be aligned:
>
>function: brw_kiovec()
>
> /*
> * First, do some alignment and validity checks
> */
> for (i = 0; i < nr; i++) {
> iobuf = iovec[i];
> if ((iobuf->offset & (size-1)) ||
> (iobuf->length & (size-1)))
> return -EINVAL;
> if (!iobuf->nr_pages)
> panic("brw_kiovec: iobuf not initialised");
> }
>
>so in your program, malloc() the buf [pointer] (larger than needed)
>and then align it to a page boundary and pass that aligned pointer
>to read().
>
>
>| /* --- 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;
>| }
>
>---
>~Randy
>-
>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at http://www.tux.org/lkml/
>
>
>
>
next prev parent reply other threads:[~2005-04-12 16:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2005-04-12 16:47 ` Randy.Dunlap
2005-04-13 13:15 ` Yves Crespin
2005-04-13 19:26 ` Randy.Dunlap
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=425BF468.1040403@wanadoo.fr \
--to=crespin.quartz@wanadoo.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=rddunlap@osdl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.