/*
Copyright (c) 1993 Xerox Corporation.  All rights reserved.
*/
/*
$Id$

$Date$
 *
 * PCR - I/O global descriptor support on Unix File System.
 *
 * This deals mostly with wait for host descriptor ready.
 *
 * Not for client use.
 */


#ifndef	←←PCR←IOGblUFS←h
#define ←←PCR←IOGblUFS←h 1


#include <config/PCR←StdDefs.h>
#include <config/PCR←OS.h>
#include <th/PCR←Th.h>
#include <io/PCR←IOGbl.h>
#include <sys/stat.h>


#if PCR←OS←EWOULDBLOCK
#   define PCR←IOGblUFS←ShouldRetry(res) \
	( ((res) == PCR←ERes←FromErr(EWOULDBLOCK)) \
		|| ((res) == PCR←ERes←FromErr(EAGAIN))\
		|| ((res) == PCR←ERes←FromErr(EINTR)) )
#else
#   define PCR←IOGblUFS←ShouldRetry(res) \
	( ((res) == PCR←ERes←FromErr(EAGAIN)) \
		|| ((res) == PCR←ERes←FromErr(EINTR)) )
#endif

#define PCR←IOGblUFS←HOSTFD(gde) \
	((gde)->gde←data[0].gde←data←←long)

#define PCR←IOGblUFS←SPLITSIZE(gde) \
	((gde)->gde←data[1].gde←data←←long)

#define PCR←IOGblUFS←DEFAULTSPLITSIZE	(16*1024)

extern PCR←ERes
PCR←IOGblUFS←SetHostFDBlocking(int hd, PCR←Bool blocking);
/*
    Turn on/off host descriptor blocking behavior.
*/


extern PCR←ERes
PCR←IOGblUFS←InstallHostFD(
    PCR←IOGbl←DEPtr gde,
    int hd
);


extern PCR←ERes
PCR←IOGblUFS←InstallHostFDs(
    PCR←IOGbl←DEPtr gde0,
    PCR←IOGbl←DEPtr gde1,
    int hd0,
    int hd1
);
/*
    Create association between allocated gde's and host fd's.
    On failure, caller is responsible for closing hd's.
*/


#if PCR←OS←POLL

#   include <host/poll.h>

/* extern int poll(struct pollfd *fds, unsigned long nfds, int timeout); */

#else
    struct pollfd {
	int fd;
	short events;
	short revents;
    };

#   define POLLIN		01
#   define POLLPRI		02
#   define POLLOUT		04

#   define POLLERR		010
#   define POLLHUP		020
#   define POLLNVAL		040

#endif

typedef volatile struct PCR←IOGblUFS←WaitReadyInfoRep *
PCR←IOGblUFS←WaitReadyInfoPtr;

typedef struct PCR←IOGblUFS←WaitReadyInfoRep {

    PCR←IOGblUFS←WaitReadyInfoPtr ufswri←next;
    PCR←IOGblUFS←WaitReadyInfoPtr ufswri←prev;
    PCR←IOGbl←DEPtr ufswri←gde;
    PCR←Th←CV ufswri←cvAny;
    PCR←Th←CV ufswri←cvIn;
    PCR←Th←CV ufswri←cvOut;
    int ufswri←pollSlot;

} PCR←IOGblUFS←WaitReadyInfo;

extern volatile PCR←IOGblUFS←WaitReadyInfoPtr
PCR←IOGblUFS←waitReadyInfo;

extern volatile PCR←IOGblUFS←WaitReadyInfoPtr
PCR←IOGblUFS←waitReadyInfoSet;

extern struct pollfd *
PCR←IOGblUFS←pollfds;

extern volatile int
PCR←IOGblUFS←pollfdCnt;



extern PCR←ERes
PCR←IOGblUFS←WaitGDEReady(
    PCR←IOGbl←DEPtr gde, int events,
    const PCR←sigset←t *sigMask, PCR←Msec wakeup
);
/*
    Wait for gbl descriptor ready for one of given events,
      or for error on the descriptor.
*/


extern PCR←ERes
PCR←IOGblUFS←WaitHDReady(
    int hd, int events,
    const PCR←sigset←t *sigMask, PCR←Msec wakeup
);
/*
    Wait for host descriptor ready for one of given events,
      or for error on descriptor.
    Caller must be in sys critical section.
*/

extern void
PCR←IOGblUFS←NotifyHDReady(
    int hd
);
/*
    Caller must be in sys critical section.
*/

extern void
PCR←IOGblUFS←NotifyHDClosed(
    int hd
);
/*
    Caller must be in sys critical section.
*/


#endif /* ! ←←PCR←IOGblUFS←h */

/*
$Log$
*/