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.

536 lines
10 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. VolInfo.c
  5. Abstract:
  6. This module implements the volume information routines for NPFS called by
  7. the dispatch driver.
  8. Author:
  9. Gary Kimura [GaryKi] 12-Apr-1990
  10. Revision History:
  11. --*/
  12. #include "NpProcs.h"
  13. //
  14. // The local debug trace level
  15. //
  16. #define Dbg (DEBUG_TRACE_VOLINFO)
  17. //
  18. // Local procedure prototypes
  19. //
  20. NTSTATUS
  21. NpCommonQueryVolumeInformation (
  22. IN PIRP Irp
  23. );
  24. NTSTATUS
  25. NpQueryFsDeviceInfo (
  26. IN PFILE_FS_DEVICE_INFORMATION Buffer,
  27. IN OUT PULONG Length
  28. );
  29. NTSTATUS
  30. NpQueryFsAttributeInfo (
  31. IN PFILE_FS_ATTRIBUTE_INFORMATION Buffer,
  32. IN OUT PULONG Length
  33. );
  34. NTSTATUS
  35. NpQueryFsVolumeInfo (
  36. IN PFILE_FS_VOLUME_INFORMATION Buffer,
  37. IN OUT PULONG Length
  38. );
  39. NTSTATUS
  40. NpQueryFsSizeInfo (
  41. IN PFILE_FS_SIZE_INFORMATION Buffer,
  42. IN OUT PULONG Length
  43. );
  44. NTSTATUS
  45. NpQueryFsFullSizeInfo (
  46. IN PFILE_FS_FULL_SIZE_INFORMATION Buffer,
  47. IN OUT PULONG Length
  48. );
  49. #ifdef ALLOC_PRAGMA
  50. #pragma alloc_text(PAGE, NpCommonQueryVolumeInformation)
  51. #pragma alloc_text(PAGE, NpFsdQueryVolumeInformation)
  52. #pragma alloc_text(PAGE, NpQueryFsAttributeInfo)
  53. #pragma alloc_text(PAGE, NpQueryFsDeviceInfo)
  54. #pragma alloc_text(PAGE, NpQueryFsVolumeInfo)
  55. #pragma alloc_text(PAGE, NpQueryFsSizeInfo)
  56. #pragma alloc_text(PAGE, NpQueryFsFullSizeInfo)
  57. #endif
  58. NTSTATUS
  59. NpFsdQueryVolumeInformation (
  60. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  61. IN PIRP Irp
  62. )
  63. /*++
  64. Routine Description:
  65. This routine implements the Fsd part of the NtQueryVolumeInformation API
  66. call.
  67. Arguments:
  68. VolumeDeviceObject - Supplies the volume device object where the file
  69. being queried exists.
  70. Irp - Supplies the Irp being processed.
  71. Return Value:
  72. NTSTATUS - The FSD status for the Irp.
  73. --*/
  74. {
  75. NTSTATUS Status;
  76. PAGED_CODE();
  77. DebugTrace(+1, Dbg, "NpFsdQueryVolumeInformation\n", 0);
  78. //
  79. // Call the common query routine, with blocking allowed if synchronous
  80. //
  81. FsRtlEnterFileSystem();
  82. Status = NpCommonQueryVolumeInformation( Irp );
  83. FsRtlExitFileSystem();
  84. if (Status != STATUS_PENDING) {
  85. NpCompleteRequest (Irp, Status);
  86. }
  87. //
  88. // And return to our caller
  89. //
  90. DebugTrace(-1, Dbg, "NpFsdQueryVolumeInformation -> %08lx\n", Status);
  91. return Status;
  92. }
  93. //
  94. // Internal support routine
  95. //
  96. NTSTATUS
  97. NpCommonQueryVolumeInformation (
  98. IN PIRP Irp
  99. )
  100. /*++
  101. Routine Description:
  102. This is the common routine for querying volume information.
  103. Arguments:
  104. Irp - Supplies the Irp being processed
  105. Return Value:
  106. NTSTATUS - The return status for the operation
  107. --*/
  108. {
  109. NTSTATUS Status;
  110. PIO_STACK_LOCATION IrpSp;
  111. ULONG Length;
  112. FS_INFORMATION_CLASS FsInformationClass;
  113. PVOID Buffer;
  114. PAGED_CODE();
  115. //
  116. // Get the current stack location
  117. //
  118. IrpSp = IoGetCurrentIrpStackLocation( Irp );
  119. DebugTrace(+1, Dbg, "NptCommonQueryVolumeInfo...\n", 0);
  120. DebugTrace( 0, Dbg, "Irp = %08lx\n", Irp );
  121. DebugTrace( 0, Dbg, "Length = %08lx\n", IrpSp->Parameters.QueryVolume.Length);
  122. DebugTrace( 0, Dbg, "FsInformationClass = %08lx\n", IrpSp->Parameters.QueryVolume.FsInformationClass);
  123. DebugTrace( 0, Dbg, "Buffer = %08lx\n", Irp->AssociatedIrp.SystemBuffer);
  124. //
  125. // Reference our input parameters to make things easier
  126. //
  127. Length = IrpSp->Parameters.QueryVolume.Length;
  128. FsInformationClass = IrpSp->Parameters.QueryVolume.FsInformationClass;
  129. Buffer = Irp->AssociatedIrp.SystemBuffer;
  130. switch (FsInformationClass) {
  131. case FileFsDeviceInformation:
  132. Status = NpQueryFsDeviceInfo( Buffer, &Length );
  133. break;
  134. case FileFsAttributeInformation:
  135. Status = NpQueryFsAttributeInfo( Buffer, &Length );
  136. break;
  137. case FileFsVolumeInformation:
  138. Status = NpQueryFsVolumeInfo( Buffer, &Length );
  139. break;
  140. case FileFsSizeInformation:
  141. Status = NpQueryFsSizeInfo( Buffer, &Length );
  142. break;
  143. case FileFsFullSizeInformation:
  144. Status = NpQueryFsFullSizeInfo( Buffer, &Length );
  145. break;
  146. default:
  147. Status = STATUS_NOT_SUPPORTED;
  148. break;
  149. }
  150. //
  151. // Set the information field to the number of bytes actually filled in
  152. //
  153. Irp->IoStatus.Information = IrpSp->Parameters.QueryVolume.Length - Length;
  154. //
  155. // And return to our caller
  156. //
  157. DebugTrace(-1, Dbg, "NpCommonQueryVolumeInformation -> %08lx\n", Status);
  158. return Status;
  159. }
  160. //
  161. // Internal support routine
  162. //
  163. NTSTATUS
  164. NpQueryFsDeviceInfo (
  165. IN PFILE_FS_DEVICE_INFORMATION Buffer,
  166. IN OUT PULONG Length
  167. )
  168. /*++
  169. Routine Description:
  170. This routine implements the query volume device call
  171. Arguments:
  172. Buffer - Supplies a pointer to the output buffer where the information
  173. is to be returned
  174. Length - Supplies the length of the buffer in byte. This variable
  175. upon return recieves the remaining bytes free in the buffer
  176. Return Value:
  177. Status - Returns the status for the query
  178. --*/
  179. {
  180. PAGED_CODE();
  181. DebugTrace(0, Dbg, "NpQueryFsDeviceInfo...\n", 0);
  182. //
  183. // Make sure the buffer is large enough
  184. //
  185. if (*Length < sizeof(FILE_FS_DEVICE_INFORMATION)) {
  186. return STATUS_BUFFER_OVERFLOW;
  187. }
  188. RtlZeroMemory( Buffer, sizeof(FILE_FS_DEVICE_INFORMATION) );
  189. //
  190. // Set the output buffer
  191. //
  192. Buffer->DeviceType = FILE_DEVICE_NAMED_PIPE;
  193. //
  194. // Adjust the length variable
  195. //
  196. *Length -= sizeof(FILE_FS_DEVICE_INFORMATION);
  197. //
  198. // And return success to our caller
  199. //
  200. return STATUS_SUCCESS;
  201. }
  202. //
  203. // Internal support routine
  204. //
  205. NTSTATUS
  206. NpQueryFsAttributeInfo (
  207. IN PFILE_FS_ATTRIBUTE_INFORMATION Buffer,
  208. IN OUT PULONG Length
  209. )
  210. /*++
  211. Routine Description:
  212. This routine implements the query volume attribute call
  213. Arguments:
  214. Buffer - Supplies a pointer to the output buffer where the information
  215. is to be returned
  216. Length - Supplies the length of the buffer in byte. This variable
  217. upon return recieves the remaining bytes free in the buffer
  218. Return Value:
  219. Status - Returns the status for the query
  220. --*/
  221. {
  222. ULONG BytesToCopy;
  223. NTSTATUS Status;
  224. PAGED_CODE();
  225. DebugTrace(0, Dbg, "NpQueryFsAttributeInfo...\n", 0);
  226. //
  227. // Determine how much of the file system name will fit.
  228. //
  229. if ( (*Length - FIELD_OFFSET( FILE_FS_ATTRIBUTE_INFORMATION,
  230. FileSystemName[0] )) >= 8 ) {
  231. BytesToCopy = 8;
  232. *Length -= FIELD_OFFSET( FILE_FS_ATTRIBUTE_INFORMATION,
  233. FileSystemName[0] ) + 8;
  234. Status = STATUS_SUCCESS;
  235. } else {
  236. BytesToCopy = *Length - FIELD_OFFSET( FILE_FS_ATTRIBUTE_INFORMATION,
  237. FileSystemName[0]);
  238. *Length = 0;
  239. Status = STATUS_BUFFER_OVERFLOW;
  240. }
  241. //
  242. // Set the output buffer
  243. //
  244. Buffer->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES;
  245. Buffer->MaximumComponentNameLength = MAXULONG;
  246. Buffer->FileSystemNameLength = BytesToCopy;
  247. RtlCopyMemory( &Buffer->FileSystemName[0], L"NPFS", BytesToCopy );
  248. //
  249. // And return success to our caller
  250. //
  251. return Status;
  252. }
  253. NTSTATUS
  254. NpQueryFsVolumeInfo (
  255. IN PFILE_FS_VOLUME_INFORMATION Buffer,
  256. IN OUT PULONG Length
  257. )
  258. /*++
  259. Routine Description:
  260. This routine implements the query volume info call
  261. Arguments:
  262. Buffer - Supplies a pointer to the buffer where the information is
  263. to be returned.
  264. Length - Supplies the length of the buffer in bytes.
  265. Return Value:
  266. NTSTATUS - The result of this query.
  267. --*/
  268. {
  269. #define NPFS_VOLUME_LABEL L"NamedPipe"
  270. ULONG BytesToCopy;
  271. NTSTATUS Status;
  272. Status = STATUS_SUCCESS;
  273. Buffer->VolumeCreationTime.QuadPart = 0;
  274. Buffer->VolumeSerialNumber = 0;
  275. Buffer->SupportsObjects = FALSE;
  276. *Length -= FIELD_OFFSET( FILE_FS_VOLUME_INFORMATION, VolumeLabel[0] );
  277. //
  278. // Check if the buffer we're given is long enough
  279. //
  280. BytesToCopy = sizeof (NPFS_VOLUME_LABEL) - sizeof (WCHAR);
  281. if (*Length < BytesToCopy) {
  282. BytesToCopy = *Length;
  283. Status = STATUS_BUFFER_OVERFLOW;
  284. }
  285. //
  286. // Copy over what we can of the volume label, and adjust *Length
  287. //
  288. Buffer->VolumeLabelLength = BytesToCopy;
  289. if (BytesToCopy) {
  290. RtlCopyMemory( &Buffer->VolumeLabel[0],
  291. NPFS_VOLUME_LABEL,
  292. BytesToCopy );
  293. }
  294. *Length -= BytesToCopy;
  295. //
  296. // Set our status and return to our caller
  297. //
  298. return Status;
  299. }
  300. NTSTATUS
  301. NpQueryFsSizeInfo (
  302. IN PFILE_FS_SIZE_INFORMATION Buffer,
  303. IN OUT PULONG Length
  304. )
  305. /*++
  306. Routine Description:
  307. This routine implements the query size info call
  308. Arguments:
  309. Buffer - Supplies a pointer to the buffer where the information is
  310. to be returned.
  311. Length - Supplies the length of the buffer in bytes.
  312. Return Value:
  313. NTSTATUS - The result of this query.
  314. --*/
  315. {
  316. Buffer->TotalAllocationUnits.QuadPart = 0;
  317. Buffer->AvailableAllocationUnits.QuadPart = 0;
  318. Buffer->SectorsPerAllocationUnit = 1;
  319. Buffer->BytesPerSector = 1;
  320. *Length -= sizeof( FILE_FS_SIZE_INFORMATION );
  321. //
  322. // Set our status and return to our caller
  323. //
  324. return STATUS_SUCCESS;
  325. }
  326. NTSTATUS
  327. NpQueryFsFullSizeInfo (
  328. IN PFILE_FS_FULL_SIZE_INFORMATION Buffer,
  329. IN OUT PULONG Length
  330. )
  331. /*++
  332. Routine Description:
  333. This routine implements the query full size info call
  334. Arguments:
  335. Buffer - Supplies a pointer to the buffer where the information is
  336. to be returned.
  337. Length - Supplies the length of the buffer in bytes.
  338. Return Value:
  339. NTSTATUS - The result of this query.
  340. --*/
  341. {
  342. RtlZeroMemory( Buffer, sizeof(FILE_FS_FULL_SIZE_INFORMATION) );
  343. *Length -= sizeof(FILE_FS_FULL_SIZE_INFORMATION);
  344. //
  345. // Set our status and return to our caller
  346. //
  347. return STATUS_SUCCESS;
  348. }