00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _VNODE_H_
00014 #define _VNODE_H_
00015
00016 #include <posix/sys/types.h>
00017 #include <posix/sys/uio.h>
00018 #include <posix/sys/queue.h>
00019
00020
00021 #ifdef __cplusplus
00022 extern "C" {
00023 #endif
00024
00025 typedef uint32_t inode_t;
00026 typedef int32_t lbno_t;
00027 typedef int32_t bno_t;
00028 typedef uint16_t segno_t;
00029
00030
00031
00032
00033
00034 struct indir {
00035 bno_t in_lbn;
00036 int in_off;
00037 int in_exists;
00038 };
00039
00040 struct componentname;
00041 typedef int32_t doff_t;
00042
00043
00044
00045
00046
00047
00048 typedef struct BufferCacheEntryType {
00049 TAILQ_ENTRY(BufferCacheEntryType) b_freelist;
00050
00051 int b_freelistindex;
00052 struct VnodeType *b_vnode;
00053 lbno_t b_lbn;
00054 bno_t b_bno;
00055 void *b_data;
00056 volatile uint32_t b_flags;
00057 status_t b_lastOpStatus;
00058 LIST_ENTRY(BufferCacheEntryType) b_vnodeLink;
00059 } BufferCacheEntryType;
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 #define NUM_BQUEUES 4
00072 #define BQ_LOCKED 0
00073 #define BQ_LRU 1
00074 #define BQ_AGE 2
00075 #define BQ_SHARED 3
00076
00077 #define B_DATASIZE 4096
00078 #define B_DATASIZE_512 512
00079
00080
00081
00082 #define B_AGE 0x00000001
00083 #define B_ASYNC 0x00000004
00084 #define B_BAD 0x00000008
00085 #define B_BUSY 0x00000010
00086 #define B_SCANNED 0x00000020
00087 #define B_CALL 0x00000040
00088 #define B_DELWRI 0x00000080
00089 #define B_DIRTY 0x00000100
00090 #define B_DONE 0x00000200
00091 #define B_EINTR 0x00000400
00092 #define B_ERROR 0x00000800
00093 #define B_GATHERED 0x00001000
00094 #define B_INVAL 0x00002000
00095 #define B_LOCKED 0x00004000
00096 #define B_NOCACHE 0x00008000
00097 #define B_CACHE 0x00020000
00098 #define B_PHYS 0x00040000
00099 #define B_RAW 0x00080000
00100 #define B_READ 0x00100000
00101 #define B_TAPE 0x00200000
00102 #define B_WANTED 0x00800000
00103 #define B_WRITE 0x01000000
00104 #define B_DATA_512 0x02000000
00105 #define B_VFLUSH 0x04000000
00106
00107 #define B_PAGE_SHARED 0x08000000
00108 #define B_PAGE_WRITE 0x10000000
00109 #define B_DEFER_READ 0x20000000
00110 #define B_BNO_VALID 0x40000000
00111 #define B_PAGE_LOCKED 0x80000000
00112
00113
00114
00115 typedef status_t op_read_vnode(void *mount, inode_t vnid, char r, struct VnodeType **node);
00116 typedef status_t op_write_vnode(struct VnodeType *vnodeP, char flags);
00117 typedef status_t op_remove_vnode(struct VnodeType *vnodeP, char r);
00118 typedef status_t op_secure_vnode(struct VnodeType *vnodeP);
00119
00120 typedef status_t op_allocate_vnode(struct VnodeType *parentVnodeP, struct VnodeType **resultVnodePP);
00121 typedef status_t op_lookup(struct VnodeType *dirVnodeP, struct VnodeType **resultVnodePP, struct componentname *cnp);
00122
00123 typedef status_t op_check_access(struct VnodeType *vnodeP, int mode, uint32_t callerUID);
00124
00125 typedef status_t op_create(struct VnodeType *parentVnodeP, struct VnodeType **resultVnodePP, struct componentname *cnp);
00126 typedef status_t op_mkdir(struct VnodeType *parentDirVnodeP, struct VnodeType **newDirVnodePP, struct componentname *cnp);
00127 typedef status_t op_symlink(void *dir, const char *name, const char *path);
00128 typedef status_t op_link(void *dir, const char *name, struct VnodeType *vnodeP);
00129
00130 typedef status_t op_rename(struct VnodeType *oldDirVnodeP, struct VnodeType *oldVnodeP, struct componentname *oldcnp,
00131 struct VnodeType *newDirVnodeP, struct VnodeType *newVnodeP, struct componentname *newcnp);
00132 typedef status_t op_unlink(struct VnodeType *parentDirVnodeP, struct VnodeType *vnodeP, struct componentname *cnp);
00133
00134 typedef status_t op_rmdir(struct VnodeType *parentDirVnodeP, struct VnodeType *vnodeP, struct componentname *cnp);
00135
00136 typedef status_t op_readlink(struct VnodeType *vnodeP, char *buf, size_t *bufsize);
00137
00138 typedef status_t op_opendir(struct VnodeType *vnodeP, void **cookie);
00139 typedef status_t op_closedir(struct VnodeType *vnodeP, void *cookie);
00140 typedef status_t op_rewinddir(struct VnodeType *vnodeP, void *cookie);
00141 struct DirEntry;
00142 typedef status_t op_readdir(struct VnodeType *vnodeP, void *cookie, long *num, struct DirEntry *buf, size_t bufsize);
00143 typedef status_t op_getbufferforoffset(struct VnodeType *vnodeP, off_t offset, BufferCacheEntryType **bufCachePP);
00144 typedef status_t op_bufferallocate(struct VnodeType *vnodeP, off_t offset, int32_t size, uint32_t flags, BufferCacheEntryType **bufCachePP);
00145 typedef status_t op_getphysicalblockaddr(struct VnodeType *vnodeP, lbno_t logicalBlockNum, bno_t *physicalBlockNumP, int *numP);
00146
00147 typedef status_t op_open(struct VnodeType *vnodeP, int omode);
00148 typedef status_t op_close(struct VnodeType *vnodeP, void *cookie);
00149 typedef status_t op_free_cookie(struct VnodeType *vnodeP, void *cookie);
00150 typedef status_t op_read(struct VnodeType *vnodeP, off_t pos, uint8_t *buf, size_t *len);
00151 typedef status_t op_write(struct VnodeType *vnodeP, off_t pos, const uint8_t *buf, size_t *len);
00152 typedef status_t op_readv(struct VnodeType *vnodeP, void *cookie, off_t pos, const struct iovec *vec,
00153 size_t count, size_t *len);
00154 typedef status_t op_writev(struct VnodeType *vnodeP, void *cookie, off_t pos, const struct iovec *vec,
00155 size_t count, size_t *len);
00156 typedef status_t op_readbuffers(struct VnodeType *vnode, size_t count, BufferCacheEntryType **bufCacheP);
00157 typedef status_t op_writebuffers(struct VnodeType *vnode, size_t count, BufferCacheEntryType **bufCacheP);
00158
00159 typedef status_t op_ioctl(struct VnodeType *vnodeP, void *cookie, int cmd, void *buf, size_t len);
00160
00161 typedef status_t op_truncate(struct VnodeType *vnodeP, off_t endOffset, uint32_t flags);
00162 typedef status_t op_setflags(struct VnodeType *vnodeP, void *cookie, int flags);
00163
00164
00165
00166 typedef status_t op_update(struct VnodeType *vnodeP, time_t accessTime, time_t modifyTime, int flags);
00167
00168 typedef status_t op_rstat(struct VnodeType *vnodeP, struct stat *);
00169 typedef status_t op_wstat(struct VnodeType *vnodeP, struct stat *, long mask);
00170 typedef status_t op_fsync(struct VnodeType *vnodeP);
00171
00172 typedef status_t op_initialize(const char *devname, void *parms, size_t len);
00173 typedef status_t op_reclaim(struct VnodeType *vnodeP);
00174 typedef status_t op_mount(int nsid, const char *devname, ulong flags,
00175 void *parms, size_t len, void **data, inode_t *vnid);
00176 typedef status_t op_unmount(struct VnodeType *vnodeP);
00177 typedef status_t op_sync(struct VnodeType *vnodeP);
00178 struct fs_info;
00179 typedef status_t op_rfsstat(struct VnodeType *vnodeP, struct fs_info *);
00180 typedef status_t op_wfsstat(struct VnodeType *vnodeP, struct fs_info *, long mask);
00181
00182 typedef status_t op_write_attr(struct VnodeType *vnodeP, const char *name, int type,
00183 const void *buf, size_t *len, off_t pos);
00184 typedef status_t op_read_attr(struct VnodeType *vnodeP, const char *name, int type,
00185 void *buf, size_t *len, off_t pos);
00186
00187 typedef void op_wake_vnode(struct VnodeType *vnodeP, void *cookie, uint pmcookietype);
00188 typedef void op_suspend_vnode(struct VnodeType *vnodeP, void *cookie, uint pmcookietype);
00189
00190 typedef struct vnode_ops {
00191 op_read_vnode (*read_vnode);
00192 op_write_vnode (*write_vnode);
00193 op_remove_vnode (*remove_vnode);
00194 op_secure_vnode (*secure_vnode);
00195 op_allocate_vnode (*allocate_vnode);
00196 op_lookup (*lookup);
00197 op_check_access (*check_access);
00198 op_create (*create);
00199 op_mkdir (*mkdir);
00200 op_symlink (*symlink);
00201 op_link (*link);
00202 op_rename (*rename);
00203 op_unlink (*unlink);
00204 op_rmdir (*rmdir);
00205 op_readlink (*readlink);
00206 op_opendir (*opendir);
00207 op_closedir (*closedir);
00208 op_rewinddir (*rewinddir);
00209 op_readdir (*readdir);
00210 op_getbufferforoffset (*getbufferforoffset);
00211 op_bufferallocate (*bufferallocate);
00212 op_getphysicalblockaddr (*getphysicalblockaddr);
00213 op_open (*open);
00214 op_close (*close);
00215 op_read (*read);
00216 op_write (*write);
00217 op_readv (*readv);
00218 op_writev (*writev);
00219 op_readbuffers (*readbuffers);
00220 op_writebuffers (*writebuffers);
00221 op_ioctl (*ioctl);
00222 op_truncate (*truncate);
00223 op_setflags (*setflags);
00224 op_update (*update);
00225 op_rstat (*rstat);
00226 op_wstat (*wstat);
00227 op_fsync (*fsync);
00228 op_initialize (*initialize);
00229 op_reclaim (*reclaim);
00230 op_mount (*mount);
00231 op_unmount (*unmount);
00232 op_sync (*sync);
00233 op_rfsstat (*rfsstat);
00234 op_wfsstat (*wfsstat);
00235 op_write_attr (*write_attr);
00236 op_read_attr (*read_attr);
00237 op_wake_vnode (*wake_vnode);
00238 op_suspend_vnode (*suspend_vnode);
00239 } vnode_ops;
00240
00241
00242
00243
00244
00245 enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD };
00246
00247
00248
00249
00250
00251
00252 enum vtagtype {
00253 VT_NON, VT_UFS, VT_NFS, VT_MFS, VT_MSDOSFS, VT_LFS, VT_LOFS, VT_FDESC,
00254 VT_PORTAL, VT_NULL, VT_UMAP, VT_KERNFS, VT_PROCFS, VT_AFS, VT_ISOFS,
00255 VT_UNION, VT_ADOSFS, VT_EXT2FS, VT_CODA, VT_FILECORE, VT_NTFS, VT_VFS,
00256 VT_OVERLAY, VT_SMBFS, VT_PTYFS
00257 };
00258
00259
00260
00261
00262 #define VROOT 0x0001
00263 #define VTEXT 0x0002
00264
00265 #define VSYSTEM 0x0004
00266
00267 #define VISTTY 0x0008
00268 #define VEXECMAP 0x0010
00269 #define VLOCKSWORK 0x0080
00270 #define VXLOCK 0x0100
00271 #define VXWANT 0x0200
00272 #define VBWAIT 0x0400
00273 #define VALIASED 0x0800
00274 #define VDIROP 0x1000
00275 #define VLAYER 0x2000
00276 #define VONWORKLST 0x4000
00277 #define VDIRTY 0x8000
00278
00279
00280
00281
00282 #define VREAD 00004
00283 #define VWRITE 00002
00284 #define VEXEC 00001
00285
00286
00287
00288
00289 #define REVOKEALL 0x0001
00290
00291 #define FSYNC_WAIT 0x0001
00292 #define FSYNC_DATAONLY 0x0002
00293 #define FSYNC_RECLAIM 0x0004
00294 #define FSYNC_LAZY 0x0008
00295
00296 #define UPDATE_WAIT 0x0001
00297 #define UPDATE_DIROP 0x0002
00298 #define UPDATE_CLOSE 0x0004
00299
00300 #define IO_UNIT 0x01
00301 #define IO_APPEND 0x02
00302 #define IO_SYNC (0x04|IO_DSYNC)
00303 #define IO_NODELOCKED 0x08
00304 #define IO_NDELAY 0x10
00305 #define IO_DSYNC 0x20
00306 #define IO_ALTSEMANTICS 0x40
00307
00308
00309 LIST_HEAD(BufferCacheList, BufferCacheEntryType);
00310
00311 typedef struct VnodeType {
00312 uint32_t v_numBuffers;
00313 uint32_t v_refCount;
00314 void *v_mount;
00315 struct BufferCacheList v_cleanListHead;
00316 struct BufferCacheList v_dirtyListHead;
00317 LIST_ENTRY(VnodeType) v_dirtyList;
00318 LIST_ENTRY(VnodeType) v_mountList;
00319 uint8_t v_type;
00320 uint8_t v_tag;
00321 uint16_t v_flag;
00322 union {
00323
00324 void *data;
00325 struct InodeType *inodeP;
00326 } v_union;
00327
00328 #define v_data v_union.data
00329 #define v_inodeP v_union.inodeP
00330 const vnode_ops *v_op;
00331 } VnodeType;
00332
00333
00334 #include <support/errors.h>
00335
00336 __inline status_t VnodeInvokeOpReadBuffers(VnodeType *vnode, size_t count, BufferCacheEntryType **bufCacheP)
00337 {
00338
00339 if (vnode->v_op->readbuffers) {
00340 return vnode->v_op->readbuffers(vnode, count, bufCacheP);
00341 }
00342 return B_UNSUPPORTED;
00343 }
00344
00345 __inline status_t VnodeInvokeOpWriteBuffers(VnodeType *vnode, size_t count, BufferCacheEntryType **bufCacheP)
00346 {
00347 if (vnode->v_op->writebuffers) {
00348 return vnode->v_op->writebuffers(vnode, count, bufCacheP);
00349 }
00350 return B_UNSUPPORTED;
00351 }
00352
00353 __inline status_t VnodeInvokeOpReclaim(VnodeType *vnode)
00354 {
00355 if (vnode->v_op->reclaim) {
00356 return vnode->v_op->reclaim(vnode);
00357 }
00358 return B_UNSUPPORTED;
00359 }
00360
00361 __inline status_t VnodeInvokeOpLookup(VnodeType *dirVnodeP, VnodeType **resultVnodePP, struct componentname *cnp)
00362 {
00363 if (dirVnodeP->v_op->lookup) {
00364 return dirVnodeP->v_op->lookup(dirVnodeP, resultVnodePP, cnp);
00365 }
00366 return B_UNSUPPORTED;
00367 }
00368
00369 __inline status_t VnodeInvokeOpGetBufferForOffset(VnodeType *dirVnodeP, off_t offset, BufferCacheEntryType **bufCachePP)
00370 {
00371 if (dirVnodeP->v_op->getbufferforoffset) {
00372 return dirVnodeP->v_op->getbufferforoffset(dirVnodeP, offset, bufCachePP);
00373 }
00374 return B_UNSUPPORTED;
00375 }
00376
00377 __inline status_t VnodeInvokeOpBufferAllocate(VnodeType *vnodeP, off_t offset, int32_t size, uint32_t flags, BufferCacheEntryType **bufCachePP)
00378 {
00379 if (vnodeP->v_op->bufferallocate) {
00380 return vnodeP->v_op->bufferallocate(vnodeP, offset, size, flags, bufCachePP);
00381 }
00382 return B_UNSUPPORTED;
00383 }
00384
00385 __inline status_t VnodeInvokeOpCreate(VnodeType *dirVnodeP, VnodeType **resultVnodePP, struct componentname *cnp)
00386 {
00387 if (dirVnodeP->v_op->create) {
00388 return dirVnodeP->v_op->create(dirVnodeP, resultVnodePP, cnp);
00389 }
00390 return B_UNSUPPORTED;
00391 }
00392
00393 __inline status_t VnodeInvokeOpAllocateVnode(VnodeType *parentVnodeP, VnodeType **resultVnodePP)
00394 {
00395 if (parentVnodeP->v_op->allocate_vnode) {
00396 return parentVnodeP->v_op->allocate_vnode(parentVnodeP, resultVnodePP);
00397 }
00398 return B_UNSUPPORTED;
00399 }
00400
00401 __inline status_t VnodeInvokeOpWriteVnode(VnodeType *vnodeP, char flags)
00402 {
00403 if (vnodeP->v_op->write_vnode) {
00404 return vnodeP->v_op->write_vnode(vnodeP, flags);
00405 }
00406 return B_UNSUPPORTED;
00407 }
00408
00409 __inline status_t VnodeInvokeOpTruncate(VnodeType *vnodeP, off_t endOffset, uint32_t flags)
00410 {
00411 if (vnodeP->v_op->truncate) {
00412 return vnodeP->v_op->truncate(vnodeP, endOffset, flags);
00413 }
00414 return B_UNSUPPORTED;
00415 }
00416
00417 __inline status_t VnodeInvokeOpOpenVnode(VnodeType *vnodeP, int omode)
00418 {
00419 if (vnodeP->v_op->open) {
00420 return vnodeP->v_op->open(vnodeP, omode);
00421 }
00422 return B_UNSUPPORTED;
00423 }
00424
00425 __inline status_t VnodeInvokeOpMakeDirectory(VnodeType *parentDirVnodeP, VnodeType **newDirVnodePP, struct componentname *cnp)
00426 {
00427 if (parentDirVnodeP->v_op->mkdir) {
00428 return parentDirVnodeP->v_op->mkdir(parentDirVnodeP, newDirVnodePP, cnp);
00429 }
00430 return B_UNSUPPORTED;
00431 }
00432
00433 __inline status_t VnodeInvokeOpGetPhysicalBlockAddress(VnodeType *vnodeP, lbno_t logicalBlockNum, bno_t *physicalBlockNumP, int *numP)
00434 {
00435 if (vnodeP->v_op->getphysicalblockaddr) {
00436 return vnodeP->v_op->getphysicalblockaddr(vnodeP, logicalBlockNum, physicalBlockNumP, numP);
00437 }
00438 return B_UNSUPPORTED;
00439 }
00440
00441 __inline status_t VnodeInvokeOpWrite(VnodeType *vnodeP, off_t offset, const uint8_t *dataP, size_t *numBytesP)
00442 {
00443 if (vnodeP->v_op->write) {
00444 return vnodeP->v_op->write(vnodeP, offset, dataP, numBytesP);
00445 }
00446 return B_UNSUPPORTED;
00447 }
00448
00449 __inline status_t VnodeInvokeOpRead(VnodeType *vnodeP, off_t offset, uint8_t *dataP, size_t *numBytesP)
00450 {
00451 if (vnodeP->v_op->read) {
00452 return vnodeP->v_op->read(vnodeP, offset, dataP, numBytesP);
00453 }
00454 return B_UNSUPPORTED;
00455 }
00456
00457 __inline status_t VnodeInvokeOpUnlink(struct VnodeType *parentDirVnodeP, VnodeType *vnodeP, struct componentname *cnp)
00458 {
00459 if (vnodeP->v_op->unlink) {
00460 return vnodeP->v_op->unlink(parentDirVnodeP, vnodeP, cnp);
00461 }
00462 return B_UNSUPPORTED;
00463 }
00464
00465 __inline status_t VnodeInvokeOpRmdir(struct VnodeType *parentDirVnodeP, VnodeType *vnodeP, struct componentname *cnp)
00466 {
00467 if (vnodeP->v_op->rmdir) {
00468 return vnodeP->v_op->rmdir(parentDirVnodeP, vnodeP, cnp);
00469 }
00470 return B_UNSUPPORTED;
00471 }
00472
00473 __inline status_t VnodeInvokeOpRename(struct VnodeType *oldDirVnodeP, struct VnodeType *oldVnodeP, struct componentname *oldcnp,
00474 struct VnodeType *newDirVnodeP, struct VnodeType *newVnodeP, struct componentname *newcnp)
00475 {
00476 if (oldDirVnodeP->v_op->rename) {
00477 return oldDirVnodeP->v_op->rename(oldDirVnodeP, oldVnodeP, oldcnp, newDirVnodeP, newVnodeP, newcnp);
00478 }
00479 return B_UNSUPPORTED;
00480 }
00481
00482 __inline status_t VnodeInvokeOpCheckAccess(struct VnodeType *vnodeP, int mode, uint32_t callerID)
00483 {
00484 if (vnodeP->v_op->check_access) {
00485 return vnodeP->v_op->check_access(vnodeP, mode, callerID);
00486 }
00487 return B_UNSUPPORTED;
00488 }
00489
00490 __inline status_t VnodeInvokeOpUpdate(struct VnodeType *vnodeP, time_t accessTime, time_t modifyTime, int flags)
00491 {
00492 if (vnodeP->v_op->update) {
00493 return vnodeP->v_op->update(vnodeP, accessTime, modifyTime, flags);
00494 }
00495 return B_UNSUPPORTED;
00496 }
00497
00498 __inline void VnodeIncrementReference(VnodeType *vnode)
00499 {
00500 vnode->v_refCount++;
00501 }
00502
00503 #if 0
00504 __inline status_t VnodeWriteBuffers(VnodeType *vnode, ssize_t count, BufferCacheEntryType **bufCacheP)
00505 {
00506 if (vnode->v_op->writebuffers) {
00507 return vnode->v_op->writebuffers(vnode, count, bufCacheP);
00508 }
00509 return B_UNSUPPORTED;
00510 }
00511 #endif
00512
00513
00514 #ifdef __cplusplus
00515 }
00516 #endif
00517
00518
00519 #endif