2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 #define AFS_CHUNKOPS 1
13 /* macros to compute useful numbers from offsets. AFS_CHUNK gives the chunk
14 number for a given offset; AFS_CHUNKOFFSET gives the offset into the chunk
15 and AFS_CHUNKBASE gives the byte offset of the base of the chunk.
16 AFS_CHUNKSIZE gives the size of the chunk containing an offset.
17 AFS_CHUNKTOBASE converts a chunk # to a base position.
18 Chunks are 0 based and go up by exactly 1, covering the file.
19 The other fields are internal and shouldn't be used */
20 /* basic parameters */
23 #define AFS_OTHERCSIZE 0x10000
24 #define AFS_LOGCHUNK 16
25 #define AFS_FIRSTCSIZE 0x40000000
27 #else /* AFS_NOCHUNKING */
29 extern afs_int32 afs_OtherCSize, afs_LogChunk, afs_FirstCSize;
31 #define AFS_OTHERCSIZE (afs_OtherCSize)
32 #define AFS_LOGCHUNK (afs_LogChunk)
33 #define AFS_FIRSTCSIZE (afs_FirstCSize)
35 #define AFS_DEFAULTCSIZE 0x10000
36 #define AFS_DEFAULTLSIZE 16
38 #endif /* AFS_NOCHUNKING */
40 #define AFS_MINCHUNK 13 /* 8k is minimum */
41 #define AFS_MAXCHUNK 18 /* 256K is maximum */
44 extern int afs_ChunkOffset(), afs_Chunk(), afs_ChunkBase(), afs_ChunkSize(),
45 afs_ChunkToBase(), afs_ChunkToSize();
48 #define AFS_CHUNKOFFSET(x) afs_ChunkOffset(x)
49 #define AFS_CHUNK(x) afs_Chunk(x)
50 #define AFS_CHUNKBASE(x) afs_ChunkBase(x)
51 #define AFS_CHUNKSIZE(x) afs_ChunkSize(x)
52 #define AFS_CHUNKTOBASE(x) afs_ChunkToBase(x)
53 #define AFS_CHUNKTOSIZE(x) afs_ChunkToSize(x)
56 #define AFS_CHUNKOFFSET(offset) ((offset < afs_FirstCSize) ? offset : \
57 ((offset - afs_FirstCSize) & (afs_OtherCSize - 1)))
59 #define AFS_CHUNK(offset) ((offset < afs_FirstCSize) ? 0 : \
60 (((offset - afs_FirstCSize) >> afs_LogChunk) + 1))
62 #define AFS_CHUNKBASE(offset) ((offset < afs_FirstCSize) ? 0 : \
63 (((offset - afs_FirstCSize) & ~(afs_OtherCSize - 1)) + afs_FirstCSize))
65 #define AFS_CHUNKSIZE(offset) ((offset < afs_FirstCSize) ? afs_FirstCSize : \
68 #define AFS_CHUNKTOBASE(chunk) ((chunk == 0) ? 0 : \
69 (afs_FirstCSize + ((chunk - 1) << afs_LogChunk)))
71 #define AFS_CHUNKTOSIZE(chunk) ((chunk == 0) ? afs_FirstCSize : afs_OtherCSize)
73 /* sizes are a power of two */
74 #define AFS_SETCHUNKSIZE(chunk) { afs_LogChunk = chunk; \
75 afs_FirstCSize = afs_OtherCSize = (1 << chunk); }
78 extern void afs_CacheTruncateDaemon();
81 * Functions exported by a cache type
84 extern struct afs_cacheOps *afs_cacheType;
96 struct dcache *(*GetDSlot)();
97 struct volume *(*GetVolSlot)();
101 /* Ideally we should have used consistent naming - like COP_OPEN, COP_TRUNCATE, etc. */
102 #define afs_CFileOpen(inode) (void *)(*(afs_cacheType->open))(inode)
103 #define afs_CFileTruncate(handle, size) (*(afs_cacheType->truncate))((handle), size)
104 #define afs_CFileRead(file, offset, data, size) (*(afs_cacheType->fread))(file, offset, data, size)
105 #define afs_CFileWrite(file, offset, data, size) (*(afs_cacheType->fwrite))(file, offset, data, size)
106 #define afs_CFileClose(handle) (*(afs_cacheType->close))(handle)
107 #define afs_GetDSlot(slot, adc) (*(afs_cacheType->GetDSlot))(slot, adc)
108 #define afs_GetVolSlot() (*(afs_cacheType->GetVolSlot))()
109 #define afs_HandleLink(avc, areq) (*(afs_cacheType->HandleLink))(avc, areq)
111 #define afs_CacheFetchProc(call, file, base, adc, avc, toxfer, xfered) \
112 (*(afs_cacheType->FetchProc))(call, file, base, adc, avc, toxfer, xfered)
113 #define afs_CacheStoreProc(call, file, bytes, avc, wake, toxfer, xfered) \
114 (*(afs_cacheType->StoreProc))(call, file, bytes, avc, wake, toxfer, xfered)
116 #endif /* AFS_CHUNKOPS */