libparted 3.6
Loading...
Searching...
No Matches
vtoc.in.h
Go to the documentation of this file.
1/*
2 * File...........: s390-tools/dasdview/vtoc.h
3 * Author(s)......: Horst Hummel <horst.hummel@de.ibm.com>
4 * Bugreports.to..: <Linux390@de.ibm.com>
5 *
6 * This is a user-space copy of the kernel vtoc,h.
7 *
8 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 2002
9 *
10 * History of changes (starts March 2002)
11 * 2002-03-12 initial
12 */
13
14#ifndef VTOC_H
15#define VTOC_H
16
17#include <string.h>
18#include <stdlib.h>
19#include <stdio.h>
20#include <errno.h>
21#include <ctype.h>
22#include <time.h>
23#include <fcntl.h>
24#include <unistd.h>
25
26#include <sys/stat.h>
27#include <sys/ioctl.h>
28
29#define LINE_LENGTH 80
30#define VTOC_START_CC 0x0
31#define VTOC_START_HH 0x1
32#define FIRST_USABLE_CYL 1
33#define FIRST_USABLE_TRK 2
34
35#define DASD_3380_TYPE 13148
36#define DASD_3390_TYPE 13200
37#define DASD_9345_TYPE 37701
38
39#define DASD_3380_VALUE 0xbb60
40#define DASD_3390_VALUE 0xe5a2
41#define DASD_9345_VALUE 0xbc98
42
43#define VOLSER_LENGTH 6
44#define BIG_DISK_SIZE 0x10000
45#define LV_COMPAT_CYL 0xFFFE
46
47/*****************************************************************************
48 * SECTION: Definition from hdreq.h *
49 *****************************************************************************/
50
51struct fdasd_hd_geometry {
52 unsigned char heads;
53 unsigned char sectors;
54 unsigned short cylinders;
55 unsigned long start;
56};
57
58
59typedef struct ttr ttr_t;
60typedef struct cchhb cchhb_t;
61typedef struct cchh cchh_t;
62typedef struct labeldate labeldate_t;
63typedef struct volume_label volume_label_t;
64typedef struct cms_volume_label cms_volume_label_t;
65typedef struct extent extent_t;
66typedef struct dev_const dev_const_t;
67typedef struct format1_label format1_label_t;
68typedef struct format4_label format4_label_t;
69typedef struct ds5ext ds5ext_t;
70typedef struct format5_label format5_label_t;
71typedef struct ds7ext ds7ext_t;
72typedef struct format7_label format7_label_t;
73typedef struct format9_label format9_label_t;
74
75struct __attribute__ ((packed)) ttr {
76 u_int16_t tt;
77 u_int8_t r;
78};
79
80struct __attribute__ ((packed)) cchhb {
81 u_int16_t cc;
82 u_int16_t hh;
83 u_int8_t b;
84};
85
86struct __attribute__ ((packed)) cchh {
87 u_int16_t cc;
88 u_int16_t hh;
89};
90
91struct __attribute__ ((packed)) labeldate {
92 u_int8_t year;
93 u_int16_t day;
94};
95
96/*
97 * The following structure is a merger of the cdl and ldl volume label.
98 * On an ldl disk there is no key information, so when reading an
99 * ldl label from disk, the data should be copied at the address of vollbl.
100 * On the other side, the field ldl_version is reserved in a cdl record
101 * and the field formatted_blocks exists only for ldl labels. So when
102 * reading a cdl label from disk, the formatted_blocks field will contain
103 * arbitrary data.
104 * This layout may be a bit awkward, but the advantage of having the
105 * same label type for both disk layout types is bigger than the effort
106 * for taking a bit of extra care at the fringes.
107 */
108
109struct __attribute__ ((packed)) volume_label {
110 char volkey[4]; /* volume key = volume label */
111 char vollbl[4]; /* volume label ("VOL1" in EBCDIC) */
112 char volid[6]; /* volume identifier */
113 u_int8_t security; /* security byte */
114 cchhb_t vtoc; /* VTOC address */
115 char res1[5]; /* reserved */
116 char cisize[4]; /* CI-size for FBA,... */
117 /* ...blanks for CKD */
118 char blkperci[4]; /* no of blocks per CI (FBA), blanks for CKD */
119 char labperci[4]; /* no of labels per CI (FBA), blanks for CKD */
120 char res2[4]; /* reserved */
121 char lvtoc[14]; /* owner code for LVTOC */
122 char res3[28]; /* reserved */
123 char ldl_version; /* version number, valid for ldl format */
124 u_int64_t formatted_blocks; /* valid when ldl_version >= "2" (in
125 EBCDIC) */
126};
127
128/*
129 * See:
130 * z/VM V5R2.0 CMS Planning and Administration
131 * SC24-6078-01
132 * What CMS Does / Disk and File Management / Disk File Format
133 * http://publib.boulder.ibm.com/infocenter/zvm/v5r4/topic/com.ibm.zvm.v54.dmsd1/hcsg2b1018.htm
134 */
135struct __attribute__ ((packed)) cms_volume_label {
136 char label_id[4]; /* Label identifier ("CMS1" in EBCDIC) */
137 char vol_id[6]; /* Volume identifier */
138 char version_id[2]; /* Version identifier ("\0\0") */
139 u_int32_t block_size; /* Disk block size (512, 1024, 2048 or 4096) */
140 u_int32_t origin_ptr; /* Disk origin pointer (4 or 5) */
141 u_int32_t usable_count; /* Number of usable cylinders/blocks */
142 u_int32_t formatted_count; /* Max # of formatted cylinders/blocks */
143 u_int32_t block_count; /* Disk size in CMS blocks */
144 u_int32_t used_count; /* Number of CMS blocks in use */
145 u_int32_t fst_size; /* File Status Table (FST) size (64) */
146 u_int32_t fst_count; /* Number of FSTs per CMS block */
147 char format_date[6]; /* Disk FORMAT date (YYMMDDhhmmss) */
148 char reserved1[2]; /* Reserved fields.
149 The low-order bit of the first byte is a
150 century flag. 0 = 1900s, 1 = 2000s.
151 It is used in conjunction with
152 "format_date" to determine the
153 four-digit year. */
154 u_int32_t disk_offset; /* Offset in blocks to the start of the
155 reserved file when the disk is reserved.
156 This is the number of blocks to skip
157 before the partition starts. */
158 u_int32_t map_block; /* Allocation map block with next hole */
159 u_int32_t hblk_disp; /* Displacement in HBLK data of next hole */
160 u_int32_t user_disp; /* Disp into user part of allocation map */
161 u_int32_t open_files; /* Count of SFS open files for this ADT.
162 open_files is not really part of the
163 volume label. It is not used for
164 minidisks. */
165 char segment_name[8]; /* Name of the shared segment.
166 segment_name is not really part of the
167 volume label. It is not stored on disk. */
168};
169
170struct __attribute__ ((packed)) extent {
171 u_int8_t typeind; /* extent type indicator */
172 u_int8_t seqno; /* extent sequence number */
173 cchh_t llimit; /* starting point of this extent */
174 cchh_t ulimit; /* ending point of this extent */
175};
176
177struct __attribute__ ((packed)) dev_const {
178 u_int16_t DS4DSCYL; /* number of logical cyls */
179 u_int16_t DS4DSTRK; /* number of tracks in a logical cylinder */
180 u_int16_t DS4DEVTK; /* device track length */
181 u_int8_t DS4DEVI; /* non-last keyed record overhead */
182 u_int8_t DS4DEVL; /* last keyed record overhead */
183 u_int8_t DS4DEVK; /* non-keyed record overhead differential */
184 u_int8_t DS4DEVFG; /* flag byte */
185 u_int16_t DS4DEVTL; /* device tolerance */
186 u_int8_t DS4DEVDT; /* number of DSCB's per track */
187 u_int8_t DS4DEVDB; /* number of directory blocks per track */
188};
189
190/*
191 * format 1 and format 8 label have the same layout so we use the following
192 * structure for both.
193 */
194struct __attribute__ ((packed)) format1_label {
195 char DS1DSNAM[44]; /* data set name */
196 u_int8_t DS1FMTID; /* format identifier */
197 char DS1DSSN[6]; /* data set serial number */
198 u_int16_t DS1VOLSQ; /* volume sequence number */
199 labeldate_t DS1CREDT; /* creation date: ydd */
200 labeldate_t DS1EXPDT; /* expiration date */
201 u_int8_t DS1NOEPV; /* number of extents on volume */
202 u_int8_t DS1NOBDB; /* no. of bytes used in last direction blk */
203 u_int8_t DS1FLAG1; /* flag 1 */
204 char DS1SYSCD[13]; /* system code */
205 labeldate_t DS1REFD; /* date last referenced */
206 u_int8_t DS1SMSFG; /* system managed storage indicators */
207 u_int8_t DS1SCXTF; /* sec. space extension flag byte */
208 u_int16_t DS1SCXTV; /* secondary space extension value */
209 u_int8_t DS1DSRG1; /* data set organisation byte 1 */
210 u_int8_t DS1DSRG2; /* data set organisation byte 2 */
211 u_int8_t DS1RECFM; /* record format */
212 u_int8_t DS1OPTCD; /* option code */
213 u_int16_t DS1BLKL; /* block length */
214 u_int16_t DS1LRECL; /* record length */
215 u_int8_t DS1KEYL; /* key length */
216 u_int16_t DS1RKP; /* relative key position */
217 u_int8_t DS1DSIND; /* data set indicators */
218 u_int8_t DS1SCAL1; /* secondary allocation flag byte */
219 char DS1SCAL3[3]; /* secondary allocation quantity */
220 ttr_t DS1LSTAR; /* last used track and block on track */
221 u_int16_t DS1TRBAL; /* space remaining on last used track */
222 u_int16_t res1; /* reserved */
223 extent_t DS1EXT1; /* first extent description */
224 extent_t DS1EXT2; /* second extent description */
225 extent_t DS1EXT3; /* third extent description */
226 cchhb_t DS1PTRDS; /* possible pointer to f2 or f3 DSCB */
227};
228
229struct __attribute__ ((packed)) format4_label {
230 char DS4KEYCD[44]; /* key code for VTOC labels: 44 times 0x04 */
231 u_int8_t DS4IDFMT; /* format identifier */
232 cchhb_t DS4HPCHR; /* highest address of a format 1 DSCB */
233 u_int16_t DS4DSREC; /* number of available DSCB's */
234 cchh_t DS4HCCHH; /* CCHH of next available alternate track */
235 u_int16_t DS4NOATK; /* number of remaining alternate tracks */
236 u_int8_t DS4VTOCI; /* VTOC indicators */
237 u_int8_t DS4NOEXT; /* number of extents in VTOC */
238 u_int8_t DS4SMSFG; /* system managed storage indicators */
239 u_int8_t DS4DEVAC; /* number of alternate cylinders.
240 Subtract from first two bytes of
241 DS4DEVSZ to get number of usable
242 cylinders. can be zero. valid
243 only if DS4DEVAV on. */
244 dev_const_t DS4DEVCT; /* device constants */
245 char DS4AMTIM[8]; /* VSAM timestamp */
246 char DS4AMCAT[3]; /* VSAM catalog indicator */
247 char DS4R2TIM[8]; /* VSAM volume/catalog match timestamp */
248 char res1[5]; /* reserved */
249 char DS4F6PTR[5]; /* pointer to first format 6 DSCB */
250 extent_t DS4VTOCE; /* VTOC extent description */
251 char res2[10]; /* reserved */
252 u_int8_t DS4EFLVL; /* extended free-space management level */
253 cchhb_t DS4EFPTR; /* pointer to extended free-space info */
254 char res3; /* reserved */
255 u_int32_t DS4DCYL; /* number of logical cyls */
256 char res4[2]; /* reserved */
257 u_int8_t DS4DEVF2; /* device flags */
258 char res5; /* reserved */
259};
260
261struct __attribute__ ((packed)) ds5ext {
262 u_int16_t t; /* RTA of the first track of free extent */
263 u_int16_t fc; /* number of whole cylinders in free ext. */
264 u_int8_t ft; /* number of remaining free tracks */
265};
266
267struct __attribute__ ((packed)) format5_label {
268 char DS5KEYID[4]; /* key identifier */
269 ds5ext_t DS5AVEXT; /* first available (free-space) extent. */
270 ds5ext_t DS5EXTAV[7]; /* seven available extents */
271 u_int8_t DS5FMTID; /* format identifier */
272 ds5ext_t DS5MAVET[18]; /* eighteen available extents */
273 cchhb_t DS5PTRDS; /* pointer to next format5 DSCB */
274};
275
276struct __attribute__ ((packed)) ds7ext {
277 u_int32_t a; /* starting RTA value */
278 u_int32_t b; /* ending RTA value + 1 */
279};
280
281struct __attribute__ ((packed)) format7_label {
282 char DS7KEYID[4]; /* key identifier */
283 ds7ext_t DS7EXTNT[5]; /* space for 5 extent descriptions */
284 u_int8_t DS7FMTID; /* format identifier */
285 ds7ext_t DS7ADEXT[11]; /* space for 11 extent descriptions */
286 char res1[2]; /* reserved */
287 cchhb_t DS7PTRDS; /* pointer to next FMT7 DSCB */
288};
289
290struct __attribute__ ((packed)) format9_label {
291 u_int8_t DS9KEYID; /* key code for format 9 labels (0x09) */
292 u_int8_t DS9SUBTY; /* subtype (0x01) */
293 u_int8_t DS9NUMF9; /* number of F9 datasets */
294 u_int8_t res1[41]; /* reserved */
295 u_int8_t DS9FMTID; /* format identifier */
296 u_int8_t res2[95]; /* reserved */
297};
298
299char *vtoc_ebcdic_enc (char const *source, char *target, int l);
300char *vtoc_ebcdic_dec (char const *source, char *target, int l);
301void vtoc_set_extent (extent_t *ext, u_int8_t typeind, u_int8_t seqno,
303void vtoc_set_cchh (cchh_t *addr, u_int32_t cc, u_int16_t hh);
304u_int32_t vtoc_get_cyl_from_cchh(cchh_t *addr);
305u_int16_t vtoc_get_head_from_cchh(cchh_t *addr);
306void vtoc_set_cchhb (cchhb_t *addr, u_int32_t cc, u_int16_t hh, u_int8_t b);
307u_int32_t vtoc_get_cyl_from_cchhb(cchhb_t *addr);
308u_int16_t vtoc_get_head_from_cchhb(cchhb_t *addr);
309u_int64_t cchhb2blk(cchhb_t *p, struct fdasd_hd_geometry *geo);
310u_int64_t cchh2blk (cchh_t *p, struct fdasd_hd_geometry *geo);
311u_int32_t cchh2trk (cchh_t *p, struct fdasd_hd_geometry *geo);
312void vtoc_set_date (labeldate_t *d, u_int8_t year, u_int16_t day);
313
315
316int vtoc_read_volume_label (int fd, unsigned long vlabel_start,
317 volume_label_t *vlabel);
318
319int vtoc_write_volume_label (int fd, unsigned long vlabel_start,
320 volume_label_t const *vlabel);
321
322void vtoc_volume_label_set_volser (volume_label_t *vlabel, char const *volser);
323
324char *vtoc_volume_label_get_volser (volume_label_t *vlabel, char *volser);
325
326void vtoc_volume_label_set_key (volume_label_t *vlabel, char const *key);
327
328void vtoc_volume_label_set_label (volume_label_t *vlabel, char const *lbl);
329
330char *vtoc_volume_label_get_label (volume_label_t *vlabel, char *lbl);
331
332void vtoc_read_label (int fd, unsigned long position, format1_label_t *f1,
334 format7_label_t *f7);
335
336void vtoc_write_label (int fd, unsigned long position,
337 format1_label_t const *f1,
338 format4_label_t const *f4,
339 format5_label_t const *f5,
340 format7_label_t const *f7,
341 format9_label_t const *f9);
342
343void vtoc_init_format1_label (unsigned int blksize,
344 extent_t *part_extent, format1_label_t *f1);
345
347 unsigned int compat_cylinders,
348 unsigned int real_cylinders,
349 unsigned int tracks,
350 unsigned int blocks,
351 unsigned int blksize,
352 u_int16_t dev_type);
353
355 u_int16_t unused_update);
356
358
360 int trk, u_int16_t a, u_int16_t b,
361 u_int8_t c);
362
364 int trk, u_int16_t a, u_int16_t b,
365 u_int8_t c);
366
368
370 u_int32_t a, u_int32_t b);
371
373 u_int32_t a, u_int32_t b);
374
375void vtoc_init_format8_label (unsigned int blksize,
376 extent_t *part_extent, format1_label_t *f1);
377
378void vtoc_update_format8_label (cchhb_t *associated_f9, format1_label_t *f8);
379
381
383 format7_label_t *f7, char ch, int verbose,
384 u_int32_t start, u_int32_t stop, u_int32_t cyl,
385 u_int32_t trk);
386
387#endif /* VTOC_H */
typedef __attribute__
Definition: vtoc.h:80
uint32_t start
Definition: dos.c:4
uint64_t block_count
Definition: f2fs.h:10
unsigned char f1
Definition: fdasd.h:0
unsigned short dev_type
Definition: fdasd.h:8
@ upper
Definition: fdasd.h:264
@ lower
Definition: fdasd.h:264
unsigned char f5
Definition: fdasd.h:4
unsigned char f4
Definition: fdasd.h:3
unsigned char reserved1
Definition: fdasd.h:2
uint16_t cyl
Definition: pc98.c:9
Definition: vtoc.h:51
unsigned long start
Definition: vtoc.h:55
unsigned char sectors
Definition: vtoc.h:53
unsigned short cylinders
Definition: vtoc.h:54
unsigned char heads
Definition: vtoc.h:52
struct volume_label volume_label_t
Definition: vtoc.h:63
struct ds7ext ds7ext_t
Definition: vtoc.h:71
struct labeldate labeldate_t
Definition: vtoc.h:62
struct format7_label format7_label_t
Definition: vtoc.h:72
struct format4_label format4_label_t
Definition: vtoc.h:68
struct format1_label format1_label_t
Definition: vtoc.h:67
struct cchhb cchhb_t
Definition: vtoc.h:60
struct dev_const dev_const_t
Definition: vtoc.h:66
struct cms_volume_label cms_volume_label_t
Definition: vtoc.h:64
struct format9_label format9_label_t
Definition: vtoc.h:73
struct format5_label format5_label_t
Definition: vtoc.h:70
struct cchh cchh_t
Definition: vtoc.h:61
struct ds5ext ds5ext_t
Definition: vtoc.h:69
struct extent extent_t
Definition: vtoc.h:65
struct ttr ttr_t
Definition: vtoc.h:59
u_int32_t cchh2trk(cchh_t *p, struct fdasd_hd_geometry *geo)
Definition: vtoc.c:311
void vtoc_init_format1_label(unsigned int blksize, extent_t *part_extent, format1_label_t *f1)
Definition: vtoc.c:793
u_int64_t cchhb2blk(cchhb_t *p, struct fdasd_hd_geometry *geo)
Definition: vtoc.c:294
void vtoc_init_format9_label(format9_label_t *f9)
Definition: vtoc.c:815
void vtoc_update_format7_label_del(format7_label_t *f7, int verbose, u_int32_t a, u_int32_t b)
Definition: vtoc.c:1212
u_int16_t vtoc_get_head_from_cchhb(cchhb_t *addr)
Definition: vtoc.c:281
void vtoc_init_format4_label(format4_label_t *f4lbl, unsigned int compat_cylinders, unsigned int real_cylinders, unsigned int tracks, unsigned int blocks, unsigned int blksize, u_int16_t dev_type)
Definition: vtoc.c:631
void vtoc_update_format7_label_add(format7_label_t *f7, int verbose, u_int32_t a, u_int32_t b)
Definition: vtoc.c:1131
void vtoc_init_format5_label(format5_label_t *f5)
Definition: vtoc.c:708
char * vtoc_ebcdic_enc(char const *source, char *target, int l)
Definition: vtoc.c:186
char * vtoc_volume_label_get_label(volume_label_t *vlabel, char *lbl)
Definition: vtoc.c:516
u_int32_t vtoc_get_cyl_from_cchh(cchh_t *addr)
Definition: vtoc.c:231
void vtoc_set_date(labeldate_t *d, u_int8_t year, u_int16_t day)
Definition: vtoc.c:318
void vtoc_set_cchhb(cchhb_t *addr, u_int32_t cc, u_int16_t hh, u_int8_t b)
Definition: vtoc.c:258
int vtoc_write_volume_label(int fd, unsigned long vlabel_start, volume_label_t const *vlabel)
Definition: vtoc.c:418
char * vtoc_ebcdic_dec(char const *source, char *target, int l)
Definition: vtoc.c:198
void vtoc_write_label(int fd, unsigned long position, format1_label_t const *f1, format4_label_t const *f4, format5_label_t const *f5, format7_label_t const *f7, format9_label_t const *f9)
Definition: vtoc.c:573
void vtoc_set_cchh(cchh_t *addr, u_int32_t cc, u_int16_t hh)
Definition: vtoc.c:221
void vtoc_volume_label_init(volume_label_t *vlabel)
Definition: vtoc.c:329
void vtoc_init_format8_label(unsigned int blksize, extent_t *part_extent, format1_label_t *f1)
Definition: vtoc.c:801
void vtoc_update_format8_label(cchhb_t *associated_f9, format1_label_t *f8)
Definition: vtoc.c:809
u_int32_t vtoc_get_cyl_from_cchhb(cchhb_t *addr)
Definition: vtoc.c:269
void vtoc_update_format5_label_del(format5_label_t *f5, int verbose, int trk, u_int16_t a, u_int16_t b, u_int8_t c)
Definition: vtoc.c:973
void vtoc_set_extent(extent_t *ext, u_int8_t typeind, u_int8_t seqno, cchh_t *lower, cchh_t *upper)
Definition: vtoc.c:210
u_int64_t cchh2blk(cchh_t *p, struct fdasd_hd_geometry *geo)
Definition: vtoc.c:303
void vtoc_init_format7_label(format7_label_t *f7)
Definition: vtoc.c:723
void vtoc_set_freespace(format4_label_t *f4, format5_label_t *f5, format7_label_t *f7, char ch, int verbose, u_int32_t start, u_int32_t stop, u_int32_t cyl, u_int32_t trk)
Definition: vtoc.c:1289
void vtoc_update_format5_label_add(format5_label_t *f5, int verbose, int trk, u_int16_t a, u_int16_t b, u_int8_t c)
Definition: vtoc.c:885
void vtoc_update_format4_label(format4_label_t *f4, cchhb_t *highest_f1, u_int16_t unused_update)
Definition: vtoc.c:827
void vtoc_volume_label_set_key(volume_label_t *vlabel, char const *key)
Definition: vtoc.c:484
void vtoc_read_label(int fd, unsigned long position, format1_label_t *f1, format4_label_t *f4, format5_label_t *f5, format7_label_t *f7)
Definition: vtoc.c:529
char * vtoc_volume_label_get_volser(volume_label_t *vlabel, char *volser)
Definition: vtoc.c:471
void vtoc_volume_label_set_volser(volume_label_t *vlabel, char const *volser)
Definition: vtoc.c:442
void vtoc_volume_label_set_label(volume_label_t *vlabel, char const *lbl)
Definition: vtoc.c:500
int vtoc_read_volume_label(int fd, unsigned long vlabel_start, volume_label_t *vlabel)
Definition: vtoc.c:341
u_int16_t vtoc_get_head_from_cchh(cchh_t *addr)
Definition: vtoc.c:243