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 <afs/param.h>
18 #include <WINNT/afsclass.h>
23 * DEFINITIONS ________________________________________________________________
29 * VARIABLES __________________________________________________________________
35 * PROTOTYPES _________________________________________________________________
41 * ROUTINES ___________________________________________________________________
46 FILESET::FILESET (LPAGGREGATE lpAggregateParent, LPVOLUMEID pvid, LPTSTR pszName)
48 m_lpiAggregate = lpAggregateParent->GetIdentifier();
49 m_lpiServer = lpAggregateParent->m_lpiServer;
50 m_lpiCell = lpAggregateParent->m_lpiCell;
56 lstrcpy (m_szName, pszName);
59 m_fStatusOutOfDate = TRUE;
60 memset (&m_fs, 0x00, sizeof(FILESETSTATUS));
63 lpAggregateParent->InvalidateAllocation();
67 FILESET::~FILESET (void)
74 void FILESET::SendDeleteNotifications (void)
76 NOTIFYCALLBACK::SendNotificationToAll (evtDestroy, GetIdentifier());
80 void FILESET::Close (void)
86 LPIDENT FILESET::GetIdentifier (void)
88 if (m_lpiThis == NULL)
90 TCHAR szCell[ cchNAME ];
91 TCHAR szServer[ cchNAME ];
92 TCHAR szAggregate[ cchNAME ];
93 m_lpiAggregate->GetCellName (szCell);
94 m_lpiAggregate->GetLongServerName (szServer);
95 m_lpiAggregate->GetAggregateName (szAggregate);
97 // Finding the identifier for a fileset is a little tricky, because
98 // (a) a fileset identifier's unique "key" includes the fileset's
99 // aggregate, and (b) filesets can move around in the cell.
101 // We'll search through our list of IDENTs and see if we can find
102 // an old IDENT object that refers to this fileset; if we can't find
103 // one, we'll create a new one. To make sure we have an accurate match,
104 // we'll require that the IDENT we find match all of the following
106 // 1- The identifier must point to a fileset
107 // 2- The identifier must have the same fileset ID as this FILESET
108 // 3- The identifier's cRef must be zero (i.e., there should
109 // not be another FILESET object out there which thinks *it*
111 // 4- The identifier must (obviously) point to the cell in which
112 // this FILESET object resides
113 // 5- If this is a fileset replica, the IDENT must be on the same
114 // aggregate as this fileset
116 // Note that the IDENT class maintains its list of IDENTs in a
117 // HASHLIST that a key placed on volume IDs. We'll use that key
118 // to speed up our search enormously.
120 BOOL fRequireSameAggregate = ProbablyReplica();
122 for (LPENUM pEnum = IDENT::x_lkFilesetID->FindFirst (&m_idVolume); pEnum; pEnum = pEnum->FindNext())
125 // Only volumes which match this fileset ID will get here.
127 LPIDENT lpiFind = (LPIDENT)( pEnum->GetObject() );
129 if (lpiFind->m_iType != itFILESET)
131 if (lpiFind->m_cRef != 0)
133 if (lstrcmpi (szCell, lpiFind->m_szCell))
135 if (fRequireSameAggregate)
137 if (lstrcmpi (szServer, lpiFind->m_szServer))
139 if (lstrcmpi (szAggregate, lpiFind->m_szAggregate))
143 // Found a match! Update the IDENT's name and location,
144 // to ensure it jives with reality... for instance, if
145 // a fileset has been moved, we'll need to fix the
146 // server and aggregate names. Since this affects one
147 // of the keys in the IDENT class's hashlist, update that list.
151 lstrcpy (m_lpiThis->m_szServer, szServer);
152 lstrcpy (m_lpiThis->m_szAggregate, szAggregate);
153 lstrcpy (m_lpiThis->m_szFileset, m_szName);
158 if (m_lpiThis == NULL)
159 m_lpiThis = New2 (IDENT,(this)); // Create a new IDENT if necessary.
161 m_lpiThis->m_cRef ++;
168 LPIDENT FILESET::GetReadWriteIdentifier (ULONG *pStatus)
170 if (m_lpiThisRW == NULL)
172 if (RefreshStatus (TRUE, pStatus))
174 if ((m_lpiThisRW = IDENT::FindIdent (this, &m_fs.idReadWrite)) == NULL)
177 *pStatus = ERROR_FILE_NOT_FOUND;
186 LPIDENT FILESET::GetReadOnlyIdentifier (LPIDENT lpiParent, ULONG *pStatus)
188 LPIDENT lpiRO = NULL;
190 if (RefreshStatus (TRUE, pStatus))
192 if (lpiParent == NULL)
193 lpiParent = m_lpiCell;
197 lpiRO = IDENT::FindFileset (lpiParent, &m_fs.idReplica);
201 TCHAR szNameRO[ cchNAME ];
202 lstrcpy (szNameRO, m_szName);
204 LPCTSTR pszExtension;
205 if ((pszExtension = lstrrchr (szNameRO, TEXT('.'))) == NULL)
206 lstrcat (szNameRO, TEXT(".readonly"));
207 else if (lstrcmpi (pszExtension, TEXT(".readonly")) && lstrcmpi (pszExtension, TEXT(".backup")))
208 lstrcat (szNameRO, TEXT(".readonly"));
210 lpiRO = IDENT::FindFileset (lpiParent, szNameRO);
216 *pStatus = ERROR_FILE_NOT_FOUND;
224 LPIDENT FILESET::GetCloneIdentifier (ULONG *pStatus)
226 if (m_lpiThisBK == NULL)
228 if (RefreshStatus (TRUE, pStatus))
230 if ((m_lpiThisBK = IDENT::FindIdent (this, &m_fs.idClone)) == NULL)
233 *pStatus = ERROR_FILE_NOT_FOUND;
242 void FILESET::Invalidate (void)
244 if (!m_fStatusOutOfDate)
246 if (m_wGhost & GHOST_HAS_SERVER_ENTRY)
247 m_fStatusOutOfDate = TRUE;
249 LPAGGREGATE lpAggregate;
250 if ((lpAggregate = m_lpiAggregate->OpenAggregate()) != NULL)
252 lpAggregate->InvalidateAllocation();
253 lpAggregate->Close();
256 NOTIFYCALLBACK::SendNotificationToAll (evtInvalidate, GetIdentifier());
261 BOOL FILESET::RefreshStatus (BOOL fNotify, ULONG *pStatus)
266 if (m_fStatusOutOfDate && (m_wGhost & GHOST_HAS_SERVER_ENTRY))
268 m_fStatusOutOfDate = FALSE;
271 NOTIFYCALLBACK::SendNotificationToAll (evtRefreshStatusBegin, GetIdentifier());
274 if ((lpServer = OpenServer (&status)) == NULL)
280 if ((hVOS = lpServer->OpenVosObject (&hCell, &status)) == NULL)
285 wp.wpVosVolumeGet.hCell = hCell;
286 wp.wpVosVolumeGet.hServer = hVOS;
287 wp.wpVosVolumeGet.idPartition = NO_PARTITION;
288 wp.wpVosVolumeGet.idVolume = m_idVolume;
290 LPAGGREGATE lpAggregate;
291 if ((lpAggregate = m_lpiAggregate->OpenAggregate()) != NULL)
293 wp.wpVosVolumeGet.idPartition = lpAggregate->GetID();
294 lpAggregate->Close();
297 if (!Worker_DoTask (wtaskVosVolumeGet, &wp, &status))
301 SetStatusFromVOS (&wp.wpVosVolumeGet.Data);
303 if ((lpAggregate = m_lpiAggregate->OpenAggregate()) != NULL)
305 lpAggregate->InvalidateAllocation();
306 lpAggregate->Close();
310 lpServer->CloseVosObject();
317 NOTIFYCALLBACK::SendNotificationToAll (evtRefreshStatusEnd, GetIdentifier(), ((rc) ? 0 : status));
326 void FILESET::GetName (LPTSTR pszName)
328 lstrcpy (pszName, m_szName);
332 void FILESET::GetID (LPVOLUMEID pvid)
338 LPCELL FILESET::OpenCell (ULONG *pStatus)
340 return m_lpiCell->OpenCell (pStatus);
344 LPSERVER FILESET::OpenServer (ULONG *pStatus)
346 return m_lpiServer->OpenServer (pStatus);
350 LPAGGREGATE FILESET::OpenAggregate (ULONG *pStatus)
352 return m_lpiAggregate->OpenAggregate (pStatus);
356 BOOL FILESET::GetStatus (LPFILESETSTATUS lpfs, BOOL fNotify, ULONG *pStatus)
358 if (!RefreshStatus (fNotify, pStatus))
361 memcpy (lpfs, &m_fs, sizeof(FILESETSTATUS));
366 short FILESET::GetGhostStatus (void)
372 PVOID FILESET::GetUserParam (void)
374 return GetIdentifier()->GetUserParam();
378 void FILESET::SetUserParam (PVOID pUserNew)
380 GetIdentifier()->SetUserParam (pUserNew);
384 BOOL FILESET::ProbablyReplica (void)
386 LPCTSTR pszExtension;
388 if ((pszExtension = lstrrchr (m_szName, TEXT('.'))) == NULL)
391 if (lstrcmpi (pszExtension, TEXT(".readonly")))
398 void FILESET::SetStatusFromVOS (PVOID lp)
400 vos_volumeEntry_p pEntry = (vos_volumeEntry_p)lp;
402 m_fs.id = m_idVolume;
403 m_fs.idReadWrite = pEntry->readWriteId;
404 m_fs.idReplica = pEntry->readOnlyId;
405 m_fs.idClone = pEntry->backupId;
406 AfsClass_UnixTimeToSystemTime (&m_fs.timeCreation, pEntry->creationDate);
407 AfsClass_UnixTimeToSystemTime (&m_fs.timeLastUpdate, pEntry->lastUpdateDate);
408 AfsClass_UnixTimeToSystemTime (&m_fs.timeLastAccess, pEntry->lastAccessDate);
409 AfsClass_UnixTimeToSystemTime (&m_fs.timeLastBackup, pEntry->lastBackupDate);
410 AfsClass_UnixTimeToSystemTime (&m_fs.timeCopyCreation, pEntry->copyCreationDate);
411 m_fs.nFiles = pEntry->fileCount;
412 m_fs.ckQuota = pEntry->maxQuota;
413 m_fs.ckUsed = pEntry->currentSize;
415 switch (pEntry->type)
417 case VOS_BACKUP_VOLUME:
419 m_fs.idClone = pEntry->id;
421 case VOS_READ_ONLY_VOLUME:
422 m_fs.Type = ftREPLICA;
423 m_fs.idReplica = pEntry->id;
425 case VOS_READ_WRITE_VOLUME:
426 m_fs.Type = ftREADWRITE;
427 m_fs.idReadWrite = pEntry->id;
431 m_fs.State &= fsMASK_VLDB;
433 switch (pEntry->status)
436 m_fs.State |= fsSALVAGE;
439 m_fs.State |= fsNO_VNODE;
442 m_fs.State |= fsNO_VOL;
445 m_fs.State |= fsNO_SERVICE;
448 m_fs.State |= fsOFFLINE;
451 m_fs.State |= fsDISK_FULL;
454 m_fs.State |= fsOVER_QUOTA;
457 m_fs.State |= fsBUSY;
460 m_fs.State |= fsMOVED;