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