Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Raw I/O question
Sorry,
I was on vacation. :)
Below you can find the program modified to be tested with raw devices.
It could take long if you have a large device so I suggest you to bind raw1 to a small partition.
Regards
Fabrizio
#include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <asm/fcntl.h> #include <errno.h> #include <string.h> #define BUFFSIZE 65536 #define BLKSIZE 4096 #define ALIGN 4096
main() {
unsigned char * buff;
int stat1=3D0,stat2=3D0,stat3=3D0;
int fd1=3D0,fd2=3D0;
=20
buff=3D(char *)(((unsigned long)buff + (BLKSIZE - 1)) & (~(BLKSIZE - 1)));
if (stat3=3Dposix_memalign(&buff,ALIGN,BUFFSIZE)) {
fprintf(stderr,"ALIGN ERR:%s\n",strerror(stat3)); exit(0);
fd1=3Dopen("/dev/raw/raw1", O_RDONLY);
if ((lseek(fd1, 0, SEEK_SET)) < 0){
perror("lseek"); // problem if 2nd arg > 2G exit (1); } while(stat1=3Dread(fd1,buff,BLKSIZE)) { if (errno) { fprintf(stderr,"%d READ ERR:%s\n",stat1,strerror(errno)); exit(0); }
}
close(fd1);
}
> -----Original Message-----
> From: Kramer, James P. [mailto:james.p.kramer_at_unisys.com]=20
> Sent: Tuesday, December 28, 2004 8:01 PM
> To: Magni Fabrizio; oracle-l_at_freelists.org
> Subject: Raw I/O question
>=20 >=20
>=20
>=20
>=20
>=20
>=20
>=20
>=20 >=20 >=20
>=20 >=20
>=20
>=20
>=20
>=20
>=20
>=20> #include <fcntl.h>
> #define _GNU_SOURCE
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <sys/ioctl.h>
> #include <sys/mman.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <stdio.h>
> #include <errno.h>
> #include <string.h>
>=20
> #define O_DIRECT 040000 /* direct disk access hint */
>=20 >=20
>=20> }
> int fd =3D open("xxx", O_RDWR|O_DIRECT);
> int len, pagesize =3D getpagesize();
> char *message;
>=20
> printf("Pagesize: %d\n", pagesize);
>=20
> posix_memalign((void **)&message, pagesize, pagesize);
> memset(message, 0xff, pagesize);
> printf("%p\n", message);
> if(fd < 0) {
> printf("Unable to open file, errno is %d.\n", errno);
> } else {
> if((len =3D read(fd, message, pagesize)) < 0) {
> perror("read");
> } else {
> printf("%d bytes read from file.\n", len);
> printf("Message: %s", message);
> }
> }
> close(fd);
>=20
> return 0;
-- http://www.freelists.org/webpage/oracle-lReceived on Tue Jan 04 2005 - 03:31:34 CST
![]() |
![]() |