2 Bacula® - The Network Backup Solution
4 Copyright (C) 2008-2010 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version three of the GNU Affero General Public
10 License as published by the Free Software Foundation, which is
11 listed in the file LICENSE.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Affero General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of Kern Sibbald.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
29 * Written by James Harper, October 2008
32 #include "exchange-fd.h"
34 file_node_t::file_node_t(char *name, node_t *parent_node) : node_t(name, NODE_TYPE_FILE, parent_node)
36 backup_file_handle = INVALID_HANDLE_VALUE;
37 restore_file_handle = INVALID_HANDLE_VALUE;
38 restore_at_file_level = FALSE;
41 file_node_t::~file_node_t()
43 if (backup_file_handle != INVALID_HANDLE_VALUE)
45 //_DebugMessage(100, "closing file handle in destructor\n");
46 CloseHandle(backup_file_handle);
48 if (restore_file_handle != INVALID_HANDLE_VALUE)
50 //_DebugMessage(100, "closing file handle in destructor\n");
51 if (restore_at_file_level)
53 CloseHandle(restore_file_handle);
63 file_node_t::startBackupFile(exchange_fd_context_t *context, struct save_pkt *sp)
65 time_t now = time(NULL);
66 _DebugMessage(100, "startBackupNode_FILE state = %d\n", state);
68 if (context->job_level == 'F' || parent->type == NODE_TYPE_STORAGE_GROUP) {
69 sp->fname = full_path;
71 _DebugMessage(100, "fname = %s\n", sp->fname);
72 sp->statp.st_mode = 0700 | S_IFREG;
73 sp->statp.st_ctime = now;
74 sp->statp.st_mtime = now;
75 sp->statp.st_atime = now;
76 sp->statp.st_size = (uint64_t)-1;
80 bfuncs->setBaculaValue(context->bpContext, bVarFileSeen, (void *)full_path);
86 file_node_t::endBackupFile(exchange_fd_context_t *context)
88 _DebugMessage(100, "endBackupNode_FILE state = %d\n", state);
90 context->current_node = parent;
96 file_node_t::createFile(exchange_fd_context_t *context, struct restore_pkt *rp)
98 //HrESERestoreOpenFile with name of log file
100 _DebugMessage(100, "createFile_FILE state = %d\n", state);
101 rp->create_status = CF_EXTRACT;
106 file_node_t::endRestoreFile(exchange_fd_context_t *context)
108 _DebugMessage(100, "endRestoreFile_FILE state = %d\n", state);
109 context->current_node = parent;
114 file_node_t::pluginIoOpen(exchange_fd_context_t *context, struct io_pkt *io)
118 char *tmp = new char[wcslen(filename) + 1];
119 wcstombs(tmp, filename, wcslen(filename) + 1);
121 _DebugMessage(100, "pluginIoOpen_FILE - filename = %s\n", tmp);
124 if (context->job_type == JOB_TYPE_BACKUP)
126 _DebugMessage(10, "Calling HrESEBackupOpenFile\n");
127 result = HrESEBackupOpenFile(hccx, filename, 65535, 1, &backup_file_handle, §ion_size);
130 _JobMessage(M_FATAL, "HrESEBackupOpenFile failed with error 0x%08x - %s\n", result, ESEErrorMessage(result));
131 backup_file_handle = INVALID_HANDLE_VALUE;
138 _DebugMessage(10, "Calling HrESERestoreOpenFile for '%s'\n", tmp);
139 result = HrESERestoreOpenFile(hccx, filename, 1, &restore_file_handle);
140 if (result == hrRestoreAtFileLevel)
142 restore_at_file_level = true;
143 _DebugMessage(100, "Calling CreateFileW for '%s'\n", tmp);
144 handle = CreateFileW(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
145 if (handle == INVALID_HANDLE_VALUE)
147 _JobMessage(M_FATAL, "CreateFile failed");
150 restore_file_handle = (void *)handle;
153 else if (result == 0)
155 _JobMessage(M_FATAL, "Exchange File IO API not yet supported for restore\n");
156 restore_at_file_level = false;
161 _JobMessage(M_FATAL, "HrESERestoreOpenFile failed with error 0x%08x - %s\n", result, ESEErrorMessage(result));
169 file_node_t::pluginIoRead(exchange_fd_context_t *context, struct io_pkt *io)
176 _DebugMessage(200, "Calling HrESEBackupReadFile\n");
177 result = HrESEBackupReadFile(hccx, backup_file_handle, io->buf, io->count, &readLength);
183 io->status = readLength;
189 file_node_t::pluginIoWrite(exchange_fd_context_t *context, struct io_pkt *io)
194 if (!restore_at_file_level)
197 if (!WriteFile(restore_file_handle, io->buf, io->count, &bytes_written, NULL))
199 _JobMessage(M_FATAL, "Write Error");
203 if (bytes_written != (DWORD)io->count)
205 _JobMessage(M_FATAL, "Short write");
208 io->status = bytes_written;
214 file_node_t::pluginIoClose(exchange_fd_context_t *context, struct io_pkt *io)
216 if (context->job_type == JOB_TYPE_BACKUP)
218 _DebugMessage(100, "Calling HrESEBackupCloseFile\n");
219 HrESEBackupCloseFile(hccx, backup_file_handle);
220 backup_file_handle = INVALID_HANDLE_VALUE;
225 if (restore_at_file_level)
227 CloseHandle(restore_file_handle);
228 restore_file_handle = INVALID_HANDLE_VALUE;