1 /*
2 
3 mtf - a Microsoft Tape Format reader (and future writer?)
4 Copyright (C) 1999  D. Alan Stewart, Layton Graphics, Inc.
5 
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 
20 Contact the author at:
21 
22 D. Alan Stewart
23 Layton Graphics, Inc.
24 155 Woolco Dr.
25 Marietta, GA 30062, USA
26 astewart@layton-graphics.com
27 
28 See mtf.c for version history, contibutors, etc.
29 
30 
31 **
32 **	mtf.h
33 **
34 **	defines, types for the Microsoft Tape Format
35 **	prototypes for functions in mtfread.c and mtfutil.c
36 **
37 */
38 
39 
40 #pragma pack(1)
41 
42 
43 #define MIN_TAPE_BLOCK_SIZE 512
44 #define MAX_TAPE_BLOCK_SIZE 65536
45 #define MAX_PRINT_STRING 100
46 #define MAX_PATTERN_LEN 100
47 #define MAX_PATTERN 20
48 
49 #define CASE_SENSITIVE 0
50 #define CASE_LOWER 1
51 #define CASE_UPPER 2
52 
53 #define min(a,b) ((a) < (b) ? (a) : (b))
54 #define max(a,b) ((a) < (b) ? (b) : (a))
55 
56 
57 typedef unsigned short BOOLEAN;
58 typedef char INT8;
59 typedef unsigned char UINT8;
60 typedef short INT16;
61 typedef unsigned short UINT16;
62 typedef long INT32;
63 typedef unsigned long UINT32;
64 
65 typedef struct
66 {
67 	UINT32	least;	/* least significant 32 bits */
68 	UINT32	most;	/* most significant 32 bits */
69 } UINT64;
70 
71 /* pointer to non-fixed length information */
72 typedef struct
73 {
74 	UINT16	size;	/* size of referenced field */
75 	UINT16	offset; /* offset to start of field from start of structure */
76 } MTF_TAPE_ADDRESS;
77 
78 /* storage of date and time */
79 typedef UINT8 MTF_DATE_TIME[5];	/* 14 bit year, 4 bit month, 5 bit day, */
80                                 /* 5 bit hour, 6 bit minute, 6 bit second */
81 
82 /* macros for reading the MTF_DATE_TIME type */
83 #define MTF_YEAR(X) (UINT16) ((X[0] << 6) | (X[1] >> 2))
84 #define MTF_MONTH(X) (UINT8) (((X[1] & 0x03) << 2) | ((X[2] & 0xC0) >> 6))
85 #define MTF_DAY(X) (UINT8) ((X[2] & 0x3E) >> 1)
86 #define MTF_HOUR(X) (UINT8) (((X[2] & 0x01) << 4) | ((X[3] & 0xF0) >> 4))
87 #define MTF_MINUTE(X) (UINT8) (((X[3] & 0x0F) << 2) | ((X[4] & 0xC0) >> 6))
88 #define MTF_SECOND(X) (UINT8) (X[4] & 0x3F)
89 
90 /* common descriptor block header */
91 typedef struct
92 {
93 	UINT32				type;		/* DBLK type */
94 	UINT32				attr;		/* block attributes */
95 	UINT16				off;		/* offset to first event */
96 	UINT8				osId;		/* OS ID */
97 	UINT8				osVer;		/* OS version */
98 	UINT64				size;		/* displayable size */
99 	UINT64				fla;		/* format logical address */
100 	UINT16 				mbc;		/* reserved for MBC */
101 	UINT8			rsv1[6];		/* reserved for future use */
102 	UINT32				cbId;		/* control block ID */
103 	UINT8			rsv2[4];		/* reserved for future use */
104 	MTF_TAPE_ADDRESS	osData;		/* OS-specific data */
105 	UINT8				strType;	/* string type */
106 	UINT8				rsv3;		/* reserved for future use */
107 	UINT16				check;		/* header checksum */
108 } MTF_DB_HDR;
109 
110 /* values for MTF_DB_HDR.type field */
111 #define MTF_TAPE 0x45504154
112 #define MTF_SSET 0x54455353
113 #define MTF_VOLB 0x424C4F56
114 #define MTF_DIRB 0x42524944
115 #define MTF_FILE 0x454C4946
116 #define MTF_CFIL 0x4C494643
117 #define MTF_ESPB 0x42505345
118 #define MTF_ESET 0x54455345
119 #define MTF_EOTM 0x4D544F45
120 #define MTF_SFMB 0x424D4653
121 
122 /* bit masks for MTF_DB_HDR.attr field for all values of MTF_DB_HDR.type */
123 #define MTF_CONTINUATION 0x0001
124 #define MTF_COMPRESSION 0x0002
125 #define MTF_EOS_AT_EOM 0x0004
126 
127 /* bit masks for MTF_DB_HDR.attr field for MTF_DB_HDR.type = MTF_TAPE */
128 #define MTF_SET_MAP_EXISTS 0x0100
129 #define MTF_FDD_ALLOWED 0x0200
130 
131 /* bit masks for MTF_DB_HDR.attr field for MTF_DB_HDR.type = MTF_SSET */
132 #define MTF_FDD_EXISTS 0x0100
133 #define MTF_ENCRYPTION 0x0200
134 
135 /* bit masks for MTF_DB_HDR.attr field for MTF_DB_HDR.type = MTF_ESET */
136 #define MTF_FDD_ABORTED 0x0100
137 #define MTF_END_OF_FAMILY 0x0200
138 #define MTF_ABORTED_SET 0x0400
139 
140 /* bit masks for MTF_DB_HDR.attr field for MTF_DB_HDR.type = MTF_EOTM */
141 #define MTF_NO_ESET_PBA 0x0100
142 #define MTF_INVALID_ESET_PBA 0x0200
143 
144 /* values for MTF_DB_HDR.osId field */
145 #define MTF_OS_NETWARE 1
146 #define MTF_OS_NETWARE_SMS 13
147 #define MTF_OS_WINDOWS_NT 14
148 #define MTF_OS_DOS 24
149 #define MTF_OS_OS2 25
150 #define MTF_OS_WINDOWS_95 26
151 #define MTF_OS_MACINTOSH 27
152 #define MTF_OS_UNIX 28
153 
154 /* values for MTF_DB_HDR.strType field */
155 #define MTF_NO_STRINGS 0
156 #define MTF_ANSI_STR 1
157 #define MTF_UNICODE_STR 2
158 
159 /* structure pointed to by the MTF_DB_HDR.osData field when MTF_DB_HDR.osId = */
160 /* MTF_OS_WINDOWS_NT and MTF_DB_HDR.osVer = 0 */
161 typedef struct
162 {
163 	UINT32	attr;	/* file attributes */
164 	UINT16	off;	/* short name offset */
165 	UINT16	size;	/* short name size */
166 	BOOLEAN	link;	/* if non-zero the file is a link to a previous file */
167 	UINT16	rsv;	/* reserved for future use */
168 } MTF_OS_DATA_WINDOWS_NT;
169 
170 /* descriptor block for MTF_DB_HDR.type = MTF_TAPE (tape header) */
171 typedef struct
172 {
173 	MTF_DB_HDR			common;		/* common block header */
174 	UINT32				famId;		/* media family ID */
175 	UINT32				attr;		/* TAPE attributes */
176 	UINT16				seq;		/* media sequence number */
177 	UINT16				encrypt;	/* password encryption */
178 	UINT16				sfmSize;	/* soft filemark block size */
179 	UINT16				catType;	/* media-based catalog type */
180 	MTF_TAPE_ADDRESS	name;		/* media name */
181 	MTF_TAPE_ADDRESS	desc;		/* media desc./label */
182 	MTF_TAPE_ADDRESS	passwd;		/* media password */
183 	MTF_TAPE_ADDRESS	software;	/* software name */
184 	UINT16				flbSize;	/* format logical block size */
185 	UINT16				vendorId;	/* software vendor ID */
186 	MTF_DATE_TIME		date;		/* media date */
187 	UINT8				ver;		/* MTF major version */
188 } MTF_TAPE_BLK;
189 
190 /* bitmasks for MTF_TAPE_BLK.attr */
191 #define MTF_TAPE_SOFT_FILEMARK_BIT 0x00000001
192 #define MTF_TAPE_MEDIA_LABEL_BIT 0x00000002
193 
194 /* values for MTF_TAPE_BLK.catType */
195 #define MTF_NO_MBC 0
196 #define MTF_MBC_TYPE_1 1
197 #define MTF_MBC_TYPE_2 2
198 
199 /* descriptor block for MTF_DB_HDR.type = MTF_SSET (start of data set) */
200 typedef struct
201 {
202 	MTF_DB_HDR			common;			/* common block header */
203 	UINT32				attr;			/* SSET attributes */
204 	UINT16				passEncrypt;	/* password encryption */
205 	UINT16				softCompress;	/* software compression */
206 	UINT16				vendor;			/* software vendor ID */
207 	UINT16				num;			/* data set number */
208 	MTF_TAPE_ADDRESS	name;			/* data set name */
209 	MTF_TAPE_ADDRESS	desc;			/* data set description */
210 	MTF_TAPE_ADDRESS	passwd;			/* data set password */
211 	MTF_TAPE_ADDRESS	user;			/* user name */
212 	UINT64				pba;			/* physical block address */
213 	MTF_DATE_TIME		date;			/* media write date */
214 	UINT8				major;			/* software major version */
215 	UINT8				minor;			/* software minor version */
216 	INT8				tz;				/* time zone */
217 	UINT8				ver;			/* MTF minor version */
218 	UINT8				catVer;			/* media catalog version 8/ */
219 } MTF_SSET_BLK;
220 
221 /* bitmasks for MTF_SSET_BLK.attr */
222 #define MTF_SSET_TRANSFER_BIT 0x00000001
223 #define MTF_SSET_COPY_BIT 0x00000002
224 #define MTF_SSET_NORMAL_BIT 0x00000004
225 #define MTF_SSET_DIFFERENTIAL_BIT 0x00000008
226 #define MTF_SSET_INCREMENTAL_BIT 0x00000010
227 #define MTF_SSET_DAILY_BIT 0x00000020
228 
229 /* value for MTF_SSET_BLK.tz when local time is not coordinated with UTC */
230 #define MTF_LOCAL_TZ 127
231 
232 /* descriptor block for MTF_DB_HDR.type = MTF_VOLB (volume) */
233 typedef struct
234 {
235 	MTF_DB_HDR			common;		/* common block header */
236 	UINT32				attr;		/* VOLB attributes */
237 	MTF_TAPE_ADDRESS	device;		/* device name */
238 	MTF_TAPE_ADDRESS	volume;		/* volume name */
239 	MTF_TAPE_ADDRESS	machine;	/* machine name */
240 	MTF_DATE_TIME		date;		/* media write date */
241 } MTF_VOLB_BLK;
242 
243 /* bitmasks for MTF_VOLB_BLK.attr */
244 #define MFT_VOLB_NO_REDIRECT_RESTORE_BIT 0x00000001
245 #define MFT_VOLB_NON_VOLUME_BIT 0x00000002
246 #define MFT_VOLB_DEV_DRIVE_BIT 0x00000004
247 #define MFT_VOLB_DEV_UNC_BIT 0x00000008
248 #define MFT_VOLB_DEV_OS_SPEC_BIT 0x00000010
249 #define MFT_VOLB_DEV_VEND_SPEC_BIT 0x00000020
250 
251 /* descriptor block for MTF_DB_HDR.type = MTF_DIRB (directory) */
252 typedef struct
253 {
254 	MTF_DB_HDR			common;		/* common block header */
255 	UINT32				attr;		/* DIRB attributes */
256 	MTF_DATE_TIME		mod;		/* last modification date */
257 	MTF_DATE_TIME		create;		/* creation date */
258 	MTF_DATE_TIME		backup;		/* backup date */
259 	MTF_DATE_TIME		access;		/* last access date */
260 	UINT32				id;			/* directory ID */
261 	MTF_TAPE_ADDRESS	name;		/* directory name */
262 } MTF_DIRB_BLK;
263 
264 /* bitmasks for MTF_DIRB_BLK.attr */
265 #define MTF_DIRB_READ_ONLY_BIT 0x00000100
266 #define MTF_DIRB_HIDDEN_BIT 0x00000200
267 #define MTF_DIRB_SYSTEM_BIT 0x00000400
268 #define MTF_DIRB_MODIFIED_BIT 0x00000800
269 #define MTF_DIRB_EMPTY_BIT 0x00010000
270 #define MTF_DIR_PATH_IN_STREAM_BIT 0x00020000
271 #define MTF_DIRB_CORRUPT_BIT 0x00040000
272 
273 /* descriptor block for MTF_DB_HDR.type = MTF_FILE (file) */
274 typedef struct
275 {
276 	MTF_DB_HDR			common;		/* common block header */
277 	UINT32				attr;		/* FILE attributes */
278 	MTF_DATE_TIME		mod;		/* last modification date */
279 	MTF_DATE_TIME		create;		/* creation date */
280 	MTF_DATE_TIME		backup;		/* backup date */
281 	MTF_DATE_TIME		access;		/* last access date */
282 	UINT32				dirId;		/* directory ID */
283 	UINT32				id;			/* file ID */
284 	MTF_TAPE_ADDRESS	name;		/* file name */
285 } MTF_FILE_BLK;
286 
287 /* bitmasks for MTF_FILE_BLK.attr */
288 #define MTF_FILE_READ_ONLY_BIT 0x00000100
289 #define MTF_FILE_HIDDEN_BIT 0x00000200
290 #define MTF_FILE_SYSTEM_BIT 0x00000400
291 #define MTF_FILE_MODIFIED_BIT 0x00000800
292 #define MTF_FILE_IN_USE_BIT 0x00010000
293 #define MTF_FILE_NAME_IN_STREAM_BIT 0x00020000
294 #define MTF_FILE_CORRUPT_BIT 0x00040000
295 
296 /* descriptor block for MTF_DB_HDR.type = MTF_CFIL (corrupt object) */
297 typedef struct
298 {
299 	MTF_DB_HDR	common;		/* common block header */
300 	UINT32		attr;		/* CFIL attributes */
301 	UINT8		rsv[8];		/* reserved for future use */
302 	UINT64		off;		/* stream offset */
303 	UINT64		num;		/* corrupt stream number */
304 } MTF_CFIL_BLK;
305 
306 /* bitmasks for MTF_CFIL_BLK.attr */
307 #define MTF_CFIL_LENGTH_CHANGE_BIT 0x00010000
308 #define MTF_CFIL_UNREADABLE_BLK_BIT 0x00020000
309 #define MTF_CFIL_DEADLOCK_BIT 0x00080000
310 #define MTF_FILE_READ_ONLY_BIT 0x00000100
311 
312 /* descriptor block for MTF_DB_HDR.type = MTF_ESPB (end of set pad) */
313 typedef MTF_DB_HDR MTF_ESPB_BLK;
314 
315 /* descriptor block for MTF_DB_HDR.type = MTF_ESET (end of data set) */
316 typedef struct
317 {
318 	MTF_DB_HDR		common;		/* common block header */
319 	UINT32			attr;		/* ESET attributes */
320 	UINT32			corrupt;	/* number of corrupt files */
321 	UINT64			mbc1;		/* reserved for MBC */
322 	UINT64			mbc2;		/* reserved for MBC */
323 	UINT16			seq;		/* FDD media sequence number */
324 	UINT16			set;		/* data set number */
325 	MTF_DATE_TIME	date;		/* media write date */
326 } MTF_ESET_BLK;
327 
328 /* bitmasks for MTF_ESET_BLK.attr */
329 #define MTF_ESET_TRANSFER_BIT 0x00000001
330 #define MTF_ESET_COPY_BIT 0x00000002
331 #define MTF_ESET_NORMAL_BIT 0x00000004
332 #define MTF_ESET_DIFFERENTIAL_BIT 0x00000008
333 #define MTF_ESET_INCREMENTAL_BIT 0x00000010
334 #define MTF_ESET_DAILY_BIT 0x00000020
335 
336 /* descriptor block for MTF_DB_HDR.type = MTF_EOTM (end of tape) */
337 typedef struct
338 {
339 	MTF_DB_HDR		common;		/* common block header */
340 	UINT64			lastEset;	/* last ESET PBA */
341 } MTF_EOTM_BLK;
342 
343 /* descriptor block for MTF_DB_HDR.type = MTF_SFMB (soft filemark) */
344 typedef struct
345 {
346 	MTF_DB_HDR	common;		/* common block header */
347 	UINT32		marks;		/* number of filemark entries */
348 	UINT32		used;		/* filemark entries used */
349 } MTF_SFMB_BLK;
350 
351 /* stream header */
352 typedef struct
353 {
354 	UINT32	id;			/* stream ID */
355 	UINT16	sysAttr;	/* stream file system attributes */
356 	UINT16	mediaAttr;	/* stream media format attributes */
357 	UINT64	length;		/* stream length */
358 	UINT16	encrypt;	/* data encryption algorithm */
359 	UINT16	compress;	/* data compression algorithm */
360 	UINT16	check;		/* checksum */
361 } MTF_STREAM_HDR;
362 
363 /* bitmasks for MTF_STREAM_HDR.sysAttr */
364 #define MTF_STREAM_MODIFIED_FOR_READ 0x00000001
365 #define MTF_STREAM_CONTAINS_SECURITY 0x00000002
366 #define MTF_STREAM_IS_NON_PORTABLE 0x00000004
367 #define MTF_STREAM_IS_SPARSE 0x00000008
368 
369 /* bitmasks for MTF_STREAM_HDR.mediaAttr */
370 #define MTF_STREAM_CONTINUE 0x00000001
371 #define MTF_STREAM_VARIABLE 0x00000002
372 #define MTF_STREAM_VAR_END 0x00000004
373 #define MTF_STREAM_ENCRYPTED 0x00000008
374 #define MTF_STREAM_COMPRESSED 0x00000010
375 #define MTF_STREAM_CHECKSUMED 0x00000020
376 #define MTF_STREAM_EMBEDDED_LENGTH 0x00000040
377 
378 /* platform-independant stream data types */
379 #define MTF_STAN 0x4E415453 /* standard */
380 #define MTF_PNAM 0x4D414E50 /* path */
381 #define MTF_FNAM 0x4D414E46 /* file name */
382 #define MTF_CSUM 0x4D555343 /* checksum */
383 #define MTF_CRPT 0x54505243 /* corrupt */
384 #define MTF_SPAD 0x44415053 /* pad */
385 #define MTF_SPAR 0x52415053 /* sparse */
386 #define MTF_TSMP 0x504D5354 /* set map, media based catalog, type 1 */
387 #define MTF_TFDD 0x44444654 /* fdd, media based catalog, type 1 */
388 #define MTF_MAP2 0x3250414D /* set map, media based catalog, type 2 */
389 #define MTF_FDD2 0x32444446 /* fdd, media based catalog, type 2 */
390 
391 /* Windows NT stream data types */
392 #define MTF_ADAT 0x54414441
393 #define MTF_NTEA 0x4145544E
394 #define MTF_NACL 0x4C43414E
395 #define MTF_NTED 0x4445544E
396 #define MTF_NTQU 0x5551544E
397 #define MTF_NTPR 0x5250544E
398 #define MTF_NTOI 0x494F544E
399 
400 /* Windows 95 stream data types */
401 #define MTF_GERC 0x43524547
402 
403 /* Netware stream data types */
404 #define MTF_N386 0x3638334E
405 #define MTF_NBND 0x444E424E
406 #define MTF_SMSD 0x44534D53
407 
408 /* OS/2 stream data types */
409 #define MTF_OACL 0x4C43414F
410 
411 /* Macintosh stream data types */
412 #define MTF_MRSC 0x4353524D
413 #define MTF_MPRV 0x5652504D
414 #define MTF_MINF 0x464E494D
415 
416 /* stream compression frame header */
417 typedef struct
418 {
419 	UINT16		id;				/* compression header id  - see define below */
420 	UINT16		attr;			/* stream media format attributes */
421 	UINT64		remain;			/* remaining stream size */
422 	UINT32		uncompress;		/* uncompressed size */
423 	UINT32		compress;		/* compressed size */
424 	UINT8		seq;			/* sequence number */
425 	UINT8		rsv;			/* reserved */
426 	UINT16		check;			/* checksum */
427 } MTF_CMP_HDR;
428 
429 #define MTF_CMP_HDR_ID 0x4846
430 
431 
432 /* prototypes for mtfread.c */
433 INT32 openMedia(void);
434 INT32 readDataSet(void);
435 INT32 readEndOfDataSet(void);
436 INT32 readTapeBlock(void);
437 INT32 readStartOfSetBlock(void);
438 INT32 readVolumeBlock(void);
439 INT32 readDirectoryBlock(void);
440 INT32 readFileBlock(void);
441 INT32 readFile(UINT16);
442 INT32 readCorruptObjectBlock(void);
443 INT32 readEndOfSetPadBlock(void);
444 INT32 readEndOfSetBlock(void);
445 INT32 readEndOfTapeMarkerBlock(void);
446 INT32 readSoftFileMarkBlock(void);
447 INT32 readNextBlock(UINT16);
448 INT32 skipToNextBlock(void);
449 INT32 skipOverStream(void);
450 INT32 writeData(int);
451 char *getString(UINT8, UINT16, UINT8*);
452 
453 /* prototypes for mtfutil.c */
454 void strlwr(char*);
455 void strupr(char*);
456 void increment64(UINT64*, UINT32);
457 void decrement64(UINT64*, UINT32);
458 void dump(char*);
459