/* -*-C-*- */

/*  magic-finger.c  */


/*
 * Author: Nikita Danilov <NikitaDanilov@yahoo.COM>
 * Keywords: dafs, vfs, open by inode, open by key
 *
 * Copyright (C) 2000 Namesys (Hans Reiser)
 *
 * This file is part of dafs.
 *
 * Dafs is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this software; see the file COPYING.  If not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 */


#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <fcntl.h>

typedef int __u32;
struct key {
  __u32 k_dir_id;
  __u32 k_objectid;
  __u32 k_offset;
  __u32 k_uniqueness;
};

#define _LINUX_REISER_FS_H
#define _LINUX_REISER_FS_SB

#include "da.h"

/* $Id$ */
static char cvsid[] = "@(#)$Id$";

int main( int argc, char **argv )
{
  if( argc < 2 )
	{
	  fprintf( stderr, 
			   "Usage:\n\n\t%s dafs_mount_point\n",
			   argv[ 0 ] );
	}
  else
	{
	  char input[ 4096 ];
	  char full_path[ 4096 ];
	  int i;
	  int mf;

	  sprintf( full_path, "%s/%s/%s",
			   argv[ 1 ], DA_ENTRY_POINT_NAME, DA_MAGIC_FINGER_NAME );
	  mf = open( full_path, O_RDONLY );
	  if( mf == -1 )
		{
		  fprintf( stderr, "Cannot open magic finger at `%s': ", full_path );
		  perror( "open" );
		  exit( 1 );
		}
	  while( !feof( stdin ) && 
			 ( fgets( input, sizeof input, stdin ) != NULL ) )
		{
		  int fd;

		  if( input[ strlen( input ) - 1 ] == '\n' )
			{
			  input[ strlen( input ) - 1 ] = '\0';
			}
		  fd = open( input, O_RDONLY );
		  if( fd == -1 )
			{
			  fprintf( stderr, "Cannot open `%s': ", input );
			  perror( "open" );
			}
		  else
			{
			  struct da_magic_finger_ioctl pad;

			  pad.u.fd = fd;
			  if( ioctl( mf, MAGIC_FINGER_BY_FD, &pad ) == -1 )
				{
				  perror( "ioctl" );
				}
			  else
				{
				  printf( "%8.8x %8.8x %8.8x %8.8x\n",
						  pad.key.k_dir_id,
						  pad.key.k_objectid,
						  pad.key.k_offset,
						  pad.key.k_uniqueness );
				}
			}
		  close( fd );
		}
	}
}

/*
 * $Log$
 */

