From: Bruno Diniz de Paula <diniz@cs.rutgers.edu>
To: linux-kernel@vger.kernel.org
Subject: Re: O_DIRECT foolish question
Date: 12 Feb 2003 17:29:52 -0500 [thread overview]
Message-ID: <1045088991.4767.85.camel@urca.rutgers.edu> (raw)
In-Reply-To: <20030212140338.6027fd94.akpm@digeo.com>
[-- Attachment #1: Type: text/plain, Size: 2545 bytes --]
On Wed, 2003-02-12 at 17:03, Andrew Morton wrote:
> Bruno Diniz de Paula <diniz@cs.rutgers.edu> wrote:
> >
> > Hi,
> >
> > I am trying to use O_DIRECT to read ordinary files and read syscall
> > always returns 0, unless when the file size equals the fs block size.
>
> It should be returning -1, with errno set to EINVAL.
But I am using multiples of page size in both buffer alignment and
buffer size (2nd and 3rd parameters of read). The issue is that when I
try to read files with sizes that are NOT multiples of block size (and
therefore also not multiples of page size), the read syscall returns 0,
with no errors. With files of size 4096, 8192 etc, everything works
fine. The errors shouldn't occur indeed, as I am using the correct
alignment and size to read. So the question remains, am I able to read
just files whose size is a multiple of block size?
Thanks,
Bruno.
PS: I am running 2.4.20...
>
> > Is
> > it true that I can only use O_DIRECT when the size of the file written
> > in the inode is a multiple of block size?
> >
>
> The file can be of any size - the kernel will zero-fill any remaining bytes.
>
> The address and length which you pass into the read() or write() system call
> must both be a multiple of the filesystem block size.
>
> It is always safe to just use the machine's page size for alignment
> calculations - no filesystem has a blocksize larger than the pagesize.
>
> A good way to do this is to run getpagesize(), and to then malloc a buffer
> which is one page larger than you need. Then round that address up to the
> next page boundary. And perform I/O into that memory with
> multiple-of-page-size requests.
>
>
>
> In the 2.5 kernel the "must be a multiple of blocksize" requirement was
> relaxed. We now support alignments and lengths down to the minimum which is
> supported by the underlying device. Typically 512 bytes, but not always.
>
> Portable applications should not assume that 512-byte alignment is supported.
> They should query the device's aligment requirements via the BLKSSZGET ioctl
> against (say) /dev/hda1. Or they can simply try 512, 1024, 2048, ... at
> initialisation time.
> -
> 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/
--
Bruno Diniz de Paula <diniz@cs.rutgers.edu>
Rutgers University
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2003-02-12 22:20 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-02-12 21:19 Bruno Diniz de Paula
2003-02-12 22:03 ` Andrew Morton
2003-02-12 22:29 ` Bruno Diniz de Paula [this message]
2003-02-12 22:42 ` Chris Wedgwood
2003-02-12 23:02 ` Bruno Diniz de Paula
2003-02-12 23:22 ` Bruno Diniz de Paula
2003-02-13 1:46 ` Randy.Dunlap
2003-02-12 23:24 ` Chris Wedgwood
2003-02-12 23:33 ` Bruno Diniz de Paula
2003-02-12 23:38 ` Chris Wedgwood
2003-02-12 23:49 ` Bruno Diniz de Paula
2003-02-12 23:51 ` Chris Wedgwood
[not found] ` <1045094589.4767.106.camel@urca.rutgers.edu>
[not found] ` <20030213001302.GA13833@f00f.org>
2003-02-13 0:36 ` Bruno Diniz de Paula
2003-02-13 5:12 ` Andrew Morton
2003-02-13 15:22 ` Bruno Diniz de Paula
2003-02-13 17:31 ` Andrew Morton
2003-02-13 22:45 ` Bruno Diniz de Paula
2003-02-12 23:33 ` Chris Wedgwood
2003-02-12 22:07 ` Chris Wedgwood
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=1045088991.4767.85.camel@urca.rutgers.edu \
--to=diniz@cs.rutgers.edu \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®