Raw I/O question

I now have another question pertaining to I/O.  In my previous question, =
I was having problems getting Direct I/O to work.  With your help, I was =
able to get that working.  Now I want to compare Raw I/O and Direct I/O =
and see if there is any difference.

I bound a disk device to a raw device by typing

raw /dev/raw/raw1 /dev/sde1

This worked.  I then changed the code below to use "/dev/raw/raw1" as =
the file that gets opened.  I needed to have the right privileges to get =
past the EACCES error in the open.  Now I am receiving an EBUSY (16) =
error on the open.  I tried changing the flags to O_RDWR | O_NONBLOCK =
and that didn't work.  Is there another way to do raw I/O?  I assumed =
that this is the way to do it.  Any other gotchas that I forgot about?

Thanks again,

James Kramer

THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY =
MATERIAL and is thus for use only by the intended recipient. If you =
received this in error, please contact the sender and delete the e-mail =
and its attachments from all computers.=20



-----Original Message-----
From: Magni Fabrizio [mailto:Fabrizio.Magni@xxxxxxxxx]
Sent: Monday, December 13, 2004 9:19 AM
To: Kramer, James P.; oracle-l@xxxxxxxxxxxxx
Subject: RE: Direct I/O questions


Hello James,
eventually I was able to make O_DIRECT work even on x86_64 (kernel
2.6.5-7.97-smp and 2.6.9 vanilla).
Unfortunately I haven't got any itanium where to test it.

I had to create a file named xxx in the same directory of the executable
with:

dd if=3D/dev/zero of=3Dxxx bs=3D4196 count=3D100

I tested on ext2, ext3, reiserfs.

Regards
Fabrizio

The code (Thanks to Andrea Arcangeli for the revision):

#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>

#define O_DIRECT         040000 /* direct disk access hint */


int main(int argc, char *argv[])
{

     int fd =3D open("xxx", O_RDWR|O_DIRECT);
     int len, pagesize =3D getpagesize();
     char *message;

        printf("Pagesize: %d\n", pagesize);

     posix_memalign((void **)&message, pagesize, pagesize);
     memset(message, 0xff, pagesize);
     printf("%p\n", message);
     if(fd < 0) {
         printf("Unable to open file, errno is %d.\n", errno);
     } else {
         if((len =3D read(fd, message, pagesize)) < 0) {
            perror("read");
          } else {
            printf("%d bytes read from file.\n", len);
            printf("Message: %s", message);
          }
    }
    close(fd);

    return 0;
}

--
http://www.freelists.org/webpage/oracle-l

Other related posts: