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.

449 lines
15 KiB

  1. /*
  2. * $Log: V:/Flite/archives/TrueFFS5/Src/FLIOCTL.C_V $
  3. *
  4. * Rev 1.7 May 09 2001 00:45:48 oris
  5. * Changed protection ioctl interface to prevent the use of input buffer as an output buffer.
  6. *
  7. * Rev 1.6 Apr 16 2001 13:43:28 oris
  8. * Removed warrnings.
  9. *
  10. * Rev 1.5 Apr 09 2001 15:09:20 oris
  11. * End with an empty line.
  12. *
  13. * Rev 1.4 Apr 01 2001 15:16:26 oris
  14. * Updated inquire capability ioctl - diffrent input and output records.
  15. *
  16. * Rev 1.3 Apr 01 2001 07:58:30 oris
  17. * copywrite notice.
  18. * FL_IOCTL_FORMAT_PHYSICAL_DRIVE ioctl is not under the LOW_LEVEL compilation flag.
  19. * Bug fix - BDK_GET_INFO no longer calls bdkCreate().
  20. *
  21. * Rev 1.2 Feb 14 2001 02:15:00 oris
  22. * Updated inquire capabilities ioctl.
  23. *
  24. * Rev 1.1 Feb 13 2001 01:52:20 oris
  25. * Added the following new IO Controls:
  26. * FL_IOCTL_FORMAT_VOLUME2,
  27. * FL_IOCTL_FORMAT_PARTITION,
  28. * FL_IOCTL_BDTL_HW_PROTECTION,
  29. * FL_IOCTL_BINARY_HW_PROTECTION,
  30. * FL_IOCTL_OTP,
  31. * FL_IOCTL_CUSTOMER_ID,
  32. * FL_IOCTL_UNIQUE_ID,
  33. * FL_IOCTL_NUMBER_OF_PARTITIONS,
  34. * FL_IOCTL_SUPPORTED_FEATURES,
  35. * FL_IOCTL_SET_ENVIRONMENT_VARIABLES,
  36. * FL_IOCTL_PLACE_EXB_BY_BUFFER,
  37. * FL_IOCTL_WRITE_IPL,
  38. * FL_IOCTL_DEEP_POWER_DOWN_MODE,
  39. * and BDK_GET_INFO type in FL_IOCTL_BDK_OPERATION
  40. * Those IOCTL were not qualed and the TrueFFS 5.0 should be release with revision 1.0 of this this file.
  41. *
  42. * Rev 1.0 Feb 04 2001 11:37:36 oris
  43. * Initial revision.
  44. *
  45. */
  46. /***********************************************************************************/
  47. /* M-Systems Confidential */
  48. /* Copyright (C) M-Systems Flash Disk Pioneers Ltd. 1995-2001 */
  49. /* All Rights Reserved */
  50. /***********************************************************************************/
  51. /* NOTICE OF M-SYSTEMS OEM */
  52. /* SOFTWARE LICENSE AGREEMENT */
  53. /* */
  54. /* THE USE OF THIS SOFTWARE IS GOVERNED BY A SEPARATE LICENSE */
  55. /* AGREEMENT BETWEEN THE OEM AND M-SYSTEMS. REFER TO THAT AGREEMENT */
  56. /* FOR THE SPECIFIC TERMS AND CONDITIONS OF USE, */
  57. /* OR CONTACT M-SYSTEMS FOR LICENSE ASSISTANCE: */
  58. /* E-MAIL = [email protected] */
  59. /***********************************************************************************/
  60. #include "flioctl.h"
  61. #include "blockdev.h"
  62. #ifdef IOCTL_INTERFACE
  63. FLStatus flIOctl(IOreq FAR2 *ioreq1)
  64. {
  65. IOreq ioreq2;
  66. void FAR1 *inputRecord;
  67. void FAR1 *outputRecord;
  68. inputRecord = ((flIOctlRecord FAR1 *)(ioreq1->irData))->inputRecord;
  69. outputRecord = ((flIOctlRecord FAR1 *)(ioreq1->irData))->outputRecord;
  70. ioreq2.irHandle = ioreq1->irHandle;
  71. switch (ioreq1->irFlags) {
  72. case FL_IOCTL_GET_INFO:
  73. {
  74. flDiskInfoOutput FAR1 *outputRec = (flDiskInfoOutput FAR1 *)outputRecord;
  75. ioreq2.irData = &(outputRec->info);
  76. outputRec->status = flVolumeInfo(&ioreq2);
  77. return outputRec->status;
  78. }
  79. #ifdef DEFRAGMENT_VOLUME
  80. case FL_IOCTL_DEFRAGMENT:
  81. {
  82. flDefragInput FAR1 *inputRec = (flDefragInput FAR1 *)inputRecord;
  83. flDefragOutput FAR1 *outputRec = (flDefragOutput FAR1 *)outputRecord;
  84. ioreq2.irLength = inputRec->requiredNoOfSectors;
  85. outputRec->status = flDefragmentVolume(&ioreq2);
  86. outputRec->actualNoOfSectors = ioreq2.irLength;
  87. return outputRec->status;
  88. }
  89. #endif /* DEFRAGMENT_VOLUME */
  90. #ifndef FL_READ_ONLY
  91. #ifdef WRITE_PROTECTION
  92. case FL_IOCTL_WRITE_PROTECT:
  93. {
  94. flWriteProtectInput FAR1 *inputRec = (flWriteProtectInput FAR1 *)inputRecord;
  95. flOutputStatusRecord FAR1 *outputRec = (flOutputStatusRecord FAR1 *)outputRecord;
  96. ioreq2.irData = inputRec->password;
  97. ioreq2.irFlags = inputRec->type;
  98. outputRec->status = flWriteProtection(&ioreq2);
  99. return outputRec->status;
  100. }
  101. #endif /* WRITE_PROTECTION */
  102. #endif /* FL_READ_ONLY */
  103. case FL_IOCTL_MOUNT_VOLUME:
  104. {
  105. flMountInput FAR1 *inputRec = (flMountInput FAR1 *)inputRecord;
  106. flOutputStatusRecord FAR1 *outputRec = (flOutputStatusRecord FAR1 *)outputRecord;
  107. if (inputRec->type == FL_DISMOUNT)
  108. outputRec->status = flDismountVolume(&ioreq2);
  109. else
  110. outputRec->status = flAbsMountVolume(&ioreq2);
  111. return outputRec->status;
  112. }
  113. #ifdef FORMAT_VOLUME
  114. case FL_IOCTL_FORMAT_VOLUME:
  115. {
  116. flFormatInput FAR1 *inputRec = (flFormatInput FAR1 *)inputRecord;
  117. flOutputStatusRecord FAR1 *outputRec = (flOutputStatusRecord FAR1 *)outputRecord;
  118. ioreq2.irFlags = inputRec->formatType;
  119. ioreq2.irData = &(inputRec->fp);
  120. outputRec->status = flFormatVolume(&ioreq2);
  121. return outputRec->status;
  122. }
  123. case FL_IOCTL_FORMAT_LOGICAL_DRIVE:
  124. {
  125. flFormatLogicalInput FAR1 *inputRec = (flFormatLogicalInput FAR1 *)inputRecord;
  126. flOutputStatusRecord FAR1 *outputRec = (flOutputStatusRecord FAR1 *)outputRecord;
  127. ioreq2.irData = &(inputRec->fp);
  128. outputRec->status = flFormatLogicalDrive(&ioreq2);
  129. return outputRec->status;
  130. }
  131. case FL_IOCTL_FORMAT_PHYSICAL_DRIVE:
  132. {
  133. flFormatPhysicalInput FAR1 *inputRec = (flFormatPhysicalInput FAR1 *)inputRecord;
  134. flOutputStatusRecord FAR1 *outputRec = (flOutputStatusRecord FAR1 *)outputRecord;
  135. ioreq2.irFlags = inputRec->formatType;
  136. ioreq2.irData = &(inputRec->fp);
  137. outputRec->status = flFormatPhysicalDrive(&ioreq2);
  138. return outputRec->status;
  139. }
  140. #endif /* FORMAT_VOLUME */
  141. #ifdef BDK_ACCESS
  142. case FL_IOCTL_BDK_OPERATION:
  143. {
  144. flBDKOperationInput FAR1 *inputRec = (flBDKOperationInput FAR1 *)inputRecord;
  145. flOutputStatusRecord FAR1 *outputRec = (flOutputStatusRecord FAR1 *)outputRecord;
  146. ioreq2.irData = &(inputRec->bdkStruct);
  147. switch(inputRec->type) {
  148. case BDK_INIT_READ:
  149. outputRec->status = bdkReadInit(&ioreq2);
  150. break;
  151. case BDK_READ:
  152. outputRec->status = bdkReadBlock(&ioreq2);
  153. break;
  154. case BDK_GET_INFO:
  155. outputRec->status = bdkPartitionInfo(&ioreq2);
  156. break;
  157. #ifndef FL_READ_ONLY
  158. case BDK_INIT_WRITE:
  159. outputRec->status = bdkWriteInit(&ioreq2);
  160. break;
  161. case BDK_WRITE:
  162. outputRec->status = bdkWriteBlock(&ioreq2);
  163. break;
  164. case BDK_ERASE:
  165. outputRec->status = bdkErase(&ioreq2);
  166. break;
  167. case BDK_CREATE:
  168. outputRec->status = bdkCreate(&ioreq2);
  169. break;
  170. #endif /* FL_READ_ONLY */
  171. default:
  172. outputRec->status = flBadParameter;
  173. break;
  174. }
  175. return outputRec->status;
  176. }
  177. #endif /* BDK_ACCESS */
  178. #ifdef HW_PROTECTION
  179. #ifdef BDK_ACCESS
  180. case FL_IOCTL_BINARY_HW_PROTECTION:
  181. {
  182. flProtectionInput FAR1 *inputRec = (flProtectionInput FAR1 *)inputRecord;
  183. flProtectionOutput FAR1 *outputRec = (flProtectionOutput FAR1 *)outputRecord;
  184. switch(inputRec->type)
  185. {
  186. case PROTECTION_INSERT_KEY:
  187. ioreq2.irData = inputRec->key;
  188. outputRec->status = bdkInsertProtectionKey(&ioreq2);
  189. break;
  190. case PROTECTION_REMOVE_KEY:
  191. outputRec->status = bdkRemoveProtectionKey(&ioreq2);
  192. break;
  193. case PROTECTION_GET_TYPE:
  194. outputRec->status = bdkIdentifyProtection(&ioreq2);
  195. outputRec->protectionType = (byte)ioreq2.irFlags;
  196. break;
  197. case PROTECTION_DISABLE_LOCK:
  198. ioreq2.irFlags = 0;
  199. outputRec->status = bdkHardwareProtectionLock(&ioreq2);
  200. break;
  201. case PROTECTION_ENABLE_LOCK:
  202. ioreq2.irFlags = LOCK_ENABLED;
  203. outputRec->status = bdkHardwareProtectionLock(&ioreq2);
  204. break;
  205. case PROTECTION_CHANGE_KEY:
  206. ioreq2.irData = inputRec->key;
  207. outputRec->status = bdkChangeProtectionKey(&ioreq2);
  208. break;
  209. case PROTECTION_CHANGE_TYPE:
  210. ioreq2.irFlags = inputRec->protectionType;
  211. outputRec->status = bdkChangeProtectionType(&ioreq2);
  212. break;
  213. default:
  214. outputRec->status = flBadParameter;
  215. break;
  216. }
  217. return outputRec->status;
  218. }
  219. #endif /* BDK_ACCESS */
  220. case FL_IOCTL_BDTL_HW_PROTECTION:
  221. {
  222. flProtectionInput FAR1 *inputRec = (flProtectionInput FAR1 *)inputRecord;
  223. flProtectionOutput FAR1 *outputRec = (flProtectionOutput FAR1 *)outputRecord;
  224. switch(inputRec->type)
  225. {
  226. case PROTECTION_INSERT_KEY:
  227. ioreq2.irData = inputRec->key;
  228. outputRec->status = flInsertProtectionKey(&ioreq2);
  229. break;
  230. case PROTECTION_REMOVE_KEY:
  231. outputRec->status = flRemoveProtectionKey(&ioreq2);
  232. break;
  233. case PROTECTION_GET_TYPE:
  234. outputRec->status = flIdentifyProtection(&ioreq2);
  235. outputRec->protectionType = (byte)ioreq2.irFlags;
  236. break;
  237. case PROTECTION_DISABLE_LOCK:
  238. ioreq2.irFlags = 0;
  239. outputRec->status = flHardwareProtectionLock(&ioreq2);
  240. break;
  241. case PROTECTION_ENABLE_LOCK:
  242. ioreq2.irFlags = LOCK_ENABLED;
  243. outputRec->status = flHardwareProtectionLock(&ioreq2);
  244. break;
  245. case PROTECTION_CHANGE_KEY:
  246. ioreq2.irData = inputRec->key;
  247. outputRec->status = flChangeProtectionKey(&ioreq2);
  248. break;
  249. case PROTECTION_CHANGE_TYPE:
  250. ioreq2.irFlags = inputRec->protectionType;
  251. outputRec->status = flChangeProtectionType(&ioreq2);
  252. break;
  253. default:
  254. outputRec->status = flBadParameter;
  255. break;
  256. }
  257. return outputRec->status;
  258. }
  259. #endif /* HW_PROTECTION */
  260. #ifdef HW_OTP
  261. case FL_IOCTL_OTP:
  262. {
  263. flOtpInput FAR1 *inputRec = (flOtpInput FAR1 *)inputRecord;
  264. flOutputStatusRecord FAR1 *outputRec = (flOutputStatusRecord FAR1 *)outputRecord;
  265. switch(inputRec->type)
  266. {
  267. case OTP_SIZE:
  268. outputRec->status = flOTPSize(&ioreq2);
  269. inputRec->lockedFlag = (byte)ioreq2.irFlags;
  270. inputRec->length = ioreq2.irCount ;
  271. inputRec->usedSize = ioreq2.irLength ;
  272. break;
  273. case OTP_READ:
  274. ioreq2.irData = inputRec->buffer; /* user buffer */
  275. ioreq2.irCount = inputRec->usedSize; /* offset */
  276. ioreq2.irLength = inputRec->length; /* size to read */
  277. outputRec->status = flOTPRead(&ioreq2);
  278. break;
  279. case OTP_WRITE_LOCK:
  280. ioreq2.irData = inputRec->buffer; /* user buffer */
  281. ioreq2.irLength = inputRec->length; /* size to read */
  282. outputRec->status = flOTPWriteAndLock(&ioreq2);
  283. break;
  284. default:
  285. outputRec->status = flBadParameter;
  286. break;
  287. }
  288. return outputRec->status;
  289. }
  290. case FL_IOCTL_CUSTOMER_ID:
  291. {
  292. flCustomerIdOutput FAR1 *outputRec = (flCustomerIdOutput FAR1 *)outputRecord;
  293. ioreq2.irData = outputRec->id;
  294. outputRec->status = flGetCustomerID(&ioreq2);
  295. return outputRec->status;
  296. }
  297. case FL_IOCTL_UNIQUE_ID:
  298. {
  299. flUniqueIdOutput FAR1 *outputRec = (flUniqueIdOutput FAR1 *)outputRecord;
  300. ioreq2.irData = outputRec->id;
  301. outputRec->status = flGetUniqueID(&ioreq2);
  302. return outputRec->status;
  303. }
  304. #endif /* HW_OTP */
  305. case FL_IOCTL_NUMBER_OF_PARTITIONS:
  306. {
  307. flCountPartitionsOutput FAR1 *outputRec = (flCountPartitionsOutput FAR1 *)outputRecord;
  308. outputRec->status = flCountVolumes(&ioreq2);
  309. outputRec->noOfPartitions = (byte) ioreq2.irFlags;
  310. return outputRec->status;
  311. }
  312. #ifdef LOW_LEVEL
  313. case FL_IOCTL_INQUIRE_CAPABILITIES:
  314. {
  315. flCapabilityInput FAR1 *inputRec = (flCapabilityInput FAR1 *)inputRecord;
  316. flCapabilityOutput FAR1 *outputRec = (flCapabilityOutput FAR1 *)outputRecord;
  317. ioreq2.irLength = inputRec->capability;
  318. outputRec->status = flInquireCapabilities(&ioreq2);
  319. outputRec->capability = ioreq2.irLength;
  320. return outputRec->status;
  321. }
  322. #endif /* LOW_LEVEL */
  323. #ifdef ENVIRONMENT_VARS
  324. /*
  325. case FL_IOCTL_EXTENDED_ENVIRONMENT_VARIABLES:
  326. {
  327. flEnvVarsInput FAR1 *inputRec = (flEnvVarsInput FAR1 *)inputRecord;
  328. flEnvVarsOutput FAR1 *outputRec = (flEnvVarsOutput FAR1 *)outputRecord;
  329. outputRec->status = flSetEnv(inputRec->varName , inputRec->varValue, &(outputRec->prevValue));
  330. return outputRec->status;
  331. }
  332. */
  333. #endif /* ENVIRONMENT_VARS */
  334. #ifdef LOW_LEVEL
  335. #ifdef WRITE_EXB_IMAGE
  336. case FL_IOCTL_PLACE_EXB_BY_BUFFER:
  337. {
  338. flPlaceExbInput FAR1 *inputRec = (flPlaceExbInput FAR1 *)inputRecord;
  339. flOutputStatusRecord FAR1 *outputRec = (flOutputStatusRecord FAR1 *)outputRecord;
  340. ioreq2.irData = inputRec->buf;
  341. ioreq2.irLength = inputRec->bufLen;
  342. ioreq2.irWindowBase = inputRec->exbWindow;
  343. ioreq2.irFlags = inputRec->exbFlags;
  344. outputRec->status = flPlaceExbByBuffer(&ioreq2);
  345. return outputRec->status;
  346. }
  347. #endif /* WRITE_EXB_IMAGE */
  348. case FL_IOCTL_EXTENDED_WRITE_IPL:
  349. {
  350. flIplInput FAR1 *inputRec = (flIplInput FAR1 *)inputRecord;
  351. flOutputStatusRecord FAR1 *outputRec = (flOutputStatusRecord FAR1 *)outputRecord;
  352. ioreq2.irData = inputRec->buf;
  353. ioreq2.irLength = inputRec->bufLen;
  354. outputRec->status = flWriteIPL(&ioreq2);
  355. return outputRec->status;
  356. }
  357. case FL_IOCTL_DEEP_POWER_DOWN_MODE:
  358. {
  359. flPowerDownInput FAR1 *inputRec = (flPowerDownInput FAR1 *)inputRecord;
  360. flOutputStatusRecord FAR1 *outputRec = (flOutputStatusRecord FAR1 *)outputRecord;
  361. ioreq2.irFlags = inputRec->state;
  362. outputRec->status = flDeepPowerDownMode(&ioreq2);
  363. return outputRec->status;
  364. }
  365. #endif /* LOW_LEVEL */
  366. #ifdef ABS_READ_WRITE
  367. #ifndef FL_READ_ONLY
  368. case FL_IOCTL_DELETE_SECTORS:
  369. {
  370. flDeleteSectorsInput FAR1 *inputRec = (flDeleteSectorsInput FAR1 *)inputRecord;
  371. flOutputStatusRecord FAR1 *outputRec = (flOutputStatusRecord FAR1 *)outputRecord;
  372. ioreq2.irSectorNo = inputRec->firstSector;
  373. ioreq2.irSectorCount = inputRec->numberOfSectors;
  374. outputRec->status = flAbsDelete(&ioreq2);
  375. return outputRec->status;
  376. }
  377. #endif /* FL_READ_ONLY */
  378. case FL_IOCTL_READ_SECTORS:
  379. {
  380. flReadWriteInput FAR1 *inputRec = (flReadWriteInput FAR1 *)inputRecord;
  381. flReadWriteOutput FAR1 *outputRec = (flReadWriteOutput FAR1 *)outputRecord;
  382. ioreq2.irSectorNo = inputRec->firstSector;
  383. ioreq2.irSectorCount = inputRec->numberOfSectors;
  384. ioreq2.irData = inputRec->buf;
  385. outputRec->status = flAbsRead(&ioreq2);
  386. outputRec->numberOfSectors = ioreq2.irSectorCount;
  387. return outputRec->status;
  388. }
  389. #ifndef FL_READ_ONLY
  390. case FL_IOCTL_WRITE_SECTORS:
  391. {
  392. flReadWriteInput FAR1 *inputRec = (flReadWriteInput FAR1 *)inputRecord;
  393. flReadWriteOutput FAR1 *outputRec = (flReadWriteOutput FAR1 *)outputRecord;
  394. ioreq2.irSectorNo = inputRec->firstSector;
  395. ioreq2.irSectorCount = inputRec->numberOfSectors;
  396. ioreq2.irData = inputRec->buf;
  397. outputRec->status = flAbsWrite(&ioreq2);
  398. outputRec->numberOfSectors = ioreq2.irSectorCount;
  399. return outputRec->status;
  400. }
  401. #endif /* FL_READ_ONLY */
  402. #endif /* ABS_READ_WRITE */
  403. default:
  404. return flBadParameter;
  405. }
  406. }
  407. #endif /* IOCTL_INTERFACE */