Jump to content

DosCancelLockRequestL: Difference between revisions

From EDM2
Ak120 (talk | contribs)
Ak120 (talk | contribs)
mNo edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Description==
DosCancelLockRequestL cancels an outstanding DosSetFileLocksL request.
DosCancelLockRequestL cancels an outstanding DosSetFileLocksL request.  


==Syntax==
==Syntax==
<PRE>
  DosCancelLockRequestL (hFile, pflLock)
#define INCL DOSFILEMGR
#include os2.h


    APIRET DosCancelLockRequestL (HFILE hFile, PFILELOCKL pflLock)
</PRE>
==Parameters==
==Parameters==
; hFile HFILE) input : File handle used in the DosSetFileLocksL function that is to be cancelled.  
;hFile (HFILE) input : File handle used in the [[DosSetFileLocksL]] function that is to be cancelled.
;pflLockL (PFILELOCKL) input : Address of the structure describing the lock request to cancel.


; pflLockL PFILELOCKL) input : Address of the structure describing the lock request to cancel.
==Return Code==
==Return Code==
ulrc APIRET) returns
;ulrc (APIRET) returns:DosCancelLockRequestL returns one of the following values
 
* 0 NO_ERROR
DosCancelLockRequestL returns one of the following values
*   ERROR_INVALID_HANDLE
 
* 87 ERROR_INVALID_PARAMETER
* 0       NO_ERROR
* 173 ERROR_CANCEL_VIOLATION
*         ERROR_INVALID_HANDLE
* 87       ERROR_INVALID_PARAMETER  
* 173     ERROR_CANCEL_VIOLATION


==Remarks==
==Remarks==
DosCancelLockRequestL allows a process to cancel the lock range request of an outstanding DosSetFileLocksL function.
DosCancelLockRequestL allows a process to cancel the lock range request of an outstanding [[DosSetFileLocksL]] function.


If two threads in a process are waiting on a lock file range, and another thread issues DosCancelLockRequestL for that lock file range, then both waiting threads are released.
If two threads in a process are waiting on a lock file range, and another thread issues DosCancelLockRequestL for that lock file range, then both waiting threads are released.
Line 33: Line 25:


==Example Code==
==Example Code==
This example opens a file named CANLOCK.DAT , locks a block of the data, writes some data to it, and then cancels the lock request.
This example opens a file named CANLOCK.DAT, locks a block of the data, writes some data to it, and then cancels the lock request.
<PRE>
<PRE>
#define INCL_DOSFILEMGR      /* File Manager values */#define INCL_DOSERRORS        /* DOS Error values    */
#define INCL_DOSFILEMGR      /* File Manager values */
#include os2.h  
#define INCL_DOSERRORS        /* DOS Error values    */
#include stdio.h  
#include <os2.h>
#include string.h  
#include <stdio.h>
#include <string.h>


int main(VOID)   
int main(VOID){
  HFILE    FileHandle  = NULLHANDLE; /* File handle */
  ULONG    Action      = 0,          /* Action taken by DosOpenL */
            Wrote        = 0;          /* Number of bytes written by DosWrite */
  CHAR      FileData 40  = "Forty bytes of demonstration text data\r\n";
  APIRET    rc          = NO_ERROR;    /* Return code */


HFILE    FileHandle   = NULLHANDLE;  /* File handle */
   FILELOCKL LockArea     = 0,         /* Area of file to lock */
ULONG     Action      = 0,           /* Action taken by DosOpenL */
            UnlockArea  = 0;         /* Area of file to unlock */
Wrote        = 0;           /* Number of bytes written by DosWrite */
CHAR      FileData 40  = "Forty bytes of demonstration text data\r\n";
APIRET    rc          = NO_ERROR;    /* Return code */


FILELOCKL LockArea     = 0 ,        /* Area of file to lock */
  rc = DosOpenL("canlock.dat",                /* File to open */
UnlockArea   = 0 ;         /* Area of file to unlock */
                FileHandle,                  /* File handle */
                Action,                      /* Action taken */
                256,                        /* File primary allocation */
                FILE_ARCHIVED,              /* File attributes */
                FILE_OPEN | FILE_CREATE,    /* Open function type */
                OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE,
                0L);                        /* No extended attributes */
  if (rc != NO_ERROR)                        /* If open failed */
    printf("DosOpenL error  return code = %u\n", rc);
    return 1; 
   
  LockArea.lOffset = 0;              /* Start locking at beginning of file */
  LockArea.lRange =  40;              /* Use a lock range of 40 bytes      */
   UnLockArea.lOffset = 0;             /* Start unlocking at beginning of file */
  UnLockArea.lRange =  0;            /* Use a unlock range of 0 bytes      */


rc = DosOpenL("canlock.dat",                /* File to open */
  rc = DosSetFileLocksL(FileHandle,   /* File handle  */
FileHandle,                  /* File handle */
                        UnlockArea,   /* No unlock area */
Action,                      /* Action taken */
                        LockArea,     /* Lock current record */
256,                          /* File primary allocation */
                        2000L,       /* Lock time-out value of 2 seconds */
FILE_ARCHIVED,                /* File attributes */
                        0L);         /* Exclusive lock, not atomic */
FILE_OPEN | FILE_CREATE,      /* Open function type */
  if (rc != NO_ERROR)
OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE,
    printf("DosSetFileLocks error  return code = %u\n", rc);
0L);                          /* No extended attributes */
    return 1;
if (rc != NO_ERROR)                        /* If open failed */
printf("DosOpenL error  return code = %u\n", rc);
return 1; 
 
LockArea.lOffset = 0;              /* Start locking at beginning of file */
LockArea.lRange =  40;              /* Use a lock range of 40 bytes      */
UnLockArea.lOffset = 0;            /* Start unlocking at beginning of file */
UnLockArea.lRange =  0;            /* Use a unlock range of 0 bytes      */
 
rc = DosSetFileLocksL(FileHandle,       /* File handle  */
UnlockArea,       /* No unlock area */
LockArea,         /* Lock current record */
2000L,             /* Lock time-out value of 2 seconds */
0L);               /* Exclusive lock, not atomic */
if (rc != NO_ERROR)
printf("DosSetFileLocks error  return code = %u\n", rc);
return 1;
   
   
 
  rc = DosWrite(FileHandle, FileData, sizeof(FileData), Wrote);
rc = DosWrite(FileHandle, FileData, sizeof(FileData), Wrote);
  if (rc != NO_ERROR)
if (rc != NO_ERROR)
    printf("DosWrite error return code = %u\n", rc);
printf("DosWrite error return code = %u\n", rc);
    return 1;
return 1;
   
   
/* Should check if (rc != NO_ERROR) here... */
  /* Should check if (rc != NO_ERROR) here... */


LockArea.lOffset = 0;              /* Start locking at beginning of file */
  LockArea.lOffset = 0;              /* Start locking at beginning of file */
LockArea.lRange =  0;              /* Use a lock range of 40 bytes      */
  LockArea.lRange =  0;              /* Use a lock range of 40 bytes      */
UnLockArea.lOffset = 0;            /* Start locking at beginning of file */
  UnLockArea.lOffset = 0;            /* Start locking at beginning of file */
UnLockArea.lRange = 40;            /* Use a lock range of 40 bytes      */
  UnLockArea.lRange = 40;            /* Use a lock range of 40 bytes      */


rc = DosSetFileLocksL(FileHandle,       /* File handle   */
  rc = DosSetFileLocksL(FileHandle,   /* File handle */
UnlockArea,       /* Unlock area */
      UnlockArea,                   /* Unlock area */
LockArea,         /* No Lock */
      LockArea,                     /* No Lock */
2000L,             /* Lock time-out value of 2 seconds */
      2000L,                         /* Lock time-out value of 2 seconds */
0L);               /* Exclusive lock, not atomic */
      0L);                           /* Exclusive lock, not atomic */
if (rc != NO_ERROR)
  if (rc != NO_ERROR)
printf("DosSetFileLocksL error  return code = %u\n", rc);
    printf("DosSetFileLocksL error  return code = %u\n", rc);
return 1;
    return 1;
  rc = DosClose(FileHandle);
  /* Should check if (rc != NO_ERROR) here... */
return NO_ERROR;
  rc = DosClose(FileHandle);
  rc = DosClose(FileHandle);
/* Should check if (rc != NO_ERROR) here... */
/* Should check if (rc != NO_ERROR) here... */


return NO_ERROR;
return NO_ERROR;
rc = DosClose(FileHandle);
}
/* Should check if (rc != NO_ERROR) here... */
</PRE>


return NO_ERROR;
</PRE>
==Related Functions==
==Related Functions==
* [[OS2 API:CPI:DosSetFileLocksL|DosSetFileLocksL]]
*[[DosSetFileLocksL]]
 


[[Category:The OS/2 API Project]]
[[Category:Dos]]

Latest revision as of 22:48, 7 January 2024

DosCancelLockRequestL cancels an outstanding DosSetFileLocksL request.

Syntax

DosCancelLockRequestL (hFile, pflLock)

Parameters

hFile (HFILE) input
File handle used in the DosSetFileLocksL function that is to be cancelled.
pflLockL (PFILELOCKL) input
Address of the structure describing the lock request to cancel.

Return Code

ulrc (APIRET) returns
DosCancelLockRequestL returns one of the following values
  • 0 NO_ERROR
  • ERROR_INVALID_HANDLE
  • 87 ERROR_INVALID_PARAMETER
  • 173 ERROR_CANCEL_VIOLATION

Remarks

DosCancelLockRequestL allows a process to cancel the lock range request of an outstanding DosSetFileLocksL function.

If two threads in a process are waiting on a lock file range, and another thread issues DosCancelLockRequestL for that lock file range, then both waiting threads are released.

Not all file-system drivers (FSDs) can cancel an outstanding lock request.

Local Area Network (LAN) servers cannot cancel an outstanding lock request if they use a version of the operating system prior to OS/2 Version 2.00.

Example Code

This example opens a file named CANLOCK.DAT, locks a block of the data, writes some data to it, and then cancels the lock request.

#define INCL_DOSFILEMGR       /* File Manager values */
#define INCL_DOSERRORS        /* DOS Error values    */
#include <os2.h>
#include <stdio.h>
#include <string.h>

int main(VOID){
  HFILE     FileHandle   = NULLHANDLE;  /* File handle */
  ULONG     Action       = 0,           /* Action taken by DosOpenL */
            Wrote        = 0;           /* Number of bytes written by DosWrite */
  CHAR      FileData 40  = "Forty bytes of demonstration text data\r\n";
  APIRET    rc           = NO_ERROR;    /* Return code */

  FILELOCKL LockArea     = 0,         /* Area of file to lock */
            UnlockArea   = 0;         /* Area of file to unlock */

  rc = DosOpenL("canlock.dat",                /* File to open */
                 FileHandle,                  /* File handle */
                 Action,                      /* Action taken */
                 256,                         /* File primary allocation */
                 FILE_ARCHIVED,               /* File attributes */
                 FILE_OPEN | FILE_CREATE,     /* Open function type */
                 OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE,
                 0L);                         /* No extended attributes */
  if (rc != NO_ERROR)                         /* If open failed */
    printf("DosOpenL error  return code = %u\n", rc);
    return 1;  
 
  LockArea.lOffset = 0;               /* Start locking at beginning of file */
  LockArea.lRange =  40;              /* Use a lock range of 40 bytes       */
  UnLockArea.lOffset = 0;             /* Start unlocking at beginning of file */
  UnLockArea.lRange =  0;             /* Use a unlock range of 0 bytes       */

  rc = DosSetFileLocksL(FileHandle,   /* File handle   */
                        UnlockArea,   /* No unlock area */
                        LockArea,     /* Lock current record */
                        2000L,        /* Lock time-out value of 2 seconds */
                        0L);          /* Exclusive lock, not atomic */
  if (rc != NO_ERROR)
    printf("DosSetFileLocks error  return code = %u\n", rc);
    return 1;
 
  rc = DosWrite(FileHandle, FileData, sizeof(FileData), Wrote);
  if (rc != NO_ERROR)
    printf("DosWrite error return code = %u\n", rc);
    return 1;
 
  /* Should check if (rc != NO_ERROR) here... */

  LockArea.lOffset = 0;               /* Start locking at beginning of file */
  LockArea.lRange =  0;               /* Use a lock range of 40 bytes       */
  UnLockArea.lOffset = 0;             /* Start locking at beginning of file */
  UnLockArea.lRange = 40;             /* Use a lock range of 40 bytes       */

  rc = DosSetFileLocksL(FileHandle,   /* File handle  */
       UnlockArea,                    /* Unlock area */
       LockArea,                      /* No Lock */
       2000L,                         /* Lock time-out value of 2 seconds */
       0L);                           /* Exclusive lock, not atomic */
  if (rc != NO_ERROR)
    printf("DosSetFileLocksL error  return code = %u\n", rc);
    return 1;
  rc = DosClose(FileHandle);
  /* Should check if (rc != NO_ERROR) here... */
 
 return NO_ERROR;
 rc = DosClose(FileHandle);
/* Should check if (rc != NO_ERROR) here... */

return NO_ERROR;
}

Related Functions