DosQueryFSInfo

From EDM2
Revision as of 21:15, 28 March 2017 by Ak120 (Talk | contribs)

Jump to: navigation, search

Gets information from a file-system device.

Syntax

DosQueryFSInfo(disknum, infolevel, pBuf, cbBuf)

Parameters

disknum (ULONG) - input 
Logical drive number for the disk about which information is to be retrieved.
This parameter can be any value from 0 through 26. If this parameter is zero, information about the disk in the current drive is retrieved. Otherwise, 1 specifies drive A, 2 specifies drive B, and so on.
When a logical drive is specified, the media in the drive is examined (for a local drive only), and the request is passed to the file system driver (FSD) responsible for managing that media, or to the FSD that is attached to the drive.
infolevel (ULONG) - input 
Level of file information required.
Possible levels are described in the list below:
1 FSIL_ALLOC Level 1 information
2 FSIL_VOLSER Level 2 information
pBuf (PVOID) - output 
Address of the storage area where the system returns the requested level of file information.
Level 1 Information: When a value of 1 (FSIL_ALLOC) is specified for infolevel, the information is returned in the format of an FSALLOCATE structure.
Level 2 Information: When a value of 2 (FSIL_VOLSER) is specified for infolevel, the information is returned in the format of an FSINFO structure.
cbBuf (ULONG) - input 
The length, in bytes, of the buffer that receives the file-system information.

Return Code

ulrc (APIRET) - returns

DosQueryFSInfo returns one of the following values:

  • 0 NO_ERROR
  • 15 ERROR_INVALID_DRIVE
  • 111 ERROR_BUFFER_OVERFLOW
  • 124 ERROR_INVALID_LEVEL
  • 125 ERROR_NO_VOLUME_LABEL

Remarks

DosQueryFSInfo gets information from a file-system device.

If the disk or diskette has no volume label, the volume label is returned as a null string.

Trailing blanks supplied at the time the volume label is defined are not considered part of the label and are not returned by DosQueryFSInfo.

Example Code

The first example displays the volume label associated with a particular drive. The second example provides allocation information for a drive from the file system.

 #define INCL_DOSFILEMGR   /* File manager values  */
 #define INCL_DOSERRORS    /* DOS error values     */
 #include <os2.h>
 #include <stdio.h>

 int main(VOID) {

 ULONG       ulDriveNumber = 0;          /* Drive number */
 FSINFO      fsBuffer      = {0};        /* File system info buffer */
 APIRET      rc            = NO_ERROR;   /* Return code */

    ulDriveNumber = 3;          /* Specify drive C (A=1, B=2, C=3, ...) */

    rc = DosQueryFSInfo(ulDriveNumber,
                        FSIL_VOLSER,      /* Request volume information */
                        &fsBuffer,        /* Buffer for information     */
                        sizeof(FSINFO));     /* Size of buffer          */

    if (rc != NO_ERROR) {
        printf("DosQueryFSInfo error: return code = %u\n", rc);
        return 1;
    } else {
        printf("Volume label: '%s'\n", fsBuffer.vol.szVolLabel);
    }
    return NO_ERROR;
  }
#define INCL_DOSFILEMGR   /* File Manager values */
#define INCL_DOSERRORS    /* DOS Error values    */
#include <os2.h>
#include <stdio.h>

int main (VOID) {
   FSALLOCATE fsaBuffer     = {0};         /* File system info buffer     */
   APIRET  rc               = NO_ERROR;    /* Return code                 */

   rc = DosQueryFSInfo(3L,                     /* Drive number 3 (C:)     */
                       FSIL_ALLOC,             /* Level 1 allocation info */
                       (PVOID)&fsaBuffer,      /* Buffer                  */
                       sizeof(FSALLOCATE));    /* Size of buffer          */

   if (rc != NO_ERROR) {
      printf("DosQueryFSInfo error: return code = %u\n", rc);
      return 1;
   } else {
      printf ("%12ld bytes in each allocation unit.\n",
               fsaBuffer.cSectorUnit * fsaBuffer.cbSector);
             /* (Sectors per allocation unit) * (Bytes per sector) */
      printf ("%12ld total allocation units.\n", fsaBuffer.cUnit);
      printf ("%12ld available allocation units on disk.\n", fsaBuffer.cUnitAvail);
   }
   DosExit(EXIT_THREAD,fsaBuffer.cUnitAvail);  /* Return available allocation units
                                             to the initiating process      */
   return NO_ERROR;
}

Related Functions