5 * Copyright (c) 1995-1997 Claus-Justus Heine
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.
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.
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,
23 * $Source: /homes/cvs/ftape-stacked/ftape/zftape/zftape-vtbl.h,v $
25 * $Date: 1997/10/28 14:30:09 $
27 * This file defines a volume table as defined in the QIC-80
28 * development standards.
31 #include <linux/list.h>
33 #include "../lowlevel/ftape-tracing.h"
35 #include "../zftape/zftape-eof.h"
36 #include "../zftape/zftape-ctl.h"
37 #include "../zftape/zftape-rw.h"
39 #define VTBL_SIZE 128 /* bytes */
41 /* The following are offsets in the vtbl. */
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)
58 #define EXT_ZFTAPE_SIG 0
59 #define EXT_ZFTAPE_BLKSZ 10
60 #define EXT_ZFTAPE_CMAP 12
61 #define EXT_ZFTAPE_QIC113 13
63 #define VTBL_DIR_SIZE 92
64 #define VTBL_DATA_SIZE 96
65 #define VTBL_OS_VERSION 104
66 #define VTBL_SRC_DRIVE 106
68 #define VTBL_RESERVED_1 123
70 #define VTBL_CMPR_UNREG 0x3f
71 #define VTBL_CMPR_USED 0x80
73 #define VTBL_RESERVED_2 126
74 #define VTBL_RESERVED_3 127
75 /* compatibility with pre revision K */
76 #define VTBL_K_CMPR 120
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.
83 #define VTBL_SCSI_SEGS 4 /* is a 4 byte value */
85 /* one vtbl is 128 bytes, that results in a maximum number of
86 * 29*1024/128 = 232 volumes.
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"
96 typedef struct zft_internal_vtbl
98 struct list_head node
;
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
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
117 unsigned int open
:1; /* just in progress of being
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)
129 #define DUMP_VOLINFO(level, desc, info) \
132 strlcpy(tmp, desc, sizeof(tmp)); \
133 TRACE(level, "Volume %d:\n" \
134 KERN_INFO "description : %s\n" \
135 KERN_INFO "first segment: %d\n" \
136 KERN_INFO "last segment: %d\n" \
137 KERN_INFO "size : " LL_X "\n" \
138 KERN_INFO "block size : %d\n" \
139 KERN_INFO "compression : %d\n" \
140 KERN_INFO "zftape volume: %d\n" \
141 KERN_INFO "QIC-113 conf.: %d", \
142 (info)->count, tmp, (info)->start_seg, (info)->end_seg, \
143 LL((info)->size), (info)->blk_sz, \
144 (info)->use_compression != 0, (info)->zft_volume != 0, \
145 (info)->qic113 != 0); \
148 extern int zft_qic_mode
;
149 extern int zft_old_ftape
;
150 extern int zft_volume_table_changed
;
152 /* exported functions */
153 extern void zft_init_vtbl (void);
154 extern void zft_free_vtbl (void);
155 extern int zft_extract_volume_headers(__u8
*buffer
);
156 extern int zft_update_volume_table (unsigned int segment
);
157 extern int zft_open_volume (zft_position
*pos
,
158 int blk_sz
, int use_compression
);
159 extern int zft_close_volume (zft_position
*pos
);
160 extern const zft_volinfo
*zft_find_volume(unsigned int seg_pos
);
161 extern int zft_skip_volumes (int count
, zft_position
*pos
);
162 extern __s64
zft_get_eom_pos (void);
163 extern void zft_skip_to_eom (zft_position
*pos
);
164 extern int zft_fake_volume_headers (eof_mark_union
*eof_map
,
165 int num_failed_sectors
);
166 extern int zft_weof (unsigned int count
, zft_position
*pos
);
167 extern void zft_move_past_eof (zft_position
*pos
);
169 static inline int zft_tape_at_eod (const zft_position
*pos
);
170 static inline int zft_tape_at_lbot (const zft_position
*pos
);
171 static inline void zft_position_before_eof (zft_position
*pos
,
172 const zft_volinfo
*volume
);
173 static inline __s64
zft_check_for_eof(const zft_volinfo
*vtbl
,
174 const zft_position
*pos
);
176 /* this function decrements the zft_seg_pos counter if we are right
177 * at the beginning of a segment. This is to handle fsfm/bsfm -- we
178 * need to position before the eof mark. NOTE: zft_tape_pos is not
181 static inline void zft_position_before_eof(zft_position
*pos
,
182 const zft_volinfo
*volume
)
184 TRACE_FUN(ft_t_flow
);
186 if (pos
->seg_pos
== volume
->end_seg
+ 1 && pos
->seg_byte_pos
== 0) {
188 pos
->seg_byte_pos
= zft_get_seg_sz(pos
->seg_pos
);
193 /* Mmmh. Is the position at the end of the last volume, that is right
194 * before the last EOF mark also logical an EOD condition?
196 static inline int zft_tape_at_eod(const zft_position
*pos
)
201 TRACE_EXIT (pos
->seg_pos
>= zft_eom_vtbl
->start_seg
||
202 zft_last_vtbl
->open
);
204 TRACE_EXIT pos
->seg_pos
> ft_last_data_segment
;
208 static inline int zft_tape_at_lbot(const zft_position
*pos
)
211 return (pos
->seg_pos
<= zft_first_vtbl
->start_seg
&&
212 pos
->volume_pos
== 0);
214 return (pos
->seg_pos
<= ft_first_data_segment
&&
215 pos
->volume_pos
== 0);
219 /* This one checks for EOF. return remaing space (may be negative)
221 static inline __s64
zft_check_for_eof(const zft_volinfo
*vtbl
,
222 const zft_position
*pos
)
224 return (__s64
)(vtbl
->size
- pos
->volume_pos
);
227 #endif /* _ZFTAPE_VTBL_H */