]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/bdb_delete.c
Complete port to Windows
[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-2006 Kern Sibbald
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
21    version 2 as amended with additional clauses defined in the
22    file LICENSE in the main source directory.
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 
27    the file LICENSE for additional details.
28
29  */
30
31
32 /* The following is necessary so that we do not include
33  * the dummy external definition of DB.
34  */
35 #define __SQL_C                       /* indicate that this is sql.c */
36
37 #include "bacula.h"
38 #include "cats.h"
39 #include "bdb.h"
40
41 #ifdef HAVE_BACULA_DB
42
43 /* Forward referenced functions */
44
45 /* -----------------------------------------------------------------------
46  *
47  *   Bacula specific defines and subroutines
48  *
49  * -----------------------------------------------------------------------
50  */
51
52
53 /*
54  * Delete a Pool record given the Name
55  *
56  * Returns: 0 on error
57  *          the number of records deleted on success
58  */
59 int db_delete_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
60 {
61    int stat;
62    POOL_DBR opr;
63
64    db_lock(mdb);
65    pr->PoolId = 0;                    /* Search on Pool Name */
66    if (!db_get_pool_record(jcr, mdb, pr)) {
67       Mmsg1(&mdb->errmsg, "No pool record %s exists\n", pr->Name);
68       db_unlock(mdb);
69       return 0;
70    }
71    fseek(mdb->poolfd, pr->rec_addr, SEEK_SET);
72    memset(&opr, 0, sizeof(opr));
73    stat = fwrite(&opr, sizeof(opr), 1, mdb->poolfd);
74    db_unlock(mdb);
75    return stat;
76 }
77
78 int db_delete_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
79 {
80    int stat;
81    MEDIA_DBR omr;
82
83    db_lock(mdb);
84    if (!db_get_media_record(jcr, mdb, mr)) {
85       Mmsg0(&mdb->errmsg, "Media record not found.\n");
86       db_unlock(mdb);
87       return 0;
88    }
89    fseek(mdb->mediafd, mr->rec_addr, SEEK_SET);
90    memset(&omr, 0, sizeof(omr));
91    stat = fwrite(&omr, sizeof(omr), 1, mdb->mediafd);
92    db_unlock(mdb);
93    return stat;
94 }
95
96 #endif /* HAVE_BACULA_DB */