]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/bdb_update.c
d75187dcdaa102f2e630e857ad9626569c158f17
[bacula/bacula] / bacula / src / cats / bdb_update.c
1 /*
2  * Bacula Catalog Database Update record interface routines
3  *
4  * Bacula Catalog Database routines written specifically
5  *  for Bacula.  Note, these routines are VERY dumb and
6  *  do not provide all the functionality of an SQL database.
7  *  The purpose of these routines is to ensure that Bacula
8  *  can limp along if no real database is loaded on the
9  *  system.
10  *   
11  *    Kern Sibbald, January MMI 
12  *
13  *    $Id:
14  */
15
16 /*
17    Copyright (C) 2001, 2002 Kern Sibbald and John Walker
18
19    This program is free software; you can redistribute it and/or
20    modify it under the terms of the GNU General Public License as
21    published by the Free Software Foundation; either version 2 of
22    the License, or (at your option) any later version.
23
24    This program is distributed in the hope that it will be useful,
25    but WITHOUT ANY WARRANTY; without even the implied warranty of
26    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27    General Public License for more details.
28
29    You should have received a copy of the GNU General Public
30    License along with this program; if not, write to the Free
31    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
32    MA 02111-1307, USA.
33
34  */
35
36
37 /* The following is necessary so that we do not include
38  * the dummy external definition of DB.
39  */
40 #define __SQL_C                       /* indicate that this is sql.c */
41
42 #include "bacula.h"
43 #include "cats.h"
44 #include "bdb.h"
45
46 #ifdef HAVE_BACULA_DB
47
48 /* Forward referenced functions */
49
50 /* -----------------------------------------------------------------------
51  *
52  *   Bacula specific defines and subroutines
53  *
54  * -----------------------------------------------------------------------
55  */
56
57
58 /*
59  * This is called at Job start time to add the
60  * most current start fields to the job record.
61  * It is assumed that you did a db_create_job_record() already.
62  */
63 int db_update_job_start_record(B_DB *mdb, JOB_DBR *jr)    
64 {
65    int len, stat;
66    JOB_DBR ojr;
67
68    Dmsg0(200, "In db_update_job_start_record\n");
69    len = sizeof(ojr);
70    memcpy(&ojr, jr, len);
71
72    if (!db_get_job_record(mdb, &ojr)) {
73       return 0;
74    }
75
76    P(mdb->mutex);
77
78    fseek(mdb->jobfd, ojr.rec_addr, SEEK_SET);
79    if (fwrite(jr, len, 1, mdb->jobfd) != 1) {
80       Mmsg1(&mdb->errmsg, _("Error updating DB Job file. ERR=%s\n"), strerror(errno));
81       stat = 0;
82    }
83    fflush(mdb->jobfd);
84
85    V(mdb->mutex);
86    return stat;
87 }
88
89 /*
90  * This is called at Job termination time to add all the
91  * other fields to the job record.
92  */
93 int db_update_job_end_record(B_DB *mdb, JOB_DBR *jr)    
94 {
95    int len, stat;
96    JOB_DBR ojr;
97
98    Dmsg0(200, "In db_update_job_start_record\n");
99    len = sizeof(ojr);
100    memcpy(&ojr, jr, len);
101
102    if (!db_get_job_record(mdb, &ojr)) {
103       return 0;
104    }
105
106    P(mdb->mutex);
107
108    fseek(mdb->jobfd, ojr.rec_addr, SEEK_SET);
109    if (fwrite(jr, len, 1, mdb->jobfd) != 1) {
110       Mmsg1(&mdb->errmsg, _("Error updating DB Job file. ERR=%s\n"), strerror(errno));
111       stat = 0;
112    }
113    fflush(mdb->jobfd);
114
115    V(mdb->mutex);
116    return stat;
117 }
118
119
120 int db_update_media_record(B_DB *mdb, MEDIA_DBR *mr) 
121
122    int stat = 1;
123    MEDIA_DBR omr;
124    int len;
125        
126    Dmsg0(200, "In db_update_media_record\n");
127    mr->MediaId = 0;
128    len = sizeof(omr);
129    memcpy(&omr, mr, len);
130
131    if (!db_get_media_record(mdb, &omr)) {
132       return 0;
133    }
134
135    P(mdb->mutex);
136
137    /* Don't allow some fields to change by copying from master record */
138    strcpy(mr->VolumeName, omr.VolumeName);
139    strcpy(mr->MediaType, omr.MediaType);
140    mr->MediaId = omr.MediaId;
141    mr->PoolId = omr.PoolId;
142    mr->VolMaxBytes = omr.VolMaxBytes;
143    mr->VolCapacityBytes = omr.VolCapacityBytes;
144    mr->Recycle = omr.Recycle;
145
146    fseek(mdb->mediafd, omr.rec_addr, SEEK_SET);
147    if (fwrite(mr, len, 1, mdb->mediafd) != 1) {
148       Mmsg1(&mdb->errmsg, _("Error updating DB Media file. ERR=%s\n"), strerror(errno));
149       stat = 0;
150    }
151    fflush(mdb->mediafd);
152
153    V(mdb->mutex);
154    return stat;
155 }
156
157 int db_update_pool_record(B_DB *mdb, POOL_DBR *pr) 
158
159    int stat = 1;
160    POOL_DBR opr;
161    int len;
162        
163    Dmsg0(200, "In db_update_pool_record\n");
164    len = sizeof(opr);
165    memcpy(&opr, pr, len);
166
167    if (!db_get_pool_record(mdb, &opr)) {
168       return 0;
169    }
170
171    P(mdb->mutex);
172
173    /* Update specific fields */
174    opr.NumVols = pr->NumVols;
175    opr.MaxVols = pr->MaxVols; 
176    opr.UseOnce = pr->UseOnce;
177    opr.UseCatalog = pr->UseCatalog;
178    opr.AcceptAnyVolume = pr->AcceptAnyVolume;
179    strcpy(opr.LabelFormat, pr->LabelFormat);
180
181    fseek(mdb->poolfd, opr.rec_addr, SEEK_SET);
182    if (fwrite(&opr, len, 1, mdb->poolfd) != 1) {
183       Mmsg1(&mdb->errmsg, _("Error updating DB Media file. ERR=%s\n"), strerror(errno));
184       stat = 0;
185    } else {
186       memcpy(pr, &opr, len);          /* return record written */
187    }
188    fflush(mdb->poolfd);
189
190    V(mdb->mutex);
191    return stat;
192 }
193
194 int db_add_MD5_to_file_record(B_DB *mdb, FileId_t FileId, char *MD5)   
195 {
196    return 1;
197 }
198
199 int db_mark_file_record(B_DB *mdb, FileId_t FileId, int JobId) 
200
201    return 1;
202 }
203
204
205 #endif /* HAVE_BACULA_DB */