*/
/*
- 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
#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);
/* -----------------------------------------------------------------------
* 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;
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 */
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;
}
* 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;
}
* 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 */
id[i++] = opr.PoolId;
}
*ids = id;
- V(mdb->mutex);
+ db_unlock(mdb);
return 1;
}
* 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;
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 */
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;
}
* 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;
}
* 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;
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 */
if (stat == 0) {
strcpy(mdb->errmsg, "Could not find requested Media record.\n");
}
- V(mdb->mutex);
+ db_unlock(mdb);
return stat;
}
* 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) {
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++;
}
}
if (!found) {
strcpy(mdb->errmsg, "No Volumes found.\n");
}
- V(mdb->mutex);
+ db_unlock(mdb);
return found;
}
* 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 */
if (!stat) {
strcpy(mdb->errmsg, "Client record not found.\n");
}
- V(mdb->mutex);
+ db_unlock(mdb);
return stat;
}
* 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 */
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 */