Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

268 lines
6.7 KiB

  1. /*************************************************************************
  2. *
  3. * DRVSTAT.C
  4. *
  5. * Drive status routines, ported from DOS
  6. *
  7. * Copyright (c) 1995 Microsoft Corporation
  8. *
  9. * $Log: N:\NT\PRIVATE\NW4\NWSCRIPT\VCS\DRVSTAT.C $
  10. *
  11. * Rev 1.2 10 Apr 1996 14:22:20 terryt
  12. * Hotfix for 21181hq
  13. *
  14. * Rev 1.2 12 Mar 1996 19:53:36 terryt
  15. * Relative NDS names and merge
  16. *
  17. * Rev 1.1 22 Dec 1995 14:24:32 terryt
  18. * Add Microsoft headers
  19. *
  20. * Rev 1.0 15 Nov 1995 18:06:54 terryt
  21. * Initial revision.
  22. *
  23. * Rev 1.1 25 Aug 1995 16:22:44 terryt
  24. * Capture support
  25. *
  26. * Rev 1.0 15 May 1995 19:10:32 terryt
  27. * Initial revision.
  28. *
  29. *************************************************************************/
  30. /*++
  31. Copyright (c) 1994 Micro Computer Systems, Inc.
  32. Module Name:
  33. nwlibs\drvstat.c
  34. Abstract:
  35. Directory APIs.
  36. Author:
  37. Shawn Walker (v-swalk) 10-10-1994
  38. Revision History:
  39. --*/
  40. #include "common.h"
  41. /*++
  42. *******************************************************************
  43. GetDriveStatus
  44. Routine Description:
  45. Get the drive status.
  46. Arguments:
  47. DriveNumber = The drive to number to use. (1=A,2=B,C=3,...)
  48. PathFormat = Format for the return path.
  49. NW_FORMAT_NETWARE - volume:path
  50. NW_FORMAT_SERVER_VOLUME - server\volume:path
  51. NW_FORMAT_DRIVE - G:\path
  52. NW_FORMAT_UNC - \\server\volume\path
  53. pStatus = A pointer to return the status of the drive.
  54. pConnectionHandle = A pointer to return the connection handle
  55. for the drive.
  56. pRootPath = The pointer to return the base root path. OPTIONAL
  57. pRelativePath = The pointer to return the relative to root path.
  58. pFullPath = The pointer to return the full path.
  59. Return Value:
  60. 0x0000 SUCCESSFUL
  61. 0x00FF INVALID_DRIVE
  62. *******************************************************************
  63. --*/
  64. unsigned int
  65. GetDriveStatus(
  66. unsigned short DriveNumber,
  67. unsigned short PathFormat,
  68. unsigned short *pStatus,
  69. unsigned int *pConnectionHandle,
  70. unsigned char *pRootPath,
  71. unsigned char *pRelativePath,
  72. unsigned char *pFullPath
  73. )
  74. {
  75. unsigned char *p;
  76. unsigned int Result;
  77. unsigned short Status;
  78. unsigned char Path[NCP_MAX_PATH_LENGTH + 1];
  79. unsigned char WorkPath[NCP_MAX_PATH_LENGTH + 1];
  80. unsigned char ServerName[NCP_SERVER_NAME_LENGTH + 1];
  81. /** Make sure the drive number is valid **/
  82. if (DriveNumber < 1 || DriveNumber > 32) {
  83. return 0x000F; /* INVALID_DRIVE */
  84. }
  85. Status = 0;
  86. DriveNumber--;
  87. if (pConnectionHandle) {
  88. /*
  89. * This should never occur.
  90. */
  91. DisplayError (0xff, "GetDriveStatus");
  92. return 0xff;
  93. }
  94. /** Get the directory path from the server **/
  95. Result = NTGetNWDrivePath( DriveNumber, ServerName, Path );
  96. if ( Result ) {
  97. *Path = 0;
  98. *ServerName = 0;
  99. }
  100. /** Convert the / in the path to \ **/
  101. for (p = Path; *p != 0 ; p++)
  102. {
  103. if (*p == '/')
  104. *p = '\\';
  105. }
  106. /** Get the status of the drive if we need to **/
  107. Status = NTNetWareDriveStatus( DriveNumber );
  108. /** Get the status of the drive if we need to **/
  109. if (pStatus) {
  110. *pStatus = Status;
  111. }
  112. /** Get the full path if we need to **/
  113. if (pFullPath) {
  114. if (Status & NETWARE_LOCAL_FREE_DRIVE) {
  115. *pFullPath = 0;
  116. }
  117. else {
  118. strcpy(WorkPath, Path);
  119. /** Build the NetWare path format (volume:path) **/
  120. if (PathFormat == NETWARE_FORMAT_NETWARE) {
  121. strcpy(pFullPath, WorkPath);
  122. }
  123. /** Build the server volume path (server\volume:path) **/
  124. else if (PathFormat == NETWARE_FORMAT_SERVER_VOLUME) {
  125. sprintf(pFullPath, "%s\\%s", ServerName, WorkPath);
  126. }
  127. /** Build the drive path (G:\path) **/
  128. else if (PathFormat == NETWARE_FORMAT_DRIVE) {
  129. p = WorkPath;
  130. while (*p != ':' && *p) {
  131. p++;
  132. }
  133. if (*p == ':') {
  134. p++;
  135. }
  136. sprintf(pFullPath, "%c:\\%s", DriveNumber + 'A', p);
  137. }
  138. /** Build the UNC path (\\server\volume\path) **/
  139. else if (PathFormat == NETWARE_FORMAT_UNC) {
  140. p = WorkPath;
  141. while (*p != ':' && *p) {
  142. p++;
  143. }
  144. if (*p == ':') {
  145. *p = '\\';
  146. }
  147. sprintf(pFullPath, "\\\\%s\\%s", ServerName, WorkPath);
  148. }
  149. }
  150. }
  151. strcpy(WorkPath, Path);
  152. /*
  153. * Path does not have the relative path (current directory) in it.
  154. */
  155. /** Get the root path if we need to **/
  156. if (pRootPath) {
  157. if (Status & NETWARE_LOCAL_FREE_DRIVE) {
  158. *pRootPath = 0;
  159. }
  160. else {
  161. /** Build the NetWare root path format (volume:) **/
  162. if (PathFormat == NETWARE_FORMAT_NETWARE) {
  163. sprintf(pRootPath, strchr(WorkPath, ':')? "%s" : "%s:", WorkPath);
  164. }
  165. /** Build the server volume root path (server\volume:) **/
  166. else if (PathFormat == NETWARE_FORMAT_SERVER_VOLUME) {
  167. if ( fNDS && !_strcmpi( ServerName, NDSTREE) )
  168. sprintf(pRootPath, strchr (WorkPath, ':')? "%s" : "%s:", WorkPath);
  169. else
  170. sprintf(pRootPath, strchr (WorkPath, ':')? "%s\\%s" : "%s\\%s:", ServerName, WorkPath);
  171. }
  172. /** Build the drive root path (G:\) **/
  173. else if (PathFormat == NETWARE_FORMAT_DRIVE) {
  174. sprintf(pRootPath, "%c:\\", DriveNumber + 'A');
  175. }
  176. /** Build the UNC root path (\\server\volume) **/
  177. else if (PathFormat == NETWARE_FORMAT_UNC) {
  178. sprintf(pRootPath, "\\\\%s\\%s", ServerName, WorkPath);
  179. }
  180. }
  181. }
  182. /** Get the relative path if we need to **/
  183. if (pRelativePath) {
  184. if (Status & NETWARE_LOCAL_FREE_DRIVE) {
  185. *pRelativePath = 0;
  186. }
  187. else {
  188. int i;
  189. NTGetCurrentDirectory( (unsigned char)DriveNumber, pRelativePath );
  190. /*
  191. * Skip the drive letter
  192. */
  193. if ( pRelativePath[0] ) {
  194. for ( i = 0; ;i++ ) {
  195. pRelativePath[i] = pRelativePath[i+3];
  196. if ( !pRelativePath[i] )
  197. break;
  198. }
  199. }
  200. }
  201. }
  202. return 0x0000;
  203. }