home *** CD-ROM | disk | FTP | other *** search
- /*
- Show names, type, volids, and paths of all drives on the system.
- The default is hard disk only; floppies can be included upon
- request.
- Author: Roger A. McGregor
- Houston, Tx
- Date : 10/09/93
- Opsys : OS/2 2.0
- Compiles under both EMX C and IBM's's C compilers.
-
- */
- #define INCL_DOSMISC
- #define INCL_DOSFILEMGR
- #define INCL_DOSDEVICES
- #define INCL_DOSERRORS
-
- #ifdef __EMX__
- #define INCL_DOSDEVIOCTL
- #endif
-
- #include <os2.h>
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
-
- struct VOLINFO
- {ULONG volser;
- UCHAR label_length;
- CHAR label [12];
- char pad [256];
- };
-
- void do_help(char *prog_name)
- {printf("Program: %s Version 1.0 Oct 9, 1993\n", prog_name);
- printf("Purpose: Displays information about the attached disk drives.\n");
- printf("Optional parameters:\n");
- printf(" ALL - display will include floppy drives\n");
- printf(" x: - list of drives; ie. C: E:\n");
- printf(" HELP - this display\n");
- printf("The default is to list all hard drives.\n");
- }
-
- void show_volids(short drivenum)
- {short i;
- char drivename [3];
- APIRET rc, rc_volser;
- FSQBUFFER2 fsquebuf;
- ULONG fsquelen = sizeof(fsquebuf);
- struct VOLINFO buf;
- char *dtype, *dlabel, *dpath;
- ULONG pathnamelen;
- char pathname [512];
-
- drivename [0] = drivenum+'A'-1;
- drivename [1] =':';
- drivename [2] = 0;
-
- dlabel = " ";
- pathname [0] = 0;
-
- DosError(0); /* Disable hard-error pop-up */
- /* Get the drive status & volser */
- rc_volser = DosQueryFSInfo(drivenum, FSIL_VOLSER, &buf, sizeof(buf));
- if((NO_ERROR == rc_volser)
- || (ERROR_FILE_NOT_FOUND == rc_volser)
- || (ERROR_NOT_READY == rc_volser))
- ;
- else
- printf("DosQueryFSInfo VOLSER error= %d\n", rc_volser);
-
- if(ERROR_NOT_READY == rc_volser)
- dtype = "Not Rdy";
- else
- {
- if(ERROR_NO_VOLUME_LABEL != rc_volser)
- {if(buf.label_length)
- dlabel = (char *)&buf.label;
- }
-
- /* get type of disk drive */
- rc = DosQueryFSAttach(drivename, 1, 1,
- &fsquebuf, &fsquelen);
- if((NO_ERROR == rc) || (ERROR_BUFFER_OVERFLOW == rc))
- {
- switch(fsquebuf.iType)
- {case FSAT_CHARDEV : dtype = "Reschar";
- break;
- case FSAT_PSEUDODEV : dtype = "Pseudo ";
- break;
- case FSAT_LOCALDRV : dtype = "Local ";
- break;
- case FSAT_REMOTEDRV : dtype = "Remote ";
- break;
- default : dtype = "Other ";
- }
- }
- else
- printf("DosQueryFSAttach error = %d\n", rc);
-
- /* get the current path on the disk */
- pathnamelen = sizeof(pathname);
- if(0 !=
- (rc = DosQueryCurrentDir(drivenum, pathname, &pathnamelen)))
- printf("DosQueryPathInfo error = %d\n", rc);
- }
- DosError(1); /* Enable hard-error pop-up */
- printf("%-7s %s %-11s %s\n", dtype, drivename, dlabel, pathname);
- }
-
- int main(int argc, char **argv)
- {
- APIRET rc;
- ULONG current, disk_mask;
- short disk_count, drivenum,
- do_all = 0;
- char *request;
-
- request = 0;
- if(argc > 1) /* user requested help, a specific disk, or all */
- {request = (char *)malloc(strlen(argv[1]));
- strcpy(request, argv[1]);
- strupr(request);
- if(!strcmp("HELP", request))
- {do_help(argv[0]);
- return 0;
- }
- if(!strcmp("ALL", request))
- do_all = 1;
- if((2 == strlen(argv [1]))
- && (':' == argv[1][1])) /* possible disk list */
- do_all = 2;
- free(request);
- request = 0;
- if(0 == do_all)
- {printf("Usage: %s [ALL | C: D: etc | HELP]\n", argv [0]);
- printf(" default is to list all hard drives\n");
- return 0;
- }
- }
- if(rc = DosPhysicalDisk(INFO_COUNT_PARTITIONABLE_DISKS,
- &disk_count, sizeof(disk_count), 0, 0))
- {printf("Error %d obtaining disk count\n", rc);
- exit(4);
- }
- printf("%d partitionable disk(s) in system.\n", disk_count);
-
- rc = DosQueryCurrentDisk(¤t, &disk_mask);
- printf("Current disk is %c:\n", current+'A'-1);
-
- printf("Type Disk Label Path\n");
-
-
- if(2 == do_all) /* disk list? */
- {for(disk_count = 1; disk_count < argc; ++disk_count)
- { /* validate the drive name */
- request = argv[disk_count];
- if((2 == strlen(request))
- && (':' == request[1]) /* possible drive letter */
- && (isalpha(request[0])))
- {drivenum = toupper(request[0])-'A'+1; /* Get the drive number */
- current = 1;
- current <<= drivenum - 1;
- if(current & disk_mask)
- show_volids(drivenum);
- else
- printf("%11s Not mounted or unavailable\n", request);
- }
- else
- printf("%11s is not a valid drive name. Must be A: thru Z:\n",
- request);
- }
- return 0;
- }
-
- if (1 == do_all)
- drivenum = 1;
- else
- {drivenum = 3;
- disk_mask >>= 2; /* shift out current and A: and B: disks */
- }
- for (; disk_mask; ++drivenum, disk_mask >>= 1)
- {
- if(1 & disk_mask)
- show_volids(drivenum);
- }
- }