Microsoft KB Archive/49375

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 19:24, 12 August 2020 by X010 (talk | contribs) (X010 moved page Microsoft KB Archive/Q49375 to Microsoft KB Archive/49375 without leaving a redirect: Text replacement - "Microsoft KB Archive/Q" to "Microsoft KB Archive/")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Using Access and Share Modes with DosOpen() PSS ID Number: Q49375 Article last modified on 12-19-1989 PSS database name: O_Os2SDK

1.10

OS/2

Summary:

When setting the parameter fsOpenMode to assign the access and share modes for a DosOpen() call, a share mode MUST be specified. An access mode may be bitwise ORed with the share mode, as well as one or more miscellaneous open flags.

Refer to the “DosOpen” section of the “Microsoft Operating System/2 Programmer’s Reference Volume 3,” Pages 95-98, for more information on DosOpen().

More Information:

Share modes specify what operations other processes can perform on the opened file. Every DosOpen() call must have a share mode specified. The following are the share modes available for DosOpen() in OS/2 Version 1.10:

 Constant                      Value
 --------                      ------
 OPEN_SHARE_DENYREADWRITE      0x0010
 OPEN_SHARE_DENYWRITE          0x0020
 OPEN_SHARE_DENYREAD           0x0030
 OPEN_SHARE_DENYNONE           Ox0040

An access mode may be bitwise ORed with the share mode. Access modes specify the operations the opening process may perform on the opened file. The access modes for DosOpen() in OS/2 1.10 are as follows:

 Constant                      Value
 --------                      ------
 OPEN_ACCESS_READONLY          0x0000
 OPEN_ACCESS_WRITEONLY         0x0001
 OPEN_ACCESS_READWRITE         0x0002

There are four other flags that may be ORed with the share mode in OS/2 1.10. These are:

 Constant                      Value
 --------                      ------
 OPEN_FLAGS_NO_INHERIT         0x0080
 OPEN_FLAGS_FAIL_ON_ERROR      0x2000
 OPEN_FLAGS_WRITE_THROUGH      0x4000
 OPEN_FLAGS_DASD               0x8000

When using DosOpen() to open a drive with OPEN_FLAGS_DASD (0x8000), an access mode of 10H is also required.

The following is a sample program using DosOpen():

  1. include<os2def.h> #include<bsedos.h> #include<stdio.h>

void main(void) { USHORT ret = 0; /* return code / USHORT Action; / DosOpen returns action taken / HFILE Handle; / file handle variable */

ret = DosOpen("direct.c",&Handle, &Action, 0L, FILE_NORMAL,
           FILE_OPEN, OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYNONE,
           0L);

printf("Return value = %hu, action = %hu\n", ret, Action);

}

Copyright Microsoft Corporation 1989.