Important: The information in this document is obsolete and should not be used for new development.
PBLockRange
You can use thePBLockRange
function to lock a portion of a file.
FUNCTION PBLockRange (paramBlock: ParmBlkPtr; async: Boolean): OSErr;
paramBlock
- A pointer to a basic File Manager parameter block.
async
- A Boolean value that specifies asynchronous (
TRUE) or synchronous (FALSE) execution.
--> ioCompletion
ProcPtr
A pointer to a completion routine. <-- ioResult
OSErr
The result code of the function. --> ioRefNum
Integer
A file reference number. --> ioReqCount
LongInt
The number of bytes in the range. --> ioPosMode
Integer
The positioning mode. --> ioPosOffset
LongInt
The positioning offset. DESCRIPTION
ThePBLockRange
function locks a portion of a file that was opened with shared
read/write permission. The beginning of the range to be locked is determined by theioPosMode
andioPosOffset
fields. The end of the range to be locked is determined by the beginning of the range and theioReqCount
field. For example, to lock the
first 50 bytes in a file, setioReqCount
to 50,ioPosMode
tofsFromStart
, andioPosOffset
to 0. SetioReqCount
to -1 to lock the maximum number of bytes from the position specified inioPosOffset
.The
PBLockRange
function uses the same parameters as bothPBRead
andPBWrite
; by calling it immediately beforePBRead
, you can use the information in the parameter block for thePBRead
call.When you're finished with the data (typically after a call to
PBWrite
), be sure to callPBUnlockRange
to free that portion of the file for subsequentPBRead
calls.SPECIAL CONSIDERATIONS
ThePBLockRange
function does nothing if the file specified in theioRefNum
field is open with shared read/write permission but is not located on a remote server volume
or is not located under a share point on a sharable local volume. See "Locking and Unlocking File Ranges" on page 2-50 for a simple way to determine whether callingPBLockRange
on an open file would in fact lock a range of bytes.
- WARNING
- In system software versions 6.0.7 and earlier, specifying
ioPosMode
asfsFromLEOF
results in the wrong byte range being locked.ASSEMBLY-LANGUAGE INFORMATION
The trap macro and routine selector forPBLockRange
are
Trap macro Selector _HFSDispatch $0010 RESULT CODES
noErr 0 No error ioErr -36 I/O error fnOpnErr -38 File not open eofErr -39 Logical end-of-file reached fLckdErr -45 File is locked by another user paramErr -50 Negative ioReqCount
rfNumErr -51 Bad reference number extFSErr -58 External file system volGoneErr -124 Server volume has been disconnected afpNoMoreLocks -5015 No more ranges can be locked afpRangeOverlap -5021 Part of range is already locked