2 * Copyright 2000, International Business Machines Corporation and others.
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
14 #include <afsconfig.h>
15 #include <afs/param.h>
20 #include <WINNT/afsclass.h>
25 * DEFINITIONS ________________________________________________________________
31 * VARIABLES __________________________________________________________________
37 * PROTOTYPES _________________________________________________________________
43 * ROUTINES ___________________________________________________________________
48 FILESET::FILESET (LPAGGREGATE lpAggregateParent, LPVOLUMEID pvid, LPTSTR pszName)
50 m_lpiAggregate = lpAggregateParent->GetIdentifier();
51 m_lpiServer = lpAggregateParent->m_lpiServer;
52 m_lpiCell = lpAggregateParent->m_lpiCell;
58 lstrcpy (m_szName, pszName);
61 m_fStatusOutOfDate = TRUE;
62 memset (&m_fs, 0x00, sizeof(FILESETSTATUS));
65 lpAggregateParent->InvalidateAllocation();
69 FILESET::~FILESET (void)
76 void FILESET::SendDeleteNotifications (void)
78 NOTIFYCALLBACK::SendNotificationToAll (evtDestroy, GetIdentifier());
82 void FILESET::Close (void)
88 LPIDENT FILESET::GetIdentifier (void)
90 if (m_lpiThis == NULL)
92 TCHAR szCell[ cchNAME ];
93 TCHAR szServer[ cchNAME ];
94 TCHAR szAggregate[ cchNAME ];
95 m_lpiAggregate->GetCellName (szCell);
96 m_lpiAggregate->GetLongServerName (szServer);
97 m_lpiAggregate->GetAggregateName (szAggregate);
99 // Finding the identifier for a fileset is a little tricky, because
100 // (a) a fileset identifier's unique "key" includes the fileset's
101 // aggregate, and (b) filesets can move around in the cell.
103 // We'll search through our list of IDENTs and see if we can find
104 // an old IDENT object that refers to this fileset; if we can't find
105 // one, we'll create a new one. To make sure we have an accurate match,
106 // we'll require that the IDENT we find match all of the following
108 // 1- The identifier must point to a fileset
109 // 2- The identifier must have the same fileset ID as this FILESET
110 // 3- The identifier's cRef must be zero (i.e., there should
111 // not be another FILESET object out there which thinks *it*
113 // 4- The identifier must (obviously) point to the cell in which
114 // this FILESET object resides
115 // 5- If this is a fileset replica, the IDENT must be on the same
116 // aggregate as this fileset
118 // Note that the IDENT class maintains its list of IDENTs in a
119 // HASHLIST that a key placed on volume IDs. We'll use that key
120 // to speed up our search enormously.
122 BOOL fRequireSameAggregate = ProbablyReplica();
124 for (LPENUM pEnum = IDENT::x_lkFilesetID->FindFirst (&m_idVolume); pEnum; pEnum = pEnum->FindNext())
127 // Only volumes which match this fileset ID will get here.
129 LPIDENT lpiFind = (LPIDENT)( pEnum->GetObject() );
131 if (lpiFind->m_iType != itFILESET)
133 if (lpiFind->m_cRef != 0)
135 if (lstrcmpi (szCell, lpiFind->m_szCell))
137 if (fRequireSameAggregate)
139 if (lstrcmpi (szServer, lpiFind->m_szServer))
141 if (lstrcmpi (szAggregate, lpiFind->m_szAggregate))
145 // Found a match! Update the IDENT's name and location,
146 // to ensure it jives with reality... for instance, if
147 // a fileset has been moved, we'll need to fix the
148 // server and aggregate names. Since this affects one
149 // of the keys in the IDENT class's hashlist, update that list.
153 lstrcpy (m_lpiThis->m_szServer, szServer);
154 lstrcpy (m_lpiThis->m_szAggregate, szAggregate);
155 lstrcpy (m_lpiThis->m_szFileset, m_szName);
160 if (m_lpiThis == NULL)
161 m_lpiThis = New2 (IDENT,(this)); // Create a new IDENT if necessary.
163 m_lpiThis->m_cRef ++;
170 LPIDENT FILESET::GetReadWriteIdentifier (ULONG *pStatus)
172 if (m_lpiThisRW == NULL)
174 if (RefreshStatus (TRUE, pStatus))
176 if ((m_lpiThisRW = IDENT::FindIdent (this, &m_fs.idReadWrite)) == NULL)
179 *pStatus = ERROR_FILE_NOT_FOUND;
188 LPIDENT FILESET::GetReadOnlyIdentifier (LPIDENT lpiParent, ULONG *pStatus)
190 LPIDENT lpiRO = NULL;
192 if (RefreshStatus (TRUE, pStatus))
194 if (lpiParent == NULL)
195 lpiParent = m_lpiCell;
199 lpiRO = IDENT::FindFileset (lpiParent, &m_fs.idReplica);
203 TCHAR szNameRO[ cchNAME ];
204 lstrcpy (szNameRO, m_szName);
206 LPCTSTR pszExtension;
207 if ((pszExtension = lstrrchr (szNameRO, TEXT('.'))) == NULL)
208 lstrcat (szNameRO, TEXT(".readonly"));
209 else if (lstrcmpi (pszExtension, TEXT(".readonly")) && lstrcmpi (pszExtension, TEXT(".backup")))
210 lstrcat (szNameRO, TEXT(".readonly"));
212 lpiRO = IDENT::FindFileset (lpiParent, szNameRO);
218 *pStatus = ERROR_FILE_NOT_FOUND;
226 LPIDENT FILESET::GetCloneIdentifier (ULONG *pStatus)
228 if (m_lpiThisBK == NULL)
230 if (RefreshStatus (TRUE, pStatus))
232 if ((m_lpiThisBK = IDENT::FindIdent (this, &m_fs.idClone)) == NULL)
235 *pStatus = ERROR_FILE_NOT_FOUND;
244 void FILESET::Invalidate (void)
246 if (!m_fStatusOutOfDate)
248 if (m_wGhost & GHOST_HAS_SERVER_ENTRY)
249 m_fStatusOutOfDate = TRUE;
251 LPAGGREGATE lpAggregate;
252 if ((lpAggregate = m_lpiAggregate->OpenAggregate()) != NULL)
254 lpAggregate->InvalidateAllocation();
255 lpAggregate->Close();
258 NOTIFYCALLBACK::SendNotificationToAll (evtInvalidate, GetIdentifier());
263 BOOL FILESET::RefreshStatus (BOOL fNotify, ULONG *pStatus)
268 if (m_fStatusOutOfDate && (m_wGhost & GHOST_HAS_SERVER_ENTRY))
270 m_fStatusOutOfDate = FALSE;
273 NOTIFYCALLBACK::SendNotificationToAll (evtRefreshStatusBegin, GetIdentifier());
276 if ((lpServer = OpenServer (&status)) == NULL)
282 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
287 wp.wpVosVolumeGet.hCell = hCell;
288 wp.wpVosVolumeGet.hServer = hVOS;
289 wp.wpVosVolumeGet.idPartition = NO_PARTITION;
290 wp.wpVosVolumeGet.idVolume = m_idVolume;
292 LPAGGREGATE lpAggregate;
293 if ((lpAggregate = m_lpiAggregate->OpenAggregate()) != NULL)
295 wp.wpVosVolumeGet.idPartition = lpAggregate->GetID();
296 lpAggregate->Close();
299 if (!Worker_DoTask (wtaskVosVolumeGet, &wp, &status))
303 SetStatusFromVOS (&wp.wpVosVolumeGet.Data);
305 if ((lpAggregate = m_lpiAggregate->OpenAggregate()) != NULL)
307 lpAggregate->InvalidateAllocation();
308 lpAggregate->Close();
312 lpServer->CloseVosObject();
319 NOTIFYCALLBACK::SendNotificationToAll (evtRefreshStatusEnd, GetIdentifier(), ((rc) ? 0 : status));
328 void FILESET::GetName (LPTSTR pszName)
330 lstrcpy (pszName, m_szName);
334 void FILESET::GetID (LPVOLUMEID pvid)
340 LPCELL FILESET::OpenCell (ULONG *pStatus)
342 return m_lpiCell->OpenCell (pStatus);
346 LPSERVER FILESET::OpenServer (ULONG *pStatus)
348 return m_lpiServer->OpenServer (pStatus);
352 LPAGGREGATE FILESET::OpenAggregate (ULONG *pStatus)
354 return m_lpiAggregate->OpenAggregate (pStatus);
358 BOOL FILESET::GetStatus (LPFILESETSTATUS lpfs, BOOL fNotify, ULONG *pStatus)
360 if (!RefreshStatus (fNotify, pStatus))
363 memcpy (lpfs, &m_fs, sizeof(FILESETSTATUS));
368 short FILESET::GetGhostStatus (void)
374 PVOID FILESET::GetUserParam (void)
376 return GetIdentifier()->GetUserParam();
380 void FILESET::SetUserParam (PVOID pUserNew)
382 GetIdentifier()->SetUserParam (pUserNew);
386 BOOL FILESET::ProbablyReplica (void)
388 LPCTSTR pszExtension;
390 if ((pszExtension = lstrrchr (m_szName, TEXT('.'))) == NULL)
393 if (lstrcmpi (pszExtension, TEXT(".readonly")))
400 void FILESET::SetStatusFromVOS (PVOID lp)
402 vos_volumeEntry_p pEntry = (vos_volumeEntry_p)lp;
404 m_fs.id = m_idVolume;
405 m_fs.idReadWrite = pEntry->readWriteId;
406 m_fs.idReplica = pEntry->readOnlyId;
407 m_fs.idClone = pEntry->backupId;
408 AfsClass_UnixTimeToSystemTime (&m_fs.timeCreation, pEntry->creationDate);
409 AfsClass_UnixTimeToSystemTime (&m_fs.timeLastUpdate, pEntry->lastUpdateDate);
410 AfsClass_UnixTimeToSystemTime (&m_fs.timeLastAccess, pEntry->lastAccessDate);
411 AfsClass_UnixTimeToSystemTime (&m_fs.timeLastBackup, pEntry->lastBackupDate);
412 AfsClass_UnixTimeToSystemTime (&m_fs.timeCopyCreation, pEntry->copyCreationDate);
413 m_fs.nFiles = pEntry->fileCount;
414 m_fs.ckQuota = pEntry->maxQuota;
415 m_fs.ckUsed = pEntry->currentSize;
417 switch (pEntry->type)
419 case VOS_BACKUP_VOLUME:
421 m_fs.idClone = pEntry->id;
423 case VOS_READ_ONLY_VOLUME:
424 m_fs.Type = ftREPLICA;
425 m_fs.idReplica = pEntry->id;
427 case VOS_READ_WRITE_VOLUME:
428 m_fs.Type = ftREADWRITE;
429 m_fs.idReadWrite = pEntry->id;
433 m_fs.State &= fsMASK_VLDB;
435 switch (pEntry->status)
438 m_fs.State |= fsSALVAGE;
441 m_fs.State |= fsNO_VNODE;
444 m_fs.State |= fsNO_VOL;
447 m_fs.State |= fsNO_SERVICE;
450 m_fs.State |= fsOFFLINE;
453 m_fs.State |= fsDISK_FULL;
456 m_fs.State |= fsOVER_QUOTA;
459 m_fs.State |= fsBUSY;
462 m_fs.State |= fsMOVED;