2 // vss.cpp -- Interface to Volume Shadow Copies (VSS)
4 // Copyright transferred from MATRIX-Computer GmbH to
5 // Kern Sibbald by express permission.
7 // Copyright (C) 2005 Kern Sibbald
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of
12 // the License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // General Public License for more details.
19 // You should have received a copy of the GNU General Public
20 // License along with this program; if not, write to the Free
21 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 // MA 02111-1307, USA.
24 // Author : Thorsten Engel
25 // Created On : Fri May 06 21:44:00 2005
31 #include <sys/types.h>
62 #include <atlcomcli.h>
66 // Used for safe string manipulation
71 #pragma comment(lib,"atlsd.lib")
76 VSSClient::VSSClient()
78 m_bCoInitializeCalled = false;
79 m_dwContext = 0; // VSS_CTX_BACKUP;
80 m_bDuringRestore = false;
81 m_bBackupIsInitialized = false;
83 m_pVectorWriterStates = new vector<int>;
84 m_pVectorWriterInfo = new vector<string>;
85 m_uidCurrentSnapshotSet = GUID_NULL;
86 memset (m_wszUniqueVolumeName,0,sizeof (m_wszUniqueVolumeName));
87 memset (m_szShadowCopyName,0,sizeof (m_szShadowCopyName));
91 VSSClient::~VSSClient()
93 // Release the IVssBackupComponents interface
94 // WARNING: this must be done BEFORE calling CoUninitialize()
96 m_pVssObject->Release();
100 if (m_pVectorWriterStates)
101 delete (m_pVectorWriterStates);
103 if (m_pVectorWriterInfo)
104 delete (m_pVectorWriterInfo);
106 // Call CoUninitialize if the CoInitialize was performed sucesfully
107 if (m_bCoInitializeCalled)
111 BOOL VSSClient::InitializeForBackup()
113 //return Initialize (VSS_CTX_BACKUP);
114 return Initialize (0);
120 BOOL VSSClient::GetShadowPath (const char* szFilePath, char* szShadowPath, int nBuflen)
122 if (!m_bBackupIsInitialized)
125 /* check for valid pathname */
128 bIsValidName = strlen (szFilePath) > 3;
130 bIsValidName &= isalpha (szFilePath[0]) &&
131 szFilePath[1]==':' &&
135 int nDriveIndex = toupper(szFilePath[0])-'A';
136 if (m_szShadowCopyName[nDriveIndex][0] != 0) {
137 strncpy (szShadowPath, m_szShadowCopyName[nDriveIndex], nBuflen);
138 nBuflen -= (int) strlen (m_szShadowCopyName[nDriveIndex]);
139 strncat (szShadowPath, szFilePath+2,nBuflen);
145 strncpy (szShadowPath, szFilePath, nBuflen);
150 const size_t VSSClient::GetWriterCount()
152 vector<int>* pV = (vector<int>*) m_pVectorWriterStates;
156 const char* VSSClient::GetWriterInfo(size_t nIndex)
158 vector<string>* pV = (vector<string>*) m_pVectorWriterInfo;
159 return pV->at(nIndex).c_str();
163 const int VSSClient::GetWriterState(size_t nIndex)
165 vector<int>* pV = (vector<int>*) m_pVectorWriterStates;
166 return pV->at(nIndex);