]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/bdb_update.c
1.19 24Apr02
[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 /*
15    Copyright (C) 2001, 2002 Kern Sibbald and John Walker
16
17    This program is free software; you can redistribute it and/or
18    modify it under the terms of the GNU General Public License as
19    published by the Free Software Foundation; either version 2 of
20    the License, or (at your option) any later version.
21
22    This program is distributed in the hope that it will be useful,
23    but WITHOUT ANY WARRANTY; without even the implied warranty of
24    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25    General Public License for more details.
26
27    You should have received a copy of the GNU General Public
28    License along with this program; if not, write to the Free
29    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30    MA 02111-1307, USA.
31
32  */
33
34
35 /* The following is necessary so that we do not include
36  * the dummy external definition of DB.
37  */
38 #define __SQL_C                       /* indicate that this is sql.c */
39
40 #include "bacula.h"
41 #include "cats.h"
42 #include "bdb.h"
43
44 #ifdef HAVE_BACULA_DB
45
46 /* Forward referenced functions */
47
48 /* -----------------------------------------------------------------------
49  *
50  *   Bacula specific defines and subroutines
51  *
52  * -----------------------------------------------------------------------
53  */
54
55
56 /*
57  * This is called at Job start time to add the
58  * most current start fields to the job record.
59  * It is assumed that you did a db_create_job_record() already.
60  */
61 int db_update_job_start_record(B_DB *mdb, JOB_DBR *jr)    
62 {
63    int len, stat;
64    JOB_DBR ojr;
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(mdb, &ojr)) {
71       return 0;
72    }
73
74    P(mdb->mutex);
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    V(mdb->mutex);
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(B_DB *mdb, JOB_DBR *jr)    
92 {
93    int len, stat;
94    JOB_DBR ojr;
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(mdb, &ojr)) {
101       return 0;
102    }
103
104    P(mdb->mutex);
105
106    fseek(mdb->jobfd, ojr.rec_addr, SEEK_SET);
107    if (fwrite(jr, len, 1, mdb->jobfd) != 1) {
108       Mmsg1(&mdb->errmsg, _("Error updating DB Job file. ERR=%s\n"), strerror(errno));
109       stat = 0;
110    }
111    fflush(mdb->jobfd);
112
113    V(mdb->mutex);
114    return stat;
115 }
116
117
118 int db_update_media_record(B_DB *mdb, MEDIA_DBR *mr) 
119
120    int stat = 1;
121    MEDIA_DBR omr;
122    int len;
123        
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(mdb, &omr)) {
130       return 0;
131    }
132
133    P(mdb->mutex);
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->VolMaxBytes = omr.VolMaxBytes;
141    mr->VolCapacityBytes = omr.VolCapacityBytes;
142    strcpy(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    V(mdb->mutex);
152    return stat;
153 }
154
155 int db_update_pool_record(B_DB *mdb, POOL_DBR *pr) 
156
157    int stat = 1;
158    POOL_DBR opr;
159    int len;
160        
161    Dmsg0(200, "In db_update_pool_record\n");
162    len = sizeof(opr);
163    memcpy(&opr, pr, len);
164
165    if (!db_get_pool_record(mdb, &opr)) {
166       return 0;
167    }
168
169    P(mdb->mutex);
170
171    /* Update specific fields */
172    opr.NumVols = pr->NumVols;
173    opr.MaxVols = pr->MaxVols; 
174    opr.UseOnce = pr->UseOnce;
175    opr.UseCatalog = pr->UseCatalog;
176    opr.AcceptAnyVolume = pr->AcceptAnyVolume;
177    strcpy(opr.LabelFormat, pr->LabelFormat);
178
179    fseek(mdb->poolfd, opr.rec_addr, SEEK_SET);
180    if (fwrite(&opr, len, 1, mdb->poolfd) != 1) {
181       Mmsg1(&mdb->errmsg, _("Error updating DB Media file. ERR=%s\n"), strerror(errno));
182       stat = 0;
183    } else {
184       memcpy(pr, &opr, len);          /* return record written */
185    }
186    fflush(mdb->poolfd);
187
188    V(mdb->mutex);
189    return stat;
190 }
191
192 int db_add_MD5_to_file_record(B_DB *mdb, FileId_t FileId, char *MD5)   
193 {
194    return 1;
195 }
196
197 int db_mark_file_record(B_DB *mdb, FileId_t FileId, int JobId) 
198
199    return 1;
200 }
201
202
203 #endif /* HAVE_BACULA_DB */