blob: ddc3e093cd043547e6d4ef5ee688a2a879fa96d4 [file] [log] [blame]
rsc39405062005-01-13 04:56:07 +00001.TH 9P-FID 3
2.SH NAME
3Fid, Fidpool, allocfidpool, freefidpool, allocfid, closefid, lookupfid, removefid,
4Req, Reqpool, allocreqpool, freereqpool, allocreq, closereq, lookupreq, removereq \- 9P fid, request tracking
5.SH SYNOPSIS
6.ft L
7.nf
8#include <u.h>
9#include <libc.h>
10#include <fcall.h>
11#include <thread.h>
12#include <9p.h>
13.fi
14.PP
15.ft L
16.nf
17.ta \w'\fL 'u +\w'\fLulong 'u
18typedef struct Fid
19{
20 ulong fid;
21 char omode; /* -1 if not open */
22 char *uid;
23 Qid qid;
24 File *file;
25 void *aux;
26 \fI...\fP
27} Fid;
28.fi
29.PP
30.ft L
31.nf
32.ta \w'\fL 'u +\w'\fLulong 'u
33typedef struct Req
34{
35 ulong tag;
36 Fcall ifcall;
37 Fcall ofcall;
38 Req *oldreq;
39 void *aux;
40 \fI...\fP
41} Req;
42.fi
43.PP
44.ft L
45.nf
46.ta \w'\fLFidpool* 'u
47Fidpool* allocfidpool(void (*destroy)(Fid*))
48void freefidpool(Fidpool *p)
49Fid* allocfid(Fidpool *p, ulong fid)
50Fid* lookupfid(Fidpool *p, ulong fid)
51void closefid(Fid *f)
52void removefid(Fid *f)
53.fi
54.PP
55.ft L
56.nf
57.ta \w'\fLReqpool* 'u
58Reqpool* allocreqpool(void (*destroy)(Req*))
59void freereqpool(Reqpool *p)
60Req* allocreq(Reqpool *p, ulong tag)
61Req* lookupreq(Reqpool *p, ulong tag)
62void closereq(Req *f)
63void removereq(Req *r)
64.fi
65.SH DESCRIPTION
66These routines provide management of
67.B Fid
68and
69.B Req
70structures from
71.BR Fidpool s
72and
73.BR Reqpool s.
74They are primarily used by the 9P server loop
75described in
76.IR 9p (3).
77.PP
78.B Fid
79structures are intended to represent
80active fids in a 9P connection, as
81.B Chan
82structures do in the Plan 9 kernel.
83The
84.B fid
85element is the integer fid used in the 9P
86connection.
87.B Omode
88is the mode under which the fid was opened, or
89.B -1
90if this fid has not been opened yet.
91Note that in addition to the values
92.BR OREAD ,
93.BR OWRITE ,
94and
95.BR ORDWR ,
96.B omode
97can contain the various flags permissible in
98an open call.
99To ignore the flags, use
100.BR omode&OMASK .
101.B Omode
102should not be changed by the client.
103The fid derives from a successful authentication by
104.BR uid .
105.B Qid
106contains the qid returned in the last successful
107.B walk
108or
109.B create
110transaction involving the fid.
111In a file tree-based server, the
112.BR Fid 's
113.B file
114element points at a
115.B File
116structure
117(see
118.IR 9p-file (3))
119corresponding to the fid.
120The
121.B aux
122member is intended for use by the
123client to hold information specific to a particular
124.BR Fid .
125With the exception of
126.BR aux ,
127these elements should be treated
128as read-only by the client.
129.PP
130.I Allocfidpool
131creates a new
132.BR Fidpool .
133.I Freefidpool
134destroys such a pool.
135.I Allocfid
136returns a new
137.B Fid
138whose fid number is
139.IR fid .
140There must not already be an extant
141.B Fid
142with that number in the pool.
143Once a
144.B Fid
145has been allocated, it can be looked up by
146fid number using
147.IR lookupfid .
148.BR Fid s
149are reference counted: both
150.I allocfid
151and
152.I lookupfid
153increment the reference count on the
154.B Fid
155structure before
156returning.
157When a reference to a
158.B Fid
159is no longer needed,
160.I closefid
161should be called to note the destruction of the reference.
162When the last reference to a
163.B Fid
164is removed, if
165.I destroy
166(supplied when creating the fid pool)
167is not zero, it is called with the
168.B Fid
169as a parameter.
170It should perform whatever cleanup is necessary
171regarding the
172.B aux
173element.
174.I Removefid
175is equivalent to
176.I closefid
177but also removes the
178.B Fid
179from the pool.
180Note that due to lingering references,
181the return of
182.I removefid
183may not mean that
184.I destroy
185has been called.
186.PP
187.IR Allocreqpool ,
188.IR freereqpool ,
189.IR allocreq ,
190.IR lookupreq ,
191.IR closereq ,
192and
193.I removereq
194are analogous but
195operate on
196.BR Reqpool s
197and
198.B Req
199structures.
200.SH SOURCE
201.B \*9/src/lib9p
202.SH SEE ALSO
203.IR 9p (3),
204.IR 9p-file (3)