Find the answer to your Linux question:
Results 1 to 5 of 5

Thread: Raw devices

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Raw devices

    Hi All,
    Trying to perform a read on a raw device on RedHat Linux 2.4.21-9.0.1.
    the call to perror following the call to read() returns the following error message :-
    Invalid argument.

    The arguments passed to the read function seem valid.
    Any help would be appreciated.

    Thank you,

  2. #2
    Linux Guru
    Join Date
    Apr 2003
    London, UK
    there is a difference between "seeming to be valid", and actually being valid...... without having a clue what your calling read with and without seeing your code it is unlikly anyone will be able to pull a solution out of the air for you...

  3. #3

    Raw Devices...

    Here is a testcode that I was using to test reading of raw devices on Linux.
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <errno.h>

    int main(int argc, char *argv[])
    int fd=-1;
    int readSize;
    char buffer[2048];
    int ioFlag = 0;
    mode_t mode = 0;
    if(argc < 2)
    printf("usage:test <fileName>\n");

    if((fd = open(argv[1], ioFlag, mode)) < 0)
    perror("file open failure:");

    printf("fd = %d \n" , fd);
    if(read(fd, (void *)buffer, 1024 ) < 0)
    printf("errno = %d \n", errno);
    perror("file read failure:");


    return 0;

    The program was compiled as follows:-
    cc -o test test.c

    The program was run as follows:-
    ./test /dev/raw/raw1

    The output of the program is as follows:-
    fd = 3
    errno = 22
    file read failure:: Invalid argument

    Any help would be appreciated.

  4. $spacer_open
  5. #4
    Linux Guru
    Join Date
    Apr 2003
    London, UK
    the code looks ok, except you need to include the extra headers
           #include <sys/types.h>
           #include <sys/stat.h>
           #include <fcntl.h>
    Which version of gcc are you using?
    what happens if you use /dev/random instead of a raw device? (/dev/random worked on my debian box, i dont have a /dev/raw/).


  6. #5

    Raw Devices.....

    Added the header files suggested but no change in result.
    Tried to read the /dev/random and the program ran successfully.
    The gcc version used is 3.2.3-24.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts