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_dwContext = 0; // VSS_CTX_BACKUP;
76 m_bDuringRestore = false;
77 m_bBackupIsInitialized = false;
79 m_pVectorWriterStates = new vector<int>;
80 m_pVectorWriterInfo = new vector<string>;
81 m_uidCurrentSnapshotSet = GUID_NULL;
82 memset(m_wszUniqueVolumeName,0, sizeof(m_wszUniqueVolumeName));
83 memset(m_szShadowCopyName,0, sizeof(m_szShadowCopyName));
87 VSSClient::~VSSClient()
89 // Release the IVssBackupComponents interface
90 // WARNING: this must be done BEFORE calling CoUninitialize()
92 m_pVssObject->Release();
96 if (m_pVectorWriterStates)
97 delete (m_pVectorWriterStates);
99 if (m_pVectorWriterInfo)
100 delete (m_pVectorWriterInfo);
102 // Call CoUninitialize if the CoInitialize was performed sucesfully
103 if (m_bCoInitializeCalled)
107 BOOL VSSClient::InitializeForBackup()
109 //return Initialize (VSS_CTX_BACKUP);
110 return Initialize(0);
116 BOOL VSSClient::GetShadowPath(const char *szFilePath, char *szShadowPath, int nBuflen)
118 if (!m_bBackupIsInitialized)
121 /* check for valid pathname */
124 bIsValidName = strlen(szFilePath) > 3;
126 bIsValidName &= isalpha (szFilePath[0]) &&
127 szFilePath[1]==':' &&
128 szFilePath[2] == '\\';
131 int nDriveIndex = toupper(szFilePath[0])-'A';
132 if (m_szShadowCopyName[nDriveIndex][0] != 0) {
133 strncpy(szShadowPath, m_szShadowCopyName[nDriveIndex], nBuflen);
134 nBuflen -= (int)strlen(m_szShadowCopyName[nDriveIndex]);
135 strncat(szShadowPath, szFilePath+2, nBuflen);
140 strncpy(szShadowPath, szFilePath, nBuflen);
146 const size_t VSSClient::GetWriterCount()
148 vector<int>* pV = (vector<int>*) m_pVectorWriterStates;
152 const char* VSSClient::GetWriterInfo(size_t nIndex)
154 vector<string>* pV = (vector<string>*) m_pVectorWriterInfo;
155 return pV->at(nIndex).c_str();
159 const int VSSClient::GetWriterState(size_t nIndex)
161 vector<int>* pV = (vector<int>*) m_pVectorWriterStates;
162 return pV->at(nIndex);