|
|
1.1 ! root 1: /**************************************************************************** ! 2: * ! 3: * PROGRAM: DRIVES.C ! 4: * ! 5: * PURPOSE: Determines all drives in the system, both local and remote, ! 6: * and their file system type ! 7: * ! 8: * FUNCTIONS: ! 9: * ! 10: * CheckRM() - verifies that a removeable media drive contains a disk ! 11: * GVI() - gets the volume information for a drive and prints out the ! 12: * file system type ! 13: * UpdateBuffer() - updates string pointer to the next string in an array ! 14: * of strings ! 15: * ! 16: * COMMENTS: ! 17: * ! 18: ****************************************************************************/ ! 19: ! 20: #include <windows.h> ! 21: #include <stdio.h> ! 22: #include <string.h> ! 23: #include "drives.h" ! 24: ! 25: #define BUFSIZE 2048 ! 26: ! 27: CHAR chBuffer[BUFSIZE]; ! 28: ! 29: /**************************************************************************** ! 30: * ! 31: * FUNCTION: CheckRM(LPTSTR) ! 32: * ! 33: * PURPOSE: Verifies that a removeable media drive contains a disk ! 34: * ! 35: * COMMENTS: ! 36: * ! 37: * This function is called each time a drive type is determined to be ! 38: * removeable (DRIVE_REMOVEABLE). An attempt is made to open a ! 39: * file in the root directory of the drive. If the attempt succeeds, ! 40: * then media is present in the drive and subsequent calls to the ! 41: * drive can be safely made. If the call fails, then there is no media ! 42: * present in the drive and no attempts should be made to access this ! 43: * drive. The Error Mode is temporarily set to 1 to allow failures ! 44: * to immediately return to the calling program. This eliminates ! 45: * unwanted dialog boxes that prompt for disks to be placed in the ! 46: * drive. ! 47: * ! 48: * INPUT: lpszDriveName - removeable media drive name (ex - "a:") ! 49: * ! 50: * OUTPUT: Returns TRUE if media present ! 51: * FALSE if media is not present ! 52: * ! 53: ****************************************************************************/ ! 54: ! 55: BOOL CheckRM(LPTSTR lpszDriveName) ! 56: { ! 57: int iRC; ! 58: LPTSTR lpszFileName=" "; ! 59: OFSTRUCT ofstruct; ! 60: WORD wStyle=OF_EXIST; ! 61: ! 62: SetErrorMode(1); ! 63: strcpy(lpszFileName,lpszDriveName); ! 64: strcat(lpszFileName,"."); ! 65: iRC=OpenFile(lpszFileName,&ofstruct,wStyle); ! 66: SetErrorMode(0); ! 67: if (iRC==-1) ! 68: return (FALSE); ! 69: _lclose(iRC); ! 70: return (TRUE); ! 71: } ! 72: ! 73: /**************************************************************************** ! 74: * ! 75: * FUNCTION: GVI(LPTSTR, LPTSTR, DWORD) ! 76: * ! 77: * PURPOSE: gets the Volume Information for the specified drive and prints ! 78: * the file system type ! 79: * ! 80: * COMMENTS: ! 81: * This function makes a call to GetVolumeInformation. The file system ! 82: * type is returned in the szSystemName buffer. The file system type ! 83: * is printed to the screen. ! 84: * ! 85: * INPUT: lpszDriveName - pointer to the drive name (ex - "a:") ! 86: * lpszSystemName - pointer to the system name buffer. This will ! 87: * be filled in by the GetVolumeInformation call ! 88: * (e.g. FAT, HPFS) ! 89: * nSystemNameSize - size of the lpszSystemName buffer ! 90: * ! 91: * OUTPUT: None ! 92: * ! 93: ****************************************************************************/ ! 94: ! 95: VOID GVI(LPTSTR lpszDriveName,LPTSTR lpszSystemName, DWORD nSystemNameSize) ! 96: { ! 97: BOOL bRC; ! 98: ! 99: bRC=GetVolumeInformation(lpszDriveName, ! 100: NULL, ! 101: NULL, ! 102: NULL, ! 103: NULL, ! 104: NULL, ! 105: lpszSystemName, ! 106: nSystemNameSize); ! 107: printf("File system = %s",lpszSystemName); ! 108: } ! 109: ! 110: /**************************************************************************** ! 111: * ! 112: * FUNCTION: UpdateBuffer(LPTSTR) ! 113: * ! 114: * PURPOSE: updates string pointer to the next string in an array ! 115: * of strings ! 116: * ! 117: * COMMENTS: ! 118: * ! 119: * INPUT: lpszString - pointer to an array of zero terminated strings. ! 120: * The final string is terminated with a double null. ! 121: * ! 122: * OUTPUT: modified pointer that points to the next string in the array ! 123: * ! 124: ****************************************************************************/ ! 125: ! 126: LPTSTR UpdateBuffer(LPTSTR lpszString) ! 127: { ! 128: return (lpszString+strlen(lpszString)+1); ! 129: } ! 130: ! 131: /**************************************************************************** ! 132: * ! 133: * FUNCTION: main() ! 134: * ! 135: * PURPOSE: the main C routine ! 136: * ! 137: * COMMENTS: ! 138: * The number of available drives is first determined by a call to ! 139: * GetLogicalDrives. This provides a bit mask of all logical drives. ! 140: * Next, a call is made to GetLogicalDriveStrings to get the valid ! 141: * drive strings for the system. ! 142: * ! 143: * For each logical drive, a call is made to GetDriveType to determine ! 144: * the drive type. If the logical drive is not in the bit mask that ! 145: * was created with the GetLogicalDrives call, then this drive is ! 146: * bypassed. ! 147: * ! 148: * GetVolumeInformation is used to determine the file system ! 149: * for the logical drive. This information is returned in the ! 150: * lpszFileSystemNameBuffer variable. If the drive type is ! 151: * remote, a check must be made to see if the drive contains a ! 152: * disk. This is accomplished by opening '.' in the root ! 153: * directory of the remote drive. The error level is temporarily ! 154: * changed from 0 to 1, to allow any OpenFileErrors to immediately ! 155: * return to the calling function, thus eliminating any unwanted ! 156: * dialog boxes. If the remote drive contains a disk, then it is ! 157: * safe to proceed with the GetVolumeInformation call. ! 158: * ! 159: * INPUT: None ! 160: * ! 161: * OUTPUT: None ! 162: * ! 163: ****************************************************************************/ ! 164: ! 165: VOID main(VOID) ! 166: { ! 167: DWORD dwDriveMask; ! 168: DWORD dwRC; ! 169: DWORD dwTemp; ! 170: DWORD cbDriveStringBufferSize=BUFSIZE; ! 171: LPTSTR lpszDriveStringBuffer=chBuffer; ! 172: LPTSTR lpszRootPathName="?:\\"; ! 173: LPTSTR lpszFileSystemNameBuffer=" "; ! 174: DWORD nFileSystemNameSize=sizeof(" "); ! 175: ! 176: dwDriveMask=GetLogicalDrives(); ! 177: dwRC=GetLogicalDriveStrings(cbDriveStringBufferSize,lpszDriveStringBuffer); ! 178: for (*lpszRootPathName='a';*lpszRootPathName<='z';(*lpszRootPathName)++) ! 179: { ! 180: dwTemp=dwDriveMask & 1; ! 181: dwDriveMask >>= 1; ! 182: if (dwTemp) ! 183: { ! 184: dwRC=GetDriveType(lpszRootPathName); ! 185: printf("The drive type for %s is ",lpszDriveStringBuffer); ! 186: lpszDriveStringBuffer=UpdateBuffer(lpszDriveStringBuffer); ! 187: switch (dwRC) ! 188: { ! 189: case DRIVE_REMOVEABLE : ! 190: printf("removeable. "); ! 191: if (CheckRM(lpszRootPathName)) ! 192: GVI(lpszRootPathName,lpszFileSystemNameBuffer,nFileSystemNameSize); ! 193: else ! 194: printf("File system = INDETERMINATE"); ! 195: break; ! 196: case DRIVE_FIXED : ! 197: printf("fixed. "); ! 198: GVI(lpszRootPathName,lpszFileSystemNameBuffer,nFileSystemNameSize); ! 199: break; ! 200: case DRIVE_REMOTE : ! 201: printf("remote. "); ! 202: GVI(lpszRootPathName,lpszFileSystemNameBuffer,nFileSystemNameSize); ! 203: break; ! 204: case DRIVE_CDROM : ! 205: printf("CD-ROM. "); ! 206: GVI(lpszRootPathName,lpszFileSystemNameBuffer,nFileSystemNameSize); ! 207: break; ! 208: case DRIVE_RAMDISK : ! 209: printf("RAM disk. "); ! 210: GVI(lpszRootPathName,lpszFileSystemNameBuffer,nFileSystemNameSize); ! 211: break; ! 212: default : ! 213: break; ! 214: } ! 215: printf("\n"); ! 216: } ! 217: } ! 218: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.