win95-initial-port-20010430
[openafs.git] / src / WINNT / afsd / cm_diskcache95.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 CM_DISKCACHE_H
11 #define CM_DISKCACHE_H
12
13 #include "queue95.h"
14
15 #define DCHash(v, c)    ((((v)->vnode + (v)->volume + (c))) & (afs_dhashsize-1))
16
17 #define CACHE_INFO_FILE "cacheInfo"
18
19 #define CACHE_INFO_MAGIC 0x34564321
20 #define CACHE_FILE_MAGIC 0x78931230
21 #define CACHE_FILES_PER_DIR 1000
22 #define CACHE_INFO_UPDATES_PER_WRITE 1
23
24 #define DPRINTF if (0) printf
25
26 /* kept on disk and in dcache entries */
27 struct fcache {
28     cm_fid_t fid;       /* Fid for this file */
29     int32 modTime;              /* last time this entry was modified */
30   /*afs_hyper_t versionNo;      /* Associated data version number */
31   int dataVersion;
32     int chunk;          /* Relative chunk number */
33     int chunkBytes;             /* Num bytes in this chunk */
34     char states;                /* Has this chunk been modified? */
35     int accessOrd;      /* change to 64 bit later */
36 #define DISK_CACHE_EMPTY 0
37 #define DISK_CACHE_USED 1
38   int index;                /* absolute chunk number */
39   int checksum;
40   /*char pad[464];   /* pad up to 512 bytes */
41 };
42
43 /* in-memory chunk file control block */
44 typedef struct cm_diskcache {
45   struct fcache f;
46
47   /*osi_queue_t lruq;
48     osi_queue_t hashq;*/
49   QLink lruq;
50   QLink openq;
51   int openfd;      /* open file descriptor */
52   struct cm_diskcache *hash_next;
53   struct cm_diskcache *hash_prev;
54   int refCount;
55   osi_mutex_t mx;
56 } cm_diskcache_t;
57
58 typedef struct cm_cacheInfoHdr {
59   int magic;
60   int chunks;     /* total chunks in cache */
61   int chunkSize;
62   char pad[500];  /* pad up to 512 bytes */
63 } cm_cacheInfoHdr_t;
64
65 typedef struct cm_cacheFileHdr {
66   int magic;
67   int index;
68 } cm_cacheFileHdr_t;
69
70 /* external functions */
71
72 /* Initialize the disk cache */
73 int diskcache_Init();
74 /* Get chunk from the cache or allocate a new chunk */
75 int diskcache_Get(cm_fid_t *fid, osi_hyper_t *offset, char *buf, int size, int *dataVersion, int *dataCount, cm_diskcache_t **dcpRet);
76 /* Write out buffer to disk */
77 int diskcache_Update(cm_diskcache_t *dcp, char *buf, int size, int dataVersion);
78 /* we accessed this chunk, so move to MRU */
79 void diskcache_Touch(cm_diskcache_t *dcp);
80
81 #endif /* CM_DISKCACHE_H */