From: Terje Eggestad <terje.eggestad@scali.no>
To: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Q: A reliable way of testing if O_DIRECT is supported
Date: 16 Oct 2001 13:41:07 +0200 [thread overview]
Message-ID: <1003232468.1964.6.camel@pc-16.office.scali.no> (raw)
Is there a reliable way of testing if O_DIRECT is supported by the
kernel?
I've a test program as follows:
======================================================================
#include <errno.h>
#include <unistd.h>
#define __USE_GNU
#include <fcntl.h>
int main()
{
int fd, flags, rc;
char * buffer;
buffer = (char *) malloc(getpagesize()*2);
buffer = (char *) (((long)buffer) / getpagesize() * getpagesize()) +
getpagesize();
fd = open ("/tmp/checkdirect.dat", O_RDWR|O_CREAT|O_TRUNC|O_DIRECT,
0600);
if (fd == -1) {
printf("open failed with errno=%d\n", errno);
exit(errno);
};
printf("open OK\n", errno);
unlink ("/tmp/checkdirect.dat");
flags = fcntl(fd, F_GETFL);
printf("fcntl(fd, F_GETFL) retuned %#o \n", flags);
printf("setting O_DIRECT(=%#o) flag with fcntl()\n", O_DIRECT);
fcntl(fd, F_SETFL, O_DIRECT|flags);
flags = fcntl(fd, F_GETFL);
printf("fcntl(fd, F_GETFL) retuned %#o \n", flags, O_DIRECT);
if (!(flags & O_DIRECT)) {
printf("failed to set O_DIRECT flag errno=%d\n", errno);
exit(errno);
};
rc = write(fd, buffer, getpagesize());
if (rc != getpagesize()) {
printf("aligned write failed with errno=%d\n", errno);
exit(errno);
};
printf("aligned write OK\n", errno);
rc = write(fd, buffer+100, 100);
if (rc != 100) {
printf("unaligned write failed with errno=%d\n", errno);
exit(errno);
};
printf("unaligned write OK\n", errno);
};
======================================================================
Now on a 2.4.10 kernel it produces (correctly)
open OK
fcntl(fd, F_GETFL) retuned 040002
setting O_DIRECT(=040000) flag with fcntl()
fcntl(fd, F_GETFL) retuned 040002
aligned write OK
unaligned write failed with errno=22
But on both a RH6.2 with a 2.2.19 and a RH7.1 with 2.4.3 (both non
stock) it gives:
open OK
fcntl(fd, F_GETFL) retuned 040002
setting O_DIRECT(=040000) flag with fcntl()
fcntl(fd, F_GETFL) retuned 040002
aligned write OK
unaligned write OK
I guess the open(,,O_DIRECT) *should* have failed on earlier kernels,
but since they don't I need another way of testing if directio is
supported.
TJ
--
_________________________________________________________________________
Terje Eggestad terje.eggestad@scali.no
Scali Scalable Linux Systems http://www.scali.com
Olaf Helsets Vei 6 tel: +47 22 62 89 61 (OFFICE)
P.O.Box 70 Bogerud +47 975 31 574 (MOBILE)
N-0621 Oslo fax: +47 22 62 89 51
NORWAY
_________________________________________________________________________
reply other threads:[~2001-10-16 11:41 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1003232468.1964.6.camel@pc-16.office.scali.no \
--to=terje.eggestad@scali.no \
--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®