windows-misc-20041025
[openafs.git] / src / WINNT / afsd / cm_scache.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_SCACHE_H_ENV__
11 #define __CM_SCACHE_H_ENV__ 1
12
13 #ifdef DJGPP
14 #include "largeint95.h"
15 #endif /* DJGPP */
16
17 typedef struct cm_fid {
18         unsigned long cell;
19         unsigned long volume;
20         unsigned long vnode;
21         unsigned long unique;
22 } cm_fid_t;
23
24 typedef struct cm_accessCache {
25         osi_queue_t q;                  /* queue header */
26         struct cm_user *userp;          /* user having access rights */
27         unsigned long rights;           /* rights */
28 } cm_accessCache_t;
29
30 typedef struct cm_file_lock {
31         osi_queue_t q;                  /* list of all locks */
32         osi_queue_t fileq;              /* per-file list of locks */
33         cm_user_t *userp;
34         LARGE_INTEGER LOffset;
35         LARGE_INTEGER LLength;
36         cm_fid_t fid;
37         unsigned char LockType;
38         unsigned char flags;
39 } cm_file_lock_t;
40
41 #define CM_FILELOCK_FLAG_INVALID        0x1
42 #define CM_FILELOCK_FLAG_WAITING        0x2
43
44 typedef struct cm_prefetch {            /* last region scanned for prefetching */
45         osi_hyper_t base;               /* start of region */
46         osi_hyper_t end;                /* first char past region */
47 } cm_prefetch_t;
48
49 typedef struct cm_scache {
50         osi_queue_t q;                  /* lru queue; cm_scacheLock */
51         struct cm_scache *nextp;        /* next in hash; cm_scacheLock */
52         cm_fid_t fid;
53         unsigned long flags;            /* flags; locked by mx */
54
55         /* synchronization stuff */
56         osi_mutex_t mx;                 /* mutex for this structure */
57         osi_rwlock_t bufCreateLock;     /* read-locked during buffer creation;
58                                          * write-locked to prevent buffers from
59                                          * being created during a truncate op, etc.
60                                          */
61         unsigned long refCount;                 /* reference count; cm_scacheLock */
62         osi_queueData_t *bufReadsp;     /* queue of buffers being read */
63         osi_queueData_t *bufWritesp;    /* queue of buffers being written */
64
65         /* parent info for ACLs */
66         long parentVnode;               /* parent vnode for ACL callbacks */
67         long parentUnique;              /* for ACL callbacks */
68
69         /* local modification stat */
70         unsigned long mask;             /* for clientModTime, length and
71                                          * truncPos */
72
73         /* file status */
74         unsigned int fileType;                  /* file type */
75         time_t clientModTime;   /* mtime */
76         time_t serverModTime;   /* at server, for concurrent call
77                                          * comparisons */
78         osi_hyper_t length;             /* file length */
79         cm_prefetch_t prefetch;         /* prefetch info structure */
80         unsigned int unixModeBits;      /* unix protection mode bits */
81         int linkCount;                  /* link count */
82         long dataVersion;               /* data version */
83         long owner;                     /* file owner */
84         long group;                     /* file owning group */
85
86         /* pseudo file status */
87         osi_hyper_t serverLength;       /* length known to server */
88
89         /* aux file status */
90         osi_hyper_t truncPos;           /* file size to truncate to before
91                                          * storing data */
92
93         /* symlink and mount point info */
94         char *mountPointStringp;        /* the string stored in a mount point;
95                                          * first char is type, then vol name.
96                                          * If this is a normal symlink, we store
97                                          * the link contents here.
98                                          */
99         cm_fid_t *mountRootFidp;        /* mounted on root */
100         time_t    mountRootGen;         /* time to update mountRootFidp? */
101         cm_fid_t *dotdotFidp;           /* parent of volume root */
102
103         /* callback info */
104         struct cm_server *cbServerp;    /* server granting callback */
105         time_t cbExpires;               /* time callback expires */
106
107         /* access cache */
108         long anyAccess;                 /* anonymous user's access */
109         struct cm_aclent *randomACLp;   /* access cache entries */
110
111         /* file locks */
112         osi_queue_t *fileLocks;
113         
114         /* volume info */
115         struct cm_volume *volp;         /* volume info; held reference */
116   
117         /* bulk stat progress */
118         osi_hyper_t bulkStatProgress;   /* track bulk stats of large dirs */
119
120         /* open state */
121         short openReads;                /* open for reading */
122         short openWrites;               /* open for writing */
123         short openShares;               /* open for read excl */
124         short openExcls;                /* open for exclusives */
125 } cm_scache_t;
126
127 /* mask field - tell what has been modified */
128 #define CM_SCACHEMASK_CLIENTMODTIME     1       /* client mod time */
129 #define CM_SCACHEMASK_LENGTH            2       /* length */
130 #define CM_SCACHEMASK_TRUNCPOS          4       /* truncation position */
131
132 /* fileType values */
133 #define CM_SCACHETYPE_FILE              1       /* a file */
134 #define CM_SCACHETYPE_DIRECTORY         2       /* a dir */
135 #define CM_SCACHETYPE_SYMLINK           3       /* a symbolic link */
136 #define CM_SCACHETYPE_MOUNTPOINT        4       /* a mount point */
137
138 /* flag bits */
139 #define CM_SCACHEFLAG_STATD                 0x01        /* status info is valid */
140 #define CM_SCACHEFLAG_DELETED           0x02    /* file has been deleted */
141 #define CM_SCACHEFLAG_CALLBACK          0x04    /* have a valid callback */
142 #define CM_SCACHEFLAG_STORING           0x08    /* status being stored back */
143 #define CM_SCACHEFLAG_FETCHING          0x10    /* status being fetched */
144 #define CM_SCACHEFLAG_SIZESTORING       0x20    /* status being stored that
145                                                  * changes the data; typically,
146                                                  * this is a truncate op. */
147 #define CM_SCACHEFLAG_INHASH            0x40    /* in the hash table */
148 #define CM_SCACHEFLAG_BULKSTATTING      0x80    /* doing a bulk stat */
149 #define CM_SCACHEFLAG_WAITING           0x200   /* waiting for fetch/store
150                                                  * state to change */
151 #define CM_SCACHEFLAG_PURERO            0x400   /* read-only (not even backup);
152                                                  * for mount point eval */
153 #define CM_SCACHEFLAG_RO                0x800   /* read-only
154                                                  * (can't do write ops) */
155 #define CM_SCACHEFLAG_GETCALLBACK       0x1000  /* we're getting a callback */
156 #define CM_SCACHEFLAG_DATASTORING       0x2000  /* data being stored */
157 #define CM_SCACHEFLAG_PREFETCHING       0x4000  /* somebody is prefetching */
158 #define CM_SCACHEFLAG_OVERQUOTA         0x8000  /* over quota */
159 #define CM_SCACHEFLAG_OUTOFSPACE        0x10000 /* out of space */
160 #define CM_SCACHEFLAG_ASYNCSTORING      0x20000 /* scheduled to store back */
161 #define CM_SCACHEFLAG_LOCKING           0x40000 /* setting/clearing file lock */
162 #define CM_SCACHEFLAG_WATCHED           0x80000 /* directory being watched */
163 #define CM_SCACHEFLAG_WATCHEDSUBTREE    0x100000 /* dir subtree being watched */
164 #define CM_SCACHEFLAG_ANYWATCH \
165                         (CM_SCACHEFLAG_WATCHED | CM_SCACHEFLAG_WATCHEDSUBTREE)
166
167 /* sync flags for calls to the server.  The CM_SCACHEFLAG_FETCHING,
168  * CM_SCACHEFLAG_STORING and CM_SCACHEFLAG_SIZESTORING flags correspond to the
169  * below, except for FETCHDATA and STOREDATA, which correspond to non-null
170  * buffers in bufReadsp and bufWritesp.
171  * These flags correspond to individual RPCs that we may be making, and at most
172  * one can be set in any one call to SyncOp.
173  */
174 #define CM_SCACHESYNC_FETCHSTATUS           0x01        /* fetching status info */
175 #define CM_SCACHESYNC_STORESTATUS           0x02        /* storing status info */
176 #define CM_SCACHESYNC_FETCHDATA             0x04        /* fetch data */
177 #define CM_SCACHESYNC_STOREDATA             0x08        /* store data */
178 #define CM_SCACHESYNC_STORESIZE         0x10    /* store new file size */
179 #define CM_SCACHESYNC_GETCALLBACK       0x20    /* fetching a callback */
180 #define CM_SCACHESYNC_STOREDATA_EXCL    0x40    /* store data */
181 #define CM_SCACHESYNC_ASYNCSTORE        0x80    /* schedule data store */
182 #define CM_SCACHESYNC_LOCK              0x100   /* set/clear file lock */
183
184 /* sync flags for calls within the client; there are no corresponding flags
185  * in the scache entry, because we hold the scache entry locked during the
186  * operations below.
187  */
188 #define CM_SCACHESYNC_GETSTATUS         0x1000  /* read the status */
189 #define CM_SCACHESYNC_SETSTATUS         0x2000  /* e.g. utimes */
190 #define CM_SCACHESYNC_READ              0x4000  /* read data from a chunk */
191 #define CM_SCACHESYNC_WRITE             0x8000  /* write data to a chunk */
192 #define CM_SCACHESYNC_SETSIZE           0x10000 /* shrink the size of a file,
193                                                  * e.g. truncate */
194 #define CM_SCACHESYNC_NEEDCALLBACK      0x20000 /* need a callback on the file */
195 #define CM_SCACHESYNC_CHECKRIGHTS       0x40000 /* check that user has desired
196                                                  * access rights */
197 #define CM_SCACHESYNC_BUFLOCKED         0x80000 /* the buffer is locked */
198 #define CM_SCACHESYNC_NOWAIT            0x100000/* don't wait for the state,
199                                                  * just fail */
200
201 /* flags for cm_MergeStatus */
202 #define CM_MERGEFLAG_FORCE              1       /* check mtime before merging;
203                                                  * used to see if we're merging
204                                                  * in old info.
205                                                  */
206
207 /* hash define.  Must not include the cell, since the callback revocation code
208  * doesn't necessarily know the cell in the case of a multihomed server
209  * contacting us from a mystery address.
210  */
211 #define CM_SCACHE_HASH(fidp)    (((unsigned long)       \
212                                    ((fidp)->volume +    \
213                                     (fidp)->vnode +     \
214                                     (fidp)->unique))    \
215                                         % cm_hashTableSize)
216
217 #include "cm_conn.h"
218 #include "cm_buf.h"
219
220 extern cm_scache_t cm_fakeSCache;
221
222 extern void cm_InitSCache(long);
223
224 extern long cm_GetSCache(cm_fid_t *, cm_scache_t **, struct cm_user *,
225         struct cm_req *);
226
227 extern void cm_PutSCache(cm_scache_t *);
228
229 extern cm_scache_t *cm_GetNewSCache(void);
230
231 extern int cm_FidCmp(cm_fid_t *, cm_fid_t *);
232
233 extern long cm_SyncOp(cm_scache_t *, struct cm_buf *, struct cm_user *,
234         struct cm_req *, long, long);
235
236 extern void cm_SyncOpDone(cm_scache_t *, struct cm_buf *, long);
237
238 extern void cm_MergeStatus(cm_scache_t *, struct AFSFetchStatus *, struct AFSVolSync *,
239         struct cm_user *, int flags);
240
241 extern void cm_AFSFidFromFid(struct AFSFid *, cm_fid_t *);
242
243 extern void cm_HoldSCache(cm_scache_t *);
244
245 extern void cm_ReleaseSCache(cm_scache_t *);
246
247 extern cm_scache_t *cm_FindSCache(cm_fid_t *fidp);
248
249 extern long cm_hashTableSize;
250
251 extern osi_rwlock_t cm_scacheLock;
252
253 extern osi_queue_t *cm_allFileLocks;
254
255 extern cm_scache_t **cm_hashTablep;
256
257 extern void cm_DiscardSCache(cm_scache_t *scp);
258
259 #endif /*  __CM_SCACHE_H_ENV__ */