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
11 // version 2 as amended with additional clauses defined in the
12 // file LICENSE in the main source directory.
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
17 // the file LICENSE for additional details.
20 // Author : Thorsten Engel
21 // Created On : Fri May 06 21:44:00 2005
27 #include <sys/types.h>
58 #include <atlcomcli.h>
62 // Used for safe string manipulation
67 #pragma comment(lib,"atlsd.lib")
72 VSSClient::VSSClient()
74 m_bCoInitializeCalled = false;
75 m_bCoInitializeSecurityCalled = false;
76 m_dwContext = 0; // VSS_CTX_BACKUP;
77 m_bDuringRestore = false;
78 m_bBackupIsInitialized = false;
80 m_pVectorWriterStates = new vector<int>;
81 m_pVectorWriterInfo = new vector<string>;
82 m_uidCurrentSnapshotSet = GUID_NULL;
83 memset(m_wszUniqueVolumeName,0, sizeof(m_wszUniqueVolumeName));
84 memset(m_szShadowCopyName,0, sizeof(m_szShadowCopyName));
88 VSSClient::~VSSClient()
90 // Release the IVssBackupComponents interface
91 // WARNING: this must be done BEFORE calling CoUninitialize()
93 m_pVssObject->Release();
97 if (m_pVectorWriterStates)
98 delete (m_pVectorWriterStates);
100 if (m_pVectorWriterInfo)
101 delete (m_pVectorWriterInfo);
103 // Call CoUninitialize if the CoInitialize was performed sucesfully
104 if (m_bCoInitializeCalled)
108 BOOL VSSClient::InitializeForBackup()
110 //return Initialize (VSS_CTX_BACKUP);
111 return Initialize(0);
117 BOOL VSSClient::GetShadowPath(const char *szFilePath, char *szShadowPath, int nBuflen)
119 if (!m_bBackupIsInitialized)
122 /* check for valid pathname */
125 bIsValidName = strlen(szFilePath) > 3;
127 bIsValidName &= isalpha (szFilePath[0]) &&
128 szFilePath[1]==':' &&
129 szFilePath[2] == '\\';
132 int nDriveIndex = toupper(szFilePath[0])-'A';
133 if (m_szShadowCopyName[nDriveIndex][0] != 0) {
134 strncpy(szShadowPath, m_szShadowCopyName[nDriveIndex], nBuflen);
135 nBuflen -= (int)strlen(m_szShadowCopyName[nDriveIndex]);
136 strncat(szShadowPath, szFilePath+2, nBuflen);
141 strncpy(szShadowPath, szFilePath, nBuflen);
147 const size_t VSSClient::GetWriterCount()
149 vector<int>* pV = (vector<int>*) m_pVectorWriterStates;
153 const char* VSSClient::GetWriterInfo(size_t nIndex)
155 vector<string>* pV = (vector<string>*) m_pVectorWriterInfo;
156 return pV->at(nIndex).c_str();
160 const int VSSClient::GetWriterState(size_t nIndex)
162 vector<int>* pV = (vector<int>*) m_pVectorWriterStates;
163 return pV->at(nIndex);