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