]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/bdb_delete.c
Update bdb calling sequence
[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  *    Version $Id$
14  */
15
16 /*
17    Copyright (C) 2001-2003 Kern Sibbald and John Walker
18
19    This program is free software; you can redistribute it and/or
20    modify it under the terms of the GNU General Public License as
21    published by the Free Software Foundation; either version 2 of
22    the License, or (at your option) any later version.
23
24    This program is distributed in the hope that it will be useful,
25    but WITHOUT ANY WARRANTY; without even the implied warranty of
26    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27    General Public License for more details.
28
29    You should have received a copy of the GNU General Public
30    License along with this program; if not, write to the Free
31    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
32    MA 02111-1307, USA.
33
34  */
35
36
37 /* The following is necessary so that we do not include
38  * the dummy external definition of DB.
39  */
40 #define __SQL_C                       /* indicate that this is sql.c */
41
42 #include "bacula.h"
43 #include "cats.h"
44 #include "bdb.h"
45
46 #ifdef HAVE_BACULA_DB
47
48 /* Forward referenced functions */
49
50 /* -----------------------------------------------------------------------
51  *
52  *   Bacula specific defines and subroutines
53  *
54  * -----------------------------------------------------------------------
55  */
56
57
58 /*
59  * Delete a Pool record given the Name
60  *
61  * Returns: 0 on error
62  *          the number of records deleted on success 
63  */
64 int db_delete_pool_record(void *jcr, B_DB *mdb, POOL_DBR *pr)
65 {
66    int stat;
67    POOL_DBR opr;
68
69    pr->PoolId = 0;                    /* Search on Pool Name */
70    if (!db_get_pool_record(jcr, mdb, pr)) {
71       Mmsg1(&mdb->errmsg, "No pool record %s exists\n", pr->Name);
72       return 0;
73    }
74    db_lock(mdb);
75    fseek(mdb->poolfd, pr->rec_addr, SEEK_SET);
76    memset(&opr, 0, sizeof(opr));
77    stat = fwrite(&opr, sizeof(opr), 1, mdb->poolfd);
78    db_unlock(mdb);
79    return stat; 
80 }
81
82 int db_delete_media_record(void *jcr, B_DB *mdb, MEDIA_DBR *mr) 
83
84    int stat;
85    MEDIA_DBR omr;
86
87    if (!db_get_media_record(jcr, mdb, mr)) {
88       Mmsg0(&mdb->errmsg, "Media record not found.\n");
89       return 0;
90    }
91    db_lock(mdb);
92    fseek(mdb->mediafd, mr->rec_addr, SEEK_SET);
93    memset(&omr, 0, sizeof(omr));
94    stat = fwrite(&omr, sizeof(omr), 1, mdb->mediafd);
95    db_unlock(mdb);
96    return stat; 
97 }
98
99 #endif /* HAVE_BACULA_DB */