Path: news.mitre.org!blanket.mitre.org!philabs!newsjunkie.ans.net!newsfeeds.ans.net!streamer1.cleveland.iagnet.net!qual.net!news1.chicago.iagnet.net!iagnet.net!news.idt.net!cam-news-hub1.bbnplanet.com!su-news-hub1.bbnplanet.com!news.bbnplanet.com!news1.digital.com!pa.dec.com!eps.enet.dec.c*m!vandenheuvel
From: vandenheuvel@eps.enet.dec.c*m (Hein RMS van den Heuvel)
Newsgroups: comp.os.vms
Subject: Re: Multiply allocated blocks in RMS file
Date: 15 JAN 98 01:49:36
Organization: Digital Equipment Corporation
Lines: 99
Message-ID: <69kbnf$cpm@usenet.pa.dec.com>
References: <884795200.231669770@dejanews.com>
NNTP-Posting-Host: epsys


In article <884795200.231669770@dejanews.com>, wilke@dylan.unm.edu writes...
:
>when doing an analyze. It seems that about 20 blocks out of a 2 million
>block file were somehow multiply allocated with another com file. When we
:
>it and extract those 20 blocks and somehow put them into our corrupted
>RMS file. Is there a way to do this? The only thing we have come up with

Actually I realized I had not done any coding this year,
and decide to throw something together that might just
do what you request (up to 127 blocks at a time).

Whether you can fix your file with it remains to be seen.
The caveats from my earlier reply still apply.

Hein.


/*
** COPY_block.C     This program copies blocks from an input file 
** 		    to the output file. It does NOT verify the end
**		    of file BYTE, so you many need SET FILE/ATR=FFB
**		    if you use it to copy the last block.
**			Have fun, 
**				Hein van den Heuvel, Digital, 
**				Burning the midnite oil on 14-JAN-1998
*/
#define MAX_BLOCKS 127
#define DEFAULT_NAME ".DAT"

#include	<rms>		/* defines for rabs and fabs	*/
#include	<stdio>		/* defins printf...		*/
#include	<starlet> 	/* defines sys$open et al 	*/
#include stdlib
#include string

main(int argc,char *argv[])
{
char		rec_buff[MAX_BLOCKS*512];	/* maximum record size		      */
struct FAB	infab, outfab, *fab;	/* Allocate fabs and a pointer to fab */
struct RAB	inrab, outrab, *rab;	/* Allocate fabs and a pointer to fab */
int		lib$signal();
int		stat, blocks;
char usage[] = "Usage: $ COPY_BLOCKS input_file target_file count vbn\n";

if (argc != 5) printf("%s",&usage), exit(1);
blocks = atoi(argv[3]);
if (blocks > MAX_BLOCKS) {
    printf ("Too many blocks. Max = %d.\n", MAX_BLOCKS);
    exit (1);
    }

infab = cc$rms_fab;			/* Make this a real FAB	(bid and bln) */

infab.fab$b_fac = FAB$M_BIO | FAB$M_GET;  /* blockio access		      */
infab.fab$l_fna = argv[1];
infab.fab$b_fns = strlen(infab.fab$l_fna);
infab.fab$l_dna = (char *) &DEFAULT_NAME; /* Default name: here file type..     */
infab.fab$b_dns = sizeof DEFAULT_NAME -1; /* .. and its size		      */

inrab = cc$rms_rab;			/* Make this a real RAB (bid and bln) */
inrab.rab$l_fab = &infab;		/* Point to FAB for $CONNECT	      */
inrab.rab$l_ubf = rec_buff;		/* Point to buffer area..	      */

outfab = cc$rms_fab;			/* Make this a real FAB	(bid and bln) */
outfab.fab$b_fac = FAB$M_BIO | FAB$M_PUT; /* blockio access		      */
outfab.fab$v_nil = 1;			/* No sharing (default on create)     */
outfab.fab$l_fna = argv[2];
outfab.fab$b_fns = strlen(outfab.fab$l_fna);
outfab.fab$l_dna = (char *) &DEFAULT_NAME;
outfab.fab$b_dns = sizeof DEFAULT_NAME -1; 

outrab = cc$rms_rab;
outrab.rab$l_fab = &outfab;
outrab.rab$l_rbf = rec_buff;		/* Same buffer address as before      */

outrab.rab$l_bkt = inrab.rab$l_bkt = atoi(argv[4]);    /* set correct vbn */

outrab.rab$w_rsz = inrab.rab$w_usz = blocks * 512 ;    /* set correct size  */

stat = sys$open ( &infab );		/* Actual open (could use &infab)   */
if (stat & 1)				/* $OPEN Success ? */
    stat = sys$open ( &outfab );	/* Try to open target file	    */
if (stat & 1)				/* Both open & create success ?	    */
    stat = sys$connect ( &inrab );	/* get some rms internal buffers    */
if (stat & 1)				/* output $CONNECT Success ?	    */
    stat = sys$connect ( &outrab );	/* input $CONNECT Success ?	    */
if (stat & 1)
    stat = sys$read ( &inrab );
if (stat & 1) 
    stat = sys$write ( &outrab );		/* Actual copy		*/
if (stat & 1) 
    stat = sys$close ( &infab );   
if (stat & 1) 
    stat = sys$close ( &outfab );
return stat;
}

