]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/cats.h
Vacation work -- see tech log
[bacula/bacula] / bacula / src / cats / cats.h
1 /*
2  * SQL header file
3  *
4  *   by Kern E. Sibbald
5  *
6  *   Anyone who accesses the database will need to include
7  *   this file.
8  *
9  * This file contains definitions common to sql.c and
10  * the external world, and definitions destined only
11  * for the external world. This is control with
12  * the define __SQL_C, which is defined only in sql.c
13  *
14  *    Version $Id$
15  */
16
17 /*
18    Copyright (C) 2000-2005 Kern Sibbald
19
20    This program is free software; you can redistribute it and/or
21    modify it under the terms of the GNU General Public License as
22    published by the Free Software Foundation; either version 2 of
23    the License, or (at your option) any later version.
24
25    This program is distributed in the hope that it will be useful,
26    but WITHOUT ANY WARRANTY; without even the implied warranty of
27    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28    General Public License for more details.
29
30    You should have received a copy of the GNU General Public
31    License along with this program; if not, write to the Free
32    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
33    MA 02111-1307, USA.
34
35  */
36
37 #ifndef __SQL_H_
38 #define __SQL_H_ 1
39
40
41 typedef void (DB_LIST_HANDLER)(void *, const char *);
42 typedef int (DB_RESULT_HANDLER)(void *, int, char **);
43
44 #define db_lock(mdb)   _db_lock(__FILE__, __LINE__, mdb)
45 #define db_unlock(mdb) _db_unlock(__FILE__, __LINE__, mdb)
46
47 #ifdef __SQL_C
48
49 #ifdef HAVE_SQLITE
50
51 #define BDB_VERSION 8
52
53 #include <sqlite.h>
54
55 /* Define opaque structure for sqlite */
56 struct sqlite {
57    char dummy;
58 };
59
60 #define IS_NUM(x)             ((x) == 1)
61 #define IS_NOT_NULL(x)        ((x) == 1)
62
63 typedef struct s_sql_field {
64    char *name;                        /* name of column */
65    int length;                        /* length */
66    int max_length;                    /* max length */
67    uint32_t type;                     /* type */
68    uint32_t flags;                    /* flags */
69 } SQL_FIELD;
70
71 /*
72  * This is the "real" definition that should only be
73  * used inside sql.c and associated database interface
74  * subroutines.
75  *                    S Q L I T E
76  */
77 typedef struct s_db {
78    BQUEUE bq;                         /* queue control */
79    brwlock_t lock;                    /* transaction lock */
80    struct sqlite *db;
81    char **result;
82    int status;
83    int nrow;                          /* nrow returned from sqlite */
84    int ncolumn;                       /* ncolum returned from sqlite */
85    int num_rows;                      /* used by code */
86    int row;                           /* seek row */
87    int field;                         /* seek field */
88    SQL_FIELD **fields;                /* defined fields */
89    int ref_count;
90    char *db_name;
91    char *db_user;
92    char *db_address;                  /* host name address */
93    char *db_socket;                   /* socket for local access */
94    char *db_password;
95    int  db_port;                      /* port for host name address */
96    bool connected;                    /* connection made to db */
97    bool have_insert_id;               /* do not have insert id */
98    bool fields_defined;               /* set when fields defined */
99    char *sqlite_errmsg;               /* error message returned by sqlite */
100    POOLMEM *errmsg;                   /* nicely edited error message */
101    POOLMEM *cmd;                      /* SQL command string */
102    POOLMEM *cached_path;              /* cached path name */
103    int cached_path_len;               /* length of cached path */
104    uint32_t cached_path_id;           /* cached path id */
105    bool allow_transactions;           /* transactions allowed */
106    bool transaction;                  /* transaction started */
107    int changes;                       /* changes during transaction */
108    POOLMEM *fname;                    /* Filename only */
109    POOLMEM *path;                     /* Path only */
110    POOLMEM *esc_name;                 /* Escaped file/path name */
111    int fnl;                           /* file name length */
112    int pnl;                           /* path name length */
113 } B_DB;
114
115
116 /*
117  * "Generic" names for easier conversion
118  *
119  *                    S Q L I T E
120  */
121 #define sql_store_result(x)   (x)->result
122 #define sql_free_result(x)    my_sqlite_free_table(x)
123 #define sql_fetch_row(x)      my_sqlite_fetch_row(x)
124 #define sql_query(x, y)       my_sqlite_query((x), (y))
125 #ifdef HAVE_SQLITE3
126 #define sql_insert_id(x,y)    sqlite3_last_insert_rowid((x)->db)
127 #define sql_close(x)          sqlite3_close((x)->db)
128 #else
129 #define sql_insert_id(x,y)    sqlite_last_insert_rowid((x)->db)
130 #define sql_close(x)          sqlite_close((x)->db)
131 #endif
132 #define sql_strerror(x)       (x)->sqlite_errmsg?(x)->sqlite_errmsg:"unknown"
133 #define sql_num_rows(x)       (x)->nrow
134 #define sql_data_seek(x, i)   (x)->row = (i)
135 #define sql_affected_rows(x)  1
136 #define sql_field_seek(x, y)  my_sqlite_field_seek((x), (y))
137 #define sql_fetch_field(x)    my_sqlite_fetch_field(x)
138 #define sql_num_fields(x)     ((x)->ncolumn)
139 #define SQL_ROW               char**
140
141
142
143 /* In cats/sqlite.c */
144 void       my_sqlite_free_table(B_DB *mdb);
145 SQL_ROW    my_sqlite_fetch_row(B_DB *mdb);
146 int        my_sqlite_query(B_DB *mdb, char *cmd);
147 void       my_sqlite_field_seek(B_DB *mdb, int field);
148 SQL_FIELD *my_sqlite_fetch_field(B_DB *mdb);
149
150
151 #else
152
153 /*                    S Q L I T E 3            */
154  
155
156 #ifdef HAVE_SQLITE3
157
158
159 #define BDB_VERSION 8
160
161 #include <sqlite3.h>
162
163 /* Define opaque structure for sqlite */
164 struct sqlite3 {
165    char dummy;
166 };
167
168 #define IS_NUM(x)             ((x) == 1)
169 #define IS_NOT_NULL(x)        ((x) == 1)
170
171 typedef struct s_sql_field {
172    char *name;                        /* name of column */
173    int length;                        /* length */
174    int max_length;                    /* max length */
175    uint32_t type;                     /* type */
176    uint32_t flags;                    /* flags */
177 } SQL_FIELD;
178
179 /*
180  * This is the "real" definition that should only be
181  * used inside sql.c and associated database interface
182  * subroutines.
183  *                    S Q L I T E
184  */
185 typedef struct s_db {
186    BQUEUE bq;                         /* queue control */
187    brwlock_t lock;                    /* transaction lock */
188    struct sqlite3 *db;
189    char **result;
190    int status;
191    int nrow;                          /* nrow returned from sqlite */
192    int ncolumn;                       /* ncolum returned from sqlite */
193    int num_rows;                      /* used by code */
194    int row;                           /* seek row */
195    int field;                         /* seek field */
196    SQL_FIELD **fields;                /* defined fields */
197    int ref_count;
198    char *db_name;
199    char *db_user;
200    char *db_address;                  /* host name address */
201    char *db_socket;                   /* socket for local access */
202    char *db_password;
203    int  db_port;                      /* port for host name address */
204    bool connected;                    /* connection made to db */
205    bool have_insert_id;               /* do not have insert id */
206    bool fields_defined;               /* set when fields defined */
207    char *sqlite_errmsg;               /* error message returned by sqlite */
208    POOLMEM *errmsg;                   /* nicely edited error message */
209    POOLMEM *cmd;                      /* SQL command string */
210    POOLMEM *cached_path;              /* cached path name */
211    int cached_path_len;               /* length of cached path */
212    uint32_t cached_path_id;           /* cached path id */
213    bool allow_transactions;           /* transactions allowed */
214    bool transaction;                  /* transaction started */
215    int changes;                       /* changes during transaction */
216    POOLMEM *fname;                    /* Filename only */
217    POOLMEM *path;                     /* Path only */
218    POOLMEM *esc_name;                 /* Escaped file/path name */
219    int fnl;                           /* file name length */
220    int pnl;                           /* path name length */
221 } B_DB;
222
223 /*
224  * Conversion of sqlite 2 names to sqlite3
225  */
226 #define sqlite_last_insert_rowid sqlite3_last_insert_rowid
227 #define sqlite_open sqlite3_open
228 #define sqlite_close sqlite3_close
229 #define sqlite_result sqlite3_result
230 #define sqlite_exec sqlite3_exec
231 #define sqlite_get_table sqlite3_get_table
232 #define sqlite_free_table sqlite3_free_table
233
234
235 /*
236  * "Generic" names for easier conversion
237  *
238  *                    S Q L I T E 3
239  */
240 #define sql_store_result(x)   (x)->result
241 #define sql_free_result(x)    my_sqlite_free_table(x)
242 #define sql_fetch_row(x)      my_sqlite_fetch_row(x)
243 #define sql_query(x, y)       my_sqlite_query((x), (y))
244 #ifdef HAVE_SQLITE3
245 #define sql_insert_id(x,y)    sqlite3_last_insert_rowid((x)->db)
246 #define sql_close(x)          sqlite3_close((x)->db)
247 #else
248 #define sql_insert_id(x,y)    sqlite_last_insert_rowid((x)->db)
249 #define sql_close(x)          sqlite_close((x)->db)
250 #endif
251 #define sql_strerror(x)       (x)->sqlite_errmsg?(x)->sqlite_errmsg:"unknown"
252 #define sql_num_rows(x)       (x)->nrow
253 #define sql_data_seek(x, i)   (x)->row = (i)
254 #define sql_affected_rows(x)  1
255 #define sql_field_seek(x, y)  my_sqlite_field_seek((x), (y))
256 #define sql_fetch_field(x)    my_sqlite_fetch_field(x)
257 #define sql_num_fields(x)     ((x)->ncolumn)
258 #define SQL_ROW               char**
259
260
261
262 /* In cats/sqlite.c */
263 void       my_sqlite_free_table(B_DB *mdb);
264 SQL_ROW    my_sqlite_fetch_row(B_DB *mdb);
265 int        my_sqlite_query(B_DB *mdb, char *cmd);
266 void       my_sqlite_field_seek(B_DB *mdb, int field);
267 SQL_FIELD *my_sqlite_fetch_field(B_DB *mdb);
268
269
270 #else
271
272 #ifdef HAVE_MYSQL
273
274 #define BDB_VERSION 8
275
276 #include <mysql.h>
277
278 /*
279  * This is the "real" definition that should only be
280  * used inside sql.c and associated database interface
281  * subroutines.
282  *
283  *                     M Y S Q L
284  */
285 typedef struct s_db {
286    BQUEUE bq;                         /* queue control */
287    brwlock_t lock;                    /* transaction lock */
288    MYSQL mysql;
289    MYSQL *db;
290    MYSQL_RES *result;
291    int status;
292    my_ulonglong num_rows;
293    int ref_count;
294    char *db_name;
295    char *db_user;
296    char *db_password;
297    char *db_address;                  /* host address */
298    char *db_socket;                   /* socket for local access */
299    int db_port;                       /* port of host address */
300    int have_insert_id;                /* do have insert_id() */
301    bool connected;
302    POOLMEM *errmsg;                   /* nicely edited error message */
303    POOLMEM *cmd;                      /* SQL command string */
304    POOLMEM *cached_path;
305    int cached_path_len;               /* length of cached path */
306    uint32_t cached_path_id;
307    int changes;                       /* changes made to db */
308    POOLMEM *fname;                    /* Filename only */
309    POOLMEM *path;                     /* Path only */
310    POOLMEM *esc_name;                 /* Escaped file/path name */
311    int fnl;                           /* file name length */
312    int pnl;                           /* path name length */
313 } B_DB;
314
315 #define DB_STATUS int
316
317 /* "Generic" names for easier conversion */
318 #define sql_store_result(x)   mysql_store_result((x)->db)
319 #define sql_free_result(x)    mysql_free_result((x)->result)
320 #define sql_fetch_row(x)      mysql_fetch_row((x)->result)
321 #define sql_query(x, y)       mysql_query((x)->db, (y))
322 #define sql_close(x)          mysql_close((x)->db)
323 #define sql_strerror(x)       mysql_error((x)->db)
324 #define sql_num_rows(x)       mysql_num_rows((x)->result)
325 #define sql_data_seek(x, i)   mysql_data_seek((x)->result, (i))
326 #define sql_affected_rows(x)  mysql_affected_rows((x)->db)
327 #define sql_insert_id(x,y)    mysql_insert_id((x)->db)
328 #define sql_field_seek(x, y)  mysql_field_seek((x)->result, (y))
329 #define sql_fetch_field(x)    mysql_fetch_field((x)->result)
330 #define sql_num_fields(x)     (int)mysql_num_fields((x)->result)
331 #define SQL_ROW               MYSQL_ROW
332 #define SQL_FIELD             MYSQL_FIELD
333
334 #else
335
336 #ifdef HAVE_POSTGRESQL
337
338 #define BDB_VERSION 8
339
340 #include <libpq-fe.h>
341
342 /* TEMP: the following is taken from select OID, typname from pg_type; */
343 #define IS_NUM(x)             ((x) == 20 || (x) == 21 || (x) == 23 || (x) == 700 || (x) == 701)
344 #define IS_NOT_NULL(x)        ((x) == 1)
345
346 typedef char **POSTGRESQL_ROW;
347 typedef struct pg_field {
348         char         *name;
349         int           max_length;
350         unsigned int  type;
351         unsigned int  flags;       // 1 == not null
352 } POSTGRESQL_FIELD;
353
354
355 /*
356  * This is the "real" definition that should only be
357  * used inside sql.c and associated database interface
358  * subroutines.
359  *
360  *                     P O S T G R E S Q L
361  */
362 typedef struct s_db {
363    BQUEUE bq;                         /* queue control */
364    brwlock_t lock;                    /* transaction lock */
365    PGconn *db;
366    PGresult *result;
367    int status;
368    POSTGRESQL_ROW row;
369    POSTGRESQL_FIELD *fields;
370    int num_rows;
371    int num_fields;
372    int row_number;            /* what row number did we get via my_postgresql_data_seek? */
373    int field_number;          /* what field number did we get via my_postgresql_field_seek? */
374    int ref_count;
375    char *db_name;
376    char *db_user;
377    char *db_password;
378    char *db_address;              /* host address */
379    char *db_socket;               /* socket for local access */
380    int db_port;                   /* port of host address */
381    int have_insert_id;            /* do have insert_id() */
382    bool connected;
383    POOLMEM *errmsg;               /* nicely edited error message */
384    POOLMEM *cmd;                  /* SQL command string */
385    POOLMEM *cached_path;
386    int cached_path_len;           /* length of cached path */
387    uint32_t cached_path_id;
388    bool allow_transactions;       /* transactions allowed */
389    bool transaction;              /* transaction started */
390    int changes;                   /* changes made to db */
391    POOLMEM *fname;                /* Filename only */
392    POOLMEM *path;                 /* Path only */
393    POOLMEM *esc_name;             /* Escaped file/path name */
394    int fnl;                       /* file name length */
395    int pnl;                       /* path name length */
396 } B_DB;
397
398 void               my_postgresql_free_result(B_DB *mdb);
399 POSTGRESQL_ROW     my_postgresql_fetch_row  (B_DB *mdb);
400 int                my_postgresql_query      (B_DB *mdb, const char *query);
401 void               my_postgresql_data_seek  (B_DB *mdb, int row);
402 int                my_postgresql_currval    (B_DB *mdb, char *table_name);
403 void               my_postgresql_field_seek (B_DB *mdb, int row);
404 POSTGRESQL_FIELD * my_postgresql_fetch_field(B_DB *mdb);
405
406
407 /* "Generic" names for easier conversion */
408 #define sql_store_result(x)   ((x)->result)
409 #define sql_free_result(x)    my_postgresql_free_result(x)
410 #define sql_fetch_row(x)      my_postgresql_fetch_row(x)
411 #define sql_query(x, y)       my_postgresql_query((x), (y))
412 #define sql_close(x)          PQfinish((x)->db)
413 #define sql_strerror(x)       PQresultErrorMessage((x)->result)
414 #define sql_num_rows(x)       ((unsigned) PQntuples((x)->result))
415 #define sql_data_seek(x, i)   my_postgresql_data_seek((x), (i))
416 #define sql_affected_rows(x)  ((unsigned) atoi(PQcmdTuples((x)->result)))
417 #define sql_insert_id(x,y)    my_postgresql_currval((x), (y))
418 #define sql_field_seek(x, y)  my_postgresql_field_seek((x), (y))
419 #define sql_fetch_field(x)    my_postgresql_fetch_field(x)
420 #define sql_num_fields(x)     ((x)->num_fields)
421 #define SQL_ROW               POSTGRESQL_ROW
422 #define SQL_FIELD             POSTGRESQL_FIELD
423
424 #else  /* USE BACULA DB routines */
425
426 #define HAVE_BACULA_DB 1
427
428 /* Change this each time there is some incompatible
429  * file format change!!!!
430  */
431 #define BDB_VERSION 13                /* file version number */
432
433 struct s_control {
434    int bdb_version;                   /* Version number */
435    uint32_t JobId;                    /* next Job Id */
436    uint32_t PoolId;                   /* next Pool Id */
437    uint32_t MediaId;                  /* next Media Id */
438    uint32_t JobMediaId;               /* next JobMedia Id */
439    uint32_t ClientId;                 /* next Client Id */
440    uint32_t FileSetId;                /* nest FileSet Id */
441    time_t time;                       /* time file written */
442 };
443
444
445 /* This is the REAL definition for using the
446  *  Bacula internal DB
447  */
448 typedef struct s_db {
449    BQUEUE bq;                         /* queue control */
450 /* pthread_mutex_t mutex;  */         /* single thread lock */
451    brwlock_t lock;                    /* transaction lock */
452    int ref_count;                     /* number of times opened */
453    struct s_control control;          /* control file structure */
454    int cfd;                           /* control file device */
455    FILE *jobfd;                       /* Jobs records file descriptor */
456    FILE *poolfd;                      /* Pool records fd */
457    FILE *mediafd;                     /* Media records fd */
458    FILE *jobmediafd;                  /* JobMedia records fd */
459    FILE *clientfd;                    /* Client records fd */
460    FILE *filesetfd;                   /* FileSet records fd */
461    char *db_name;                     /* name of database */
462    POOLMEM *errmsg;                   /* nicely edited error message */
463    POOLMEM *cmd;                      /* Command string */
464    POOLMEM *cached_path;
465    int cached_path_len;               /* length of cached path */
466    uint32_t cached_path_id;
467 } B_DB;
468
469 #endif /* HAVE_SQLITE3 */
470 #endif /* HAVE_MYSQL */
471 #endif /* HAVE_SQLITE */
472 #endif /* HAVE_POSTGRESQL */
473
474 /* Use for better error location printing */
475 #define UPDATE_DB(jcr, db, cmd) UpdateDB(__FILE__, __LINE__, jcr, db, cmd)
476 #define INSERT_DB(jcr, db, cmd) InsertDB(__FILE__, __LINE__, jcr, db, cmd)
477 #define QUERY_DB(jcr, db, cmd) QueryDB(__FILE__, __LINE__, jcr, db, cmd)
478 #define DELETE_DB(jcr, db, cmd) DeleteDB(__FILE__, __LINE__, jcr, db, cmd)
479
480
481 #else    /* not __SQL_C */
482
483 /* This is a "dummy" definition for use outside of sql.c
484  */
485 typedef struct s_db {
486    int dummy;                         /* for SunOS compiler */
487 } B_DB;
488
489 #endif /*  __SQL_C */
490
491 extern uint32_t bacula_db_version;
492
493 /* ***FIXME*** FileId_t should *really* be uint64_t
494  *  but at the current time, this breaks MySQL.
495  */
496 typedef uint32_t FileId_t;
497 typedef uint32_t DBId_t;              /* general DB id type */
498 typedef uint32_t JobId_t;
499
500 #define faddr_t long
501
502
503 /* Job information passed to create job record and update
504  * job record at end of job. Note, although this record
505  * contains all the fields found in the Job database record,
506  * it also contains fields found in the JobMedia record.
507  */
508 /* Job record */
509 struct JOB_DBR {
510    JobId_t JobId;
511    char Job[MAX_NAME_LENGTH];         /* Job unique name */
512    char Name[MAX_NAME_LENGTH];        /* Job base name */
513    int JobType;                       /* actually char(1) */
514    int JobLevel;                      /* actually char(1) */
515    int JobStatus;                     /* actually char(1) */
516    DBId_t ClientId;                   /* Id of client */
517    DBId_t PoolId;                     /* Id of pool */
518    DBId_t FileSetId;                  /* Id of FileSet */
519    time_t SchedTime;                  /* Time job scheduled */
520    time_t StartTime;                  /* Job start time */
521    time_t EndTime;                    /* Job termination time */
522    utime_t JobTDate;                  /* Backup time/date in seconds */
523    uint32_t VolSessionId;
524    uint32_t VolSessionTime;
525    uint32_t JobFiles;
526    uint32_t JobErrors;
527    uint32_t JobMissingFiles;
528    uint64_t JobBytes;
529
530    /* Note, FirstIndex, LastIndex, Start/End File and Block
531     * are only used in the JobMedia record.
532     */
533    uint32_t FirstIndex;               /* First index this Volume */
534    uint32_t LastIndex;                /* Last index this Volume */
535    uint32_t StartFile;
536    uint32_t EndFile;
537    uint32_t StartBlock;
538    uint32_t EndBlock;
539
540    char cSchedTime[MAX_TIME_LENGTH];
541    char cStartTime[MAX_TIME_LENGTH];
542    char cEndTime[MAX_TIME_LENGTH];
543    /* Extra stuff not in DB */
544    faddr_t rec_addr;
545 };
546
547 /* Job Media information used to create the media records
548  * for each Volume used for the job.
549  */
550 /* JobMedia record */
551 struct JOBMEDIA_DBR {
552    DBId_t JobMediaId;                 /* record id */
553    JobId_t  JobId;                    /* JobId */
554    DBId_t MediaId;                    /* MediaId */
555    uint32_t FirstIndex;               /* First index this Volume */
556    uint32_t LastIndex;                /* Last index this Volume */
557    uint32_t StartFile;                /* File for start of data */
558    uint32_t EndFile;                  /* End file on Volume */
559    uint32_t StartBlock;               /* start block on tape */
560    uint32_t EndBlock;                 /* last block */
561 };
562
563
564 /* Volume Parameter structure */
565 struct VOL_PARAMS {
566    char VolumeName[MAX_NAME_LENGTH];  /* Volume name */
567    char MediaType[MAX_NAME_LENGTH];   /* Media Type */
568    uint32_t VolIndex;                 /* Volume seqence no. */
569    uint32_t FirstIndex;               /* First index this Volume */
570    uint32_t LastIndex;                /* Last index this Volume */
571    uint32_t StartFile;                /* File for start of data */
572    uint32_t EndFile;                  /* End file on Volume */
573    uint32_t StartBlock;               /* start block on tape */
574    uint32_t EndBlock;                 /* last block */
575 };
576
577
578 /* Attributes record -- NOT same as in database because
579  *  in general, this "record" creates multiple database
580  *  records (e.g. pathname, filename, fileattributes).
581  */
582 struct ATTR_DBR {
583    char *fname;                       /* full path & filename */
584    char *link;                        /* link if any */
585    char *attr;                        /* attributes statp */
586    uint32_t FileIndex;
587    uint32_t Stream;
588    JobId_t  JobId;
589    DBId_t ClientId;
590    DBId_t PathId;
591    DBId_t FilenameId;
592    FileId_t FileId;
593 };
594
595
596 /* File record -- same format as database */
597 struct FILE_DBR {
598    FileId_t FileId;
599    uint32_t FileIndex;
600    JobId_t  JobId;
601    DBId_t FilenameId;
602    DBId_t PathId;
603    JobId_t  MarkId;
604    char LStat[256];
605    char SIG[50];
606    int SigType;                       /* NO_SIG/MD5_SIG/SHA1_SIG */
607 };
608
609 /* Pool record -- same format as database */
610 struct POOL_DBR {
611    DBId_t PoolId;
612    char Name[MAX_NAME_LENGTH];        /* Pool name */
613    uint32_t NumVols;                  /* total number of volumes */
614    uint32_t MaxVols;                  /* max allowed volumes */
615    int32_t LabelType;                 /* Bacula/ANSI/IBM */
616    int32_t UseOnce;                   /* set to use once only */
617    int32_t UseCatalog;                /* set to use catalog */
618    int32_t AcceptAnyVolume;           /* set to accept any volume sequence */
619    int32_t AutoPrune;                 /* set to prune automatically */
620    int32_t Recycle;                   /* default Vol recycle flag */
621    utime_t  VolRetention;             /* retention period in seconds */
622    utime_t  VolUseDuration;           /* time in secs volume can be used */
623    uint32_t MaxVolJobs;               /* Max Jobs on Volume */
624    uint32_t MaxVolFiles;              /* Max files on Volume */
625    uint64_t MaxVolBytes;              /* Max bytes on Volume */
626    char PoolType[MAX_NAME_LENGTH];
627    char LabelFormat[MAX_NAME_LENGTH];
628    /* Extra stuff not in DB */
629    faddr_t rec_addr;
630 };
631
632 class DEVICE_DBR {
633 public:
634    DBId_t DeviceId;
635    char Name[MAX_NAME_LENGTH];        /* Device name */
636    DBId_t MediaTypeId;                /* MediaType */
637    DBId_t StorageId;                  /* Storage id if autochanger */
638    uint32_t DevMounts;                /* Number of times mounted */
639    uint32_t DevErrors;                /* Number of read/write errors */
640    uint64_t DevReadBytes;             /* Number of bytes read */
641    uint64_t DevWriteBytes;            /* Number of bytew written */
642    uint64_t DevReadTime;              /* time spent reading volume */
643    uint64_t DevWriteTime;             /* time spent writing volume */
644    uint64_t DevReadTimeSincCleaning;  /* read time since cleaning */
645    uint64_t DevWriteTimeSincCleaning; /* write time since cleaning */
646    time_t   CleaningDate;             /* time last cleaned */
647    utime_t  CleaningPeriod;           /* time between cleanings */
648 };
649
650 class STORAGE_DBR {
651 public:
652    DBId_t StorageId;
653    char Name[MAX_NAME_LENGTH];        /* Device name */
654    DBId_t MediaTypeId;                /* MediaType */
655    int AutoChanger;                   /* Set if autochanger */
656 };
657
658 class MEDIATYPE_DBR {
659 public:
660    DBId_t MediaTypeId;
661    char MediaType[MAX_NAME_LENGTH];   /* MediaType string */
662    int ReadOnly;                      /* Set if read-only */
663 };
664
665
666 /* Media record -- same as the database */
667 struct MEDIA_DBR {
668    DBId_t MediaId;                    /* Unique volume id */
669    char VolumeName[MAX_NAME_LENGTH];  /* Volume name */
670    char MediaType[MAX_NAME_LENGTH];   /* Media type */
671    DBId_t PoolId;                     /* Pool id */
672    time_t   FirstWritten;             /* Time Volume first written */
673    time_t   LastWritten;              /* Time Volume last written */
674    time_t   LabelDate;                /* Date/Time Volume labeled */
675    int32_t  LabelType;                /* Label (Bacula/ANSI/IBM) */
676    uint32_t VolJobs;                  /* number of jobs on this medium */
677    uint32_t VolFiles;                 /* Number of files */
678    uint32_t VolBlocks;                /* Number of blocks */
679    uint32_t VolMounts;                /* Number of times mounted */
680    uint32_t VolErrors;                /* Number of read/write errors */
681    uint32_t VolWrites;                /* Number of writes */
682    uint32_t VolReads;                 /* Number of reads */
683    uint64_t VolBytes;                 /* Number of bytes written */
684    uint32_t VolParts;                 /* Number of parts written */
685    uint64_t MaxVolBytes;              /* Max bytes to write to Volume */
686    uint64_t VolCapacityBytes;         /* capacity estimate */
687    uint64_t VolReadTime;              /* time spent reading volume */
688    uint64_t VolWriteTime;             /* time spent writing volume */
689    utime_t  VolRetention;             /* Volume retention in seconds */
690    utime_t  VolUseDuration;           /* time in secs volume can be used */
691    uint32_t MaxVolJobs;               /* Max Jobs on Volume */
692    uint32_t MaxVolFiles;              /* Max files on Volume */
693    int32_t  Recycle;                  /* recycle yes/no */
694    int32_t  Slot;                     /* slot in changer */
695    int32_t  InChanger;                /* Volume currently in changer */
696    uint32_t EndFile;                  /* Last file on volume */
697    uint32_t EndBlock;                 /* Last block on volume */
698    char VolStatus[20];                /* Volume status */
699    /* Extra stuff not in DB */
700    faddr_t rec_addr;                  /* found record address */
701    /* Since the database returns times as strings, this is how we pass
702     *   them back.
703     */
704    char    cFirstWritten[MAX_TIME_LENGTH]; /* FirstWritten returned from DB */
705    char    cLastWritten[MAX_TIME_LENGTH];  /* LastWritten returned from DB */
706    char    cLabelData[MAX_TIME_LENGTH];    /* LabelData returned from DB */
707 };
708
709 /* Client record -- same as the database */
710 struct CLIENT_DBR {
711    DBId_t ClientId;                   /* Unique Client id */
712    int AutoPrune;
713    utime_t FileRetention;
714    utime_t JobRetention;
715    char Name[MAX_NAME_LENGTH];        /* Client name */
716    char Uname[256];                   /* Uname for client */
717 };
718
719 /* Counter record as in database */
720 struct COUNTER_DBR {
721    char Counter[MAX_NAME_LENGTH];
722    int32_t MinValue;
723    int32_t MaxValue;
724    int32_t CurrentValue;
725    char WrapCounter[MAX_NAME_LENGTH];
726 };
727
728
729 /* FileSet record -- same as the database */
730 struct FILESET_DBR {
731    DBId_t FileSetId;                  /* Unique FileSet id */
732    char FileSet[MAX_NAME_LENGTH];     /* FileSet name */
733    char MD5[50];                      /* MD5 signature of include/exclude */
734    time_t CreateTime;                 /* date created */
735    /*
736     * This is where we return CreateTime
737     */
738    char cCreateTime[MAX_TIME_LENGTH]; /* CreateTime as returned from DB */
739    /* Not in DB but returned by db_create_fileset() */
740    bool created;                      /* set when record newly created */
741 };
742
743
744
745 #include "protos.h"
746 #include "jcr.h"
747
748 /*
749  * Some functions exported by sql.c for use withing the
750  *   cats directory.
751  */
752 void list_result(B_DB *mdb, DB_LIST_HANDLER *send, void *ctx, e_list_type type);
753 void list_dashes(B_DB *mdb, DB_LIST_HANDLER *send, void *ctx);
754 int get_sql_record_max(JCR *jcr, B_DB *mdb);
755 int check_tables_version(JCR *jcr, B_DB *mdb);
756 void _db_unlock(const char *file, int line, B_DB *mdb);
757 void _db_lock(const char *file, int line, B_DB *mdb);
758
759 #endif /* __SQL_H_ */