]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/dev.h
First cut new SD lock + restore buffer bug fix
[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)             _lock_device(__FILE__, __LINE__, (dev)) 
35 #define new_lock_device_state(dev,state) _lock_device(__FILE__, __LINE__, (dev), (state))
36 #define new_unlock_device(dev)           _unlock_device(__FILE__, __LINE__, (dev))
37
38 /* Arguments to open_dev() */
39 #define READ_WRITE 0
40 #define READ_ONLY  1
41
42 /* Generic status bits returned from status_dev() */
43 #define MT_TAPE      (1<<0)                /* is tape device */
44 #define MT_EOF       (1<<1)                /* just read EOF */
45 #define MT_BOT       (1<<2)                /* at beginning of tape */
46 #define MT_EOT       (1<<3)                /* end of tape reached */
47 #define MT_SM        (1<<4)                /* DDS setmark */
48 #define MT_EOD       (1<<5)                /* DDS at end of data */
49 #define MT_WR_PROT   (1<<6)                /* tape write protected */
50 #define MT_ONLINE    (1<<7)                /* tape online */
51 #define MT_DR_OPEN   (1<<8)                /* tape door open */
52 #define MT_IM_REP_EN (1<<9)                /* immediate report enabled */
53
54
55 /* Bits for device capabilities */
56 #define CAP_EOF          0x0001       /* has MTWEOF */
57 #define CAP_BSR          0x0002       /* has MTBSR */
58 #define CAP_BSF          0x0004       /* has MTBSF */
59 #define CAP_FSR          0x0008       /* has MTFSR */
60 #define CAP_FSF          0x0010       /* has MTFSF */
61 #define CAP_EOM          0x0020       /* has MTEOM */
62 #define CAP_REM          0x0040       /* is removable media */
63 #define CAP_RACCESS      0x0080       /* is random access device */
64 #define CAP_AUTOMOUNT    0x0100       /* Read device at start to see what is there */
65 #define CAP_LABEL        0x0200       /* Label blank tapes */
66 #define CAP_ANONVOLS     0x0400       /* Mount without knowing volume name */
67 #define CAP_ALWAYSOPEN   0x0800       /* always keep device open */
68 #define CAP_AUTOCHANGER  0x1000       /* AutoChanger */
69 #define CAP_OFFLINEUNMOUNT 0x2000     /* Offline before unmount */
70
71
72 /* Tape state bits */
73 #define ST_OPENED    0x001            /* set when device opened */
74 #define ST_TAPE      0x002            /* is a tape device */  
75 #define ST_LABEL     0x004            /* label found */
76 #define ST_MALLOC    0x008            /* dev packet malloc'ed in init_dev() */
77 #define ST_APPEND    0x010            /* ready for Bacula append */
78 #define ST_READ      0x020            /* ready for Bacula read */
79 #define ST_EOT       0x040            /* at end of tape */
80 #define ST_WEOT      0x080            /* Got EOT on write */
81 #define ST_EOF       0x100            /* Read EOF i.e. zero bytes */
82 #define ST_NEXTVOL   0x200            /* Start writing on next volume */
83 #define ST_SHORT     0x400            /* Short block read */
84
85 /* dev_blocked states (mutually exclusive) */
86 #define BST_NOT_BLOCKED       0       /* not blocked */
87 #define BST_UNMOUNTED         1       /* User unmounted device */
88 #define BST_WAITING_FOR_SYSOP 2       /* Waiting for operator to mount tape */
89 #define BST_DOING_ACQUIRE     3       /* Opening/validating/moving tape */
90 #define BST_WRITING_LABEL     4       /* Labeling a tape */  
91 #define BST_UNMOUNTED_WAITING_FOR_SYSOP 5 /* Closed by user during mount request */
92
93 /* Volume Catalog Information structure definition */
94 typedef struct s_volume_catalog_info {
95    /* Media info for the current Volume */
96    uint32_t VolCatJobs;               /* number of jobs on this Volume */
97    uint32_t VolCatFiles;              /* Number of files */
98    uint32_t VolCatBlocks;             /* Number of blocks */
99    uint64_t VolCatBytes;              /* Number of bytes written */
100    uint32_t VolCatMounts;             /* Number of mounts this volume */
101    uint32_t VolCatErrors;             /* Number of errors this volume */
102    uint32_t VolCatWrites;             /* Number of writes this volume */
103    uint32_t VolCatReads;              /* Number of reads this volume */
104    uint32_t VolCatRecycles;           /* Number of recycles this volume */
105    int32_t  Slot;                     /* Slot in changer */
106    uint64_t VolCatMaxBytes;           /* max bytes to write */
107    uint64_t VolCatCapacityBytes;      /* capacity estimate */
108    char VolCatStatus[20];             /* Volume status */
109    char VolCatName[MAX_NAME_LENGTH];  /* Desired volume to mount */
110 } VOLUME_CAT_INFO;
111
112
113 /* Device structure definition */
114 typedef struct s_device {
115    struct s_device *next;             /* pointer to next open device */
116    void *attached_jcrs;               /* attached JCR list */
117    brwlock_t lock;                    /* new device locking mechanism */
118    pthread_mutex_t mutex;             /* access control */
119    pthread_cond_t wait;               /* thread wait variable */
120    pthread_cond_t wait_next_vol;      /* wait for tape to be mounted */
121    pthread_t no_wait_id;              /* this thread must not wait */
122    int dev_blocked;                   /* set if we must wait (i.e. change tape) */
123    int num_waiting;                   /* number of threads waiting */
124    int num_writers;                   /* number of writing threads */
125    int use_count;                     /* usage count on this device */
126    int fd;                            /* file descriptor */
127    int capabilities;                  /* capabilities mask */
128    int state;                         /* state mask */
129    int dev_errno;                     /* Our own errno */
130    int mode;                          /* read/write modes */
131    char *dev_name;                    /* device name */
132    char *errmsg;                      /* nicely edited error message */
133    uint32_t block_num;                /* current block number base 0 */
134    uint32_t file;                     /* current file number base 0 */
135    uint32_t file_bytes;               /* bytes in this file */
136    uint32_t LastBlockNumWritten;      /* last block written */
137    uint32_t min_block_size;           /* min block size */
138    uint32_t max_block_size;           /* max block size */
139    uint32_t max_volume_jobs;          /* max jobs to put on one volume */
140    uint64_t max_volume_files;         /* max files to put on one volume */
141    uint64_t max_volume_size;          /* max bytes to put on one volume */
142    uint64_t max_file_size;            /* max file size to put in one file on volume */
143    uint64_t volume_capacity;          /* advisory capacity */
144    uint32_t max_rewind_wait;          /* max secs to allow for rewind */
145    uint32_t max_open_wait;            /* max secs to allow for open */
146    void *device;                      /* pointer to Device Resource */
147
148    VOLUME_CAT_INFO VolCatInfo;        /* Volume Catalog Information */
149    VOLUME_LABEL VolHdr;               /* Actual volume label */
150
151 } DEVICE;
152
153
154
155
156 #ifdef SunOS
157 #define DEFAULT_TAPE_DRIVE "/dev/rmt/0cbn"
158 #endif
159 #ifdef AIX
160 #define DEFAULT_TAPE_DRIVE "/dev/rmt0.1"
161 #endif
162 #ifdef SGI
163 #define DEFAULT_TAPE_DRIVE "/dev/tps0d4nr"
164 #endif
165 #ifdef Linux
166 #define DEFAULT_TAPE_DRIVE "/dev/nst0"
167 #endif
168 #ifdef OSF
169 #define DEFAULT_TAPE_DRIVE "/dev/nrmt0"
170 #endif
171 #ifdef HPUX
172 #define DEFAULT_TAPE_DRIVE "/dev/rmt/0hnb"
173 #endif
174 #ifdef FreeBSD
175 #define DEFAULT_TAPE_DRIVE "/dev/nrst0"
176 #endif
177
178 /* Default default */
179 #ifndef DEFAULT_TAPE_DRIVE
180 #define DEFAULT_TAPE_DRIVE "/dev/nst0"
181 #endif
182
183 /* Get some definition of function to position
184  *  to the end of the medium in MTEOM. System
185  *  dependent. Arrgggg!
186  */
187 #ifndef MTEOM
188 #ifdef  MTSEOD
189 #define MTEOM MTSEOD
190 #endif
191 #ifdef MTEOD
192 #undef MTEOM
193 #define MTEOM MTEOD
194 #endif
195 #endif
196
197 #endif