From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 23-MAY-1989 11:49
To:	MRGATE::"ARISIA::EVERHART"
Subj:	UNDELETE program 1 of 3

Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Tue, 23 MAY 89 07:08:18 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Tue, 23 May 89 07:06:34 PDT
Received: by ucbvax.Berkeley.EDU (5.61/1.36)
	id AA17072; Tue, 23 May 89 06:54:30 -0700
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 23 May 89 09:31:47 GMT
From: mcvax!ukc!stl!scott@uunet.uu.net  (Mike Scott)
Organization: STC Technology Limited, London Road, Harlow, Essex, UK
Subject: UNDELETE program 1 of 3
Message-Id: <1469@stl.stc.co.uk>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

I noticed a couple of posting recently requesting an undelete program.
Well, here's the one we've been using here for some years. It was
written by a colleague, Gary Nebbett, who has agreed to my posting it.


$! ..................... Cut between dotted lines and save. ....................
$!.............................................................................
$! VAX/VMS archive file created by VMS_SHARE V06.06A 19-DEC-1988.
$!
$! VMS_SHARE was written by James Gray (Gray:OSBUSouth@Xerox.COM) from
$! VMS_SHAR by Michael Bednarek (U3369429@ucsvc.dn.mu.oz.au).
$!
$! To unpack, simply save, concatinate all parts into one file and
$! execute (@) that file.
$!
$! This archive was created by user SCOTT
$! on 23-MAY-1989 10:11:42.23.
$!
$! ATTENTION: To keep each article below 31 blocks (15872 bytes), this
$!            program has been transmitted in 3 parts.  You should
$!            concatenate ALL parts to ONE file and execute (@) that file.
$!
$! It contains the following 6 files:
$!        AAAREADME.1ST
$!        BUILD.COM
$!        RMS.PAS
$!        UNDELETE.CLD
$!        UNDELETE.PAS
$!        UNDELETE_MSG.MSG
$!
$!==============================================================================
$ SET SYMBOL/SCOPE=( NOLOCAL, NOGLOBAL )
$ VERSION = F$GETSYI( "VERSION" )
$ IF VERSION .GES "V4.4" THEN GOTO VERSION_OK
$ WRITE SYS$OUTPUT "You are running VMS ''VERSION'; ", -
    "VMS_SHARE V06.06A 19-DEC-1988 requires VMS V4.4 or higher."
$ EXIT 44 ! SS$_ABORT
$VERSION_OK:
$ GOTO START
$!
$UNPACK_FILE:
$ WRITE SYS$OUTPUT "Creating ''FILE_IS'"
$ DEFINE/USER_MODE SYS$OUTPUT NL:
$ EDIT/TPU/COMMAND=SYS$INPUT/NODISPLAY/OUTPUT='FILE_IS'/NOSECTION -
    VMS_SHARE_DUMMY.DUMMY
b_part := CREATE_BUFFER( "{Part}", GET_INFO( COMMAND_LINE, "file_name" ) )
; s_file_spec := GET_INFO( COMMAND_LINE, "output_file" ); SET( OUTPUT_FILE
, b_part, s_file_spec ); b_errors := CREATE_BUFFER( "{Errors}" ); i_errors 
:= 0; pat_beg_1 := ANCHOR & "-+-+-+ Beginning"; pat_beg_2 := LINE_BEGIN 
& "+-+-+-+ Beginning"; pat_end := ANCHOR & "+-+-+-+-+ End"; POSITION
( BEGINNING_OF( b_part ) ); LOOP EXITIF SEARCH( SPAN( ' ' )@r_trail 
& LINE_END, FORWARD) = 0; POSITION( r_trail ); ERASE( r_trail ); ENDLOOP
; POSITION( BEGINNING_OF( b_part ) ); i_append_line := 0; LOOP EXITIF MARK
( NONE ) = END_OF( b_part ); s_x := ERASE_CHARACTER( 1 )
; IF s_x = '+' THEN r_skip := SEARCH( pat_beg_1, FORWARD, EXACT ); IF r_skip 
<> 0 THEN s_x := ''; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ERASE_LINE; ENDIF
; ENDIF; IF s_x = '-' THEN r_skip := SEARCH( pat_end, FORWARD, EXACT )
; IF r_skip <> 0 THEN s_x := ''; MOVE_HORIZONTAL( -CURRENT_OFFSET ); m_skip 
:= MARK( NONE ); r_skip := SEARCH( pat_beg_2, FORWARD, EXACT ); IF r_skip 
<> 0 THEN POSITION( END_OF( r_skip ) ); MOVE_HORIZONTAL( -CURRENT_OFFSET )
; MOVE_VERTICAL( 1 ); MOVE_HORIZONTAL( -1 ); ELSE POSITION( END_OF( b_part ) 
); ENDIF; ERASE( CREATE_RANGE( m_skip, MARK( NONE ), NONE ) ); ENDIF; ENDIF
; IF s_x = 'V' THEN s_x := ''; IF i_append_line <> 0 THEN APPEND_LINE
; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ENDIF; i_append_line := 1
; MOVE_VERTICAL( 1 ); ENDIF; IF s_x = 'X' THEN s_x := ''; IF i_append_line 
<> 0 THEN APPEND_LINE; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ENDIF
; i_append_line := 0; MOVE_VERTICAL( 1 ); ENDIF; IF s_x <> '' THEN i_errors 
:= i_errors + 1; s_text := CURRENT_LINE; POSITION( b_errors ); COPY_TEXT
( "The following line could not be unpacked properly:" ); SPLIT_LINE
; COPY_TEXT( s_x ); COPY_TEXT( s_text ); POSITION( b_part ); MOVE_VERTICAL
( 1 ); ENDIF; ENDLOOP; POSITION( BEGINNING_OF( b_part ) ); LOOP r_x := SEARCH
( "`", FORWARD, EXACT ); EXITIF r_x = 0; POSITION( r_x ); ERASE_CHARACTER( 1 
); COPY_TEXT( ASCII( INT( ERASE_CHARACTER( 3 ) ) ) ); ENDLOOP
; IF i_errors = 0 THEN SET( NO_WRITE, b_errors, ON ); ELSE POSITION
( BEGINNING_OF( b_errors ) ); COPY_TEXT( FAO
( "The following !UL errors were detected while unpacking !AS", i_errors
, s_file_spec ) ); SPLIT_LINE; SET( OUTPUT_FILE, b_errors, "SYS$COMMAND" )
; ENDIF; EXIT; 
$ DELETE VMS_SHARE_DUMMY.DUMMY;*
$ CHECKSUM 'FILE_IS
$ WRITE SYS$OUTPUT " CHECKSUM ", -
  F$ELEMENT( CHECKSUM_IS .EQ. CHECKSUM$CHECKSUM, ",", "failed!!,passed." )
$ RETURN
$!
$START:
$ FILE_IS = "AAAREADME.1ST"
$ CHECKSUM_IS = 678562302
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
XAt last: a working, fully atomatic undelete program.  Of course, on a
Xmulti-user system, you have to be pretty sharp to undelete a file before
Xsomeone else reuses its data blocks!`032
X
XUNDELETE needs to be installed with privileges phy_io and sysprv. It has
Xceratin security measures built in, but we still also set acnt for the
Xinstalled image.`032
X
XIts author is a colleague of mine, Gary Nebbett, grn@stl.stc.co.uk. I'm just
Xposting it with his agreement.`032
X
VNaturally, this code comes with no warranty whatsoever: you install and use i
Xt
Xentirely at your own risk.`032
X
$ GOSUB UNPACK_FILE
$ FILE_IS = "BUILD.COM"
$ CHECKSUM_IS = 1713251057
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X$ message undelete_msg
X$ pascal rms/envi
X$ pascal undelete
X$ link undelete,rms,undelete_msg
$ GOSUB UNPACK_FILE
$ FILE_IS = "RMS.PAS"
$ CHECKSUM_IS = 426865013
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
XMODULE RMS;
X
XCONST
X
X`009STRING_MAX`009= 255;
X
X
X
XTYPE
X
X`009$UBYTE`009= [BYTE] 0..255;
X
X`009$UWORD`009= [WORD] 0..65535;
X
X`009$QUAD`009= [QUAD, UNSAFE] RECORD
X`009`009`009L0 : UNSIGNED;
X`009`009`009L1 : INTEGER;
X`009`009  END;
X
X`009$IOSB`009= [QUAD, UNSAFE] RECORD
X`009`009`009Status`009: $UWORD;
X`009`009`009Count`009: INTEGER;
X`009`009`009Unused`009: $UWORD;
X`009`009  END;
X
X
X`009$DESCR`009= [QUAD, UNSAFE] RECORD
X`009`009`009Length`009: $UWORD;
X`009`009`009Dtype`009: $UBYTE;
X`009`009`009Class`009: $UBYTE;
X`009`009`009Address`009: UNSIGNED;
X`009`009  END;
X
X`009$STRING`009= VARYING [STRING_MAX] OF CHAR;
X
X`009$BIT2`009= [BIT(2), UNSAFE] 0..3;
X`009$BIT6`009= [BIT(6), UNSAFE] 0..63;
X
X`009HM$TYPE`009= RECORD
X`009`009`009HM$HOMELBN`009: INTEGER;
X`009`009`009HM$ALHOMELBN`009: INTEGER;
X`009`009`009HM$ALTIDXLBN`009: INTEGER;
X`009`009`009HM$STRUCVER`009: $UBYTE;
X`009`009`009HM$STRUCLEV`009: $UBYTE;
X`009`009`009HM$CLUSTER`009: $UWORD;
X`009`009`009HM$HOMEVBN`009: $UWORD;
X`009`009`009HM$ALHOMEVBN`009: $UWORD;
X`009`009`009HM$ALTIDXVBN`009: $UWORD;
X`009`009`009HM$IBMAPVBN`009: $UWORD;
X`009`009`009HM$IBMAPLBN`009: INTEGER;
X`009`009`009HM$MAXFILES`009: INTEGER;
X`009`009`009HM$IBMAPSIZE`009: $UWORD;
X`009`009`009HM$RESFILES`009: $UWORD;
X`009`009`009HM$DEVTYPE`009: $UWORD;
X`009`009`009HM$RVN`009`009: $UWORD;
X`009`009`009HM$SETCOUNT`009: $UWORD;
X`009`009`009HM$VOLCHAR`009: $UWORD;
X`009`009`009HM$VOLOWNER`009: INTEGER;
X`009`009`009HM$SEC_MASK`009: INTEGER;
X`009`009`009HM$PROTECT`009: $UWORD;
X`009`009`009HM$FILEPROT`009: $UWORD;
X`009`009`009HM$RECPROT`009: $UWORD;
X`009`009`009HM$CHECKSUM1`009: $UWORD;
X`009`009`009HM$CREDATE`009: $QUAD;
X`009`009`009HM$WINDOW`009: $UBYTE;
X`009`009`009HM$LRU_LIM`009: $UBYTE;
X`009`009`009HM$EXTEND`009: $UWORD;
X`009`009`009HM$RETAINMIN`009: $QUAD;
X`009`009`009HM$RETAINMAX`009: $QUAD;
X`009`009`009HM$REVDATE`009: $QUAD;
X`009`009`009HM$MIN_CLASS`009: PACKED ARRAY [1..20] OF $UBYTE;
X`009`009`009HM$MAX_CLASS`009: PACKED ARRAY [1..20] OF $UBYTE;
X`009`009`009HM$PAD1`009`009: PACKED ARRAY [1..320] OF CHAR;
X`009`009`009HM$SERIALNUM`009: INTEGER;
X`009`009`009HM$STRUCTNAME`009: PACKED ARRAY [1..12] OF CHAR;
X`009`009`009HM$VOLNAME`009: PACKED ARRAY [1..12] OF CHAR;
X`009`009`009HM$OWNERNAME`009: PACKED ARRAY [1..12] OF CHAR;
X`009`009`009HM$FORMAT`009: PACKED ARRAY [1..12] OF CHAR;
X`009`009`009HM$PAD2`009`009: $UWORD;
X`009`009`009HM$CHECKSUM2`009: $UWORD;
X`009`009  END;
X
X`009FAT$TYPE= PACKED RECORD
X`009`009`009FAT$B_RTYPE`009: $UBYTE;
X`009`009`009FAT$B_RATTRIB`009: $UBYTE;
X`009`009`009FAT$W_RSIZE`009: $UWORD;
X`009`009`009FAT$L_HIBLK`009: INTEGER;
X`009`009`009FAT$L_EFBLK`009: INTEGER;
X`009`009`009FAT$W_FFBYTE`009: $UWORD;
X`009`009`009FAT$B_BKTSIZE`009: $UBYTE;
X`009`009`009FAT$B_VFCSIZE`009: $UBYTE;
X`009`009`009FAT$W_MAXREC`009: $UWORD;
X`009`009`009FAT$W_DEFEXT`009: $UWORD;
X`009`009`009FAT$W_GBC`009: $UWORD;
X`009`009`009FAT$_RESERVED`009: PACKED ARRAY [1..6] OF $UBYTE;
X`009`009`009FAT$W_UNUSED`009: $UWORD;
X`009`009`009FAT$W_VERSIONS`009: $UWORD;
X`009`009  END;
X
X`009FH$TYPE`009= RECORD
X`009`009`009FH$IDOFFSET`009: $UBYTE;
X`009`009`009FH$MPOFFSET`009: $UBYTE;
X`009`009`009FH$ACOFFSET`009: $UBYTE;
X`009`009`009FH$RSOFFSET`009: $UBYTE;
X`009`009`009FH$SEG_NUM`009: $UWORD;
X`009`009`009FH$STRUCVER`009: $UBYTE;
X`009`009`009FH$STRUCLEV`009: $UBYTE;
X`009`009`009FH$FID_NUM`009: $UWORD;
X`009`009`009FH$FID_SEQ`009: $UWORD;
X`009`009`009FH$FID_RVN`009: $UWORD;
X`009`009`009FH$EX_FIDNUM`009: $UWORD;
X`009`009`009FH$EX_FIDSEQ`009: $UWORD;
X`009`009`009FH$EX_FIDRVN`009: $UWORD;
X`009`009`009FH$RECATTR`009: FAT$TYPE;
X`009`009`009FH$FILECHAR`009: INTEGER;
X`009`009`009FH$RECPROT`009: $UWORD;
X`009`009`009FH$MAP_INUSE`009: $UBYTE;
X`009`009`009FH$ACC_MODE`009: $UBYTE;
X`009`009`009FH$UICMEMBER`009: $UWORD;
X`009`009`009FH$UICGROUP`009: $UWORD;
X`009`009`009FH$FILEPROT`009: $UWORD;
X`009`009`009FH$BK_FIDNUM`009: $UWORD;
X`009`009`009FH$BK_FIDSEQ`009: $UWORD;
X`009`009`009FH$BK_FIDRVN`009: $UWORD;
X`009`009`009FH$JOURNAL`009: $UWORD;
X`009`009`009FH$PAD1`009`009: $UWORD;
X`009`009`009FH$HIGHWATER`009: $UWORD;
X`009`009`009FH$PAD2`009`009: PACKED ARRAY [1..8] OF CHAR;
X`009`009`009FH$CLASS_PROT`009: PACKED ARRAY [1..20] OF CHAR;
X`009`009`009FH$PAD3`009`009: PACKED ARRAY [1..402] OF CHAR;
X`009`009`009FH$CHECKSUM`009: $UWORD;
X`009`009  END;
X
X`009FI$TYPE`009= RECORD
X`009`009`009FI$FILENAME`009: PACKED ARRAY [1..20] OF CHAR;
X`009`009`009FI$REVISION`009: $UWORD;
X`009`009`009FI$CREDATE`009: $QUAD;
X`009`009`009FI$REVDATE`009: $QUAD;
X`009`009`009FI$EXPDATE`009: $QUAD;
X`009`009`009FI$BAKDATE`009: $QUAD;
X`009`009`009FI$FILENAMEXT`009: PACKED ARRAY [1..66] OF CHAR;
X`009`009`009FI$USERLABEL`009: PACKED ARRAY [1..80] OF CHAR;
X`009`009  END;
X
X`009FM$TYPE`009= PACKED RECORD
X`009`009`009FIELD$1`009`009: $UBYTE;
X`009`009`009FIELD$2`009`009: $BIT6;
X`009`009`009MAP$TYPE`009: $BIT2;
X`009`009`009FIELD$3`009`009: $UWORD;
X`009`009`009FIELD$4`009`009: $UWORD;
X`009`009`009FIELD$5`009`009: $UWORD;
X`009`009  END;
X
X`009MESSAGE`009= PACKED RECORD
X`009`009`009ARG$COUNT`009: $UWORD;
X`009`009`009DEF$MESSAGE$OPT`009: $UWORD;
X`009`009`009MESSAGE$CODE`009: INTEGER;
X`009`009`009FAO$COUNT`009: $UWORD;
X`009`009`009NEW$MESSAGE$OPT`009: $UWORD;
X`009`009`009FAO$1`009`009: INTEGER;
X`009`009`009FAO$2`009`009: INTEGER;
X`009`009`009FAO$3`009`009: INTEGER;
X`009`009`009FAO$4`009`009: INTEGER;
X`009`009`009FAO$5`009`009: INTEGER;
X`009`009`009FAO$6`009`009: INTEGER;
X`009`009`009FAO$7`009`009: INTEGER;
X`009`009`009FAO$8`009`009: INTEGER;
X`009`009`009FAO$9`009`009: INTEGER;
X`009`009`009FAO$10`009`009: INTEGER;
X`009`009  END;
X
X
XVAR
X`009UNDELETE_LOCATED`009: [EXTERNAL] INTEGER;
X`009UNDELETE_WRITTEN`009: [EXTERNAL] INTEGER;
X`009UNDELETE_WRITERR`009: [EXTERNAL] INTEGER;
X`009UNDELETE_NONFOUND`009: [EXTERNAL] INTEGER;
X
X
X
XFUNCTION CLI$GET_VALUE`032
X    (%STDESCR Name : PACKED ARRAY [lb..ub : INTEGER] OF CHAR;
X    Value : $DESCR)`032
X: INTEGER; EXTERNAL;
X
XFUNCTION LIB$GETJPI
X    (ITMCODE`009: INTEGER;
X     PID`009: INTEGER := %IMMED 0;
V     PRCNAM`009: [CLASS_S] PACKED ARRAY [lb1..ub1 : INTEGER] OF CHAR := %IMME
XD 0;
X     VAR OUTVAL`009: $QUAD := %IMMED 0;
V     VAR OUTSTR`009: [CLASS_S] PACKED ARRAY [lb2..ub2 : INTEGER] OF CHAR := %
XIMMED 0;
X     VAR OUTLEN`009: $UWORD := %IMMED 0)`032
X: INTEGER; EXTERNAL;
X
XFUNCTION LIB$GET_VM
X    (Block_Size : INTEGER;
X     VAR Block_Base : INTEGER)`032
X: INTEGER; EXTERNAL;
X
XFUNCTION LIB$SIGNAL
X    (%IMMED Condition : INTEGER;
X     %IMMED Arg_Count : INTEGER := %IMMED 0;
X     %IMMED ARG1      : INTEGER := %IMMED 0;
X     %IMMED ARG2      : INTEGER := %IMMED 0;
X     %IMMED ARG3      : INTEGER := %IMMED 0;
X     %IMMED ARG4      : INTEGER := %IMMED 0;
X     %IMMED ARG5      : INTEGER := %IMMED 0;
X     %IMMED ARG6      : INTEGER := %IMMED 0;
X     %IMMED ARG7      : INTEGER := %IMMED 0;
X     %IMMED ARG8      : INTEGER := %IMMED 0;
X     %IMMED ARG9      : INTEGER := %IMMED 0;
X     %IMMED ARG10     : INTEGER := %IMMED 0)
X: INTEGER; EXTERNAL;
X
X
V`123*************************************************************************
X******
X
XFormat of file header map area
X
X
X31                             16 15                              0
X+--------------------------------+--------------------------------+
V`124                                `124type`124        placement          `1
X24
X+--------------------------------+--------------------------------+
X`124                                `124                                `124
X+--------------------------------+--------------------------------+
X
X31                             16 15                              0
X+--------------------------------+--------------------------------+
V`124          lbn                   `124type`124   lbn    `124    count  `032
X    `124
X+--------------------------------+--------------------------------+
X`124                                `124                                `124
X+--------------------------------+--------------------------------+
X
X31                             16 15                              0
X+--------------------------------+--------------------------------+
V`124             lbn                `124type`124          count            `1
X24
X+--------------------------------+--------------------------------+
X`124                                `124             lbn                `124
X+--------------------------------+--------------------------------+
X
X31                             16 15                              0
X+--------------------------------+--------------------------------+
V`124            count               `124type`124          count            `1
X24
X+--------------------------------+--------------------------------+
X`124             lbn                `124             lbn                `124
X+--------------------------------+--------------------------------+
X
V*****************************************************************************
X**`125
X
XEND.
$ GOSUB UNPACK_FILE
$ FILE_IS = "UNDELETE.CLD"
$ CHECKSUM_IS = 104220899
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
XDEFINE VERB UNDELETE
X        IMAGE     UNDELETE
X        PARAMETER P1, LABEL=Filename, VALUE(REQUIRED), PROMPT="File"
$ GOSUB UNPACK_FILE
$ FILE_IS = "UNDELETE.PAS"
$ CHECKSUM_IS = 1683804827
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X[INHERIT ('RMS', 'SYS$LIBRARY:STARLET')] PROGRAM Undelete;
X
XCONST
X`009MAX_BLOCK`009= 10000;
X`009MAX_FILES`009= 50000;
X`009MAX_NAME`009= 39;
X`009MAX_PRIVS`009= 63;
X
X`009PRV$V_SYSPRV`009= 28;
X
XTYPE
X`009MAP$PTR`009`009= `094FM$TYPE;
X
X`009BLOCK`009`009= ARRAY [0..511] OF CHAR;
X
X`009FILE$DATA`009= ARRAY [0..MAX_BLOCK] OF BLOCK;
X
X`009VMFH$TYPE`009= RECORD
X`009`009`009`009Link`009`009: `094VMFH$TYPE;
X`009`009`009`009Header`009`009: FH$TYPE;
X`009`009`009`009Exheader`009: `094VMFH$TYPE;
X`009`009`009`009Data`009`009: `094FILE$DATA;
X`009`009`009`009Data_Length`009: INTEGER;
X`009`009`009  END;
X
XVAR
X`009Filename_Desc`009: [VOLATILE] $DESCR;
X`009Filename`009: [VOLATILE] $STRING;
-+-+-+-+-+ End of part 1 +-+-+-+-+-


--
Regards.    Mike Scott       STL, London Road, Harlow, Essex  CM17 9NA, UK
scott@stl.stc.co.uk <or> ...uunet!mcvax!ukc!stl!scott <or>
PSI%234237100122::SCOTT        phone +44-279-29531 xtn 3133.

