[lkml]   [2001]   [Feb]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Subjectrawio usage

I am quite new to rawio and am experimenting with with its usage. My test
environment is Redhat 7.0, kernel version 2.2.16-22 having an external fibre
channel drive having 2 disks (/dev/sda1 and /dev/sdb1)

All I am trying to do is to write and read to & from the disk using a raw
device. Externally I did a "raw /dev/raw/raw1 /dev/sdb1" and then I wrote a
small program to do the read/write. The program is:

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

int main(int argc, char *argv[])
int fd;
char writeBuf[512];
char readBuf[100];

memset(readBuf, '\0', 100);
memset(writeBuf, '\0', 100);

memcpy(writeBuf, "This is a test", 14);
printf("writeBuf = %s\n", writeBuf);

fd = open(argv[1], O_RDWR);
if (fd < 0) {
exit (1);

if ((lseek(fd, 0L, 0)) < 0){
exit (1);

if ((write(fd, writeBuf, 512)) < 0) {
printf ("errno = %d\n", errno);

lseek(fd, 0L, 0);
if ((read(fd, readBuf, 512)) < 0) {

printf("The readbuf is %s\n", readBuf);
return 0;

When I run this program as root, I get the error "write: Invalid argument".
It is basically returning errno = 22 which is EINVAL and as per the write
manpage means that fd is attached to an object which is unsuitable for

Could someone guide me on where I am going wrong & how to use raw devices?

Mayank Vasa
Confluence Networks.

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

 \ /
  Last update: 2005-03-22 12:57    [W:0.037 / U:13.396 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site