OpenAFS
OpenAFS distributed network file system
/cygdrive/c/src/openafs/openafs.git/repo/src/afs/afs_chunkops.h
00001 /*
00002  * Copyright 2000, International Business Machines Corporation and others.
00003  * All Rights Reserved.
00004  *
00005  * This software has been released under the terms of the IBM Public
00006  * License.  For details, see the LICENSE file in the top-level source
00007  * directory or online at http://www.openafs.org/dl/license10.html
00008  */
00009 
00010 #ifndef AFS_CHUNKOPS
00011 #define AFS_CHUNKOPS 1
00012 
00013 /* macros to compute useful numbers from offsets.  AFS_CHUNK gives the chunk
00014     number for a given offset; AFS_CHUNKOFFSET gives the offset into the chunk
00015     and AFS_CHUNKBASE gives the byte offset of the base of the chunk.
00016       AFS_CHUNKSIZE gives the size of the chunk containing an offset.
00017       AFS_CHUNKTOBASE converts a chunk # to a base position.
00018       Chunks are 0 based and go up by exactly 1, covering the file.
00019       The other fields are internal and shouldn't be used */
00020 /* basic parameters */
00021 
00022 #define AFS_OTHERCSIZE  (afs_OtherCSize)
00023 #define AFS_LOGCHUNK    (afs_LogChunk)
00024 #define AFS_FIRSTCSIZE  (afs_FirstCSize)
00025 
00026 #define AFS_DEFAULTCSIZE 0x10000
00027 #define AFS_DEFAULTLSIZE 16
00028 
00029 #define AFS_CHUNKOFFSET(offset) ((offset < afs_FirstCSize) ? offset : \
00030                          ((offset - afs_FirstCSize) & (afs_OtherCSize - 1)))
00031 
00032 #define AFS_CHUNK(offset) ((offset < afs_FirstCSize) ? 0 : \
00033                          (((offset - afs_FirstCSize) >> afs_LogChunk) + 1))
00034 
00035 #define AFS_CHUNKBASE(offset) ((offset < afs_FirstCSize) ? 0 : \
00036         (((offset - afs_FirstCSize) & ~(afs_OtherCSize - 1)) + afs_FirstCSize))
00037 
00038 #define AFS_CHUNKSIZE(offset) ((offset < afs_FirstCSize) ? afs_FirstCSize : \
00039                                afs_OtherCSize)
00040 
00041 #define AFS_CHUNKTOBASE(chunk) ((chunk == 0) ? 0 :               \
00042         ((afs_size_t) afs_FirstCSize + ((afs_size_t) (chunk - 1) << afs_LogChunk)))
00043 
00044 #define AFS_CHUNKTOSIZE(chunk) ((chunk == 0) ? afs_FirstCSize : afs_OtherCSize)
00045 
00046 /* sizes are a power of two */
00047 #define AFS_SETCHUNKSIZE(chunk) { afs_LogChunk = chunk; \
00048                       afs_FirstCSize = afs_OtherCSize = (1 << chunk);  }
00049 
00050 /*
00051  * Functions exported by a cache type
00052  */
00053 
00054 struct afs_cacheOps {
00055     void *(*open) (afs_dcache_id_t *ainode);
00056     int (*truncate) (struct osi_file * fp, afs_int32 len);
00057     int (*fread) (struct osi_file * fp, int offset, void *buf, afs_int32 len);
00058     int (*fwrite) (struct osi_file * fp, afs_int32 offset, void *buf,
00059                    afs_int32 len);
00060     int (*close) (struct osi_file * fp);
00061     int (*vreadUIO) (afs_dcache_id_t *, struct uio *);
00062     int (*vwriteUIO) (struct vcache *, afs_dcache_id_t *, struct uio *);
00063     struct dcache *(*GetDSlot) (afs_int32 aslot, int needvalid);
00064     struct volume *(*GetVolSlot) (void);
00065     int (*HandleLink) (struct vcache * avc, struct vrequest * areq);
00066 };
00067 
00068 /* Ideally we should have used consistent naming - like COP_OPEN, COP_TRUNCATE, etc. */
00069 #define afs_CFileOpen(inode)          (void *)(*(afs_cacheType->open))(inode)
00070 #define afs_CFileTruncate(handle, size) (*(afs_cacheType->truncate))((handle), size)
00071 #define afs_CFileRead(file, offset, data, size) (*(afs_cacheType->fread))(file, offset, data, size)
00072 #define afs_CFileWrite(file, offset, data, size) (*(afs_cacheType->fwrite))(file, offset, data, size)
00073 #define afs_CFileClose(handle)          (*(afs_cacheType->close))(handle)
00074 #define afs_GetValidDSlot(slot) (*(afs_cacheType->GetDSlot))(slot, 1)
00075 #define afs_GetNewDSlot(slot)   (*(afs_cacheType->GetDSlot))(slot, 0)
00076 #define afs_GetVolSlot()                (*(afs_cacheType->GetVolSlot))()
00077 #define afs_HandleLink(avc, areq)       (*(afs_cacheType->HandleLink))(avc, areq)
00078 
00079 /* These memcpys should get optimised to simple assignments when afs_dcache_id_t
00080  * is simple */
00081 static_inline void afs_copy_inode(afs_dcache_id_t *dst, afs_dcache_id_t *src) {
00082     memcpy(dst, src, sizeof(afs_dcache_id_t));
00083 }
00084 
00085 static_inline void afs_reset_inode(afs_dcache_id_t *i) {
00086     memset(i, 0, sizeof(afs_dcache_id_t));
00087 }
00088 
00089 /* We need to have something we can output as the 'inode' for fstrace calls.
00090  * This is a hack */
00091 static_inline int afs_inode2trace(afs_dcache_id_t *i) {
00092     return i->mem;
00093 }
00094 
00095 
00096 #endif /* AFS_CHUNKOPS */
 All Data Structures Files Functions Variables