9pfid 3.6 KB

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