1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2002-2010 Free Software Foundation Europe e.V.
5    Copyright (C) 2013-2018 Bareos GmbH & Co. KG
6 
7    This program is Free Software; you can redistribute it and/or
8    modify it under the terms of version three of the GNU Affero General Public
9    License as published by the Free Software Foundation and included
10    in the file LICENSE.
11 
12    This program is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15    Affero General Public License for more details.
16 
17    You should have received a copy of the GNU Affero General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20    02110-1301, USA.
21 */
22 /*
23  * Kern Sibbald, July 2002
24  */
25 /**
26  * @file
27  * Bootstrap Record header file
28  *
29  * BootStrapRecord (bootstrap record) handling routines split from ua_restore.c July 2003
30  * Bootstrap send handling routines split from restore.c July 2012
31  */
32 
33 #ifndef BAREOS_DIRD_BSR_H_
34 #define BAREOS_DIRD_BSR_H_
35 
36 #include "dird/ua.h"
37 
38 namespace directordaemon {
39 
40 /**
41  * FileIndex entry in restore bootstrap record
42  */
43 struct RestoreBootstrapRecordFileIndex {
44    RestoreBootstrapRecordFileIndex *next;
45    int32_t findex;
46    int32_t findex2;
47 };
48 
49 /**
50  * Restore bootstrap record -- not the real one, but useful here
51  *  The restore bsr is a chain of BootStrapRecord records (linked by next).
52  *  Each BootStrapRecord represents a single JobId, and within it, it
53  *    contains a linked list of file indexes for that JobId.
54  *    The CompleteBsr() routine, will then add all the volumes
55  *    on which the Job is stored to the BootStrapRecord.
56  */
57 struct RestoreBootstrapRecord {
58    RestoreBootstrapRecord *next;                        /**< next JobId */
59    JobId_t JobId;                     /**< JobId this bsr */
60    uint32_t VolSessionId;
61    uint32_t VolSessionTime;
62    int      VolCount;                 /**< Volume parameter count */
63    VolumeParameters *VolParams;             /**< Volume, start/end file/blocks */
64    RestoreBootstrapRecordFileIndex *fi;                   /**< File indexes this JobId */
65    char *fileregex;                   /**< Only restore files matching regex */
66 };
67 
68 class UaContext;
69 
70 /**
71  * Open bootstrap file.
72  */
73 struct bootstrap_info
74 {
75    FILE *bs;
76    UaContext *ua;
77    char storage[MAX_NAME_LENGTH + 1];
78 };
79 
80 RestoreBootstrapRecord *new_bsr();
81 namespace directordaemon {
82    void FreeBsr(RestoreBootstrapRecord *bsr);
83 } /* namespace director */
84 bool CompleteBsr(UaContext *ua, RestoreBootstrapRecord *bsr);
85 uint32_t WriteBsrFile(UaContext *ua, RestoreContext &rx);
86 void DisplayBsrInfo(UaContext *ua, RestoreContext &rx);
87 uint32_t WriteBsr(UaContext *ua, RestoreContext &rx, PoolMem *buffer);
88 void AddFindex(RestoreBootstrapRecord *bsr, uint32_t JobId, int32_t findex);
89 void AddFindexAll(RestoreBootstrapRecord *bsr, uint32_t JobId);
90 RestoreBootstrapRecordFileIndex *new_findex();
91 void MakeUniqueRestoreFilename(UaContext *ua, POOLMEM *&fname);
92 void PrintBsr(UaContext *ua, RestoreContext &rx);
93 bool OpenBootstrapFile(JobControlRecord *jcr, bootstrap_info &info);
94 bool SendBootstrapFile(JobControlRecord *jcr, BareosSocket *sock, bootstrap_info &info);
95 void CloseBootstrapFile(bootstrap_info &info);
96 
97 } /* namespace directordaemon */
98 #endif // BAREOS_DIRD_BSR_H_
99