/* -*-C-*- */

/*  cv.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 "da.h"

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

/* externs */

/* forward declarations */

int cv_ioctl( struct inode * inode, struct file * filp, 
			  unsigned int cmd, unsigned long arg );

/* global data definitions */

static struct file_operations cv_file_ops = 
{
  ioctl: &cv_ioctl,
};

static struct inode_operations	cv_inode_ops = {
#if defined( LINUX_2_2 )
  default_file_ops: &cv_file_ops,
#endif
};

/* definitions */

int cv_ioctl( struct inode * inode, struct file * filp, 
			  unsigned int cmd, unsigned long arg )
{
  struct wait_queue **queue;

  TRACE;
  HASSERT( inode != NULL );

  queue = ( struct wait_queue ** ) HENTRY( inode -> u.generic_ip ) -> specific;
  switch( cmd )
	{
	case CV_SLEEP_ON:
	  {
		sleep_on( queue );
		break;
	  }
	case CV_SLEEP_ON_INT:
	  {
		interruptible_sleep_on( queue );
		break;
	  }
	case CV_WAKE_UP:
	  {
		wake_up( queue );
		break;
	  }
	case CV_BROADCAST:
	default:
	  return -ENOTTY;
	}
  TRACE;
  return 0;
}

struct da_entry *new_cv_entry( struct da_entry *parent, 
							   char *name, umode_t mode,
							   struct wait_queue **queue )
{
  struct da_entry *result;
  
  HASSERT( ! S_ISDIR( mode ) );
  
  result = new_entry( parent, name, mode | S_IFSOCK, 
					  &cv_inode_ops, &cv_file_ops );
  result -> specific = queue;
  return result;
}

/*
 * $Log$
 */

