~youscribe/parted/3.1

« back to all changes in this revision

Viewing changes to include/parted/vtoc.in.h

  • Committer: Guilhem Lettron
  • Date: 2012-10-22 14:37:59 UTC
  • Revision ID: guilhem+ubuntu@lettron.fr-20121022143759-m403kecgz13sknvp
3.1 from tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
46
 
 
47
typedef struct ttr              ttr_t;
 
48
typedef struct cchhb            cchhb_t;
 
49
typedef struct cchh             cchh_t;
 
50
typedef struct labeldate        labeldate_t;
 
51
typedef struct volume_label     volume_label_t;
 
52
typedef struct cms_volume_label cms_volume_label_t;
 
53
typedef struct ldl_volume_label ldl_volume_label_t;
 
54
typedef struct extent           extent_t;
 
55
typedef struct dev_const        dev_const_t;
 
56
typedef struct format1_label    format1_label_t;
 
57
typedef struct format4_label    format4_label_t;
 
58
typedef struct ds5ext           ds5ext_t;
 
59
typedef struct format5_label    format5_label_t;
 
60
typedef struct ds7ext           ds7ext_t;
 
61
typedef struct format7_label    format7_label_t;
 
62
 
 
63
struct __attribute__ ((packed)) ttr {
 
64
        u_int16_t tt;
 
65
        u_int8_t  r;
 
66
};
 
67
 
 
68
struct  __attribute__ ((packed)) cchhb {
 
69
        u_int16_t cc;
 
70
        u_int16_t hh;
 
71
        u_int8_t b;
 
72
};
 
73
 
 
74
struct __attribute__ ((packed)) cchh {
 
75
        u_int16_t cc;
 
76
        u_int16_t hh;
 
77
};
 
78
 
 
79
struct __attribute__ ((packed)) labeldate {
 
80
        u_int8_t  year;
 
81
        u_int16_t day;
 
82
};
 
83
 
 
84
struct __attribute__ ((packed)) volume_label {
 
85
        char volkey[4];         /* volume key = volume label                 */
 
86
        char vollbl[4];         /* volume label ("VOL1" in EBCDIC)           */
 
87
        char volid[6];          /* volume identifier                         */
 
88
        u_int8_t security;      /* security byte                             */
 
89
        cchhb_t vtoc;           /* VTOC address                              */
 
90
        char res1[5];           /* reserved                                  */
 
91
        char cisize[4];         /* CI-size for FBA,...                       */
 
92
                                /* ...blanks for CKD                         */
 
93
        char blkperci[4];       /* no of blocks per CI (FBA), blanks for CKD */
 
94
        char labperci[4];       /* no of labels per CI (FBA), blanks for CKD */
 
95
        char res2[4];           /* reserved                                  */
 
96
        char lvtoc[14];         /* owner code for LVTOC                      */
 
97
        char res3[29];          /* reserved                                  */
 
98
        char fudge[4];          /* filler to match length of ldl label       */
 
99
};
 
100
 
 
101
struct __attribute__ ((packed)) ldl_volume_label {
 
102
        char vollbl[4];         /* Label identifier ("LNX1" in EBCDIC)       */
 
103
        char volid[6];          /* Volume identifier                         */
 
104
        char res3[69];          /* Reserved field                            */
 
105
        char ldl_version[1];    /* Version number, valid for ldl format      */
 
106
        u_int64_t formatted_blocks;  /* valid when ldl_version >= "2" (in
 
107
                                        EBCDIC)                              */
 
108
};
 
109
 
 
110
/*
 
111
 * See:
 
112
 *      z/VM V5R2.0 CMS Planning and Administration
 
113
 *      SC24-6078-01
 
114
 *      What CMS Does / Disk and File Management / Disk File Format
 
115
 * http://publib.boulder.ibm.com/infocenter/zvm/v5r4/topic/com.ibm.zvm.v54.dmsd1/hcsg2b1018.htm
 
116
 */
 
117
struct __attribute__ ((packed)) cms_volume_label {
 
118
        char label_id[4];       /* Label identifier ("CMS1" in EBCDIC)       */
 
119
        char vol_id[6];         /* Volume identifier                         */
 
120
        char version_id[2];     /* Version identifier ("\0\0")               */
 
121
        u_int32_t block_size;   /* Disk block size (512, 1024, 2048 or 4096) */
 
122
        u_int32_t origin_ptr;   /* Disk origin pointer (4 or 5)              */
 
123
        u_int32_t usable_count; /* Number of usable cylinders/blocks         */
 
124
        u_int32_t formatted_count; /* Max # of formatted cylinders/blocks    */
 
125
        u_int32_t block_count;  /* Disk size in CMS blocks                   */
 
126
        u_int32_t used_count;   /* Number of CMS blocks in use               */
 
127
        u_int32_t fst_size;     /* File Status Table (FST) size (64)         */
 
128
        u_int32_t fst_count;    /* Number of FSTs per CMS block              */
 
129
        char format_date[6];    /* Disk FORMAT date (YYMMDDhhmmss)           */
 
130
        char reserved1[2];      /* Reserved fields.
 
131
                                   The low-order bit of the first byte is a
 
132
                                   century flag.  0 = 1900s, 1 = 2000s.
 
133
                                   It is used in conjunction with
 
134
                                   "format_date" to determine the
 
135
                                   four-digit year.                          */
 
136
        u_int32_t disk_offset;  /* Offset in blocks to the start of the
 
137
                                   reserved file when the disk is reserved.
 
138
                                   This is the number of blocks to skip
 
139
                                   before the partition starts.              */
 
140
        u_int32_t map_block;    /* Allocation map block with next hole       */
 
141
        u_int32_t hblk_disp;    /* Displacement in HBLK data of next hole    */
 
142
        u_int32_t user_disp;    /* Disp into user part of allocation map     */
 
143
        u_int32_t open_files;   /* Count of SFS open files for this ADT.
 
144
                                   open_files is not really part of the
 
145
                                   volume label.  It is not used for
 
146
                                   minidisks.                                */
 
147
        char segment_name[8];   /* Name of the shared segment.
 
148
                                   segment_name is not really part of the
 
149
                                   volume label.  It is not stored on disk.  */
 
150
};
 
151
 
 
152
struct __attribute__ ((packed)) extent {
 
153
        u_int8_t  typeind;      /* extent type indicator */
 
154
        u_int8_t  seqno;        /* extent sequence number */
 
155
        cchh_t llimit;          /* starting point of this extent */
 
156
        cchh_t ulimit;          /* ending point of this extent */
 
157
};
 
158
 
 
159
struct __attribute__ ((packed)) dev_const {
 
160
        u_int16_t DS4DSCYL;     /* number of logical cyls */
 
161
        u_int16_t DS4DSTRK;     /* number of tracks in a logical cylinder  */
 
162
        u_int16_t DS4DEVTK;     /* device track length */
 
163
        u_int8_t  DS4DEVI;      /* non-last keyed record overhead */
 
164
        u_int8_t  DS4DEVL;      /* last keyed record overhead */
 
165
        u_int8_t  DS4DEVK;      /* non-keyed record overhead differential */
 
166
        u_int8_t  DS4DEVFG;     /* flag byte */
 
167
        u_int16_t DS4DEVTL;     /* device tolerance */
 
168
        u_int8_t  DS4DEVDT;     /* number of DSCB's per track */
 
169
        u_int8_t  DS4DEVDB;     /* number of directory blocks per track */
 
170
};
 
171
 
 
172
struct __attribute__ ((packed)) format1_label {
 
173
        char  DS1DSNAM[44];     /* data set name                           */
 
174
        u_int8_t  DS1FMTID;     /* format identifier                       */
 
175
        char  DS1DSSN[6];       /* data set serial number                  */
 
176
        u_int16_t DS1VOLSQ;     /* volume sequence number                  */
 
177
        labeldate_t DS1CREDT;   /* creation date: ydd                      */
 
178
        labeldate_t DS1EXPDT;   /* expiration date                         */
 
179
        u_int8_t  DS1NOEPV;     /* number of extents on volume             */
 
180
        u_int8_t  DS1NOBDB;     /* no. of bytes used in last direction blk */
 
181
        u_int8_t  DS1FLAG1;     /* flag 1                                  */
 
182
        char  DS1SYSCD[13];     /* system code                             */
 
183
        labeldate_t DS1REFD;    /* date last referenced                    */
 
184
        u_int8_t  DS1SMSFG;     /* system managed storage indicators       */
 
185
        u_int8_t  DS1SCXTF;     /* sec. space extension flag byte          */
 
186
        u_int16_t DS1SCXTV;     /* secondary space extension value         */
 
187
        u_int8_t  DS1DSRG1;     /* data set organisation byte 1            */
 
188
        u_int8_t  DS1DSRG2;     /* data set organisation byte 2            */
 
189
        u_int8_t  DS1RECFM;     /* record format                           */
 
190
        u_int8_t  DS1OPTCD;     /* option code                             */
 
191
        u_int16_t DS1BLKL;      /* block length                            */
 
192
        u_int16_t DS1LRECL;     /* record length                           */
 
193
        u_int8_t  DS1KEYL;      /* key length                              */
 
194
        u_int16_t DS1RKP;       /* relative key position                   */
 
195
        u_int8_t  DS1DSIND;     /* data set indicators                     */
 
196
        u_int8_t  DS1SCAL1;     /* secondary allocation flag byte          */
 
197
        char DS1SCAL3[3];       /* secondary allocation quantity           */
 
198
        ttr_t DS1LSTAR;         /* last used track and block on track      */
 
199
        u_int16_t DS1TRBAL;     /* space remaining on last used track      */
 
200
        u_int16_t res1;         /* reserved                                */
 
201
        extent_t DS1EXT1;       /* first extent description                */
 
202
        extent_t DS1EXT2;       /* second extent description               */
 
203
        extent_t DS1EXT3;       /* third extent description                */
 
204
        cchhb_t DS1PTRDS;       /* possible pointer to f2 or f3 DSCB       */
 
205
};
 
206
 
 
207
struct __attribute__ ((packed)) format4_label {
 
208
        char  DS4KEYCD[44];     /* key code for VTOC labels: 44 times 0x04 */
 
209
        u_int8_t  DS4IDFMT;     /* format identifier                       */
 
210
        cchhb_t DS4HPCHR;       /* highest address of a format 1 DSCB      */
 
211
        u_int16_t DS4DSREC;     /* number of available DSCB's              */
 
212
        cchh_t DS4HCCHH;        /* CCHH of next available alternate track  */
 
213
        u_int16_t DS4NOATK;     /* number of remaining alternate tracks    */
 
214
        u_int8_t  DS4VTOCI;     /* VTOC indicators                         */
 
215
        u_int8_t  DS4NOEXT;     /* number of extents in VTOC               */
 
216
        u_int8_t  DS4SMSFG;     /* system managed storage indicators       */
 
217
        u_int8_t  DS4DEVAC;     /* number of alternate cylinders.
 
218
                                   Subtract from first two bytes of
 
219
                                   DS4DEVSZ to get number of usable
 
220
                                   cylinders. can be zero. valid
 
221
                                   only if DS4DEVAV on.                    */
 
222
        dev_const_t DS4DEVCT;   /* device constants                        */
 
223
        char DS4AMTIM[8];       /* VSAM time stamp                         */
 
224
        char DS4AMCAT[3];       /* VSAM catalog indicator                  */
 
225
        char DS4R2TIM[8];       /* VSAM volume/catalog match time stamp    */
 
226
        char res1[5];           /* reserved                                */
 
227
        char DS4F6PTR[5];       /* pointer to first format 6 DSCB          */
 
228
        extent_t DS4VTOCE;      /* VTOC extent description                 */
 
229
        char res2[10];          /* reserved                                */
 
230
        u_int8_t DS4EFLVL;      /* extended free-space management level    */
 
231
        cchhb_t DS4EFPTR;       /* pointer to extended free-space info     */
 
232
        char res3[9];           /* reserved                                */
 
233
};
 
234
 
 
235
struct __attribute__ ((packed)) ds5ext {
 
236
        u_int16_t t;            /* RTA of the first track of free extent   */
 
237
        u_int16_t fc;           /* number of whole cylinders in free ext.  */
 
238
        u_int8_t  ft;           /* number of remaining free tracks         */
 
239
};
 
240
 
 
241
struct __attribute__ ((packed)) format5_label {
 
242
        char DS5KEYID[4];       /* key identifier                          */
 
243
        ds5ext_t DS5AVEXT;      /* first available (free-space) extent.    */
 
244
        ds5ext_t DS5EXTAV[7];   /* seven available extents                 */
 
245
        u_int8_t DS5FMTID;      /* format identifier                       */
 
246
        ds5ext_t DS5MAVET[18];  /* eighteen available extents              */
 
247
        cchhb_t DS5PTRDS;       /* pointer to next format5 DSCB            */
 
248
};
 
249
 
 
250
struct __attribute__ ((packed)) ds7ext {
 
251
        u_int32_t a;            /* starting RTA value                      */
 
252
        u_int32_t b;            /* ending RTA value + 1                    */
 
253
};
 
254
 
 
255
struct __attribute__ ((packed)) format7_label {
 
256
        char DS7KEYID[4];       /* key identifier                          */
 
257
        ds7ext_t DS7EXTNT[5];   /* space for 5 extent descriptions         */
 
258
        u_int8_t DS7FMTID;      /* format identifier                       */
 
259
        ds7ext_t DS7ADEXT[11];  /* space for 11 extent descriptions        */
 
260
        char res1[2];           /* reserved                                */
 
261
        cchhb_t DS7PTRDS;       /* pointer to next FMT7 DSCB               */
 
262
};
 
263
 
 
264
char *vtoc_ebcdic_enc (char const *source, char *target, int l);
 
265
char *vtoc_ebcdic_dec (char const *source, char *target, int l);
 
266
void vtoc_set_extent (extent_t *ext, u_int8_t typeind, u_int8_t seqno,
 
267
                      cchh_t *lower, cchh_t *upper);
 
268
void vtoc_set_cchh (cchh_t *addr, u_int16_t cc, u_int16_t hh);
 
269
void vtoc_set_cchhb (cchhb_t *addr, u_int16_t cc, u_int16_t hh, u_int8_t b);
 
270
void vtoc_set_date (labeldate_t *d, u_int8_t year, u_int16_t day);
 
271
 
 
272
void vtoc_volume_label_init (volume_label_t *vlabel);
 
273
 
 
274
int vtoc_read_volume_label (int fd, unsigned long vlabel_start,
 
275
                            volume_label_t *vlabel);
 
276
 
 
277
int vtoc_write_volume_label (int fd, unsigned long vlabel_start,
 
278
                             volume_label_t const *vlabel);
 
279
 
 
280
void vtoc_volume_label_set_volser (volume_label_t *vlabel, char const *volser);
 
281
 
 
282
char *vtoc_volume_label_get_volser (volume_label_t *vlabel, char *volser);
 
283
 
 
284
void vtoc_volume_label_set_key (volume_label_t *vlabel, char const *key);
 
285
 
 
286
void vtoc_volume_label_set_label (volume_label_t *vlabel, char const *lbl);
 
287
 
 
288
char *vtoc_volume_label_get_label (volume_label_t *vlabel, char *lbl);
 
289
 
 
290
void vtoc_read_label (int fd, unsigned long position, format1_label_t *f1,
 
291
                      format4_label_t *f4, format5_label_t *f5,
 
292
                      format7_label_t *f7);
 
293
 
 
294
void vtoc_write_label (int fd, unsigned long position,
 
295
                       format1_label_t const *f1,
 
296
                       format4_label_t const *f4,
 
297
                       format5_label_t const *f5,
 
298
                       format7_label_t const *f7);
 
299
 
 
300
void vtoc_init_format1_label (char *volid, unsigned int blksize,
 
301
                              extent_t *part_extent, format1_label_t *f1);
 
302
 
 
303
void vtoc_init_format4_label (format4_label_t *f4lbl,
 
304
                              unsigned int usable_partitions,
 
305
                              unsigned int cylinders,
 
306
                              unsigned int tracks,
 
307
                              unsigned int blocks,
 
308
                              unsigned int blksize,
 
309
                              u_int16_t dev_type);
 
310
 
 
311
void vtoc_update_format4_label (format4_label_t *f4, cchhb_t *highest_f1,
 
312
                                u_int16_t unused_update);
 
313
 
 
314
void vtoc_init_format5_label (format5_label_t *f5);
 
315
 
 
316
void vtoc_update_format5_label_add (format5_label_t *f5, int verbose, int cyl,
 
317
                                    int trk, u_int16_t a, u_int16_t b,
 
318
                                    u_int8_t c);
 
319
 
 
320
void vtoc_update_format5_label_del (format5_label_t *f5, int verbose, int cyl,
 
321
                                    int trk, u_int16_t a, u_int16_t b,
 
322
                                    u_int8_t c);
 
323
 
 
324
void vtoc_init_format7_label (format7_label_t *f7);
 
325
 
 
326
void vtoc_update_format7_label_add (format7_label_t *f7, int verbose,
 
327
                                    u_int32_t a, u_int32_t b);
 
328
 
 
329
void vtoc_update_format7_label_del (format7_label_t *f7, int verbose,
 
330
                                    u_int32_t a, u_int32_t b);
 
331
 
 
332
void vtoc_set_freespace(format4_label_t *f4, format5_label_t *f5,
 
333
                        format7_label_t *f7, char ch, int verbose,
 
334
                        u_int32_t start, u_int32_t stop, int cyl, int trk);
 
335
 
 
336
#endif /* VTOC_H */