[comp.os.vms] .. and VMS .DIR file entries

robert@arizona.edu (Robert J. Drabek) (06/12/87)

In article <2405@usceast.UUCP>, still@usceast.UUCP (Bert Still) writes:
> 
> 	I have 2 (possibly) strange questions for netland. The first concerns
> the VAX-C run-time library. Listed in the VAX-C manual are references to some
> ... 
> 	The second question concerns VMS directories. I have perused the
> "orange manuals" for the last two weeks looking for something that describes
> the VMS directory files' organization. So far, by dumping the contents of
> ...

The following more or less works, but there are still some problems
and I am posting this hoping someone can fill in some of the blanks.

Yes, I know there are routines like lib$find_file() to do this work,
but I needed something faster.

The highest-version entries are
  ???
  ??? I don't recall exactly what these were
  ???
  1 byte containing name length
  name-length bytes containing the name
  sometimes a null byte
  2 bytes - version number
  3 bytes of unknown (to me) information
  3 null bytes

The lower-version entries are
  2 bytes - version number
  3 bytes of unknown (to me) information
  3 null bytes
  
/* -------------------------------------------------------------------- */

/* readdir
     Read the next directory entry and return its string name.
     I used fopen() and fclose() in place of opendir() and
     closedir().
*/
char *readdir(dp)
FILE *dp;
{
  int ch, i, len, ver;
  char *p;
  static char temp[8];
  static char dirname[MAXNAMLEN + 1];

  ch = fgetc(dp);
  ver = (fgetc(dp) << 8) + ch;
  if ((ch = fgetc(dp)) == EOF) return 0;
  if (ch == 0) {  /* higher-version entry */
    len = fgetc(dp);
    for (i = 0; i < len; i++) {
      ch = fgetc(dp);
      dirname[i] = isprint(ch) ? tolower(ch) : '?';
    }
    dirname[i] = ';';
    dirname[i + 1] = '\0';
    while ((ch = fgetc(dp)) == 0)
      ;
    ver = (fgetc(dp) << 8) + ch;
    sprintf(temp, "%d", ver);
    strcat(dirname, temp);
    fread(temp, 1, 6, dp); /* skip over unknown stuff */
    }
  else {  /* lower-version entry */
    fread(temp, 1, 5, dp); /* skip over unknown stuff */
    sprintf(temp, "%d", ver);
    p = strrchr(dirname, ';');
    strcpy(p + 1, temp);
  }

  return dirname;

}  /* readdir */

/* -------------------------------------------------------------------- */
-- 
Robert J. Drabek
Department of Computer Science
University of Arizona
Tucson, AZ  85721

rcb@rti.UUCP (06/15/87)

The following is the specification of a directory file format:

	2 bytes - Maximum number of versions (usually 32767)
	1 byte  - Null spacer
	1 byte  - Length of name
	n bytes - Name with possibly a null byte after to realign to a 
			word boundry.
	
	repeat the next section for each version of the file until the
	end of the record:
		
		2 bytes - version number
		6 bytes - FID number (3 2byte numbers)

Hope this helps.
-- 
					Random (Randy Buckland)
					Research Triangle Institute
					rcb@rti.rti.org [128.109.139.2]
					...!mcnc!rti-sel!rcb