]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/bdb_update.c
Replace explicit checks for "/" with calls to IsPathSeparator, strchr with first_path...
[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 /* -----------------------------------------------------------------------
45  *
46  *   Bacula specific defines and subroutines
47  *
48  * -----------------------------------------------------------------------
49  */
50
51
52 /*
53  * This is called at Job start time to add the
54  * most current start fields to the job record.
55  * It is assumed that you did a db_create_job_record() already.
56  */
57 bool db_update_job_start_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
58 {
59    int len, stat = 1;
60    JOB_DBR ojr;
61
62    db_lock(mdb);
63
64    Dmsg0(200, "In db_update_job_start_record\n");
65    len = sizeof(ojr);
66    memcpy(&ojr, jr, len);
67
68    if (!db_get_job_record(jcr, mdb, &ojr)) {
69       db_unlock(mdb);
70       return 0;
71    }
72
73
74    fseek(mdb->jobfd, ojr.rec_addr, SEEK_SET);
75    if (fwrite(jr, len, 1, mdb->jobfd) != 1) {
76       Mmsg1(mdb->errmsg, _("Error updating DB Job file. ERR=%s\n"), strerror(errno));
77       stat = 0;
78    }
79    fflush(mdb->jobfd);
80
81    db_unlock(mdb);
82    return stat;
83 }
84
85 /*
86  * This is called at Job termination time to add all the
87  * other fields to the job record.
88  */
89 int db_update_job_end_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
90 {
91    int len, stat = 1;
92    JOB_DBR ojr;
93
94    db_lock(mdb);
95
96    Dmsg0(200, "In db_update_job_start_record\n");
97    len = sizeof(ojr);
98    memcpy(&ojr, jr, len);
99
100    if (!db_get_job_record(jcr, mdb, &ojr)) {
101       db_unlock(mdb);
102       return 0;
103    }
104
105    fseek(mdb->jobfd, ojr.rec_addr, SEEK_SET);
106    if (fwrite(jr, len, 1, mdb->jobfd) != 1) {
107       Mmsg1(&mdb->errmsg, _("Error updating DB Job file. ERR=%s\n"), strerror(errno));
108       stat = 0;
109    }
110    fflush(mdb->jobfd);
111
112    db_unlock(mdb);
113    return stat;
114 }
115
116
117 int db_update_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
118 {
119    int stat = 1;
120    MEDIA_DBR omr;
121    int len;
122
123    db_lock(mdb);
124    Dmsg0(200, "In db_update_media_record\n");
125    mr->MediaId = 0;
126    len = sizeof(omr);
127    memcpy(&omr, mr, len);
128
129    if (!db_get_media_record(jcr, mdb, &omr)) {
130       db_unlock(mdb);
131       return 0;
132    }
133
134
135    /* Don't allow some fields to change by copying from master record */
136    strcpy(mr->VolumeName, omr.VolumeName);
137    strcpy(mr->MediaType, omr.MediaType);
138    mr->MediaId = omr.MediaId;
139    mr->PoolId = omr.PoolId;
140    mr->MaxVolBytes = omr.MaxVolBytes;
141    mr->VolCapacityBytes = omr.VolCapacityBytes;
142    mr->Recycle = omr.Recycle;
143
144    fseek(mdb->mediafd, omr.rec_addr, SEEK_SET);
145    if (fwrite(mr, len, 1, mdb->mediafd) != 1) {
146       Mmsg1(mdb->errmsg, _("Error updating DB Media file. ERR=%s\n"), strerror(errno));
147       stat = 0;
148    }
149    fflush(mdb->mediafd);
150
151    db_unlock(mdb);
152    return stat;
153 }
154
155 int db_update_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
156 {
157    int stat = 1;
158    POOL_DBR opr;
159    int len;
160
161    db_lock(mdb);
162    Dmsg0(200, "In db_update_pool_record\n");
163    len = sizeof(opr);
164    memcpy(&opr, pr, len);
165
166    if (!db_get_pool_record(jcr, mdb, &opr)) {
167       db_unlock(mdb);
168       return 0;
169    }
170
171
172    /* Update specific fields */
173    opr.NumVols = pr->NumVols;
174    opr.MaxVols = pr->MaxVols;
175    opr.UseOnce = pr->UseOnce;
176    opr.UseCatalog = pr->UseCatalog;
177    opr.AcceptAnyVolume = pr->AcceptAnyVolume;
178    strcpy(opr.LabelFormat, pr->LabelFormat);
179
180    fseek(mdb->poolfd, opr.rec_addr, SEEK_SET);
181    if (fwrite(&opr, len, 1, mdb->poolfd) != 1) {
182       Mmsg1(mdb->errmsg, _("Error updating DB Media file. ERR=%s\n"), strerror(errno));
183       stat = 0;
184    } else {
185       memcpy(pr, &opr, len);          /* return record written */
186    }
187    fflush(mdb->poolfd);
188
189    db_unlock(mdb);
190    return stat;
191 }
192
193 int db_add_digest_to_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, char *digest, int type)
194 {
195    return 1;
196 }
197
198 int db_mark_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, JobId_t JobId)
199 {
200    return 1;
201 }
202
203 int db_update_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr)
204 {
205    return 1;
206 }
207
208 int db_update_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr)
209 {
210    return 0;
211 }
212
213 int db_update_media_defaults(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
214 {
215    return 1;
216 }
217
218 void db_make_inchanger_unique(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
219 {
220   return;
221 }
222
223 #endif /* HAVE_BACULA_DB */