zftape-vtbl.h 7.5 KB

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