From: Nathan Black <NBlack@md.aacisd.com>
To: "'Mayank Vasa'" <mvasa@confluencenetworks.com>
Cc: "'linux-kernel@vger.kernel.org'" <linux-kernel@vger.kernel.org>
Subject: RE: rawio usage
Date: Tue, 6 Feb 2001 09:48:00 -0500 [thread overview]
Message-ID: <8FED3D71D1D2D411992A009027711D671890@md> (raw)
need 512 byte alignment
i.e.
change
char writeBuf[512];
to:
char writeBuf[1023];
writeBuf = (char *)(((int )&writeBuf[0] + 511) &~511);
This will typecast the writeBuffer address to an int and add 511 to the
address. When you and that with ~511( invert 511). That will result int
something in a multiple of 512 for the address.
Then just typecast it back.
That is how to align it. Jens Was kind enough to tell me how to do this.
Nathan
-----Original Message-----
From: Mayank Vasa [mailto:mvasa@confluencenetworks.com]
Sent: Tuesday, February 06, 2001 1:37 AM
To: Linux-Kernel
Subject: rawio usage
Hi,
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) {
perror("open");
exit (1);
}
if ((lseek(fd, 0L, 0)) < 0){
perror("lseek");
exit (1);
}
if ((write(fd, writeBuf, 512)) < 0) {
printf ("errno = %d\n", errno);
perror("write");
exit(1);
}
lseek(fd, 0L, 0);
if ((read(fd, readBuf, 512)) < 0) {
perror("read");
exit(1);
}
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
writing.
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 majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
next reply other threads:[~2001-02-06 14:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-02-06 14:48 Nathan Black [this message]
-- strict thread matches above, loose matches on Subject: below --
2001-02-06 19:09 Douglas Gilbert
2001-02-06 6:36 Mayank Vasa
2001-02-06 14:17 ` Stephen C. Tweedie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8FED3D71D1D2D411992A009027711D671890@md \
--to=nblack@md.aacisd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mvasa@confluencenetworks.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®