2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2018 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Written by James Harper, July 2010
22 * Used only in "old Exchange plugin" now deprecated.
25 #include "exchange-fd.h"
27 file_node_t::file_node_t(char *name, node_t *parent_node) : node_t(name, NODE_TYPE_FILE, parent_node)
29 backup_file_handle = INVALID_HANDLE_VALUE;
30 restore_file_handle = INVALID_HANDLE_VALUE;
31 restore_at_file_level = FALSE;
34 file_node_t::~file_node_t()
36 if (backup_file_handle != INVALID_HANDLE_VALUE)
38 //_DebugMessage(100, "closing file handle in destructor\n");
39 CloseHandle(backup_file_handle);
41 if (restore_file_handle != INVALID_HANDLE_VALUE)
43 //_DebugMessage(100, "closing file handle in destructor\n");
44 if (restore_at_file_level)
46 CloseHandle(restore_file_handle);
56 file_node_t::startBackupFile(exchange_fd_context_t *context, struct save_pkt *sp)
58 time_t now = time(NULL);
59 _DebugMessage(100, "startBackupNode_FILE state = %d\n", state);
61 if (context->job_level == 'F' || parent->type == NODE_TYPE_STORAGE_GROUP) {
62 sp->fname = full_path;
64 _DebugMessage(100, "fname = %s\n", sp->fname);
65 sp->statp.st_mode = 0700 | S_IFREG;
66 sp->statp.st_ctime = now;
67 sp->statp.st_mtime = now;
68 sp->statp.st_atime = now;
69 sp->statp.st_size = (uint64_t)-1;
73 bfuncs->setBaculaValue(context->bpContext, bVarFileSeen, (void *)full_path);
79 file_node_t::endBackupFile(exchange_fd_context_t *context)
81 _DebugMessage(100, "endBackupNode_FILE state = %d\n", state);
83 context->current_node = parent;
89 file_node_t::createFile(exchange_fd_context_t *context, struct restore_pkt *rp)
91 //HrESERestoreOpenFile with name of log file
93 _DebugMessage(0, "createFile_FILE state = %d\n", state);
94 rp->create_status = CF_EXTRACT;
99 file_node_t::endRestoreFile(exchange_fd_context_t *context)
101 _DebugMessage(0, "endRestoreFile_FILE state = %d\n", state);
102 context->current_node = parent;
107 file_node_t::pluginIoOpen(exchange_fd_context_t *context, struct io_pkt *io)
111 char *tmp = new char[wcslen(filename) + 1];
112 wcstombs(tmp, filename, wcslen(filename) + 1);
114 _DebugMessage(0, "pluginIoOpen_FILE - filename = %s\n", tmp);
117 if (context->job_type == JOB_TYPE_BACKUP)
119 _DebugMessage(10, "Calling HrESEBackupOpenFile\n");
120 result = HrESEBackupOpenFile(hccx, filename, 65535, 1, &backup_file_handle, §ion_size);
123 _JobMessage(M_FATAL, "HrESEBackupOpenFile failed with error 0x%08x - %s\n", result, ESEErrorMessage(result));
124 backup_file_handle = INVALID_HANDLE_VALUE;
131 _DebugMessage(10, "Calling HrESERestoreOpenFile for '%s'\n", tmp);
132 result = HrESERestoreOpenFile(hccx, filename, 1, &restore_file_handle);
133 if (result == hrRestoreAtFileLevel)
135 restore_at_file_level = true;
136 _DebugMessage(100, "Calling CreateFileW for '%s'\n", tmp);
137 handle = CreateFileW(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
138 if (handle == INVALID_HANDLE_VALUE)
140 _JobMessage(M_FATAL, "CreateFile failed");
143 restore_file_handle = (void *)handle;
146 else if (result == 0)
148 _JobMessage(M_FATAL, "Exchange File IO API not yet supported for restore\n");
149 restore_at_file_level = false;
154 _JobMessage(M_FATAL, "HrESERestoreOpenFile failed with error 0x%08x - %s\n", result, ESEErrorMessage(result));
162 file_node_t::pluginIoRead(exchange_fd_context_t *context, struct io_pkt *io)
169 _DebugMessage(200, "Calling HrESEBackupReadFile\n");
170 result = HrESEBackupReadFile(hccx, backup_file_handle, io->buf, io->count, &readLength);
176 io->status = readLength;
182 file_node_t::pluginIoWrite(exchange_fd_context_t *context, struct io_pkt *io)
187 if (!restore_at_file_level)
190 if (!WriteFile(restore_file_handle, io->buf, io->count, &bytes_written, NULL))
192 _JobMessage(M_FATAL, "Write Error");
196 if (bytes_written != (DWORD)io->count)
198 _JobMessage(M_FATAL, "Short write");
201 io->status = bytes_written;
207 file_node_t::pluginIoClose(exchange_fd_context_t *context, struct io_pkt *io)
209 if (context->job_type == JOB_TYPE_BACKUP)
211 _DebugMessage(100, "Calling HrESEBackupCloseFile\n");
212 HrESEBackupCloseFile(hccx, backup_file_handle);
213 backup_file_handle = INVALID_HANDLE_VALUE;
218 if (restore_at_file_level)
220 CloseHandle(restore_file_handle);
221 restore_file_handle = INVALID_HANDLE_VALUE;