doscall2.pas 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953
  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 64-bit OS/2 API functions for file handling
  5. implemented in DOSCALL1.DLL - functions supported in WSeB/MCP/eCS
  6. or their fake (simulated) implementation for lower OS/2
  7. versions (real availability checked during initialization).
  8. See the file COPYING.FPC, included in this distribution,
  9. for details about the copyright.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. **********************************************************************}
  14. unit DosCall2;
  15. {***************************************************************************}
  16. interface
  17. {***************************************************************************}
  18. uses
  19. DosCalls;
  20. type
  21. TFileLockL = record
  22. case boolean of
  23. false:
  24. (Offset: int64; (* Offset to beginning of the lock (or unlock) range. *)
  25. Range: int64); (* Length of the lock (or unlock) range in bytes. *)
  26. (* Length of 0 => locking (or unlocking) not required. *)
  27. true:
  28. (lOffset: int64;
  29. lRange: int64);
  30. end;
  31. PFileLockL = ^TFileLockL;
  32. (*
  33. DosCancelLockRequestL cancels an outstanding DosSetFileLocksL request.
  34. If two threads in a process are waiting on a lock file range, and another
  35. thread issues DosCancelLockRequestL for that lock file range, then both
  36. waiting threads are released.
  37. Not all file-system drivers (FSDs) can cancel an outstanding lock request.
  38. Local Area Network (LAN) servers cannot cancel an outstanding lock request
  39. if they use a version of the operating system prior to OS/2 Version 2.00.
  40. Possible results:
  41. 0 No_Error
  42. 6 Error_Invalid_Handle
  43. 87 Error_Invalid_Parameter
  44. 173 Error_Cancel_Violation
  45. Handle = File handle used in the DosSetFileLocksL function
  46. that is to be cancelled.
  47. Lock = Specification of the lock request to be cancelled.
  48. *)
  49. type
  50. TDosCancelLockRequestL = function (Handle: THandle; var Lock: TFileLockL):
  51. cardinal; cdecl;
  52. function DummyDosCancelLockRequestL (Handle: THandle;
  53. var Lock: TFileLockL): cardinal; cdecl;
  54. (*
  55. DosProtectSetFileLocksL locks and unlocks a range of an open file.
  56. Parameters:
  57. Handle = file handle
  58. Unlock = record containing the offset and length of a range to be unlocked
  59. Lock = record containing the offset and length of a range to be locked
  60. Timeout = the maximum time that the process is to wait for the requested locks
  61. (in milliseconds)
  62. Flags = bit mask specifying action to be taken.
  63. Bits 31..2 are reserved.
  64. Bit 1 (Atomic) means request for atomic locking - if the bit is set
  65. and the lock range is equal to the unlock range, an atomic lock occurs.
  66. If this bit is set to 1 and the lock range is not equal to the unlock
  67. range, an error is returned. If this bit is set to 0, then the lock
  68. may or may not occur atomically with the unlock.
  69. Bit 0 (Share) defines the type of access that other processes may have
  70. to the file range that is being locked. If this bit is set to 0
  71. (default), other processes have no access to the locked file range.
  72. The current process has exclusive access to the locked file range,
  73. which must not overlap any other locked file range. If this bit is set
  74. to 1, the current process and other processes have shared read only
  75. access to the locked file range. A file range with shared access may
  76. overlap any other file range with shared access, but must not overlap
  77. any other file range with exclusive access.
  78. FileHandleLockID = filehandle lockid returned by a previous DosProtectOpenL.
  79. Possible return codes:
  80. 0 NO_ERROR
  81. 6 ERROR_INVALID_HANDLE
  82. 33 ERROR_LOCK_VIOLATION
  83. 36 ERROR_SHARING_BUFFER_EXCEEDED
  84. 87 ERROR_INVALID_PARAMETER
  85. 95 ERROR_INTERRUPT
  86. 174 ERROR_ATOMIC_LOCK_NOT_SUPPORTED
  87. 175 ERROR_READ_LOCKS_NOT_SUPPORTED
  88. Remarks:
  89. DosProtectSetFileLocksL allows a process to lock and unlock a range in a file.
  90. The time during which a file range is locked should be short.
  91. If the lock and unlock ranges are both zero, ERROR_LOCK_VIOLATION is returned
  92. to the caller.
  93. If you only want to lock a file range, set the unlock file offset and the
  94. unlock range length to zero.
  95. If you only want to unlock a file range, set the lock file offset and the lock
  96. range length to zero.
  97. When the Atomic bit of flags is set to 0, and DosProtectSetFileLocksL specifies
  98. a lock operation and an unlock operation, the unlock operation occurs first,
  99. and then the lock operation is performed. If an error occurs during the unlock
  100. operation, an error code is returned and the lock operation is not performed.
  101. If an error occurs during the lock operation, an error code is returned and the
  102. unlock remains in effect if it was successful.
  103. The lock operation is atomic when all of these conditions are met:
  104. - The Atomic bit is set to 1 in flags
  105. - The unlock range is the same as the lock range
  106. - The process has shared access to the file range, and has requested exclusive
  107. access to it; or the process has exclusive access to the file range, and has
  108. requested shared access to it.
  109. Some file system drivers (FSDs) may not support atomic lock operations.
  110. Versions of the operating system prior to OS/2 Version 2.00 do not support
  111. atomic lock operations. If the application receives the error code
  112. ERROR_ATOMIC_LOCK_NOT_SUPPORTED, the application should unlock the file range
  113. and then lock it using a non-atomic operation (with the atomic bit set to 0
  114. in Flags). The application should also refresh its internal buffers before
  115. making any changes to the file.
  116. If you issue DosProtectClose to close a file with locks still in effect,
  117. the locks are released in no defined sequence.
  118. If you end a process with a file open, and you have locks in effect in that
  119. file, the file is closed and the locks are released in no defined sequence.
  120. The locked range can be anywhere in the logical file. Locking beyond the end
  121. of the file is not an error. A file range to be locked exclusively must first
  122. be cleared of any locked file sub-ranges or overlapping locked file ranges.
  123. If you repeat DosProtectSetFileLocksL for the same file handle and file range,
  124. then you duplicate access to the file range. Access to locked file ranges
  125. is not duplicated across DosExecPgm. The proper method of using locks is
  126. to attempt to lock the file range, and to examine the return value.
  127. The following table shows the level of access granted when the accessed file
  128. range is locked with an exclusive lock or a shared lock. Owner refers to
  129. a process that owns the lock. Non-owner refers to a process that does not own
  130. the lock.
  131. Action Exclusive Lock Shared Lock
  132. ===================================================================
  133. Owner read Success Success
  134. -------------------------------------------------------------------
  135. Non-owner Wait for unlock. Return Success
  136. read error code after time-out.
  137. -------------------------------------------------------------------
  138. Owner write Success Wait for unlock. Return
  139. error code after time-out.
  140. -------------------------------------------------------------------
  141. Non-owner Wait for unlock. Return Wait for unlock. Return
  142. write error code after time-out. error code after time-out.
  143. -------------------------------------------------------------------
  144. If only locking is specified, DosProtectSetFileLocksL locks the specified file
  145. range using Lock. If the lock operation cannot be accomplished, an error is
  146. returned, and the file range is not locked.
  147. After the lock request is processed, a file range can be unlocked using the
  148. Unlock parameter of another DosProtectSetFileLocksL request. If unlocking
  149. cannot be accomplished, an error is returned.
  150. Instead of denying read/write access to an entire file by specifying access
  151. and sharing modes with DosProtectOpenL requests, a process attempts to lock
  152. only the range needed for read/write access and examines the error code
  153. returned.
  154. Once a specified file range is locked exclusively, read and write access by
  155. another process is denied until the file range is unlocked. If both unlocking
  156. and locking are specified by DosProtectSetFileLocksL, the unlocking operation
  157. is performed first, then locking is done.
  158. *)
  159. type
  160. TDosProtectSetFileLocksL = function (Handle: THandle; var Unlock: TFileLockL;
  161. var Lock: TFileLockL; Timeout: cardinal; Flags: cardinal;
  162. FileHandleLockID: cardinal): cardinal; cdecl;
  163. function DummyDosProtectSetFileLocksL (Handle: THandle; var Unlock: TFileLockL;
  164. var Lock: TFileLockL; Timeout: cardinal; Flags: cardinal;
  165. FileHandleLockID: cardinal): cardinal; cdecl;
  166. (*
  167. DosSetFileLocksL locks and unlocks a range of an open file.
  168. Parameters
  169. Handle = file handle
  170. Unlock = record containing the offset and length of a range to be unlocked
  171. Lock = record containing the offset and length of a range to be locked
  172. Timeout = the maximum time that the process is to wait for the requested locks
  173. (in milliseconds)
  174. Flags = bit mask specifying action to be taken.
  175. Bits 31..2 are reserved.
  176. Bit 1 (Atomic) means request for atomic locking - if the bit is set
  177. and the lock range is equal to the unlock range, an atomic lock occurs.
  178. If this bit is set to 1 and the lock range is not equal to the unlock
  179. range, an error is returned. If this bit is set to 0, then the lock
  180. may or may not occur atomically with the unlock.
  181. Bit 0 (Share) defines the type of access that other processes may have
  182. to the file range that is being locked. If this bit is set to 0
  183. (default), other processes have no access to the locked file range.
  184. The current process has exclusive access to the locked file range,
  185. which must not overlap any other locked file range. If this bit is set
  186. to 1, the current process and other processes have shared read only
  187. access to the locked file range. A file range with shared access may
  188. overlap any other file range with shared access, but must not overlap
  189. any other file range with exclusive access.
  190. Possible return codes:
  191. 0 NO_ERROR
  192. 1 ERROR_INVALID_FUNCTION
  193. 6 ERROR_INVALID_HANDLE
  194. 33 ERROR_LOCK_VIOLATION
  195. 36 ERROR_SHARING_BUFFER_EXCEEDED
  196. 87 ERROR_INVALID_PARAMETER
  197. 95 ERROR_INTERRUPT
  198. 174 ERROR_ATOMIC_LOCK_NOT_SUPPORTED
  199. 175 ERROR_READ_LOCKS_NOT_SUPPORTED
  200. Remarks:
  201. DosSetFileLocksL allows a process to lock and unlock a range in a file. The time during which a file range is locked should be short.
  202. If the lock and unlock ranges are both zero, ERROR_LOCK_VIOLATION is returned to the caller.
  203. If you only want to lock a file range, set the unlock file offset and the unlock range length to zero.
  204. If you only want to unlock a file range, set the lock file offset and the lock range length to zero.
  205. When the Atomic bit of flags is set to 0, and DosSetFileLocksL specifies a lock operation and an unlock operation, the unlock operation occurs first, and then the lock operation is performed. If an error occurs during the unlock operation, an error code is returned and the lock operation is not performed. If an error occurs during the lock operation, an error code is returned and the unlock remains in effect if it was successful.
  206. The lock operation is atomic when all of these conditions are met
  207. The Atomic bit is set to 1 in flags
  208. The unlock range is the same as the lock range
  209. The process has shared access to the file range, and has requested exclusive access to it; or the process has exclusive access to the file range, and has requested shared access to it.
  210. Some file system drivers (FSDs) may not support atomic lock operations. Versions of the operating system prior to OS/2 Version 2.00 do not support atomic lock operations. If the application receives the error code ERROR_ATOMIC_LOCK_NOT_SUPPORTED, the application should unlock the file range and then lock it using a non-atomic operation (with the atomic bit set to 0 in flags). The application should also refresh its internal buffers before making any changes to the file.
  211. If you issue DosClose to close a file with locks still in effect, 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 file, the file is closed and the locks are released in no defined sequence.
  213. The locked range can be anywhere in the logical file. Locking beyond the end of the file is not an error. A file range to be locked exclusively must first be cleared of any locked file subranges or overlapping locked file ranges.
  214. If you repeat DosSetFileLocksL for the same file handle and file range, then you duplicate access to the file range. Access to locked file ranges is not duplicated across DosExecPgm. The proper method of using locks is to attempt to lock the file range, and to examine the return value.
  215. The following table shows the level of access granted when the accessed file range is locked with an exclusive lock or a shared lock. Owner refers to a process that owns the lock. Non-owner refers to a process that does not own the lock.
  216. Action Exclusive Lock Shared Lock
  217. ===================================================================
  218. Owner read Success Success
  219. -------------------------------------------------------------------
  220. Non-owner Wait for unlock. Return Success
  221. read error code after time-out.
  222. -------------------------------------------------------------------
  223. Owner write Success Wait for unlock. Return
  224. error code after time-out.
  225. -------------------------------------------------------------------
  226. Non-owner Wait for unlock. Return Wait for unlock. Return
  227. write error code after time-out. error code after time-out.
  228. -------------------------------------------------------------------
  229. If only locking is specified, DosSetFileLocksL locks the specified file range using pflLock. If the lock operation cannot be accomplished, an error is returned, and the file range is not locked.
  230. After the lock request is processed, a file range can be unlocked using the Unlock parameter of another DosSetFileLocksL request. If unlocking cannot be accomplished, an error is returned.
  231. Instead of denying read/write access to an entire file by specifying access and sharing modes with DosOpenL requests, a process attempts to lock only the range needed for read/write access and examines the error code returned.
  232. Once a specified file range is locked exclusively, read and write access by another process is denied until the file range is unlocked. If both unlocking and locking are specified by DosSetFileLocksL, the unlocking operation is performed first, then locking is done.
  233. *)
  234. type
  235. TDosSetFileLocksL = function (Handle: THandle; var Unlock: TFileLockL;
  236. var Lock: TFileLockL; Timeout: cardinal; Flags: cardinal): cardinal; cdecl;
  237. function DummyDosSetFileLocksL (Handle: THandle; var Unlock: TFileLockL;
  238. var Lock: TFileLockL; Timeout: cardinal; Flags: cardinal): cardinal; cdecl;
  239. (*
  240. DosProtectOpenL opens a new file, an existing file, or a replacement for an existing file and returns a protected file handle. An open file can have extended attributes.
  241. Parameters:
  242. FileName = ASCIIZ path name of the file or device to be opened.
  243. Handle = handle for the file is returned here.
  244. Action = value that specifies the action taken by DosProtectOpenL is returned
  245. here; if DosProtectOpenL fails, this value has no meaning, otherwise,
  246. it is one of the following values:
  247. 1 FILE_EXISTED - file already existed.
  248. 2 FILE_CREATED - file was created.
  249. 3 FILE_TRUNCATED - file existed and was changed to a given size (file was
  250. replaced).
  251. InitSize = new logical size of the file (end of data, EOD), in bytes; this
  252. parameter is significant only when creating a new file or replacing
  253. an existing one. Otherwise, it is ignored. It is an error to create
  254. or replace a file with a nonzero length if the OpenMode
  255. Access-Mode flag is set to read-only.
  256. Attrib = file attributes; this parameter contains the following bit fields:
  257. Bits Description
  258. 31..6 - reserved, must be 0.
  259. 5 FILE_ARCHIVED (0x00000020) - file has been archived.
  260. 4 FILE_DIRECTORY (0x00000010) - file is a subdirectory.
  261. 3 - reserved, must be 0.
  262. 2 FILE_SYSTEM (0x00000004) - file is a system file.
  263. 1 FILE_HIDDEN (0x00000002) - file is hidden and does not appear in a directory
  264. listing.
  265. 0 FILE_READONLY (0x00000001) - file can be read from, but not written to.
  266. 0 FILE_NORMAL (0x00000000) - file can be read from or written to.
  267. File attributes apply only if the file is created. These bits may be set
  268. individually or in combination. For example, an attribute value of 0x00000021
  269. (bits 5 and 0 set to 1) indicates a read-only file that has been archived.
  270. OpenFlags = the action to be taken depending on whether the file exists or does not exist.
  271. This parameter contains the following bit fields
  272. Bits Description
  273. 31..8 - reserved, must be 0.
  274. 7..4 - the following flags apply if the file does not exist:
  275. 0000 OPEN_ACTION_FAIL_IF_NEW
  276. Open an existing file; fail if the file does not exist.
  277. 0001 OPEN_ACTION_CREATE_IF_NEW
  278. Create the file if the file does not exist.
  279. 3..0 The following flags apply if the file does not exist:
  280. 0000 OPEN_ACTION_FAIL_IF_EXISTS
  281. Open the file; fail if the file already exists.
  282. 0001 OPEN_ACTION_OPEN_IF_EXISTS
  283. Open the file if it already exists.
  284. 0010 OPEN_ACTION_REPLACE_IF_EXISTS
  285. Replace the file if it already exists.
  286. OpenMode = the mode of the open function.
  287. This parameter contains the following bit fields
  288. Bits Description
  289. 31 - reserved, must be zero.
  290. 30 OPEN_FLAGS_PROTECTED_HANDLE (0x40000000) - protected file handle flag.
  291. 0 - unprotected Handle
  292. 1 - protected Handle
  293. Protected handle requires the FileHandleLockID to be specified on subsequent
  294. DosProtectxxxx calls.
  295. Unprotected handle requires the FileHandleLockID value to be specified as zero
  296. on subsequent DosProtectxxxx calls. An unprotected handle may be used with the
  297. unprotected calls such as DosRead and DosWrite.
  298. 29 OPEN_SHARE_DENYLEGACY (0x10000000)
  299. Deny read/write access by the DosOpen command
  300. 0 - allow read/write access by the DosOpen command.
  301. 1 - deny read/write access by the DosOpen command.
  302. A file opened by DosOpenL will not be allowed to grow larger than 2GB while that same file is open via a legacy DosOpen call. Setting this bit to 1 will prevent access by the obsolete DosOpen API and ensure that no error will occur when growing the file.
  303. 28..16 - reserved, must be zero.
  304. 15 OPEN_FLAGS_DASD (0x00008000)
  305. Direct Open flag
  306. 0 - FileName represents a file to be opened normally.
  307. 1 - FileName is drive (such as C or A), and represents a mounted disk or diskette volume to be opened for direct access.
  308. 14 OPEN_FLAGS_WRITE_THROUGH (0x00004000)
  309. Write-Through flag
  310. 0 - writes to the file may go through the file-system driver's cache; the file-system driver writes the sectors when the cache is full or the file is closed.
  311. 1 - writes to the file may go through the file-system driver's cache, but the sectors are written (the actual file I/O operation is completed) before a synchronous write call returns. This state of the file defines it as a synchronous file. For synchronous files, this bit must be set, because the data must be written to the medium for synchronous write operations.
  312. This bit flag is not inherited by child processes.
  313. 13 OPEN_FLAGS_FAIL_ON_ERROR (0x00002000)
  314. Fail-Errors flag. Media I O errors are handled as follows
  315. 0 - reported through the system critical-error handler.
  316. 1 - reported directly to the caller by way of a return code.
  317. Media I/O errors generated through Category 08h Logical Disk Control IOCtl Commands always get reported directly to the caller by way of return code. The Fail-Errors function applies only to non-IOCtl handle-based file I/O calls.
  318. This flag bit is not inherited by child processes.
  319. 12 OPEN_FLAGS_NO_CACHE (0x00001000)
  320. No-Cache/Cache flag
  321. 0 - the file-system driver should place data from I/O operations into its cache.
  322. 1 - I/O operations to the file need not be done through the file-system driver's cache.
  323. The setting of this bit determines whether file-system drivers should place data into the cache. Like the write-through bit, this is a per-handle bit, and is not inherited by child processes.
  324. 11 - reserved; must be 0.
  325. 10..8 - the locality of reference flags contain information about how the application is to get access to the file. The values are as follows:
  326. 000 OPEN_FLAGS_NO_LOCALITY (0x00000000)
  327. No locality known.
  328. 001 OPEN_FLAGS_SEQUENTIAL (0x00000100)
  329. Mainly sequential access.
  330. 010 OPEN_FLAGS_RANDOM (0x00000200)
  331. Mainly random access.
  332. 011 OPEN_FLAGS_RANDOMSEQUENTIAL (0x00000300)
  333. Random with some locality.
  334. 7 OPEN_FLAGS_NOINHERIT (0x00000080)
  335. Inheritance flag
  336. 0 - file handle is inherited by a process created from a call to DosExecPgm.
  337. 1 - file handle is private to the current process.
  338. This bit is not inherited by child processes.
  339. 6..4 Sharing Mode flags; this field defines any restrictions to file access placed by the caller on other processes. The values are as follows:
  340. 001 OPEN_SHARE_DENYREADWRITE (0x00000010)
  341. Deny read write access.
  342. 010 OPEN_SHARE_DENYWRITE (0x00000020)
  343. Deny write access.
  344. 011 OPEN_SHARE_DENYREAD (0x00000030)
  345. Deny read access.
  346. 100 OPEN_SHARE_DENYNONE (0x00000040)
  347. Deny neither read nor write access (deny none).
  348. Any other value is invalid.
  349. 3 Reserved; must be 0.
  350. 2 0 Access-Mode flags. This field defines the file access required by the caller. The values are as follows
  351. 000 OPEN_ACCESS_READONLY (0x00000000)
  352. Read-only access
  353. 001 OPEN_ACCESS_WRITEONLY (0x00000001)
  354. Write-only access
  355. 010 OPEN_ACCESS_READWRITE (0x00000002)
  356. Read/write access.
  357. Any other value is invalid, as are any other combinations.
  358. File sharing requires the cooperation of sharing processes. This cooperation is communicated through sharing and access modes. Any sharing restrictions placed on a file opened by a process are removed when the process closes the file with a DosClose request.
  359. Sharing Mode
  360. Specifies the type of file access that other processes may have. For example, if other processes can continue to read the file while your process is operating on it, specify Deny Write. The sharing mode prevents other processes from writing to the file but still allows them to read it.
  361. Access Mode
  362. Specifies the type of file access (access mode) needed by your process. For example, if your process requires read/write access, and another process has already opened the file with a sharing mode of Deny None, your DosProtectOpenL request succeeds. However, if the file is open with a sharing mode of Deny Write, the process is denied access.
  363. If the file is inherited by a child process, all sharing and access restrictions also are inherited.
  364. If an open file handle is duplicated by a call to DosDupHandle, all sharing and access restrictions also are duplicated.
  365. EA = pointer to an extended attribute buffer.
  366. Input The address of the extended-attribute buffer, which contains an EAOP2 structure. The fpFEA2List field in the EAOP2 structure points to a data area where the relevant FEA2 list is to be found. The fpGEA2List and oError fields are ignored.
  367. Output fpGEA2List and fpFEA2List are unchanged. The area that fpFEA2List points to is unchanged. If an error occurred during the set, oError is the offset of the FEA2 entry where the error occurred. The return code from DosProtectOpenL is the error code for that error condition. If no error occurred, oError is undefined.
  368. EA is nil, then no extended attributes are defined for the file. If extended attributes are not to be defined or modified, the pointer peaop2 must be set to zero.
  369. FileHandleLockID = 32-bit lockid for the file handle is returned here
  370. Possible return codes:
  371. 0 NO_ERROR
  372. 2 ERROR_FILE_NOT_FOUND
  373. 3 ERROR_PATH_NOT_FOUND
  374. 4 ERROR_TOO_MANY_OPEN_FILES
  375. 5 ERROR_ACCESS_DENIED
  376. 12 ERROR_INVALID_ACCESS
  377. 26 ERROR_NOT_DOS_DISK
  378. 32 ERROR_SHARING_VIOLATION
  379. 36 ERROR_SHARING_BUFFER_EXCEEDED
  380. 82 ERROR_CANNOT_MAKE
  381. 87 ERROR_INVALID_PARAMETER
  382. 99 ERROR_DEVICE_IN_USE
  383. 108 ERROR_DRIVE_LOCKED
  384. 110 ERROR_OPEN_FAILED
  385. 112 ERROR_DISK_FULL
  386. 206 ERROR_FILENAME_EXCED_RANGE
  387. 231 ERROR_PIPE_BUSY
  388. Remarks:
  389. A successful DosProtectOpenL request returns a handle and a 32-bit lockid for accessing the file. The read/write pointer is set at the first byte of the file. The position of the pointer can be changed with DosProtectSetFilePtrL or by read and write operations on the file.
  390. The file s date and time can be queried with DosProtectQueryFileInfo. They are set with DosProtectSetFileInfo.
  391. The read-only attribute of a file can be set with the ATTRIB command.
  392. ulAttribute cannot be set to Volume Label. To set volume-label information, issue DosProtectSetFileInfo with a logical drive number. Volume labels cannot be opened.
  393. cbFile affects the size of the file only when the file is new or is a replacement. If an existing file is opened, cbFile is ignored. To change the size of the existing file, issue DosProtectSetFileSizeL.
  394. The value in cbFile is a recommended size. If the full size cannot be allocated, the open request may still succeed. The file system makes a reasonable attempt to allocate the new size in an area that is as nearly contiguous as possible on the medium. When the file size is extended, the values of the new bytes are undefined.
  395. The Direct Open bit provides direct access to an entire disk or diskette volume, independent of the file system. This mode of opening the volume that is currently on the drive returns a handle to the calling function; the handle represents the logical volume as a single file. The calling function specifies this handle with a DosDevIOCtl Category 8, DSK_LOCKDRIVE request to prevent other processes from accessing the logical volume. When you are finished using the logical volume, issue a DosDevIOCtl Category 8, DSK_UNLOCKDRIVE request to allow other processes to access the logical volume.
  396. The file-handle state bits can be set by DosProtectOpenL and DosProtectSetFHState. An application can query the file-handle state bits, as well as the rest of the Open Mode field, by issuing DosProtectQueryFHState.
  397. You can use an EAOP2 structure to set extended attributes in peaop2 when creating a file, replacing an existing file, or truncating an existing file. No extended attributes are set when an existing file is just opened.
  398. A replacement operation is logically equivalent to atomically deleting and re-creating the file. This means that any extended attributes associated with the file also are deleted before the file is re-created.
  399. The pfhFileHandleLockID returned is required on each of the DosProtectxxx functions. An incorrect pfhFileHandleLockID on subsequent DosProtectxxx calls results in an ERROR_ACCESS_DENIED return code.
  400. The DosProtectxxx functions can be used with a NULL filehandle lockid, if the subject filehandle was obtained from DosOpen.
  401. *)
  402. type
  403. TDosProtectOpenL = function (FileName: PChar; var Handle: THandle;
  404. var Action: cardinal; InitSize: int64; Attrib,
  405. OpenFlags, OpenMode: cardinal; EA: PEAOp2;
  406. var FileHandleLockID: cardinal): cardinal; cdecl;
  407. function DummyDosProtectOpenL (FileName: PChar; var Handle: THandle;
  408. var Action: cardinal; InitSize: int64; Attrib,
  409. OpenFlags, OpenMode: cardinal; EA: PEAOp2;
  410. var FileHandleLockID: cardinal): cardinal; cdecl;
  411. (*
  412. DosProtectSetFilePtrL moves the read or write pointer according to the type
  413. of move specified.
  414. Parameters:
  415. Handle = the handle returned by a previous DosOpenL function.
  416. Pos = The signed distance (offset) to move, in bytes.
  417. Method = The method of moving - location in the file at which the read/write
  418. pointer starts before adding the Pos offset. The values and their
  419. meanings are as shown in the following list:
  420. 0 FILE_BEGIN - move the pointer from the beginning of the file.
  421. 1 FILE_CURRENT - move the pointer from the current location of the
  422. read/write pointer.
  423. 2 FILE_END - move the pointer from the end of the file; use this method
  424. to determine a file's size.
  425. PosActual = address of the new pointer location.
  426. FileHandleLockID = The filehandle lockid returned by a previous
  427. DosProtectOpenL.
  428. Possible return codes:
  429. 0 NO_ERROR
  430. 1 ERROR_INVALID_FUNCTION
  431. 6 ERROR_INVALID_HANDLE
  432. 132 ERROR_SEEK_ON_DEVICE
  433. 131 ERROR_NEGATIVE_SEEK
  434. 130 ERROR_DIRECT_ACCESS_HANDLE
  435. Remarks:
  436. The read/write pointer in a file is a signed 64-bit number. A negative value
  437. for Pos moves the pointer backward in the file; a positive value moves it
  438. forward. DosProtectSetFilePtrL cannot be used to move to a negative position in
  439. the file.
  440. DosProtectSetFilePtrL cannot be used for a character device or pipe.
  441. *)
  442. type
  443. TDosProtectSetFilePtrL = function (Handle: THandle; Pos: int64;
  444. Method: cardinal;
  445. var PosActual: int64; FileHandleLockID: cardinal): cardinal; cdecl;
  446. function DummyDosProtectSetFilePtrL (Handle: THandle; Pos: int64;
  447. Method: cardinal; var PosActual: int64;
  448. FileHandleLockID: cardinal): cardinal; cdecl;
  449. (*
  450. DosProtectSetFileSizeL changes the size of a file.
  451. Parameters:
  452. Handle = handle of the file whose size to be changed.
  453. Size = new size, in bytes, of the file.
  454. FileHandleLockID = the filehandle lockid obtained from DosProtectOpenL.
  455. Possible return codes:
  456. 0 NO_ERROR
  457. 5 ERROR_ACCESS_DENIED
  458. 6 ERROR_INVALID_HANDLE
  459. 26 ERROR_NOT_DOS_DISK
  460. 33 ERROR_LOCK_VIOLATION
  461. 87 ERROR_INVALID_PARAMETER
  462. 112 ERROR_DISK_FULL
  463. Remarks:
  464. When DosProtectSetFileSizeL is issued, the file must be open in a mode that
  465. allows write access.
  466. The size of the open file can be truncated or extended. If the file size is
  467. being extended, the file system tries to allocate additional bytes in
  468. a contiguous (or nearly contiguous) space on the medium. The values of the new
  469. bytes are undefined.
  470. *)
  471. type
  472. TDosProtectSetFileSizeL = function (Handle: THandle; Size: int64;
  473. FileHandleLockID: cardinal): cardinal; cdecl;
  474. function DummyDosProtectSetFileSizeL (Handle: THandle; Size: int64;
  475. FileHandleLockID: cardinal): cardinal; cdecl;
  476. const
  477. Sys_DosCancelLockRequestL: TDosCancelLockRequestL =
  478. @DummyDosCancelLockRequestL;
  479. Sys_DosSetFileLocksL: TDosSetFileLocksL = @DummyDosSetFileLocksL;
  480. Sys_DosProtectSetFileLocksL: TDosProtectSetFileLocksL =
  481. @DummyDosProtectSetFileLocksL;
  482. Sys_DosProtectOpenL: TDosProtectOpenL = @DummyDosProtectOpenL;
  483. Sys_DosProtectSetFilePtrL: TDosProtectSetFilePtrL =
  484. @DummyDosProtectSetFilePtrL;
  485. Sys_DosProtectSetFileSizeL: TDosProtectSetFileSizeL =
  486. @DummyDosProtectSetFileSizeL;
  487. {***************************************************************************}
  488. implementation
  489. {***************************************************************************}
  490. uses
  491. OS2Def;
  492. (*
  493. DosCreateThread2
  494. *)
  495. (*
  496. DosDumpProcess initiates a process dump from a specified process. This may be used as part of an error handling routine to gather information about an error that may be analyzed later using the OS/2 System Dump Formatter. Configuration of Process Dump may be done using the PDUMPSYS, PDUMPUSR, and PROCDUMP commands.
  497. APIRET APIENTRY DosDumpProcess (ULONG Flag, ULONG Drive, PID Pid)
  498. Parameters
  499. flag (ULONG) input
  500. Flags specify the function to be performed
  501. DDP_DISABLEPROCDUMP 0x00000000L Disable process dumps.
  502. DDP_ENABLEPROCDUMP 0x00000001L Enable process dumps.
  503. DDP_PERFORMPROCDUMP 0x00000002L Perform process dump.
  504. drive (ULONG) input
  505. The ASCII character for the drive on which process dump files are to be created. This is required only with the DDP_ENABLEPROCDUMP.
  506. Note: Use the PROCDUMP command to customize fully the drive and path.
  507. pid (PID) input
  508. The process to be dumped. 0L specified the current process; otherwise a valid process ID must be specified.
  509. Note: Use the PDUMPUSR command to specify what information will be dumped. Use the PROCDUMP command to customize options per process and in particular to specify whether child or parent process will be dumped. This parameter is actioned only with DDP_PERFORMPROCDUMP.
  510. Returns
  511. ulrc (APIRET) returns
  512. Return Code.
  513. DosDumpProcess returns the following value
  514. 87 ERROR_INVALID_PARAMETER
  515. Remarks
  516. For maximum flexibility the use of DosDumpProcess should be limited to the DDP_PERFORMPROCDUMP function. This allows you to specify whether Process Dump should be enabled through the use of the PROCDUMP command. You may customize Process Dump completely through use of the PDUMPUSR, PDUMPSYS, AND PROCDUMP commands. For further information, see PROCDUMP.DOC in the OS2\SYSTEM\RAS directory. DDP_ENABLEPROCDUMP and DDP_DISABLEPROCDUMP are provided for backwards compatibility only.
  517. DosDumpProcess
  518. *)
  519. (*
  520. DosForceSystemDump
  521. function DosGetProcessorStatus (...): cardinal; cdecl;
  522. external 'DOSCALLS' index 447;
  523. function DosQueryPageUsage (...): cardinal; cdecl;
  524. external 'DOSCALLS' index 358;
  525. *)
  526. (*
  527. DosSetProcessorStatus = DOSCALLS.448
  528. DosCreateSpinLock = DOSCALLS.449
  529. DosAcquireSpinLock = DOSCALLS.450
  530. DosReleaseSpinLock = DOSCALLS.451
  531. DosFreeSpinLock = DOSCALLS.452
  532. DosListIO
  533. DosListIOL
  534. DosPerfSystemCall
  535. DosQueryABIOSSuport
  536. function DosQueryMemState (...): cardinal; cdecl;
  537. external 'DOSCALLS' index 307;
  538. ___ function Dos16QueryModFromCS (...): ...
  539. external 'DOSCALLS' index 359;
  540. DosQueryModFromEIP
  541. *)
  542. (*
  543. The following API calls are made available through unit System:
  544. DosOpenL = DOSCALLS.981
  545. DosSetFilePtrL = DOSCALLS.988
  546. DosSetFileSizeL = DOSCALLS.989
  547. *)
  548. (* Todo:
  549. WSeB/eCS APIs:
  550. Creates a private Read/Write alias or an LDT code segment alias to part
  551. of an existing memory object. The alias object is accessible only to the
  552. process that created it. The original object must be accessible to the caller
  553. of DosAliasMem.
  554. An alias is removed by calling DosFreeMem with the alias address.
  555. Although it is possible to create a Read/Write alias to a code segment
  556. to allow code modification, this is not recommended. On Pentium processors,
  557. and later, pipe-lining techniques used by the processor might allow
  558. the processor not to be aware of the modified code, if appropriate
  559. pipe-line serialization is not performed by the programmer. For further
  560. information see the processor documentation.
  561. Possible return values:
  562. 0 No_Error
  563. 8 Error_Not_Enough_Memory
  564. 87 Error_Invalid_Parameter
  565. 95 Error_Interrupt
  566. 32798 Error_Crosses_Object_Boundary
  567. pMem = Pointer to the memory to be aliased. It must be on a page boundary
  568. (i.e. aligned to 4 kB), but may specify an address within a memory
  569. object.
  570. Size = Specifies size in bytes for the memory to alias. The entire range
  571. must lie within a single memory object and must be committed
  572. if OBJ_SELMAPALL is specified.
  573. Alias = Pointer where the address of the aliased memory is returned.
  574. The corresponding LDT selector is not explicitly returned but may be
  575. calculated by using the Compatibility Mapping Algorithm
  576. ((Alias shr 13) or 7).
  577. Flags = Combination of the following values:
  578. obj_SelMapAll = $800 (Create a Read/Write 32 bit alias
  579. to the address specified. The entire range
  580. must be committed, start on page boundary
  581. and be within the extent of a single memory
  582. object. An LDT selector is created to map
  583. the entire range specified. If obj_SelMapAll
  584. is not specified, then size is rounded up
  585. to a 4K multiple and the alias created
  586. inherits the permissions from the pages
  587. of the original object.)
  588. obj_Tile = $40 (Obj_Tile may be specified, but currently
  589. this is enforced whether or not specified.
  590. This forces LDT selectors to be based
  591. on 64K boundaries.)
  592. sel_Code = 1 (Marks the LDT alias selector(s)
  593. Read-Executable code selectors.)
  594. sel_Use32 = 2 (Used with obj_SelMapAll, otherwise ignored.
  595. Marks the first alias LDT selector
  596. as a 32 bit selector by setting the BIG/C32
  597. bit.)
  598. function DosAliasMem (pMem: pointer; Size: cardinal; var Alias: pointer; Flags: cardinal): cardinal; cdecl;
  599. external 'DOSCALLS' index 298;
  600. *)
  601. (*
  602. DosQueryThreadAffinity
  603. DosSetThreadAffinity
  604. Dos16SysTrace
  605. DosVerifyPidTid
  606. *)
  607. function DummyDosCancelLockRequestL (Handle: THandle; var Lock: TFileLockL): cardinal; cdecl;
  608. var
  609. Lock0: TFileLock;
  610. begin
  611. if (Lock.Offset > high (longint)) or (Lock.Range > high (longint)) or
  612. (Lock.Offset < 0) or (Lock.Range < 0) then
  613. DummyDosCancelLockRequestL := Error_Invalid_Parameter
  614. else
  615. begin
  616. Lock0.Offset := longint (Lock.Offset);
  617. Lock0.Range := longint (Lock.Range);
  618. DummyDosCancelLockRequestL := DosCancelLockRequest (Handle, Lock0);
  619. end;
  620. end;
  621. function DummyDosProtectSetFileLocksL (Handle: THandle; var Unlock: TFileLockL;
  622. var Lock: TFileLockL; Timeout: cardinal; Flags: cardinal;
  623. FileHandleLockID: cardinal): cardinal; cdecl;
  624. var
  625. Lock0: TFileLock;
  626. UnLock0: TFileLock;
  627. begin
  628. if (Lock.Offset > high (longint)) or (Lock.Range > high (longint)) or
  629. (Unlock.Offset > high (longint)) or (Unlock.Range > high (longint)) then
  630. DummyDosProtectSetFileLocksL := Error_Invalid_Parameter
  631. else
  632. begin
  633. Lock0.Offset := longint (Lock.Offset);
  634. Lock0.Range := longint (Lock.Range);
  635. Unlock0.Offset := longint (Unlock.Offset);
  636. Unlock0.Range := longint (Lock.Range);
  637. DummyDosProtectSetFileLocksL := DosProtectSetFileLocks (Handle, Unlock0,
  638. Lock0, Timeout, Flags, FileHandleLockID);
  639. end;
  640. end;
  641. function DummyDosSetFileLocksL (Handle: THandle; var Unlock: TFileLockL;
  642. var Lock: TFileLockL; Timeout: cardinal; Flags: cardinal): cardinal; cdecl;
  643. var
  644. Lock0: TFileLock;
  645. UnLock0: TFileLock;
  646. begin
  647. if (Lock.Offset > high (longint)) or (Lock.Range > high (longint)) or
  648. (Lock.Offset < 0) or (Lock.Range < 0) or
  649. (Unlock.Offset < 0) or (Unlock.Range < 0) or
  650. (Unlock.Offset > high (longint)) or (Unlock.Range > high (longint)) then
  651. DummyDosSetFileLocksL := Error_Invalid_Parameter
  652. else
  653. begin
  654. Lock0.Offset := longint (Lock.Offset);
  655. Lock0.Range := longint (Lock.Range);
  656. Unlock0.Offset := longint (Unlock.Offset);
  657. Unlock0.Range := longint (Lock.Range);
  658. DummyDosSetFileLocksL := DosSetFileLocks (Handle, Unlock0, Lock0, Timeout,
  659. Flags);
  660. end;
  661. end;
  662. function DummyDosProtectOpenL (FileName: PChar; var Handle: THandle;
  663. var Action: cardinal; InitSize: int64; Attrib,
  664. OpenFlags, OpenMode: cardinal; EA: PEAOp2;
  665. var FileHandleLockID: cardinal): cardinal; cdecl;
  666. begin
  667. if InitSize > high (longint) then
  668. DummyDosProtectOpenL := Error_Invalid_Parameter
  669. else
  670. DummyDosProtectOpenL := DosProtectOpen (FileName, Handle, Action,
  671. longint (InitSize), Attrib, OpenFlags, OpenMode, EA, FileHandleLockID);
  672. end;
  673. function DummyDosProtectSetFilePtrL (Handle: THandle; Pos: int64;
  674. Method: cardinal; var PosActual: int64;
  675. FileHandleLockID: cardinal): cardinal; cdecl;
  676. var
  677. PosActual0: cardinal;
  678. begin
  679. if (Pos < low (longint)) or (Pos > high (longint)) then
  680. DummyDosProtectSetFilePtrL := Error_Invalid_Parameter
  681. else
  682. begin
  683. DummyDosProtectSetFilePtrL := DosProtectSetFilePtr (Handle, longint (Pos),
  684. Method, PosActual0, FileHandleLockID);
  685. PosActual := PosActual0;
  686. end;
  687. end;
  688. function DummyDosProtectSetFileSizeL (Handle: THandle; Size: int64;
  689. FileHandleLockID: cardinal): cardinal; cdecl;
  690. begin
  691. if (Size > high (cardinal)) then
  692. DummyDosProtectSetFileSizeL := Error_Invalid_Parameter
  693. else
  694. DummyDosProtectSetFileSizeL := DosProtectSetFileSize (Handle,
  695. cardinal (Size), FileHandleLockID);
  696. end;
  697. var
  698. P: pointer;
  699. begin
  700. if FSApi64 then
  701. (* DosCallsHandle successfully initialized during initialization of unit *)
  702. (* System and basic 64-bit functions were loaded successfully. *)
  703. begin
  704. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32CancelLockRequestL, nil, P)
  705. = 0 then
  706. Sys_DosCancelLockRequestL := TDosCancelLockRequestL (P);
  707. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32ProtectSetFileLocksL, nil, P)
  708. = 0 then
  709. Sys_DosProtectSetFileLocksL := TDosProtectSetFileLocksL (P);
  710. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32SetFileLocksL, nil, P)
  711. = 0 then
  712. Sys_DosSetFileLocksL := TDosSetFileLocksL (P);
  713. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32ProtectOpenL, nil, P) = 0 then
  714. Sys_DosProtectOpenL := TDosProtectOpenL (P);
  715. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32ProtectSetFilePtrL, nil, P)
  716. = 0 then
  717. Sys_DosProtectSetFilePtrL := TDosProtectSetFilePtrL (P);
  718. if DosQueryProcAddr (DosCallsHandle, Ord_Dos32ProtectSetFileSizeL, nil, P)
  719. = 0 then
  720. Sys_DosProtectSetFileSizeL := TDosProtectSetFileSizeL (P);
  721. end;
  722. end.