1 /****************************************************************************
2 ** File: pipe-handler.h
3 ** Program: pipe-handler - an AmigaDOS handler for named pipes
5 ** Author: Ed Puckett qix@mit-oz
7 ** Copyright 1987 by EpAc Software. All Rights Reserved.
9 ** History: 05-Jan-87 Original Version (1.0)
10 ** 07-Feb-87 Added shared locks for individual pipes.
11 ** PIPEDATA structure modified to include
12 ** a FileLock structure.
13 ** 07-Feb-87 Added #if's forautomatic pipe naming "feature"
14 ** for pipes specified with empty names.
15 ** 12-Feb-87 Added ParentDir packet handling.
16 ** 12-Feb-87 Fixed bug in OpenPipe() and PipeLock():
17 ** they previously ignored the lock passed in
18 ** packet. Bug uncovered when pipes became
19 ** lockable, and thus assignable.
20 ** 26-Mar-87 Fixed bug in ClosePipe() in pipecreate.c: not
21 ** closing r/w mode properly (extraneous else).
22 ** 27-Mar-87 Added PipeDupLock() to pipedir.c and the case
23 ** for it in pipe-handler.c. This was missing
24 ** in the original version!
25 ** 28-Mar-87 Added code to handler() to remove ':' from
26 ** end of handler name. This caused problems
27 ** with Examine(); it expects no ending ':'.
32 /*---------------------------------------------------------------------------
35 ** DEBUG : add code to open a window for debugging information.
36 ** Messages are output as requests come in, etc. DEBUG is
37 ** active if defined at all.
39 ** (The following are active only if #defined nonzero)
41 ** CON_TAP_ONLY : only CON: pipe taps are allowed. The full CON:
42 ** specification must be given, though, like CON:0/0/100/100/z.
44 ** PIPEDIR : include code so that the handler looks like a directory.
45 ** This allows "Dir" and "List" to work, as well as "CD".
46 ** The functions in pipedir.c are unnecessary if false.
48 ** UPDATE_PIPEDATE : if PIPEDIR is true, then this controls whether or not
49 ** the handler's date is updated with each access to a pipe,
50 ** or is just left at its startup time.
52 ** AUTONAME : include code so that specifying a null pipe name causes
53 ** the handler to select a new, as yet unused, name.
54 ** Unfortunately, this causes inconsistent behaviour for Lock(),
55 ** since a null name indicates a lock is desired on the handler.
56 ** Thus locking PIPE: and opening PIPE: reference different
59 ** AUTONAME_STAR: Like AUTONAME, but use the special name 'PIPE:*' for the
60 ** automatic pipe name. This works around the Lock() issues
64 #define CON_TAP_ONLY 0
66 #define UPDATE_PIPEDATE 1
67 #define AUTONAME 0 /* Use PIPE: for auto names */
68 #define AUTONAME_STAR 1 /* Use PIPE:* for automatic names */
72 #define ALLOCMEM_FLAGS MEMF_PUBLIC
76 /*---------------------------------------------------------------------------
79 typedef struct pipedata
80 { PIPELISTNODE link
; /* for list handling */
81 char name
[PIPENAMELEN
]; /* the pipe's name */
82 PIPEBUF
*buf
; /* see pipebuf.c */
83 BYTE flags
; /* see values below */
84 PIPELISTHEADER readerlist
; /* list of waiting read requests */
85 PIPELISTHEADER writerlist
; /* list of waiting write requests */
86 BPTR tapfh
; /* file handle of tap, 0 if none */
88 ULONG lockct
; /* number of extant locks */
89 struct FileLock
*lock
; /* this pipe's lock - see note above */
90 struct DateStamp accessdate
; /* date last accessed */
95 #define OPEN_FOR_READ (1 << 0)
96 #define OPEN_FOR_WRITE (1 << 1) /* flags for pipedata struct */
100 /*---------------------------------------------------------------------------
101 ** PIPEKEYs are similar to file handles. Each successful pipe open request
102 ** has a PIPEKEY associated with it, which in turn refers to the pipe.
103 ** The filehandle returned to the client has the address of the PIPEKEY
104 ** stored in its Arg1 field, so that read, write and close packets will
105 ** identify the pipe and its mode of opening.
108 typedef struct pipekey
110 int openmode
; /* Type field of original open request */
111 IOTYPE iotype
; /* (somewhat redundant) see pipesched.h */
117 extern struct DeviceNode
*DevNode
;
118 extern struct MsgPort
*PipePort
;
119 extern char HandlerName
[];
121 extern PIPELISTHEADER pipelist
;
123 extern PIPELISTHEADER tapwaitlist
;
124 extern struct MsgPort
*TapReplyPort
;
127 extern struct DateStamp PipeDate
;
131 #define BPTRtoCptr(Bp) BADDR(Bp)
132 #define CptrtoBPTR(Cp) MKBADDR(Cp)
134 #define BPTRtoCptr(Bp) ((char *) ((ULONG) (Bp) << 2))
135 #define CptrtoBPTR(Cp) ((BPTR) ((ULONG) (Cp) >> 2))
138 #define QuickReplyPkt(pkt) PutMsg ((pkt)->dp_Port, (pkt)->dp_Link)
140 extern void handler ( /* StartPkt */ );
141 extern PIPEDATA
*FindPipe ( /* name */ );
145 /*---------------------
146 ** references to system
150 #include <proto/exec.h>
151 #include <proto/dos.h>
153 extern struct Library
*OpenLibrary ();
154 extern void CloseLibrary ();
155 extern struct Task
*FindTask ();
156 extern struct MsgPort
*CreatePort ();
157 extern ULONG
Wait ();
158 extern struct Message
*GetMsg ();
159 extern void PutMsg ();
160 extern BYTE
*AllocMem ();
161 extern void FreeMem ();
162 extern void CopyMem ();
164 extern struct MsgPort
*DeviceProc ();
168 extern struct DateStamp
*DateStamp ();
171 extern struct Library
*AbsExecBase
;
173 /*---------------------------------
174 ** these are new to the 1.2 release
177 #ifndef MODE_READWRITE
178 # define MODE_READWRITE 1004
179 #endif /* MODE_READWRITE */
182 # define ACTION_END 1007 /* not really new, just missing */
183 #endif /* ACTION_END */
185 #endif /* !__AROS__ */
187 #ifndef MODE_READONLY
188 # define MODE_READONLY MODE_OLDFILE
189 #endif /* MODE_READONLY */