]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/bdb_get.c
Implement restore files
[bacula/bacula] / bacula / src / cats / bdb_get.c
index c94c3e73e9a8d0376af1e3e12c89e03984032007..e152c227ba3416c0ff016666a6ae60fe8cac2aea 100644 (file)
  *  system.
  *   
  *    Kern Sibbald, January MMI 
+ *
+ *    Version $Id$
  */
 
 /*
-   Copyright (C) 2001, 2002 Kern Sibbald and John Walker
+   Copyright (C) 2001-2003 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -47,8 +49,6 @@
 #ifdef HAVE_BACULA_DB
 
 /* Forward referenced functions */
-int db_get_media_record(B_DB *mdb, MEDIA_DBR *mr);
-int db_get_pool_record(B_DB *mdb, POOL_DBR *pr);
 
 
 /* -----------------------------------------------------------------------
@@ -65,7 +65,7 @@ int db_get_pool_record(B_DB *mdb, POOL_DBR *pr);
  *         1 on success
  */
 
-int db_get_job_record(B_DB *mdb, JOB_DBR *jr)
+int db_get_job_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
 { 
    JOB_DBR ojr;
    faddr_t rec_addr;
@@ -73,15 +73,15 @@ int db_get_job_record(B_DB *mdb, JOB_DBR *jr)
    int stat = 0;
    int len;
 
-   P(mdb->mutex);
+   db_lock(mdb);
    if (jr->JobId == 0 && jr->Name[0] == 0) { /* he wants # of Job records */
       jr->JobId = mdb->control.JobId;
-      V(mdb->mutex);
+      db_unlock(mdb);
       return 1;
    }
    Dmsg0(200, "Open Jobs\n");
    if (!bdb_open_jobs_file(mdb)) {
-      V(mdb->mutex);
+      db_unlock(mdb);
       return 0;
    }
    fseek(mdb->jobfd, 0L, SEEK_SET);   /* rewind file */
@@ -115,7 +115,7 @@ int db_get_job_record(B_DB *mdb, JOB_DBR *jr)
    if (!found) {
       strcpy(mdb->errmsg, "Job record not found.\n");
    }
-   V(mdb->mutex);
+   db_unlock(mdb);
    Dmsg1(200, "Return job stat=%d\n", stat);
    return stat;
 }
@@ -127,13 +127,13 @@ int db_get_job_record(B_DB *mdb, JOB_DBR *jr)
  * Returns: -1 on failure
  *         number on success
  */
-int db_get_num_pool_records(B_DB *mdb)
+int db_get_num_pool_records(JCR *jcr, B_DB *mdb)
 {
    int stat = 0;
 
-   P(mdb->mutex);
+   db_lock(mdb);
    stat = mdb->control.PoolId;
-   V(mdb->mutex);
+   db_unlock(mdb);
    return stat;
 }
 
@@ -144,17 +144,17 @@ int db_get_num_pool_records(B_DB *mdb)
  *  Returns 0: on failure
  *         1: on success
  */
-int db_get_pool_ids(B_DB *mdb, int *num_ids, uint32_t *ids[])
+int db_get_pool_ids(JCR *jcr, B_DB *mdb, int *num_ids, uint32_t *ids[])
 {
    int i = 0;
    uint32_t *id;
    POOL_DBR opr;
    int len;
 
-   P(mdb->mutex);
+   db_lock(mdb);
    *ids = NULL;
    if (!bdb_open_pools_file(mdb)) {
-      V(mdb->mutex);
+      db_unlock(mdb);
       return 0;
    }
    fseek(mdb->poolfd, 0L, SEEK_SET);   /* rewind file */
@@ -167,7 +167,7 @@ int db_get_pool_ids(B_DB *mdb, int *num_ids, uint32_t *ids[])
       id[i++] = opr.PoolId;
    }
    *ids = id;
-   V(mdb->mutex);
+   db_unlock(mdb);
    return 1;
 }
 
@@ -180,7 +180,7 @@ int db_get_pool_ids(B_DB *mdb, int *num_ids, uint32_t *ids[])
  * Returns: 0 on failure
  *         id on success 
  */
-int db_get_pool_record(B_DB *mdb, POOL_DBR *pr)
+int db_get_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
 {
    POOL_DBR opr;
    faddr_t rec_addr;
@@ -188,10 +188,10 @@ int db_get_pool_record(B_DB *mdb, POOL_DBR *pr)
    int stat = 0;
    int len;
 
-   P(mdb->mutex);
+   db_lock(mdb);
    Dmsg0(200, "Open pools\n");
    if (!bdb_open_pools_file(mdb)) {
-      V(mdb->mutex);
+      db_unlock(mdb);
       return 0;
    }
    fseek(mdb->poolfd, 0L, SEEK_SET);   /* rewind file */
@@ -225,7 +225,7 @@ int db_get_pool_record(B_DB *mdb, POOL_DBR *pr)
    if (!found) {
       strcpy(mdb->errmsg, "Pool record not found.\n");
    }
-   V(mdb->mutex);
+   db_unlock(mdb);
    Dmsg1(200, "Return pool stat=%d\n", stat);
    return stat;
 }
@@ -236,47 +236,54 @@ int db_get_pool_record(B_DB *mdb, POOL_DBR *pr)
  * Returns: -1 on failure
  *         number on success
  */
-int db_get_num_media_records(B_DB *mdb)
+int db_get_num_media_records(JCR *jcr, B_DB *mdb)
 {
    int stat = 0;
 
-   P(mdb->mutex);
+   db_lock(mdb);
    stat = mdb->control.MediaId;
-   V(mdb->mutex);
+   db_unlock(mdb);
    return stat;
 }
 
 /*
- * This function returns a list of all the Media record ids.
+ * This function returns a list of all the Media record ids 
+ *  for a specified PoolId
  *  The caller must free ids if non-NULL.
  *
  *  Returns 0: on failure
  *         1: on success
  */
-int db_get_media_ids(B_DB *mdb, int *num_ids, uint32_t *ids[])
+int db_get_media_ids(JCR *jcr, B_DB *mdb, uint32_t PoolId, int *num_ids, uint32_t *ids[])
 {
    int i = 0;
    uint32_t *id;
    MEDIA_DBR omr;
    int len;
 
-   P(mdb->mutex);
+   db_lock(mdb);
    *ids = NULL;
    if (!bdb_open_media_file(mdb)) {
-      V(mdb->mutex);
+      db_unlock(mdb);
       return 0;
    }
    fseek(mdb->mediafd, 0L, SEEK_SET);  /* rewind file */
    /* Linear search through Pool records
     */
    len = sizeof(omr);
+   if (mdb->control.MediaId == 0) {
+      db_unlock(mdb);
+      return 0;
+   }
    *num_ids = mdb->control.MediaId;
    id = (uint32_t *)malloc(*num_ids * sizeof(uint32_t));
    while (fread(&omr, len, 1, mdb->mediafd) > 0) {
-      id[i++] = omr.MediaId;
+      if (PoolId == omr.MediaId) {
+        id[i++] = omr.MediaId;
+      }
    }
    *ids = id;
-   V(mdb->mutex);
+   db_unlock(mdb);
    return 1;
 }
 
@@ -288,7 +295,7 @@ int db_get_media_ids(B_DB *mdb, int *num_ids, uint32_t *ids[])
  * Returns: 0 on failure
  *         id on success 
  */
-int db_get_media_record(B_DB *mdb, MEDIA_DBR *mr)
+int db_get_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
 {
    faddr_t rec_addr;
    int found = 0;
@@ -296,9 +303,9 @@ int db_get_media_record(B_DB *mdb, MEDIA_DBR *mr)
    int len;
    MEDIA_DBR omr;
 
-   P(mdb->mutex);
+   db_lock(mdb);
    if (!bdb_open_media_file(mdb)) {
-      V(mdb->mutex);
+      db_unlock(mdb);
       return 0;
    }
    fseek(mdb->mediafd, 0L, SEEK_SET);  /* rewind file */
@@ -336,7 +343,7 @@ int db_get_media_record(B_DB *mdb, MEDIA_DBR *mr)
    if (stat == 0) {
       strcpy(mdb->errmsg, "Could not find requested Media record.\n");
    }
-   V(mdb->mutex);
+   db_unlock(mdb);
    return stat;
 }
 
@@ -347,25 +354,25 @@ int db_get_media_record(B_DB *mdb, MEDIA_DBR *mr)
  *             Volumes are concatenated in VolumeNames
  *             separated by a vertical bar (|).
  */
-int db_get_job_volume_names(B_DB *mdb, uint32_t JobId, char *VolumeNames)
+int db_get_job_volume_names(JCR *jcr, B_DB *mdb, uint32_t JobId, POOLMEM **VolumeNames)
 {
    int found = 0;
    JOBMEDIA_DBR jm;
    MEDIA_DBR mr;
    int jmlen, mrlen;
 
-   P(mdb->mutex);
+   db_lock(mdb);
    if (!bdb_open_jobmedia_file(mdb)) {
-      V(mdb->mutex);
+      db_unlock(mdb);
       return 0;
    }
    if (!bdb_open_media_file(mdb)) {
-      V(mdb->mutex);
+      db_unlock(mdb);
       return 0;
    }
    jmlen = sizeof(jm);
    mrlen = sizeof(mr);
-   *VolumeNames = 0;
+   *VolumeNames[0] = 0;
    fseek(mdb->jobmediafd, 0L, SEEK_SET); /* rewind the file */
    while (fread(&jm, jmlen, 1, mdb->jobmediafd) > 0) {
       if (jm.JobId == JobId) {
@@ -373,10 +380,10 @@ int db_get_job_volume_names(B_DB *mdb, uint32_t JobId, char *VolumeNames)
         fseek(mdb->mediafd, 0L, SEEK_SET);
         while (fread(&mr, mrlen, 1, mdb->mediafd) > 0) {
            if (jm.MediaId == mr.MediaId) {
-              if (*VolumeNames != 0) {         /* if not first name, */
-                  strcat(VolumeNames, "|");     /* add separator */
+              if (*VolumeNames[0] != 0) {      /* if not first name, */
+                  pm_strcat(VolumeNames, "|");  /* add separator */
               }
-              strcat(VolumeNames, mr.VolumeName); /* add Volume Name */
+              pm_strcat(VolumeNames, mr.VolumeName); /* add Volume Name */
               found++;
            }
         }
@@ -385,7 +392,7 @@ int db_get_job_volume_names(B_DB *mdb, uint32_t JobId, char *VolumeNames)
    if (!found) {
       strcpy(mdb->errmsg, "No Volumes found.\n");
    }
-   V(mdb->mutex);
+   db_unlock(mdb);
    return found; 
 }
 
@@ -397,15 +404,15 @@ int db_get_job_volume_names(B_DB *mdb, uint32_t JobId, char *VolumeNames)
  * Returns: 0 on failure
  *         id on success 
  */
-int db_get_client_record(B_DB *mdb, CLIENT_DBR *cr)
+int db_get_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr)
 {
    CLIENT_DBR lcr;
    int len;
    int stat = 0;
 
-   P(mdb->mutex);
+   db_lock(mdb);
    if (!bdb_open_client_file(mdb)) {
-      V(mdb->mutex);
+      db_unlock(mdb);
       return 0;
    }
    fseek(mdb->clientfd, 0L, SEEK_SET);  /* rewind file */
@@ -432,7 +439,7 @@ int db_get_client_record(B_DB *mdb, CLIENT_DBR *cr)
    if (!stat) {
       strcpy(mdb->errmsg, "Client record not found.\n");
    }
-   V(mdb->mutex);
+   db_unlock(mdb);
    return stat;
 }
 
@@ -444,14 +451,14 @@ int db_get_client_record(B_DB *mdb, CLIENT_DBR *cr)
  * Returns: 0 on failure
  *         id on success 
  */
-int db_get_fileset_record(B_DB *mdb, FILESET_DBR *fsr)
+int db_get_fileset_record(JCR *jcr, B_DB *mdb, FILESET_DBR *fsr)
 {
    FILESET_DBR lfsr;
    int stat = 0;
 
-   P(mdb->mutex);
+   db_lock(mdb);
    if (!bdb_open_fileset_file(mdb)) {
-      V(mdb->mutex);
+      db_unlock(mdb);
       return 0;
    }
    fseek(mdb->filesetfd, 0L, SEEK_SET);   /* rewind file */
@@ -479,15 +486,23 @@ int db_get_fileset_record(B_DB *mdb, FILESET_DBR *fsr)
    if (!stat) {
       strcpy(mdb->errmsg, "FileSet record not found.\n");
    }
-   V(mdb->mutex);
+   db_unlock(mdb);
    return stat;
 }
 
 
 
-int db_get_file_attributes_record(B_DB *mdb, char *fname, FILE_DBR *fdbr) 
+int db_get_file_attributes_record(JCR *jcr, B_DB *mdb, char *fname, FILE_DBR *fdbr) 
 { return 0; }
 
+int db_get_job_volume_parameters(JCR *jcr, B_DB *mdb, uint32_t JobId, VOL_PARAMS **VolParams)
+{ return 0; }
+
+int db_get_client_ids(JCR *jcr, B_DB *mdb, int *num_ids, uint32_t *ids[])
+{ return 0; }
+
+int db_get_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr)
+{ return 0; }
 
 
 #endif /* HAVE_BACULA_DB */