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.

1138 lines
47 KiB

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