1 |
1275 |
phoenix |
#ifndef _ZFTAPE_VTBL_H
|
2 |
|
|
#define _ZFTAPE_VTBL_H
|
3 |
|
|
|
4 |
|
|
/*
|
5 |
|
|
* Copyright (c) 1995-1997 Claus-Justus Heine
|
6 |
|
|
|
7 |
|
|
This program is free software; you can redistribute it and/or
|
8 |
|
|
modify it under the terms of the GNU General Public License as
|
9 |
|
|
published by the Free Software Foundation; either version 2, or (at
|
10 |
|
|
your option) any later version.
|
11 |
|
|
|
12 |
|
|
This program is distributed in the hope that it will be useful, but
|
13 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15 |
|
|
General Public License for more details.
|
16 |
|
|
|
17 |
|
|
You should have received a copy of the GNU General Public License
|
18 |
|
|
along with this program; see the file COPYING. If not, write to
|
19 |
|
|
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
|
20 |
|
|
USA.
|
21 |
|
|
|
22 |
|
|
*
|
23 |
|
|
* $Source: /home/marcus/revision_ctrl_test/oc_cvs/cvs/or1k/linux/linux-2.4/drivers/char/ftape/zftape/zftape-vtbl.h,v $
|
24 |
|
|
* $Revision: 1.1.1.1 $
|
25 |
|
|
* $Date: 2004-04-15 02:02:31 $
|
26 |
|
|
*
|
27 |
|
|
* This file defines a volume table as defined in the QIC-80
|
28 |
|
|
* development standards.
|
29 |
|
|
*/
|
30 |
|
|
|
31 |
|
|
#include <linux/list.h>
|
32 |
|
|
|
33 |
|
|
#include "../lowlevel/ftape-tracing.h"
|
34 |
|
|
|
35 |
|
|
#include "../zftape/zftape-eof.h"
|
36 |
|
|
#include "../zftape/zftape-ctl.h"
|
37 |
|
|
#include "../zftape/zftape-rw.h"
|
38 |
|
|
|
39 |
|
|
#define VTBL_SIZE 128 /* bytes */
|
40 |
|
|
|
41 |
|
|
/* The following are offsets in the vtbl. */
|
42 |
|
|
#define VTBL_SIG 0
|
43 |
|
|
#define VTBL_START 4
|
44 |
|
|
#define VTBL_END 6
|
45 |
|
|
#define VTBL_DESC 8
|
46 |
|
|
#define VTBL_DATE 52
|
47 |
|
|
#define VTBL_FLAGS 56
|
48 |
|
|
#define VTBL_FL_VENDOR_SPECIFIC (1<<0)
|
49 |
|
|
#define VTBL_FL_MUTLI_CARTRIDGE (1<<1)
|
50 |
|
|
#define VTBL_FL_NOT_VERIFIED (1<<2)
|
51 |
|
|
#define VTBL_FL_REDIR_INHIBIT (1<<3)
|
52 |
|
|
#define VTBL_FL_SEG_SPANNING (1<<4)
|
53 |
|
|
#define VTBL_FL_DIRECTORY_LAST (1<<5)
|
54 |
|
|
#define VTBL_FL_RESERVED_6 (1<<6)
|
55 |
|
|
#define VTBL_FL_RESERVED_7 (1<<7)
|
56 |
|
|
#define VTBL_M_NO 57
|
57 |
|
|
#define VTBL_EXT 58
|
58 |
|
|
#define EXT_ZFTAPE_SIG 0
|
59 |
|
|
#define EXT_ZFTAPE_BLKSZ 10
|
60 |
|
|
#define EXT_ZFTAPE_CMAP 12
|
61 |
|
|
#define EXT_ZFTAPE_QIC113 13
|
62 |
|
|
#define VTBL_PWD 84
|
63 |
|
|
#define VTBL_DIR_SIZE 92
|
64 |
|
|
#define VTBL_DATA_SIZE 96
|
65 |
|
|
#define VTBL_OS_VERSION 104
|
66 |
|
|
#define VTBL_SRC_DRIVE 106
|
67 |
|
|
#define VTBL_DEV 122
|
68 |
|
|
#define VTBL_RESERVED_1 123
|
69 |
|
|
#define VTBL_CMPR 124
|
70 |
|
|
#define VTBL_CMPR_UNREG 0x3f
|
71 |
|
|
#define VTBL_CMPR_USED 0x80
|
72 |
|
|
#define VTBL_FMT 125
|
73 |
|
|
#define VTBL_RESERVED_2 126
|
74 |
|
|
#define VTBL_RESERVED_3 127
|
75 |
|
|
/* compatability with pre revision K */
|
76 |
|
|
#define VTBL_K_CMPR 120
|
77 |
|
|
|
78 |
|
|
/* the next is used by QIC-3020 tapes with format code 6 (>2^16
|
79 |
|
|
* segments) It is specified in QIC-113, Rev. G, Section 5 (SCSI
|
80 |
|
|
* volume table). The difference is simply, that we only store the
|
81 |
|
|
* number of segments used, not the starting segment.
|
82 |
|
|
*/
|
83 |
|
|
#define VTBL_SCSI_SEGS 4 /* is a 4 byte value */
|
84 |
|
|
|
85 |
|
|
/* one vtbl is 128 bytes, that results in a maximum number of
|
86 |
|
|
* 29*1024/128 = 232 volumes.
|
87 |
|
|
*/
|
88 |
|
|
#define ZFT_MAX_VOLUMES (FT_SEGMENT_SIZE/VTBL_SIZE)
|
89 |
|
|
#define VTBL_ID "VTBL"
|
90 |
|
|
#define VTBL_IDS { VTBL_ID, "XTBL", "UTID", "EXVT" } /* other valid ids */
|
91 |
|
|
#define ZFT_VOL_NAME "zftape volume" /* volume label used by me */
|
92 |
|
|
#define ZFTAPE_SIG "LINUX ZFT"
|
93 |
|
|
|
94 |
|
|
/* global variables
|
95 |
|
|
*/
|
96 |
|
|
typedef struct zft_internal_vtbl
|
97 |
|
|
{
|
98 |
|
|
struct list_head node;
|
99 |
|
|
int count;
|
100 |
|
|
unsigned int start_seg; /* 32 bits are enough for now */
|
101 |
|
|
unsigned int end_seg; /* 32 bits are enough for now */
|
102 |
|
|
__s64 size; /* uncompressed size */
|
103 |
|
|
unsigned int blk_sz; /* block size for this volume */
|
104 |
|
|
unsigned int zft_volume :1; /* zftape created this volume */
|
105 |
|
|
unsigned int use_compression:1; /* compressed volume */
|
106 |
|
|
unsigned int qic113 :1; /* layout of compressed block
|
107 |
|
|
* info and vtbl conforms to
|
108 |
|
|
* QIC-113, Rev. G
|
109 |
|
|
*/
|
110 |
|
|
unsigned int new_volume :1; /* it was created by us, this
|
111 |
|
|
* run. this allows the
|
112 |
|
|
* fields that aren't really
|
113 |
|
|
* used by zftape to be filled
|
114 |
|
|
* in by some user level
|
115 |
|
|
* program.
|
116 |
|
|
*/
|
117 |
|
|
unsigned int open :1; /* just in progress of being
|
118 |
|
|
* written
|
119 |
|
|
*/
|
120 |
|
|
} zft_volinfo;
|
121 |
|
|
|
122 |
|
|
extern struct list_head zft_vtbl;
|
123 |
|
|
#define zft_head_vtbl list_entry(zft_vtbl.next, zft_volinfo, node)
|
124 |
|
|
#define zft_eom_vtbl list_entry(zft_vtbl.prev, zft_volinfo, node)
|
125 |
|
|
#define zft_last_vtbl list_entry(zft_eom_vtbl->node.prev, zft_volinfo, node)
|
126 |
|
|
#define zft_first_vtbl list_entry(zft_head_vtbl->node.next, zft_volinfo, node)
|
127 |
|
|
#define zft_vtbl_empty (zft_eom_vtbl->node.prev == &zft_head_vtbl->node)
|
128 |
|
|
|
129 |
|
|
#define DUMP_VOLINFO(level, desc, info) \
|
130 |
|
|
{ \
|
131 |
|
|
char tmp[21]; \
|
132 |
|
|
strncpy(tmp, desc, 20); \
|
133 |
|
|
tmp[20] = '\0'; \
|
134 |
|
|
TRACE(level, "Volume %d:\n" \
|
135 |
|
|
KERN_INFO "description : %s\n" \
|
136 |
|
|
KERN_INFO "first segment: %d\n" \
|
137 |
|
|
KERN_INFO "last segment: %d\n" \
|
138 |
|
|
KERN_INFO "size : " LL_X "\n" \
|
139 |
|
|
KERN_INFO "block size : %d\n" \
|
140 |
|
|
KERN_INFO "compression : %d\n" \
|
141 |
|
|
KERN_INFO "zftape volume: %d\n" \
|
142 |
|
|
KERN_INFO "QIC-113 conf.: %d", \
|
143 |
|
|
(info)->count, tmp, (info)->start_seg, (info)->end_seg, \
|
144 |
|
|
LL((info)->size), (info)->blk_sz, \
|
145 |
|
|
(info)->use_compression != 0, (info)->zft_volume != 0, \
|
146 |
|
|
(info)->qic113 != 0); \
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
extern int zft_qic_mode;
|
150 |
|
|
extern int zft_old_ftape;
|
151 |
|
|
extern int zft_volume_table_changed;
|
152 |
|
|
|
153 |
|
|
/* exported functions */
|
154 |
|
|
extern void zft_init_vtbl (void);
|
155 |
|
|
extern void zft_free_vtbl (void);
|
156 |
|
|
extern void zft_new_vtbl_entry (void);
|
157 |
|
|
extern int zft_extract_volume_headers(__u8 *buffer);
|
158 |
|
|
extern int zft_update_volume_table (unsigned int segment);
|
159 |
|
|
extern int zft_open_volume (zft_position *pos,
|
160 |
|
|
int blk_sz, int use_compression);
|
161 |
|
|
extern int zft_close_volume (zft_position *pos);
|
162 |
|
|
extern const zft_volinfo *zft_find_volume(unsigned int seg_pos);
|
163 |
|
|
extern int zft_skip_volumes (int count, zft_position *pos);
|
164 |
|
|
extern __s64 zft_get_eom_pos (void);
|
165 |
|
|
extern void zft_skip_to_eom (zft_position *pos);
|
166 |
|
|
extern int zft_fake_volume_headers (eof_mark_union *eof_map,
|
167 |
|
|
int num_failed_sectors);
|
168 |
|
|
extern int zft_weof (unsigned int count, zft_position *pos);
|
169 |
|
|
extern void zft_move_past_eof (zft_position *pos);
|
170 |
|
|
|
171 |
|
|
static inline int zft_tape_at_eod (const zft_position *pos);
|
172 |
|
|
static inline int zft_tape_at_lbot (const zft_position *pos);
|
173 |
|
|
static inline void zft_position_before_eof (zft_position *pos,
|
174 |
|
|
const zft_volinfo *volume);
|
175 |
|
|
static inline __s64 zft_check_for_eof(const zft_volinfo *vtbl,
|
176 |
|
|
const zft_position *pos);
|
177 |
|
|
|
178 |
|
|
/* this function decrements the zft_seg_pos counter if we are right
|
179 |
|
|
* at the beginning of a segment. This is to handel fsfm/bsfm -- we
|
180 |
|
|
* need to position before the eof mark. NOTE: zft_tape_pos is not
|
181 |
|
|
* changed
|
182 |
|
|
*/
|
183 |
|
|
static inline void zft_position_before_eof(zft_position *pos,
|
184 |
|
|
const zft_volinfo *volume)
|
185 |
|
|
{
|
186 |
|
|
TRACE_FUN(ft_t_flow);
|
187 |
|
|
|
188 |
|
|
if (pos->seg_pos == volume->end_seg + 1 && pos->seg_byte_pos == 0) {
|
189 |
|
|
pos->seg_pos --;
|
190 |
|
|
pos->seg_byte_pos = zft_get_seg_sz(pos->seg_pos);
|
191 |
|
|
}
|
192 |
|
|
TRACE_EXIT;
|
193 |
|
|
}
|
194 |
|
|
|
195 |
|
|
/* Mmmh. Is the position at the end of the last volume, that is right
|
196 |
|
|
* before the last EOF mark also logical an EOD condition?
|
197 |
|
|
*/
|
198 |
|
|
static inline int zft_tape_at_eod(const zft_position *pos)
|
199 |
|
|
{
|
200 |
|
|
TRACE_FUN(ft_t_any);
|
201 |
|
|
|
202 |
|
|
if (zft_qic_mode) {
|
203 |
|
|
TRACE_EXIT (pos->seg_pos >= zft_eom_vtbl->start_seg ||
|
204 |
|
|
zft_last_vtbl->open);
|
205 |
|
|
} else {
|
206 |
|
|
TRACE_EXIT pos->seg_pos > ft_last_data_segment;
|
207 |
|
|
}
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
static inline int zft_tape_at_lbot(const zft_position *pos)
|
211 |
|
|
{
|
212 |
|
|
if (zft_qic_mode) {
|
213 |
|
|
return (pos->seg_pos <= zft_first_vtbl->start_seg &&
|
214 |
|
|
pos->volume_pos == 0);
|
215 |
|
|
} else {
|
216 |
|
|
return (pos->seg_pos <= ft_first_data_segment &&
|
217 |
|
|
pos->volume_pos == 0);
|
218 |
|
|
}
|
219 |
|
|
}
|
220 |
|
|
|
221 |
|
|
/* This one checks for EOF. return remaing space (may be negative)
|
222 |
|
|
*/
|
223 |
|
|
static inline __s64 zft_check_for_eof(const zft_volinfo *vtbl,
|
224 |
|
|
const zft_position *pos)
|
225 |
|
|
{
|
226 |
|
|
return (__s64)(vtbl->size - pos->volume_pos);
|
227 |
|
|
}
|
228 |
|
|
|
229 |
|
|
#endif /* _ZFTAPE_VTBL_H */
|