]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/bdb_update.c
Update bdb calling sequence
[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 int db_update_job_start_record(void *jcr, B_DB *mdb, JOB_DBR *jr)    
65 {
66    int len, stat = 1;
67    JOB_DBR ojr;
68
69    Dmsg0(200, "In db_update_job_start_record\n");
70    len = sizeof(ojr);
71    memcpy(&ojr, jr, len);
72
73    if (!db_get_job_record(jcr, mdb, &ojr)) {
74       return 0;
75    }
76
77    db_lock(mdb);
78
79    fseek(mdb->jobfd, ojr.rec_addr, SEEK_SET);
80    if (fwrite(jr, len, 1, mdb->jobfd) != 1) {
81       Mmsg1(&mdb->errmsg, _("Error updating DB Job file. ERR=%s\n"), strerror(errno));
82       stat = 0;
83    }
84    fflush(mdb->jobfd);
85
86    db_unlock(mdb);
87    return stat;
88 }
89
90 /*
91  * This is called at Job termination time to add all the
92  * other fields to the job record.
93  */
94 int db_update_job_end_record(void *jcr, B_DB *mdb, JOB_DBR *jr)    
95 {
96    int len, stat = 1;
97    JOB_DBR ojr;
98
99    Dmsg0(200, "In db_update_job_start_record\n");
100    len = sizeof(ojr);
101    memcpy(&ojr, jr, len);
102
103    if (!db_get_job_record(jcr, mdb, &ojr)) {
104       return 0;
105    }
106
107    db_lock(mdb);
108
109    fseek(mdb->jobfd, ojr.rec_addr, SEEK_SET);
110    if (fwrite(jr, len, 1, mdb->jobfd) != 1) {
111       Mmsg1(&mdb->errmsg, _("Error updating DB Job file. ERR=%s\n"), strerror(errno));
112       stat = 0;
113    }
114    fflush(mdb->jobfd);
115
116    db_unlock(mdb);
117    return stat;
118 }
119
120
121 int db_update_media_record(void *jcr, B_DB *mdb, MEDIA_DBR *mr) 
122
123    int stat = 1;
124    MEDIA_DBR omr;
125    int len;
126        
127    Dmsg0(200, "In db_update_media_record\n");
128    mr->MediaId = 0;
129    len = sizeof(omr);
130    memcpy(&omr, mr, len);
131
132    if (!db_get_media_record(jcr, mdb, &omr)) {
133       return 0;
134    }
135
136    db_lock(mdb);
137
138    /* Don't allow some fields to change by copying from master record */
139    strcpy(mr->VolumeName, omr.VolumeName);
140    strcpy(mr->MediaType, omr.MediaType);
141    mr->MediaId = omr.MediaId;
142    mr->PoolId = omr.PoolId;
143    mr->MaxVolBytes = omr.MaxVolBytes;
144    mr->VolCapacityBytes = omr.VolCapacityBytes;
145    mr->Recycle = omr.Recycle;
146
147    fseek(mdb->mediafd, omr.rec_addr, SEEK_SET);
148    if (fwrite(mr, len, 1, mdb->mediafd) != 1) {
149       Mmsg1(&mdb->errmsg, _("Error updating DB Media file. ERR=%s\n"), strerror(errno));
150       stat = 0;
151    }
152    fflush(mdb->mediafd);
153
154    db_unlock(mdb);
155    return stat;
156 }
157
158 int db_update_pool_record(void *jcr, B_DB *mdb, POOL_DBR *pr) 
159
160    int stat = 1;
161    POOL_DBR opr;
162    int len;
163        
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       return 0;
170    }
171
172    db_lock(mdb);
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_MD5_to_file_record(void *jcr, B_DB *mdb, FileId_t FileId, char *MD5)   
196 {
197    return 1;
198 }
199
200 int db_mark_file_record(void *jcr, B_DB *mdb, FileId_t FileId, JobId_t JobId)
201
202    return 1;
203 }
204
205
206 #endif /* HAVE_BACULA_DB */