Jump to content

DosQueryCurrentDisk: Difference between revisions

From EDM2
Ak120 (talk | contribs)
mNo edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==DosQueryCurrentDisk==
DosQueryCurrentDisk is used to query which drive is the current default drive for the process and to get the drives available.
 
 
===Syntax===
 
rc = DosQueryCurrentDisk( ''pulDrive'', ''pulLogical'' );
 
===Parameters===
 
; PULONG ''pulDrive'' (output)
: Pointer to the current drive number. (1=A, 2=B etc.)
; PULONG ''pulLogical'' (output)
: Pointer to a 32-bit bit area where each of the 26 lowest bits represents a drive (0=A, 1=B etc.) If bit n is set(=1) then the drive corresponding to n exists.


===Returns===
==Syntax==
DosQueryCurrentDisk(pdisknum, plogical)


; APIRET rc
==Parameters==
: 0 NO_ERROR
;pdisknum (PULONG) - output: Address of the number of the default drive.
:The value 1 means drive A, 2 means drive B, 3 means drive C, and so on. The maximum possible value is 26, which corresponds to drive Z. (Pointer to the current drive number. (1=A, 2=B etc.))
;plogical (PULONG) - output: Address of the bit map where the system returns the mapping of the logical drives.
:This bit map is stored in the low-order portion of the 32-bit area. (Pointer to a 32-bit bit area where each of the 26 lowest bits represents a drive (0=A, 1=B etc.) If bit n is set(=1) then the drive corresponding to n exists.)
:Logical drives A to Z have one-to-one mapping with bit positions 0 to 25 of the map; for example, bit 0 represents drive A, bit 1 represents drive B, and so on. The settings of these bits indicate which drives exist, as follows:
::0 - The logical drive does not exist.
::1 - The logical drive exists.


===Include Info===
==Returns==
;ulrc (APIRET) - returns:DosQueryCurrentDisk returns the following value:
* 0 NO_ERROR


#define INCL_DOSFILEMGR
==Sample Code==
#include <os2.h>
<code>
 
===Usage Explanation===
 
DosQueryCurrentDisk is used to query which drive is the current default drive for the process and to get the drives available.
 
===Relevant Structures===
 
===Gotchas===
 
===Sample Code===
  #define INCL_DOSFILEMGR
  #define INCL_DOSFILEMGR
  #include <os2.h>
  #include <os2.h>
Line 42: Line 29:
  rc=DosQueryCurrentDisk(&ulDrive, &ulLogical);        /* Get current drive  */
  rc=DosQueryCurrentDisk(&ulDrive, &ulLogical);        /* Get current drive  */
  printf("Current Drive is %c.\n",(char)ulDrive+'A'-1); /* Print current drive */
  printf("Current Drive is %c.\n",(char)ulDrive+'A'-1); /* Print current drive */
</code>
This example displays information about the current disk and logical drives.
<PRE>
#define INCL_DOSFILEMGR  /* File Manager values */
#define INCL_DOSERRORS    /* DOS Error values    */
#include <os2.h>
#include <stdio.h>
#include <string.h>
int main(VOID) {
  ULONG  ulDriveNum  = 0;      /* Drive number (A=1, B=2, C=3, ...)    */
  ULONG  ulDriveMap  = 0;      /* Mapping of valid drives              */
  ULONG  i            = 0;      /* A loop index                        */
  APIRET  rc          = NO_ERROR;  /* Return code                      */
  rc = DosQueryCurrentDisk (&ulDriveNum, &ulDriveMap);
  if (rc != NO_ERROR) {
      printf ("DosQueryCurrentDisk error : return code = %u\n", rc);
      return 1;
  }
  printf ("Current disk = %c\n", 'A' + ulDriveNum - 1);
  printf ("Logical disks: ");
  printf ("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z\n");
  printf ("        valid? ");
    /* Each bit in the ulDriveMap corresponds to a specific logical drive.
        bit 0 = A:, bit 1 = B:, ... , bit 24 = Y:, bit 25 = Z:
        For each drive, shift the bit string to the left to get rid of
        the bits before the one we want, then shift that result right 31
        bits to leave just the one we are interested in. */
  for (i = 0; i < 26; i++) {
    printf (( (ulDriveMap<<(31-i)) >> 31) ? "Y " : "- ");
    }
  printf ("\n");                          /* Print a newline character */


===See Also===
  return NO_ERROR;
}
</PRE>


* [[OS2 API:CPI:DosSetDefaultDisk|DosSetDefaultDisk]]
==Related Functions==
*[[DosSetDefaultDisk]]


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

Latest revision as of 04:42, 1 December 2019

DosQueryCurrentDisk is used to query which drive is the current default drive for the process and to get the drives available.

Syntax

DosQueryCurrentDisk(pdisknum, plogical)

Parameters

pdisknum (PULONG) - output
Address of the number of the default drive.
The value 1 means drive A, 2 means drive B, 3 means drive C, and so on. The maximum possible value is 26, which corresponds to drive Z. (Pointer to the current drive number. (1=A, 2=B etc.))
plogical (PULONG) - output
Address of the bit map where the system returns the mapping of the logical drives.
This bit map is stored in the low-order portion of the 32-bit area. (Pointer to a 32-bit bit area where each of the 26 lowest bits represents a drive (0=A, 1=B etc.) If bit n is set(=1) then the drive corresponding to n exists.)
Logical drives A to Z have one-to-one mapping with bit positions 0 to 25 of the map; for example, bit 0 represents drive A, bit 1 represents drive B, and so on. The settings of these bits indicate which drives exist, as follows:
0 - The logical drive does not exist.
1 - The logical drive exists.

Returns

ulrc (APIRET) - returns
DosQueryCurrentDisk returns the following value:
  • 0 NO_ERROR

Sample Code

#define INCL_DOSFILEMGR
#include <os2.h>
#include <stdio.h>   /* For printf */

ULONG ulDrive;
ULONG ulLogical;
APIRET rc;

rc=DosQueryCurrentDisk(&ulDrive, &ulLogical);         /* Get current drive   */
printf("Current Drive is %c.\n",(char)ulDrive+'A'-1); /* Print current drive */

This example displays information about the current disk and logical drives.

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

int main(VOID) {
   ULONG   ulDriveNum   = 0;      /* Drive number (A=1, B=2, C=3, ...)    */
   ULONG   ulDriveMap   = 0;      /* Mapping of valid drives              */
   ULONG   i            = 0;      /* A loop index                         */
   APIRET  rc           = NO_ERROR;  /* Return code                       */

   rc = DosQueryCurrentDisk (&ulDriveNum, &ulDriveMap);

   if (rc != NO_ERROR) {
      printf ("DosQueryCurrentDisk error : return code = %u\n", rc);
      return 1;
   }
   printf ("Current disk = %c\n", 'A' + ulDriveNum - 1);
   printf ("Logical disks: ");
   printf ("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z\n");
   printf ("        valid? ");

     /* Each bit in the ulDriveMap corresponds to a specific logical drive.
        bit 0 = A:, bit 1 = B:, ... , bit 24 = Y:, bit 25 = Z:
        For each drive, shift the bit string to the left to get rid of
        the bits before the one we want, then shift that result right 31
        bits to leave just the one we are interested in. */

  for (i = 0; i < 26; i++) {
     printf (( (ulDriveMap<<(31-i)) >> 31) ? "Y " : "- ");
    }
   printf ("\n");                          /* Print a newline character */

   return NO_ERROR;
}

Related Functions