12 #include <sys/ioctl.h>
15 #include <linux/types.h>
16 #include <linux/hdreg.h>
21 #define LINE_LENGTH 80
22 #define VTOC_START_CC 0x0
23 #define VTOC_START_HH 0x1
24 #define FIRST_USABLE_CYL 1
25 #define FIRST_USABLE_TRK 2
27 #define DASD_3380_TYPE 13148
28 #define DASD_3390_TYPE 13200
29 #define DASD_9345_TYPE 37701
31 #define DASD_3380_VALUE 0xbb60
32 #define DASD_3390_VALUE 0xe5a2
33 #define DASD_9345_VALUE 0xbc98
35 #define VOLSER_LENGTH 6
36 #define BIG_DISK_SIZE 0x10000
38 #define VTOC_ERROR "VTOC error:"
45 } __attribute__ ((packed
)) ttr_t
;
52 } __attribute__ ((packed
)) cchhb_t
;
58 } __attribute__ ((packed
)) cchh_t
;
60 typedef struct labeldate
64 } __attribute__ ((packed
)) labeldate_t
;
67 typedef struct volume_label
69 char volkey
[4]; /* volume key = volume label */
70 char vollbl
[4]; /* volume label */
71 char volid
[6]; /* volume identifier */
72 __u8 security
; /* security byte */
73 cchhb_t vtoc
; /* VTOC address */
74 char res1
[5]; /* reserved */
75 char cisize
[4]; /* CI-size for FBA,... */
76 /* ...blanks for CKD */
77 char blkperci
[4]; /* no of blocks per CI (FBA), blanks for CKD */
78 char labperci
[4]; /* no of labels per CI (FBA), blanks for CKD */
79 char res2
[4]; /* reserved */
80 char lvtoc
[14]; /* owner code for LVTOC */
81 char res3
[29]; /* reserved */
82 } __attribute__ ((packed
)) volume_label_t
;
87 __u8 typeind
; /* extent type indicator */
88 __u8 seqno
; /* extent sequence number */
89 cchh_t llimit
; /* starting point of this extent */
90 cchh_t ulimit
; /* ending point of this extent */
91 } __attribute__ ((packed
)) extent_t
;
94 typedef struct dev_const
96 __u16 DS4DSCYL
; /* number of logical cyls */
97 __u16 DS4DSTRK
; /* number of tracks in a logical cylinder */
98 __u16 DS4DEVTK
; /* device track length */
99 __u8 DS4DEVI
; /* non-last keyed record overhead */
100 __u8 DS4DEVL
; /* last keyed record overhead */
101 __u8 DS4DEVK
; /* non-keyed record overhead differential */
102 __u8 DS4DEVFG
; /* flag byte */
103 __u16 DS4DEVTL
; /* device tolerance */
104 __u8 DS4DEVDT
; /* number of DSCB's per track */
105 __u8 DS4DEVDB
; /* number of directory blocks per track */
106 } __attribute__ ((packed
)) dev_const_t
;
109 typedef struct format1_label
111 char DS1DSNAM
[44]; /* data set name */
112 __u8 DS1FMTID
; /* format identifier */
113 char DS1DSSN
[6]; /* data set serial number */
114 __u16 DS1VOLSQ
; /* volume sequence number */
115 labeldate_t DS1CREDT
; /* creation date: ydd */
116 labeldate_t DS1EXPDT
; /* expiration date */
117 __u8 DS1NOEPV
; /* number of extents on volume */
118 __u8 DS1NOBDB
; /* no. of bytes used in last direction blk */
119 __u8 DS1FLAG1
; /* flag 1 */
120 char DS1SYSCD
[13]; /* system code */
121 labeldate_t DS1REFD
; /* date last referenced */
122 __u8 DS1SMSFG
; /* system managed storage indicators */
123 __u8 DS1SCXTF
; /* sec. space extension flag byte */
124 __u16 DS1SCXTV
; /* secondary space extension value */
125 __u8 DS1DSRG1
; /* data set organisation byte 1 */
126 __u8 DS1DSRG2
; /* data set organisation byte 2 */
127 __u8 DS1RECFM
; /* record format */
128 __u8 DS1OPTCD
; /* option code */
129 __u16 DS1BLKL
; /* block length */
130 __u16 DS1LRECL
; /* record length */
131 __u8 DS1KEYL
; /* key length */
132 __u16 DS1RKP
; /* relative key position */
133 __u8 DS1DSIND
; /* data set indicators */
134 __u8 DS1SCAL1
; /* secondary allocation flag byte */
135 char DS1SCAL3
[3]; /* secondary allocation quantity */
136 ttr_t DS1LSTAR
; /* last used track and block on track */
137 __u16 DS1TRBAL
; /* space remaining on last used track */
138 __u16 res1
; /* reserved */
139 extent_t DS1EXT1
; /* first extent description */
140 extent_t DS1EXT2
; /* second extent description */
141 extent_t DS1EXT3
; /* third extent description */
142 cchhb_t DS1PTRDS
; /* possible pointer to f2 or f3 DSCB */
143 } __attribute__ ((packed
)) format1_label_t
;
146 typedef struct format4_label
148 char DS4KEYCD
[44]; /* key code for VTOC labels: 44 times 0x04 */
149 __u8 DS4IDFMT
; /* format identifier */
150 cchhb_t DS4HPCHR
; /* highest address of a format 1 DSCB */
151 __u16 DS4DSREC
; /* number of available DSCB's */
152 cchh_t DS4HCCHH
; /* CCHH of next available alternate track */
153 __u16 DS4NOATK
; /* number of remaining alternate tracks */
154 __u8 DS4VTOCI
; /* VTOC indicators */
155 __u8 DS4NOEXT
; /* number of extents in VTOC */
156 __u8 DS4SMSFG
; /* system managed storage indicators */
157 __u8 DS4DEVAC
; /* number of alternate cylinders.
158 Subtract from first two bytes of
159 DS4DEVSZ to get number of usable
160 cylinders. can be zero. valid
161 only if DS4DEVAV on. */
162 dev_const_t DS4DEVCT
; /* device constants */
163 char DS4AMTIM
[8]; /* VSAM time stamp */
164 char DS4AMCAT
[3]; /* VSAM catalog indicator */
165 char DS4R2TIM
[8]; /* VSAM volume/catalog match time stamp */
166 char res1
[5]; /* reserved */
167 char DS4F6PTR
[5]; /* pointer to first format 6 DSCB */
168 extent_t DS4VTOCE
; /* VTOC extent description */
169 char res2
[10]; /* reserved */
170 __u8 DS4EFLVL
; /* extended free-space management level */
171 cchhb_t DS4EFPTR
; /* pointer to extended free-space info */
172 char res3
[9]; /* reserved */
173 } __attribute__ ((packed
)) format4_label_t
;
176 typedef struct ds5ext
178 __u16 t
; /* RTA of the first track of free extent */
179 __u16 fc
; /* number of whole cylinders in free ext. */
180 __u8 ft
; /* number of remaining free tracks */
181 } __attribute__ ((packed
)) ds5ext_t
;
184 typedef struct format5_label
186 char DS5KEYID
[4]; /* key identifier */
187 ds5ext_t DS5AVEXT
; /* first available (free-space) extent. */
188 ds5ext_t DS5EXTAV
[7]; /* seven available extents */
189 __u8 DS5FMTID
; /* format identifier */
190 ds5ext_t DS5MAVET
[18]; /* eighteen available extents */
191 cchhb_t DS5PTRDS
; /* pointer to next format5 DSCB */
192 } __attribute__ ((packed
)) format5_label_t
;
195 typedef struct ds7ext
197 __u32 a
; /* starting RTA value */
198 __u32 b
; /* ending RTA value + 1 */
199 } __attribute__ ((packed
)) ds7ext_t
;
202 typedef struct format7_label
204 char DS7KEYID
[4]; /* key identifier */
205 ds7ext_t DS7EXTNT
[5]; /* space for 5 extent descriptions */
206 __u8 DS7FMTID
; /* format identifier */
207 ds7ext_t DS7ADEXT
[11]; /* space for 11 extent descriptions */
208 char res1
[2]; /* reserved */
209 cchhb_t DS7PTRDS
; /* pointer to next FMT7 DSCB */
210 } __attribute__ ((packed
)) format7_label_t
;
213 char * vtoc_ebcdic_enc (
214 unsigned char source
[LINE_LENGTH
],
215 unsigned char target
[LINE_LENGTH
],
217 char * vtoc_ebcdic_dec (
218 unsigned char source
[LINE_LENGTH
],
219 unsigned char target
[LINE_LENGTH
],
221 void vtoc_set_extent (
231 void vtoc_set_cchhb (
241 void vtoc_volume_label_init (
242 volume_label_t
*vlabel
);
244 int vtoc_read_volume_label (
246 unsigned long vlabel_start
,
247 volume_label_t
* vlabel
);
249 int vtoc_write_volume_label (
251 unsigned long vlabel_start
,
252 volume_label_t
*vlabel
);
254 void vtoc_volume_label_set_volser (
255 volume_label_t
*vlabel
,
258 char *vtoc_volume_label_get_volser (
259 volume_label_t
*vlabel
,
262 void vtoc_volume_label_set_key (
263 volume_label_t
*vlabel
,
266 void vtoc_volume_label_set_label (
267 volume_label_t
*vlabel
,
270 char *vtoc_volume_label_get_label (
271 volume_label_t
*vlabel
,
274 void vtoc_read_label (
276 unsigned long position
,
280 format7_label_t
*f7
);
282 void vtoc_write_label (
284 unsigned long position
,
288 format7_label_t
*f7
);
291 void vtoc_init_format1_label (
293 unsigned int blksize
,
294 extent_t
*part_extent
,
295 format1_label_t
*f1
);
298 void vtoc_init_format4_label (
299 format4_label_t
*f4lbl
,
300 unsigned int usable_partitions
,
301 unsigned int cylinders
,
304 unsigned int blksize
,
307 void vtoc_update_format4_label (
310 __u16 unused_update
);
313 void vtoc_init_format5_label (
314 format5_label_t
*f5
);
316 void vtoc_update_format5_label_add (
325 void vtoc_update_format5_label_del (
335 void vtoc_init_format7_label (
336 format7_label_t
*f7
);
338 void vtoc_update_format7_label_add (
344 void vtoc_update_format7_label_del (
351 void vtoc_set_freespace(