]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/bdb_update.c
35fa610a89bfa3b6d9a5c38fdbc76c70835fa5a3
[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-2006 Kern Sibbald
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
22    version 2 as amended with additional clauses defined in the
23    file LICENSE in the main source directory.
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 
28    the file LICENSE for additional details.
29
30  */
31
32
33 /* The following is necessary so that we do not include
34  * the dummy external definition of DB.
35  */
36 #define __SQL_C                       /* indicate that this is sql.c */
37
38 #include "bacula.h"
39 #include "cats.h"
40 #include "bdb.h"
41
42 #ifdef HAVE_BACULA_DB
43
44 /* Forward referenced functions */
45
46 /* -----------------------------------------------------------------------
47  *
48  *   Bacula specific defines and subroutines
49  *
50  * -----------------------------------------------------------------------
51  */
52
53
54 /*
55  * This is called at Job start time to add the
56  * most current start fields to the job record.
57  * It is assumed that you did a db_create_job_record() already.
58  */
59 bool db_update_job_start_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
60 {
61    int len, stat = 1;
62    JOB_DBR ojr;
63
64    db_lock(mdb);
65
66    Dmsg0(200, "In db_update_job_start_record\n");
67    len = sizeof(ojr);
68    memcpy(&ojr, jr, len);
69
70    if (!db_get_job_record(jcr, mdb, &ojr)) {
71       db_unlock(mdb);
72       return 0;
73    }
74
75
76    fseek(mdb->jobfd, ojr.rec_addr, SEEK_SET);
77    if (fwrite(jr, len, 1, mdb->jobfd) != 1) {
78       Mmsg1(mdb->errmsg, _("Error updating DB Job file. ERR=%s\n"), strerror(errno));
79       stat = 0;
80    }
81    fflush(mdb->jobfd);
82
83    db_unlock(mdb);
84    return stat;
85 }
86
87 /*
88  * This is called at Job termination time to add all the
89  * other fields to the job record.
90  */
91 int db_update_job_end_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
92 {
93    int len, stat = 1;
94    JOB_DBR ojr;
95
96    db_lock(mdb);
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(jcr, mdb, &ojr)) {
103       db_unlock(mdb);
104       return 0;
105    }
106
107    fseek(mdb->jobfd, ojr.rec_addr, SEEK_SET);
108    if (fwrite(jr, len, 1, mdb->jobfd) != 1) {
109       Mmsg1(&mdb->errmsg, _("Error updating DB Job file. ERR=%s\n"), strerror(errno));
110       stat = 0;
111    }
112    fflush(mdb->jobfd);
113
114    db_unlock(mdb);
115    return stat;
116 }
117
118
119 int db_update_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
120 {
121    int stat = 1;
122    MEDIA_DBR omr;
123    int len;
124
125    db_lock(mdb);
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(jcr, mdb, &omr)) {
132       db_unlock(mdb);
133       return 0;
134    }
135
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->MaxVolBytes = omr.MaxVolBytes;
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    db_unlock(mdb);
154    return stat;
155 }
156
157 int db_update_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
158 {
159    int stat = 1;
160    POOL_DBR opr;
161    int len;
162
163    db_lock(mdb);
164    Dmsg0(200, "In db_update_pool_record\n");
165    len = sizeof(opr);
166    memcpy(&opr, pr, len);
167
168    if (!db_get_pool_record(jcr, mdb, &opr)) {
169       db_unlock(mdb);
170       return 0;
171    }
172
173
174    /* Update specific fields */
175    opr.NumVols = pr->NumVols;
176    opr.MaxVols = pr->MaxVols;
177    opr.UseOnce = pr->UseOnce;
178    opr.UseCatalog = pr->UseCatalog;
179    opr.AcceptAnyVolume = pr->AcceptAnyVolume;
180    strcpy(opr.LabelFormat, pr->LabelFormat);
181
182    fseek(mdb->poolfd, opr.rec_addr, SEEK_SET);
183    if (fwrite(&opr, len, 1, mdb->poolfd) != 1) {
184       Mmsg1(mdb->errmsg, _("Error updating DB Media file. ERR=%s\n"), strerror(errno));
185       stat = 0;
186    } else {
187       memcpy(pr, &opr, len);          /* return record written */
188    }
189    fflush(mdb->poolfd);
190
191    db_unlock(mdb);
192    return stat;
193 }
194
195 int db_add_digest_to_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, char *digest, int type)
196 {
197    return 1;
198 }
199
200 int db_mark_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, JobId_t JobId)
201 {
202    return 1;
203 }
204
205 int db_update_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr)
206 {
207    return 1;
208 }
209
210 int db_update_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr)
211 {
212    return 0;
213 }
214
215 int db_update_media_defaults(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
216 {
217    return 1;
218 }
219
220
221 #endif /* HAVE_BACULA_DB */