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