]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/bdb_delete.c
1.19 24Apr02
[bacula/bacula] / bacula / src / cats / bdb_delete.c
1 /*
2  * Bacula Catalog Database Delete 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  * Delete a Pool record given the Name
58  *
59  * Returns: 0 on error
60  *          the number of records deleted on success 
61  */
62 int db_delete_pool_record(B_DB *mdb, POOL_DBR *pr)
63 {
64    int stat;
65    POOL_DBR opr;
66
67    pr->PoolId = 0;                    /* Search on Pool Name */
68    if (!db_get_pool_record(mdb, pr)) {
69       Mmsg1(&mdb->errmsg, "No pool record %s exists\n", pr->Name);
70       return 0;
71    }
72    P(mdb->mutex);
73    fseek(mdb->poolfd, pr->rec_addr, SEEK_SET);
74    memset(&opr, 0, sizeof(opr));
75    stat = fwrite(&opr, sizeof(opr), 1, mdb->poolfd);
76    V(mdb->mutex);
77    return stat; 
78 }
79
80 int db_delete_media_record(B_DB *mdb, MEDIA_DBR *mr) 
81
82    int stat;
83    MEDIA_DBR omr;
84
85    if (!db_get_media_record(mdb, mr)) {
86       Mmsg0(&mdb->errmsg, "Media record not found.\n");
87       return 0;
88    }
89    P(mdb->mutex);
90    fseek(mdb->mediafd, mr->rec_addr, SEEK_SET);
91    memset(&omr, 0, sizeof(omr));
92    stat = fwrite(&omr, sizeof(omr), 1, mdb->mediafd);
93    V(mdb->mutex);
94    return stat; 
95 }
96
97 #endif /* HAVE_BACULA_DB */