rx-glock-order-headers-correctly-so-its-defined-or-not-consistently-20020322
[openafs.git] / src / afs / afs_chunk.c
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 #include <afsconfig.h>
11 #include "../afs/param.h"
12
13 RCSID("$Header$");
14
15 #include "../afs/stds.h"
16 #include "../afs/sysincludes.h" /* Standard vendor system headers */
17 #include "../afs/afsincludes.h" /* Afs-based standard headers */
18 #include "../afs/afs_stats.h"
19
20 /*
21  * Chunk module.
22  */
23
24 afs_int32 afs_FirstCSize = AFS_DEFAULTCSIZE;
25 afs_int32 afs_OtherCSize = AFS_DEFAULTCSIZE;
26 afs_int32 afs_LogChunk = AFS_DEFAULTLSIZE;
27
28 #ifdef notdef
29 int afs_ChunkOffset(offset)
30     afs_int32 offset;
31 {
32
33     AFS_STATCNT(afs_ChunkOffset);
34     if (offset < afs_FirstCSize) 
35         return offset;
36     else
37         return ((offset - afs_FirstCSize) & (afs_OtherCSize - 1));
38 }
39
40
41 int afs_Chunk(offset)
42     afs_int32 offset;
43 {
44     AFS_STATCNT(afs_Chunk);
45     if (offset < afs_FirstCSize)
46         return 0;
47     else
48         return (((offset - afs_FirstCSize) >> afs_LogChunk) + 1);
49 }
50
51
52 int afs_ChunkBase(offset)
53     int offset;
54 {
55     AFS_STATCNT(afs_ChunkBase);
56     if (offset < afs_FirstCSize)
57         return 0;
58     else
59         return (((offset - afs_FirstCSize) & ~(afs_OtherCSize - 1)) + afs_FirstCSize);
60 }
61
62
63 int afs_ChunkSize(offset)
64     afs_int32 offset;
65 {
66     AFS_STATCNT(afs_ChunkSize);
67     if (offset < afs_FirstCSize)
68         return afs_FirstCSize;
69     else
70         return afs_OtherCSize;
71 }
72
73
74 int afs_ChunkToBase(chunk)
75     afs_int32 chunk;
76 {
77     AFS_STATCNT(afs_ChunkToBase);
78     if (chunk == 0)
79         return 0;
80     else 
81         return (afs_FirstCSize + ((chunk - 1) << afs_LogChunk));
82 }
83
84
85 int afs_ChunkToSize(chunk)
86     afs_int32 chunk;
87 {
88     AFS_STATCNT(afs_ChunkToSize);
89     if (chunk == 0)
90         return afs_FirstCSize;
91     else
92         return afs_OtherCSize;
93 }
94
95 /* sizes are a power of two */
96 int afs_SetChunkSize(chunk)
97      afs_int32 chunk;
98   {
99       AFS_STATCNT(afs_SetChunkSize);
100       afs_LogChunk = chunk;
101       afs_FirstCSize = afs_OtherCSize = (1 << chunk);
102   }
103
104 #endif /* notdef */