Source code of Windows XP (NT5)
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.

952 lines
30 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. tapeapi.c
  5. Abstract:
  6. This module implements Win32 Tape APIs
  7. Author:
  8. Steve Wood (stevewo) 26-Mar-1992
  9. Lori Brown (Maynard)
  10. Revision History:
  11. --*/
  12. #include "basedll.h"
  13. #pragma hdrstop
  14. #include <ntddtape.h>
  15. DWORD
  16. BasepDoTapeOperation(
  17. IN HANDLE TapeDevice,
  18. IN ULONG IoControlCode,
  19. IN PVOID InputBuffer,
  20. IN ULONG InputBufferLength,
  21. OUT PVOID OutputBuffer,
  22. IN ULONG OutputBufferLength
  23. );
  24. DWORD
  25. BasepDoTapeOperation(
  26. IN HANDLE TapeDevice,
  27. IN ULONG IoControlCode,
  28. IN PVOID InputBuffer,
  29. IN ULONG InputBufferLength,
  30. OUT PVOID OutputBuffer,
  31. IN ULONG OutputBufferLength
  32. )
  33. {
  34. HANDLE NotificationEvent;
  35. NTSTATUS Status;
  36. IO_STATUS_BLOCK IoStatus;
  37. PIO_STATUS_BLOCK IoStatusBlock;
  38. IoStatusBlock = &IoStatus;
  39. NotificationEvent = CreateEvent(NULL, FALSE, FALSE,
  40. NULL);
  41. if (NotificationEvent == NULL) {
  42. return GetLastError();
  43. }
  44. Status = NtDeviceIoControlFile( TapeDevice,
  45. NotificationEvent,
  46. NULL,
  47. NULL,
  48. IoStatusBlock,
  49. IoControlCode,
  50. InputBuffer,
  51. InputBufferLength,
  52. OutputBuffer,
  53. OutputBufferLength
  54. );
  55. if (Status == STATUS_PENDING) {
  56. WaitForSingleObject(NotificationEvent, INFINITE);
  57. Status = IoStatus.Status;
  58. }
  59. CloseHandle(NotificationEvent);
  60. if (!NT_SUCCESS( Status )) {
  61. return BaseSetLastNTError( Status );
  62. }
  63. else {
  64. return NO_ERROR;
  65. }
  66. }
  67. DWORD
  68. WINAPI
  69. SetTapePosition(
  70. HANDLE hDevice,
  71. DWORD dwPositionMethod,
  72. DWORD dwPartition,
  73. DWORD dwOffsetLow,
  74. DWORD dwOffsetHigh,
  75. BOOL bImmediate
  76. )
  77. /*++
  78. Routine Description:
  79. This API is used to set the tape position.
  80. Arguments:
  81. hDevice - Handle to the device on which to set the tape position.
  82. dwPositionMethod - Type of positioning to perform.
  83. This parameter can have one of the following values:
  84. TAPE_REWIND - Position the tape to beginning-of-tape or to
  85. beginning-of-partition if a multiple partition mode is in
  86. effect (ref: CreateTapePartition API). The parameters
  87. dwPartition, dwOffsetHigh, and dwOffsetLow are ignored.
  88. TAPE_ABSOLUTE_BLOCK - Position the tape to the device specific
  89. block address specified by dwOffsetHigh/dwOffsetLow. The
  90. dwPartition parameter is ignored.
  91. TAPE_LOGICAL_BLOCK - Position the tape to the logical block address
  92. specified by dwOffsetHigh/dwOffsetLow. If a multiple partition
  93. mode is in effect (ref: CreateTapePartition API), then the tape
  94. is positioned to the specified logical block address in the
  95. partition specified by dwPartition; otherwise, the dwPartition
  96. parameter value must be 0.
  97. TAPE_SPACE_END_OF_DATA - Position the tape to the end-of-data
  98. on tape or to the end-of-data in the current partition if a
  99. multiple partition mode is in effect (ref: CreateTapePartition
  100. API). The parameters dwPartition, dwOffsetHigh, and dwOffsetLow
  101. are ignored.
  102. TAPE_SPACE_RELATIVE_BLOCKS - Position forward or reverse the number
  103. of blocks specified by dwOffsetHigh/dwOffsetLow. The dwPartition
  104. parameter is ignored.
  105. TAPE_SPACE_FILEMARKS - Position forward or reverse the number of
  106. filemarks specified by dwOffsetHigh/dwOffsetLow. The dwPartition
  107. parameter is ignored.
  108. TAPE_SPACE_SEQUENTIAL_FMKS - Position forward or reverse to the
  109. next occurrence, if any, of the consecutive number of filemarks
  110. specified by dwOffsetHigh/dwOffsetLow. The dwPartition parameter
  111. is ignored.
  112. TAPE_SPACE_SETMARKS - Position forward or reverse the number of
  113. setmarks specified by dwOffsetHigh/dwOffsetLow. The dwPartition
  114. parameter is ignored.
  115. TAPE_SPACE_SEQUENTIAL_SMKS - Position forward or reverse to the
  116. next occurrence, if any, of the consecutive number of setmarks
  117. specified by dwOffsetHigh/dwOffsetLow. The dwPartition parameter
  118. is ignored.
  119. Note that a drive/tape may not support all dwPositionMethod values:
  120. an "unsupported" error indication is returned if the dwPositionMethod
  121. is one that is not flagged as supported in the drive's features bits
  122. (ref: GetTapeParameters API).
  123. dwPartition - The partition number for the position operation specified
  124. by dwPositionMethod (if not ignored).
  125. A partition number value of 0 selects the current partition for
  126. the position operation.
  127. Partitions are numbered logically from 1 to N: the first partition
  128. of the tape is partition number 1, the next is partition number 2,
  129. etc. However, a partition number does not imply a physical/linear
  130. position on tape -- partition number 1 on tape may not be at BOT.
  131. This parameter must be set to 0 if a multiple partition mode is not
  132. in effect (ref: CreateTapePartition API).
  133. dwOffsetHigh/dwOffsetLow - The block address or count for the position
  134. operation specified by dwPositionMethod.
  135. When the offset specifies the number of blocks, filemarks, or
  136. setmarks to position over, a positive value N in the offset shall
  137. cause forward positioning over N blocks, filemarks, or setmarks,
  138. ending on the end-of-partition/tape side of a block, filemark, or
  139. setmark. A zero value in the offset shall cause no change of
  140. position. A negative value N in the offset shall cause reverse
  141. positioning (toward beginning-of-partition/tape) over N blocks,
  142. filemarks, or setmarks, ending on the beginning-of-partition side
  143. of a block, filemark, or setmark.
  144. bImmediate - Return immediately without waiting for the operation to
  145. complete.
  146. Note that a drive/tape may not support the bImmediate option for
  147. either some or all dwPositionMethod values: an "unsupported" error
  148. indication is returned if the bImmediate dwPositionMethod is one
  149. that is not flagged as supported in the drive's features bits
  150. (ref: GetTapeParameters API).
  151. Return Value:
  152. If the function is successful, the return value is NO_ERROR. Otherwise,
  153. it is a Win32 API error code.
  154. --*/
  155. {
  156. TAPE_SET_POSITION TapeSetPosition;
  157. TapeSetPosition.Method = dwPositionMethod;
  158. TapeSetPosition.Partition = dwPartition;
  159. TapeSetPosition.Offset.LowPart = dwOffsetLow;
  160. TapeSetPosition.Offset.HighPart = dwOffsetHigh;
  161. TapeSetPosition.Immediate = (BOOLEAN)bImmediate;
  162. return BasepDoTapeOperation( hDevice,
  163. IOCTL_TAPE_SET_POSITION,
  164. &TapeSetPosition,
  165. sizeof( TapeSetPosition ),
  166. NULL,
  167. 0
  168. );
  169. }
  170. DWORD
  171. WINAPI
  172. GetTapePosition(
  173. HANDLE hDevice,
  174. DWORD dwPositionType,
  175. LPDWORD lpdwPartition,
  176. LPDWORD lpdwOffsetLow,
  177. LPDWORD lpdwOffsetHigh
  178. )
  179. /*++
  180. Routine Description:
  181. This API is used to get the tape position.
  182. Arguments:
  183. hDevice - Handle to the device on which to get the tape position.
  184. dwPositionType - Type of position to return.
  185. This parameter can have one of the following values:
  186. TAPE_ABSOLUTE_POSITION - Return a device specific block address to
  187. the LARGE_INTEGER pointed to by lpliOffset.
  188. The DWORD pointed to by the lpdwPartition parameter is set to 0.
  189. TAPE_LOGICAL_POSITION - Return a logical block address to the
  190. LARGE_INTEGER pointed to by lpliOffset.
  191. The DWORD pointed to by the lpdwPartition parameter is set to 0
  192. if a multiple partition mode is not in effect; otherwise, it is
  193. set to the partition number of the currently selected partition
  194. (ref: CreateTapePartition API).
  195. Logical block addresses are 0 based -- 0 is a valid logical
  196. block address. A logical block address is a relative reference
  197. point (ref: logical positioning whitepaper).
  198. lpdwPartition - Pointer to a DWORD that receives the appropriate return
  199. value for the dwPositionType values explained above.
  200. lpliOffset - Pointer to a LARGE_INTEGER that receives the appropriate
  201. return value for the dwPositionType values explained above.
  202. Return Value:
  203. If the function is successful, the return value is NO_ERROR. Otherwise,
  204. it is a Win32 API error code.
  205. --*/
  206. {
  207. TAPE_GET_POSITION TapeGetPosition;
  208. DWORD rc;
  209. TapeGetPosition.Type = dwPositionType;
  210. rc = BasepDoTapeOperation( hDevice,
  211. IOCTL_TAPE_GET_POSITION,
  212. &TapeGetPosition,
  213. sizeof( TapeGetPosition ),
  214. &TapeGetPosition,
  215. sizeof( TapeGetPosition )
  216. );
  217. if (rc == NO_ERROR) {
  218. *lpdwPartition = TapeGetPosition.Partition;
  219. *lpdwOffsetLow = TapeGetPosition.Offset.LowPart;
  220. *lpdwOffsetHigh = TapeGetPosition.Offset.HighPart;
  221. }
  222. else {
  223. *lpdwPartition = 0;
  224. *lpdwOffsetLow = 0;
  225. *lpdwOffsetHigh = 0;
  226. }
  227. return rc;
  228. }
  229. DWORD
  230. WINAPI
  231. PrepareTape(
  232. HANDLE hDevice,
  233. DWORD dwOperation,
  234. BOOL bImmediate
  235. )
  236. /*++
  237. Routine Description:
  238. This API is used to prepare the tape.
  239. Arguments:
  240. hDevice - Handle to the device on which to prepare the tape.
  241. dwOperation - Type of tape preparation to perform.
  242. This parameter can have one of the following values:
  243. TAPE_LOAD - Load the tape and position the tape to beginning-of-medium.
  244. TAPE_UNLOAD - Position the tape to beginning-of-medium for removal from
  245. the device.
  246. Following a successful unload operation, the device shall return an
  247. error for all subsequent medium-access commands until a load
  248. operation is successfully completed.
  249. TAPE_TENSION - Tension the tape in the device as required. The
  250. implementation of this operation is device specific.
  251. TAPE_LOCK - Disable the removal of the tape from the device.
  252. TAPE_UNLOCK - Enable the removal of the tape from the device.
  253. TAPE_FORMAT - Format media in tape device.
  254. bImmediate - Return immediately without waiting for operation to complete.
  255. Return Value:
  256. If the function is successful, the return value is NO_ERROR. Otherwise,
  257. it is a Win32 API error code.
  258. --*/
  259. {
  260. TAPE_PREPARE TapePrepare;
  261. TapePrepare.Operation = dwOperation;
  262. TapePrepare.Immediate = (BOOLEAN)bImmediate;
  263. return BasepDoTapeOperation( hDevice,
  264. IOCTL_TAPE_PREPARE,
  265. &TapePrepare,
  266. sizeof( TapePrepare ),
  267. NULL,
  268. 0
  269. );
  270. }
  271. DWORD
  272. WINAPI
  273. EraseTape(
  274. HANDLE hDevice,
  275. DWORD dwEraseType,
  276. BOOL bImmediate
  277. )
  278. /*++
  279. Routine Description:
  280. This API is used to erase the tape partition.
  281. Arguments:
  282. hDevice - Handle to the device on which to erase the tape partition.
  283. dwEraseType - Type of erase to perform.
  284. This parameter can have one of the following values:
  285. TAPE_ERASE_SHORT - Write an erase gap or end-of-recorded data marker
  286. beginning at the current position.
  287. TAPE_ERASE_LONG - Erase all remaining media in the current partition
  288. beginning at the current position.
  289. bImmediate - Return immediately without waiting for operation to complete.
  290. Return Value:
  291. If the function is successful, the return value is NO_ERROR. Otherwise,
  292. it is a Win32 API error code.
  293. --*/
  294. {
  295. TAPE_ERASE TapeErase;
  296. TapeErase.Type = dwEraseType;
  297. TapeErase.Immediate = (BOOLEAN)bImmediate;
  298. return BasepDoTapeOperation( hDevice,
  299. IOCTL_TAPE_ERASE,
  300. &TapeErase,
  301. sizeof( TapeErase ),
  302. NULL,
  303. 0
  304. );
  305. }
  306. DWORD
  307. WINAPI
  308. CreateTapePartition(
  309. HANDLE hDevice,
  310. DWORD dwPartitionMethod,
  311. DWORD dwCount,
  312. DWORD dwSize
  313. )
  314. /*++
  315. Routine Description:
  316. This API is used to create partitions.
  317. Arguments:
  318. hDevice - Handle to the device on which to create partitions.
  319. dwPartitionMethod - Type of partitioning to perform.
  320. Creating partitions causes the tape to be reformatted. All previous
  321. information recorded on the tape is destroyed.
  322. This parameter can have one of the following values:
  323. TAPE_FIXED_PARTITIONS - Partition the tape based on the device's fixed
  324. definition of partitions. The dwCount and dwSize parameters are
  325. ignored.
  326. TAPE_SELECT_PARTITIONS - Partition the tape into the number of
  327. partitions specified by dwCount using the partition sizes defined
  328. by the device. The dwSize parameter is ignored.
  329. TAPE_INITIATOR_PARTITIONS - Partition the tape into the number of
  330. partitions specified by dwCount using the partition size specified
  331. by dwSize for all but the last partition. The size of the last
  332. partition is the remainder of the tape.
  333. dwCount - Number of partitions to create. The maximum number of partitions
  334. a device can create is returned by GetTapeParameters.
  335. dwSize - Partition size in megabytes. The maximum capacity of a tape is
  336. returned by GetTapeParameters.
  337. Return Value:
  338. If the function is successful, the return value is NO_ERROR. Otherwise,
  339. it is a Win32 API error code.
  340. --*/
  341. {
  342. TAPE_CREATE_PARTITION TapeCreatePartition;
  343. TapeCreatePartition.Method = dwPartitionMethod;
  344. TapeCreatePartition.Count = dwCount;
  345. TapeCreatePartition.Size = dwSize;
  346. return BasepDoTapeOperation( hDevice,
  347. IOCTL_TAPE_CREATE_PARTITION,
  348. &TapeCreatePartition,
  349. sizeof( TapeCreatePartition ),
  350. NULL,
  351. 0
  352. );
  353. }
  354. DWORD
  355. WINAPI
  356. WriteTapemark(
  357. HANDLE hDevice,
  358. DWORD dwTapemarkType,
  359. DWORD dwTapemarkCount,
  360. BOOL bImmediate
  361. )
  362. /*++
  363. Routine Description:
  364. This API is used to write tapemarks.
  365. Arguments:
  366. hDevice - Handle to the device on which to write the tapemarks.
  367. dwTapemarkType - Type of tapemarks to write.
  368. This parameter can have one of the following values:
  369. TAPE_SETMARKS - Write the number of setmarks specified by
  370. dwTapemarkCount to the tape.
  371. A setmark is a special recorded element containing no user data.
  372. A setmark provides a segmentation scheme hierarchically superior
  373. to filemarks.
  374. TAPE_FILEMARKS - Write the number of filemarks specified by
  375. dwTapemarkCount to the tape.
  376. A filemark is a special recorded element containing no user data.
  377. TAPE_SHORT_FILEMARKS - Write the number of short filemarks specified by
  378. dwTapemarkCount to the tape.
  379. A short filemark contains a short erase gap that does not allow a
  380. write operation to be performed. The short filemark cannot be
  381. overwritten except when the write operation is performed from the
  382. beginning-of-partition or from a previous long filemark.
  383. TAPE_LONG_FILEMARKS - Write the number of long filemarks specified by
  384. dwTapemarkCount to the tape.
  385. A long filemark includes a long erase gap. This gap allows the
  386. initiator to position on the beginning-of-partition side of the
  387. filemark, in the erase gap, and append data with the write
  388. operation. This causes the long filemark and any data following
  389. the long filemark to be erased.
  390. dwTapemarkCount - The number of tapemarks to write.
  391. bImmediate - Return immediately without waiting for operation to complete.
  392. Return Value:
  393. If the function is successful, the return value is NO_ERROR. Otherwise,
  394. it is a Win32 API error code.
  395. --*/
  396. {
  397. TAPE_WRITE_MARKS TapeWriteMarks;
  398. TapeWriteMarks.Type = dwTapemarkType;
  399. TapeWriteMarks.Count = dwTapemarkCount;
  400. TapeWriteMarks.Immediate = (BOOLEAN)bImmediate;
  401. return BasepDoTapeOperation( hDevice,
  402. IOCTL_TAPE_WRITE_MARKS,
  403. &TapeWriteMarks,
  404. sizeof( TapeWriteMarks ),
  405. NULL,
  406. 0
  407. );
  408. }
  409. DWORD
  410. WINAPI
  411. GetTapeParameters(
  412. HANDLE hDevice,
  413. DWORD dwOperation,
  414. LPDWORD lpdwSize,
  415. LPVOID lpTapeInformation
  416. )
  417. /*++
  418. Routine Description:
  419. This API is used to get information about a tape device.
  420. Arguments:
  421. hDevice - Handle to the device on which to get the information.
  422. dwOperation - Type of information to get.
  423. This parameter can have one of the following values:
  424. GET_TAPE_MEDIA_INFORMATION - Return the media specific information in
  425. lpTapeInformation.
  426. GET_TAPE_DRIVE_INFORMATION - Return the device specific information in
  427. lpTapeInformation.
  428. lpdwSize - Pointer to a DWORD containing the size of the buffer pointed to
  429. by lpTapeInformation. If the buffer is too small, this parameter
  430. returns with the required size in bytes.
  431. lpTapeInformation - Pointer to a buffer to receive the information. The
  432. structure returned in the buffer is determined by dwOperation.
  433. For GET_TAPE_MEDIA_INFORMATION, lpTapeInformation returns the following
  434. structure:
  435. LARGE_INTEGER Capacity - The maximum tape capacity in bytes.
  436. LARGE_INTEGER Remaining - The remaining tape capacity in bytes.
  437. DWORD BlockSize - The size of a fixed-length logical block in bytes.
  438. A block size of 0 indicates variable-length block mode, where the
  439. length of a block is set by the write operation. The default
  440. fixed-block size and the range of valid block sizes are returned
  441. by GetTapeParameters.
  442. DWORD PartitionCount - Number of partitions on the tape. If only one
  443. partition is supported by the device, this parameter is set to 0.
  444. BOOLEAN WriteProtected - Indicates if the tape is write protected:
  445. 0 is write enabled, 1 is write protected.
  446. For GET_TAPE_DRIVE_INFORMATION, lpTapeInformation returns the following
  447. structure:
  448. BOOLEAN ECC - Indicates if hardware error correction is enabled or
  449. disabled: 0 is disabled, 1 is enabled.
  450. BOOLEAN Compression - Indicates if hardware data compression is enabled
  451. or disabled: 0 is disabled, 1 is enabled.
  452. BOOLEAN DataPadding - Indicates if data padding is disabled or enabled:
  453. 0 is disabled, 1 is enabled.
  454. BOOLEAN ReportSetmarks - Indicates if reporting setmarks is enabled or
  455. disabled: 0 is disabled, 1 is enabled.
  456. DWORD DefaultBlockSize - Returns the default fixed-block size for the
  457. device.
  458. DWORD MaximumBlockSize - Returns the maximum block size for the device.
  459. DWORD MinimumBlockSize - Returns the minimum block size for the device.
  460. DWORD MaximumPartitionCount - Returns the maximum number of partitions
  461. the device can create.
  462. DWORD FeaturesLow - The lower 32 bits of the device features flag.
  463. DWORD FeaturesHigh - The upper 32 bits of the device features flag.
  464. The device features flag represents the operations a device
  465. supports by returning a value of 1 in the appropriate bit for each
  466. feature supported.
  467. This parameter can have one or more of the following bit values
  468. set in the lower 32 bits:
  469. TAPE_DRIVE_FIXED - Supports creating fixed data partitions.
  470. TAPE_DRIVE_SELECT - Supports creating select data partitions.
  471. TAPE_DRIVE_INITIATOR - Supports creating initiator-defined
  472. partitions.
  473. TAPE_DRIVE_ERASE_SHORT - Supports short erase operation.
  474. TAPE_DRIVE_ERASE_LONG - Supports long erase operation.
  475. TAPE_DRIVE_ERASE_BOP_ONLY - Supports erase operation from the
  476. beginning-of-partition only.
  477. TAPE_DRIVE_TAPE_CAPACITY - Supports returning the maximum capacity
  478. of the tape.
  479. TAPE_DRIVE_TAPE_REMAINING - Supports returning the remaining
  480. capacity of the tape.
  481. TAPE_DRIVE_FIXED_BLOCK - Supports fixed-length block mode.
  482. TAPE_DRIVE_VARIABLE_BLOCK - Supports variable-length block mode.
  483. TAPE_DRIVE_WRITE_PROTECT - Supports returning if the tape is write
  484. enabled or write protected.
  485. TAPE_DRIVE_ECC - Supports hardware error correction.
  486. TAPE_DRIVE_COMPRESSION - Supports hardware data compression.
  487. TAPE_DRIVE_PADDING - Supports data padding.
  488. TAPE_DRIVE_REPORT_SMKS - Supports reporting setmarks.
  489. TAPE_DRIVE_GET_ABSOLUTE_BLK - Supports returning the current device
  490. specific block address.
  491. TAPE_DRIVE_GET_LOGICAL_BLK - Supports returning the current logical
  492. block address (and logical tape partition).
  493. This parameter can have one or more of the following bit values
  494. set in the upper 32 bits:
  495. TAPE_DRIVE_LOAD_UNLOAD - Supports enabling and disabling the device
  496. for further operations.
  497. TAPE_DRIVE_TENSION - Supports tensioning the tape.
  498. TAPE_DRIVE_LOCK_UNLOCK - Supports enabling and disabling removal of
  499. the tape from the device.
  500. TAPE_DRIVE_SET_BLOCK_SIZE - Supports setting the size of a
  501. fixed-length logical block or setting variable-length block
  502. mode.
  503. TAPE_DRIVE_SET_ECC - Supports enabling and disabling hardware error
  504. correction.
  505. TAPE_DRIVE_SET_COMPRESSION - Supports enabling and disabling
  506. hardware data compression.
  507. TAPE_DRIVE_SET_PADDING - Supports enabling and disabling data
  508. padding.
  509. TAPE_DRIVE_SET_REPORT_SMKS - Supports enabling and disabling
  510. reporting of setmarks.
  511. TAPE_DRIVE_ABSOLUTE_BLK - Supports positioning to a device specific
  512. block address.
  513. TAPE_DRIVE_ABS_BLK_IMMED - Supports immediate positioning to a
  514. device specific block address.
  515. TAPE_DRIVE_LOGICAL_BLK - Supports positioning to a logical block
  516. address in a partition.
  517. TAPE_DRIVE_LOG_BLK_IMMED - Supports immediate positioning to a
  518. logical block address in a partition.
  519. TAPE_DRIVE_END_OF_DATA - Supports positioning to the end-of-data
  520. in a partition.
  521. TAPE_DRIVE_RELATIVE_BLKS - Supports positioning forward (or
  522. reverse) a specified number of blocks.
  523. TAPE_DRIVE_FILEMARKS - Supports positioning forward (or reverse)
  524. a specified number of filemarks.
  525. TAPE_DRIVE_SEQUENTIAL_FMKS - Supports positioning forward (or
  526. reverse) to the first occurrence of a specified number of
  527. consecutive filemarks.
  528. TAPE_DRIVE_SETMARKS - Supports positioning forward (or reverse)
  529. a specified number of setmarks.
  530. TAPE_DRIVE_SEQUENTIAL_SMKS - Supports positioning forward (or
  531. reverse) to the first occurrence of a specified number of
  532. consecutive setmarks.
  533. TAPE_DRIVE_REVERSE_POSITION - Supports positioning over blocks,
  534. filemarks, or setmarks in the reverse direction.
  535. TAPE_DRIVE_WRITE_SETMARKS - Supports writing setmarks.
  536. TAPE_DRIVE_WRITE_FILEMARKS - Supports writing filemarks.
  537. TAPE_DRIVE_WRITE_SHORT_FMKS - Supports writing short filemarks.
  538. TAPE_DRIVE_WRITE_LONG_FMKS - Supports writing long filemarks.
  539. Return Value:
  540. If the function is successful, the return value is NO_ERROR. Otherwise,
  541. it is a Win32 API error code.
  542. --*/
  543. {
  544. DWORD rc;
  545. switch (dwOperation) {
  546. case GET_TAPE_MEDIA_INFORMATION:
  547. if (*lpdwSize < sizeof(TAPE_GET_MEDIA_PARAMETERS)) {
  548. *lpdwSize = sizeof(TAPE_GET_MEDIA_PARAMETERS);
  549. rc = ERROR_MORE_DATA ;
  550. } else {
  551. rc = BasepDoTapeOperation( hDevice,
  552. IOCTL_TAPE_GET_MEDIA_PARAMS,
  553. NULL,
  554. 0,
  555. lpTapeInformation,
  556. sizeof( TAPE_GET_MEDIA_PARAMETERS )
  557. );
  558. }
  559. break;
  560. case GET_TAPE_DRIVE_INFORMATION:
  561. if (*lpdwSize < sizeof(TAPE_GET_DRIVE_PARAMETERS)) {
  562. *lpdwSize = sizeof(TAPE_GET_DRIVE_PARAMETERS);
  563. rc = ERROR_MORE_DATA ;
  564. } else {
  565. rc = BasepDoTapeOperation( hDevice,
  566. IOCTL_TAPE_GET_DRIVE_PARAMS,
  567. NULL,
  568. 0,
  569. lpTapeInformation,
  570. sizeof( TAPE_GET_DRIVE_PARAMETERS )
  571. );
  572. }
  573. break;
  574. default:
  575. rc = ERROR_INVALID_FUNCTION;
  576. break;
  577. }
  578. return rc;
  579. }
  580. DWORD
  581. WINAPI
  582. SetTapeParameters(
  583. HANDLE hDevice,
  584. DWORD dwOperation,
  585. LPVOID lpTapeInformation
  586. )
  587. /*++
  588. Routine Description:
  589. This API is used to set information about a tape device.
  590. Arguments:
  591. hDevice - Handle to the device on which to set the information.
  592. dwOperation - Type of information to set.
  593. This parameter can have one of the following values:
  594. SET_TAPE_MEDIA_INFORMATION - Set the media specific information
  595. specified in lpTapeInformation.
  596. SET_TAPE_DRIVE_INFORMATION - Set the device specific information
  597. specified in lpTapeInformation.
  598. lpTapeInformation - Pointer to a buffer containing the information to set.
  599. The structure returned in the buffer is determined by dwOperation.
  600. For SET_TAPE_MEDIA_INFORMATION, lpTapeInformation contains the
  601. following structure:
  602. DWORD BlockSize - The size of a fixed-length logical block in bytes.
  603. A block size of 0 indicates variable-length block mode, where the
  604. length of a block is set by the write operation. The default
  605. fixed-block size and the range of valid block sizes are returned
  606. by GetTapeParameters.
  607. For SET_TAPE_DRIVE_INFORMATION, lpTapeInformation contains the
  608. following structure:
  609. BOOLEAN ECC - Enables or disables hardware error correction: 0 is
  610. disabled, 1 is enabled.
  611. BOOLEAN Compression - Enables or disables hardware data compression:
  612. 0 is disabled, 1 is enabled.
  613. BOOLEAN DataPadding - Enables or disables data padding: 0 is disabled,
  614. 1 is enabled.
  615. BOOLEAN ReportSetmarks - Enables or disables reporting of setmarks:
  616. 0 is disabled, 1 is enabled.
  617. Return Value:
  618. If the function is successful, the return value is NO_ERROR. Otherwise,
  619. it is a Win32 API error code.
  620. --*/
  621. {
  622. DWORD rc;
  623. switch (dwOperation) {
  624. case SET_TAPE_MEDIA_INFORMATION:
  625. rc = BasepDoTapeOperation( hDevice,
  626. IOCTL_TAPE_SET_MEDIA_PARAMS,
  627. lpTapeInformation,
  628. sizeof( TAPE_SET_MEDIA_PARAMETERS ),
  629. NULL,
  630. 0
  631. );
  632. break;
  633. case SET_TAPE_DRIVE_INFORMATION:
  634. rc = BasepDoTapeOperation( hDevice,
  635. IOCTL_TAPE_SET_DRIVE_PARAMS,
  636. lpTapeInformation,
  637. sizeof( TAPE_SET_DRIVE_PARAMETERS ),
  638. NULL,
  639. 0
  640. );
  641. break;
  642. default:
  643. rc = ERROR_INVALID_FUNCTION;
  644. break;
  645. }
  646. return rc;
  647. }
  648. DWORD
  649. WINAPI
  650. GetTapeStatus(
  651. HANDLE hDevice
  652. )
  653. /*++
  654. Routine Description:
  655. This API is used to get the status of a tape device.
  656. Arguments:
  657. hDevice - Handle to the device on which to get the status.
  658. Return Value:
  659. If the device is ready to accept an appropriate medium-access command
  660. without returning an error, the return value is NO_ERROR. Otherwise,
  661. it is a Win32 API error code.
  662. --*/
  663. {
  664. return BasepDoTapeOperation( hDevice,
  665. IOCTL_TAPE_GET_STATUS,
  666. NULL,
  667. 0,
  668. NULL,
  669. 0
  670. );
  671. }