caff5665a292e9965402d8c23c8579e53fab5659
[openafs.git] / src / afs / afs_chunkops.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 #ifndef AFS_CHUNKOPS
11 #define AFS_CHUNKOPS 1
12
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 */
21 #ifdef AFS_NOCHUNKING
22
23 #define AFS_OTHERCSIZE  0x10000
24 #define AFS_LOGCHUNK    16
25 #define AFS_FIRSTCSIZE  0x40000000
26
27 #else /* AFS_NOCHUNKING */
28
29 extern afs_int32 afs_OtherCSize, afs_LogChunk, afs_FirstCSize;
30
31 #define AFS_OTHERCSIZE  (afs_OtherCSize)
32 #define AFS_LOGCHUNK    (afs_LogChunk)
33 #define AFS_FIRSTCSIZE  (afs_FirstCSize)
34
35 #define AFS_DEFAULTCSIZE 0x10000
36 #define AFS_DEFAULTLSIZE 16
37
38 #endif /* AFS_NOCHUNKING */
39
40 #define AFS_MINCHUNK 13  /* 8k is minimum */
41 #define AFS_MAXCHUNK 18  /* 256K is maximum */
42
43 #ifdef notdef
44 extern int afs_ChunkOffset(), afs_Chunk(), afs_ChunkBase(), afs_ChunkSize(), 
45     afs_ChunkToBase(), afs_ChunkToSize();
46
47 /* macros */
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)
54 #endif
55
56 #define AFS_CHUNKOFFSET(offset) ((offset < afs_FirstCSize) ? offset : \
57                          ((offset - afs_FirstCSize) & (afs_OtherCSize - 1)))
58
59 #define AFS_CHUNK(offset) ((offset < afs_FirstCSize) ? 0 : \
60                          (((offset - afs_FirstCSize) >> afs_LogChunk) + 1))
61
62 #define AFS_CHUNKBASE(offset) ((offset < afs_FirstCSize) ? 0 : \
63         (((offset - afs_FirstCSize) & ~(afs_OtherCSize - 1)) + afs_FirstCSize))
64
65 #define AFS_CHUNKSIZE(offset) ((offset < afs_FirstCSize) ? afs_FirstCSize : \
66                                afs_OtherCSize)
67
68 #define AFS_CHUNKTOBASE(chunk) ((chunk == 0) ? 0 :               \
69         (afs_FirstCSize + ((chunk - 1) << afs_LogChunk)))
70
71 #define AFS_CHUNKTOSIZE(chunk) ((chunk == 0) ? afs_FirstCSize : afs_OtherCSize)
72
73 /* sizes are a power of two */
74 #define AFS_SETCHUNKSIZE(chunk) { afs_LogChunk = chunk; \
75                       afs_FirstCSize = afs_OtherCSize = (1 << chunk);  }
76
77
78 extern void afs_CacheTruncateDaemon();
79
80 /*
81  * Functions exported by a cache type 
82  */
83
84 extern struct afs_cacheOps *afs_cacheType;
85
86 struct afs_cacheOps {
87     void *(*open)();
88     int (*truncate)();
89     int (*fread)();
90     int (*fwrite)();
91     int (*close)();
92     int (*vread)();
93     int (*vwrite)();
94     int (*FetchProc)();
95     int (*StoreProc)();
96     struct dcache *(*GetDSlot)();
97     struct volume *(*GetVolSlot)();
98     int (*HandleLink)();
99 };
100
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)
110
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)
115
116 #endif /* AFS_CHUNKOPS */
117
118
119