home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / dmap00.zip / dmap.c next >
Text File  |  1993-10-17  |  5KB  |  189 lines

  1. /* 
  2.  Show names, type, volids, and paths of all drives on the system.
  3.  The default is hard disk only; floppies can be included upon
  4.  request.
  5.  Author: Roger A. McGregor
  6.          Houston, Tx
  7.  Date  : 10/09/93
  8.  Opsys : OS/2 2.0
  9.  Compiles under both EMX C and IBM's's C compilers.
  10.  
  11. */
  12. #define INCL_DOSMISC
  13. #define INCL_DOSFILEMGR
  14. #define INCL_DOSDEVICES
  15. #define INCL_DOSERRORS
  16.  
  17. #ifdef __EMX__
  18. #define INCL_DOSDEVIOCTL
  19. #endif
  20.  
  21. #include <os2.h>
  22.  
  23. #include <stdlib.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <ctype.h>
  27.  
  28. struct VOLINFO
  29.         {ULONG volser;
  30.          UCHAR label_length;
  31.          CHAR label [12];
  32.          char pad [256];
  33.          };
  34.  
  35. void do_help(char *prog_name)
  36. {printf("Program: %s  Version 1.0 Oct 9, 1993\n", prog_name);
  37.  printf("Purpose: Displays information about the attached disk drives.\n");
  38.  printf("Optional parameters:\n");
  39.  printf("  ALL  - display will include floppy drives\n");
  40.  printf("  x:   - list of drives; ie. C: E:\n");
  41.  printf("  HELP - this display\n");
  42.  printf("The default is to list all hard drives.\n");
  43. }
  44.  
  45. void show_volids(short drivenum)
  46. {short i;
  47. char drivename [3];
  48. APIRET rc, rc_volser;
  49. FSQBUFFER2 fsquebuf;
  50. ULONG fsquelen = sizeof(fsquebuf);
  51. struct VOLINFO buf;
  52. char *dtype, *dlabel, *dpath;
  53. ULONG pathnamelen;
  54. char pathname [512];
  55.  
  56. drivename [0] = drivenum+'A'-1;
  57. drivename [1] =':';
  58. drivename [2] = 0;
  59.  
  60. dlabel = " ";
  61. pathname [0] = 0;
  62.  
  63. DosError(0);                         /* Disable hard-error pop-up  */
  64.     /* Get the drive status & volser */
  65. rc_volser = DosQueryFSInfo(drivenum, FSIL_VOLSER, &buf, sizeof(buf));
  66. if((NO_ERROR == rc_volser) 
  67.   || (ERROR_FILE_NOT_FOUND == rc_volser)
  68.   || (ERROR_NOT_READY == rc_volser))
  69.    ;
  70. else
  71.    printf("DosQueryFSInfo VOLSER error= %d\n", rc_volser);
  72.  
  73. if(ERROR_NOT_READY == rc_volser)
  74.     dtype = "Not Rdy";
  75. else
  76.    {
  77.     if(ERROR_NO_VOLUME_LABEL != rc_volser)
  78.       {if(buf.label_length)
  79.          dlabel = (char *)&buf.label;
  80.       }
  81.  
  82.    /* get type of disk drive */
  83.     rc = DosQueryFSAttach(drivename, 1, 1,
  84.                           &fsquebuf, &fsquelen);
  85.     if((NO_ERROR == rc) || (ERROR_BUFFER_OVERFLOW == rc))
  86.        {
  87.         switch(fsquebuf.iType)
  88.          {case FSAT_CHARDEV :   dtype = "Reschar";
  89.              break;
  90.           case FSAT_PSEUDODEV : dtype = "Pseudo ";
  91.              break;
  92.           case FSAT_LOCALDRV :  dtype = "Local  ";
  93.              break;
  94.           case FSAT_REMOTEDRV : dtype = "Remote ";
  95.              break;
  96.           default :             dtype = "Other  ";
  97.          }
  98.        }
  99.     else
  100.        printf("DosQueryFSAttach error = %d\n", rc);
  101.  
  102.         /* get the current path on the disk */
  103.     pathnamelen = sizeof(pathname);
  104.     if(0 !=
  105.        (rc = DosQueryCurrentDir(drivenum, pathname, &pathnamelen)))
  106.           printf("DosQueryPathInfo error = %d\n", rc);
  107.    }
  108. DosError(1);                         /* Enable hard-error pop-up   */
  109. printf("%-7s  %s  %-11s %s\n", dtype, drivename, dlabel, pathname);
  110. }
  111.  
  112. int main(int argc, char **argv)
  113. {
  114. APIRET rc;
  115. ULONG current, disk_mask;
  116. short disk_count, drivenum,
  117.       do_all = 0;
  118. char *request;
  119.  
  120. request = 0;
  121. if(argc > 1)        /* user requested help, a specific disk, or all */
  122.     {request = (char *)malloc(strlen(argv[1]));
  123.      strcpy(request, argv[1]);
  124.      strupr(request);
  125.      if(!strcmp("HELP", request))
  126.         {do_help(argv[0]);
  127.          return 0;
  128.         }
  129.      if(!strcmp("ALL", request))
  130.         do_all = 1;
  131.      if((2 == strlen(argv [1]))
  132.        && (':' == argv[1][1]))  /* possible disk list */
  133.         do_all = 2;
  134.      free(request);
  135.      request = 0;
  136.      if(0 == do_all)
  137.         {printf("Usage: %s [ALL | C: D: etc | HELP]\n", argv [0]);
  138.          printf("       default is to list all hard drives\n");
  139.          return 0;
  140.         }
  141.     }
  142. if(rc = DosPhysicalDisk(INFO_COUNT_PARTITIONABLE_DISKS,
  143.                         &disk_count, sizeof(disk_count), 0, 0))
  144.     {printf("Error %d obtaining disk count\n", rc);
  145.      exit(4);
  146.     }
  147. printf("%d partitionable disk(s) in system.\n", disk_count);
  148.  
  149. rc = DosQueryCurrentDisk(¤t, &disk_mask);
  150. printf("Current disk is %c:\n", current+'A'-1);
  151.  
  152. printf("Type    Disk Label       Path\n");
  153.  
  154.  
  155. if(2 == do_all) /* disk list? */
  156.   {for(disk_count = 1; disk_count < argc; ++disk_count)
  157.       {  /* validate the drive name */
  158.        request = argv[disk_count];
  159.        if((2 == strlen(request))
  160.          && (':' == request[1])         /* possible drive letter */
  161.          && (isalpha(request[0])))
  162.            {drivenum = toupper(request[0])-'A'+1;  /* Get the drive number */
  163.             current = 1;
  164.             current <<= drivenum - 1;
  165.             if(current & disk_mask)
  166.                 show_volids(drivenum);
  167.             else
  168.                 printf("%11s Not mounted or unavailable\n", request);
  169.            }
  170.         else
  171.            printf("%11s is not a valid drive name. Must be A: thru Z:\n",
  172.                   request);
  173.       }
  174.    return 0;
  175.   }
  176.  
  177. if (1 == do_all)
  178.    drivenum = 1;
  179. else
  180.    {drivenum = 3;
  181.     disk_mask >>= 2;        /* shift out current and A: and B: disks */
  182.    }
  183. for (; disk_mask; ++drivenum, disk_mask >>= 1)
  184.    {
  185.     if(1 & disk_mask)
  186.        show_volids(drivenum);
  187.    }
  188. }
  189.