From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX" 20-JUL-1992 10:06:15.29
To:	info-vax@kl.sri.com
CC:	
Subj:	Re: Ownership of indexf.sys file

In article <920719180647.20200eec@hartwick.edu>, BILL@HARTWICK.EDU (SYSTEM MANAGER) writes:
>Does any one know how to change the ownership of the Indexf.sys file?
>Somehow I using my account instead of the System account and therefore it does
>not have the System as owner but BILL instead. I am going to change the
>protection so owner cannot delete until i figure this one out. Any ideas?

I think you've only got two choices:
	1)  Backup the disk, initialize it, and use BACKUP to restore the files
	    to the disk.  I don't think you can use and IMAGE BACKUP to do
	    this, so you'll have to deal with multiple directory entries by
	    hand.
	2)  Edit the file headers (both primary and backup) for INDEXF.SYS in
	    INDEXF.SYS.  The VBN of the backup file header for INDEXF.SYS is
	    found in the 11th word of the second block of INDEXF.SYS.  The VBN
	    for the primary file header for INDEXF.SYS is computed by adding
	    the 12th word in the second block of INDEXF.SYS to the 17th word in
	    that block.  The UIC is specified in the 16th longword of the file
	    header.  The last word of the file header is a checksum which can
	    be computed by adding the values of the first 255 words of the
	    header in a longword, then taking the low order word of the result.
Here's a C function to compute that checksum, given that you've read the header
into an array:

unsigned short checksum(unsigned short *header)
{	union
	{	unsigned long longword;
		unsigned short word[2];
	} cksm;
	int i;

	cksm.longword = 0;
	for(i = 0; i < 255; ++i)
		cksm.longword += header[i];
	return cksm.word[0];
}

Or, in FORTRAN

	INTEGER*2 FUNCTION CHECKSUM(HEADER)
	INTEGER*2 HEADER, WORD(2), I
	INTEGER*4 LONGWORD
	EQUIVALENCE(LONGWORD, WORD(1))
	DO 10 I = 1, 255
10	LONGWORD = LONGWORD + HEADER(I)	
	CHECKSUM = WORD(1)
	RETURN
	END

If you DO edit the INDEXF.SYS file headers, I strongly suggest that you make an
image backup of your disk first, in case something goes wrong and that you test
the program that makes the new version of the header before putting it in
INDEXF.SYS.  To test the software:
	1)  Have it copy what it thinks are the INDEXF.SYS file headers to a
	    file with fixed-length, 512-byte records with no carriage control;
	2)  Make sure your program got the right blocks by issuing the command:
		$ DUMP/FILE new_file
	    This will give you a formatted description of the contents of the
	    header.
	3)  Have your software modify the two blocks in this file, changing the
	    UIC and fixing the checksum.
	4)  DUMP the file again to make sure that the modified headers are
	    still valid;
	5)  Have your program copy these blocks back into INDEXF.SYS.
Writing the software shouldn't be very difficult.  I'd use FORTRAN or DCL
myself, since it will allow you easily to get at the records you need to
modify and to update them.  The VAXC runtime library doesn't allow you to do
this very easily, though you could write most of your code in C and use FORTRAN
only for the I/O.  In case you decide to do things in C, here's some code that
defines the parts of a file header and the home block for a disk:

/******************************************************************************\
 * ODS2.H -- ODS-2.1 structure definitions				      *
\******************************************************************************/

/* Home Block -- VBN 2 of INDEXF.SYS                                          */

struct HOME_BLOCK {
	unsigned long  HBLB;		/* Home Block LBN		      */
	unsigned long  AHLB;		/* Alternate Home Block LBN	      */
	unsigned long  IHLB;		/* Backup Index File Header LBN	      */
	unsigned short VLEV;		/* Structure Level and Version	      */
	unsigned short SBCL;		/* Storage Bitmap Cluster Factor      */
	unsigned short HBVB;		/* Home Block VBN		      */
	unsigned short AHVB;		/* Backup Home Block VBN              */
	unsigned short IHVB;		/* Backup Index File Header VBN	      */
	unsigned short IBVB;		/* Index File Bitmap VBN	      */
	unsigned long  IBLB;		/* Index File Bitmap LBN	      */
	unsigned long  FMAX;		/* Maximum Number of Files	      */
	unsigned short IBSZ;		/* Index File Bitmap Size	      */
	unsigned short RSVF;		/* Number of Reserved Files	      */
	unsigned short DVTY;		/* Disk Device Type		      */
	unsigned short RVN;		/* Relative Volume Number	      */
	unsigned short NVOL;		/* Number of Volumes		      */
	unsigned short VCHA;		/* Volume Characteristics	      */
					/**************************************\
					 * need to define                     *
					 * CH.NDC, CH.NAT, CH.RCK, and CH.WCK *
					\**************************************/
	unsigned long  VOWN;		/* Volume Owner UIC		      */
	unsigned long  VSMX;		/* Volume Security Mask		      */
	unsigned short VPRO;		/* Volume Protection		      */
	unsigned short DFPR;		/* Default File Protection	      */
	unsigned short DRPC;		/* Default Record Protection	      */
	unsigned short CHK1;		/* First Checksum		      */
	unsigned long  VDAT[2];		/* Volume Creation Date		      */
	unsigned char  WISZ;		/* Default Window Size		      */
	unsigned char  LRUC;		/* Directory Pre-Access Limit	      */
	unsigned short FIEX;		/* Default File Extend		      */
	unsigned char  H_1[388];	/* (not used)			      */
	unsigned char  SNAM[12];	/* Structure Name		      */
	unsigned char  INDN[12];	/* Volume Name			      */
	unsigned char  INDO[12];	/* Volume Owner			      */
	unsigned char  INDF[12];	/* Format Type			      */
	unsigned char  H_2[2];		/* (not used)			      */
	unsigned short CHK2;		/* Second Checksum	     	      */
};

/* File Header Header							      */
struct FILE_HEADER_HEADER {
	unsigned char  IDOF;		/* Ident Area Offset	 	      */
	unsigned char  MPOF;		/* Map Area Offset		      */
	unsigned char  ACOF;		/* Access Control List Offset	      */
	unsigned char  RSOF;		/* Reserved Area Offset		      */
	unsigned short FSEG;		/* Extension Segment Number	      */
	unsigned short FLEV;		/* Structure Level and Version	      */
	unsigned short FNUM;		/* File Number			      */
	unsigned short FSEQ;		/* File Sequence Number		      */
	unsigned short FRVN;		/* Relative Volume Number	      */
	unsigned short EFNU;		/* Extension File Number	      */
	unsigned short EFSQ;		/* Extension File Sequence Number     */
	unsigned short ERVN;		/* Extension Relative Volume Number   */
	unsigned char  UFAT[32];	/* User File Attributes		      */
	variant_union {
	    unsigned long  FCHA;	/* File Characteristics 	      */
	    variant_struct {
		unsigned char UCHA;	/* User Controlled Char.	      */
		unsigned char SCHA;	/* System Controlled Char.	      */
		unsigned char  F_1[2];	/* not named			      */
	    } F_2;
	} F_3;
	unsigned char  F_4[2];		/* not used			      */
	unsigned char  USE;   		/* Map Words in Use		      */
	unsigned char  PRIV;		/* Accessor Privilege Level	      */
	variant_union {
	    unsigned long  FOWN;	/* File Owner UIC		      */
	    variant_struct {
		unsigned short PROG;	/* Programmer (Member) No.	      */
		unsigned short PROJ;	/* Project (Group) Number	      */
	    } F_5;
	} F_6;
	unsigned short FPRO;		/* File Protection Code		      */
					/**************************************\
					 * Need to define		      *
					 * FP.RDV, FP.WRV, FP.EXE, and FP.DEL *
					\**************************************/
	unsigned short RPRO;		/* Record Protection Code	      */
					/**************************************\
					 * Need to define		      *
					 * RP.RDV, RP.WRV, RP.EXE, and RP.DEL *
					\**************************************/
	unsigned char  F_7[4];		/* Not Used			      */
	unsigned long  SEMK;		/* Security Mask		      */
};
#define HDHD sizeof(struct FILE_HEADER_HEADER)

/* File Header Ident Area						      */

struct FILE_HEADER_IDENT {
	unsigned char  FNAM[20];	/* File Name			      */
	unsigned short RVNO;		/* Revision Number		      */
	unsigned long  CRDT[2];		/* Creation Date and Time	      */
	unsigned long  RVDT[2];		/* Revision Date and Time	      */
	unsigned long  EXDT[2];		/* Expiration Date and Time	      */
	unsigned long  BKDT[2];		/* Backup Date and Time		      */
	unsigned char  ULAB[80];	/* User Label			      */
};
#define IDHD sizeof(struct FILE_HEADER_IDENT)

/* File Header								      */

struct FILE_HEADER {
	struct FILE_HEADER_HEADER H;	/* Header Area			      */
	char  FH_1[510-HDHD];		/* Ident, Map, ACL and Reserved Areas */
	unsigned short CKSM;		/* Block Checksum		      */
};

/* Retrieval pointers							      */

struct RTR_PTR_00 {
	unsigned PLACEMENT  : 14;	/* Placement Control		      */
	unsigned FORMAT     :  2;	/* Retrieval Pointer Format	      */
};

struct RTR_PTR_01 {
	unsigned char   COUNT_01;	/* Count			      */
	unsigned HI_LBN_01  :  6;	/* High-Order Part of LBN	      */
	unsigned FORMAT     :  2;	/* Retrieval Pointer Format	      */
	unsigned short LO_LBN_01;	/* Low-Order Part of LBN	      */
};

struct RTR_PTR_10 {
	unsigned COUNT_10   : 14;	/* Count			      */
	unsigned FORMAT     :  2;	/* Retrieval Pointer Format	      */
	unsigned long     LBN_10;	/* Logical Block Number		      */
};

struct RTR_PTR_11 {
	unsigned HI_CNT_11  : 14;	/* High-Order Part of Count	      */
	unsigned FORMAT     :  2;	/* Retrieval Pointer Format	      */
	unsigned short LO_CNT_11;	/* Low-Order Part of Count	      */
	unsigned long     LBN_11;	/* Logical Block Number		      */
};

--------------------------------------------------------------------------------
Carl J Lydick | INTERnet: CARL@SOL1.GPS.CALTECH.EDU | NSI/HEPnet: SOL1::CARL

Disclaimer:  Hey, I understand VAXen and VMS.  That's what I get paid for.  My
understanding of astronomy is purely at the amateur level (or below).  So
unless what I'm saying is directly related to VAX/VMS, don't hold me or my
organization responsible for it.  If it IS related to VAX/VMS, you can try to
hold me responsible for it, but my organization had nothing to do with it.

