shoshana@pdi.UUCP (Shoshana Abrass) (03/02/91)
Last week I posted a question and answer about how to read the volume
header into a c program. My code looks like this (extras and error
checking removed for brevity):
struct volume_header *vh;
fd = open("/dev/rvh", O_RDONLY);
ioctl(fd, DIOCGETVH, vh);
The ioctl call fills "vh" with useful information, and I can then read
the volume directory and determine the length and logical-block-number
of the file I want to read. But... what now? I'd like to read this
file in off the disk. I've looked at the man pages for vh, dksc,
and the include files dvh.h and dkio.h, and nothing jumps out at me.
I've tried doing an lseek to the logical block number, but I get either
zeros or garbage. I know zilch about how devices work at this level, so
I tried the following lseeks on both /dev/vh and /dev/rvh:
lbn
sizeof(struct volume_header) + lbn
I then do a read of length-of-file, and I get 512 bytes back - of nothing.
Perhaps there's an ioctl command for this that I haven't found yet, or I'm
not doing the lseeks-reads correctly.
By the way, if I copy the file from the volume directory onto disk using
dvhtool, I get an ascii file containing what I expect. The length and lbn
in my program also match the values returned by dvhtool:
File name Length Block #
sgilabel 280 1
diskno 512 414 <== the file I want
ide 500224 415
sash 200704 1392
-shoshana
shoshana@pdi.comolson@anchor.esd.sgi.com (Dave Olson) (03/02/91)
In <9103012010.AA04983@koko.pdi.com> shoshana@pdi.UUCP (Shoshana Abrass) writes: | Last week I posted a question and answer about how to read the volume | header into a c program. My code looks like this (extras and error | checking removed for brevity): | struct volume_header *vh; | fd = open("/dev/rvh", O_RDONLY); | ioctl(fd, DIOCGETVH, vh); | The ioctl call fills "vh" with useful information, and I can then read | the volume directory and determine the length and logical-block-number | of the file I want to read. But... what now? I'd like to read this | file in off the disk. | By the way, if I copy the file from the volume directory onto disk using | dvhtool, I get an ascii file containing what I expect. The length and lbn | in my program also match the values returned by dvhtool: | File name Length Block # | sgilabel 280 1 | diskno 512 414 <== the file I want An lseek(fd, 414*512, 0), followed by a read is all that dvhtool does in this case. (Where fd is a file descriptor for the volume header, 414 is the vd_lbn from the structure, and 512 is the dp_secbytes from the vh, with the caveat that if dp_secbytes is 0, you assume 512 for compatiblity reasons.) You must of course read multiples of dp_secbytes bytes, in all cases, since you are dealing with the raw disk, but that doesn't sound like your problem. -- Dave Olson Life would be so much easier if we could just look at the source code.
jeremy@perf2.asd.sgi.com (Jeremy Higdon) (03/05/91)
In article <9103012010.AA04983@koko.pdi.com>, shoshana@pdi.UUCP (Shoshana Abrass) writes: > > Last week I posted a question and answer about how to read the volume > header into a c program. My code looks like this (extras and error > checking removed for brevity): > > struct volume_header *vh; > > fd = open("/dev/rvh", O_RDONLY); > ioctl(fd, DIOCGETVH, vh); > > The ioctl call fills "vh" with useful information, and I can then read > the volume directory and determine the length and logical-block-number > of the file I want to read. But... what now? I'd like to read this > file in off the disk. I've looked at the man pages for vh, dksc, > and the include files dvh.h and dkio.h, and nothing jumps out at me. > > I've tried doing an lseek to the logical block number, but I get either > zeros or garbage. I know zilch about how devices work at this level, so > I tried the following lseeks on both /dev/vh and /dev/rvh: > > lbn > sizeof(struct volume_header) + lbn > Try lbn*NBPSCTR (lbn*512) as the seek argument.