/*static char *SCCSID = "@(#)cmgetfs.c	6.2 90/12/10";                                 */
/****************************************************************************/
/*                                                                          */
/*                       IBM/Microsoft Confidential                         */
/*                                                                          */
/*                 Copyright (c) IBM Corporation  1987, 1990                */
/*                 Copyright (c) Microsoft Corp.  1987, 1990                */
/*                           All Rights Reserved                            */
/*                                                                          */
/****************************************************************************/
/******* START OF SPECIFICATION ********************************/
/*                                                             */
/* SUBROUTINE  NAME:  comgetFSname                             */
/*                                                             */
/* DESCRIPTIVE NAME:  common routine to get FS name            */
/*                                                             */
/* FUNCTION: Determines file system name  and sets flag        */
/*           if the file system is FAT                         */
/*                                                             */
/* NOTES:                                                      */
/*                                                             */
/* ENTRY POINT:  comgetFSname                                  */
/*   LINKAGE:                                                  */
/*                                                             */
/* INPUT:                                                      */
/*        ptr to drive letter:                                 */
/*        ptr to fsname:                                       */
/*        ptr to fatflag:                                      */
/* EXIT-NORMAL:                                                */
/*                                                             */
/*        drive letter:     unchanged                          */
/*                                                             */
/*        fsname:           the file system name               */
/*                                                             */
/*        fatflag:          0 if non FAT file system           */
/*                          1 if FAT file system               */
/*                          2 unsure                           */
/* EXIT-ERROR:                                                 */
/*                 return code = 4 (terminate due to error)    */
/* EFFECTS:                                                    */
/*                                                             */
/* INTERNAL REFERENCES:   none                                 */
/*        ROUTINES:                                            */
/*                                                             */
/*                                                             */
/* EXTERNAL REFERENCES:   DOSQFSATTACH                         */
/*        ROUTINES:                                            */
/*                                                             */
/* NOTE:                                                       */
/*        This routine also displays the following messages    */
/*        when appropriate:                                    */
/*                                                             */
/*        Executing program %1.                                */
/*        Unable to execute the specified program.             */
/*                                                             */
/*                                                             */
/************ END OF SOURCE FILE SPECIFICATIONS ****************/

/* #include <doscall.h> */ /* csc */                  /* DOS call             */
#include "tmpdos16.h"
#include <utilmids.h>
#include <error.h>
#include <string.h>                    /* C run time func      */
#include <comsub.h>

#define MAXPATHLEN 256    /* csc */

extern unsigned char chkboot( unsigned char *);

/*----------------------------------------------------------------------*/
/*             data structures and variables                            */
/*----------------------------------------------------------------------*/
  /* In the following structure, szName, szFSDName and rgFSAData */
  /* are variable length, we will reference them by pointers     */


struct IFS_data      {
        unsigned short iType;
        unsigned short cbName;          /* length of szName   */
        unsigned char  szName[MAXPATHLEN];      /* szName should be variable length */
        unsigned short cbFSDName;       /* length of FSDName  */
        unsigned char  szFSDName[MAXPATHLEN];   /* szFSDName should be variable len */
        unsigned short cbFSAData;       /* length of FSAData  */
        unsigned char  rgFSAData[MAXPATHLEN];   /* rgFSAData should be variable len */
        } DataBuffer;

comgetFSname(drive, fsname, fatflag)
char *drive;
char *fsname;
unsigned char *fatflag;
{
#define      STD_OUTPUT        0
#define      STD_ERROR         1
#define      INSERT            1         /* insert varialbe into msg    */
#define      LEVEL1            1
#define      ORDINAL           1

unsigned short rc = 0;
unsigned short DataBufferLen;
char     *ptr;


       *fatflag = 0;             /* initialize flag to NONE FAT */
       DataBufferLen = sizeof(struct IFS_data);

       rc = DOSQFSATTACH(
             (char _far16 *    ) drive,        /*  drive letter               */
             (unsigned short      ) ORDINAL,      /*  Ordinal always starts at 1 */
             (unsigned short      ) LEVEL1,       /*  Level 1 returns data for the */
                                            /*  specific drive or device     */
                                            /*  name refered to by devicename*/
             (char _far16 * ) &DataBuffer,     /*  the return info buffer   */
             (unsigned short _far16 *) &DataBufferLen, /* the return buffer len   */
             (unsigned long)  0 );            /* reserved (must be zero) */


     if ( rc == 0 ) {
           ptr = DataBuffer.szName;
           ptr = ptr + DataBuffer.cbName + 1;/* to get to cbFSDName  */
           ptr = ptr + 2;                    /* to get to szFSDName  */
           strcpy(fsname, ptr);              /* pass back the FS name */
           if ( !strcmpi(fsname,"UNKNOWN") ) {/* if do not know the fat type*/
              *fatflag = chkboot(drive); /* 1 - FAT  0 - NONFAT  2 - not sure*/
              if ( *fatflag == 2 )
                 return( ERROR_NOT_DOS_DISK) ;
           } else if ( !strcmpi(fsname, "FAT") ) {
                 *fatflag = 1;
           }
           com_dispmsg(MSG_CMM_FS_TYPE,STD_OUTPUT,INSERT, fsname);
     }


       return(rc);

}
