[OpenAFS-devel] openafs-devel@openafs.org

John_Morin@transarc.com John_Morin@transarc.com
Wed, 3 Jan 2001 13:57:51 -0500 (EST)


> What I wonder is - how hard would it be to access the contents of an AFS
> volume from a file server, without going through AFS itself - i.e. by direct
> file access - sortof a really fast 'vos dump' equivalent.
> 
> -- Nathan

Hi Nathan:

Not difficult. I use it as a programming exercise for new developers in
AFS. You simply read the V file from the /vicepx/ partition as the
starting point. 

I hope I get this right :-)

The V file contains the VolumeHeader structure as found in vol/volume.h.
The VolumeHeader.volumeInfo field contains the inode for the volumeInfo
struct. Likewise for the large vnode index file and the small vnode
index file. 

The volumeInfo inode points to an inode that describes the volume. It
contains the VolumeDiskData structure as found in the volume.h file. 

The index file is basically a list of AFS vnodes as defined in
vol/vnode.h (VnodeDiskObject). The large vnode index file contains
directory vnodes and the small vnode index file contains file vnodes.
They are both very similar except the large vnode index file contains
ACLs for directories so it is a little larger. Within the AFS Vnode is
the actual inode containing the data.

[BTW: An AFS VNode bears no resemblance to an the VFS VNode.]

To read an inode, I have the following program. Of course, this won't
work on some platforms. I have only run it on a Solaris machine.

--------------------------------------------
/* Sample code for reading an AFS inode (bare bones - no error checking)
 * To compile:
 *    cc -o readinode -I/usr/afsws/include -I/usr/include readinode.c
/lib/afs/libsys.a
 * Usage:
 *    readinode <partition> <inodenumber>
 *    ex: readinode /vicepa 1234
 * Author:
 *    John Morin.
 */

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>

extern iopen();

main(argc, argv)
  int  argc;
  char **argv;
{
  int code, fd;
  int inode;
  struct stat status;
  int size;
  char buf[1024];

  code = stat(argv[1],&status);
  if (code) {
     printf("Stat on %s failed: errno=%d\n", argv[1], errno);
     exit(1);
  }
  inode = atol(argv[2]);

  fd = iopen(status.st_dev, inode, O_RDONLY);

  printf("Device=0x%x   Inode=%u   fd=%d\n", status.st_dev, inode, fd);
  printf("-------------------------------\n");

  while (size = read(fd, buf, 1024)) {
     write(2, buf, size);
  }
}
--------------------------------------------

The first directory vnode is the root directory for the volume. Vos dump
just traverses the vnode index files dumping out the vnodes and the data.

Now if you want to understand the directory structures and be able to
parse the volume as a hierarchical tree, I suggest looking at
volser/restorevol.c. This contains the vos dump format and how to parse
it. The program actually restores a volume to non-AFS space.

	- John Morin.
	  Morin@Transarc.com