]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/dev.h
This commit was manufactured by cvs2svn to create tag
[bacula/bacula] / bacula / src / stored / dev.h
1 /*
2  * Definitions for using the Device functions in Bacula
3  *  Tape and File storage access
4  *
5  */
6 /*
7    Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
8
9    This program is free software; you can redistribute it and/or
10    modify it under the terms of the GNU General Public License as
11    published by the Free Software Foundation; either version 2 of
12    the License, or (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17    General Public License for more details.
18
19    You should have received a copy of the GNU General Public
20    License along with this program; if not, write to the Free
21    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22    MA 02111-1307, USA.
23
24  */
25
26
27 #ifndef __DEV_H
28 #define __DEV_H 1
29
30 /* Arguments to open_dev() */
31 #define READ_WRITE 0
32 #define READ_ONLY  1
33
34 /* Generic status bits returned from status_dev() */
35 #define MT_TAPE      (1<<0)                /* is tape device */
36 #define MT_EOF       (1<<1)                /* just read EOF */
37 #define MT_BOT       (1<<2)                /* at beginning of tape */
38 #define MT_EOT       (1<<3)                /* end of tape reached */
39 #define MT_SM        (1<<4)                /* DDS setmark */
40 #define MT_EOD       (1<<5)                /* DDS at end of data */
41 #define MT_WR_PROT   (1<<6)                /* tape write protected */
42 #define MT_ONLINE    (1<<7)                /* tape online */
43 #define MT_DR_OPEN   (1<<8)                /* tape door open */
44 #define MT_IM_REP_EN (1<<9)                /* immediate report enabled */
45
46
47 /* Bits for device capabilities */
48 #define CAP_EOF        0x001          /* has MTWEOF */
49 #define CAP_BSR        0x002          /* has MTBSR */
50 #define CAP_BSF        0x004          /* has MTBSF */
51 #define CAP_FSR        0x008          /* has MTFSR */
52 #define CAP_FSF        0x010          /* has MTFSF */
53 #define CAP_EOM        0x020          /* has MTEOM */
54 #define CAP_REM        0x040          /* is removable media */
55 #define CAP_RACCESS    0x080          /* is random access device */
56 #define CAP_AUTOMOUNT  0x100          /* Read device at start to see what is there */
57 #define CAP_LABEL      0x200          /* Label blank tapes */
58 #define CAP_ANONVOLS   0x400          /* Mount without knowing volume name */
59 #define CAP_ALWAYSOPEN 0x800          /* always keep device open */
60
61
62 /* Tape state bits */
63 #define ST_OPENED    0x001            /* set when device opened */
64 #define ST_TAPE      0x002            /* is a tape device */  
65 #define ST_LABEL     0x004            /* label found */
66 #define ST_MALLOC    0x008            /* dev packet malloc'ed in init_dev() */
67 #define ST_APPEND    0x010            /* ready for Bacula append */
68 #define ST_READ      0x020            /* ready for Bacula read */
69 #define ST_EOT       0x040            /* at end of tape */
70 #define ST_WEOT      0x080            /* Got EOT on write */
71 #define ST_EOF       0x100            /* Read EOF i.e. zero bytes */
72 #define ST_NEXTVOL   0x200            /* Start writing on next volume */
73 #define ST_SHORT     0x400            /* Short block read */
74
75 /* dev_blocked states (mutually exclusive) */
76 #define BST_NOT_BLOCKED       0       /* not blocked */
77 #define BST_UNMOUNTED         1       /* User unmounted device */
78 #define BST_WAITING_FOR_SYSOP 2       /* Waiting for operator to mount tape */
79 #define BST_DOING_ACQUIRE     3       /* Opening/validating/moving tape */
80 #define BST_WRITING_LABEL     4       /* Labeling a tape */  
81 #define BST_UNMOUNTED_WAITING_FOR_SYSOP 5 /* Closed by user during mount request */
82
83 /* Volume Catalog Information structure definition */
84 typedef struct s_volume_catalog_info {
85    /* Media info for the current Volume */
86    uint32_t VolCatJobs;               /* number of jobs on this Volume */
87    uint32_t VolCatFiles;              /* Number of files */
88    uint32_t VolCatBlocks;             /* Number of blocks */
89    uint64_t VolCatBytes;              /* Number of bytes written */
90    uint32_t VolCatMounts;             /* Number of mounts this volume */
91    uint32_t VolCatErrors;             /* Number of errors this volume */
92    uint32_t VolCatWrites;             /* Number of writes this volume */
93    uint32_t VolCatReads;              /* Number of reads this volume */
94    uint32_t VolCatRecycles;           /* Number of recycles this volume */
95    uint64_t VolCatMaxBytes;           /* max bytes to write */
96    uint64_t VolCatCapacityBytes;      /* capacity estimate */
97    char VolCatStatus[20];             /* Volume status */
98    char VolCatName[MAX_NAME_LENGTH];  /* Desired volume to mount */
99 } VOLUME_CAT_INFO;
100
101
102 /* Device structure definition */
103 typedef struct s_device {
104    struct s_device *next;             /* pointer to next open device */
105    pthread_mutex_t mutex;             /* access control */
106    pthread_cond_t wait;               /* thread wait variable */
107    pthread_cond_t wait_next_vol;      /* wait for tape to be mounted */
108    pthread_t no_wait_id;              /* this thread must not wait */
109    int dev_blocked;                   /* set if we must wait (i.e. change tape) */
110    int num_waiting;                   /* number of threads waiting */
111    int num_writers;                   /* number of writing threads */
112    int use_count;                     /* usage count on this device */
113    int fd;                            /* file descriptor */
114    int capabilities;                  /* capabilities mask */
115    int state;                         /* state mask */
116    int dev_errno;                     /* Our own errno */
117    int mode;                          /* read/write modes */
118    char *dev_name;                    /* device name */
119    char *errmsg;                      /* nicely edited error message */
120    uint32_t block_num;                /* current block number base 0 */
121    uint32_t file;                     /* current file number base 0 */
122    uint32_t LastBlockNumWritten;      /* last block written */
123    uint32_t min_block_size;           /* min block size */
124    uint32_t max_block_size;           /* max block size */
125    uint32_t max_volume_jobs;          /* max jobs to put on one volume */
126    int64_t max_volume_files;          /* max files to put on one volume */
127    int64_t max_volume_size;           /* max bytes to put on one volume */
128    int64_t max_file_size;             /* max file size in bytes */
129    int64_t volume_capacity;           /* advisory capacity */
130    uint32_t max_rewind_wait;          /* max secs to allow for rewind */
131    void *device;                      /* pointer to Device Resource */
132
133    VOLUME_CAT_INFO VolCatInfo;        /* Volume Catalog Information */
134    struct Volume_Label VolHdr;        /* Actual volume label */
135
136 } DEVICE;
137
138
139
140
141 #ifdef SunOS
142 #define DEFAULT_TAPE_DRIVE "/dev/rmt/0cbn"
143 #endif
144 #ifdef AIX
145 #define DEFAULT_TAPE_DRIVE "/dev/rmt0.1"
146 #endif
147 #ifdef SGI
148 #define DEFAULT_TAPE_DRIVE "/dev/tps0d4nr"
149 #endif
150 #ifdef Linux
151 #define DEFAULT_TAPE_DRIVE "/dev/nst0"
152 #endif
153 #ifdef OSF
154 #define DEFAULT_TAPE_DRIVE "/dev/nrmt0"
155 #endif
156 #ifdef HPUX
157 #define DEFAULT_TAPE_DRIVE "/dev/rmt/0hnb"
158 #endif
159 #ifdef FreeBSD
160 #define DEFAULT_TAPE_DRIVE "/dev/nrst0"
161 #endif
162
163 /* Default default */
164 #ifndef DEFAULT_TAPE_DRIVE
165 #define DEFAULT_TAPE_DRIVE "/dev/nst0"
166 #endif
167
168 /* Get some definition of function to position
169  *  to the end of the medium in MTEOM. System
170  *  dependent. Arrgggg!
171  */
172 #ifndef MTEOM
173 #ifdef  MTSEOD
174 #define MTEOM MTSEOD
175 #endif
176 #ifdef MTEOD
177 #undef MTEOM
178 #define MTEOM MTEOD
179 #endif
180 #endif
181
182 #endif