rsc | be7cbb4 | 2005-07-12 15:24:18 +0000 | [diff] [blame^] | 1 | .TH VENTI-FILE 3 |
| 2 | .SH NAME |
| 3 | VtFile, |
| 4 | vtfileopenroot, |
| 5 | vtfilecreateroot, |
| 6 | vtfileopen, |
| 7 | vtfilecreate, |
| 8 | vtfileblock, |
| 9 | vtfileread, |
| 10 | vtfilewrite, |
| 11 | vtfileflush, |
| 12 | vtfileincref, |
| 13 | vtfileclose, |
| 14 | vtfilegetentry, |
| 15 | vtfilesetentry, |
| 16 | vtfileblockscore, |
| 17 | vtfilegetdirsize, |
| 18 | vtfilesetdirsize, |
| 19 | vtfileunlock, |
| 20 | vtfilelock, |
| 21 | vtfilelock2, |
| 22 | vtfileflushbefore, |
| 23 | vtfiletruncate, |
| 24 | vtfilegetsize, |
| 25 | vtfilesetsize, |
| 26 | vtfileremove \- Venti files |
| 27 | .SH SYNOPSIS |
| 28 | .ta +\w'\fLVtBlock* 'u |
| 29 | .PP |
| 30 | .B |
| 31 | VtFile* vtfilecreateroot(VtCache *c, int psize, int dsize, int type); |
| 32 | .PP |
| 33 | .B |
| 34 | VtFile* vtfileopenroot(VtCache *c, VtEntry *e); |
| 35 | .PP |
| 36 | .B |
| 37 | VtFile* vtfileopen(VtFile *f, u32int n, int mode); |
| 38 | .PP |
| 39 | .B |
| 40 | VtFile* vtfilecreate(VtFile *f, int psize, int dsize, int dir); |
| 41 | .PP |
| 42 | .B |
| 43 | void vtfileincref(VtFile *f); |
| 44 | .PP |
| 45 | .B |
| 46 | void vtfileclose(VtFile *f); |
| 47 | .PP |
| 48 | .B |
| 49 | int vtfileremove(VtFile *f); |
| 50 | .PP |
| 51 | .B |
| 52 | VtBlock* vtfileblock(VtFile *f, u32int n, int mode); |
| 53 | .PP |
| 54 | .B |
| 55 | long vtfileread(VtFile *f, void *buf, long n, vlong offset); |
| 56 | .PP |
| 57 | .B |
| 58 | long vtfilewrite(VtFile *f, void *buf, long n, vlong offset); |
| 59 | .PP |
| 60 | .B |
| 61 | int vtfileflush(VtFile *f); |
| 62 | .PP |
| 63 | .B |
| 64 | int vtfileflushbefore(VtFile *f, vlong offset); |
| 65 | .PP |
| 66 | .B |
| 67 | int vtfiletruncate(VtFile *f); |
| 68 | .PP |
| 69 | .B |
| 70 | uvlong vtfilegetsize(VtFile *f); |
| 71 | .PP |
| 72 | .B |
| 73 | int vtfilesetsize(VtFile *f, vlong size); |
| 74 | .PP |
| 75 | .B |
| 76 | u32int vtfilegetdirsize(VtFile *f); |
| 77 | .PP |
| 78 | .B |
| 79 | int vtfilesetdirsize(VtFile *f, u32int size); |
| 80 | .PP |
| 81 | .B |
| 82 | int vtfilegetentry(VtFile *f, VtEntry *e); |
| 83 | .PP |
| 84 | .B |
| 85 | int vtfilesetentry(VtFile *f, VtEntry *e); |
| 86 | .PP |
| 87 | .B |
| 88 | int vtfileblockscore(VtFile *f, u32int n, uchar score[VtScoreSize]); |
| 89 | .PP |
| 90 | .B |
| 91 | int vtfilelock(VtFile *f, int mode); |
| 92 | .PP |
| 93 | .B |
| 94 | int vtfilelock2(VtFile *f, VtFile *f, int mode); |
| 95 | .PP |
| 96 | .B |
| 97 | void vtfileunlock(VtFile *f); |
| 98 | .SH DESCRIPTION |
| 99 | These routines provide a simple interface to create and |
| 100 | manipulate Venti file trees (see |
| 101 | .IR venti (1)). |
| 102 | .PP |
| 103 | .I Vtfilecreateroot |
| 104 | creates a new Venti file. |
| 105 | .I Btype |
| 106 | must be either |
| 107 | .B VtDataType |
| 108 | or |
| 109 | .BR VtDirType , |
| 110 | specifying a data or directory file. |
| 111 | .I Dsize |
| 112 | is the block size to use for leaf (data or directory) blocks in the hash tree; |
| 113 | .I psize |
| 114 | is the block size to use for intermediate (pointer) blocks. |
| 115 | .PP |
| 116 | .I Vtfileopenroot |
| 117 | opens an existing Venti file described by |
| 118 | .IR e . |
| 119 | .PP |
| 120 | .I Vtfileopen |
| 121 | opens the Venti file described by the |
| 122 | .IR n th |
| 123 | entry in the directory |
| 124 | .IR f . |
| 125 | .I Mode |
| 126 | should be one of |
| 127 | .IR VtOREAD , |
| 128 | .IR VtOWRITE , |
| 129 | or |
| 130 | .IR VtORDWR , |
| 131 | indicating how the returned file is to be used. |
| 132 | The |
| 133 | .IR VtOWRITE |
| 134 | and |
| 135 | .IR VtORDWR |
| 136 | modes can only be used if |
| 137 | .IR f |
| 138 | is open with mode |
| 139 | .IR VtORDWR . |
| 140 | .PP |
| 141 | .I Vtfilecreate |
| 142 | creates a new file in the directory |
| 143 | .I f |
| 144 | with block type |
| 145 | .I type |
| 146 | and block sizes |
| 147 | .I dsize |
| 148 | and |
| 149 | .I psize |
| 150 | (see |
| 151 | .I vtfilecreateroot |
| 152 | above). |
| 153 | .PP |
| 154 | Each file has an associated reference count |
| 155 | and holds a reference to its parent in the file tree. |
| 156 | .I Vtfileincref |
| 157 | increments this reference count. |
| 158 | .I Vtfileclose |
| 159 | decrements the reference count. |
| 160 | If there are no other references, |
| 161 | .I vtfileclose |
| 162 | releases the reference to |
| 163 | .IR f 's |
| 164 | parent and then frees the in-memory structure |
| 165 | .IR f . |
| 166 | The data stored in |
| 167 | .I f |
| 168 | is still accessible by reopening it. |
| 169 | .PP |
| 170 | .I Vtfileremove |
| 171 | removes the file |
| 172 | .I f |
| 173 | from its parent directory. |
| 174 | It also acts as |
| 175 | .IR vtfileclose , |
| 176 | releasing the reference to |
| 177 | .I f |
| 178 | and potentially freeing the structure. |
| 179 | .PP |
| 180 | .I Vtfileblock |
| 181 | returns the |
| 182 | .IR n th |
| 183 | block in the file |
| 184 | .IR f . |
| 185 | If there are not |
| 186 | .I n |
| 187 | blocks in the file and |
| 188 | .I mode |
| 189 | is |
| 190 | .BR VtOREAD , |
| 191 | .I vtfileblock |
| 192 | returns nil. |
| 193 | If the mode is |
| 194 | .B VtOWRITE |
| 195 | or |
| 196 | .BR VtORDWR , |
| 197 | .I vtfileblock |
| 198 | grows the file as needed and then returns the block. |
| 199 | .PP |
| 200 | .I Vtfileread |
| 201 | reads at most |
| 202 | .I n |
| 203 | bytes at offset |
| 204 | .I offset |
| 205 | from |
| 206 | .I f |
| 207 | into memory at |
| 208 | .IR buf . |
| 209 | It returns the number of bytes read. |
| 210 | .PP |
| 211 | .I Vtfilewrite |
| 212 | writes the |
| 213 | .I n |
| 214 | bytes in memory at |
| 215 | .I buf |
| 216 | into the file |
| 217 | .I f |
| 218 | at offset |
| 219 | .IR n . |
| 220 | It returns the number of bytes written, |
| 221 | or \-1 on error. |
| 222 | Writing fewer bytes than requested will only happen |
| 223 | if an error is encountered. |
| 224 | .PP |
| 225 | .I Vtfilewrite |
| 226 | writes to an in-memory copy of the data blocks |
| 227 | (see |
| 228 | .IR venti-cache (3)) |
| 229 | instead of writing directly to Venti. |
| 230 | .I Vtfileflush |
| 231 | writes all copied blocks associated with |
| 232 | .I f |
| 233 | to the Venti server. |
| 234 | .I Vtfileflushbefore |
| 235 | flushes only those blocks corresponding to data in the file before |
| 236 | byte |
| 237 | .IR offset . |
| 238 | Loops that |
| 239 | .I vtfilewrite |
| 240 | should call |
| 241 | .I vtfileflushbefore |
| 242 | regularly to avoid filling the block cache with dirty blocks. |
| 243 | .PP |
| 244 | .I Vtfiletruncate |
| 245 | changes the file |
| 246 | .I f |
| 247 | to have zero length. |
| 248 | .PP |
| 249 | .I Vtfilegetsize |
| 250 | returns the length (in bytes) of file |
| 251 | .IR f . |
| 252 | .PP |
| 253 | .I Vtfilesetsize |
| 254 | sets the length (in bytes) of file |
| 255 | .IR f . |
| 256 | .PP |
| 257 | .I Vtfilegetdirsize |
| 258 | returns the length (in directory entries) |
| 259 | of the directory |
| 260 | .IR f . |
| 261 | .PP |
| 262 | .I Vtfilesetdirsize |
| 263 | sets the length (in directory entries) |
| 264 | of the directory |
| 265 | .IR f . |
| 266 | .PP |
| 267 | .I Vtfilegetentry |
| 268 | fills |
| 269 | .I e |
| 270 | with an entry that can be passed to |
| 271 | .IR vtfileopenroot |
| 272 | to reopen |
| 273 | .I f |
| 274 | at a later time. |
| 275 | .PP |
| 276 | .I Vtfilesetentry |
| 277 | sets the entry associated with |
| 278 | .I f |
| 279 | to be |
| 280 | .IR e . |
| 281 | .PP |
| 282 | .I Vtfileblockscore |
| 283 | returns in |
| 284 | .I score |
| 285 | the score of the |
| 286 | .I n th |
| 287 | block in the file |
| 288 | .IR f . |
| 289 | .PP |
| 290 | Venti files are locked and unlocked |
| 291 | via |
| 292 | .I vtfilelock |
| 293 | and |
| 294 | .I vtfileunlock |
| 295 | to moderate concurrent access. |
| 296 | Only one thread at a time\(emthe one that has the file locked\(emcan |
| 297 | read or modify the file. |
| 298 | The functions that return files |
| 299 | .RI ( vtfilecreateroot , |
| 300 | .IR vtfileopenroot , |
| 301 | .IR vtfilecreate , |
| 302 | and |
| 303 | .IR vtfileopen ) |
| 304 | return them unlocked. |
| 305 | When files are passed to any of the functions documented in |
| 306 | this manual page, it is the caller's responsibility to ensure that |
| 307 | they are already locked. |
| 308 | .PP |
| 309 | Internally, a file is locked by locking the |
| 310 | block that contains its directory entry. |
| 311 | When two files in the same |
| 312 | directory both need to be locked, |
| 313 | .I vtfilelock2 |
| 314 | must be used. |
| 315 | It locks both its arguments, taking special care |
| 316 | not to deadlock if their entries are stored |
| 317 | in the same directory block. |
| 318 | .SH SOURCE |
| 319 | .B \*9/src/libventi/file.c |
| 320 | .SH SEE ALSO |
| 321 | .IR venti (1), |
| 322 | .IR venti-cache (3), |
| 323 | .IR venti-conn (3), |
| 324 | .IR venti-client (3) |