/* -*-C-*- */

/*  cv-ctl.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 != 3 )
	{
	  fprintf( stderr, 
			   "Usage:\n\n\t%s dafs_mount_point [sleep|sleep_in|wake]\n",
			   argv[ 0 ] );
	}
  else
	{
	  char full_path[ 4096 ];
	  int ioctl_cmd;
	  int cv;

	  sprintf( full_path, "%s/%s/%s", 
			   argv[ 1 ], DA_ENTRY_POINT_NAME, DA_GLOBAL_WAIT_QUEUE );
	  cv = open( full_path, O_RDONLY );
	  if( cv == -1 )
		{
		  fprintf( stderr, "Cannot open cv-queue at `%s': ", full_path );
		  perror( "open" );
		  exit( 1 );
		}
	  if( !strcmp( argv[ 2 ], "sleep" ) )
		{
		  ioctl_cmd = CV_SLEEP_ON;
		}
	  else if( !strcmp( argv[ 2 ], "sleep_in" ) )
		{
		  ioctl_cmd = CV_SLEEP_ON_INT;
		}
	  else if( !strcmp( argv[ 2 ], "wake" ) )
		{
		  ioctl_cmd = CV_WAKE_UP;
		}
	  else
		{
		  fprintf( stderr, "Invalid command\n" );
		  exit( 1 );
		}
	  if( ioctl( cv, ioctl_cmd, 0 ) == -1 )
		{
		  perror( "cv-queue ioctl" );
		  exit( 1 );
		}
	  close( cv );
	}
}

/*
 * $Log$
 */

