doscall2.pas 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2014 by the Free Pascal development team.
  4. Additional OS/2 API functions implemented in DOSCALL1.DLL:
  5. - File handling (64-bit functions available in WSeB/MCP/eCS and
  6. protected access to file handles as available in OS/2 2.1+)
  7. - Certain SMP related functions for querying and setting status
  8. of processors and thread and system affinity (available
  9. in SMP-ready versions of OS/2 kernels)
  10. - Support for working with extended LIBPATH (available in
  11. OS/2 Warp 4.0 and higher).
  12. Availability of individual functions is checked dynamically during
  13. initialization and fake (simulated) functions are used if running
  14. under an OS/2 version not providing the respective functionality.
  15. See the file COPYING.FPC, included in this distribution,
  16. for details about the copyright.
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  20. **********************************************************************}
  21. unit DosCall2;
  22. {***************************************************************************}
  23. interface
  24. {***************************************************************************}
  25. uses
  26. DosCalls, Strings;
  27. const
  28. (* Status in DosGet/SetProcessorStatus *)
  29. PROC_OFFLINE = 0; (* Processor is offline *)
  30. PROC_ONLINE = 1; (* Processor is online *)
  31. (* Scope in DosQueryThreadAffinity *)
  32. AFNTY_THREAD = 0; (* Return the current threads processor affinity mask. *)
  33. AFNTY_SYSTEM = 1; (* Return the system's current capable processor affinity
  34. mask. *)
  35. (* Flags in DosQuery/SetExtLibPath *)
  36. BEGIN_LIBPATH = 1; (* The new path is searched before the LIBPATH. *)
  37. END_LIBPATH = 2; (* The new path is searched after the LIBPATH. *)
  38. type
  39. TFileLockL = record
  40. case boolean of
  41. false:
  42. (Offset: int64; (* Offset to beginning of the lock (or unlock) range. *)
  43. Range: int64); (* Length of the lock (or unlock) range in bytes. *)
  44. (* Length of 0 => locking (or unlocking) not required. *)
  45. true:
  46. (lOffset: int64;
  47. lRange: int64);
  48. end;
  49. PFileLockL = ^TFileLockL;
  50. TMPAffinity = record
  51. Mask: array [0..1] of cardinal;
  52. end;
  53. PMPAffinity = ^TMPAffinity;
  54. function DosOpenL (FileName: PChar; var Handle: THandle;
  55. var Action: cardinal; InitSize: int64;
  56. Attrib, OpenFlags, FileMode: cardinal;
  57. EA: pointer): cardinal; cdecl;
  58. function DosSetFilePtrL (Handle: THandle; Pos: int64; Method: cardinal;
  59. var PosActual: int64): cardinal; cdecl;
  60. function DosSetFileSizeL (Handle: THandle; Size: int64): cardinal; cdecl;
  61. function DosProtectOpen (FileName: PChar; var Handle: longint;
  62. var Action: longint; InitSize, Attrib,
  63. OpenFlags, OpenMode: longint; ea: PEAOp2;
  64. var FileHandleLockID: cardinal): cardinal; cdecl;
  65. function DosProtectOpen (const FileName: string; var Handle: longint;
  66. var Action: longint; InitSize, Attrib,
  67. OpenFlags, OpenMode: longint; ea: PEAOp2;
  68. var FileHandleLockID: cardinal): cardinal;
  69. function DosProtectOpen (const FileName: string; var Handle: THandle;
  70. var Action: cardinal; InitSize, Attrib,
  71. OpenFlags, OpenMode: cardinal; ea: PEAOp2;
  72. var FileHandleLockID: cardinal): cardinal;
  73. function DosProtectRead (Handle: longint; var Buffer; Count: longint;
  74. var ActCount: longint; FileHandleLockID: cardinal): cardinal; cdecl;
  75. function DosProtectWrite (Handle: longint; const Buffer; Count: longint;
  76. var ActCount: longint;
  77. FileHandleLockID: cardinal): cardinal; cdecl;
  78. function DosProtectSetFilePtr (Handle: longint; Pos, Method: longint;
  79. var PosActual: longint;
  80. FileHandleLockID: cardinal): cardinal; cdecl;
  81. function DosProtectSetFilePtr (Handle: THandle; Pos: longint;
  82. FileHandleLockID: cardinal): cardinal;
  83. function DosProtectGetFilePtr (Handle: longint;
  84. var PosActual: longint; FileHandleLockID: cardinal): cardinal;
  85. function DosProtectGetFilePtr (Handle: THandle;
  86. var PosActual: cardinal; FileHandleLockID: cardinal): cardinal;
  87. function DosProtectEnumAttribute (Handle: THandle; Entry: cardinal; var Buf;
  88. BufSize: cardinal; var Count: cardinal;
  89. InfoLevel: cardinal;
  90. FileHandleLockID: cardinal): cardinal;
  91. function DosProtectEnumAttribute (const FileName: string; Entry: cardinal;
  92. var Buf; BufSize: cardinal;
  93. var Count: cardinal; InfoLevel: cardinal;
  94. FileHandleLockID: cardinal): cardinal;
  95. function DosProtectOpen (FileName: PChar; var Handle: THandle;
  96. var Action: cardinal; InitSize, Attrib,
  97. OpenFlags, OpenMode: cardinal; ea: PEAOp2;
  98. var FileHandleLockID: cardinal): cardinal; cdecl;
  99. function DosProtectClose (Handle: THandle;
  100. FileHandleLockID: cardinal): cardinal; cdecl;
  101. function DosProtectRead (Handle: THandle; var Buffer; Count: cardinal;
  102. var ActCount: cardinal; FileHandleLockID: cardinal): cardinal; cdecl;
  103. function DosProtectWrite (Handle: THandle; const Buffer; Count: cardinal;
  104. var ActCount: cardinal;
  105. FileHandleLockID: cardinal): cardinal; cdecl;
  106. function DosProtectSetFilePtr (Handle: THandle; Pos: longint;
  107. Method: cardinal; var PosActual: cardinal;
  108. FileHandleLockID: cardinal): cardinal; cdecl;
  109. function DosProtectSetFileSize (Handle: THandle; Size: cardinal;
  110. FileHandleLockID: cardinal): cardinal; cdecl;
  111. function DosProtectQueryFHState (Handle: THandle; var FileMode: cardinal;
  112. FileHandleLockID: cardinal): cardinal; cdecl;
  113. function DosProtectSetFHState (Handle: THandle; FileMode: cardinal;
  114. FileHandleLockID: cardinal): cardinal; cdecl;
  115. function DosProtectQueryFileInfo (Handle: THandle; InfoLevel: cardinal;
  116. AFileStatus: PFileStatus; FileStatusLen: cardinal;
  117. FileHandleLockID: cardinal): cardinal; cdecl;
  118. function DosProtectSetFileInfo (Handle: THandle; InfoLevel: cardinal;
  119. AFileStatus: PFileStatus; FileStatusLen: cardinal;
  120. FileHandleLockID: cardinal): cardinal; cdecl;
  121. function DosProtectEnumAttribute (RefType: cardinal; AFile: pointer;
  122. Entry: cardinal; var Buf; BufSize: cardinal;
  123. var Count: cardinal; InfoLevel: cardinal;
  124. FileHandleLockID: cardinal): cardinal; cdecl;
  125. function DosProtectSetFileLocks (Handle: THandle;
  126. var Unlock, Lock: TFileLock;
  127. Timeout, Flags: cardinal;
  128. FileHandleLockID: cardinal): cardinal; cdecl;
  129. (*
  130. DosCancelLockRequestL cancels an outstanding DosSetFileLocksL request.
  131. If two threads in a process are waiting on a lock file range, and another
  132. thread issues DosCancelLockRequestL for that lock file range, then both
  133. waiting threads are released.
  134. Not all file-system drivers (FSDs) can cancel an outstanding lock request.
  135. Local Area Network (LAN) servers cannot cancel an outstanding lock request
  136. if they use a version of the operating system prior to OS/2 Version 2.00.
  137. Possible results:
  138. 0 No_Error
  139. 6 Error_Invalid_Handle
  140. 87 Error_Invalid_Parameter
  141. 173 Error_Cancel_Violation
  142. Handle = File handle used in the DosSetFileLocksL function
  143. that is to be cancelled.
  144. Lock = Specification of the lock request to be cancelled.
  145. *)
  146. function DosCancelLockRequestL (Handle: THandle;
  147. var Lock: TFileLockL): cardinal; cdecl;
  148. (*
  149. DosProtectSetFileLocksL locks and unlocks a range of an open file.
  150. Parameters:
  151. Handle = file handle
  152. Unlock = record containing the offset and length of a range to be unlocked
  153. Lock = record containing the offset and length of a range to be locked
  154. Timeout = the maximum time that the process is to wait for the requested locks
  155. (in milliseconds)
  156. Flags = bit mask specifying action to be taken.
  157. Bits 31..2 are reserved.
  158. Bit 1 (Atomic) means request for atomic locking - if the bit is set
  159. and the lock range is equal to the unlock range, an atomic lock occurs.
  160. If this bit is set to 1 and the lock range is not equal to the unlock
  161. range, an error is returned. If this bit is set to 0, then the lock
  162. may or may not occur atomically with the unlock.
  163. Bit 0 (Share) defines the type of access that other processes may have
  164. to the file range that is being locked. If this bit is set to 0
  165. (default), other processes have no access to the locked file range.
  166. The current process has exclusive access to the locked file range,
  167. which must not overlap any other locked file range. If this bit is set
  168. to 1, the current process and other processes have shared read only
  169. access to the locked file range. A file range with shared access may
  170. overlap any other file range with shared access, but must not overlap
  171. any other file range with exclusive access.
  172. FileHandleLockID = filehandle lockid returned by a previous DosProtectOpenL.
  173. Possible return codes:
  174. 0 NO_ERROR
  175. 6 ERROR_INVALID_HANDLE
  176. 33 ERROR_LOCK_VIOLATION
  177. 36 ERROR_SHARING_BUFFER_EXCEEDED
  178. 87 ERROR_INVALID_PARAMETER
  179. 95 ERROR_INTERRUPT
  180. 174 ERROR_ATOMIC_LOCK_NOT_SUPPORTED
  181. 175 ERROR_READ_LOCKS_NOT_SUPPORTED
  182. Remarks:
  183. DosProtectSetFileLocksL allows a process to lock and unlock a range in a file.
  184. The time during which a file range is locked should be short.
  185. If the lock and unlock ranges are both zero, ERROR_LOCK_VIOLATION is returned
  186. to the caller.
  187. If you only want to lock a file range, set the unlock file offset and the
  188. unlock range length to zero.
  189. If you only want to unlock a file range, set the lock file offset and the lock
  190. range length to zero.
  191. When the Atomic bit of flags is set to 0, and DosProtectSetFileLocksL specifies
  192. a lock operation and an unlock operation, the unlock operation occurs first,
  193. and then the lock operation is performed. If an error occurs during the unlock
  194. operation, an error code is returned and the lock operation is not performed.
  195. If an error occurs during the lock operation, an error code is returned and the
  196. unlock remains in effect if it was successful.
  197. The lock operation is atomic when all of these conditions are met:
  198. - The Atomic bit is set to 1 in flags
  199. - The unlock range is the same as the lock range
  200. - The process has shared access to the file range, and has requested exclusive
  201. access to it; or the process has exclusive access to the file range, and has
  202. requested shared access to it.
  203. Some file system drivers (FSDs) may not support atomic lock operations.
  204. Versions of the operating system prior to OS/2 Version 2.00 do not support
  205. atomic lock operations. If the application receives the error code
  206. ERROR_ATOMIC_LOCK_NOT_SUPPORTED, the application should unlock the file range
  207. and then lock it using a non-atomic operation (with the atomic bit set to 0
  208. in Flags). The application should also refresh its internal buffers before
  209. making any changes to the file.
  210. If you issue DosProtectClose to close a file with locks still in effect,
  211. the locks are released in no defined sequence.
  212. If you end a process with a file open, and you have locks in effect in that
  213. file, the file is closed and the locks are released in no defined sequence.
  214. The locked range can be anywhere in the logical file. Locking beyond the end
  215. of the file is not an error. A file range to be locked exclusively must first
  216. be cleared of any locked file sub-ranges or overlapping locked file ranges.
  217. If you repeat DosProtectSetFileLocksL for the same file handle and file range,
  218. then you duplicate access to the file range. Access to locked file ranges
  219. is not duplicated across DosExecPgm. The proper method of using locks is
  220. to attempt to lock the file range, and to examine the return value.
  221. The following table shows the level of access granted when the accessed file
  222. range is locked with an exclusive lock or a shared lock. Owner refers to
  223. a process that owns the lock. Non-owner refers to a process that does not own
  224. the lock.
  225. Action Exclusive Lock Shared Lock
  226. ===================================================================
  227. Owner read Success Success
  228. -------------------------------------------------------------------
  229. Non-owner Wait for unlock. Return Success
  230. read error code after time-out.
  231. -------------------------------------------------------------------
  232. Owner write Success Wait for unlock. Return
  233. error code after time-out.
  234. -------------------------------------------------------------------
  235. Non-owner Wait for unlock. Return Wait for unlock. Return
  236. write error code after time-out. error code after time-out.
  237. -------------------------------------------------------------------
  238. If only locking is specified, DosProtectSetFileLocksL locks the specified file
  239. range using Lock. If the lock operation cannot be accomplished, an error is
  240. returned, and the file range is not locked.
  241. After the lock request is processed, a file range can be unlocked using the
  242. Unlock parameter of another DosProtectSetFileLocksL request. If unlocking
  243. cannot be accomplished, an error is returned.
  244. Instead of denying read/write access to an entire file by specifying access
  245. and sharing modes with DosProtectOpenL requests, a process attempts to lock
  246. only the range needed for read/write access and examines the error code
  247. returned.
  248. Once a specified file range is locked exclusively, read and write access by
  249. another process is denied until the file range is unlocked. If both unlocking
  250. and locking are specified by DosProtectSetFileLocksL, the unlocking operation
  251. is performed first, then locking is done.
  252. *)
  253. function DosProtectSetFileLocksL (Handle: THandle; var Unlock: TFileLockL;
  254. var Lock: TFileLockL; Timeout: cardinal; Flags: cardinal;
  255. FileHandleLockID: cardinal): cardinal; cdecl;
  256. (*
  257. DosSetFileLocksL locks and unlocks a range of an open file.
  258. Parameters:
  259. Handle = file handle
  260. Unlock = record containing the offset and length of a range to be unlocked
  261. Lock = record containing the offset and length of a range to be locked
  262. Timeout = the maximum time that the process is to wait for the requested locks
  263. (in milliseconds)
  264. Flags = bit mask specifying action to be taken.
  265. Bits 31..2 are reserved.
  266. Bit 1 (Atomic) means request for atomic locking - if the bit is set
  267. and the lock range is equal to the unlock range, an atomic lock occurs.
  268. If this bit is set to 1 and the lock range is not equal to the unlock
  269. range, an error is returned. If this bit is set to 0, then the lock
  270. may or may not occur atomically with the unlock.
  271. Bit 0 (Share) defines the type of access that other processes may have
  272. to the file range that is being locked. If this bit is set to 0
  273. (default), other processes have no access to the locked file range.
  274. The current process has exclusive access to the locked file range,
  275. which must not overlap any other locked file range. If this bit is set
  276. to 1, the current process and other processes have shared read only
  277. access to the locked file range. A file range with shared access may
  278. overlap any other file range with shared access, but must not overlap
  279. any other file range with exclusive access.
  280. Possible return codes:
  281. 0 NO_ERROR
  282. 1 ERROR_INVALID_FUNCTION
  283. 6 ERROR_INVALID_HANDLE
  284. 33 ERROR_LOCK_VIOLATION
  285. 36 ERROR_SHARING_BUFFER_EXCEEDED
  286. 87 ERROR_INVALID_PARAMETER
  287. 95 ERROR_INTERRUPT
  288. 174 ERROR_ATOMIC_LOCK_NOT_SUPPORTED
  289. 175 ERROR_READ_LOCKS_NOT_SUPPORTED
  290. Remarks:
  291. DosSetFileLocksL allows a process to lock and unlock a range in a file. The
  292. time during which a file range is locked should be short.
  293. If the lock and unlock ranges are both zero, ERROR_LOCK_VIOLATION is returned
  294. to the caller.
  295. If you only want to lock a file range, set the unlock file offset and the
  296. unlock range length to zero.
  297. If you only want to unlock a file range, set the lock file offset and the lock
  298. range length to zero.
  299. When the Atomic bit of flags is set to 0, and DosSetFileLocksL specifies a lock
  300. operation and an unlock operation, the unlock operation occurs first, and then
  301. the lock operation is performed. If an error occurs during the unlock
  302. operation, an error code is returned and the lock operation is not performed.
  303. If an error occurs during the lock operation, an error code is returned and the
  304. unlock remains in effect if it was successful.
  305. The lock operation is atomic when all of these conditions are met:
  306. - The Atomic bit is set to 1 in flags
  307. - The unlock range is the same as the lock range
  308. - The process has shared access to the file range, and has requested exclusive
  309. access to it; or the process has exclusive access to the file range, and has
  310. requested shared access to it.
  311. Some file system drivers (FSDs) may not support atomic lock operations.
  312. Versions of the operating system prior to OS/2 Version 2.00 do not support
  313. atomic lock operations. If the application receives the error code
  314. ERROR_ATOMIC_LOCK_NOT_SUPPORTED, the application should unlock the file range
  315. and then lock it using a non-atomic operation (with the atomic bit set to 0 in
  316. flags). The application should also refresh its internal buffers before making
  317. any changes to the file.
  318. If you issue DosClose to close a file with locks still in effect, the locks are
  319. released in no defined sequence.
  320. If you end a process with a file open, and you have locks in effect in that
  321. file, the file is closed and the locks are released in no defined sequence.
  322. The locked range can be anywhere in the logical file. Locking beyond the end of
  323. the file is not an error. A file range to be locked exclusively must first be
  324. cleared of any locked file subranges or overlapping locked file ranges.
  325. If you repeat DosSetFileLocksL for the same file handle and file range, then
  326. you duplicate access to the file range. Access to locked file ranges is not
  327. duplicated across DosExecPgm. The proper method of using locks is to attempt to
  328. lock the file range, and to examine the return value.
  329. The following table shows the level of access granted when the accessed file
  330. range is locked with an exclusive lock or a shared lock. Owner refers to
  331. a process that owns the lock. Non-owner refers to a process that does not own
  332. the lock.
  333. Action Exclusive Lock Shared Lock
  334. ===================================================================
  335. Owner read Success Success
  336. -------------------------------------------------------------------
  337. Non-owner Wait for unlock. Return Success
  338. read error code after time-out.
  339. -------------------------------------------------------------------
  340. Owner write Success Wait for unlock. Return
  341. error code after time-out.
  342. -------------------------------------------------------------------
  343. Non-owner Wait for unlock. Return Wait for unlock. Return
  344. write error code after time-out. error code after time-out.
  345. -------------------------------------------------------------------
  346. If only locking is specified, DosSetFileLocksL locks the specified file range
  347. using Lock. If the lock operation cannot be accomplished, an error is
  348. returned, and the file range is not locked.
  349. After the lock request is processed, a file range can be unlocked using the
  350. Unlock parameter of another DosSetFileLocksL request. If unlocking cannot be
  351. accomplished, an error is returned.
  352. Instead of denying read/write access to an entire file by specifying access and
  353. sharing modes with DosOpenL requests, a process attempts to lock only the range
  354. needed for read/write access and examines the error code returned.
  355. Once a specified file range is locked exclusively, read and write access by
  356. another process is denied until the file range is unlocked. If both unlocking
  357. and locking are specified by DosSetFileLocksL, the unlocking operation is
  358. performed first, then locking is done.
  359. *)
  360. function DosSetFileLocksL (Handle: THandle; var Unlock: TFileLockL;
  361. var Lock: TFileLockL; Timeout: cardinal; Flags: cardinal): cardinal; cdecl;
  362. (*
  363. DosProtectOpenL opens a new file, an existing file, or a replacement for an
  364. existing file and returns a protected file handle. An open file can have
  365. extended attributes.
  366. Parameters:
  367. FileName = ASCIIZ path name of the file or device to be opened.
  368. Handle = handle for the file is returned here.
  369. Action = value that specifies the action taken by DosProtectOpenL is returned
  370. here; if DosProtectOpenL fails, this value has no meaning, otherwise,
  371. it is one of the following values:
  372. 1 FILE_EXISTED - file already existed.
  373. 2 FILE_CREATED - file was created.
  374. 3 FILE_TRUNCATED - file existed and was changed to a given size (file was
  375. replaced).
  376. InitSize = new logical size of the file (end of data, EOD), in bytes; this
  377. parameter is significant only when creating a new file or replacing
  378. an existing one. Otherwise, it is ignored. It is an error to create
  379. or replace a file with a nonzero length if the OpenMode
  380. Access-Mode flag is set to read-only.
  381. Attrib = file attributes; this parameter contains the following bit fields:
  382. Bits Description
  383. 31..6 - reserved, must be 0.
  384. 5 FILE_ARCHIVED (0x00000020) - file has been archived.
  385. 4 FILE_DIRECTORY (0x00000010) - file is a subdirectory.
  386. 3 - reserved, must be 0.
  387. 2 FILE_SYSTEM (0x00000004) - file is a system file.
  388. 1 FILE_HIDDEN (0x00000002) - file is hidden and does not appear in
  389. a directory listing.
  390. 0 FILE_READONLY (0x00000001) - file can be read from, but not written
  391. to.
  392. 0 FILE_NORMAL (0x00000000) - file can be read from or written to.
  393. File attributes apply only if the file is created. These bits may be set
  394. individually or in combination. For example, an attribute value of 0x00000021
  395. (bits 5 and 0 set to 1) indicates a read-only file that has been archived.
  396. OpenFlags = the action to be taken depending on whether the file exists or
  397. does not exist. This parameter contains the following bit fields:
  398. Bits Description
  399. 31..8 - reserved, must be 0.
  400. 7..4 - the following flags apply if the file does not exist:
  401. 0000 OPEN_ACTION_FAIL_IF_NEW
  402. Open an existing file; fail if the file does not exist.
  403. 0001 OPEN_ACTION_CREATE_IF_NEW
  404. Create the file if the file does not exist.
  405. 3..0 The following flags apply if the file does not exist:
  406. 0000 OPEN_ACTION_FAIL_IF_EXISTS
  407. Open the file; fail if the file already exists.
  408. 0001 OPEN_ACTION_OPEN_IF_EXISTS
  409. Open the file if it already exists.
  410. 0010 OPEN_ACTION_REPLACE_IF_EXISTS
  411. Replace the file if it already exists.
  412. OpenMode = the mode of the open function. This parameter contains the
  413. following bit fields:
  414. Bits Description
  415. 31 - reserved, must be zero.
  416. 30 OPEN_FLAGS_PROTECTED_HANDLE (0x40000000) - protected file handle flag.
  417. 0 - unprotected Handle
  418. 1 - protected Handle
  419. Protected handle requires the FileHandleLockID to be specified on subsequent
  420. DosProtectxxxx calls.
  421. Unprotected handle requires the FileHandleLockID value to be specified as
  422. zero on subsequent DosProtectxxxx calls. An unprotected handle may be used
  423. with the unprotected calls such as DosRead and DosWrite.
  424. 29 OPEN_SHARE_DENYLEGACY (0x10000000)
  425. Deny read/write access by the DosOpen command:
  426. 0 - allow read/write access by the DosOpen command.
  427. 1 - deny read/write access by the DosOpen command.
  428. A file opened by DosOpenL will not be allowed to grow larger than 2GB while
  429. that same file is open via a legacy DosOpen call. Setting this bit to 1 will
  430. prevent access by the obsolete DosOpen API and ensure that no error will
  431. occur when growing the file.
  432. 28..16 - reserved, must be zero.
  433. 15 OPEN_FLAGS_DASD (0x00008000)
  434. Direct Open flag:
  435. 0 - FileName represents a file to be opened normally.
  436. 1 - FileName is drive (such as C or A), and represents a mounted
  437. disk or diskette volume to be opened for direct access.
  438. 14 OPEN_FLAGS_WRITE_THROUGH (0x00004000)
  439. Write-Through flag:
  440. 0 - writes to the file may go through the file-system driver's
  441. cache; the file-system driver writes the sectors when the
  442. cache is full or the file is closed.
  443. 1 - writes to the file may go through the file-system driver's
  444. cache, but the sectors are written (the actual file I/O
  445. operation is completed) before a synchronous write call
  446. returns. This state of the file defines it as a synchronous
  447. file. For synchronous files, this bit must be set, because the
  448. data must be written to the medium for synchronous write
  449. operations.
  450. This bit flag is not inherited by child processes.
  451. 13 OPEN_FLAGS_FAIL_ON_ERROR (0x00002000)
  452. Fail-Errors flag. Media I/O errors are handled as follows:
  453. 0 - reported through the system critical-error handler.
  454. 1 - reported directly to the caller by way of a return code.
  455. Media I/O errors generated through Category 08h Logical Disk Control IOCtl
  456. Commands always get reported directly to the caller by way of return code.
  457. The Fail-Errors function applies only to non-IOCtl handle-based file I/O
  458. calls.
  459. This flag bit is not inherited by child processes.
  460. 12 OPEN_FLAGS_NO_CACHE (0x00001000)
  461. No-Cache/Cache flag:
  462. 0 - the file-system driver should place data from I/O operations
  463. into its cache.
  464. 1 - I/O operations to the file need not be done through the
  465. file-system driver's cache.
  466. The setting of this bit determines whether file-system drivers should place
  467. data into the cache. Like the write-through bit, this is a per-handle bit,
  468. and is not inherited by child processes.
  469. 11 - reserved; must be 0.
  470. 10..8 - the locality of reference flags contain information about how the
  471. application is to get access to the file. The values are as
  472. follows:
  473. 000 OPEN_FLAGS_NO_LOCALITY (0x00000000)
  474. No locality known.
  475. 001 OPEN_FLAGS_SEQUENTIAL (0x00000100)
  476. Mainly sequential access.
  477. 010 OPEN_FLAGS_RANDOM (0x00000200)
  478. Mainly random access.
  479. 011 OPEN_FLAGS_RANDOMSEQUENTIAL (0x00000300)
  480. Random with some locality.
  481. 7 OPEN_FLAGS_NOINHERIT (0x00000080)
  482. Inheritance flag:
  483. 0 - file handle is inherited by a process created from a call to
  484. DosExecPgm.
  485. 1 - file handle is private to the current process.
  486. This bit is not inherited by child processes.
  487. 6..4 Sharing Mode flags; this field defines any restrictions to file
  488. access placed by the caller on other processes. The values are as
  489. follows:
  490. 001 OPEN_SHARE_DENYREADWRITE (0x00000010)
  491. Deny read write access.
  492. 010 OPEN_SHARE_DENYWRITE (0x00000020)
  493. Deny write access.
  494. 011 OPEN_SHARE_DENYREAD (0x00000030)
  495. Deny read access.
  496. 100 OPEN_SHARE_DENYNONE (0x00000040)
  497. Deny neither read nor write access (deny none).
  498. Any other value is invalid.
  499. 3 Reserved; must be 0.
  500. 2..0 Access-Mode flags. This field defines the file access required by the
  501. caller. The values are as follows:
  502. 000 OPEN_ACCESS_READONLY (0x00000000)
  503. Read-only access
  504. 001 OPEN_ACCESS_WRITEONLY (0x00000001)
  505. Write-only access
  506. 010 OPEN_ACCESS_READWRITE (0x00000002)
  507. Read/write access.
  508. Any other value is invalid, as are any other combinations.
  509. File sharing requires the cooperation of sharing processes. This cooperation is
  510. communicated through sharing and access modes. Any sharing restrictions placed
  511. on a file opened by a process are removed when the process closes the file with
  512. a DosClose request.
  513. Sharing Mode:
  514. Specifies the type of file access that other processes may have. For example,
  515. if other processes can continue to read the file while your process is
  516. operating on it, specify Deny Write. The sharing mode prevents other processes
  517. from writing to the file but still allows them to read it.
  518. Access Mode:
  519. Specifies the type of file access (access mode) needed by your process. For
  520. example, if your process requires read/write access, and another process has
  521. already opened the file with a sharing mode of Deny None, your DosProtectOpenL
  522. request succeeds. However, if the file is open with a sharing mode of Deny
  523. Write, the process is denied access.
  524. If the file is inherited by a child process, all sharing and access
  525. restrictions also are inherited.
  526. If an open file handle is duplicated by a call to DosDupHandle, all sharing and
  527. access restrictions also are duplicated.
  528. EA = pointer to an extended attribute buffer. The address of the
  529. extended-attribute buffer, which contains an EAOP2 structure. The
  530. fpFEA2List field in the EAOP2 structure points to a data area where the
  531. relevant FEA2 list is to be found. The fpGEA2List and oError fields are
  532. ignored.
  533. Output fpGEA2List and fpFEA2List are unchanged. The area that fpFEA2List points
  534. to is unchanged. If an error occurred during the set, oError is the offset of
  535. the FEA2 entry where the error occurred. The return code from DosProtectOpenL
  536. is the error code for that error condition. If no error occurred, oError is
  537. undefined.
  538. EA is nil, then no extended attributes are defined for the file. If extended
  539. attributes are not to be defined or modified, the pointer EA must be set to
  540. nil.
  541. FileHandleLockID = 32-bit LockID for the file handle is returned here.
  542. Possible return codes:
  543. 0 NO_ERROR
  544. 2 ERROR_FILE_NOT_FOUND
  545. 3 ERROR_PATH_NOT_FOUND
  546. 4 ERROR_TOO_MANY_OPEN_FILES
  547. 5 ERROR_ACCESS_DENIED
  548. 12 ERROR_INVALID_ACCESS
  549. 26 ERROR_NOT_DOS_DISK
  550. 32 ERROR_SHARING_VIOLATION
  551. 36 ERROR_SHARING_BUFFER_EXCEEDED
  552. 82 ERROR_CANNOT_MAKE
  553. 87 ERROR_INVALID_PARAMETER
  554. 99 ERROR_DEVICE_IN_USE
  555. 108 ERROR_DRIVE_LOCKED
  556. 110 ERROR_OPEN_FAILED
  557. 112 ERROR_DISK_FULL
  558. 206 ERROR_FILENAME_EXCED_RANGE
  559. 231 ERROR_PIPE_BUSY
  560. Remarks:
  561. A successful DosProtectOpenL request returns a handle and a 32-bit LockID for
  562. accessing the file. The read/write pointer is set at the first byte of the
  563. file. The position of the pointer can be changed with DosProtectSetFilePtrL or
  564. by read and write operations on the file.
  565. The file s date and time can be queried with DosProtectQueryFileInfo. They are
  566. set with DosProtectSetFileInfo.
  567. The read-only attribute of a file can be set with the ATTRIB command.
  568. ulAttribute cannot be set to Volume Label. To set volume-label information,
  569. issue DosProtectSetFileInfo with a logical drive number. Volume labels cannot
  570. be opened.
  571. InitSize affects the size of the file only when the file is new or is
  572. a replacement. If an existing file is opened, cbFile is ignored. To change the
  573. size of the existing file, issue DosProtectSetFileSizeL.
  574. The value in InitSize is a recommended size. If the full size cannot be
  575. allocated, the open request may still succeed. The file system makes
  576. a reasonable attempt to allocate the new size in an area that is as nearly
  577. contiguous as possible on the medium. When the file size is extended, the
  578. values of the new bytes are undefined.
  579. The Direct Open bit provides direct access to an entire disk or diskette
  580. volume, independent of the file system. This mode of opening the volume that is
  581. currently on the drive returns a handle to the calling function; the handle
  582. represents the logical volume as a single file. The calling function specifies
  583. this handle with a DosDevIOCtl Category 8, DSK_LOCKDRIVE request to prevent
  584. other processes from accessing the logical volume. When you are finished using
  585. the logical volume, issue a DosDevIOCtl Category 8, DSK_UNLOCKDRIVE request to
  586. allow other processes to access the logical volume.
  587. The file-handle state bits can be set by DosProtectOpenL and
  588. DosProtectSetFHState. An application can query the file-handle state bits, as
  589. well as the rest of the Open Mode field, by issuing DosProtectQueryFHState.
  590. You can use an TEAOP2 structure to set extended attributes in EA when creating
  591. a file, replacing an existing file, or truncating an existing file. No extended
  592. attributes are set when an existing file is just opened.
  593. A replacement operation is logically equivalent to atomically deleting and
  594. re-creating the file. This means that any extended attributes associated with
  595. the file also are deleted before the file is re-created.
  596. The FileHandleLockID returned is required on each of the DosProtectxxx
  597. functions. An incorrect pfhFileHandleLockID on subsequent DosProtectxxx calls
  598. results in an ERROR_ACCESS_DENIED return code.
  599. The DosProtectxxx functions can be used with a NULL filehandle LockID, if the
  600. subject filehandle was obtained from DosOpen.
  601. *)
  602. function DosProtectOpenL (FileName: PChar; var Handle: THandle;
  603. var Action: cardinal; InitSize: int64; Attrib,
  604. OpenFlags, OpenMode: cardinal; EA: PEAOp2;
  605. var FileHandleLockID: cardinal): cardinal; cdecl;
  606. (*
  607. DosProtectSetFilePtrL moves the read or write pointer according to the type
  608. of move specified.
  609. Parameters:
  610. Handle = the handle returned by a previous DosOpenL function.
  611. Pos = The signed distance (offset) to move, in bytes.
  612. Method = The method of moving - location in the file at which the read/write
  613. pointer starts before adding the Pos offset. The values and their
  614. meanings are as shown in the following list:
  615. 0 FILE_BEGIN - move the pointer from the beginning of the file.
  616. 1 FILE_CURRENT - move the pointer from the current location of the
  617. read/write pointer.
  618. 2 FILE_END - move the pointer from the end of the file; use this method
  619. to determine a file's size.
  620. PosActual = address of the new pointer location.
  621. FileHandleLockID = The filehandle lockid returned by a previous
  622. DosProtectOpenL.
  623. Possible return codes:
  624. 0 NO_ERROR
  625. 1 ERROR_INVALID_FUNCTION
  626. 6 ERROR_INVALID_HANDLE
  627. 132 ERROR_SEEK_ON_DEVICE
  628. 131 ERROR_NEGATIVE_SEEK
  629. 130 ERROR_DIRECT_ACCESS_HANDLE
  630. Remarks:
  631. The read/write pointer in a file is a signed 64-bit number. A negative value
  632. for Pos moves the pointer backward in the file; a positive value moves it
  633. forward. DosProtectSetFilePtrL cannot be used to move to a negative position in
  634. the file.
  635. DosProtectSetFilePtrL cannot be used for a character device or pipe.
  636. *)
  637. function DosProtectSetFilePtrL (Handle: THandle; Pos: int64;
  638. Method: cardinal; var PosActual: int64;
  639. FileHandleLockID: cardinal): cardinal; cdecl;
  640. (*
  641. DosProtectSetFileSizeL changes the size of a file.
  642. Parameters:
  643. Handle = handle of the file whose size to be changed.
  644. Size = new size, in bytes, of the file.
  645. FileHandleLockID = the filehandle lockid obtained from DosProtectOpenL.
  646. Possible return codes:
  647. 0 NO_ERROR
  648. 5 ERROR_ACCESS_DENIED
  649. 6 ERROR_INVALID_HANDLE
  650. 26 ERROR_NOT_DOS_DISK
  651. 33 ERROR_LOCK_VIOLATION
  652. 87 ERROR_INVALID_PARAMETER
  653. 112 ERROR_DISK_FULL
  654. Remarks:
  655. When DosProtectSetFileSizeL is issued, the file must be open in a mode that
  656. allows write access.
  657. The size of the open file can be truncated or extended. If the file size is
  658. being extended, the file system tries to allocate additional bytes in
  659. a contiguous (or nearly contiguous) space on the medium. The values of the new
  660. bytes are undefined.
  661. *)
  662. function DosProtectSetFileSizeL (Handle: THandle; Size: int64;
  663. FileHandleLockID: cardinal): cardinal; cdecl;
  664. (*
  665. DosGetProcessorStatus allows checking status of individual processors
  666. in a SMP machine.
  667. Parameters:
  668. ProcID = Procesor ID numbered 1 through n, where there are n processors in
  669. total.
  670. Status = Returned processor status defined as follows:
  671. PROC_OFFLINE 0x00000000 Processor is offline
  672. PROC_ONLINE 0x00000001 Processor is online
  673. Possible return codes:
  674. 0 NO_ERROR
  675. 87 ERROR_INVALID_PARAMETER
  676. *)
  677. function DosGetProcessorStatus (ProcID: cardinal;
  678. var Status: cardinal): cardinal; cdecl;
  679. (*
  680. DosSetProcessorStatus sets the ONLINE or OFFLINE status of a processor on
  681. an SMP system. The processor status may be queried using DosGetProcessorStatus.
  682. ONLINE status implies the processor is available for running work. OFFLINE
  683. status implies the processor is not available for running work. The processor
  684. that executes DosSetProcessorStatus must be ONLINE.
  685. Parameters:
  686. ProcID = Processor ID numbered from 1 through n, where there are n processors
  687. in total.
  688. Status = Requested processor status defined as follows:
  689. PROC_OFFLINE 0x00000000 Processor is offline.
  690. PROC_ONLINE 0x00000001 Processor is online.
  691. Possible return codes:
  692. 0 NO_ERROR
  693. 87 ERROR_INVALID_PARAMETER
  694. *)
  695. function DosSetProcessorStatus (ProcID: cardinal;
  696. Status: cardinal): cardinal; cdecl;
  697. (*
  698. DosQueryThreadAffinity allows a thread to inquire for the current thread's
  699. processor affinity mask and the system's capable processor affinity mask.
  700. Parameters:
  701. Scope = Scope of the query defined by one of the following values:
  702. AFNTY_THREAD Return the current threads processor affinity mask.
  703. AFNTY_SYSTEM Return the system's current capable processor affinity mask.
  704. AffinityMask = Affinity mask is returned here; processors 0..31 are in Mask [0]
  705. and processors 32..63 are in Mask [1].
  706. Possible return codes:
  707. 13 ERROR_INVALID_DATA
  708. 87 ERROR_INVALID_PARAMETER
  709. *)
  710. function DosQueryThreadAffinity (Scope: cardinal;
  711. var AffinityMask: TMPAffinity): cardinal; cdecl;
  712. (*
  713. DosQueryExtLibPath returns the current path to be searched before or after the
  714. system LIBPATH when locating DLLs.
  715. Parameters:
  716. ExtLIBPATH = Buffer for receiving the extended LIBPATH string.
  717. ???
  718. If the buffer pointed to by this parameter is not large enough to hold
  719. the extended LIBPATH or an extended LIBPATH is not currently defined, this
  720. parameter returns a pointer to a NULL string.
  721. ??? How is it detected if the size is not passed???
  722. Flags - flag indicating when the new path is searched - possible values:
  723. BEGIN_LIBPATH - The new path is searched before the LIBPATH.
  724. END_LIBPATH - The new path is searched after the LIBPATH.
  725. Possible return codes:
  726. 0 NO_ERROR
  727. 87 ERROR_INVALID_PARAMETER
  728. 122 ERROR_INSUFFICIENT_BUFER
  729. *)
  730. function DosQueryExtLibPath (ExtLibPath: PChar; Flags: cardinal): cardinal;
  731. cdecl;
  732. (*
  733. DosSetExtLibPath defines the current path to be searched before or after the
  734. system LIBPATH when locating DLLs.
  735. Parameters:
  736. ExtLIBPATH = New extended LIBPATH string. Maximum size is 1024 bytes.
  737. A pointer to a NULL string removes the extended LIBPATH.
  738. Flags = When the new path is searched - possible values:
  739. BEGIN_LIBPATH (1) - the new path is searched before the LIBPATH.
  740. END_LIBPATH (2) - the new path is searched after the LIBPATH.
  741. The LIBPATH string is an environment variable found in the CONFIG.SYS file
  742. consisting of a set of paths. If a fully-qualified path is not specified when
  743. a module is loaded, the system searches these paths to find the DLL.
  744. There are two extended LIBPATH strings, BeginLIBPATH and EndLIBPATH.
  745. BeginLIBPATH is searched before the system LIBPATH, and EndLIBPATH is searched
  746. after both BeginLIBPATH and the system LIBPATH. These extended LIBPATHs can be
  747. set either from the command line using the "SET" command, or by calling
  748. DosSetExtLIBPATH. When DosSetExtLIBPATH is called, all modifications become
  749. specific to that process. Initial settings can be set for all processes in the
  750. system by setting the values in CONFIG.SYS using the "set" command.
  751. Note: The extended LIBPATHs are not true environment variables, and do not
  752. appear when querying the environment.
  753. Every process inherits the settings of BeginLIBPATH and EndLIBPATH from the
  754. process that starts it. If the extended library paths are initialized in
  755. CONFIG.SYS, those extended library paths become the initial settings for new
  756. processes. If a process changes BeginLIBPATH or EndLIBPATH and starts a new
  757. process, the new child process inherits the changed contents. Child processes
  758. that inherit their parent's extended LIBPATHs maintain their own copy.
  759. Modifications made by the parent after the child has been created have no
  760. effect on the children.
  761. This function permits the use of two symbols within the path string:
  762. %BeginLIBPATH% and %EndLIBPATH%. These symbols are replaced with the current
  763. string settings for the extended library paths.
  764. The LIBPATHs strings are only searched when the specified DLL is not currently
  765. loaded. The only way to guarantee that the DLL being used is the correct
  766. version is to set the fully-qualified path in DosLoadModule. When a request is
  767. made to load a module and a path is not specified, the system searches the
  768. paths in the LIBPATH string and uses the first instance of the specified DLL it
  769. finds. If the new paths are added to the search strings, the system does not
  770. check those directories to see if a different version exists. Consequently, if
  771. two processes started from different directories use the same DLL, but
  772. different versions of that DLL exist in both directories, the version of the
  773. DLL loaded by the first process is the one used by both processes. The only way
  774. to prevent this from occurring is to specify the path to the DLL when
  775. DosLoadModule is called.
  776. Consequently, if one process sets its BeginLIBPATH to C:\PROCESS1\DLL and loads
  777. the DLL MYAPP.DLL from that directory, and then a second process sets its
  778. BeginLIBPATH to C:\PROCESS2\DLL and there is for a different version of
  779. MYAPP.DLL in C:\PROCESS2\DLL, the second process will link to the DLL from
  780. C:\PROCESS1\DLL since it was already loaded.
  781. Both BeginLIBPATH and EndLIBPATH can be set from the command line using the SET
  782. command.
  783. Possible return codes:
  784. 0 NO_ERROR
  785. 8 ERROR_NOT_ENOUGH_MEMORY
  786. 87 ERROR_INVALID_PARAMETER
  787. 161 ERROR_BAD_PATHNAME
  788. *)
  789. function DosSetExtLibPath (ExtLibPath: PChar; Flags: cardinal): cardinal;
  790. cdecl;
  791. {***************************************************************************}
  792. implementation
  793. {***************************************************************************}
  794. uses
  795. OS2Def;
  796. function DummyDosCancelLockRequestL (Handle: THandle; var Lock: TFileLockL): cardinal; cdecl;
  797. var
  798. Lock0: TFileLock;
  799. begin
  800. if (Lock.Offset > high (longint)) or (Lock.Range > high (longint)) or
  801. (Lock.Offset < 0) or (Lock.Range < 0) then
  802. DummyDosCancelLockRequestL := Error_Invalid_Parameter
  803. else
  804. begin
  805. Lock0.Offset := longint (Lock.Offset);
  806. Lock0.Range := longint (Lock.Range);
  807. DummyDosCancelLockRequestL := DosCancelLockRequest (Handle, Lock0);
  808. end;
  809. end;
  810. function DummyDosProtectSetFileLocksL (Handle: THandle; var Unlock: TFileLockL;
  811. var Lock: TFileLockL; Timeout: cardinal; Flags: cardinal;
  812. FileHandleLockID: cardinal): cardinal; cdecl;
  813. var
  814. Lock0: TFileLock;
  815. UnLock0: TFileLock;
  816. begin
  817. if (Lock.Offset > high (longint)) or (Lock.Range > high (longint)) or
  818. (Unlock.Offset > high (longint)) or (Unlock.Range > high (longint)) then
  819. DummyDosProtectSetFileLocksL := Error_Invalid_Parameter
  820. else
  821. begin
  822. Lock0.Offset := longint (Lock.Offset);
  823. Lock0.Range := longint (Lock.Range);
  824. Unlock0.Offset := longint (Unlock.Offset);
  825. Unlock0.Range := longint (Lock.Range);
  826. DummyDosProtectSetFileLocksL := DosProtectSetFileLocks (Handle, Unlock0,
  827. Lock0, Timeout, Flags, FileHandleLockID);
  828. end;
  829. end;
  830. function DummyDosSetFileLocksL (Handle: THandle; var Unlock: TFileLockL;
  831. var Lock: TFileLockL; Timeout: cardinal; Flags: cardinal): cardinal; cdecl;
  832. var
  833. Lock0: TFileLock;
  834. UnLock0: TFileLock;
  835. begin
  836. if (Lock.Offset > high (longint)) or (Lock.Range > high (longint)) or
  837. (Lock.Offset < 0) or (Lock.Range < 0) or
  838. (Unlock.Offset < 0) or (Unlock.Range < 0) or
  839. (Unlock.Offset > high (longint)) or (Unlock.Range > high (longint)) then
  840. DummyDosSetFileLocksL := Error_Invalid_Parameter
  841. else
  842. begin
  843. Lock0.Offset := longint (Lock.Offset);
  844. Lock0.Range := longint (Lock.Range);
  845. Unlock0.Offset := longint (Unlock.Offset);
  846. Unlock0.Range := longint (Lock.Range);
  847. DummyDosSetFileLocksL := DosSetFileLocks (Handle, Unlock0, Lock0, Timeout,
  848. Flags);
  849. end;
  850. end;
  851. function DummyDosProtectOpenL (FileName: PChar; var Handle: THandle;
  852. var Action: cardinal; InitSize: int64; Attrib,
  853. OpenFlags, OpenMode: cardinal; EA: PEAOp2;
  854. var FileHandleLockID: cardinal): cardinal; cdecl;
  855. begin
  856. if InitSize > high (longint) then
  857. DummyDosProtectOpenL := Error_Invalid_Parameter
  858. else
  859. DummyDosProtectOpenL := DosProtectOpen (FileName, Handle, Action,
  860. longint (InitSize), Attrib, OpenFlags, OpenMode, EA, FileHandleLockID);
  861. end;
  862. function DummyDosProtectSetFilePtrL (Handle: THandle; Pos: int64;
  863. Method: cardinal; var PosActual: int64;
  864. FileHandleLockID: cardinal): cardinal; cdecl;
  865. var
  866. PosActual0: cardinal;
  867. begin
  868. if (Pos < low (longint)) or (Pos > high (longint)) then
  869. DummyDosProtectSetFilePtrL := Error_Invalid_Parameter
  870. else
  871. begin
  872. DummyDosProtectSetFilePtrL := DosProtectSetFilePtr (Handle, longint (Pos),
  873. Method, PosActual0, FileHandleLockID);
  874. PosActual := PosActual0;
  875. end;
  876. end;
  877. function DummyDosProtectSetFileSizeL (Handle: THandle; Size: int64;
  878. FileHandleLockID: cardinal): cardinal; cdecl;
  879. begin
  880. if (Size > high (cardinal)) then
  881. DummyDosProtectSetFileSizeL := Error_Invalid_Parameter
  882. else
  883. DummyDosProtectSetFileSizeL := DosProtectSetFileSize (Handle,
  884. cardinal (Size), FileHandleLockID);
  885. end;
  886. function DummyDosProtectSetFileLocks (Handle: THandle;
  887. var Unlock, Lock: TFileLock;
  888. Timeout, Flags: cardinal;
  889. FileHandleLockID: cardinal): cardinal; cdecl;
  890. begin
  891. if FileHandleLockID <> 0 then
  892. DummyDosProtectSetFileLocks := Error_Invalid_Parameter
  893. else
  894. DummyDosProtectSetFileLocks := DosSetFileLocks (Handle, Unlock, Lock,
  895. Timeout, Flags);
  896. end;
  897. function DummyDosProtectOpen (FileName: PChar; var Handle: THandle;
  898. var Action: cardinal; InitSize, Attrib,
  899. OpenFlags, OpenMode: cardinal; ea: PEAOp2;
  900. var FileHandleLockID: cardinal): cardinal; cdecl;
  901. begin
  902. DummyDosProtectOpen := DosOpen (FileName, Handle, Action, InitSize, Attrib,
  903. OpenFlags, OpenMode, EA);
  904. FileHandleLockID := 0;
  905. end;
  906. function DummyDosProtectClose (Handle: THandle;
  907. FileHandleLockID: cardinal): cardinal; cdecl;
  908. begin
  909. DummyDosProtectClose := DosClose (Handle);
  910. end;
  911. function DummyDosProtectRead (Handle: THandle; var Buffer; Count: cardinal;
  912. var ActCount: cardinal; FileHandleLockID: cardinal): cardinal; cdecl;
  913. begin
  914. DummyDosProtectRead := DosRead (Handle, Buffer, Count, ActCount);
  915. end;
  916. function DummyDosProtectWrite (Handle: THandle; const Buffer; Count: cardinal;
  917. var ActCount: cardinal;
  918. FileHandleLockID: cardinal): cardinal; cdecl;
  919. begin
  920. DummyDosProtectWrite := DosWrite (Handle, Buffer, Count, ActCount);
  921. end;
  922. function DummyDosProtectSetFilePtr (Handle: THandle; Pos: longint;
  923. Method: cardinal; var PosActual: cardinal;
  924. FileHandleLockID: cardinal): cardinal; cdecl;
  925. begin
  926. DummyDosProtectSetFilePtr := DosSetFilePtr (Handle, Pos, Method, PosActual);
  927. end;
  928. function DummyDosProtectSetFileSize (Handle: THandle; Size: cardinal;
  929. FileHandleLockID: cardinal): cardinal; cdecl;
  930. begin
  931. DummyDosProtectSetFileSize := DosSetFileSize (Handle, Size);
  932. end;
  933. function DummyDosProtectQueryFHState (Handle: THandle; var FileMode: cardinal;
  934. FileHandleLockID: cardinal): cardinal; cdecl;
  935. begin
  936. DummyDosProtectQueryFHState := DosQueryFHState (Handle, FileMode);
  937. end;
  938. function DummyDosProtectSetFHState (Handle: THandle; FileMode: cardinal;
  939. FileHandleLockID: cardinal): cardinal; cdecl;
  940. begin
  941. DummyDosProtectSetFHState := DosSetFHState (Handle, FileMode);
  942. end;
  943. function DummyDosProtectQueryFileInfo (Handle: THandle; InfoLevel: cardinal;
  944. AFileStatus: PFileStatus; FileStatusLen: cardinal;
  945. FileHandleLockID: cardinal): cardinal; cdecl;
  946. begin
  947. DummyDosProtectQueryFileInfo := DosQueryFileInfo (Handle, InfoLevel,
  948. AFileStatus, FileStatusLen);
  949. end;
  950. function DummyDosProtectSetFileInfo (Handle: THandle; InfoLevel: cardinal;
  951. AFileStatus: PFileStatus; FileStatusLen: cardinal;
  952. FileHandleLockID: cardinal): cardinal; cdecl;
  953. begin
  954. DummyDosProtectSetFileInfo := DosSetFileInfo (Handle, InfoLevel,
  955. AFileStatus, FileStatusLen);
  956. end;
  957. function DummyDosProtectEnumAttribute (RefType: cardinal; AFile: pointer;
  958. Entry: cardinal; var Buf; BufSize: cardinal;
  959. var Count: cardinal; InfoLevel: cardinal;
  960. FileHandleLockID: cardinal): cardinal; cdecl;
  961. begin
  962. DummyDosProtectEnumAttribute := DosEnumAttribute (RefType, AFile, Entry,
  963. Buf, BufSize, Count, InfoLevel);
  964. end;
  965. function DummyDosGetProcessorStatus (ProcID: cardinal;
  966. var Status: cardinal): cardinal; cdecl;
  967. begin
  968. if ProcID = 1 then
  969. begin
  970. Status := 1;
  971. DummyDosGetProcessorStatus := No_Error;
  972. end
  973. else
  974. DummyDosGetProcessorStatus := Error_Invalid_Parameter;
  975. end;
  976. function DummyDosSetProcessorStatus (ProcID: cardinal;
  977. Status: cardinal): cardinal; cdecl;
  978. begin
  979. DummyDosSetProcessorStatus := Error_Invalid_Parameter;
  980. end;
  981. function DummyDosQueryThreadAffinity (Scope: cardinal;
  982. var AffinityMask: TMPAffinity): cardinal; cdecl;
  983. begin
  984. DummyDosQueryThreadAffinity := Error_Invalid_Function;
  985. end;
  986. function DummyDosSetThreadAffinity (var AffinityMask: TMPAffinity): cardinal;
  987. cdecl;
  988. begin
  989. DummyDosSetThreadAffinity := Error_Invalid_Function;
  990. end;
  991. function DummyDosQueryExtLibPath (ExtLibPath: PChar;
  992. Flags: cardinal): cardinal; cdecl;
  993. begin
  994. if ExtLibPath <> nil then
  995. begin
  996. ExtLibPath := #0;
  997. DummyDosQueryExtLibPath := No_Error;
  998. end
  999. else
  1000. DummyDosQueryExtLibPath := Error_Invalid_Parameter;
  1001. end;
  1002. function DummyDosSetExtLibPath (ExtLibPath: PChar; Flags: cardinal): cardinal;
  1003. cdecl; inline;
  1004. begin
  1005. DummyDosSetExtLibPath := Error_Not_Enough_Memory;
  1006. end;
  1007. type
  1008. TDosProtectOpen = function (FileName: PChar; var Handle: THandle;
  1009. var Action: cardinal; InitSize, Attrib,
  1010. OpenFlags, OpenMode: cardinal; ea: PEAOp2;
  1011. var FileHandleLockID: cardinal): cardinal; cdecl;
  1012. TDosProtectClose = function (Handle: THandle;
  1013. FileHandleLockID: cardinal): cardinal; cdecl;
  1014. TDosProtectRead = function (Handle: THandle; var Buffer; Count: cardinal;
  1015. var ActCount: cardinal; FileHandleLockID: cardinal): cardinal; cdecl;
  1016. TDosProtectWrite = function (Handle: THandle; const Buffer; Count: cardinal;
  1017. var ActCount: cardinal;
  1018. FileHandleLockID: cardinal): cardinal; cdecl;
  1019. TDosProtectSetFilePtr = function (Handle: THandle; Pos: longint;
  1020. Method: cardinal; var PosActual: cardinal;
  1021. FileHandleLockID: cardinal): cardinal; cdecl;
  1022. TDosProtectSetFileSize = function (Handle: THandle; Size: cardinal;
  1023. FileHandleLockID: cardinal): cardinal; cdecl;
  1024. TDosProtectQueryFHState = function (Handle: THandle; var FileMode: cardinal;
  1025. FileHandleLockID: cardinal): cardinal; cdecl;
  1026. TDosProtectSetFHState = function (Handle: THandle; FileMode: cardinal;
  1027. FileHandleLockID: cardinal): cardinal; cdecl;
  1028. TDosProtectQueryFileInfo = function (Handle: THandle; InfoLevel: cardinal;
  1029. AFileStatus: PFileStatus; FileStatusLen: cardinal;
  1030. FileHandleLockID: cardinal): cardinal; cdecl;
  1031. TDosProtectSetFileInfo = function (Handle: THandle; InfoLevel: cardinal;
  1032. AFileStatus: PFileStatus; FileStatusLen: cardinal;
  1033. FileHandleLockID: cardinal): cardinal; cdecl;
  1034. TDosProtectEnumAttribute = function (RefType: cardinal; AFile: pointer;
  1035. Entry: cardinal; var Buf; BufSize: cardinal;
  1036. var Count: cardinal; InfoLevel: cardinal;
  1037. FileHandleLockID: cardinal): cardinal; cdecl;
  1038. TDosProtectSetFileLocks = function (Handle: THandle;
  1039. var Unlock, Lock: TFileLock;
  1040. Timeout, Flags: cardinal;
  1041. FileHandleLockID: cardinal): cardinal; cdecl;
  1042. TDosCancelLockRequestL = function (Handle: THandle; var Lock: TFileLockL):
  1043. cardinal; cdecl;
  1044. TDosProtectSetFileLocksL = function (Handle: THandle; var Unlock: TFileLockL;
  1045. var Lock: TFileLockL; Timeout: cardinal; Flags: cardinal;
  1046. FileHandleLockID: cardinal): cardinal; cdecl;
  1047. TDosSetFileLocksL = function (Handle: THandle; var Unlock: TFileLockL;
  1048. var Lock: TFileLockL; Timeout: cardinal; Flags: cardinal): cardinal; cdecl;
  1049. TDosProtectOpenL = function (FileName: PChar; var Handle: THandle;
  1050. var Action: cardinal; InitSize: int64; Attrib,
  1051. OpenFlags, OpenMode: cardinal; EA: PEAOp2;
  1052. var FileHandleLockID: cardinal): cardinal; cdecl;
  1053. TDosProtectSetFilePtrL = function (Handle: THandle; Pos: int64;
  1054. Method: cardinal;
  1055. var PosActual: int64; FileHandleLockID: cardinal): cardinal; cdecl;
  1056. TDosProtectSetFileSizeL = function (Handle: THandle; Size: int64;
  1057. FileHandleLockID: cardinal): cardinal; cdecl;
  1058. TDosGetProcessorStatus = function (ProcID: cardinal;
  1059. var Status: cardinal): cardinal; cdecl;
  1060. TDosSetProcessorStatus = function (ProcID: cardinal;
  1061. Status: cardinal): cardinal; cdecl;
  1062. TDosQueryThreadAffinity = function (Scope: cardinal;
  1063. var AffinityMask: TMPAffinity): cardinal; cdecl;
  1064. TDosSetThreadAffinity = function (var AffinityMask: TMPAffinity): cardinal;
  1065. cdecl;
  1066. TDosQueryExtLibPath = function (ExtLibPath: PChar;
  1067. Flags: cardinal): cardinal; cdecl;
  1068. TDosSetExtLibPath = function (ExtLibPath: PChar; Flags: cardinal): cardinal;
  1069. cdecl;
  1070. const
  1071. Sys_DosCancelLockRequestL: TDosCancelLockRequestL =
  1072. @DummyDosCancelLockRequestL;
  1073. Sys_DosSetFileLocksL: TDosSetFileLocksL = @DummyDosSetFileLocksL;
  1074. Sys_DosProtectSetFileLocksL: TDosProtectSetFileLocksL =
  1075. @DummyDosProtectSetFileLocksL;
  1076. Sys_DosProtectOpenL: TDosProtectOpenL = @DummyDosProtectOpenL;
  1077. Sys_DosProtectSetFilePtrL: TDosProtectSetFilePtrL =
  1078. @DummyDosProtectSetFilePtrL;
  1079. Sys_DosProtectSetFileSizeL: TDosProtectSetFileSizeL =
  1080. @DummyDosProtectSetFileSizeL;
  1081. Sys_DosProtectOpen: TDosProtectOpen = @DummyDosProtectOpen;
  1082. Sys_DosProtectClose: TDosProtectClose = @DummyDosProtectClose;
  1083. Sys_DosProtectRead: TDosProtectRead = @DummyDosProtectRead;
  1084. Sys_DosProtectWrite: TDosProtectWrite = @DummyDosProtectWrite;
  1085. Sys_DosProtectSetFilePtr: TDosProtectSetFilePtr = @DummyDosProtectSetFilePtr;
  1086. Sys_DosProtectSetFileSize: TDosProtectSetFileSize =
  1087. @DummyDosProtectSetFileSize;
  1088. Sys_DosProtectQueryFHState: TDosProtectQueryFHState =
  1089. @DummyDosProtectQueryFHState;
  1090. Sys_DosProtectSetFHState: TDosProtectSetFHState = @DummyDosProtectSetFHState;
  1091. Sys_DosProtectQueryFileInfo: TDosProtectQueryFileInfo =
  1092. @DummyDosProtectQueryFileInfo;
  1093. Sys_DosProtectSetFileInfo: TDosProtectSetFileInfo =
  1094. @DummyDosProtectSetFileInfo;
  1095. Sys_DosProtectEnumAttribute: TDosProtectEnumAttribute =
  1096. @DummyDosProtectEnumAttribute;
  1097. Sys_DosProtectSetFileLocks: TDosProtectSetFileLocks =
  1098. @DummyDosProtectSetFileLocks;
  1099. Sys_DosGetProcessorStatus: TDosGetProcessorStatus =
  1100. @DummyDosGetProcessorStatus;
  1101. Sys_DosSetProcessorStatus: TDosSetProcessorStatus =
  1102. @DummyDosSetProcessorStatus;
  1103. Sys_DosQueryThreadAffinity: TDosQueryThreadAffinity =
  1104. @DummyDosQueryThreadAffinity;
  1105. Sys_DosSetThreadAffinity: TDosSetThreadAffinity = @DummyDosSetThreadAffinity;
  1106. Sys_DosQueryExtLibPath: TDosQueryExtLibPath = @DummyDosQueryExtLibPath;
  1107. Sys_DosSetExtLibPath: TDosSetExtLibPath = @DummyDosSetExtLibPath;
  1108. function DosOpenL (FileName: PChar; var Handle: THandle;
  1109. var Action: cardinal; InitSize: int64;
  1110. Attrib, OpenFlags, FileMode: cardinal;
  1111. EA: pointer): cardinal; cdecl; inline;
  1112. begin
  1113. DosOpenL := Sys_DosOpenL (FileName, Handle, Action, InitSize, Attrib,
  1114. OpenFlags, FileMode, EA);
  1115. end;
  1116. function DosSetFilePtrL (Handle: THandle; Pos: int64; Method: cardinal;
  1117. var PosActual: int64): cardinal; cdecl; inline;
  1118. begin
  1119. DosSetFilePtrL := Sys_DosSetFilePtrL (Handle, Pos, Method, PosActual);
  1120. end;
  1121. function DosSetFileSizeL (Handle: THandle; Size: int64): cardinal; cdecl;
  1122. inline;
  1123. begin
  1124. DosSetFileSizeL := Sys_DosSetFileSizeL (Handle, Size);
  1125. end;
  1126. function DosProtectOpen (FileName: PChar; var Handle: THandle;
  1127. var Action: cardinal; InitSize, Attrib,
  1128. OpenFlags, OpenMode: cardinal; EA: PEAOp2;
  1129. var FileHandleLockID: cardinal): cardinal; cdecl; inline;
  1130. begin
  1131. DosProtectOpen := Sys_DosProtectOpen (FileName, Handle, Action, InitSize,
  1132. Attrib, OpenFlags, OpenMode, EA, FileHandleLockID);
  1133. end;
  1134. function DosProtectClose (Handle: THandle;
  1135. FileHandleLockID: cardinal): cardinal; cdecl; inline;
  1136. begin
  1137. DosProtectClose := Sys_DosProtectClose (Handle, FileHandleLockID);
  1138. end;
  1139. function DosProtectRead (Handle: THandle; var Buffer; Count: cardinal;
  1140. var ActCount: cardinal; FileHandleLockID: cardinal): cardinal; cdecl; inline;
  1141. begin
  1142. DosProtectRead := Sys_DosProtectRead (Handle, Buffer, Count, ActCount,
  1143. FileHandleLockID);
  1144. end;
  1145. function DosProtectWrite (Handle: THandle; const Buffer; Count: cardinal;
  1146. var ActCount: cardinal;
  1147. FileHandleLockID: cardinal): cardinal; cdecl; inline;
  1148. begin
  1149. DosProtectWrite := Sys_DosProtectWrite (Handle, Buffer, Count, ActCount,
  1150. FileHandleLockID);
  1151. end;
  1152. function DosProtectSetFilePtr (Handle: THandle; Pos: longint;
  1153. Method: cardinal; var PosActual: cardinal;
  1154. FileHandleLockID: cardinal): cardinal; cdecl; inline;
  1155. begin
  1156. DosProtectSetFilePtr := Sys_DosProtectSetFilePtr (Handle, Pos, Method,
  1157. PosActual, FileHandleLockID);
  1158. end;
  1159. function DosProtectSetFileSize (Handle: THandle; Size: cardinal;
  1160. FileHandleLockID: cardinal): cardinal; cdecl; inline;
  1161. begin
  1162. DosProtectSetFileSize := Sys_DosProtectSetFileSize (Handle, Size,
  1163. FileHandleLockID);
  1164. end;
  1165. function DosProtectQueryFHState (Handle: THandle; var FileMode: cardinal;
  1166. FileHandleLockID: cardinal): cardinal; cdecl; inline;
  1167. begin
  1168. DosProtectQueryFHState := Sys_DosProtectQueryFHState (Handle, FileMode,
  1169. FileHandleLockID);
  1170. end;
  1171. function DosProtectSetFHState (Handle: THandle; FileMode: cardinal;
  1172. FileHandleLockID: cardinal): cardinal; cdecl; inline;
  1173. begin
  1174. DosProtectSetFHState := Sys_DosProtectSetFHState (Handle, FileMode,
  1175. FileHandleLockID);
  1176. end;
  1177. function DosProtectQueryFileInfo (Handle: THandle; InfoLevel: cardinal;
  1178. AFileStatus: PFileStatus; FileStatusLen: cardinal;
  1179. FileHandleLockID: cardinal): cardinal; cdecl; inline;
  1180. begin
  1181. DosProtectQueryFileInfo := Sys_DosProtectQueryFileInfo (Handle, InfoLevel,
  1182. AFileStatus, FileStatusLen, FileHandleLockID);
  1183. end;
  1184. function DosProtectSetFileInfo (Handle: THandle; InfoLevel: cardinal;
  1185. AFileStatus: PFileStatus; FileStatusLen: cardinal;
  1186. FileHandleLockID: cardinal): cardinal; cdecl; inline;
  1187. begin
  1188. DosProtectSetFileInfo := Sys_DosProtectSetFileInfo (Handle, InfoLevel,
  1189. AFileStatus, FileStatusLen, FileHandleLockID);
  1190. end;
  1191. function DosProtectEnumAttribute (RefType: cardinal; AFile: pointer;
  1192. Entry: cardinal; var Buf; BufSize: cardinal;
  1193. var Count: cardinal; InfoLevel: cardinal;
  1194. FileHandleLockID: cardinal): cardinal; cdecl; inline;
  1195. begin
  1196. DosProtectEnumAttribute := Sys_DosProtectEnumAttribute (RefType, AFile,
  1197. Entry, Buf, BufSize, Count, InfoLevel, FileHandleLockID);
  1198. end;
  1199. function DosProtectSetFileLocks (Handle: THandle;
  1200. var Unlock, Lock: TFileLock;
  1201. Timeout, Flags: cardinal;
  1202. FileHandleLockID: cardinal): cardinal; cdecl; inline;
  1203. begin
  1204. DosProtectSetFileLocks := Sys_DosProtectSetFileLocks (Handle, Unlock, Lock,
  1205. Timeout, Flags, FileHandleLockID);
  1206. end;
  1207. function DosProtectOpen (FileName: PChar; var Handle: longint;
  1208. var Action: longint; InitSize, Attrib,
  1209. OpenFlags, OpenMode: longint; ea: PEAOp2;
  1210. var FileHandleLockID: cardinal): cardinal; cdecl; inline;
  1211. begin
  1212. DosProtectOpen := Sys_DosProtectOpen (FileName, THandle (Handle),
  1213. cardinal (Action), cardinal (InitSize), cardinal (Attrib),
  1214. cardinal (OpenFlags), cardinal (OpenMode), EA, FileHandleLockID);
  1215. end;
  1216. function DosProtectOpen (const FileName: string; var Handle: longint;
  1217. var Action: longint; InitSize, Attrib,
  1218. OpenFlags, OpenMode: longint; ea: PEAOp2;
  1219. var FileHandleLockID: cardinal): cardinal;
  1220. var
  1221. T: array [0..255] of char;
  1222. begin
  1223. StrPCopy (@T, FileName);
  1224. DosProtectOpen := Sys_DosProtectOpen (@T, THandle (Handle),
  1225. cardinal (Action), cardinal (InitSize), cardinal (Attrib),
  1226. cardinal (OpenFlags), cardinal (OpenMode), EA, FileHandleLockID);
  1227. end;
  1228. function DosProtectOpen (const FileName: string; var Handle: THandle;
  1229. var Action: cardinal; InitSize, Attrib,
  1230. OpenFlags, OpenMode: cardinal; ea: PEAOp2;
  1231. var FileHandleLockID: cardinal): cardinal;
  1232. var
  1233. T: array [0..255] of char;
  1234. begin
  1235. StrPCopy (@T, FileName);
  1236. DosProtectOpen := Sys_DosProtectOpen (@T, Handle, Action, InitSize, Attrib,
  1237. OpenFlags, OpenMode, EA, FileHandleLockID);
  1238. end;
  1239. function DosProtectRead (Handle: longint; var Buffer; Count: longint;
  1240. var ActCount: longint; FileHandleLockID: cardinal): cardinal; cdecl; inline;
  1241. begin
  1242. DosProtectRead := Sys_DosProtectRead (THandle (Handle), Buffer,
  1243. cardinal (Count), cardinal (ActCount), FileHandleLockID);
  1244. end;
  1245. function DosProtectWrite (Handle: longint; const Buffer; Count: longint;
  1246. var ActCount: longint;
  1247. FileHandleLockID: cardinal): cardinal; cdecl; inline;
  1248. begin
  1249. DosProtectWrite := Sys_DosProtectWrite (THandle (Handle), Buffer,
  1250. cardinal (Count), cardinal (ActCount), FileHandleLockID);
  1251. end;
  1252. function DosProtectSetFilePtr (Handle: longint; Pos, Method: longint;
  1253. var PosActual: longint;
  1254. FileHandleLockID: cardinal): cardinal; cdecl; inline;
  1255. begin
  1256. DosProtectSetFilePtr := Sys_DosProtectSetFilePtr (THandle (Handle),
  1257. cardinal (Pos), cardinal (Method), cardinal (PosActual), FileHandleLockID);
  1258. end;
  1259. function DosProtectSetFilePtr (Handle: THandle; Pos: longint;
  1260. FileHandleLockID: cardinal): cardinal;
  1261. var
  1262. PosActual: cardinal;
  1263. begin
  1264. DosProtectSetFilePtr := DosProtectSetFilePtr (Handle, Pos, 0, PosActual,
  1265. FileHandleLockID);
  1266. end;
  1267. function DosProtectGetFilePtr (Handle: longint;
  1268. var PosActual: longint; FileHandleLockID: cardinal): cardinal;
  1269. begin
  1270. DosProtectGetFilePtr := DosProtectSetFilePtr (THandle (Handle), 0, 1,
  1271. cardinal (PosActual), FileHandleLockID);
  1272. end;
  1273. function DosProtectGetFilePtr (Handle: THandle;
  1274. var PosActual: cardinal; FileHandleLockID: cardinal): cardinal;
  1275. begin
  1276. DosProtectGetFilePtr := DosProtectSetFilePtr (Handle, 0, 1, PosActual,
  1277. FileHandleLockID);
  1278. end;
  1279. function DosProtectEnumAttribute (Handle: THandle; Entry: cardinal; var Buf;
  1280. BufSize: cardinal; var Count: cardinal;
  1281. InfoLevel: cardinal;
  1282. FileHandleLockID: cardinal): cardinal;
  1283. begin
  1284. DosProtectEnumAttribute := DosProtectEnumAttribute (0, @Handle, Entry, Buf,
  1285. BufSize, Count, InfoLevel, FileHandleLockID);
  1286. end;
  1287. function DosProtectEnumAttribute (const FileName: string; Entry: cardinal;
  1288. var Buf; BufSize: cardinal;
  1289. var Count: cardinal; InfoLevel: cardinal;
  1290. FileHandleLockID: cardinal): cardinal;
  1291. var
  1292. T: array [0..255] of char;
  1293. begin
  1294. StrPCopy (@T, FileName);
  1295. DosProtectEnumAttribute := DosProtectEnumAttribute (1, @T, Entry, Buf,
  1296. BufSize, Count, InfoLevel, FileHandleLockID);
  1297. end;
  1298. function DosCancelLockRequestL (Handle: THandle;
  1299. var Lock: TFileLockL): cardinal; cdecl; inline;
  1300. begin
  1301. DosCancelLockRequestL := Sys_DosCancelLockRequestL (Handle, Lock);
  1302. end;
  1303. function DosProtectSetFileLocksL (Handle: THandle; var Unlock: TFileLockL;
  1304. var Lock: TFileLockL; Timeout: cardinal; Flags: cardinal;
  1305. FileHandleLockID: cardinal): cardinal; cdecl; inline;
  1306. begin
  1307. DosProtectSetFileLocksL := Sys_DosProtectSetFileLocksL (Handle, Unlock, Lock,
  1308. Timeout, Flags, FileHandleLockID);
  1309. end;
  1310. function DosSetFileLocksL (Handle: THandle; var Unlock: TFileLockL;
  1311. var Lock: TFileLockL; Timeout: cardinal; Flags: cardinal): cardinal; cdecl;
  1312. inline;
  1313. begin
  1314. DosSetFileLocksL := Sys_DosSetFileLocksL (Handle, Unlock, Lock, Timeout,
  1315. Flags);
  1316. end;
  1317. function DosProtectOpenL (FileName: PChar; var Handle: THandle;
  1318. var Action: cardinal; InitSize: int64; Attrib,
  1319. OpenFlags, OpenMode: cardinal; EA: PEAOp2;
  1320. var FileHandleLockID: cardinal): cardinal; cdecl; inline;
  1321. begin
  1322. DosProtectOpenL := Sys_DosProtectOpenL (FileName, Handle, Action, InitSize,
  1323. Attrib, OpenFlags, OpenMode, EA, FileHandleLockID);
  1324. end;
  1325. function DosProtectSetFilePtrL (Handle: THandle; Pos: int64;
  1326. Method: cardinal; var PosActual: int64;
  1327. FileHandleLockID: cardinal): cardinal; cdecl; inline;
  1328. begin
  1329. DosProtectSetFilePtrL := Sys_DosProtectSetFilePtrL (Handle, Pos, Method,
  1330. PosActual, FileHandleLockID);
  1331. end;
  1332. function DosProtectSetFileSizeL (Handle: THandle; Size: int64;
  1333. FileHandleLockID: cardinal): cardinal; cdecl; inline;
  1334. begin
  1335. DosProtectSetFileSizeL := Sys_DosProtectSetFileSizeL (Handle, Size,
  1336. FileHandleLockID);
  1337. end;
  1338. function DosGetProcessorStatus (ProcID: cardinal;
  1339. var Status: cardinal): cardinal; cdecl; inline;
  1340. begin
  1341. DosGetProcessorStatus := Sys_DosGetProcessorStatus (ProcID, Status);
  1342. end;
  1343. function DosSetProcessorStatus (ProcID: cardinal;
  1344. Status: cardinal): cardinal; cdecl; inline;
  1345. begin
  1346. DosSetProcessorStatus := Sys_DosSetProcessorStatus (ProcID, Status);
  1347. end;
  1348. function DosQueryThreadAffinity (Scope: cardinal;
  1349. var AffinityMask: TMPAffinity): cardinal; cdecl; inline;
  1350. begin
  1351. DosQueryThreadAffinity := Sys_DosQueryThreadAffinity (Scope, AffinityMask);
  1352. end;
  1353. function DosSetThreadAffinity (var AffinityMask: TMPAffinity): cardinal; cdecl;
  1354. inline;
  1355. begin
  1356. DosSetThreadAffinity := Sys_DosSetThreadAffinity (AffinityMask);
  1357. end;
  1358. function DosQueryExtLibPath (ExtLibPath: PChar; Flags: cardinal): cardinal;
  1359. cdecl; inline;
  1360. begin
  1361. DosQueryExtLibPath := Sys_DosQueryExtLibPath (ExtLibPath, Flags);
  1362. end;
  1363. function DosSetExtLibPath (ExtLibPath: PChar; Flags: cardinal): cardinal;
  1364. cdecl; inline;
  1365. begin
  1366. DosSetExtLibPath := Sys_DosSetExtLibPath (ExtLibPath, Flags);
  1367. end;
  1368. var
  1369. P: pointer;
  1370. begin
  1371. if FSApi64 then
  1372. (* DosCallsHandle successfully initialized during initialization of unit *)
  1373. (* System and basic 64-bit functions were loaded successfully. *)
  1374. begin
  1375. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32CancelLockRequestL, nil, P)
  1376. = 0 then
  1377. Sys_DosCancelLockRequestL := TDosCancelLockRequestL (P);
  1378. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32ProtectSetFileLocksL, nil, P)
  1379. = 0 then
  1380. Sys_DosProtectSetFileLocksL := TDosProtectSetFileLocksL (P);
  1381. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32SetFileLocksL, nil, P)
  1382. = 0 then
  1383. Sys_DosSetFileLocksL := TDosSetFileLocksL (P);
  1384. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32ProtectOpenL, nil, P) = 0
  1385. then
  1386. Sys_DosProtectOpenL := TDosProtectOpenL (P);
  1387. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32ProtectSetFilePtrL, nil, P)
  1388. = 0 then
  1389. Sys_DosProtectSetFilePtrL := TDosProtectSetFilePtrL (P);
  1390. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32ProtectSetFileSizeL, nil, P)
  1391. = 0 then
  1392. Sys_DosProtectSetFileSizeL := TDosProtectSetFileSizeL (P);
  1393. end;
  1394. if DosCallsHandle = THandle (-1) then
  1395. Exit;
  1396. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32ProtectOpen, nil, P) = 0 then
  1397. begin
  1398. Sys_DosProtectOpen := TDosProtectOpen (P);
  1399. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32ProtectClose, nil, P) = 0
  1400. then
  1401. Sys_DosProtectClose := TDosProtectClose (P);
  1402. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32ProtectRead, nil, P) = 0 then
  1403. Sys_DosProtectRead := TDosProtectRead (P);
  1404. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32ProtectWrite, nil, P) = 0
  1405. then
  1406. Sys_DosProtectWrite := TDosProtectWrite (P);
  1407. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32ProtectSetFilePtr, nil,
  1408. P) = 0 then
  1409. Sys_DosProtectSetFilePtr := TDosProtectSetFilePtr (P);
  1410. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32ProtectSetFileSize, nil,
  1411. P) = 0 then
  1412. Sys_DosProtectSetFileSize := TDosProtectSetFileSize (P);
  1413. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32ProtectQueryFHState, nil,
  1414. P) = 0 then
  1415. Sys_DosProtectQueryFHState := TDosProtectQueryFHState (P);
  1416. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32ProtectSetFHState, nil,
  1417. P) = 0 then
  1418. Sys_DosProtectSetFHState := TDosProtectSetFHState (P);
  1419. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32ProtectQueryFileInfo, nil,
  1420. P) = 0 then
  1421. Sys_DosProtectQueryFileInfo := TDosProtectQueryFileInfo (P);
  1422. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32ProtectSetFileInfo, nil,
  1423. P) = 0 then
  1424. Sys_DosProtectSetFileInfo := TDosProtectSetFileInfo (P);
  1425. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32ProtectEnumAttribute, nil,
  1426. P) = 0 then
  1427. Sys_DosProtectEnumAttribute := TDosProtectEnumAttribute (P);
  1428. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32ProtectSetFileLocks, nil,
  1429. P) = 0 then
  1430. Sys_DosProtectSetFileLocks := TDosProtectSetFileLocks (P);
  1431. end;
  1432. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32GetProcessorStatus, nil,
  1433. P) = 0 then
  1434. Sys_DosGetProcessorStatus := TDosGetProcessorStatus (P);
  1435. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32SetProcessorStatus, nil,
  1436. P) = 0 then
  1437. Sys_DosSetProcessorStatus := TDosSetProcessorStatus (P);
  1438. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32QueryThreadAffinity, nil,
  1439. P) = 0 then
  1440. Sys_DosQueryThreadAffinity := TDosQueryThreadAffinity (P);
  1441. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32SetThreadAffinity, nil,
  1442. P) = 0 then
  1443. Sys_DosSetThreadAffinity := TDosSetThreadAffinity (P);
  1444. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32QueryExtLibPath, nil,
  1445. P) = 0 then
  1446. Sys_DosQueryExtLibPath := TDosQueryExtLibPath (P);
  1447. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32SetExtLibPath, nil,
  1448. P) = 0 then
  1449. Sys_DosSetExtLibPath := TDosSetExtLibPath (P);
  1450. end.
  1451. (*
  1452. Todo:
  1453. DosCreateSpinLock = DOSCALLS.449 - might be simulated using semaphores on non-SMP
  1454. DosAcquireSpinLock = DOSCALLS.450 - might be simulated using semaphores on non-SMP
  1455. DosReleaseSpinLock = DOSCALLS.451 - might be simulated using semaphores on non-SMP
  1456. DosFreeSpinLock = DOSCALLS.452 - might be simulated using semaphores on non-SMP
  1457. DosQueryModFromEIP - may be simulated by returning empty value if not available or possibly by using data returned by DosQuerySysState (if they are equal across different OS/2 versions?)
  1458. ___ function Dos16QueryModFromCS (...): ...
  1459. external 'DOSCALLS' index 359;
  1460. DosVerifyPidTid - may be implemented by analyzing information returned by DosQuerySysState
  1461. x DosQueryExtLibPath - may be simulated by providing empty result if not available
  1462. x DosSetExtLibPath - may be simulated by returning ERROR_NOT_ENOUGH_MEMORY if not available
  1463. Dos32AcquireSpinLock | DOSCALLS | SMP | SMP
  1464. Dos32FreeSpinLock | DOSCALLS | SMP | SMP
  1465. x Dos32GetProcessorStatus | DOSCALLS | SMP | SMP
  1466. Dos32ReleaseSpinLock | DOSCALLS | SMP | SMP
  1467. x Dos32SetProcessorStatus | DOSCALLS | SMP | SMP
  1468. Dos32TestPSD | DOSCALLS | SMP | SMP
  1469. x Dos32QueryThreadAffinity | DOSCALLS | PROC | 2.45
  1470. Dos32QueryThreadContext | DOSCALLS | XCPT | 2.40
  1471. x Dos32SetThreadAffinity | DOSCALLS | PROC | 2.45
  1472. Dos32AllocThreadLocalMemory | DOSCALLS | PROC | 2.30
  1473. Dos32FreeThreadLocalMemory | DOSCALLS | PROC | 2.30
  1474. Dos32ListIO | DOSCALLS | FILE | 2.45
  1475. x Dos32ProtectClose | DOSCALLS | FILE | 2.10
  1476. x Dos32ProtectEnumAttribute | DOSCALLS | FILE | 2.10
  1477. x Dos32ProtectOpen | DOSCALLS | FILE | 2.10
  1478. x Dos32ProtectQueryFHState | DOSCALLS | FILE | 2.10
  1479. x Dos32ProtectQueryFileInfo | DOSCALLS | FILE | 2.10
  1480. x Dos32ProtectRead | DOSCALLS | FILE | 2.10
  1481. x Dos32ProtectSetFHState | DOSCALLS | FILE | 2.10
  1482. x Dos32ProtectSetFileInfo | DOSCALLS | FILE | 2.10
  1483. x Dos32ProtectSetFileLocks | DOSCALLS | FILE | 2.10
  1484. x Dos32ProtectSetFilePtr | DOSCALLS | FILE | 2.10
  1485. x Dos32ProtectSetFileSize | DOSCALLS | FILE | 2.10
  1486. x Dos32ProtectWrite | DOSCALLS | FILE | 2.10
  1487. Dos32QueryABIOSSupport | DOSCALLS | MOD | 2.10
  1488. Dos32QueryModFromEIP | DOSCALLS | MOD | 2.10
  1489. Dos32SuppressPopUps | DOSCALLS | MISC | 2.10
  1490. Dos32VerifyPidTid | DOSCALLS | MISC | 2.30
  1491. *)