1 /* Copyright 2007 Secure Endpoints Inc.
6 /* This source file provides the declarations
7 * which specify the AFS Cache Manager Volume Status Event
11 #include <afs/param.h>
20 #include <WINNT/afsreg.h>
22 HMODULE hVolStatus = NULL;
23 dll_VolStatus_Funcs_t dll_funcs;
24 cm_VolStatus_Funcs_t cm_funcs;
26 /* This function is used to load any Volume Status Handlers
27 * and their associated function pointers.
30 cm_VolStatus_Initialization(void)
32 long (__fastcall * dll_VolStatus_Initialization)(dll_VolStatus_Funcs_t * dll_funcs, cm_VolStatus_Funcs_t *cm_funcs) = NULL;
36 char wd[MAX_PATH+1] = "";
38 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
39 0, KEY_QUERY_VALUE, &parmKey);
40 if (code == ERROR_SUCCESS) {
41 dummyLen = sizeof(wd);
42 code = RegQueryValueEx(parmKey, "VolStatusHandler", NULL, NULL,
43 (BYTE *) &wd, &dummyLen);
44 RegCloseKey (parmKey);
47 if (code == ERROR_SUCCESS && wd[0])
48 hVolStatus = LoadLibrary(wd);
50 (FARPROC) dll_VolStatus_Initialization = GetProcAddress(hVolStatus, "@VolStatus_Initialization@8");
51 if (dll_VolStatus_Initialization) {
52 cm_funcs.version = CM_VOLSTATUS_FUNCS_VERSION;
53 cm_funcs.cm_VolStatus_Path_To_ID = cm_VolStatus_Path_To_ID;
54 cm_funcs.cm_VolStatus_Path_To_DFSlink = cm_VolStatus_Path_To_DFSlink;
56 code = dll_VolStatus_Initialization(&dll_funcs, &cm_funcs);
59 if (dll_VolStatus_Initialization == NULL || code != 0 ||
60 dll_funcs.version != DLL_VOLSTATUS_FUNCS_VERSION) {
61 FreeLibrary(hVolStatus);
70 /* This function is used to unload any Volume Status Handlers
71 * that were loaded during initialization.
74 cm_VolStatus_Finalize(void)
76 if (hVolStatus == NULL)
79 FreeLibrary(hVolStatus);
84 /* This function notifies the Volume Status Handlers that the
85 * AFS client service has started. If the network is started
86 * at this point we call cm_VolStatus_Network_Started().
89 cm_VolStatus_Service_Started(void)
93 if (hVolStatus == NULL)
96 code = dll_funcs.dll_VolStatus_Service_Started();
97 if (code == 0 && smb_IsNetworkStarted())
98 code = dll_funcs.dll_VolStatus_Network_Started(cm_NetbiosName, cm_NetbiosName);
103 /* This function notifies the Volume Status Handlers that the
104 * AFS client service is stopping.
107 cm_VolStatus_Service_Stopped(void)
111 if (hVolStatus == NULL)
114 code = dll_funcs.dll_VolStatus_Service_Stopped();
120 /* This function notifies the Volume Status Handlers that the
121 * AFS client service is accepting network requests using the
122 * specified netbios names.
126 cm_VolStatus_Network_Started(const char * netbios32, const char * netbios64)
128 cm_VolStatus_Network_Started(const char * netbios)
133 if (hVolStatus == NULL)
137 code = dll_funcs.dll_VolStatus_Network_Started(netbios32, netbios64);
139 code = dll_funcs.dll_VolStatus_Network_Started(netbios, netbios);
145 /* This function notifies the Volume Status Handlers that the
146 * AFS client service is no longer accepting network requests
147 * using the specified netbios names
151 cm_VolStatus_Network_Stopped(const char * netbios32, const char * netbios64)
153 cm_VolStatus_Network_Stopped(const char * netbios)
158 if (hVolStatus == NULL)
162 code = dll_funcs.dll_VolStatus_Network_Stopped(netbios32, netbios64);
164 code = dll_funcs.dll_VolStatus_Network_Stopped(netbios, netbios);
170 /* This function is called when the IP address list changes.
171 * Volume Status Handlers can use this notification as a hint
172 * that it might be possible to determine volume IDs for paths
173 * that previously were not accessible.
176 cm_VolStatus_Network_Addr_Change(void)
180 if (hVolStatus == NULL)
183 code = dll_funcs.dll_VolStatus_Network_Addr_Change();
188 /* This function notifies the Volume Status Handlers that the
189 * state of the specified cell.volume has changed.
192 cm_VolStatus_Change_Notification(afs_uint32 cellID, afs_uint32 volID, enum volstatus status)
196 if (hVolStatus == NULL)
199 code = dll_funcs.dll_VolStatus_Change_Notification(cellID, volID, status);
206 cm_VolStatus_Path_To_ID(const char * share, const char * path, afs_uint32 * cellID, afs_uint32 * volID)
212 if (cellID == NULL || volID == NULL)
213 return CM_ERROR_INVAL;
218 code = cm_NameI(cm_data.rootSCachep, (char *)path, CM_FLAG_FOLLOW, cm_rootUserp, (char *)share, &req, &scp);
222 lock_ObtainMutex(&scp->mx);
223 code = cm_SyncOp(scp, NULL,cm_rootUserp, &req, 0,
224 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
226 lock_ReleaseMutex(&scp->mx);
227 cm_ReleaseSCache(scp);
231 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
233 *cellID = scp->fid.cell;
234 *volID = scp->fid.volume;
236 lock_ReleaseMutex(&scp->mx);
237 cm_ReleaseSCache(scp);
243 cm_VolStatus_Path_To_DFSlink(const char * share, const char * path, afs_uint32 *pBufSize, char *pBuffer)
250 if (pBufSize == NULL || (pBuffer == NULL && *pBufSize != 0))
251 return CM_ERROR_INVAL;
255 code = cm_NameI(cm_data.rootSCachep, (char *)path, CM_FLAG_FOLLOW, cm_rootUserp, (char *)share, &req, &scp);
259 lock_ObtainMutex(&scp->mx);
260 code = cm_SyncOp(scp, NULL, cm_rootUserp, &req, 0,
261 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
263 lock_ReleaseMutex(&scp->mx);
264 cm_ReleaseSCache(scp);
268 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
270 if (scp->fileType != CM_SCACHETYPE_DFSLINK)
271 return CM_ERROR_NOT_A_DFSLINK;
273 len = strlen(scp->mountPointStringp) + 1;
276 else if (*pBufSize >= len) {
277 strcpy(pBuffer, scp->mountPointStringp);
280 code = CM_ERROR_TOOBIG;
282 lock_ReleaseMutex(&scp->mx);
283 cm_ReleaseSCache(scp);