
        page    ,132
        title   V86CODE\lock.asm

.xlist
include v86seg.inc
.xcref
include basemaca.inc
include osmaca.inc
include oldmaca.inc
include demmac.inc
include dossymc.inc
include filemode.inc
include opncreat.inc
include error.inc
include mi.inc
include mvdmexp.inc
include demsvc.inc
include dirent.inc
include pdb.inc
include demdbcs.inc
include devhdr.inc
include dos3dev.inc
include syscalls.inc
include extattr.inc
include struc30.inc
include demcd.inc
.cref
.list
        CpuMode 386

        ReferV86    ConSwap,BYTE
        ReferV86    ConSFT,DWORD
        ReferV86    CurrentPDB,WORD
        ReferV86    Temp_Var,WORD
        ReferV86    ExtErr_Locus,BYTE
        ReferV86    ExtErr,WORD
        ReferV86    CURDRV,BYTE

V86LoL  SEGMENT
        EXTRN   CDSADDR: Dword
V86LoL  ENDS

V86CODE SEGMENT
        ASSUME  CS:V86GROUP,DS:NOTHING,ES:NOTHING,SS:NOTHING

        EXTRN   JFNFree:NEAR
        EXTRN   RMDevCheckName:NEAR
        EXTRN   RMDevAllocDI:NEAR
        EXTRN   pJFNFromHandle:NEAR
        EXTRN   Sys_Ret_OK:NEAR
        EXTRN   Sys_Ret_Err:NEAR
        EXTRN   Sys_Return:NEAR
        EXTRN   RMDevWrite:NEAR
        EXTRN   VSFNFromHandle:NEAR
        EXTRN   RMDevRead:NEAR
        EXTRN   Get_User_Stack:NEAR
        EXTRN   SFFromSFN:NEAR
        EXTRN   RMDevCloseDI:NEAR
        EXTRN   RMDevOpen:NEAR
        EXTRN   RMDevClose:NEAR
        EXTRN   $Alloc:NEAR
        EXTRN   $Dealloc:NEAR
        EXTRN   RMDevCheck:NEAR
        EXTRN   RMDevXFlags:NEAR
        EXTRN   FCB_Return:NEAR
        EXTRN   $GET_DATE:NEAR
        EXTRN   $GET_TIME:NEAR
        EXTRN   $GET_VERSION:NEAR



;***    $LockOper - Lock/Unlock file region
;
;       ENTRY   AL = 0 Lock AL = 1 Unlock
;               BX = handle
;               CX:DX - Start address of region to be locked
;               SI:DI - length of region
;
;       EXIT    Carry Clear
;                       it worked
;               Carry Set
;                       AX = ERROR_INVALID_HANDLE
;                          = ERROR_INVALID_FUNCTION
;                          = ERROR_LOCK_VIOLATION
;                          = ERROR_ACCESS_DENIED
;
        ASSUME  CS:V86GROUP,DS:NOTHING,ES:NOTHING,SS:NOTHING

Procedure $LockOper,near
        call    VSFNFromHandle          ; Get the VSFN
        .if     nc                      ; exit if bad handle
          call    RMDevCheck
          ;return ZF CY = file
          ;       ZF NC = OS/2 device
          ;       NZ NC = DOS device
          .if     c                     ; Skip if a device
            xor     ah,ah
            SVC     SVC_DEMLOCKOPER     ; Let OS/2 do all the work for files
            jc      short lk4           ; Skip if error
            jmp     Sys_Ret_OK          ; return A-OK
          .endif
        .endif

        mov     ax,ERROR_INVALID_HANDLE ; Can't lock a device
lk4:    jmp     Sys_Ret_Err
EndProc   $LockOper


V86CODE ENDS

        END
