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
11 #include <afs/param.h>
15 #include <WINNT/afsclass.h>
20 * DEFINITIONS ________________________________________________________________
26 * VARIABLES __________________________________________________________________
32 * PROTOTYPES _________________________________________________________________
38 * ROUTINES ___________________________________________________________________
43 FILESET::FILESET (LPAGGREGATE lpAggregateParent, LPVOLUMEID pvid, LPTSTR pszName)
45 m_lpiAggregate = lpAggregateParent->GetIdentifier();
46 m_lpiServer = lpAggregateParent->m_lpiServer;
47 m_lpiCell = lpAggregateParent->m_lpiCell;
53 lstrcpy (m_szName, pszName);
56 m_fStatusOutOfDate = TRUE;
57 memset (&m_fs, 0x00, sizeof(FILESETSTATUS));
60 lpAggregateParent->InvalidateAllocation();
64 FILESET::~FILESET (void)
71 void FILESET::SendDeleteNotifications (void)
73 NOTIFYCALLBACK::SendNotificationToAll (evtDestroy, GetIdentifier());
77 void FILESET::Close (void)
83 LPIDENT FILESET::GetIdentifier (void)
85 if (m_lpiThis == NULL)
87 TCHAR szCell[ cchNAME ];
88 TCHAR szServer[ cchNAME ];
89 TCHAR szAggregate[ cchNAME ];
90 m_lpiAggregate->GetCellName (szCell);
91 m_lpiAggregate->GetLongServerName (szServer);
92 m_lpiAggregate->GetAggregateName (szAggregate);
94 // Finding the identifier for a fileset is a little tricky, because
95 // (a) a fileset identifier's unique "key" includes the fileset's
96 // aggregate, and (b) filesets can move around in the cell.
98 // We'll search through our list of IDENTs and see if we can find
99 // an old IDENT object that refers to this fileset; if we can't find
100 // one, we'll create a new one. To make sure we have an accurate match,
101 // we'll require that the IDENT we find match all of the following
103 // 1- The identifier must point to a fileset
104 // 2- The identifier must have the same fileset ID as this FILESET
105 // 3- The identifier's cRef must be zero (i.e., there should
106 // not be another FILESET object out there which thinks *it*
108 // 4- The identifier must (obviously) point to the cell in which
109 // this FILESET object resides
110 // 5- If this is a fileset replica, the IDENT must be on the same
111 // aggregate as this fileset
113 // Note that the IDENT class maintains its list of IDENTs in a
114 // HASHLIST that a key placed on volume IDs. We'll use that key
115 // to speed up our search enormously.
117 BOOL fRequireSameAggregate = ProbablyReplica();
119 for (LPENUM pEnum = IDENT::x_lkFilesetID->FindFirst (&m_idVolume); pEnum; pEnum = pEnum->FindNext())
122 // Only volumes which match this fileset ID will get here.
124 LPIDENT lpiFind = (LPIDENT)( pEnum->GetObject() );
126 if (lpiFind->m_iType != itFILESET)
128 if (lpiFind->m_cRef != 0)
130 if (lstrcmpi (szCell, lpiFind->m_szCell))
132 if (fRequireSameAggregate)
134 if (lstrcmpi (szServer, lpiFind->m_szServer))
136 if (lstrcmpi (szAggregate, lpiFind->m_szAggregate))
140 // Found a match! Update the IDENT's name and location,
141 // to ensure it jives with reality... for instance, if
142 // a fileset has been moved, we'll need to fix the
143 // server and aggregate names. Since this affects one
144 // of the keys in the IDENT class's hashlist, update that list.
148 lstrcpy (m_lpiThis->m_szServer, szServer);
149 lstrcpy (m_lpiThis->m_szAggregate, szAggregate);
150 lstrcpy (m_lpiThis->m_szFileset, m_szName);
155 if (m_lpiThis == NULL)
156 m_lpiThis = New2 (IDENT,(this)); // Create a new IDENT if necessary.
158 m_lpiThis->m_cRef ++;
165 LPIDENT FILESET::GetReadWriteIdentifier (ULONG *pStatus)
167 if (m_lpiThisRW == NULL)
169 if (RefreshStatus (TRUE, pStatus))
171 if ((m_lpiThisRW = IDENT::FindIdent (this, &m_fs.idReadWrite)) == NULL)
174 *pStatus = ERROR_FILE_NOT_FOUND;
183 LPIDENT FILESET::GetReadOnlyIdentifier (LPIDENT lpiParent, ULONG *pStatus)
185 LPIDENT lpiRO = NULL;
187 if (RefreshStatus (TRUE, pStatus))
189 if (lpiParent == NULL)
190 lpiParent = m_lpiCell;
194 lpiRO = IDENT::FindFileset (lpiParent, &m_fs.idReplica);
198 TCHAR szNameRO[ cchNAME ];
199 lstrcpy (szNameRO, m_szName);
201 LPCTSTR pszExtension;
202 if ((pszExtension = lstrrchr (szNameRO, TEXT('.'))) == NULL)
203 lstrcat (szNameRO, TEXT(".readonly"));
204 else if (lstrcmpi (pszExtension, TEXT(".readonly")) && lstrcmpi (pszExtension, TEXT(".backup")))
205 lstrcat (szNameRO, TEXT(".readonly"));
207 lpiRO = IDENT::FindFileset (lpiParent, szNameRO);
213 *pStatus = ERROR_FILE_NOT_FOUND;
221 LPIDENT FILESET::GetCloneIdentifier (ULONG *pStatus)
223 if (m_lpiThisBK == NULL)
225 if (RefreshStatus (TRUE, pStatus))
227 if ((m_lpiThisBK = IDENT::FindIdent (this, &m_fs.idClone)) == NULL)
230 *pStatus = ERROR_FILE_NOT_FOUND;
239 void FILESET::Invalidate (void)
241 if (!m_fStatusOutOfDate)
243 if (m_wGhost & GHOST_HAS_SERVER_ENTRY)
244 m_fStatusOutOfDate = TRUE;
246 LPAGGREGATE lpAggregate;
247 if ((lpAggregate = m_lpiAggregate->OpenAggregate()) != NULL)
249 lpAggregate->InvalidateAllocation();
250 lpAggregate->Close();
253 NOTIFYCALLBACK::SendNotificationToAll (evtInvalidate, GetIdentifier());
258 BOOL FILESET::RefreshStatus (BOOL fNotify, ULONG *pStatus)
263 if (m_fStatusOutOfDate && (m_wGhost & GHOST_HAS_SERVER_ENTRY))
265 m_fStatusOutOfDate = FALSE;
268 NOTIFYCALLBACK::SendNotificationToAll (evtRefreshStatusBegin, GetIdentifier());
271 if ((lpServer = OpenServer (&status)) == NULL)
277 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
282 wp.wpVosVolumeGet.hCell = hCell;
283 wp.wpVosVolumeGet.hServer = hVOS;
284 wp.wpVosVolumeGet.idPartition = NO_PARTITION;
285 wp.wpVosVolumeGet.idVolume = m_idVolume;
287 LPAGGREGATE lpAggregate;
288 if ((lpAggregate = m_lpiAggregate->OpenAggregate()) != NULL)
290 wp.wpVosVolumeGet.idPartition = lpAggregate->GetID();
291 lpAggregate->Close();
294 if (!Worker_DoTask (wtaskVosVolumeGet, &wp, &status))
298 SetStatusFromVOS (&wp.wpVosVolumeGet.Data);
300 if ((lpAggregate = m_lpiAggregate->OpenAggregate()) != NULL)
302 lpAggregate->InvalidateAllocation();
303 lpAggregate->Close();
307 lpServer->CloseVosObject();
314 NOTIFYCALLBACK::SendNotificationToAll (evtRefreshStatusEnd, GetIdentifier(), ((rc) ? 0 : status));
323 void FILESET::GetName (LPTSTR pszName)
325 lstrcpy (pszName, m_szName);
329 void FILESET::GetID (LPVOLUMEID pvid)
335 LPCELL FILESET::OpenCell (ULONG *pStatus)
337 return m_lpiCell->OpenCell (pStatus);
341 LPSERVER FILESET::OpenServer (ULONG *pStatus)
343 return m_lpiServer->OpenServer (pStatus);
347 LPAGGREGATE FILESET::OpenAggregate (ULONG *pStatus)
349 return m_lpiAggregate->OpenAggregate (pStatus);
353 BOOL FILESET::GetStatus (LPFILESETSTATUS lpfs, BOOL fNotify, ULONG *pStatus)
355 if (!RefreshStatus (fNotify, pStatus))
358 memcpy (lpfs, &m_fs, sizeof(FILESETSTATUS));
363 short FILESET::GetGhostStatus (void)
369 PVOID FILESET::GetUserParam (void)
371 return GetIdentifier()->GetUserParam();
375 void FILESET::SetUserParam (PVOID pUserNew)
377 GetIdentifier()->SetUserParam (pUserNew);
381 BOOL FILESET::ProbablyReplica (void)
383 LPCTSTR pszExtension;
385 if ((pszExtension = lstrrchr (m_szName, TEXT('.'))) == NULL)
388 if (lstrcmpi (pszExtension, TEXT(".readonly")))
395 void FILESET::SetStatusFromVOS (PVOID lp)
397 vos_volumeEntry_p pEntry = (vos_volumeEntry_p)lp;
399 m_fs.id = m_idVolume;
400 m_fs.idReadWrite = pEntry->readWriteId;
401 m_fs.idReplica = pEntry->readOnlyId;
402 m_fs.idClone = pEntry->backupId;
403 AfsClass_UnixTimeToSystemTime (&m_fs.timeCreation, pEntry->creationDate);
404 AfsClass_UnixTimeToSystemTime (&m_fs.timeLastUpdate, pEntry->lastUpdateDate);
405 AfsClass_UnixTimeToSystemTime (&m_fs.timeLastAccess, pEntry->lastAccessDate);
406 AfsClass_UnixTimeToSystemTime (&m_fs.timeLastBackup, pEntry->lastBackupDate);
407 AfsClass_UnixTimeToSystemTime (&m_fs.timeCopyCreation, pEntry->copyCreationDate);
408 m_fs.nFiles = pEntry->fileCount;
409 m_fs.ckQuota = pEntry->maxQuota;
410 m_fs.ckUsed = pEntry->currentSize;
412 switch (pEntry->type)
\r
414 case VOS_BACKUP_VOLUME:
\r
415 m_fs.Type = ftCLONE;
\r
416 m_fs.idClone = pEntry->id;
\r
418 case VOS_READ_ONLY_VOLUME:
\r
419 m_fs.Type = ftREPLICA;
\r
420 m_fs.idReplica = pEntry->id;
\r
422 case VOS_READ_WRITE_VOLUME:
\r
423 m_fs.Type = ftREADWRITE;
\r
424 m_fs.idReadWrite = pEntry->id;
\r
428 m_fs.State &= fsMASK_VLDB;
430 switch (pEntry->status)
433 m_fs.State |= fsSALVAGE;
436 m_fs.State |= fsNO_VNODE;
439 m_fs.State |= fsNO_VOL;
442 m_fs.State |= fsNO_SERVICE;
445 m_fs.State |= fsOFFLINE;
448 m_fs.State |= fsDISK_FULL;
451 m_fs.State |= fsOVER_QUOTA;
454 m_fs.State |= fsBUSY;
457 m_fs.State |= fsMOVED;