Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1099 lines
44 KiB

  1. //____________________________________________________________________________
  2. //
  3. // (C) Copyright Seagate Software, Inc. 1994-1996
  4. // � 1998 Seagate Software, Inc. All rights reserved.
  5. //
  6. // All Rights Reserved Worldwide.
  7. //
  8. //____________________________________________________________________________
  9. //
  10. // FILE NAME : mtf_api.h
  11. //
  12. // DESCRIPTION : api for creating mtf format structures
  13. // (see detail description below)
  14. //
  15. // CREATED: 6/20/95
  16. //
  17. //____________________________________________________________________________
  18. //
  19. // $Revision: 1.35 $
  20. // $Date: 02 Feb 1995 15:47:04 $
  21. // $Modtime: 02 Feb 1995 15:37:38 $
  22. //
  23. //____________________________________________________________________________
  24. /*****************************************************************************
  25. DETAIL DESCRIPTION
  26. NOTE: See the file MTF_TST.C for an example showing how to use this API
  27. OVERVIEW
  28. ========
  29. The MTF API provides a set of structures, each of which corresponds (but is not
  30. identical to) to the structures described in the Microsoft Tape Format reference
  31. manual. The client instanciates these structures, fills in the fields and then
  32. uses an MTF API function to format the information in the structure into a supplied
  33. buffer in MTF format. The buffer is then padded up to the next alignment factor
  34. using an MTF API call and then may then be written to tape using WIN32 Write.
  35. For example, to write an MTF TAPE DBLK,
  36. 1) Instanciate the MTF API structures. The common header structure is used
  37. separately so that it can be re-used among DBLK writes
  38. MTF_DBLK_HDR_INFO sHdr;
  39. MTF_DBLK_TAPE_INFO sTape;
  40. 2) Use MTF API set default functions to set default values of these
  41. MTF_SetDblkHdrDefaults(&sHdr);
  42. MTF_SetTAPEDefaults(&sTape);
  43. 3) Override the default values as necessary
  44. sHdr.uFormatLogicalAddress = ...
  45. ...
  46. sTape.szTapeName = L"MY TAPE!"
  47. ...
  48. 4) Use the MTF API calls to format the contents of these structures into a buffer.
  49. If the API needs more room than BUFSIZE then then ammount needed is stored in
  50. nBufUsed. Otherwise nBufUsed reflects the amount of space in the buffer
  51. used by the call.
  52. MTF_WriteTAPEDblk(&sHdr,
  53. &sTape,
  54. pBuffer,
  55. BUFSIZE,
  56. &nBufUsed);
  57. 5) NOTE WELL: The write calls *DO NOT PAD* to the next alignment index. But this
  58. is easily done using the MTF API call:
  59. MTF_PadToNextAlignmentFactor(pBuffer,
  60. nBufUsed,
  61. BUFSIZE,
  62. &nBufUsed);
  63. 6) At this point, nBufUsed % MTF_GetAlignmentFactor should == 0. If our blocksize
  64. evenly divides our alignment factor, then we can use the WIN32 Write call to
  65. WriteFile(hTape, pBuffer, nBufUsed, &nBytesWritten, 0);
  66. Since our blocksize divides our AF, then nBytesWritten should == nBufUsed
  67. *** SEE THE MTF_TST.C FOR A COMPLETE EXAMPLE SHOWING THE USE OF THIS API TO CREATE
  68. A BACKUP SET
  69. MTF API DATA STRUCTURE AND FUNCTION SUMMARY
  70. ===========================================
  71. ===========================================
  72. **summary only -- generic detail comments appear below**
  73. LOW LEVEL TYPES
  74. ===============
  75. The following are typedefed to the corresponding "unsigned __intxx"
  76. types:
  77. UINT8
  78. UINT16
  79. UINT32
  80. UINT64
  81. functions:
  82. MTF_CreateUINT64() -- creates a 64 bit unsigned from two UINT32 values (lsb & msb)
  83. DATE & TIME
  84. ===========
  85. MTF_DATE_TIME -- structure used by MTF API for holding packed date & time info
  86. MTF_CreateDateTimeNull() -- returns a null MTF_DATE_TIME
  87. MTF_CreateDateTime() -- creates MTF_DATE_TIME from year, month, day, hour, min, sec
  88. MTF_CreateDateTimeFromTM() -- creates MTF_DATE_TIME from struct tm in <time.h>
  89. MTF_CreateDateTimeFromFileTime() -- creates MTF_DATE_TIME from FILETIME used by FindFirst/FindNext
  90. MTF_CreateDateTimeToTM() -- fills in a struct tm structure given an MTF_DATE_TIME struct
  91. ALIGNMENT FACTOR
  92. ================
  93. MTF_SetAlignmentFactor -- sets the alignment factor for the MTF API (you must do this)
  94. MTF_GetAlignmentFactor -- returns the set alignment factor
  95. MTF_PadToNextAlignmentFactor -- Pads out a buffer using an SPAD to the next alignment factor
  96. MTF_PadToNextPhysicalBlockBoundary -- Pads out a buffer using an SPAD to the next physical block boundary
  97. MTF COMMON HEADER BLOCK
  98. =======================
  99. MTF_DBLK_HDR_INFO -- common block header (must be supplied to all calls to write dblks
  100. MTF_SetDblkHdrDefaults -- sets default values (always call this before you set your own)
  101. MTF TAPE DBLK INFO
  102. ==================
  103. MTF_DBLK_TAPE_INFO -- info corresponding to a TAPE dblk
  104. MTF_SetTAPEDefaults -- sets defaults (always do this before setting your own)
  105. MTF_WriteTAPEDblk -- formats info in MTF_DBLK_TAPE_INFO to tape
  106. MTF_ReadTAPEDblk -- reads info back from a buffer holding MTF FORMATTED TAPE DBLK
  107. MTF SSET DBLK INFO
  108. ==================
  109. MTF_DBLK_SSET_INFO -- all similar to above but for SSET DBLK
  110. MTF_SetSSETDefaults --
  111. MTF_WriteSSETDblk --
  112. MTF_ReadSSETDblk --
  113. MTF VOLB DBLK INFO
  114. ==================
  115. MTF_DBLK_VOLB_INFO -- all similar to above but for VOLB DBLK
  116. MTF_SetVOLBDefaults --
  117. MTF_WriteVOLBDblk --
  118. MTF_ReadVOLBDblk --
  119. MTF_SetVOLBForDevice -- sets default values given a device name ("C:") using
  120. GetVolumeInformation (WIN32 call)
  121. MTF DIRB DBLK INFO
  122. ==================
  123. MTF_DBLK_DIRB_INFO -- all similar to above but for DIRB DBLK
  124. MTF_SetDIRBDefaults --
  125. MTF_WriteDIRBDblk -- (dblk only -- no stream)
  126. MTF_ReadDIRBDblk --
  127. MTF_SetDIRBFromFindData -- sets default values given a WIN32_FIND_DATAW struct (returned
  128. from calls to WIN32 FindFirst, FindNext, etc..
  129. MTF FILE DBLK INFO
  130. ==================
  131. MTF_DBLK_FILE_INFO -- all similar to above but for FILE DBLK
  132. MTF_SetFILEDefaults --
  133. MTF_WriteFILEDblk -- (dblk only -- no stream)
  134. MTF_ReadFILEDblk --
  135. MTF_SetFILEFromFindData -- sets default values given a WIN32_FIND_DATAW struct (returned
  136. from calls to WIN32 FindFirst, FindNext, etc..
  137. MTF CFIL DBLK INFO
  138. ==================
  139. MTF_DBLK_CFIL_INFO -- all similar to above but for CFIL DBLK
  140. MTF_SetCFILDefaults --
  141. MTF_WriteCFILDblk --
  142. MTF_ReadCFILDblk --
  143. MTF ESET DBLK INFO
  144. ==================
  145. MTF_DBLK_ESET_INFO -- all similar to above but for ESET DBLK
  146. MTF_SetESETDefaults --
  147. MTF_WriteESETDblk --
  148. MTF_ReadESETDblk --
  149. MTF EOTM DBLK INFO
  150. ==================
  151. MTF_DBLK_EOTM_INFO -- all similar to above but for EOTM DBLK
  152. MTF_SetEOTMDefaults --
  153. MTF_WriteEOTMDblk --
  154. MTF_ReadEOTMDblk --
  155. MTF STREAM INFO
  156. ==================
  157. MTF_STREAM_INFO -- all similar to above but for EOTM DBLK
  158. MTF_SetSTREAMDefaults --
  159. MTF_WriteSTREAMHeader --
  160. MTF_ReadSTREAMHeader --
  161. MTF_SetSTREAMDefaultsFromStreamId
  162. -- sets stream defaults from a WIN32_STREAM_ID struct
  163. (returned from the WIN32 BackupRead function)
  164. ***********************************************************************************/
  165. #ifndef _MTF_API_H_
  166. #define _MTF_API_H_
  167. #include <windows.h>
  168. #include <stdlib.h>
  169. #include <wchar.h>
  170. #include <time.h>
  171. #ifdef __cplusplus
  172. extern "C" {
  173. #endif
  174. /***********************************************************************************
  175. ************************************************************************************
  176. ************************************************************************************
  177. **** MTF Constants, defines and bit masks
  178. ************************************************************************************
  179. ************************************************************************************
  180. ***********************************************************************************/
  181. /* ==================================================================================
  182. MTF ERROR CODES
  183. ================================================================================== */
  184. #define MTF_ERROR_NONE 0
  185. #define MTF_ERROR_BUFFER_TOO_SMALL 1000
  186. #define MTF_NO_STREAMS 1001
  187. #define MTF_OUT_OF_MEMORY 1002
  188. /* ==================================================================================
  189. MTF Misc. Defaults and Constants
  190. ================================================================================== */
  191. #define MTF_DEFAULT_ALIGNMENT_FACTOR 1024;
  192. #define MTF_FORMAT_VER_MAJOR 1
  193. #define MTF_FORMAT_VER_MINOR 0 // BMD: This API is verison 5; use 0 for compatibility with NT Backup
  194. #define MTF_PW_ENCRYPT_NONE 0
  195. #define MTF_DATA_ENCRYPT_NONE 0
  196. #define MTF_ECC_NONE 0
  197. #define MTF_COMPRESS_NONE 0
  198. #define MTF_OTC_NONE 0
  199. #define MTF_OTC_TYPE 1
  200. #define MTF_OTC_VERSION 2
  201. #define MTF_LOCAL_TZ 127
  202. #define MTF_STRING_NONE 0
  203. #define MTF_STRING_ANSI_STR 1
  204. #define MTF_STRING_UNICODE_STR 2
  205. #define MTF_OSID_NT 14
  206. #define MTF_OSID_DOS 24
  207. /* ==================================================================================
  208. MTF Block Types
  209. ================================================================================== */
  210. #define MTF_ID_TAPE "TAPE" /* Tape Header ID */
  211. #define MTF_ID_VOLB "VOLB" /* Volume Control Block ID */
  212. #define MTF_ID_SSET "SSET" /* Start of Backup Set Description Block ID */
  213. #define MTF_ID_ESET "ESET" /* End of Backup Set Description Block ID */
  214. #define MTF_ID_EOTM "EOTM" /* End of tape, continuation Block ID */
  215. #define MTF_ID_DIRB "DIRB" /* Directory Descriptor Block ID */
  216. #define MTF_ID_FILE "FILE" /* File Descriptor Block ID */
  217. #define MTF_ID_CFIL "CFIL" /* Corrupt File Descriptor Block ID */
  218. #define MTF_ID_ESPB "ESPB" /* End of Set Pad Block */
  219. #define MTF_ID_SFMB "SFMB" /* Soft Filemark Descriptor Block ID */
  220. /* ==================================================================================
  221. DBLK Block Attributes
  222. The lower 16 bits are reserved for general attribute bits (those
  223. which may appear in more than one type of DBLK), the upper 16 are
  224. for attributes which are specific to one type of DBLK.
  225. Note that the block specific bit definitions overlap, and the block
  226. type is used to determine the meaning of a given bit.
  227. ================================================================================== */
  228. /* any : */
  229. #define MTF_CONTINUATION 0x00000001UL
  230. #define MTF_COMPRESSION 0x00000004UL
  231. #define MTF_EOS_AT_EOM 0x00000008UL
  232. #define MTF_VAR_BLKS 0x00000010UL
  233. #define MTF_SESSION 0x00000020UL
  234. /* TAPE : */
  235. #define MTF_SM_EXISTS 0x00010000UL
  236. #define MTF_FDD_ALLOWED 0x00020000UL
  237. #define MTF_SM_ALT_OVERWRITE 0x00040000UL
  238. #define MTF_FDD_ALT_PART 0x00080000UL
  239. #define MTF_SM_ALT_APPEND 0x00200000UL
  240. /* SSET : */
  241. #define MTF_FDD_EXISTS 0x00010000UL
  242. #define MTF_ENCRYPTION 0x00020000UL
  243. /* ESET : */
  244. #define MTF_FDD_ABORTED 0x00010000UL
  245. #define MTF_END_OF_FAMILY 0x00020000UL
  246. #define MTF_ABORTED_SET 0x00040000UL
  247. #define MTF_SET_VERIFIED 0x00080000UL
  248. /* EOTM : */
  249. #define MTF_NO_ESET_PBA 0x00010000UL
  250. #define MTF_INVALID_ESET_PBA 0x00020000UL
  251. /* ==================================================================================
  252. TAPE Block Attributes
  253. ================================================================================== */
  254. #define MTF_TAPE_SOFT_FILEMARK 0x00000001UL
  255. #define MTF_TAPE_MEDIA_LABEL 0x00000002UL
  256. /* ==================================================================================
  257. SSET Block Attributes
  258. ================================================================================== */
  259. #define MTF_SSET_TRANSFER 0x00000001UL
  260. #define MTF_SSET_COPY 0x00000002UL
  261. #define MTF_SSET_NORMAL 0x00000004UL
  262. #define MTF_SSET_DIFFERENTIAL 0x00000008UL
  263. #define MTF_SSET_INCREMENTAL 0x00000010UL
  264. #define MTF_SSET_DAILY 0x00000020UL
  265. /* ==================================================================================
  266. VOLB Block Attributes
  267. ================================================================================== */
  268. #define MTF_VOLB_NO_REDIRECT 0x00000001UL
  269. #define MTF_VOLB_NON_VOLUME 0x00000002UL
  270. #define MTF_VOLB_DEV_DRIVE 0x00000004UL
  271. #define MTF_VOLB_DEV_UNC 0x00000008UL
  272. #define MTF_VOLB_DEV_OS_SPEC 0x00000010UL
  273. #define MTF_VOLB_DEV_VEND_SPEC 0x00000020UL
  274. /* ==================================================================================
  275. DIRB Block Attributes
  276. ================================================================================== */
  277. #define MTF_DIRB_READ_ONLY 0x00000100UL
  278. #define MTF_DIRB_HIDDEN 0x00000200UL
  279. #define MTF_DIRB_SYSTEM 0x00000400UL
  280. #define MTF_DIRB_MODIFIED 0x00000800UL
  281. #define MTF_DIRB_EMPTY 0x00010000UL
  282. #define MTF_DIRB_PATH_IN_STREAM 0x00020000UL
  283. #define MTF_DIRB_CORRUPT 0x00040000UL
  284. /* ==================================================================================
  285. FILE Block Attributes
  286. ================================================================================== */
  287. #define MTF_FILE_READ_ONLY 0x00000100UL
  288. #define MTF_FILE_HIDDEN 0x00000200UL
  289. #define MTF_FILE_SYSTEM 0x00000400UL
  290. #define MTF_FILE_MODIFIED 0x00000800UL
  291. #define MTF_FILE_IN_USE 0x00010000UL
  292. #define MTF_FILE_NAME_IN_STREAM 0x00020000UL
  293. #define MTF_FILE_CORRUPT 0x00040000UL
  294. /* ==================================================================================
  295. CFIL Block Attributes
  296. ================================================================================== */
  297. #define MTF_CFIL_LENGTH_CHANGE 0x00010000UL
  298. #define MTF_CFIL_UNREADABLE_BLK 0x00020000UL
  299. #define MTF_CFIL_DEADLOCK 0x00040000UL
  300. /* ==================================================================================
  301. ESET Block Attributes
  302. ================================================================================== */
  303. #define MTF_ESET_TRANSFER 0x00000001UL
  304. #define MTF_ESET_COPY 0x00000002UL
  305. #define MTF_ESET_NORMAL 0x00000004UL
  306. #define MTF_ESET_DIFFERENTIAL 0x00000008UL
  307. #define MTF_ESET_INCREMENTAL 0x00000010UL
  308. #define MTF_ESET_DAILY 0x00000020UL
  309. /* ==================================================================================
  310. STREAM File System Attributes
  311. ================================================================================== */
  312. #define MTF_STREAM_MODIFIED_BY_READ 0x00000001UL
  313. #define MTF_STREAM_CONTAINS_SECURITY 0x00000002UL
  314. #define MTF_STREAM_IS_NON_PORTABLE 0x00000004UL
  315. #define MTF_STREAM_IS_SPARSE 0x00000008UL
  316. /* ==================================================================================
  317. STREAM Media Format Attributes
  318. ================================================================================== */
  319. #define MTF_STREAM_CONTINUE 0x00000001UL
  320. #define MTF_STREAM_VARIABLE 0x00000002UL
  321. #define MTF_STREAM_VAR_END 0x00000004UL
  322. #define MTF_STREAM_ENCRYPTED 0x00000008UL
  323. #define MTF_STREAM_COMPRESSED 0x00000010UL
  324. #define MTF_STREAM_CHECKSUMED 0x00000020UL
  325. #define MTF_STREAM_EMBEDDED_LENGTH 0x00000040UL
  326. /* ==================================================================================
  327. STREAM Types (Platform Independent)
  328. ================================================================================== */
  329. #define MTF_STANDARD_DATA_STREAM "STAN"
  330. #define MTF_PATH_NAME_STREAM "PNAM"
  331. #define MTF_FILE_NAME_STREAM "FNAM"
  332. #define MTF_CHECKSUM_STREAM "CSUM"
  333. #define MTF_CORRUPT_STREAM "CRPT"
  334. #define MTF_PAD_STREAM "SPAD"
  335. #define MTF_SPARSE_STREAM "SPAR"
  336. #define MTF_MBC_LMO_SET_MAP_STREAM "TSMP"
  337. #define MTF_MBC_LMO_FDD_STREAM "TFDD"
  338. #define MTF_MBC_SLO_SET_MAP_STREAM "MAP2"
  339. #define MTF_MBC_SLO_FDD_STREAM "FDD2"
  340. /* ==================================================================================
  341. STREAM Types (Windows NT specific)
  342. ================================================================================== */
  343. #define MTF_NTFS_ALT_STREAM "ADAT"
  344. #define MTF_NTFS_EA_STREAM "NTEA"
  345. #define MTF_NT_SECURITY_STREAM "NACL"
  346. #define MTF_NT_ENCRYPTED_STREAM "NTED"
  347. #define MTF_NT_QUOTA_STREAM "NTQU"
  348. #define MTF_NT_PROPERTY_STREAM "NTPR"
  349. #define MTF_NT_REPARSE_STREAM "NTRP"
  350. #define MTF_NT_OBJECT_ID_STREAM "NTOI"
  351. /* ==================================================================================
  352. STREAM Frame Headers
  353. ================================================================================== */
  354. #define MTF_COMPRESSION_HEADER_ID "FM"
  355. #define MTF_ECRYPTION_HEADER_ID "EH"
  356. /* ==================================================================================
  357. * Turn on packing here. Need to be sure that date is packed.
  358. ================================================================================== */
  359. #pragma pack(1)
  360. /***********************************************************************************
  361. ************************************************************************************
  362. ************************************************************************************
  363. **** MTF Miscelaneous Data Types (and some handy methods for them)
  364. ************************************************************************************
  365. ************************************************************************************
  366. ***********************************************************************************/
  367. /* ==================================================================================
  368. General Data Types
  369. ================================================================================== */
  370. UINT64 MTF_CreateUINT64(
  371. UINT32 uLSB, UINT32 uMSB);
  372. /* ==================================================================================
  373. Compressed date structure for storing dates in minimal space on tape:
  374. BYTE 0 BYTE 1 BYTE 2 BYTE 3 BYTE 4
  375. 76543210 76543210 76543210 76543210 76543210
  376. yyyyyyyy yyyyyymm mmdddddh hhhhmmmm mmssssss
  377. ================================================================================== */
  378. typedef struct {
  379. UINT8 dt_field[5] ;
  380. } MTF_DATE_TIME;
  381. /************************************************************************************
  382. * MTF_CreateDataTime#####()
  383. *
  384. * Description: Given various arguments, this set of functions returns a packed
  385. * MTF_DATE_TIME struct which can then be assigned to fields found
  386. * in the various info structs found below
  387. * Example:
  388. * sSetInfo.sBackupDate = MTF_CreateDateTime(1995, 6, 12, 16, 30, 0);
  389. ************************************************************************************/
  390. MTF_DATE_TIME MTF_CreateDateTimeNull();
  391. MTF_DATE_TIME MTF_CreateDateTime(
  392. int iYear,
  393. int iMonth,
  394. int iDay,
  395. int iHour,
  396. int iMinute,
  397. int iSecond
  398. );
  399. MTF_DATE_TIME MTF_CreateDateTimeFromTM(
  400. struct tm *pT);
  401. MTF_DATE_TIME MTF_CreateDateTimeFromFileTime(
  402. FILETIME sFileTime);
  403. void MTF_CreateDateTimeToTM(
  404. MTF_DATE_TIME *pDT,
  405. struct tm *pT);
  406. /***********************************************************************************
  407. ************************************************************************************
  408. **** MTF Alignment Factor
  409. ************************************************************************************
  410. ***********************************************************************************/
  411. /************************************************************************************
  412. * MTF_SetAlignmentFactor()
  413. *
  414. * Description: Sets the alignment factor to be used by the MTF API
  415. * (particularly by MTF_PadToNextAlignmentFactor and MTF_WriteTAPEDblk)
  416. *
  417. * Pre:
  418. * Post: MTF API Alignment Factor == uAF
  419. *
  420. * uAF -- alignment factor value to set
  421. ************************************************************************************/
  422. void MTF_SetAlignmentFactor(
  423. UINT16 uAF);
  424. /************************************************************************************
  425. * MTF_GetAlignmentFactor()
  426. *
  427. * Description: Returns the Alignment Factor set by MTF_SetAlignmentFactor
  428. *
  429. * Pre: MTF_SetAlignmentFactor has been called
  430. ************************************************************************************/
  431. UINT16 MTF_GetAlignmentFactor();
  432. /************************************************************************************
  433. * MTF_PadToNextAlignmentFactor()
  434. *
  435. * Description: Appends an SPAD stream to the buffer so as to pad the buffer out to
  436. * the next alignment factor
  437. *
  438. *
  439. * Pre: The alignment factor has been set by calling MTF_SetAlignmentFactor,
  440. * pBuffer points to a buffer whose size is reflected by nBufferSize
  441. *
  442. * Post: return value == MTF_ERROR_NONE
  443. * => padding was successful, *pnSizeUsed reflects amount of buffer used,
  444. * AND *pnSizeUsed % MTF_GetAlignmentFactor == 0 is TRUE
  445. * return value == MTF_ERROR_BUFFER_TOO_SMALL
  446. * => The buffer was too small, *pnSizeUsed reflects the amound needed
  447. *
  448. * NOTE: If the space between the end of the buffer and the next alignment factor is
  449. * smaller than the size of a stream header, then the spad hogs up the whole
  450. * next alignment factor.
  451. *
  452. * pBuffer -- the buffer to spad out
  453. * nBufUsed -- the amount of the buffer used so far (position where to append)
  454. * nBufferSize -- the size of the buffer pointed to by pBuffer
  455. * pnSizeUsed -- points to where to store size used or needed
  456. ************************************************************************************/
  457. DWORD MTF_PadToNextAlignmentFactor(
  458. BYTE *pBuffer,
  459. size_t nBufUsed,
  460. size_t nBufferSize,
  461. size_t *pnSizeUsed);
  462. /************************************************************************************
  463. * MTF_PadToNextPhysicalBlockBoundary() - (bmd)
  464. *
  465. * Description: Appends an SPAD stream to the buffer so as to pad the buffer out to
  466. * the next physical block boundary.
  467. *
  468. ************************************************************************************/
  469. DWORD MTF_PadToNextPhysicalBlockBoundary(
  470. BYTE *pBuffer,
  471. size_t nBlockSize,
  472. size_t nBufUsed,
  473. size_t nBufferSize,
  474. size_t *pnSizeUsed);
  475. /***********************************************************************************
  476. ************************************************************************************
  477. ************************************************************************************
  478. **** MTF API STRUCTURES
  479. ************************************************************************************
  480. ************************************************************************************
  481. ***********************************************************************************/
  482. /***********************************************************************************
  483. GENERIC DETAIL COMMENTS FOR FUNCTIONS FOUND BELOW
  484. =================================================
  485. ************************************************************************************
  486. * MTF_Set####Defaults()
  487. *
  488. * Description: Sets up default values for the structure. Always call this to
  489. * avoid garbage values in case you over look a field,
  490. * Pre:
  491. * Post: All fields of the referenced structure are filled in with *something*.
  492. * Date fields are initialized to current date and time.
  493. * Strings pointers are set to 0
  494. * Most other values set to 0
  495. *
  496. * p####Info -- pointer to structure to be set
  497. ************************************************************************************
  498. void MTF_Set####Defaults(
  499. MTF_####_INFO *p####Info);
  500. ************************************************************************************
  501. * MTF_Write####Dblk()
  502. *
  503. * Description: Formats the information supplied in psHdrInfo and ps####Info into
  504. * MTF Format and places the results in pBuffer
  505. *
  506. * Pre: psHdrInfo and ps####Info contain valid information / default values
  507. * pBuffer points to a buffer where resulting format is to be stored
  508. * nBuffer size indicates the size of the buffer
  509. *
  510. * MTF_WriteTAPEDblk -- MTF_SetAlingmentFactor has been called
  511. *
  512. * Post: return value == MTF_ERROR_NONE
  513. * => Format was successful, *pnSizeUsed reflects amount of buffer used
  514. * return value == MTF_ERROR_BUFFER_TOO_SMALL
  515. * => The buffer was too small, *pnSizeUsed reflects the amound needed
  516. *
  517. * psHdrInfo -- MTF Common header information
  518. * ps####Info -- MTF DBLK info
  519. * pBuffer -- pointer to buffer which will receive MTF formatted info
  520. * pBufferSize -- the size of the buffer pointed to by pBuffer
  521. * pnSizeUsed -- pointer to a size_t in which amount of buffer used or needed is stored
  522. ************************************************************************************
  523. DWORD MTF_Write####Dblk( MTF_DBLK_HDR_INFO *psHdrInfo,
  524. MTF_DBLK_####_INFO *ps####Info,
  525. BYTE *pBuffer,
  526. size_t nBufferSize,
  527. size_t *pnSizeUsed);
  528. ************************************************************************************
  529. * MTF_Read####Dblk()
  530. *
  531. * Description: Translates MTF Formatted information from a buffer to MTF API info
  532. * structures -- the opposite of MTF_Write####Dblk
  533. *
  534. *
  535. * Pre: pBuffer contains correct MTF Buffer information
  536. *
  537. * Post: psHdrInfo and ps####Info contain the de-formatted info.
  538. *
  539. * NOTE: Strings point to strings stored statically by the API, and will be over
  540. * written on the next read call.
  541. *
  542. * psHdrInfo -- MTF Common header info struct to receive info
  543. * ps####Info -- MTF DBLK info struct to receive info
  544. * pBuffer -- pointer to buffer which holds MTF formatted data
  545. ************************************************************************************
  546. DWORD MTF_Read####Dblk( MTF_DBLK_HDR_INFO *psHdrInfo,
  547. MTF_DBLK_####_INFO *ps####Info,
  548. BYTE *pBuffer);
  549. ************************************************************************************
  550. * MTF_Set####From?????????()
  551. *
  552. * Description: Similar to MTF_Set####Defaults(), but takes as an argument one or more
  553. * commonly used structures and sets values from that. For example,
  554. * MTF_SetFILEFromFindData takes as an argument a WIN32_FIND_DATA struct
  555. * from which it extracts the file name, date, time, etc.
  556. *
  557. *
  558. * Pre:
  559. * Post: As many fields as are reasonable are automatically set. The rest of the
  560. * fields are set to default values.
  561. *
  562. * NOTE: Strings such as file names, directory names are stored statically by the
  563. * MTF API and are only good until the next call to an MTF_Set#####From??????
  564. * function.
  565. *
  566. * NOTE: FILE and DIRB calls automatically set the file and directory attibutes from
  567. * the info in the WIN32_FIND_DATA structure.
  568. *
  569. * NOTE: MTF_SetSTREAMFromStreamId will automatically set the stream header id based
  570. * on the attributes found in the WIN32 stream header
  571. *
  572. ************************************************************************************
  573. void MTF_Set####From?????????(MTF_DBLK_####_INFO *p####Info,
  574. SomeType???? Id???
  575. ....);
  576. ***********************************************************************************/
  577. /* ==================================================================================
  578. Common DBLK: MTF_STD_DBLK_INFO
  579. ================================================================================== */
  580. typedef struct {
  581. char acBlockType[5]; /* for reading only -- ignored when writing (includes \0)*/
  582. UINT32 uBlockAttributes;
  583. UINT16 uOffsetToFirstStream; /* for reading only */
  584. UINT8 uOSID; /* Machine/OS id where written, low byte */
  585. UINT8 uOSVersion; /* Machine/OS id where written, high byte */
  586. UINT64 uDisplayableSize; /* Displayable data size */
  587. UINT64 uFormatLogicalAddress;
  588. UINT16 uReservedForMBC; /* Reserved for Media Based Catalog */
  589. UINT16 uSoftwareCompression; /* Software Compression Algorithm */
  590. UINT32 uControlBlockId; /* Used for error recovery */
  591. void * pvOSData; /* OS specific Data */
  592. UINT16 uOSDataSize; /* the size of the OS data in bytes */
  593. UINT8 uStringType; /* String type */
  594. UINT16 uHeaderCheckSum; /* for reading only */
  595. } MTF_DBLK_HDR_INFO;
  596. void MTF_SetDblkHdrDefaults(
  597. MTF_DBLK_HDR_INFO *pStdInfo);
  598. /* ==================================================================================
  599. TAPE DBLK: MTF_TAPE_INFO
  600. ================================================================================== */
  601. typedef struct {
  602. UINT32 uTapeFamilyId;
  603. UINT32 uTapeAttributes;
  604. UINT16 uTapeSequenceNumber;
  605. UINT16 uPasswordEncryptionAlgorithm;
  606. UINT16 uSoftFilemarkBlockSize;
  607. UINT16 uTapeCatalogType;
  608. wchar_t * szTapeName;
  609. wchar_t * szTapeDescription;
  610. wchar_t * szTapePassword;
  611. wchar_t * szSoftwareName;
  612. UINT16 uAlignmentFactor;
  613. UINT16 uSoftwareVendorId;
  614. MTF_DATE_TIME sTapeDate;
  615. UINT8 uMTFMajorVersion;
  616. } MTF_DBLK_TAPE_INFO;
  617. void MTF_SetTAPEDefaults(MTF_DBLK_TAPE_INFO *pTapeInfo);
  618. DWORD MTF_WriteTAPEDblk( MTF_DBLK_HDR_INFO *psHdrInfo,
  619. MTF_DBLK_TAPE_INFO *psTapeInfo,
  620. BYTE *pBuffer,
  621. size_t nBufferSize,
  622. size_t *pnSizeUsed);
  623. DWORD MTF_ReadTAPEDblk( MTF_DBLK_HDR_INFO *psHdrInfo,
  624. MTF_DBLK_TAPE_INFO *psTapeInfo,
  625. BYTE *pBuffer);
  626. /* ==================================================================================
  627. Start of Set DBLK (SSET)
  628. ================================================================================== */
  629. typedef struct {
  630. UINT32 uSSETAttributes;
  631. UINT16 uPasswordEncryptionAlgorithm;
  632. UINT16 uDataEncryptionAlgorithm;
  633. UINT16 uSoftwareVendorId;
  634. UINT16 uDataSetNumber;
  635. wchar_t * szDataSetName;
  636. wchar_t * szDataSetDescription;
  637. wchar_t * szDataSetPassword;
  638. wchar_t * szUserName;
  639. UINT64 uPhysicalBlockAddress;
  640. MTF_DATE_TIME sMediaWriteDate;
  641. UINT8 uSoftwareVerMjr;
  642. UINT8 uSoftwareVerMnr;
  643. UINT8 uTimeZone ;
  644. UINT8 uMTFMinorVer ;
  645. UINT8 uTapeCatalogVersion;
  646. } MTF_DBLK_SSET_INFO;
  647. void MTF_SetSSETDefaults(MTF_DBLK_SSET_INFO *pSSETInfo);
  648. DWORD MTF_WriteSSETDblk( MTF_DBLK_HDR_INFO *psHdrInfo,
  649. MTF_DBLK_SSET_INFO *psTapeInfo,
  650. BYTE *pBuffer,
  651. size_t nBufferSize,
  652. size_t *pnSizeUsed);
  653. DWORD MTF_ReadSSETDblk( MTF_DBLK_HDR_INFO *psHdrInfo,
  654. MTF_DBLK_SSET_INFO *psTapeInfo,
  655. BYTE *pBuffer);
  656. /* ==================================================================================
  657. Volume DBLK (VOLB)
  658. ================================================================================== */
  659. typedef struct {
  660. UINT32 uVolumeAttributes;
  661. wchar_t * szDeviceName;
  662. wchar_t * szVolumeName;
  663. wchar_t * szMachineName;
  664. MTF_DATE_TIME sMediaWriteDate;
  665. } MTF_DBLK_VOLB_INFO;
  666. typedef struct {
  667. UINT32 uFileSystemFlags;
  668. UINT32 uBackupSetAttributes;
  669. } MTF_VOLB_OS_NT_1;
  670. void MTF_SetVOLBDefaults(MTF_DBLK_VOLB_INFO *pVOLBInfo);
  671. void MTF_SetVOLBForDevice(MTF_DBLK_VOLB_INFO *pVOLBInfo, wchar_t *szDevice);
  672. DWORD MTF_WriteVOLBDblk( MTF_DBLK_HDR_INFO *psHdrInfo,
  673. MTF_DBLK_VOLB_INFO *psTapeInfo,
  674. BYTE *pBuffer,
  675. size_t nBufferSize,
  676. size_t *pnSizeUsed);
  677. DWORD MTF_ReadVOLBDblk( MTF_DBLK_HDR_INFO *psHdrInfo,
  678. MTF_DBLK_VOLB_INFO *psTapeInfo,
  679. BYTE *pBuffer);
  680. /* ==================================================================================
  681. Directory DBLK (DIRB)
  682. ================================================================================== */
  683. typedef struct {
  684. UINT32 uDirectoryAttributes;
  685. MTF_DATE_TIME sLastModificationDate;
  686. MTF_DATE_TIME sCreationDate;
  687. MTF_DATE_TIME sBackupDate;
  688. MTF_DATE_TIME sLastAccessDate;
  689. UINT32 uDirectoryId;
  690. wchar_t * szDirectoryName;
  691. } MTF_DBLK_DIRB_INFO;
  692. typedef struct {
  693. UINT32 uDirectoryAttributes;
  694. } MTF_DIRB_OS_NT_0;
  695. typedef struct {
  696. UINT32 uDirectoryAttributes;
  697. UINT16 uShortNameOffset;
  698. UINT16 uShortNameSize;
  699. } MTF_DIRB_OS_NT_1;
  700. void MTF_SetDIRBDefaults(MTF_DBLK_DIRB_INFO *pDIRBInfo);
  701. void MTF_SetDIRBFromFindData( MTF_DBLK_DIRB_INFO *pDIRBInfo,
  702. wchar_t *szFullFileName,
  703. WIN32_FIND_DATAW *pFindData);
  704. DWORD MTF_WriteDIRBDblk( MTF_DBLK_HDR_INFO *psHdrInfo,
  705. MTF_DBLK_DIRB_INFO *psTapeInfo,
  706. BYTE *pBuffer,
  707. size_t nBufferSize,
  708. size_t *pnSizeUsed);
  709. DWORD MTF_ReadDIRBDblk( MTF_DBLK_HDR_INFO *psHdrInfo,
  710. MTF_DBLK_DIRB_INFO *psTapeInfo,
  711. BYTE *pBuffer);
  712. /* ==================================================================================
  713. File DBLK (FILE)
  714. ================================================================================== */
  715. typedef struct {
  716. UINT32 uFileAttributes;
  717. MTF_DATE_TIME sLastModificationDate;
  718. MTF_DATE_TIME sCreationDate;
  719. MTF_DATE_TIME sBackupDate;
  720. MTF_DATE_TIME sLastAccessDate;
  721. UINT32 uDirectoryId;
  722. UINT32 uFileId;
  723. wchar_t * szFileName;
  724. UINT64 uDisplaySize;
  725. } MTF_DBLK_FILE_INFO;
  726. typedef struct {
  727. UINT32 uFileAttributes;
  728. UINT16 uShortNameOffset;
  729. UINT16 uShortNameSize;
  730. UINT16 lLink;
  731. UINT16 uReserved;
  732. } MTF_FILE_OS_NT_0;
  733. typedef struct {
  734. UINT32 uFileAttributes;
  735. UINT16 uShortNameOffset;
  736. UINT16 uShortNameSize;
  737. UINT32 uFileFlags;
  738. } MTF_FILE_OS_NT_1;
  739. void MTF_SetFILEDefaults(MTF_DBLK_FILE_INFO *pFILEInfo);
  740. void MTF_SetFILEFromFindData( MTF_DBLK_FILE_INFO *pFILEInfo,
  741. WIN32_FIND_DATAW *pFindData);
  742. DWORD MTF_WriteFILEDblk( MTF_DBLK_HDR_INFO *psHdrInfo,
  743. MTF_DBLK_FILE_INFO *psTapeInfo,
  744. BYTE *pBuffer,
  745. size_t nBufferSize,
  746. size_t *pnSizeUsed);
  747. DWORD MTF_ReadFILEDblk( MTF_DBLK_HDR_INFO *psHdrInfo,
  748. MTF_DBLK_FILE_INFO *psTapeInfo,
  749. BYTE *pBuffer);
  750. /* ==================================================================================
  751. Corrupt File DBLK (CFIL)
  752. ================================================================================== */
  753. typedef struct {
  754. UINT32 uCFileAttributes;
  755. UINT32 uDirectoryId; /* Or CFIL Attributes ***/
  756. UINT32 uFileId; /* Or reserved ***/
  757. UINT64 uStreamOffset;
  758. UINT16 uCorruptStreamNumber;
  759. } MTF_DBLK_CFIL_INFO;
  760. void MTF_SetCFILDefaults(MTF_DBLK_CFIL_INFO *pCFILInfo);
  761. DWORD MTF_WriteCFILDblk( MTF_DBLK_HDR_INFO *psHdrInfo,
  762. MTF_DBLK_CFIL_INFO *psTapeInfo,
  763. BYTE *pBuffer,
  764. size_t nBufferSize,
  765. size_t *pnSizeUsed);
  766. DWORD MTF_ReadCFILDblk( MTF_DBLK_HDR_INFO *psHdrInfo,
  767. MTF_DBLK_CFIL_INFO *psTapeInfo,
  768. BYTE *pBuffer);
  769. /* ==================================================================================
  770. End of Set Pad DBLK (ESPB)
  771. ================================================================================== */
  772. DWORD MTF_WriteESPBDblk( MTF_DBLK_HDR_INFO *psHdrInfo,
  773. BYTE *pBuffer,
  774. size_t nBufferSize,
  775. size_t *pnSizeUsed);
  776. DWORD MTF_ReadESPBDblk( MTF_DBLK_HDR_INFO *psHdrInfo,
  777. BYTE *pBuffer);
  778. /* ==================================================================================
  779. End of Set DBLK (ESET)
  780. ================================================================================== */
  781. typedef struct {
  782. UINT32 uESETAttributes;
  783. UINT32 uNumberOfCorrupFiles;
  784. UINT64 uSetMapPBA;
  785. UINT64 uFileDetailPBA;
  786. UINT16 uFDDTapeSequenceNumber;
  787. UINT16 uDataSetNumber;
  788. MTF_DATE_TIME sMediaWriteDate;
  789. } MTF_DBLK_ESET_INFO;
  790. void MTF_SetESETDefaults(MTF_DBLK_ESET_INFO *pESETInfo);
  791. DWORD MTF_WriteESETDblk( MTF_DBLK_HDR_INFO *psHdrInfo,
  792. MTF_DBLK_ESET_INFO *psTapeInfo,
  793. BYTE *pBuffer,
  794. size_t nBufferSize,
  795. size_t *pnSizeUsed);
  796. DWORD MTF_ReadESETDblk( MTF_DBLK_HDR_INFO *psHdrInfo,
  797. MTF_DBLK_ESET_INFO *psTapeInfo,
  798. BYTE *pBuffer);
  799. /* ==================================================================================
  800. End of Tape Media DBLK (EOTM)
  801. ================================================================================== */
  802. typedef struct {
  803. UINT64 uLastESETPBA;
  804. } MTF_DBLK_EOTM_INFO;
  805. void MTF_SetEOTMDefaults(MTF_DBLK_EOTM_INFO *pEOTMInfo);
  806. DWORD MTF_WriteEOTMDblk( MTF_DBLK_HDR_INFO *psHdrInfo,
  807. MTF_DBLK_EOTM_INFO *psTapeInfo,
  808. BYTE *pBuffer,
  809. size_t nBufferSize,
  810. size_t *pnSizeUsed);
  811. DWORD MTF_ReadEOTMDblk( MTF_DBLK_HDR_INFO *psHdrInfo,
  812. MTF_DBLK_EOTM_INFO *psTapeInfo,
  813. BYTE *pBuffer);
  814. /* ==================================================================================
  815. Soft Filemark DBLK (SFMB) - (bmd)
  816. ================================================================================== */
  817. typedef struct {
  818. UINT32 uNumberOfFilemarkEntries;
  819. UINT32 uFilemarkEntriesUsed;
  820. UINT32 uFilemarkArray[1];
  821. } MTF_DBLK_SFMB_INFO;
  822. size_t MTF_GetMaxSoftFilemarkEntries(size_t nBlockSize);
  823. void MTF_InsertSoftFilemark(MTF_DBLK_SFMB_INFO *psSoftInfo,
  824. UINT32 pba);
  825. DWORD MTF_WriteSFMBDblk(MTF_DBLK_HDR_INFO *psHdrInfo,
  826. MTF_DBLK_SFMB_INFO *psSoftInfo,
  827. BYTE *pBuffer,
  828. size_t nBufferSize,
  829. size_t *pnSizeUsed);
  830. DWORD MTF_ReadSFMBDblk(MTF_DBLK_HDR_INFO *psHdrInfo,
  831. MTF_DBLK_SFMB_INFO *psSoftInfo,
  832. BYTE *pBuffer);
  833. /* ==================================================================================
  834. STREAM
  835. ================================================================================== */
  836. typedef struct {
  837. UINT8 acStreamId[4];
  838. UINT16 uStreamFileSystemAttributes;
  839. UINT16 uStreamTapeFormatAttributes;
  840. UINT64 uStreamLength;
  841. UINT16 uDataEncryptionAlgorithm;
  842. UINT16 uDataCompressionAlgorithm;
  843. UINT16 uCheckSum;
  844. } MTF_STREAM_INFO;
  845. void MTF_SetSTREAMDefaults(MTF_STREAM_INFO *pSTREAMInfo,
  846. char *szId);
  847. void MTF_SetSTREAMFromStreamId( MTF_STREAM_INFO *pSTREAMInfo,
  848. WIN32_STREAM_ID *pStreamId,
  849. size_t nIDHeaderSize);
  850. void MTF_SetStreamIdFromSTREAM( WIN32_STREAM_ID *pStreamId,
  851. MTF_STREAM_INFO *pSTREAMInfo,
  852. size_t nIDHeaderSize);
  853. DWORD MTF_WriteStreamHeader(MTF_STREAM_INFO *psStreamInfo,
  854. BYTE *pBuffer,
  855. size_t nBufferSize,
  856. size_t *pnSizeUsed);
  857. DWORD MTF_WriteNameStream(char *szType,
  858. wchar_t *szName,
  859. BYTE *pBuffer,
  860. size_t nBufferSize,
  861. size_t *pnSizeUsed);
  862. DWORD MTF_ReadStreamHeader( MTF_STREAM_INFO *psStreamInfo,
  863. BYTE *pBuffer);
  864. /* ==================================================================================
  865. Utilities
  866. ================================================================================== */
  867. void MTF_DBLK_HDR_INFO_ReadFromBuffer(
  868. MTF_DBLK_HDR_INFO *psHdrInfo,
  869. BYTE *pBuffer);
  870. #pragma pack()
  871. #ifdef __cplusplus
  872. }
  873. #endif
  874. #endif