]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/dev.h
10ca3577d636cac4c0317f12eabb8d6d53b78ad5
[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  *   Version $Id$
6  *
7  */
8 /*
9    Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
10
11    This program is free software; you can redistribute it and/or
12    modify it under the terms of the GNU General Public License as
13    published by the Free Software Foundation; either version 2 of
14    the License, or (at your option) any later version.
15
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19    General Public License for more details.
20
21    You should have received a copy of the GNU General Public
22    License along with this program; if not, write to the Free
23    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24    MA 02111-1307, USA.
25
26  */
27
28
29 #ifndef __DEV_H
30 #define __DEV_H 1
31
32 /* #define NEW_LOCK 1 */
33
34 #define new_lock_device(dev)             _new_lock_device(__FILE__, __LINE__, (dev)) 
35 #define new_lock_device_state(dev,state) _new_lock_device(__FILE__, __LINE__, (dev), (state))
36 #define new_unlock_device(dev)           _new_unlock_device(__FILE__, __LINE__, (dev))
37
38 #define lock_device(d) _lock_device(__FILE__, __LINE__, (d))
39 #define unlock_device(d) _unlock_device(__FILE__, __LINE__, (d))
40 #define block_device(d, s) _block_device(__FILE__, __LINE__, (d), s)
41 #define unblock_device(d) _unblock_device(__FILE__, __LINE__, (d))
42 #define steal_device_lock(d, p, s) _steal_device_lock(__FILE__, __LINE__, (d), (p), s)
43 #define return_device_lock(d, p) _return_device_lock(__FILE__, __LINE__, (d), (p))
44
45 /* Arguments to open_dev() */
46 #define READ_WRITE 0
47 #define READ_ONLY  1
48
49 /* Generic status bits returned from status_dev() */
50 #define MT_TAPE      (1<<0)                /* is tape device */
51 #define MT_EOF       (1<<1)                /* just read EOF */
52 #define MT_BOT       (1<<2)                /* at beginning of tape */
53 #define MT_EOT       (1<<3)                /* end of tape reached */
54 #define MT_SM        (1<<4)                /* DDS setmark */
55 #define MT_EOD       (1<<5)                /* DDS at end of data */
56 #define MT_WR_PROT   (1<<6)                /* tape write protected */
57 #define MT_ONLINE    (1<<7)                /* tape online */
58 #define MT_DR_OPEN   (1<<8)                /* tape door open */
59 #define MT_IM_REP_EN (1<<9)                /* immediate report enabled */
60
61
62 /* Bits for device capabilities */
63 #define CAP_EOF            0x0001     /* has MTWEOF */
64 #define CAP_BSR            0x0002     /* has MTBSR */
65 #define CAP_BSF            0x0004     /* has MTBSF */
66 #define CAP_FSR            0x0008     /* has MTFSR */
67 #define CAP_FSF            0x0010     /* has MTFSF */
68 #define CAP_EOM            0x0020     /* has MTEOM */
69 #define CAP_REM            0x0040     /* is removable media */
70 #define CAP_RACCESS        0x0080     /* is random access device */
71 #define CAP_AUTOMOUNT      0x0100     /* Read device at start to see what is there */
72 #define CAP_LABEL          0x0200     /* Label blank tapes */
73 #define CAP_ANONVOLS       0x0400     /* Mount without knowing volume name */
74 #define CAP_ALWAYSOPEN     0x0800     /* always keep device open */
75 #define CAP_AUTOCHANGER    0x1000     /* AutoChanger */
76 #define CAP_OFFLINEUNMOUNT 0x2000     /* Offline before unmount */
77 #define CAP_STREAM         0x4000     /* Stream device */
78
79
80 /* Device state bits */
81 #define ST_OPENED    0x0001           /* set when device opened */
82 #define ST_TAPE      0x0002           /* is a tape device */  
83 #define ST_FILE      0x0004           /* is a file device */
84 #define ST_FIFO      0x0008           /* is a fifo device */
85 #define ST_PROG      0x0010           /* is a program device */
86 #define ST_LABEL     0x0020           /* label found */
87 #define ST_MALLOC    0x0040           /* dev packet malloc'ed in init_dev() */
88 #define ST_APPEND    0x0080           /* ready for Bacula append */
89 #define ST_READ      0x0100           /* ready for Bacula read */
90 #define ST_EOT       0x0200           /* at end of tape */
91 #define ST_WEOT      0x0400           /* Got EOT on write */
92 #define ST_EOF       0x0800           /* Read EOF i.e. zero bytes */
93 #define ST_NEXTVOL   0x1000           /* Start writing on next volume */
94 #define ST_SHORT     0x2000           /* Short block read */
95
96 /* dev_blocked states (mutually exclusive) */
97 #define BST_NOT_BLOCKED       0       /* not blocked */
98 #define BST_UNMOUNTED         1       /* User unmounted device */
99 #define BST_WAITING_FOR_SYSOP 2       /* Waiting for operator to mount tape */
100 #define BST_DOING_ACQUIRE     3       /* Opening/validating/moving tape */
101 #define BST_WRITING_LABEL     4       /* Labeling a tape */  
102 #define BST_UNMOUNTED_WAITING_FOR_SYSOP 5 /* Closed by user during mount request */
103
104 /* Volume Catalog Information structure definition */
105 typedef struct s_volume_catalog_info {
106    /* Media info for the current Volume */
107    uint32_t VolCatJobs;               /* number of jobs on this Volume */
108    uint32_t VolCatFiles;              /* Number of files */
109    uint32_t VolCatBlocks;             /* Number of blocks */
110    uint64_t VolCatBytes;              /* Number of bytes written */
111    uint32_t VolCatMounts;             /* Number of mounts this volume */
112    uint32_t VolCatErrors;             /* Number of errors this volume */
113    uint32_t VolCatWrites;             /* Number of writes this volume */
114    uint32_t VolCatReads;              /* Number of reads this volume */
115    uint32_t VolCatRecycles;           /* Number of recycles this volume */
116    int32_t  Slot;                     /* Slot in changer */
117    uint32_t VolCatMaxJobs;            /* Maximum Jobs to write to volume */
118    uint32_t VolCatMaxFiles;           /* Maximum files to write to volume */
119    uint64_t VolCatMaxBytes;           /* Max bytes to write to volume */
120    uint64_t VolCatCapacityBytes;      /* capacity estimate */
121    char VolCatStatus[20];             /* Volume status */
122    char VolCatName[MAX_NAME_LENGTH];  /* Desired volume to mount */
123 } VOLUME_CAT_INFO;
124
125
126 typedef struct s_steal_lock {
127    pthread_t         no_wait_id;      /* id of no wait thread */
128    int               dev_blocked;     /* state */
129 } bsteal_lock_t;
130
131
132 /* Device structure definition */
133 typedef struct s_device {
134    struct s_device *next;             /* pointer to next open device */
135    void *attached_jcrs;               /* attached JCR list */
136 #ifdef NEW_LOCK
137    brwlock_t lock;                    /* new device locking mechanism */
138 #endif
139    pthread_mutex_t mutex;             /* access control */
140    pthread_cond_t wait;               /* thread wait variable */
141    pthread_cond_t wait_next_vol;      /* wait for tape to be mounted */
142    pthread_t no_wait_id;              /* this thread must not wait */
143    int dev_blocked;                   /* set if we must wait (i.e. change tape) */
144    int num_waiting;                   /* number of threads waiting */
145    int num_writers;                   /* number of writing threads */
146    int use_count;                     /* usage count on this device */
147    int fd;                            /* file descriptor */
148    int capabilities;                  /* capabilities mask */
149    int state;                         /* state mask */
150    int dev_errno;                     /* Our own errno */
151    int mode;                          /* read/write modes */
152    char *dev_name;                    /* device name */
153    char *errmsg;                      /* nicely edited error message */
154    uint32_t block_num;                /* current block number base 0 */
155    uint32_t file;                     /* current file number base 0 */
156    uint64_t file_addr;                /* Current file read/write address */
157    uint32_t EndBlock;                 /* last block written */
158    uint32_t EndFile;                  /* last file written */
159    uint32_t min_block_size;           /* min block size */
160    uint32_t max_block_size;           /* max block size */
161    uint32_t max_volume_jobs;          /* max jobs to put on one volume */
162    uint64_t max_volume_files;         /* max files to put on one volume */
163    uint64_t max_volume_size;          /* max bytes to put on one volume */
164    uint64_t max_file_size;            /* max file size to put in one file on volume */
165    uint64_t volume_capacity;          /* advisory capacity */
166    uint32_t max_rewind_wait;          /* max secs to allow for rewind */
167    uint32_t max_open_wait;            /* max secs to allow for open */
168    void *device;                      /* pointer to Device Resource */
169
170    VOLUME_CAT_INFO VolCatInfo;        /* Volume Catalog Information */
171    VOLUME_LABEL VolHdr;               /* Actual volume label */
172
173 } DEVICE;
174
175
176
177
178 #ifdef SunOS
179 #define DEFAULT_TAPE_DRIVE "/dev/rmt/0cbn"
180 #endif
181 #ifdef AIX
182 #define DEFAULT_TAPE_DRIVE "/dev/rmt0.1"
183 #endif
184 #ifdef SGI
185 #define DEFAULT_TAPE_DRIVE "/dev/tps0d4nr"
186 #endif
187 #ifdef Linux
188 #define DEFAULT_TAPE_DRIVE "/dev/nst0"
189 #endif
190 #ifdef OSF
191 #define DEFAULT_TAPE_DRIVE "/dev/nrmt0"
192 #endif
193 #ifdef HPUX
194 #define DEFAULT_TAPE_DRIVE "/dev/rmt/0hnb"
195 #endif
196 #ifdef FreeBSD
197 #define DEFAULT_TAPE_DRIVE "/dev/nrst0"
198 #endif
199
200 /* Default default */
201 #ifndef DEFAULT_TAPE_DRIVE
202 #define DEFAULT_TAPE_DRIVE "/dev/nst0"
203 #endif
204
205 /* Get some definition of function to position
206  *  to the end of the medium in MTEOM. System
207  *  dependent. Arrgggg!
208  */
209 #ifndef MTEOM
210 #ifdef  MTSEOD
211 #define MTEOM MTSEOD
212 #endif
213 #ifdef MTEOD
214 #undef MTEOM
215 #define MTEOM MTEOD
216 #endif
217 #endif
218
219 #endif