From: Kern S. <ke...@us...> - 2005-09-29 08:56:49
|
Update of /cvsroot/bacula/bacula/src/cats In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4026/src/cats Modified Files: bdb.c bdb_find.c bdb_get.c Log Message: Bring cats/bdb_x.c routines up to version 1.37 (return values are different). Index: bdb.c =================================================================== RCS file: /cvsroot/bacula/bacula/src/cats/bdb.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- bdb.c 21 Dec 2004 16:18:30 -0000 1.22 +++ bdb.c 29 Sep 2005 08:56:38 -0000 1.23 @@ -11,25 +11,18 @@ * Version $Id$ * */ - - /* - Copyright (C) 2001-2003 Kern Sibbald and John Walker + Copyright (C) 2000-2005 Kern Sibbald This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ @@ -37,7 +30,7 @@ /* The following is necessary so that we do not include * the dummy external definition of DB. */ -#define __SQL_C /* indicate that this is sql.c */ +#define __SQL_C /* indicate that this is sql.c */ #include "bacula.h" #include "cats.h" @@ -103,18 +96,18 @@ */ B_DB * db_init_database(JCR *jcr, char const *db_name, char const *db_user, char const *db_password, - char const *db_address, int db_port, char const *db_socket, - int mult_db_connections) + char const *db_address, int db_port, char const *db_socket, + int mult_db_connections) { B_DB *mdb; - P(mutex); /* lock DB queue */ + P(mutex); /* lock DB queue */ /* Look to see if DB already open */ for (mdb=NULL; (mdb=(B_DB *)qnext(&db_list, &mdb->bq)); ) { if (strcmp(mdb->db_name, db_name) == 0) { - Dmsg2(200, "DB REopen %d %s\n", mdb->ref_count, db_name); - mdb->ref_count++; - V(mutex); - return mdb; /* already open */ + Dmsg2(200, "DB REopen %d %s\n", mdb->ref_count, db_name); + mdb->ref_count++; + V(mutex); + return mdb; /* already open */ } } Dmsg0(200, "db_open first time\n"); @@ -167,14 +160,14 @@ free_memory(dbf); if (mdb->cfd < 0) { Mmsg2(&mdb->errmsg, _("Unable to open Catalog DB control file %s: ERR=%s\n"), - dbf, strerror(errno)); + dbf, strerror(errno)); V(mutex); return 0; } Dmsg0(200, "DB open\n"); /* See if the file was previously written */ filend = lseek(mdb->cfd, 0, SEEK_END); - if (filend == 0) { /* No, initialize everything */ + if (filend == 0) { /* No, initialize everything */ Dmsg0(200, "Init DB files\n"); memset(&mdb->control, 0, sizeof(mdb->control)); mdb->control.bdb_version = BDB_VERSION; @@ -227,7 +220,7 @@ Mmsg2(&mdb->errmsg, _("Error, catalog DB control file wrong version. " "Wanted %d, got %d\n" "Please reinitialize the working directory.\n"), - BDB_VERSION, mdb->control.bdb_version); + BDB_VERSION, mdb->control.bdb_version); badctl = 1; } bacula_db_version = mdb->control.bdb_version; @@ -247,26 +240,26 @@ qdchain(&mdb->bq); /* close file descriptors */ if (mdb->cfd >= 0) { - close(mdb->cfd); + close(mdb->cfd); } free(mdb->db_name); if (mdb->jobfd) { - fclose(mdb->jobfd); + fclose(mdb->jobfd); } if (mdb->poolfd) { - fclose(mdb->poolfd); + fclose(mdb->poolfd); } if (mdb->mediafd) { - fclose(mdb->mediafd); + fclose(mdb->mediafd); } if (mdb->jobmediafd) { - fclose(mdb->jobmediafd); + fclose(mdb->jobmediafd); } if (mdb->clientfd) { - fclose(mdb->clientfd); + fclose(mdb->clientfd); } if (mdb->filesetfd) { - fclose(mdb->filesetfd); + fclose(mdb->filesetfd); } rwl_destroy(&mdb->lock); free_pool_memory(mdb->errmsg); @@ -305,11 +298,11 @@ dbf = make_filename(mdb, DB_JOBS_FILENAME); mdb->jobfd = fopen(dbf, "r+"); if (!mdb->jobfd) { - Mmsg2(&mdb->errmsg, "Error opening DB Jobs file %s: ERR=%s\n", - dbf, strerror(errno)); - Emsg0(M_FATAL, 0, mdb->errmsg); - free_memory(dbf); - return 0; + Mmsg2(&mdb->errmsg, "Error opening DB Jobs file %s: ERR=%s\n", + dbf, strerror(errno)); + Emsg0(M_FATAL, 0, mdb->errmsg); + free_memory(dbf); + return 0; } free_memory(dbf); } @@ -327,11 +320,11 @@ dbf = make_filename(mdb, DB_JOBMEDIA_FILENAME); mdb->jobmediafd = fopen(dbf, "r+"); if (!mdb->jobmediafd) { - Mmsg2(&mdb->errmsg, "Error opening DB JobMedia file %s: ERR=%s\n", - dbf, strerror(errno)); - Emsg0(M_FATAL, 0, mdb->errmsg); - free_memory(dbf); - return 0; + Mmsg2(&mdb->errmsg, "Error opening DB JobMedia file %s: ERR=%s\n", + dbf, strerror(errno)); + Emsg0(M_FATAL, 0, mdb->errmsg); + free_memory(dbf); + return 0; } free_memory(dbf); } @@ -350,11 +343,11 @@ dbf = make_filename(mdb, DB_POOLS_FILENAME); mdb->poolfd = fopen(dbf, "r+"); if (!mdb->poolfd) { - Mmsg2(&mdb->errmsg, "Error opening DB Pools file %s: ERR=%s\n", - dbf, strerror(errno)); - Emsg0(M_FATAL, 0, mdb->errmsg); - free_memory(dbf); - return 0; + Mmsg2(&mdb->errmsg, "Error opening DB Pools file %s: ERR=%s\n", + dbf, strerror(errno)); + Emsg0(M_FATAL, 0, mdb->errmsg); + free_memory(dbf); + return 0; } Dmsg1(200, "Opened pool file %s\n", dbf); free_memory(dbf); @@ -373,11 +366,11 @@ dbf = make_filename(mdb, DB_CLIENT_FILENAME); mdb->clientfd = fopen(dbf, "r+"); if (!mdb->clientfd) { - Mmsg2(&mdb->errmsg, "Error opening DB Clients file %s: ERR=%s\n", - dbf, strerror(errno)); - Emsg0(M_FATAL, 0, mdb->errmsg); - free_memory(dbf); - return 0; + Mmsg2(&mdb->errmsg, "Error opening DB Clients file %s: ERR=%s\n", + dbf, strerror(errno)); + Emsg0(M_FATAL, 0, mdb->errmsg); + free_memory(dbf); + return 0; } free_memory(dbf); } @@ -395,11 +388,11 @@ dbf = make_filename(mdb, DB_CLIENT_FILENAME); mdb->filesetfd = fopen(dbf, "r+"); if (!mdb->filesetfd) { - Mmsg2(&mdb->errmsg, "Error opening DB FileSet file %s: ERR=%s\n", - dbf, strerror(errno)); - Emsg0(M_FATAL, 0, mdb->errmsg); - free_memory(dbf); - return 0; + Mmsg2(&mdb->errmsg, "Error opening DB FileSet file %s: ERR=%s\n", + dbf, strerror(errno)); + Emsg0(M_FATAL, 0, mdb->errmsg); + free_memory(dbf); + return 0; } free_memory(dbf); } @@ -419,10 +412,10 @@ dbf = make_filename(mdb, DB_MEDIA_FILENAME); mdb->mediafd = fopen(dbf, "r+"); if (!mdb->mediafd) { - Mmsg2(&mdb->errmsg, "Error opening DB Media file %s: ERR=%s\n", - dbf, strerror(errno)); - free_memory(dbf); - return 0; + Mmsg2(&mdb->errmsg, "Error opening DB Media file %s: ERR=%s\n", + dbf, strerror(errno)); + free_memory(dbf); + return 0; } free_memory(dbf); } @@ -435,7 +428,7 @@ int errstat; if ((errstat=rwl_writelock(&mdb->lock)) != 0) { e_msg(file, line, M_ABORT, 0, "rwl_writelock failure. ERR=%s\n", - strerror(errstat)); + strerror(errstat)); } } @@ -444,7 +437,7 @@ int errstat; if ((errstat=rwl_writeunlock(&mdb->lock)) != 0) { e_msg(file, line, M_ABORT, 0, "rwl_writeunlock failure. ERR=%s\n", - strerror(errstat)); + strerror(errstat)); } } @@ -461,5 +454,12 @@ { } +bool db_update_storage_record(JCR *jcr, B_DB *mdb, STORAGE_DBR *sr) +{ return true; } + +void +db_list_pool_records(JCR *jcr, B_DB *mdb, POOL_DBR *pdbr, + DB_LIST_HANDLER *sendit, void *ctx, e_list_type type) +{ } #endif /* HAVE_BACULA_DB */ Index: bdb_find.c =================================================================== RCS file: /cvsroot/bacula/bacula/src/cats/bdb_find.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- bdb_find.c 21 Dec 2004 16:18:30 -0000 1.14 +++ bdb_find.c 29 Sep 2005 08:56:38 -0000 1.15 @@ -2,8 +2,8 @@ * Bacula Catalog Database Find record interface routines * * Note, generally, these routines are more complicated - * that a simple search by name or id. Such simple - * request are in get.c + * that a simple search by name or id. Such simple + * request are in get.c * * Bacula Catalog Database routines written specifically * for Bacula. Note, these routines are VERY dumb and @@ -40,7 +40,7 @@ /* The following is necessary so that we do not include * the dummy external definition of DB. */ -#define __SQL_C /* indicate that this is sql.c */ +#define __SQL_C /* indicate that this is sql.c */ #include "bacula.h" #include "cats.h" @@ -63,16 +63,15 @@ * so we can do Incremental and Differential saves. * * Returns: 0 on failure - * 1 on success, jr unchanged, but stime set + * 1 on success, jr unchanged, but stime set */ -int db_find_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime) +bool db_find_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime) { char cmd[MAXSTRING], Name[MAX_NAME_LENGTH], StartTime[MAXSTRING]; int Type, Level; uint32_t JobId, EndId, ClientId; char cType[10], cLevel[10], JobStatus[10]; - int stat = 0; - int found; + bool found = false; long addr; db_lock(mdb); @@ -88,51 +87,50 @@ while (fgets(cmd, sizeof(cmd), mdb->jobfd)) { if (sscanf(cmd, "JobStart JobId=%d Name=%127s Type=%1s Level=%1s " "StartTime=%100s", &JobId, Name, cType, cLevel, StartTime) == 5) { - if (JobId < jr->JobId) { - continue; /* older not a candidate */ - } - Type = cType[0]; - Level = cLevel[0]; - unbash_spaces(Name); - unbash_spaces(StartTime); - Dmsg4(200, "Got Type=%c Level=%c Name=%s StartTime=%s\n", - Type, Level, Name, StartTime); - Dmsg3(200, "Want Type=%c Level=%c Name=%s\n", jr->JobType, jr->JobLevel, - jr->Name); - /* Differential is since last Full backup */ - /* Incremental is since last FULL or Incremental or Differential */ - if (((jr->JobLevel == L_DIFFERENTIAL) && (Type == jr->JobType && - Level == L_FULL && strcmp(Name, jr->Name) == 0)) || - ((jr->JobLevel == L_INCREMENTAL) && (Type == jr->JobType && - (Level == L_FULL || Level == L_INCREMENTAL || - Level == L_DIFFERENTIAL) && strcmp(Name, jr->Name) == 0))) { - addr = ftell(mdb->jobfd); /* save current location */ - JobStatus[0] = 0; - found = 0; - /* Search for matching JobEnd record */ - while (!found && fgets(cmd, sizeof(cmd), mdb->jobfd)) { - if (sscanf(cmd, "JobEnd JobId=%d JobStatus=%1s ClientId=%d", - &EndId, JobStatus, &ClientId) == 3) { - if (EndId == JobId && *JobStatus == 'T' && ClientId == jr->ClientId) { - Dmsg0(200, "====found EndJob matching Job\n"); - found = 1; - break; - } - } - } - /* Reset for next read */ - fseek(mdb->jobfd, addr, SEEK_SET); - if (found) { - pm_strcpy(stime, StartTime); - stat = 1; /* Got a candidate */ - Dmsg5(200, "Got candidate JobId=%d Type=%c Level=%c Name=%s StartTime=%s\n", - JobId, Type, Level, Name, StartTime); - } - } + if (JobId < jr->JobId) { + continue; /* older not a candidate */ + } + Type = cType[0]; + Level = cLevel[0]; + unbash_spaces(Name); + unbash_spaces(StartTime); + Dmsg4(200, "Got Type=%c Level=%c Name=%s StartTime=%s\n", + Type, Level, Name, StartTime); + Dmsg3(200, "Want Type=%c Level=%c Name=%s\n", jr->JobType, jr->JobLevel, + jr->Name); + /* Differential is since last Full backup */ + /* Incremental is since last FULL or Incremental or Differential */ + if (((jr->JobLevel == L_DIFFERENTIAL) && (Type == jr->JobType && + Level == L_FULL && strcmp(Name, jr->Name) == 0)) || + ((jr->JobLevel == L_INCREMENTAL) && (Type == jr->JobType && + (Level == L_FULL || Level == L_INCREMENTAL || + Level == L_DIFFERENTIAL) && strcmp(Name, jr->Name) == 0))) { + addr = ftell(mdb->jobfd); /* save current location */ + JobStatus[0] = 0; + found = false; + /* Search for matching JobEnd record */ + while (!found && fgets(cmd, sizeof(cmd), mdb->jobfd)) { + if (sscanf(cmd, "JobEnd JobId=%d JobStatus=%1s ClientId=%d", + &EndId, JobStatus, &ClientId) == 3) { + if (EndId == JobId && *JobStatus == 'T' && ClientId == jr->ClientId) { + Dmsg0(200, "====found EndJob matching Job\n"); + found = true; + break; + } + } + } + /* Reset for next read */ + fseek(mdb->jobfd, addr, SEEK_SET); + if (found) { + pm_strcpy(stime, StartTime); + Dmsg5(200, "Got candidate JobId=%d Type=%c Level=%c Name=%s StartTime=%s\n", + JobId, Type, Level, Name, StartTime); + } + } } } db_unlock(mdb); - return stat; + return found; } @@ -144,7 +142,7 @@ * Note! this does not correctly implement InChanger. * * Returns: 0 on failure - * numrows on success + * numrows on success */ int db_find_next_volume(JCR *jcr, B_DB *mdb, int item, bool InChanger, MEDIA_DBR *mr) @@ -159,20 +157,20 @@ db_unlock(mdb); return 0; } - fseek(mdb->mediafd, 0L, SEEK_SET); /* rewind file */ + fseek(mdb->mediafd, 0L, SEEK_SET); /* rewind file */ len = sizeof(omr); while (fread(&omr, len, 1, mdb->mediafd) > 0) { if (mr->PoolId == omr.PoolId && strcmp(mr->VolStatus, omr.VolStatus) == 0 && - strcmp(mr->MediaType, omr.MediaType) == 0) { - if (!(++index == item)) { /* looking for item'th entry */ - Dmsg0(200, "Media record matches, but not index\n"); - continue; - } - Dmsg0(200, "Media record matches\n"); - memcpy(mr, &omr, len); - Dmsg1(200, "Findnextvol MediaId=%d\n", mr->MediaId); - stat = 1; - break; /* found it */ + strcmp(mr->MediaType, omr.MediaType) == 0) { + if (!(++index == item)) { /* looking for item'th entry */ + Dmsg0(200, "Media record matches, but not index\n"); + continue; + } + Dmsg0(200, "Media record matches\n"); + memcpy(mr, &omr, len); + Dmsg1(200, "Findnextvol MediaId=%d\n", mr->MediaId); + stat = 1; + break; /* found it */ } } db_unlock(mdb); Index: bdb_get.c =================================================================== RCS file: /cvsroot/bacula/bacula/src/cats/bdb_get.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- bdb_get.c 21 Dec 2004 16:18:30 -0000 1.15 +++ bdb_get.c 29 Sep 2005 08:56:38 -0000 1.16 @@ -1,8 +1,8 @@ /* * Bacula Catalog Database Get record interface routines * Note, these routines generally get a record by id or - * by name. If more logic is involved, the routine - * should be in find.c + * by name. If more logic is involved, the routine + * should be in find.c * * Bacula Catalog Database routines written specifically * for Bacula. Note, these routines are VERY dumb and @@ -40,7 +40,7 @@ /* The following is necessary so that we do not include * the dummy external definition of DB. */ -#define __SQL_C /* indicate that this is sql.c */ +#define __SQL_C /* indicate that this is sql.c */ #include "bacula.h" #include "cats.h" @@ -62,7 +62,7 @@ /* * Get Job record for given JobId * Returns: 0 on failure - * 1 on success + * 1 on success */ int db_get_job_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr) @@ -92,24 +92,24 @@ while (fread(&ojr, len, 1, mdb->jobfd) > 0) { /* If id not zero, search by Id */ if (jr->JobId != 0) { - if (jr->JobId == ojr.JobId) { - found = 1; - } + if (jr->JobId == ojr.JobId) { + found = 1; + } /* Search by Job */ } else if (strcmp(jr->Job, ojr.Job) == 0) { - found = 1; - Dmsg1(200, "Found Job: %s\n", ojr.Job); + found = 1; + Dmsg1(200, "Found Job: %s\n", ojr.Job); } if (!found) { - rec_addr = ftell(mdb->jobfd); /* save start next record */ - continue; + rec_addr = ftell(mdb->jobfd); /* save start next record */ + continue; } /* Found desired record, now return it */ memcpy(jr, &ojr, len); jr->rec_addr = rec_addr; stat = ojr.JobId; Dmsg2(200, "Found job record: JobId=%d Job=%s", - ojr.JobId, ojr.Job); + ojr.JobId, ojr.Job); break; } if (!found) { @@ -125,7 +125,7 @@ * Get the number of pool records * * Returns: -1 on failure - * number on success + * number on success */ int db_get_num_pool_records(JCR *jcr, B_DB *mdb) { @@ -142,7 +142,7 @@ * The caller must free ids if non-NULL. * * Returns 0: on failure - * 1: on success + * 1: on success */ int db_get_pool_ids(JCR *jcr, B_DB *mdb, int *num_ids, uint32_t *ids[]) { @@ -177,22 +177,21 @@ * If the PoolId is non-zero, we get its record, * otherwise, we search on the PoolName * - * Returns: 0 on failure - * id on success + * Returns: false on failure + * true on success */ -int db_get_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr) +bool db_get_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr) { POOL_DBR opr; faddr_t rec_addr; - int found = 0; - int stat = 0; + bool found = false; int len; db_lock(mdb); Dmsg0(200, "Open pools\n"); if (!bdb_open_pools_file(mdb)) { db_unlock(mdb); - return 0; + return false; } fseek(mdb->poolfd, 0L, SEEK_SET); /* rewind file */ rec_addr = 0; @@ -202,39 +201,37 @@ while (fread(&opr, len, 1, mdb->poolfd) > 0) { /* If id not zero, search by Id */ if (pr->PoolId != 0) { - if (pr->PoolId == opr.PoolId) { - found = 1; - } + if (pr->PoolId == opr.PoolId) { + found = true; + } /* Search by Name */ } else if (strcmp(pr->Name, opr.Name) == 0) { - found = 1; - Dmsg1(200, "Found pool: %s\n", opr.Name); + found = true; + Dmsg1(200, "Found pool: %s\n", opr.Name); } if (!found) { - rec_addr = ftell(mdb->poolfd); /* save start next record */ - continue; + rec_addr = ftell(mdb->poolfd); /* save start next record */ + continue; } /* Found desired record, now return it */ memcpy(pr, &opr, len); pr->rec_addr = rec_addr; - stat = opr.PoolId; Dmsg3(200, "Found pool record: PoolId=%d Name=%s PoolType=%s\n", - opr.PoolId, opr.Name, opr.PoolType); + opr.PoolId, opr.Name, opr.PoolType); break; } if (!found) { strcpy(mdb->errmsg, "Pool record not found.\n"); } db_unlock(mdb); - Dmsg1(200, "Return pool stat=%d\n", stat); - return stat; + return found; } /* * Get the number of Media records * * Returns: -1 on failure - * number on success + * number on success */ int db_get_num_media_records(JCR *jcr, B_DB *mdb) { @@ -251,10 +248,10 @@ * for a specified PoolId * The caller must free ids if non-NULL. * - * Returns 0: on failure - * 1: on success + * Returns false: on failure + * true: on success */ -int db_get_media_ids(JCR *jcr, B_DB *mdb, uint32_t PoolId, int *num_ids, uint32_t *ids[]) +bool db_get_media_ids(JCR *jcr, B_DB *mdb, uint32_t PoolId, int *num_ids, uint32_t *ids[]) { int i = 0; uint32_t *id; @@ -265,26 +262,26 @@ *ids = NULL; if (!bdb_open_media_file(mdb)) { db_unlock(mdb); - return 0; + return false; } - fseek(mdb->mediafd, 0L, SEEK_SET); /* rewind file */ + 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; + return false; } *num_ids = mdb->control.MediaId; id = (uint32_t *)malloc(*num_ids * sizeof(uint32_t)); while (fread(&omr, len, 1, mdb->mediafd) > 0) { if (PoolId == omr.MediaId) { - id[i++] = omr.MediaId; + id[i++] = omr.MediaId; } } *ids = id; db_unlock(mdb); - return 1; + return true; } /* @@ -292,67 +289,65 @@ * If the MediaId is non-zero, we get its record, * otherwise, we search on the MediaName * - * Returns: 0 on failure - * id on success + * Returns: false on failure + * true on success */ -int db_get_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr) +bool db_get_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr) { faddr_t rec_addr; - int found = 0; - int stat = 0; + bool found = false; int len; MEDIA_DBR omr; db_lock(mdb); if (!bdb_open_media_file(mdb)) { - db_unlock(mdb); - return 0; + goto get_out; } - fseek(mdb->mediafd, 0L, SEEK_SET); /* rewind file */ + fseek(mdb->mediafd, 0L, SEEK_SET); /* rewind file */ rec_addr = 0; /* Linear search through Media records */ len = sizeof(omr); while (fread(&omr, len, 1, mdb->mediafd) > 0) { if (omr.MediaId == 0) { - continue; /* deleted record */ + continue; /* deleted record */ } Dmsg1(200, "VolName=%s\n", omr.VolumeName); /* If id not zero, search by Id */ if (mr->MediaId != 0) { - Dmsg1(200, "MediaId=%d\n", mr->MediaId); - if (mr->MediaId == omr.MediaId) { - found = 1; - } + Dmsg1(200, "MediaId=%d\n", mr->MediaId); + if (mr->MediaId == omr.MediaId) { + found = true; + } /* Search by Name */ } else if (strcmp(mr->VolumeName, omr.VolumeName) == 0) { - found = 1; + found = true; } if (!found) { - rec_addr = ftell(mdb->mediafd); /* save start next record */ - continue; + rec_addr = ftell(mdb->mediafd); /* save start next record */ + continue; } /* Found desired record, now return it */ memcpy(mr, &omr, len); mr->rec_addr = rec_addr; - stat = omr.MediaId; Dmsg3(200, "Found media record: MediaId=%d Name=%s MediaType=%s\n", - omr.MediaId, omr.VolumeName, mr->MediaType); + omr.MediaId, omr.VolumeName, mr->MediaType); break; } - if (stat == 0) { + if (!found) { strcpy(mdb->errmsg, "Could not find requested Media record.\n"); } +get_out: db_unlock(mdb); - return stat; + return found; } /* * Find VolumeNames for a give JobId * Returns: 0 on error or no Volumes found - * number of volumes on success - * Volumes are concatenated in VolumeNames - * separated by a vertical bar (|). + * number of volumes on success + * Volumes are concatenated in VolumeNames + * separated by a vertical bar (|). */ int db_get_job_volume_names(JCR *jcr, B_DB *mdb, uint32_t JobId, POOLMEM **VolumeNames) { @@ -376,17 +371,17 @@ fseek(mdb->jobmediafd, 0L, SEEK_SET); /* rewind the file */ while (fread(&jm, jmlen, 1, mdb->jobmediafd) > 0) { if (jm.JobId == JobId) { - /* Now look up VolumeName in Media file given MediaId */ - fseek(mdb->mediafd, 0L, SEEK_SET); - while (fread(&mr, mrlen, 1, mdb->mediafd) > 0) { - if (jm.MediaId == mr.MediaId) { - if (*VolumeNames[0] != 0) { /* if not first name, */ - pm_strcat(VolumeNames, "|"); /* add separator */ - } - pm_strcat(VolumeNames, mr.VolumeName); /* add Volume Name */ - found++; - } - } + /* Now look up VolumeName in Media file given MediaId */ + fseek(mdb->mediafd, 0L, SEEK_SET); + while (fread(&mr, mrlen, 1, mdb->mediafd) > 0) { + if (jm.MediaId == mr.MediaId) { + if (*VolumeNames[0] != 0) { /* if not first name, */ + pm_strcat(VolumeNames, "|"); /* add separator */ + } + pm_strcat(VolumeNames, mr.VolumeName); /* add Volume Name */ + found++; + } + } } } if (!found) { @@ -402,7 +397,7 @@ * otherwise, we search on the Name * * Returns: 0 on failure - * id on success + * id on success */ int db_get_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr) { @@ -415,7 +410,7 @@ db_unlock(mdb); return 0; } - fseek(mdb->clientfd, 0L, SEEK_SET); /* rewind file */ + fseek(mdb->clientfd, 0L, SEEK_SET); /* rewind file */ /* * Linear search through Client records */ @@ -423,17 +418,17 @@ while (fread(&lcr, len, 1, mdb->clientfd)) { /* If id not zero, search by Id */ if (cr->ClientId != 0) { - if (cr->ClientId != lcr.ClientId) { - continue; - } + if (cr->ClientId != lcr.ClientId) { + continue; + } /* Search by Name */ } else if (strcmp(cr->Name, lcr.Name) != 0) { - continue; /* not found */ + continue; /* not found */ } memcpy(cr, &lcr, len); stat = lcr.ClientId; Dmsg2(200, "Found Client record: ClientId=%d Name=%s\n", - lcr.ClientId, lcr.Name); + lcr.ClientId, lcr.Name); break; } if (!stat) { @@ -444,12 +439,12 @@ } /* - * Get FileSet Record (We read the FILESET_DBR structure) + * Get FileSet Record (We read the FILESET_DBR structure) * If the FileSetId is non-zero, we get its record, * otherwise, we search on the FileSet (its name). * * Returns: 0 on failure - * id on success + * id on success */ int db_get_fileset_record(JCR *jcr, B_DB *mdb, FILESET_DBR *fsr) { @@ -468,19 +463,19 @@ while (fread(&lfsr, sizeof(lfsr), 1, mdb->filesetfd) > 0) { /* If id not zero, search by Id */ if (fsr->FileSetId != 0) { - if (fsr->FileSetId != lfsr.FileSetId) { - continue; - } + if (fsr->FileSetId != lfsr.FileSetId) { + continue; + } /* Search by Name & MD5 */ } else if (strcmp(fsr->FileSet, lfsr.FileSet) != 0 || - strcmp(fsr->MD5, lfsr.MD5) != 0) { - continue; /* not found */ + strcmp(fsr->MD5, lfsr.MD5) != 0) { + continue; /* not found */ } /* Found desired record, now return it */ memcpy(fsr, &lfsr, sizeof(lfsr)); stat = fsr->FileSetId; Dmsg2(200, "Found FileSet record: FileSetId=%d FileSet=%s\n", - lfsr.FileSetId, lfsr.FileSet); + lfsr.FileSetId, lfsr.FileSet); break; } if (!stat) { |