From: hoffman@xdelta.zko.dec.nospam Sent: Thursday, October 12, 2000 9:59 AM To: Info-VAX@Mvb.Saic.Com Subject: Re: Reading and writing files via $QIO in C In article <5.0.0.25.0.20001011144441.01bc82e0@24.8.96.48>, Dan Sugalski writes: :Well, I'm about to embark on yet another Adventure In C. (Lucky me...) This :time I need to either open and rip through an existing file, or create and :dump data to a new file. Do you need to use $qio (readvblk-level file access), or will direct RMS access from C work? Or do you need memory-mapped access to the file? (I usually prefer direct RMS access, but I will drop down to use virtual $qio operations when I need speed -- though only when I do not need the cluster-aware caching and interlocking provided by RMS.) :Anyone got example code kicking around that I can peer at for a bit that :does this sort of thing? Ayup... Here are a few different approaches: www.openvms.compaq.com/freeware/srh_examples/RMS_EXAMPLES.C www.openvms.compaq.com/wizard/wiz_2486.html attached (old, crufty) example... Probably a few others kicking around... --------------------------- pure personal opinion --------------------------- Hoff (Stephen) Hoffman OpenVMS Engineering hoffman#xdelta.zko.dec.com #module EXAMPLE "SRH X1.0-000" #pragma builtins /* ** COPYRIGHT (c) 1992 BY ** DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASSACHUSETTS. ** ALL RIGHTS RESERVED. ** ** THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED ** ONLY IN ACCORDANCE OF THE TERMS OF SUCH LICENSE AND WITH THE ** INCLUSION OF THE ABOVE COPYRIGHT NOTICE. THIS SOFTWARE OR ANY OTHER ** COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY ** OTHER PERSON. NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY ** TRANSFERRED. ** ** THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE ** AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT ** CORPORATION. ** ** DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS ** SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL. */ /* **++ ** Facility: ** ** Examples ** ** Version: V1.0 ** ** Abstract: ** ** Shows some RMS operations from C ** ** Author: ** Unknown ** ** Creation Date: 1-Jan-1990 ** ** Modification History: **-- */ #include #include #include #include #include #include #include #include #include typedef struct { short int iosb1; long int length; short int spec; } iosb; typedef struct { long int fiblength; long int fibaddress; } fibd; typedef struct { short int atr_size; short int atr_type; long int atr_address; } acb; static fibd fibdescr; static iosb iostat; static short int disk_chan; static stat_t sbuff; static struct fibdef *fib; static char data[512]; #define BAD(x) (!((x) & 1)) main (int argc, char *argv[]) { int i,j,k; $DESCRIPTOR(device, "work3:"); $DESCRIPTOR(filename, "temp.dat"); int status; status = sys$assign (&device, &disk_chan, NULL, NULL); if (BAD(status)) lib$stop (status); printf ("chanel = %d\n", disk_chan); if (access("temp.dat",0)) { /* * This crashes and burns fibdescr.fiblength = sizeof (struct fibdef); fibdescr.fibaddress = fib; fib->fib$r_exctl_overlay.fib$r_exctl_bits.fib$v_extend = 1; fib->fib$r_exctl_overlay.fib$r_exctl_bits.fib$v_aldef = 1; fib->fib$l_exsz = 5; fib->fib$l_exvbn = 0; status = sys$qiow (NULL, disk_chan, (IO$_CREATE | IO$M_EXTEND), &iostat, NULL, NULL, &fibdescr, NULL, NULL, NULL, NULL, NULL); printf ("alloc = %d\n", fib->fib$l_exsz); printf ("vbn = %d\n", fib->fib$l_exvbn); printf ("status = %x, %d : %d\n", status, status, iostat.length); printf ("iostatus = %x, %d : %d\n", iostat.iosb1, iostat.iosb1); */ /* */ j = open ("temp.dat", O_WRONLY | O_CREAT | O_TRUNC); for (i = 0; i < 512; i++) data[i] = i; write (j, data, 512); close (j); /* */ } stat ("temp.dat", &sbuff); printf ("fid = (%d %d %d)\n",sbuff.st_ino[0],sbuff.st_ino[1],sbuff.st_ino[2]); fib = (struct fibdef *) calloc (sizeof(struct fibdef), 1); fib->fib$r_acctl_overlay.fib$r_acctl_bits0.fib$v_nowrite = 1; fib->fib$r_acctl_overlay.fib$r_acctl_bits0.fib$v_write = 1; fib->fib$r_acctl_overlay.fib$r_acctl_fields2.fib$b_wsize = 7; fib->fib$r_fid_overlay.fib$w_fid[0] = sbuff.st_ino[0]; fib->fib$r_fid_overlay.fib$w_fid[1] = sbuff.st_ino[1]; fib->fib$r_fid_overlay.fib$w_fid[2] = sbuff.st_ino[2]; fibdescr.fiblength = FIB$K_LENGTH; fibdescr.fibaddress = &(fib->fib$r_acctl_overlay.fib$l_acctl); status = sys$qiow (NULL, disk_chan, (IO$_ACCESS | IO$M_ACCESS), &iostat, NULL, NULL, &fibdescr, NULL, NULL, NULL, NULL, NULL); if (BAD(status)) lib$stop (status); if (BAD(iostat.iosb1)) lib$stop (iostat.iosb1); fib->fib$r_acctl_overlay.fib$l_acctl = 0; fibdescr.fiblength = sizeof (struct fibdef); fibdescr.fibaddress = fib; fib->fib$r_exctl_overlay.fib$r_exctl_bits.fib$v_extend = 1; fib->fib$r_exctl_overlay.fib$r_exctl_bits.fib$v_aldef = 1; fib->fib$l_exsz = 5; fib->fib$l_exvbn = 0; status = sys$qiow (NULL, disk_chan, (IO$_MODIFY), &iostat, NULL, NULL, &fibdescr, NULL, NULL, NULL, NULL, NULL); printf ("alloc = %d\n", fib->fib$l_exsz); printf ("vbn = %d\n", fib->fib$l_exvbn); printf ("status = %x, %d : %d\n", status, status, iostat.length); printf ("iostatus = %x, %d : %d\n", iostat.iosb1, iostat.iosb1); fib->fib$r_exctl_overlay.fib$w_exctl = 0; for (j = 1; j < 5; j++) { for (i = 0; i < 512; i++) data[i] = j; status = sys$qiow (NULL, disk_chan, (IO$_WRITEVBLK), &iostat, NULL, NULL, data, 512, j, NULL, NULL, NULL); printf ("write status = %x, %d : %d\n", status, status, iostat.length); } for (j = 1; j < 5; j++) { for (i = 0; i < 512; i++) data[i] = 0; status = sys$qiow (NULL, disk_chan, (IO$_READVBLK), &iostat, NULL, NULL, data, 512, j, NULL, NULL, NULL); printf ("read status = %x, %d : %d\n", status, status, iostat.length); printf ("data[0] = %d\n", (long) data[0]); } status = sys$qiow (NULL, disk_chan, (IO$_DEACCESS), &iostat, NULL, NULL, &fibdescr, NULL, NULL, NULL, NULL, NULL); if (BAD(status)) lib$stop (status); exit(1); }