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