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 #define AFS_OTHERCSIZE (afs_OtherCSize)
30 #define AFS_LOGCHUNK (afs_LogChunk)
31 #define AFS_FIRSTCSIZE (afs_FirstCSize)
33 #define AFS_DEFAULTCSIZE 0x10000
34 #define AFS_DEFAULTLSIZE 16
36 #endif /* AFS_NOCHUNKING */
38 #define AFS_MINCHUNK 13 /* 8k is minimum */
39 #define AFS_MAXCHUNK 18 /* 256K is maximum */
41 #define AFS_CHUNKOFFSET(offset) ((offset < afs_FirstCSize) ? offset : \
42 ((offset - afs_FirstCSize) & (afs_OtherCSize - 1)))
44 #define AFS_CHUNK(offset) ((offset < afs_FirstCSize) ? 0 : \
45 (((offset - afs_FirstCSize) >> afs_LogChunk) + 1))
47 #define AFS_CHUNKBASE(offset) ((offset < afs_FirstCSize) ? 0 : \
48 (((offset - afs_FirstCSize) & ~(afs_OtherCSize - 1)) + afs_FirstCSize))
50 #define AFS_CHUNKSIZE(offset) ((offset < afs_FirstCSize) ? afs_FirstCSize : \
53 #define AFS_CHUNKTOBASE(chunk) ((chunk == 0) ? 0 : \
54 ((afs_size_t) afs_FirstCSize + ((afs_size_t) (chunk - 1) << afs_LogChunk)))
56 #define AFS_CHUNKTOSIZE(chunk) ((chunk == 0) ? afs_FirstCSize : afs_OtherCSize)
58 /* sizes are a power of two */
59 #define AFS_SETCHUNKSIZE(chunk) { afs_LogChunk = chunk; \
60 afs_FirstCSize = afs_OtherCSize = (1 << chunk); }
63 * Functions exported by a cache type
67 #if defined(AFS_SUN57_64BIT_ENV) || defined(AFS_SGI62_ENV)
68 void *(*open) (ino_t ainode);
70 void *(*open) (afs_int32 ainode);
72 int (*truncate) (struct osi_file * fp, afs_int32 len);
73 int (*fread) (struct osi_file * fp, int offset, void *buf, afs_int32 len);
74 int (*fwrite) (struct osi_file * fp, afs_int32 offset, void *buf,
76 int (*close) (struct osi_file * fp);
77 int (*vread) (register struct vcache * avc, struct uio * auio,
78 struct AFS_UCRED * acred, daddr_t albn, struct buf ** abpp,
80 int (*vwrite) (register struct vcache * avc, struct uio * auio, int aio,
81 struct AFS_UCRED * acred, int noLock);
82 int (*FetchProc) (register struct rx_call * acall,
83 struct osi_file * afile, afs_size_t abase,
84 struct dcache * adc, struct vcache * avc,
85 afs_size_t * abytesToXferP, afs_size_t * abytesXferredP,
86 afs_int32 lengthFound);
87 int (*StoreProc) (register struct rx_call * acall,
88 struct osi_file * afile, register afs_int32 alen,
89 struct vcache * avc, int *shouldWake,
90 afs_size_t * abytesToXferP,
91 afs_size_t * abytesXferredP);
92 struct dcache *(*GetDSlot) (register afs_int32 aslot,
93 register struct dcache * tmpdc);
94 struct volume *(*GetVolSlot) (void);
95 int (*HandleLink) (register struct vcache * avc, struct vrequest * areq);
98 /* Ideally we should have used consistent naming - like COP_OPEN, COP_TRUNCATE, etc. */
99 #define afs_CFileOpen(inode) (void *)(*(afs_cacheType->open))(inode)
100 #define afs_CFileTruncate(handle, size) (*(afs_cacheType->truncate))((handle), size)
101 #define afs_CFileRead(file, offset, data, size) (*(afs_cacheType->fread))(file, offset, data, size)
102 #define afs_CFileWrite(file, offset, data, size) (*(afs_cacheType->fwrite))(file, offset, data, size)
103 #define afs_CFileClose(handle) (*(afs_cacheType->close))(handle)
104 #define afs_GetDSlot(slot, adc) (*(afs_cacheType->GetDSlot))(slot, adc)
105 #define afs_GetVolSlot() (*(afs_cacheType->GetVolSlot))()
106 #define afs_HandleLink(avc, areq) (*(afs_cacheType->HandleLink))(avc, areq)
108 #define afs_CacheFetchProc(call, file, base, adc, avc, toxfer, xfered, length) \
109 (*(afs_cacheType->FetchProc))(call, file, (afs_size_t)base, adc, avc, (afs_size_t *)toxfer, (afs_size_t *)xfered, length)
110 #define afs_CacheStoreProc(call, file, bytes, avc, wake, toxfer, xfered) \
111 (*(afs_cacheType->StoreProc))(call, file, bytes, avc, wake, toxfer, xfered)
113 #endif /* AFS_CHUNKOPS */