Find the answer to your Linux question:
Results 1 to 2 of 2
Hi All, Trying to perform a read on a raw device on Red Hat Enterprise Linux AS release 4 Kernel 2.6.9-68.9 x86_64 the call to perror following the call to ...
  1. #1
    Just Joined!
    Join Date
    Dec 2009
    Posts
    2

    'read' system call fails for RAW devices

    Hi All,

    Trying to perform a read on a raw device on Red Hat Enterprise Linux AS release 4 Kernel 2.6.9-68.9 x86_64
    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,
    Ravi

  2. #2
    Just Joined!
    Join Date
    Dec 2009
    Posts
    2
    Here is a testcode that I was using to test reading of raw devices on Linux.
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #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");
    exit(1);
    }

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

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

    close(fd);

    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

Posting Permissions

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