Binding raw devices in Linux kernel 2.6

Discussion in 'C Programming' started by galapogos, Jul 3, 2009.

  1. galapogos

    galapogos Guest

    Hi,

    I'm trying to port an old program compiled on kernel 2.4, onto kernel
    2.6. I've using a Mandriva 2009.1 box as my development PC. I've
    managed to get the program to build properly once I've gotten the
    necessary libraries, and it also runs.

    However, one of the first things that the program does is to bind the
    raw devices(already set up as separate logical partitions within the
    drive as /dev/sdaN) to /dev/rawN, in order to access them later
    directly.

    To do so, the first thing that it does is to open /dev/rawctl with the
    following code:

    Code:
    if ((master_fd = open("/dev/rawctl", O_RDWR, 0)) < 0) {
      return ERR_FAILURE;
    }
    
    However, open always returns -1, hence the program fails at this
    point.

    Has anything changed between kernel 2.4 and 2.6 that may cause a
    failure when I try to open /dev/rawctl?

    Thanks!
     
    galapogos, Jul 3, 2009
    #1
    1. Advertising

  2. On Fri, 03 Jul 2009 04:40:07 -0400, galapogos <> wrote:

    >
    Code:
    > if ((master_fd = open("/dev/rawctl", O_RDWR, 0)) < 0) {
    >   return ERR_FAILURE;
    > Has anything changed between kernel 2.4 and 2.6 that may cause a
    > failure when I try to open /dev/rawctl?[/color]
    
     From "man raw" ...
    
    WARNING
            The rawio is a deprecated interface since Linux kernel 2.6.3. Please, modify your application to open the
            block device with the O_DIRECT flag.
    
    Regards, Dave Hodgins
    
    -- 
    Change nomail.afraid.org to ody.ca to reply by email.
    (nomail.afraid.org has been set up specifically for
    use in usenet. Feel free to use it yourself.)
     
    David W. Hodgins, Jul 3, 2009
    #2
    1. Advertising

  3. galapogos schrieb:
    >
    > However, one of the first things that the program does is to bind the
    > raw devices(already set up as separate logical partitions within the
    > drive as /dev/sdaN) to /dev/rawN, in order to access them later
    > directly.
    >

    Forgetting about "raw devices" and using O_DIRECT should do the trick. But
    first read Linus' ramblings about O_DIRECT and "raw io" in general:

    http://kerneltrap.org/node/7563

    Kind regards

    Jan
     
    Jan Kandziora, Jul 5, 2009
    #3
  4. galapogos

    galapogos Guest

    On Jul 6, 6:08 am, Jan Kandziora <> wrote:
    > galapogos schrieb:
    >
    > > However, one of the first things that the program does is to bind the
    > > raw devices(already set up as separate logical partitions within the
    > > drive as /dev/sdaN) to /dev/rawN, in order to access them later
    > > directly.

    >
    > Forgetting about "raw devices" and using O_DIRECT should do the trick. But
    > first read Linus' ramblings about O_DIRECT and "raw io" in general:
    >
    > http://kerneltrap.org/node/7563
    >
    > Kind regards
    >
    >         Jan


    Thanks. Does that mean that there's no way of using binding devices
    to /dev/rawN? The original code author has left and I'm not sure why
    raw devices were used rather than using ioctl calls.

    So, by O_DIRECT, you do mean sending ioctl() to the device with
    O_DIRECT flag, right?
     
    galapogos, Jul 6, 2009
    #4
  5. galapogos schrieb:
    >
    > Thanks. Does that mean that there's no way of using binding devices
    > to /dev/rawN? The original code author has left and I'm not sure why
    > raw devices were used rather than using ioctl calls.
    >

    You could rely on this deprecated kernel feature and activate it in the
    kernel of your machine, but as you said, you'll try to *port* the software
    to Linux-2.6, it seems pretty straightforward to leave out raw devices
    entirely.


    > So, by O_DIRECT, you do mean sending ioctl() to the device with
    > O_DIRECT flag, right?
    >

    No. O_DIRECT is applied on open(). You don't have to "bind" a raw
    device /dev/raw/raw3 to a block device like /dev/sda6 using /dev/rawctl or
    the "raw" utility, then use /dev/raw/raw3 instead of /dev/sda6.

    Just open /dev/sda6 with O_DIRECT flag. You can even open simple files with
    O_DIRECT. Make sure to

    #define _GNU_SOURCE

    before any #include. BUT, if you plan to really rework your application, it
    may be wise to take a side look to madvise() and posix_fadvise().

    Kind regards

    Jan
     
    Jan Kandziora, Jul 7, 2009
    #5
  6. galapogos

    galapogos Guest

    On Jul 8, 4:01 am, Jan Kandziora <> wrote:
    > galapogos schrieb:
    >
    > > Thanks. Does that mean that there's no way of using binding devices
    > > to /dev/rawN? The original code author has left and I'm not sure why
    > > raw devices were used rather than using ioctl calls.

    >
    > You could rely on this deprecated kernel feature and activate it in the
    > kernel of your machine, but as you said, you'll try to *port* the software
    > to Linux-2.6, it seems pretty straightforward to leave out raw devices
    > entirely.
    >
    > > So, by O_DIRECT, you do mean sending ioctl() to the device with
    > > O_DIRECT flag, right?

    >
    > No. O_DIRECT is applied on open(). You don't have to "bind" a raw
    > device /dev/raw/raw3 to a block device like /dev/sda6 using /dev/rawctl or
    > the "raw" utility, then use /dev/raw/raw3 instead of /dev/sda6.
    >
    > Just open /dev/sda6 with O_DIRECT flag. You can even open simple files with
    > O_DIRECT. Make sure to
    >
    > #define _GNU_SOURCE
    >
    > before any #include. BUT, if you plan to really rework your application, it
    > may be wise to take a side look to madvise() and posix_fadvise().
    >
    > Kind regards
    >
    >         Jan


    Thanks. It turned out I didn't enable the deprecated raw. It works
    after I do so. If I run into any other problems I'll check out the
    O_DIRECT. However, conservations with the original author of the code
    revealed that the motivation to use raw instead of O_DIRECT was to
    bypass any caching that the motherboard chipset does so that the write
    happens immediately. This is important since we're dealing with timing
    critical events. Apparently O_DIRECT isn't as "direct" in his
    experience.
     
    galapogos, Jul 8, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. yogesh
    Replies:
    3
    Views:
    587
    Kenny McCormack
    Feb 12, 2006
  2. =?iso-8859-1?q?S=E9bastien_de_Mapias?=

    Accessing raw devices (hard drives) with Java ?

    =?iso-8859-1?q?S=E9bastien_de_Mapias?=, Sep 10, 2007, in forum: Java
    Replies:
    10
    Views:
    2,272
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Sep 15, 2007
  3. Naveen Vaila

    "Windows CE Devices and Palm Devices Help Needed"

    Naveen Vaila, May 24, 2004, in forum: ASP .Net Mobile
    Replies:
    1
    Views:
    508
    Abraham Durairaj
    Jun 23, 2004
  4. Replies:
    3
    Views:
    176
  5. Lars Gierth
    Replies:
    6
    Views:
    225
    David Masover
    Mar 20, 2010
Loading...

Share This Page