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.

3065 lines
78 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. fileinfo.c
  5. Abstract:
  6. This module implements the get / set file information routines for
  7. Netware Redirector.
  8. Author:
  9. Manny Weiser (mannyw) 4-Mar-1993
  10. Revision History:
  11. --*/
  12. #include "procs.h"
  13. //
  14. // The debug trace level
  15. //
  16. #define Dbg (DEBUG_TRACE_FILEINFO)
  17. //
  18. // local procedure prototypes
  19. //
  20. NTSTATUS
  21. NwCommonQueryInformation (
  22. IN PIRP_CONTEXT pIrpContext
  23. );
  24. NTSTATUS
  25. NwCommonSetInformation (
  26. IN PIRP_CONTEXT pIrpContet
  27. );
  28. NTSTATUS
  29. NwQueryBasicInfo (
  30. IN PIRP_CONTEXT IrpContext,
  31. IN PICB Icb,
  32. IN PFILE_BASIC_INFORMATION Buffer
  33. );
  34. NTSTATUS
  35. NwQueryStandardInfo (
  36. IN PIRP_CONTEXT IrpContext,
  37. IN PICB Icb,
  38. IN PFILE_STANDARD_INFORMATION Buffer
  39. );
  40. NTSTATUS
  41. NwQueryInternalInfo (
  42. IN PIRP_CONTEXT IrpContext,
  43. IN PICB Icb,
  44. IN PFILE_INTERNAL_INFORMATION Buffer
  45. );
  46. NTSTATUS
  47. NwQueryEaInfo (
  48. IN PIRP_CONTEXT IrpContext,
  49. IN PFILE_EA_INFORMATION Buffer
  50. );
  51. NTSTATUS
  52. NwQueryNameInfo (
  53. IN PIRP_CONTEXT IrpContext,
  54. IN PICB Icb,
  55. IN PFILE_NAME_INFORMATION Buffer,
  56. IN OUT PULONG Length
  57. );
  58. NTSTATUS
  59. NwQueryAltNameInfo (
  60. IN PIRP_CONTEXT IrpContext,
  61. IN PICB Icb,
  62. IN PFILE_NAME_INFORMATION Buffer,
  63. IN OUT PULONG Length
  64. );
  65. NTSTATUS
  66. NwQueryPositionInfo (
  67. IN PIRP_CONTEXT IrpContext,
  68. IN PICB Icb,
  69. IN PFILE_POSITION_INFORMATION Buffer
  70. );
  71. NTSTATUS
  72. NwSetBasicInfo (
  73. IN PIRP_CONTEXT IrpContext,
  74. IN PICB Icb,
  75. IN PFILE_BASIC_INFORMATION Buffer
  76. );
  77. NTSTATUS
  78. NwSetDispositionInfo (
  79. IN PIRP_CONTEXT IrpContext,
  80. IN PICB Icb,
  81. IN PFILE_DISPOSITION_INFORMATION Buffer
  82. );
  83. NTSTATUS
  84. NwSetRenameInfo (
  85. IN PIRP_CONTEXT IrpContext,
  86. IN PICB Icb,
  87. IN PFILE_RENAME_INFORMATION Buffer
  88. );
  89. NTSTATUS
  90. NwSetPositionInfo (
  91. IN PIRP_CONTEXT IrpContext,
  92. IN PICB Icb,
  93. IN PFILE_POSITION_INFORMATION Buffer
  94. );
  95. NTSTATUS
  96. NwSetAllocationInfo (
  97. IN PIRP_CONTEXT IrpContext,
  98. IN PICB Icb,
  99. IN PFILE_ALLOCATION_INFORMATION Buffer
  100. );
  101. NTSTATUS
  102. NwSetEndOfFileInfo (
  103. IN PIRP_CONTEXT IrpContext,
  104. IN PICB Icb,
  105. IN PFILE_END_OF_FILE_INFORMATION Buffer
  106. );
  107. #ifdef ALLOC_PRAGMA
  108. #pragma alloc_text( PAGE, NwFsdQueryInformation )
  109. #pragma alloc_text( PAGE, NwFsdSetInformation )
  110. #pragma alloc_text( PAGE, NwCommonQueryInformation )
  111. #pragma alloc_text( PAGE, NwCommonSetInformation )
  112. #pragma alloc_text( PAGE, NwQueryStandardInfo )
  113. #pragma alloc_text( PAGE, NwQueryInternalInfo )
  114. #pragma alloc_text( PAGE, NwQueryEaInfo )
  115. #pragma alloc_text( PAGE, NwQueryNameInfo )
  116. #pragma alloc_text( PAGE, NwQueryPositionInfo )
  117. #pragma alloc_text( PAGE, NwSetBasicInfo )
  118. #pragma alloc_text( PAGE, NwSetDispositionInfo )
  119. #pragma alloc_text( PAGE, NwDeleteFile )
  120. #pragma alloc_text( PAGE, NwSetRenameInfo )
  121. #pragma alloc_text( PAGE, NwSetPositionInfo )
  122. #pragma alloc_text( PAGE, NwSetAllocationInfo )
  123. #pragma alloc_text( PAGE, NwSetEndOfFileInfo )
  124. #pragma alloc_text( PAGE, OccurenceCount )
  125. #ifndef QFE_BUILD
  126. #pragma alloc_text( PAGE1, NwQueryBasicInfo )
  127. #endif
  128. #endif
  129. #if 0 // Not pageable
  130. // see ifndef QFE_BUILD above
  131. #endif
  132. NTSTATUS
  133. NwFsdQueryInformation (
  134. IN PDEVICE_OBJECT DeviceObject,
  135. IN PIRP Irp
  136. )
  137. /*++
  138. Routine Description:
  139. This routine implements the FSD part of the NtQueryInformationFile API
  140. calls.
  141. Arguments:
  142. DeviceObject - Supplies a pointer to the device object to use.
  143. Irp - Supplies a pointer to the Irp to process.
  144. Return Value:
  145. NTSTATUS - The Fsd status for the Irp
  146. --*/
  147. {
  148. NTSTATUS status;
  149. PIRP_CONTEXT pIrpContext = NULL;
  150. BOOLEAN TopLevel;
  151. PAGED_CODE();
  152. DebugTrace(+1, Dbg, "NwFsdQueryInformation\n", 0);
  153. //
  154. // Call the common query information routine.
  155. //
  156. FsRtlEnterFileSystem();
  157. TopLevel = NwIsIrpTopLevel( Irp );
  158. try {
  159. pIrpContext = AllocateIrpContext( Irp );
  160. status = NwCommonQueryInformation( pIrpContext );
  161. } except(NwExceptionFilter( Irp, GetExceptionInformation() )) {
  162. if ( pIrpContext == NULL ) {
  163. //
  164. // If we couldn't allocate an irp context, just complete
  165. // irp without any fanfare.
  166. //
  167. status = STATUS_INSUFFICIENT_RESOURCES;
  168. Irp->IoStatus.Status = status;
  169. Irp->IoStatus.Information = 0;
  170. IoCompleteRequest ( Irp, IO_NETWORK_INCREMENT );
  171. } else {
  172. //
  173. // We had some trouble trying to perform the requested
  174. // operation, so we'll abort the I/O request with
  175. // the error Status that we get back from the
  176. // execption code
  177. //
  178. status = NwProcessException( pIrpContext, GetExceptionCode() );
  179. }
  180. }
  181. if ( pIrpContext ) {
  182. if ( status != STATUS_PENDING ) {
  183. NwDequeueIrpContext( pIrpContext, FALSE );
  184. }
  185. NwCompleteRequest( pIrpContext, status );
  186. }
  187. if ( TopLevel ) {
  188. NwSetTopLevelIrp( NULL );
  189. }
  190. FsRtlExitFileSystem();
  191. //
  192. // Return to the caller.
  193. //
  194. DebugTrace(-1, Dbg, "NwFsdQueryInformation -> %08lx\n", status );
  195. return status;
  196. }
  197. NTSTATUS
  198. NwFsdSetInformation (
  199. IN PDEVICE_OBJECT DeviceObject,
  200. IN PIRP Irp
  201. )
  202. /*++
  203. Routine Description:
  204. This routine implements the FSD part of the NtSetInformationFile API
  205. calls.
  206. Arguments:
  207. DeviceObject - Supplies the device object to use.
  208. Irp - Supplies the Irp being processed
  209. Return Value:
  210. NTSTATUS - The Fsd status for the Irp
  211. --*/
  212. {
  213. NTSTATUS status;
  214. PIRP_CONTEXT pIrpContext = NULL;
  215. BOOLEAN TopLevel;
  216. PAGED_CODE();
  217. DebugTrace(+1, Dbg, "NwFsdSetInformation\n", 0);
  218. //
  219. // Call the common Set Information routine.
  220. //
  221. FsRtlEnterFileSystem();
  222. TopLevel = NwIsIrpTopLevel( Irp );
  223. try {
  224. pIrpContext = AllocateIrpContext( Irp );
  225. status = NwCommonSetInformation( pIrpContext );
  226. } except(NwExceptionFilter( Irp, GetExceptionInformation() )) {
  227. if ( pIrpContext == NULL ) {
  228. //
  229. // If we couldn't allocate an irp context, just complete
  230. // irp without any fanfare.
  231. //
  232. status = STATUS_INSUFFICIENT_RESOURCES;
  233. Irp->IoStatus.Status = status;
  234. Irp->IoStatus.Information = 0;
  235. IoCompleteRequest ( Irp, IO_NETWORK_INCREMENT );
  236. } else {
  237. //
  238. // We had some trouble trying to perform the requested
  239. // operation, so we'll abort the I/O request with
  240. // the error Status that we get back from the
  241. // execption code
  242. //
  243. status = NwProcessException( pIrpContext, GetExceptionCode() );
  244. }
  245. }
  246. if ( pIrpContext ) {
  247. if ( status != STATUS_PENDING ) {
  248. NwDequeueIrpContext( pIrpContext, FALSE );
  249. }
  250. NwCompleteRequest( pIrpContext, status );
  251. }
  252. if ( TopLevel ) {
  253. NwSetTopLevelIrp( NULL );
  254. }
  255. FsRtlExitFileSystem();
  256. //
  257. // Return to the caller.
  258. //
  259. DebugTrace(-1, Dbg, "NwFsdSetInformation -> %08lx\n", status );
  260. return status;
  261. }
  262. NTSTATUS
  263. NwCommonQueryInformation (
  264. IN PIRP_CONTEXT pIrpContext
  265. )
  266. /*++
  267. Routine Description:
  268. This is the common routine for querying information on a file.
  269. Arguments:
  270. pIrpContext - Supplies Irp context information.
  271. Return Value:
  272. NTSTATUS - the return status for the operation.
  273. --*/
  274. {
  275. PIRP Irp;
  276. PIO_STACK_LOCATION irpSp;
  277. NTSTATUS status;
  278. ULONG length;
  279. FILE_INFORMATION_CLASS fileInformationClass;
  280. PVOID buffer;
  281. NODE_TYPE_CODE nodeTypeCode;
  282. PICB icb;
  283. PFCB fcb;
  284. PVOID fsContext, fsContext2;
  285. PFILE_ALL_INFORMATION AllInfo;
  286. PAGED_CODE();
  287. //
  288. // Get the current stack location.
  289. //
  290. Irp = pIrpContext->pOriginalIrp;
  291. irpSp = IoGetCurrentIrpStackLocation( Irp );
  292. DebugTrace(+1, Dbg, "NwCommonQueryInformation...\n", 0);
  293. DebugTrace( 0, Dbg, " Irp = %08lx\n", (ULONG_PTR)Irp);
  294. DebugTrace( 0, Dbg, " ->Length = %08lx\n", irpSp->Parameters.QueryFile.Length);
  295. DebugTrace( 0, Dbg, " ->FileInformationClass = %08lx\n", irpSp->Parameters.QueryFile.FileInformationClass);
  296. DebugTrace( 0, Dbg, " ->Buffer = %08lx\n", (ULONG_PTR)Irp->AssociatedIrp.SystemBuffer);
  297. //
  298. // Find out who are.
  299. //
  300. if ((nodeTypeCode = NwDecodeFileObject( irpSp->FileObject,
  301. &fsContext,
  302. &fsContext2 )) == NTC_UNDEFINED) {
  303. status = STATUS_INVALID_HANDLE;
  304. DebugTrace(-1, Dbg, "NwCommonQueryInformation -> %08lx\n", status );
  305. return status;
  306. }
  307. //
  308. // Make sure that this the user is querying an ICB.
  309. //
  310. switch (nodeTypeCode) {
  311. case NW_NTC_ICB:
  312. icb = (PICB)fsContext2;
  313. break;
  314. default: // This is an illegal file object to query
  315. DebugTrace(0, Dbg, "Node type code is not incorrect\n", 0);
  316. DebugTrace(-1, Dbg, "NwCommonQueryInformation -> STATUS_INVALID_PARAMETER\n", 0);
  317. return STATUS_INVALID_PARAMETER;
  318. }
  319. pIrpContext->Icb = icb;
  320. //
  321. // Make local copies of the input parameters.
  322. //
  323. length = irpSp->Parameters.QueryFile.Length;
  324. fileInformationClass = irpSp->Parameters.QueryFile.FileInformationClass;
  325. buffer = Irp->AssociatedIrp.SystemBuffer;
  326. //
  327. // Now acquire shared access to the FCB
  328. //
  329. fcb = icb->SuperType.Fcb;
  330. try {
  331. NwVerifyIcbSpecial( icb );
  332. //
  333. // Based on the information class we'll do different actions. Each
  334. // of the procedure that we're calling fill up as much of the
  335. // buffer as possible and return the remaining length, and status
  336. // This is done so that we can use them to build up the
  337. // FileAllInformation request. These procedures do not complete the
  338. // IRP, instead this procedure must complete the IRP.
  339. //
  340. status = STATUS_SUCCESS;
  341. switch (fileInformationClass) {
  342. case FileAllInformation:
  343. AllInfo = buffer;
  344. //
  345. // First call all the Query Info handlers we can call
  346. // synchronously.
  347. //
  348. NwQueryInternalInfo( pIrpContext, icb, &AllInfo->InternalInformation );
  349. NwQueryEaInfo( pIrpContext, &AllInfo->EaInformation );
  350. NwQueryPositionInfo( pIrpContext, icb, &AllInfo->PositionInformation );
  351. length -= FIELD_OFFSET( FILE_ALL_INFORMATION, NameInformation );
  352. status = NwQueryNameInfo( pIrpContext, icb, &AllInfo->NameInformation, &length );
  353. if ( !NT_ERROR( status ) ) {
  354. status = NwQueryStandardInfo( pIrpContext, icb, &AllInfo->StandardInformation );
  355. }
  356. if ( !NT_ERROR( status ) ) {
  357. status = NwQueryBasicInfo( pIrpContext, icb, &AllInfo->BasicInformation );
  358. }
  359. break;
  360. case FileBasicInformation:
  361. length -= sizeof( FILE_BASIC_INFORMATION );
  362. status = NwQueryBasicInfo( pIrpContext, icb, buffer );
  363. break;
  364. case FileStandardInformation:
  365. //
  366. // We will handle this call for information asynchronously.
  367. // The callback routine will fill in the missing data, and
  368. // complete the IRP.
  369. //
  370. // Remember the buffer length, and status to return.
  371. //
  372. length -= sizeof( FILE_STANDARD_INFORMATION );
  373. status = NwQueryStandardInfo( pIrpContext, icb, buffer );
  374. break;
  375. case FileInternalInformation:
  376. status = NwQueryInternalInfo( pIrpContext, icb, buffer );
  377. length -= sizeof( FILE_INTERNAL_INFORMATION );
  378. break;
  379. case FileEaInformation:
  380. status = NwQueryEaInfo( pIrpContext, buffer );
  381. length -= sizeof( FILE_EA_INFORMATION );
  382. break;
  383. case FilePositionInformation:
  384. status = NwQueryPositionInfo( pIrpContext, icb, buffer );
  385. length -= sizeof( FILE_POSITION_INFORMATION );
  386. break;
  387. case FileNameInformation:
  388. status = NwQueryNameInfo( pIrpContext, icb, buffer, &length );
  389. break;
  390. case FileAlternateNameInformation:
  391. if (!DisableAltFileName) {
  392. status = NwQueryAltNameInfo( pIrpContext, icb, buffer, &length);
  393. break;
  394. }
  395. default:
  396. status = STATUS_INVALID_PARAMETER;
  397. break;
  398. }
  399. //
  400. // Set the information field to the number of bytes actually
  401. // filled in and then complete the request. (This is
  402. // irrelavent if the Query worker function returned
  403. // STATUS_PENDING).
  404. //
  405. if ( status != STATUS_PENDING ) {
  406. Irp->IoStatus.Information =
  407. irpSp->Parameters.QueryFile.Length - length;
  408. }
  409. } finally {
  410. DebugTrace(-1, Dbg, "NwCommonQueryInformation -> %08lx\n", status );
  411. }
  412. return status;
  413. }
  414. NTSTATUS
  415. NwCommonSetInformation (
  416. IN PIRP_CONTEXT IrpContext
  417. )
  418. /*++
  419. Routine Description:
  420. This is the common routine for setting information on a file.
  421. Arguments:
  422. IrpContext - Supplies the Irp to process
  423. Return Value:
  424. NTSTATUS - the return status for the operation
  425. --*/
  426. {
  427. PIRP irp;
  428. PIO_STACK_LOCATION irpSp;
  429. NTSTATUS status;
  430. ULONG length;
  431. FILE_INFORMATION_CLASS fileInformationClass;
  432. PVOID buffer;
  433. NODE_TYPE_CODE nodeTypeCode;
  434. PICB icb;
  435. PFCB fcb;
  436. PVOID fsContext;
  437. //
  438. // Get the current Irp stack location.
  439. //
  440. irp = IrpContext->pOriginalIrp;
  441. irpSp = IoGetCurrentIrpStackLocation( irp );
  442. DebugTrace(+1, Dbg, "NwCommonSetInformation...\n", 0);
  443. DebugTrace( 0, Dbg, " Irp = %08lx\n", (ULONG_PTR)irp);
  444. DebugTrace( 0, Dbg, " ->Length = %08lx\n", irpSp->Parameters.SetFile.Length);
  445. DebugTrace( 0, Dbg, " ->FileInformationClass = %08lx\n", irpSp->Parameters.SetFile.FileInformationClass);
  446. DebugTrace( 0, Dbg, " ->Buffer = %08lx\n", (ULONG_PTR)irp->AssociatedIrp.SystemBuffer);
  447. //
  448. // Get a pointer to the FCB and ensure that this is a server side
  449. // handler to a file.
  450. //
  451. if ((nodeTypeCode = NwDecodeFileObject( irpSp->FileObject,
  452. &fsContext,
  453. (PVOID *)&icb )) == NTC_UNDEFINED ) {
  454. status = STATUS_INVALID_HANDLE;
  455. DebugTrace(-1, Dbg, "NwCommonSetInformation -> %08lx\n", status );
  456. return status;
  457. }
  458. //
  459. // Make sure that this the user is querying an ICB.
  460. //
  461. switch (nodeTypeCode) {
  462. case NW_NTC_ICB:
  463. fcb = icb->SuperType.Fcb;
  464. break;
  465. default: // This is an illegal file object to query
  466. DebugTrace(0, Dbg, "Node type code is not incorrect\n", 0);
  467. DebugTrace(-1, Dbg, "NwCommonSetInformation -> STATUS_INVALID_PARAMETER\n", 0);
  468. return STATUS_INVALID_PARAMETER;
  469. }
  470. IrpContext->Icb = icb;
  471. //
  472. // Make local copies of the input parameters.
  473. //
  474. length = irpSp->Parameters.SetFile.Length;
  475. fileInformationClass = irpSp->Parameters.SetFile.FileInformationClass;
  476. buffer = irp->AssociatedIrp.SystemBuffer;
  477. try {
  478. NwVerifyIcb( icb );
  479. //
  480. // Based on the information class we'll do different actions. Each
  481. // procedure that we're calling will complete the request.
  482. //
  483. switch (fileInformationClass) {
  484. case FileBasicInformation:
  485. status = NwSetBasicInfo( IrpContext, icb, buffer );
  486. break;
  487. case FileDispositionInformation:
  488. status = NwSetDispositionInfo( IrpContext, icb, buffer );
  489. break;
  490. case FileRenameInformation:
  491. status = NwSetRenameInfo( IrpContext, icb, buffer );
  492. break;
  493. case FilePositionInformation:
  494. status = NwSetPositionInfo( IrpContext, icb, buffer );
  495. break;
  496. case FileLinkInformation:
  497. status = STATUS_INVALID_DEVICE_REQUEST;
  498. break;
  499. case FileAllocationInformation:
  500. status = NwSetAllocationInfo( IrpContext, icb, buffer );
  501. break;
  502. case FileEndOfFileInformation:
  503. status = NwSetEndOfFileInfo( IrpContext, icb, buffer );
  504. break;
  505. default:
  506. status = STATUS_INVALID_PARAMETER;
  507. break;
  508. }
  509. } finally {
  510. DebugTrace(-1, Dbg, "NwCommonSetInformation -> %08lx\n", status);
  511. }
  512. return status;
  513. }
  514. NTSTATUS
  515. NwQueryBasicInfo (
  516. IN PIRP_CONTEXT IrpContext,
  517. IN PICB Icb,
  518. OUT PFILE_BASIC_INFORMATION Buffer
  519. )
  520. /*++
  521. Routine Description:
  522. This routine performs the query basic information operation.
  523. This routine cannot be paged, it is called from QueryStandardInfoCallback.
  524. Arguments:
  525. Icb - Supplies a pointer the ICB for the file being querying.
  526. Buffer - Supplies a pointer to the buffer where the information is
  527. to be returned.
  528. Return Value:
  529. VOID
  530. --*/
  531. {
  532. PFCB Fcb;
  533. NTSTATUS Status;
  534. ULONG Attributes;
  535. USHORT CreationDate;
  536. USHORT CreationTime = DEFAULT_TIME;
  537. USHORT LastAccessDate;
  538. USHORT LastModifiedDate;
  539. USHORT LastModifiedTime;
  540. BOOLEAN FirstTime = TRUE;
  541. DebugTrace(0, Dbg, "QueryBasicInfo...\n", 0);
  542. //
  543. // Zero out the buffer.
  544. //
  545. RtlZeroMemory( Buffer, sizeof(FILE_BASIC_INFORMATION) );
  546. Fcb = Icb->SuperType.Fcb;
  547. //
  548. // It is ok to attempt a reconnect if this request fails with a
  549. // connection error.
  550. //
  551. SetFlag( IrpContext->Flags, IRP_FLAG_RECONNECTABLE );
  552. NwAcquireSharedFcb( Fcb->NonPagedFcb, TRUE );
  553. //
  554. // If we already know the file attributes, simply return them.
  555. //
  556. if ( FlagOn( Fcb->Flags, FCB_FLAGS_ATTRIBUTES_ARE_VALID ) ) {
  557. //
  558. // Set the various fields in the record
  559. //
  560. Buffer->CreationTime = NwDateTimeToNtTime(
  561. Fcb->CreationDate,
  562. Fcb->CreationTime
  563. );
  564. Buffer->LastAccessTime = NwDateTimeToNtTime(
  565. Fcb->LastAccessDate,
  566. DEFAULT_TIME
  567. );
  568. Buffer->LastWriteTime = NwDateTimeToNtTime(
  569. Fcb->LastModifiedDate,
  570. Fcb->LastModifiedTime
  571. );
  572. DebugTrace(0, Dbg, "QueryBasic known %wZ\n", &Fcb->RelativeFileName);
  573. DebugTrace(0, Dbg, "LastModifiedDate %x\n", Fcb->LastModifiedDate);
  574. DebugTrace(0, Dbg, "LastModifiedTime %x\n", Fcb->LastModifiedTime);
  575. DebugTrace(0, Dbg, "CreationDate %x\n", Fcb->CreationDate );
  576. DebugTrace(0, Dbg, "CreationTime %x\n", Fcb->CreationTime );
  577. DebugTrace(0, Dbg, "LastAccessDate %x\n", Fcb->LastAccessDate );
  578. Buffer->FileAttributes = Fcb->NonPagedFcb->Attributes;
  579. if ( Buffer->FileAttributes == 0 ) {
  580. Buffer->FileAttributes = FILE_ATTRIBUTE_NORMAL;
  581. }
  582. NwReleaseFcb( Fcb->NonPagedFcb );
  583. return STATUS_SUCCESS;
  584. } else if ( Fcb->RelativeFileName.Length == 0 ) {
  585. //
  586. // Allow 'cd \' to work.
  587. //
  588. Buffer->FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
  589. Buffer->CreationTime = NwDateTimeToNtTime(
  590. DEFAULT_DATE,
  591. DEFAULT_TIME
  592. );
  593. Buffer->LastAccessTime = Buffer->CreationTime;
  594. Buffer->LastWriteTime = Buffer->CreationTime;
  595. NwReleaseFcb( Fcb->NonPagedFcb );
  596. return STATUS_SUCCESS;
  597. } else {
  598. NwReleaseFcb( Fcb->NonPagedFcb );
  599. IrpContext->pNpScb = Fcb->Scb->pNpScb;
  600. Retry:
  601. if ( !BooleanFlagOn( Fcb->Flags, FCB_FLAGS_LONG_NAME ) ) {
  602. DebugTrace(0, Dbg, "QueryBasic short %wZ\n", &Fcb->RelativeFileName);
  603. Status = ExchangeWithWait (
  604. IrpContext,
  605. SynchronousResponseCallback,
  606. "FwbbJ",
  607. NCP_SEARCH_FILE,
  608. -1,
  609. Fcb->Vcb->Specific.Disk.Handle,
  610. Fcb->NodeTypeCode == NW_NTC_FCB ?
  611. SEARCH_ALL_FILES : SEARCH_ALL_DIRECTORIES,
  612. &Icb->SuperType.Fcb->RelativeFileName );
  613. if ( NT_SUCCESS( Status ) ) {
  614. Status = ParseResponse(
  615. IrpContext,
  616. IrpContext->rsp,
  617. IrpContext->ResponseLength,
  618. "N==_b-==wwww",
  619. 14,
  620. &Attributes,
  621. &CreationDate,
  622. &LastAccessDate,
  623. &LastModifiedDate,
  624. &LastModifiedTime);
  625. //
  626. // If this was a directory, there's no usable
  627. // time/date info from the server.
  628. //
  629. if ( ( NT_SUCCESS( Status ) ) &&
  630. ( Attributes & NW_ATTRIBUTE_DIRECTORY ) ) {
  631. CreationDate = DEFAULT_DATE;
  632. LastAccessDate = DEFAULT_DATE;
  633. LastModifiedDate = DEFAULT_DATE;
  634. LastModifiedTime = DEFAULT_TIME;
  635. }
  636. }
  637. } else {
  638. DebugTrace(0, Dbg, "QueryBasic long %wZ\n", &Fcb->RelativeFileName);
  639. Status = ExchangeWithWait (
  640. IrpContext,
  641. SynchronousResponseCallback,
  642. "LbbWDbDbC",
  643. NCP_LFN_GET_INFO,
  644. Fcb->Vcb->Specific.Disk.LongNameSpace,
  645. Fcb->Vcb->Specific.Disk.LongNameSpace,
  646. Fcb->NodeTypeCode == NW_NTC_FCB ?
  647. SEARCH_ALL_FILES : SEARCH_ALL_DIRECTORIES,
  648. LFN_FLAG_INFO_ATTRIBUTES |
  649. LFN_FLAG_INFO_MODIFY_TIME |
  650. LFN_FLAG_INFO_CREATION_TIME,
  651. Fcb->Vcb->Specific.Disk.VolumeNumber,
  652. Fcb->Vcb->Specific.Disk.Handle,
  653. 0,
  654. &Icb->SuperType.Fcb->RelativeFileName );
  655. if ( NT_SUCCESS( Status ) ) {
  656. Status = ParseResponse(
  657. IrpContext,
  658. IrpContext->rsp,
  659. IrpContext->ResponseLength,
  660. "N_e_xx_xx_x",
  661. 4,
  662. &Attributes,
  663. 12,
  664. &CreationTime,
  665. &CreationDate,
  666. 4,
  667. &LastModifiedTime,
  668. &LastModifiedDate,
  669. 4,
  670. &LastAccessDate );
  671. }
  672. }
  673. if ( NT_SUCCESS( Status ) ) {
  674. //
  675. // Set the various fields in the record
  676. //
  677. Buffer->CreationTime = NwDateTimeToNtTime(
  678. CreationDate,
  679. CreationTime
  680. );
  681. Buffer->LastAccessTime = NwDateTimeToNtTime(
  682. LastAccessDate,
  683. DEFAULT_TIME
  684. );
  685. Buffer->LastWriteTime = NwDateTimeToNtTime(
  686. LastModifiedDate,
  687. LastModifiedTime
  688. );
  689. DebugTrace(0, Dbg, "CreationDate %x\n", CreationDate );
  690. DebugTrace(0, Dbg, "CreationTime %x\n", CreationTime );
  691. DebugTrace(0, Dbg, "LastAccessDate %x\n", LastAccessDate );
  692. DebugTrace(0, Dbg, "LastModifiedDate %x\n", LastModifiedDate);
  693. DebugTrace(0, Dbg, "LastModifiedTime %x\n", LastModifiedTime);
  694. Buffer->FileAttributes = (UCHAR)Attributes;
  695. if ( Buffer->FileAttributes == 0 ) {
  696. Buffer->FileAttributes = FILE_ATTRIBUTE_NORMAL;
  697. }
  698. } else if ((Status == STATUS_INVALID_HANDLE) &&
  699. (FirstTime)) {
  700. //
  701. // Check to see if Volume handle is invalid. Caused when volume
  702. // is unmounted and then remounted.
  703. //
  704. FirstTime = FALSE;
  705. NwReopenVcbHandle( IrpContext, Fcb->Vcb );
  706. goto Retry;
  707. }
  708. return( Status );
  709. }
  710. }
  711. #if NWFASTIO
  712. BOOLEAN
  713. NwFastQueryBasicInfo (
  714. IN PFILE_OBJECT FileObject,
  715. IN BOOLEAN Wait,
  716. IN OUT PFILE_BASIC_INFORMATION Buffer,
  717. OUT PIO_STATUS_BLOCK IoStatus,
  718. IN PDEVICE_OBJECT DeviceObject
  719. )
  720. /*++
  721. Routine Description:
  722. This routine is for the fast query call for standard file information.
  723. Arguments:
  724. FileObject - Supplies the file object used in this operation
  725. Wait - Indicates if we are allowed to wait for the information
  726. Buffer - Supplies the output buffer to receive the basic information
  727. IoStatus - Receives the final status of the operation
  728. Return Value:
  729. BOOLEAN - TRUE if the operation succeeded and FALSE if the caller
  730. needs to take the long route.
  731. --*/
  732. {
  733. NODE_TYPE_CODE NodeTypeCode;
  734. PICB Icb;
  735. PFCB Fcb;
  736. PVOID FsContext;
  737. FsRtlEnterFileSystem();
  738. try {
  739. //
  740. // Find out who are.
  741. //
  742. if ((NodeTypeCode = NwDecodeFileObject( FileObject,
  743. &FsContext,
  744. &Icb )) != NW_NTC_ICB ) {
  745. DebugTrace(-1, Dbg, "NwFastQueryStandardInfo -> FALSE\n", 0 );
  746. return FALSE;
  747. }
  748. Fcb = Icb->SuperType.Fcb;
  749. NwAcquireExclusiveFcb( Fcb->NonPagedFcb, TRUE );
  750. //
  751. // If we don't have the info handy, we can't use the fast path.
  752. //
  753. if ( !FlagOn( Fcb->Flags, FCB_FLAGS_ATTRIBUTES_ARE_VALID ) ) {
  754. NwReleaseFcb( Fcb->NonPagedFcb );
  755. return( FALSE );
  756. }
  757. //
  758. // Set the various fields in the record
  759. //
  760. Buffer->CreationTime = NwDateTimeToNtTime(
  761. Fcb->CreationDate,
  762. Fcb->CreationTime
  763. );
  764. Buffer->LastAccessTime = NwDateTimeToNtTime(
  765. Fcb->LastAccessDate,
  766. DEFAULT_TIME
  767. );
  768. Buffer->LastWriteTime = NwDateTimeToNtTime(
  769. Fcb->LastModifiedDate,
  770. Fcb->LastModifiedTime
  771. );
  772. DebugTrace(0, Dbg, "QueryBasic known %wZ\n", &Fcb->RelativeFileName);
  773. DebugTrace(0, Dbg, "LastModifiedDate %x\n", Fcb->LastModifiedDate);
  774. DebugTrace(0, Dbg, "LastModifiedTime %x\n", Fcb->LastModifiedTime);
  775. DebugTrace(0, Dbg, "CreationDate %x\n", Fcb->CreationDate );
  776. DebugTrace(0, Dbg, "CreationTime %x\n", Fcb->CreationTime );
  777. DebugTrace(0, Dbg, "LastAccessDate %x\n", Fcb->LastAccessDate );
  778. Buffer->FileAttributes = Fcb->NonPagedFcb->Attributes;
  779. if ( Buffer->FileAttributes == 0 ) {
  780. Buffer->FileAttributes = FILE_ATTRIBUTE_NORMAL;
  781. }
  782. IoStatus->Status = STATUS_SUCCESS;
  783. IoStatus->Information = sizeof( *Buffer );
  784. NwReleaseFcb( Fcb->NonPagedFcb );
  785. return TRUE;
  786. } finally {
  787. FsRtlExitFileSystem();
  788. }
  789. }
  790. #endif
  791. NTSTATUS
  792. NwQueryStandardInfo (
  793. IN PIRP_CONTEXT IrpContext,
  794. IN PICB Icb,
  795. IN PFILE_STANDARD_INFORMATION Buffer
  796. )
  797. /*++
  798. Routine Description:
  799. This routine perforNw the query standard information operation.
  800. Arguments:
  801. Fcb - Supplies the FCB of the being queried
  802. Buffer - Supplies a pointer to the buffer where the information is
  803. to be returned
  804. Return Value:
  805. VOID
  806. --*/
  807. {
  808. NTSTATUS Status;
  809. PFCB Fcb;
  810. ULONG FileSize;
  811. BOOLEAN FirstTime = TRUE;
  812. PAGED_CODE();
  813. Fcb = Icb->SuperType.Fcb;
  814. //
  815. // Zero out the buffer.
  816. //
  817. RtlZeroMemory( Buffer, sizeof(FILE_STANDARD_INFORMATION) );
  818. //
  819. // Fill in the answers we already know.
  820. //
  821. Buffer->NumberOfLinks = 1;
  822. Buffer->DeletePending = (BOOLEAN)FlagOn( Fcb->Flags, FCB_FLAGS_DELETE_ON_CLOSE );
  823. if ( Fcb->NodeTypeCode == NW_NTC_FCB ) {
  824. Buffer->Directory = FALSE;
  825. } else {
  826. Buffer->Directory = TRUE;
  827. }
  828. if ( !Icb->HasRemoteHandle ) {
  829. //
  830. // It is ok to attempt a reconnect if this request fails with a
  831. // connection error.
  832. //
  833. SetFlag( IrpContext->Flags, IRP_FLAG_RECONNECTABLE );
  834. if ( Fcb->NodeTypeCode == NW_NTC_DCB ||
  835. FlagOn( Fcb->Vcb->Flags, VCB_FLAG_PRINT_QUEUE ) ) {
  836. //
  837. // Allow 'cd \' to work.
  838. //
  839. Buffer->AllocationSize.QuadPart = 0;
  840. Buffer->EndOfFile.QuadPart = 0;
  841. return STATUS_SUCCESS;
  842. } else {
  843. //
  844. // No open handle for this file. Use a path based NCP
  845. // to get the file size.
  846. //
  847. Retry:
  848. IrpContext->pNpScb = Fcb->Scb->pNpScb;
  849. if ( !BooleanFlagOn( Icb->SuperType.Fcb->Flags, FCB_FLAGS_LONG_NAME ) ) {
  850. Status = ExchangeWithWait (
  851. IrpContext,
  852. SynchronousResponseCallback,
  853. "FwbbJ",
  854. NCP_SEARCH_FILE,
  855. -1,
  856. Fcb->Vcb->Specific.Disk.Handle,
  857. SEARCH_ALL_FILES,
  858. &Fcb->RelativeFileName );
  859. if ( NT_SUCCESS( Status ) ) {
  860. Status = ParseResponse(
  861. IrpContext,
  862. IrpContext->rsp,
  863. IrpContext->ResponseLength,
  864. "N_d",
  865. 20,
  866. &FileSize );
  867. }
  868. } else {
  869. Status = ExchangeWithWait (
  870. IrpContext,
  871. SynchronousResponseCallback,
  872. "LbbWDbDbC",
  873. NCP_LFN_GET_INFO,
  874. Fcb->Vcb->Specific.Disk.LongNameSpace,
  875. Fcb->Vcb->Specific.Disk.LongNameSpace,
  876. SEARCH_ALL_FILES,
  877. LFN_FLAG_INFO_FILE_SIZE,
  878. Fcb->Vcb->Specific.Disk.VolumeNumber,
  879. Fcb->Vcb->Specific.Disk.Handle,
  880. 0,
  881. &Fcb->RelativeFileName );
  882. if ( NT_SUCCESS( Status ) ) {
  883. Status = ParseResponse(
  884. IrpContext,
  885. IrpContext->rsp,
  886. IrpContext->ResponseLength,
  887. "N_e",
  888. 10,
  889. &FileSize );
  890. }
  891. }
  892. if ((Status == STATUS_INVALID_HANDLE) &&
  893. (FirstTime)) {
  894. //
  895. // Check to see if Volume handle is invalid. Caused when volume
  896. // is unmounted and then remounted.
  897. //
  898. FirstTime = FALSE;
  899. NwReopenVcbHandle( IrpContext, Fcb->Vcb );
  900. goto Retry;
  901. }
  902. Buffer->AllocationSize.QuadPart = FileSize;
  903. Buffer->EndOfFile.QuadPart = FileSize;
  904. }
  905. } else {
  906. //
  907. // Start a Get file size NCP
  908. //
  909. IrpContext->pNpScb = Fcb->Scb->pNpScb;
  910. if ( Fcb->NodeTypeCode == NW_NTC_FCB ) {
  911. AcquireFcbAndFlushCache( IrpContext, Fcb->NonPagedFcb );
  912. }
  913. Status = ExchangeWithWait(
  914. IrpContext,
  915. SynchronousResponseCallback,
  916. "F-r",
  917. NCP_GET_FILE_SIZE,
  918. &Icb->Handle, sizeof(Icb->Handle ) );
  919. if ( NT_SUCCESS( Status ) ) {
  920. //
  921. // Get the data from the response.
  922. //
  923. Status = ParseResponse(
  924. IrpContext,
  925. IrpContext->rsp,
  926. IrpContext->ResponseLength,
  927. "Nd",
  928. &FileSize );
  929. }
  930. if ( NT_SUCCESS( Status ) ) {
  931. //
  932. // Fill in Allocation size and EOF, based on the response.
  933. //
  934. Buffer->AllocationSize.QuadPart = FileSize;
  935. Buffer->EndOfFile.QuadPart = Buffer->AllocationSize.QuadPart;
  936. }
  937. }
  938. return( Status );
  939. }
  940. #if NWFASTIO
  941. BOOLEAN
  942. NwFastQueryStandardInfo (
  943. IN PFILE_OBJECT FileObject,
  944. IN BOOLEAN Wait,
  945. IN OUT PFILE_STANDARD_INFORMATION Buffer,
  946. OUT PIO_STATUS_BLOCK IoStatus,
  947. IN PDEVICE_OBJECT DeviceObject
  948. )
  949. /*++
  950. Routine Description:
  951. This routine is for the fast query call for standard file information.
  952. Arguments:
  953. FileObject - Supplies the file object used in this operation
  954. Wait - Indicates if we are allowed to wait for the information
  955. Buffer - Supplies the output buffer to receive the basic information
  956. IoStatus - Receives the final status of the operation
  957. Return Value:
  958. BOOLEAN - TRUE if the operation succeeded and FALSE if the caller
  959. needs to take the long route.
  960. --*/
  961. {
  962. NODE_TYPE_CODE NodeTypeCode;
  963. PICB Icb;
  964. PFCB Fcb;
  965. PVOID FsContext;
  966. //
  967. // Find out who are.
  968. //
  969. try {
  970. FsRtlEnterFileSystem();
  971. if ((NodeTypeCode = NwDecodeFileObject( FileObject,
  972. &FsContext,
  973. &Icb )) != NW_NTC_ICB ) {
  974. DebugTrace(-1, Dbg, "NwFastQueryStandardInfo -> FALSE\n", 0 );
  975. return FALSE;
  976. }
  977. Fcb = Icb->SuperType.Fcb;
  978. //
  979. // If we have the info handy, we can use the fast path.
  980. //
  981. if ( Fcb->NodeTypeCode == NW_NTC_DCB ||
  982. FlagOn( Fcb->Vcb->Flags, VCB_FLAG_PRINT_QUEUE ) ) {
  983. Buffer->AllocationSize.QuadPart = 0;
  984. Buffer->EndOfFile.QuadPart = 0;
  985. Buffer->NumberOfLinks = 1;
  986. Buffer->DeletePending = (BOOLEAN)FlagOn( Fcb->Flags, FCB_FLAGS_DELETE_ON_CLOSE );
  987. Buffer->Directory = TRUE;
  988. IoStatus->Status = STATUS_SUCCESS;
  989. IoStatus->Information = sizeof( *Buffer );
  990. return TRUE;
  991. } else {
  992. return FALSE;
  993. }
  994. } finally {
  995. FsRtlExitFileSystem();
  996. }
  997. }
  998. #endif
  999. NTSTATUS
  1000. NwQueryInternalInfo (
  1001. IN PIRP_CONTEXT IrpContext,
  1002. IN PICB Icb,
  1003. IN PFILE_INTERNAL_INFORMATION Buffer
  1004. )
  1005. /*++
  1006. Routine Description:
  1007. This routine perforNw the query internal information operation.
  1008. Arguments:
  1009. Fcb - Supplies the FCB of the being queried.
  1010. Buffer - Supplies a pointer to the buffer where the information is
  1011. to be returned.
  1012. Return Value:
  1013. VOID
  1014. --*/
  1015. {
  1016. PAGED_CODE();
  1017. DebugTrace(0, Dbg, "QueryInternalInfo...\n", 0);
  1018. //
  1019. // Zero out the buffer.
  1020. //
  1021. RtlZeroMemory( Buffer, sizeof(FILE_INTERNAL_INFORMATION) );
  1022. //
  1023. // Set the internal index number to be the address of the ICB.
  1024. //
  1025. Buffer->IndexNumber.HighPart = 0;
  1026. Buffer->IndexNumber.QuadPart = (ULONG_PTR)Icb->NpFcb;
  1027. return( STATUS_SUCCESS );
  1028. }
  1029. NTSTATUS
  1030. NwQueryEaInfo (
  1031. IN PIRP_CONTEXT IrpContext,
  1032. IN PFILE_EA_INFORMATION Buffer
  1033. )
  1034. /*++
  1035. Routine Description:
  1036. This routine performs the query Ea information operation.
  1037. Arguments:
  1038. Buffer - Supplies a pointer to the buffer where the information is
  1039. to be returned
  1040. Return Value:
  1041. VOID - The result of this query
  1042. --*/
  1043. {
  1044. PAGED_CODE();
  1045. DebugTrace(0, Dbg, "QueryEaInfo...\n", 0);
  1046. //
  1047. // Zero out the buffer.
  1048. //
  1049. RtlZeroMemory(Buffer, sizeof(FILE_EA_INFORMATION));
  1050. return STATUS_SUCCESS;
  1051. }
  1052. NTSTATUS
  1053. NwQueryNameInfo (
  1054. IN PIRP_CONTEXT IrpContext,
  1055. IN PICB Icb,
  1056. IN PFILE_NAME_INFORMATION Buffer,
  1057. IN PULONG Length
  1058. )
  1059. /*++
  1060. Routine Description:
  1061. This routine performs the query name information operation.
  1062. Arguments:
  1063. Fcb - Supplies the FCB of the file to query.
  1064. Buffer - Supplies a pointer to the buffer where the information is
  1065. to be returned
  1066. Length - Supplies and receives the length of the buffer in bytes.
  1067. Return Value:
  1068. NTSTATUS - The result of this query.
  1069. --*/
  1070. {
  1071. ULONG bytesToCopy;
  1072. ULONG fileNameSize;
  1073. PFCB Fcb = Icb->SuperType.Fcb;
  1074. NTSTATUS status;
  1075. PAGED_CODE();
  1076. DebugTrace(0, Dbg, "QueryNameInfo...\n", 0);
  1077. //
  1078. // Win32 expects the root directory name to be '\' terminated,
  1079. // the netware server does not. So if this is a root directory,
  1080. // (i.e RelativeFileName length is 0) append a '\' to the path name.
  1081. //
  1082. //
  1083. // See if the buffer is large enough, and decide how many bytes to copy.
  1084. //
  1085. *Length -= FIELD_OFFSET( FILE_NAME_INFORMATION, FileName[0] );
  1086. fileNameSize = Fcb->FullFileName.Length;
  1087. if ( Fcb->RelativeFileName.Length == 0 ) {
  1088. fileNameSize += sizeof(L'\\');
  1089. }
  1090. Buffer->FileNameLength = fileNameSize;
  1091. if ( *Length >= fileNameSize ) {
  1092. status = STATUS_SUCCESS;
  1093. bytesToCopy = fileNameSize;
  1094. } else {
  1095. status = STATUS_BUFFER_OVERFLOW;
  1096. bytesToCopy = *Length;
  1097. }
  1098. //
  1099. // Copy over the file name and its length.
  1100. //
  1101. RtlMoveMemory(
  1102. Buffer->FileName,
  1103. Fcb->FullFileName.Buffer,
  1104. bytesToCopy);
  1105. //
  1106. // If this is a root directory, and there is space in the buffer
  1107. // append a '\' to make win32 happy.
  1108. //
  1109. if ( Fcb->RelativeFileName.Length == 0 && status == STATUS_SUCCESS ) {
  1110. Buffer->FileName[ fileNameSize/sizeof(WCHAR) - 1 ] = L'\\';
  1111. }
  1112. *Length -= bytesToCopy;
  1113. return status;
  1114. }
  1115. NTSTATUS
  1116. NwQueryAltNameInfo (
  1117. IN PIRP_CONTEXT pIrpContext,
  1118. IN PICB Icb,
  1119. IN PFILE_NAME_INFORMATION Buffer,
  1120. IN PULONG Length
  1121. )
  1122. /*++
  1123. Routine Description:
  1124. This routine performs the AltName query name information operation.
  1125. Arguments:
  1126. Fcb - Supplies the FCB of the file to query.
  1127. Buffer - Supplies a pointer to the buffer where the information is
  1128. to be returned
  1129. Length - Supplies and receives the length of the buffer in bytes.
  1130. Return Value:
  1131. NTSTATUS - The result of this query.
  1132. --*/
  1133. {
  1134. ULONG bytesToCopy;
  1135. ULONG fileNameSize;
  1136. PFCB Fcb = Icb->SuperType.Fcb;
  1137. UNICODE_STRING ShortName;
  1138. NTSTATUS status;
  1139. PAGED_CODE();
  1140. DebugTrace(0, Dbg, "QueryAltNameInfo...\n", 0);
  1141. pIrpContext->pNpScb = Fcb->Scb->pNpScb;
  1142. //
  1143. // See if the buffer is large enough, and decide how many bytes to copy.
  1144. //
  1145. *Length -= FIELD_OFFSET( FILE_NAME_INFORMATION, FileName[0] );
  1146. ShortName.MaximumLength = MAX_PATH;
  1147. ShortName.Buffer=NULL;
  1148. ShortName.Length = 0;
  1149. status = ExchangeWithWait (
  1150. pIrpContext,
  1151. SynchronousResponseCallback,
  1152. "LbbWDbDbC",
  1153. NCP_LFN_GET_INFO,
  1154. Fcb->Vcb->Specific.Disk.LongNameSpace,
  1155. 0x0, //0x0 DOS Nam
  1156. SEARCH_ALL_DIRECTORIES,
  1157. LFN_FLAG_INFO_NAME,
  1158. Fcb->Vcb->Specific.Disk.VolumeNumber,
  1159. Fcb->Vcb->Specific.Disk.Handle,
  1160. 0,
  1161. &Fcb->RelativeFileName );
  1162. if (!NT_SUCCESS( status ) ){
  1163. return status;
  1164. }
  1165. ShortName.Buffer= ALLOCATE_POOL(NonPagedPool,
  1166. ShortName.MaximumLength+sizeof(WCHAR));
  1167. if (ShortName.Buffer == NULL){
  1168. return STATUS_INSUFFICIENT_RESOURCES;
  1169. }
  1170. status = ParseResponse(
  1171. pIrpContext,
  1172. pIrpContext->rsp,
  1173. pIrpContext->ResponseLength,
  1174. "N_P",
  1175. 76,
  1176. &ShortName);
  1177. if ( NT_SUCCESS( status ) ) {
  1178. fileNameSize = ShortName.Length;
  1179. if ( *Length >= fileNameSize ) {
  1180. status = STATUS_SUCCESS;
  1181. bytesToCopy = fileNameSize;
  1182. } else {
  1183. status = STATUS_BUFFER_OVERFLOW;
  1184. bytesToCopy = *Length;
  1185. }
  1186. Buffer->FileNameLength = fileNameSize;
  1187. RtlMoveMemory(
  1188. Buffer->FileName,
  1189. ShortName.Buffer,
  1190. bytesToCopy);
  1191. *Length -= bytesToCopy;
  1192. }
  1193. FREE_POOL(ShortName.Buffer);
  1194. return status;
  1195. }
  1196. NTSTATUS
  1197. NwQueryPositionInfo (
  1198. IN PIRP_CONTEXT IrpContext,
  1199. IN PICB Icb,
  1200. IN PFILE_POSITION_INFORMATION Buffer
  1201. )
  1202. /*++
  1203. Routine Description:
  1204. This routine performs the query position information operation.
  1205. Arguments:
  1206. Fcb - Supplies the FCB of the file being queried.
  1207. Buffer - Supplies a pointer to the buffer where the information is
  1208. to be returned.
  1209. Return Value:
  1210. VOID
  1211. --*/
  1212. {
  1213. PAGED_CODE();
  1214. DebugTrace(0, Dbg, "QueryPositionInfo...\n", 0);
  1215. //
  1216. // Return the current byte offset. This info is totally
  1217. // bogus for asynchronous files. Also note that we don't
  1218. // use the FilePosition member of the ICB for anything.
  1219. //
  1220. if ( Icb->FileObject ) {
  1221. Buffer->CurrentByteOffset.QuadPart = Icb->FileObject->CurrentByteOffset.QuadPart;
  1222. }
  1223. return STATUS_SUCCESS;
  1224. }
  1225. NTSTATUS
  1226. NwSetBasicInfo (
  1227. IN PIRP_CONTEXT pIrpContext,
  1228. IN PICB Icb,
  1229. IN PFILE_BASIC_INFORMATION Buffer
  1230. )
  1231. /*++
  1232. Routine Description:
  1233. This routine sets the basic information for a file.
  1234. Arguments:
  1235. pIrpContext - Supplies Irp context information.
  1236. Icb - Supplies the ICB for the file being modified.
  1237. Buffer - Supplies the buffer containing the data being set.
  1238. Return Value:
  1239. NTSTATUS - Returns our completion status.
  1240. --*/
  1241. {
  1242. PFCB Fcb;
  1243. NTSTATUS Status;
  1244. BOOLEAN SetTime = FALSE;
  1245. BOOLEAN SetAttributes = FALSE;
  1246. ULONG LfnFlag = 0;
  1247. PAGED_CODE();
  1248. DebugTrace(0, Dbg, "SetBasicInfo...\n", 0);
  1249. Fcb = Icb->SuperType.Fcb;
  1250. pIrpContext->pNpScb = Fcb->Scb->pNpScb;
  1251. //
  1252. // Append this IRP context and wait to get to the front.
  1253. // then grab from FCB
  1254. //
  1255. NwAppendToQueueAndWait( pIrpContext );
  1256. NwAcquireExclusiveFcb( Fcb->NonPagedFcb, TRUE );
  1257. //
  1258. // It is ok to attempt a reconnect if this request fails with a
  1259. // connection error.
  1260. //
  1261. SetFlag( pIrpContext->Flags, IRP_FLAG_RECONNECTABLE );
  1262. if (Buffer->CreationTime.QuadPart != 0) {
  1263. //
  1264. // Modify the creation time.
  1265. //
  1266. Status = NwNtTimeToNwDateTime(
  1267. Buffer->CreationTime,
  1268. &Fcb->CreationDate,
  1269. &Fcb->CreationTime );
  1270. if ( !NT_SUCCESS( Status ) ) {
  1271. NwReleaseFcb( Fcb->NonPagedFcb );
  1272. return( Status );
  1273. }
  1274. SetTime = TRUE;
  1275. LfnFlag |= LFN_FLAG_SET_INFO_CREATE_DATE | LFN_FLAG_SET_INFO_CREATE_TIME;
  1276. }
  1277. if (Buffer->LastAccessTime.QuadPart != 0) {
  1278. USHORT Dummy;
  1279. //
  1280. // Modify the last access time.
  1281. //
  1282. Status = NwNtTimeToNwDateTime(
  1283. Buffer->LastAccessTime,
  1284. &Fcb->LastAccessDate,
  1285. &Dummy );
  1286. if ( !NT_SUCCESS( Status ) ) {
  1287. NwReleaseFcb( Fcb->NonPagedFcb );
  1288. return( Status );
  1289. }
  1290. SetTime = TRUE;
  1291. LfnFlag |= LFN_FLAG_SET_INFO_LASTACCESS_DATE;
  1292. // Set the last access flag in the ICB so that we update
  1293. // last access time for real when we close this handle!
  1294. Icb->UserSetLastAccessTime = TRUE;
  1295. }
  1296. if (Buffer->LastWriteTime.QuadPart != 0) {
  1297. //
  1298. // Modify the last write time
  1299. //
  1300. Status = NwNtTimeToNwDateTime(
  1301. Buffer->LastWriteTime,
  1302. &Fcb->LastModifiedDate,
  1303. &Fcb->LastModifiedTime );
  1304. if ( !NT_SUCCESS( Status ) ) {
  1305. NwReleaseFcb( Fcb->NonPagedFcb );
  1306. return( Status );
  1307. }
  1308. LfnFlag |= LFN_FLAG_SET_INFO_MODIFY_DATE | LFN_FLAG_SET_INFO_MODIFY_TIME;
  1309. }
  1310. if (Buffer->FileAttributes != 0) {
  1311. LfnFlag |= LFN_FLAG_SET_INFO_ATTRIBUTES;
  1312. }
  1313. if ( LfnFlag == 0 ) {
  1314. //
  1315. // Nothing to set, simply return success.
  1316. //
  1317. Status = STATUS_SUCCESS;
  1318. }
  1319. if ( Fcb->NodeTypeCode == NW_NTC_FCB ) {
  1320. //
  1321. // Call plain FlushCache - we don't want to acquire and
  1322. // release the NpFcb. We are already at the front and have the Fcb
  1323. // exclusive.
  1324. //
  1325. FlushCache( pIrpContext, Fcb->NonPagedFcb );
  1326. }
  1327. if ( BooleanFlagOn( Fcb->Flags, FCB_FLAGS_LONG_NAME ) ) {
  1328. Status = ExchangeWithWait(
  1329. pIrpContext,
  1330. SynchronousResponseCallback,
  1331. "LbbWDW--WW==WW==_W_bDbC",
  1332. NCP_LFN_SET_INFO,
  1333. Fcb->Vcb->Specific.Disk.LongNameSpace,
  1334. Fcb->Vcb->Specific.Disk.LongNameSpace,
  1335. Fcb->NodeTypeCode == NW_NTC_FCB ?
  1336. SEARCH_ALL_FILES : SEARCH_ALL_DIRECTORIES,
  1337. LfnFlag,
  1338. NtAttributesToNwAttributes( Buffer->FileAttributes ),
  1339. Fcb->CreationDate,
  1340. Fcb->CreationTime,
  1341. Fcb->LastModifiedDate,
  1342. Fcb->LastModifiedTime,
  1343. 8,
  1344. Fcb->LastAccessDate,
  1345. 8,
  1346. Fcb->Vcb->Specific.Disk.VolumeNumber,
  1347. Fcb->Vcb->Specific.Disk.Handle,
  1348. 0,
  1349. &Fcb->RelativeFileName );
  1350. } else {
  1351. if ( LfnFlag & LFN_FLAG_SET_INFO_ATTRIBUTES ) {
  1352. Status = ExchangeWithWait(
  1353. pIrpContext,
  1354. SynchronousResponseCallback,
  1355. "FbbbU",
  1356. NCP_SET_FILE_ATTRIBUTES,
  1357. NtAttributesToNwAttributes( Buffer->FileAttributes ),
  1358. Fcb->Vcb->Specific.Disk.Handle,
  1359. Fcb->NodeTypeCode == NW_NTC_FCB ?
  1360. SEARCH_ALL_FILES : SEARCH_ALL_DIRECTORIES,
  1361. &Fcb->RelativeFileName );
  1362. if ( !NT_SUCCESS( Status ) ) {
  1363. NwReleaseFcb( Fcb->NonPagedFcb );
  1364. return( Status );
  1365. }
  1366. }
  1367. #if 0
  1368. //
  1369. // We could conceivably use ScanDir/SetDir to update last access
  1370. // and create time. Not supported yet.
  1371. //
  1372. if ( LfnFlag & ( LFN_FLAG_SET_INFO_LASTACCESS_DATE | LFN_FLAG_SET_INFO_CREATE_DATE ) ) {
  1373. ULONG SearchIndex;
  1374. ULONG Directory;
  1375. Status = ExchangeWithWait(
  1376. pIrpContext,
  1377. SynchronousResponseCallback,
  1378. "SbbdU",
  1379. 0x16, 0x1E, // Scan dir entry
  1380. Fcb->Vcb->Specific.Disk.Handle,
  1381. 0x06, // Search attributes
  1382. -1, // Search index
  1383. &Fcb->RelativeFileName );
  1384. if ( NT_SUCCESS( Status ) ) {
  1385. Status = ParseResponse(
  1386. pIrpContext,
  1387. pIrpContext->rsp,
  1388. pIrpContext->ResponseLength,
  1389. "Ndd",
  1390. &SearchIndex,
  1391. &Directory );
  1392. }
  1393. if ( NT_SUCCESS( Status ) ) {
  1394. Status = ExchangeWithWait(
  1395. pIrpContext,
  1396. SynchronousResponseCallback,
  1397. "Sbbdddw=----_ww==ww==ww",
  1398. 0x16, 0x25, // Set dir entry
  1399. Fcb->Vcb->Specific.Disk.Handle,
  1400. 0x06, // Search attributes
  1401. SearchIndex,
  1402. 0, // Change Bits?
  1403. Directory,
  1404. 12,
  1405. Fcb->CreationDate,
  1406. 0,
  1407. Fcb->LastAccessDate,
  1408. 0,
  1409. Fcb->LastModifiedDate,
  1410. Fcb->LastModifiedTime );
  1411. }
  1412. }
  1413. #endif
  1414. if ( LfnFlag & LFN_FLAG_SET_INFO_MODIFY_DATE ) {
  1415. Status = ExchangeWithWait(
  1416. pIrpContext,
  1417. SynchronousResponseCallback,
  1418. "F-rww-",
  1419. NCP_SET_FILE_TIME,
  1420. &Icb->Handle, sizeof( Icb->Handle ),
  1421. Fcb->LastModifiedTime,
  1422. Fcb->LastModifiedDate );
  1423. }
  1424. }
  1425. NwReleaseFcb( Fcb->NonPagedFcb );
  1426. //
  1427. // And return to our caller
  1428. //
  1429. return Status;
  1430. }
  1431. NTSTATUS
  1432. NwSetDispositionInfo (
  1433. IN PIRP_CONTEXT pIrpContext,
  1434. IN PICB Icb,
  1435. IN PFILE_DISPOSITION_INFORMATION Buffer
  1436. )
  1437. /*++
  1438. Routine Description:
  1439. This routine sets the disposition information for a file.
  1440. Arguments:
  1441. pIrpContext - Supplies Irp context information.
  1442. Icb - Supplies the ICB for the file being modified.
  1443. Buffer - Supplies the buffer containing the data being set.
  1444. Return Value:
  1445. NTSTATUS - Returns our completion status.
  1446. --*/
  1447. {
  1448. PFCB Fcb;
  1449. NTSTATUS Status;
  1450. PAGED_CODE();
  1451. DebugTrace(0, Dbg, "SetDispositionInfo...\n", 0);
  1452. Fcb = Icb->SuperType.Fcb;
  1453. if ( FlagOn( Fcb->Vcb->Flags, VCB_FLAG_PRINT_QUEUE ) ) {
  1454. //
  1455. // This is a print queue, just pretend this IRP succeeded.
  1456. //
  1457. Status = STATUS_SUCCESS;
  1458. } else {
  1459. //
  1460. // This is a real file or directory. Mark it delete pending.
  1461. //
  1462. SetFlag( Fcb->Flags, FCB_FLAGS_DELETE_ON_CLOSE );
  1463. pIrpContext->pNpScb = Fcb->Scb->pNpScb;
  1464. pIrpContext->Icb = Icb;
  1465. Icb->State = ICB_STATE_CLOSE_PENDING;
  1466. //
  1467. // Go ahead, delete the file.
  1468. //
  1469. Status = NwDeleteFile( pIrpContext );
  1470. }
  1471. return( Status );
  1472. }
  1473. NTSTATUS
  1474. NwDeleteFile(
  1475. PIRP_CONTEXT pIrpContext
  1476. )
  1477. /*++
  1478. Routine Description:
  1479. This routine continues processing of the SetDispositionInfo request.
  1480. It must run in the redirector FSP.
  1481. Arguments:
  1482. pIrpContext - A pointer to the IRP context information for the
  1483. request in progress.
  1484. Return Value:
  1485. The status of the operation.
  1486. --*/
  1487. {
  1488. PICB Icb;
  1489. PFCB Fcb;
  1490. NTSTATUS Status;
  1491. PAGED_CODE();
  1492. Icb = pIrpContext->Icb;
  1493. Fcb = Icb->SuperType.Fcb;
  1494. ClearFlag( Fcb->Flags, FCB_FLAGS_DELETE_ON_CLOSE );
  1495. //
  1496. // To a delete a file, first close the remote handle.
  1497. //
  1498. if ( Icb->HasRemoteHandle ) {
  1499. Icb->HasRemoteHandle = FALSE;
  1500. Status = ExchangeWithWait(
  1501. pIrpContext,
  1502. SynchronousResponseCallback,
  1503. "F-r",
  1504. NCP_CLOSE,
  1505. Icb->Handle, sizeof( Icb->Handle ) );
  1506. }
  1507. //
  1508. // Note that this request cannot be reconnectable since, it can
  1509. // be called via NwCloseIcb(). See comment in that routine for
  1510. // more info.
  1511. //
  1512. if ( Fcb->NodeTypeCode == NW_NTC_FCB ) {
  1513. if ( !BooleanFlagOn( Fcb->Flags, FCB_FLAGS_LONG_NAME ) ) {
  1514. Status = ExchangeWithWait(
  1515. pIrpContext,
  1516. SynchronousResponseCallback,
  1517. "FbbJ",
  1518. NCP_DELETE_FILE,
  1519. Fcb->Vcb->Specific.Disk.Handle,
  1520. SEARCH_ALL_FILES,
  1521. &Fcb->RelativeFileName );
  1522. } else {
  1523. Status = ExchangeWithWait(
  1524. pIrpContext,
  1525. SynchronousResponseCallback,
  1526. "LbbW-DbC",
  1527. NCP_LFN_DELETE_FILE,
  1528. Fcb->Vcb->Specific.Disk.LongNameSpace,
  1529. Fcb->Vcb->Specific.Disk.VolumeNumber,
  1530. NW_ATTRIBUTE_SYSTEM | NW_ATTRIBUTE_HIDDEN,
  1531. Fcb->Vcb->Specific.Disk.Handle,
  1532. LFN_FLAG_SHORT_DIRECTORY,
  1533. &Fcb->RelativeFileName );
  1534. }
  1535. } else {
  1536. ASSERT( Fcb->NodeTypeCode == NW_NTC_DCB );
  1537. if ( !BooleanFlagOn( Fcb->Flags, FCB_FLAGS_LONG_NAME ) ) {
  1538. Status = ExchangeWithWait(
  1539. pIrpContext,
  1540. SynchronousResponseCallback,
  1541. "SbbJ",
  1542. NCP_DIR_FUNCTION, NCP_DELETE_DIRECTORY,
  1543. Fcb->Vcb->Specific.Disk.Handle,
  1544. SEARCH_ALL_DIRECTORIES,
  1545. &Fcb->RelativeFileName );
  1546. } else {
  1547. Status = ExchangeWithWait(
  1548. pIrpContext,
  1549. SynchronousResponseCallback,
  1550. "LbbW-DbC",
  1551. NCP_LFN_DELETE_FILE,
  1552. Fcb->Vcb->Specific.Disk.LongNameSpace,
  1553. Fcb->Vcb->Specific.Disk.VolumeNumber,
  1554. SEARCH_ALL_DIRECTORIES,
  1555. Fcb->Vcb->Specific.Disk.Handle,
  1556. LFN_FLAG_SHORT_DIRECTORY,
  1557. &Fcb->RelativeFileName );
  1558. }
  1559. }
  1560. if ( NT_SUCCESS( Status )) {
  1561. Status = ParseResponse(
  1562. pIrpContext,
  1563. pIrpContext->rsp,
  1564. pIrpContext->ResponseLength,
  1565. "N" );
  1566. } else {
  1567. //
  1568. // We can map all failures to STATUS_NO_SUCH_FILE
  1569. // except ACCESS_DENIED, which happens with a read
  1570. // only file.
  1571. //
  1572. if ( Status != STATUS_ACCESS_DENIED ) {
  1573. Status = STATUS_NO_SUCH_FILE;
  1574. }
  1575. }
  1576. return Status;
  1577. }
  1578. NTSTATUS
  1579. NwSetRenameInfo (
  1580. IN PIRP_CONTEXT IrpContext,
  1581. IN PICB Icb,
  1582. IN PFILE_RENAME_INFORMATION Buffer
  1583. )
  1584. /*++
  1585. Routine Description:
  1586. This routine set rename information for a file.
  1587. Arguments:
  1588. pIrpContext - A pointer to the IRP context information for the
  1589. request in progress.
  1590. Icb - A pointer to the ICB of the file to set.
  1591. Buffer - The request buffer.
  1592. Return Value:
  1593. The status of the operation.
  1594. --*/
  1595. {
  1596. PIRP Irp;
  1597. PIO_STACK_LOCATION irpSp;
  1598. NTSTATUS Status;
  1599. NTSTATUS Status2;
  1600. PFCB Fcb;
  1601. PFCB TargetFcb;
  1602. BOOLEAN HandleAllocated = FALSE;
  1603. BYTE Handle;
  1604. PICB TargetIcb = NULL;
  1605. UNICODE_STRING OldDrive;
  1606. UNICODE_STRING OldServer;
  1607. UNICODE_STRING OldVolume;
  1608. UNICODE_STRING OldPath;
  1609. UNICODE_STRING OldFileName;
  1610. UNICODE_STRING OldFullName;
  1611. WCHAR OldDriveLetter;
  1612. UNICODE_STRING OldFcbFullName;
  1613. UNICODE_STRING NewDrive;
  1614. UNICODE_STRING NewServer;
  1615. UNICODE_STRING NewVolume;
  1616. UNICODE_STRING NewPath;
  1617. UNICODE_STRING NewFileName;
  1618. UNICODE_STRING NewFullName;
  1619. WCHAR NewDriveLetter;
  1620. UNICODE_STRING NewFcbFullName;
  1621. USHORT i;
  1622. PAGED_CODE();
  1623. DebugTrace(+1, Dbg, "SetRenameInfo...\n", 0);
  1624. //
  1625. // Can't try to set rename info on a print queue.
  1626. //
  1627. Fcb = Icb->SuperType.Fcb;
  1628. if ( FlagOn( Fcb->Vcb->Flags, VCB_FLAG_PRINT_QUEUE ) ) {
  1629. return( STATUS_INVALID_PARAMETER );
  1630. }
  1631. //
  1632. // It is ok to attempt a reconnect if this request fails with a
  1633. // connection error.
  1634. //
  1635. SetFlag( IrpContext->Flags, IRP_FLAG_RECONNECTABLE );
  1636. //
  1637. // Get the current stack location.
  1638. //
  1639. Irp = IrpContext->pOriginalIrp;
  1640. irpSp = IoGetCurrentIrpStackLocation( Irp );
  1641. DebugTrace( 0, Dbg, " ->FullFileName = %wZ\n",
  1642. &Fcb->FullFileName);
  1643. if (irpSp->Parameters.SetFile.FileObject != NULL) {
  1644. TargetIcb = irpSp->Parameters.SetFile.FileObject->FsContext2;
  1645. DebugTrace( 0, Dbg, " ->FullFileName = %wZ\n",
  1646. &TargetIcb->SuperType.Fcb->FullFileName);
  1647. if ( TargetIcb->SuperType.Fcb->Scb != Icb->SuperType.Fcb->Scb ) {
  1648. return STATUS_NOT_SAME_DEVICE;
  1649. }
  1650. } else {
  1651. DebugTrace( 0, Dbg, " ->FullFileName in users buffer\n", 0);
  1652. DebugTrace(-1, Dbg, "SetRenameInfo %08lx\n", STATUS_NOT_IMPLEMENTED);
  1653. return STATUS_NOT_IMPLEMENTED;
  1654. }
  1655. DebugTrace( 0, Dbg, " ->TargetFileName = %wZ\n",
  1656. &irpSp->Parameters.SetFile.FileObject->FileName);
  1657. TargetFcb = ((PNONPAGED_FCB)irpSp->Parameters.SetFile.FileObject->FsContext)->Fcb;
  1658. IrpContext->pNpScb = Fcb->Scb->pNpScb;
  1659. NwAppendToQueueAndWait( IrpContext );
  1660. NwAcquireExclusiveFcb( Fcb->NonPagedFcb, TRUE );
  1661. try {
  1662. //
  1663. // If either source or destination is a long name, use
  1664. // the long name path.
  1665. //
  1666. if ( !BooleanFlagOn( Fcb->Flags, FCB_FLAGS_LONG_NAME ) &&
  1667. IsFatNameValid( &TargetFcb->RelativeFileName ) &&
  1668. !BooleanFlagOn( Fcb->Vcb->Flags, VCB_FLAG_LONG_NAME ) ) {
  1669. //
  1670. // Strip to UID portion of the FCB name.
  1671. //
  1672. for ( i = 0 ; i < Fcb->FullFileName.Length / sizeof(WCHAR) ; i++ ) {
  1673. if ( Fcb->FullFileName.Buffer[i] == OBJ_NAME_PATH_SEPARATOR ) {
  1674. break;
  1675. }
  1676. }
  1677. ASSERT( Fcb->FullFileName.Buffer[i] == OBJ_NAME_PATH_SEPARATOR );
  1678. OldFcbFullName.Length = Fcb->FullFileName.Length - i*sizeof(WCHAR);
  1679. OldFcbFullName.Buffer = Fcb->FullFileName.Buffer + i;
  1680. Status = CrackPath (
  1681. &OldFcbFullName,
  1682. &OldDrive,
  1683. &OldDriveLetter,
  1684. &OldServer,
  1685. &OldVolume,
  1686. &OldPath,
  1687. &OldFileName,
  1688. &OldFullName );
  1689. ASSERT(NT_SUCCESS(Status));
  1690. //
  1691. // Strip to UID portion of the FCB name.
  1692. //
  1693. TargetFcb = ((PNONPAGED_FCB)(irpSp->Parameters.SetFile.FileObject->FsContext))->Fcb;
  1694. for ( i = 0 ; i < TargetFcb->FullFileName.Length / sizeof(WCHAR) ; i++ ) {
  1695. if ( TargetFcb->FullFileName.Buffer[i] == OBJ_NAME_PATH_SEPARATOR ) {
  1696. break;
  1697. }
  1698. }
  1699. ASSERT( TargetFcb->FullFileName.Buffer[i] == OBJ_NAME_PATH_SEPARATOR );
  1700. NewFcbFullName.Length = TargetFcb->FullFileName.Length - i*sizeof(WCHAR);
  1701. NewFcbFullName.Buffer = TargetFcb->FullFileName.Buffer + i;
  1702. Status = CrackPath (
  1703. &NewFcbFullName,
  1704. &NewDrive,
  1705. &NewDriveLetter,
  1706. &NewServer,
  1707. &NewVolume,
  1708. &NewPath,
  1709. &NewFileName,
  1710. &NewFullName );
  1711. ASSERT(NT_SUCCESS(Status));
  1712. //
  1713. // Make sure that this is the same volume.
  1714. //
  1715. if ( RtlCompareUnicodeString( &NewVolume, &OldVolume, TRUE ) != 0 ) {
  1716. try_return( Status = STATUS_NOT_SAME_DEVICE );
  1717. }
  1718. if (Icb->SuperType.Fcb->IcbCount != 1) {
  1719. try_return( Status = STATUS_ACCESS_DENIED );
  1720. }
  1721. //
  1722. // After a rename, the only operation allowed on the handle is an
  1723. // NtClose.
  1724. //
  1725. Icb->State = ICB_STATE_CLOSE_PENDING;
  1726. if ((irpSp->Parameters.SetFile.ReplaceIfExists ) &&
  1727. (TargetIcb->Exists)) {
  1728. // Delete the file
  1729. Status2 = ExchangeWithWait(
  1730. IrpContext,
  1731. SynchronousResponseCallback,
  1732. "Fb-J",
  1733. NCP_DELETE_FILE,
  1734. TargetFcb->Vcb->Specific.Disk.Handle,
  1735. &TargetFcb->RelativeFileName );
  1736. #ifdef NWDBG
  1737. if ( NT_SUCCESS( Status2 ) ) {
  1738. Status2 = ParseResponse(
  1739. IrpContext,
  1740. IrpContext->rsp,
  1741. IrpContext->ResponseLength,
  1742. "N" );
  1743. }
  1744. ASSERT(NT_SUCCESS(Status2));
  1745. #endif
  1746. }
  1747. //
  1748. // Need to create a handle to the directory containing the old
  1749. // file/directory name because directory rename does not contain a
  1750. // path and there might not be room for two paths in a file rename.
  1751. //
  1752. // The way we do this is to allocate a temporary handle on the server.
  1753. // This request is at the front of the Scb->Requests queue and so can
  1754. // use the temporary handle and delete it without affecting any other
  1755. // requests.
  1756. //
  1757. if ( OldPath.Length == 0 ) {
  1758. // In the root so use the VCB handle.
  1759. Handle = Fcb->Vcb->Specific.Disk.Handle;
  1760. } else {
  1761. Status = ExchangeWithWait (
  1762. IrpContext,
  1763. SynchronousResponseCallback,
  1764. "SbbJ", // NCP Allocate temporary directory handle
  1765. NCP_DIR_FUNCTION, NCP_ALLOCATE_TEMP_DIR_HANDLE,
  1766. Fcb->Vcb->Specific.Disk.Handle,
  1767. '[',
  1768. &OldPath );
  1769. if ( NT_SUCCESS( Status ) ) {
  1770. Status = ParseResponse(
  1771. IrpContext,
  1772. IrpContext->rsp,
  1773. IrpContext->ResponseLength,
  1774. "Nb",
  1775. &Handle );
  1776. }
  1777. if (!NT_SUCCESS(Status)) {
  1778. try_return(Status);
  1779. }
  1780. HandleAllocated = TRUE;
  1781. }
  1782. if ( Fcb->NodeTypeCode == NW_NTC_DCB ) {
  1783. //
  1784. // We can only rename files in the same directory
  1785. //
  1786. if ( RtlCompareUnicodeString( &NewPath, &OldPath, TRUE ) != 0 ) {
  1787. try_return(Status = STATUS_NOT_SUPPORTED);
  1788. } else {
  1789. Status = ExchangeWithWait ( IrpContext,
  1790. SynchronousResponseCallback,
  1791. "SbJJ",
  1792. NCP_DIR_FUNCTION, NCP_RENAME_DIRECTORY,
  1793. Handle,
  1794. &OldFileName,
  1795. &NewFileName);
  1796. }
  1797. } else {
  1798. //
  1799. // We have to close the handle associated with the Icb that
  1800. // is doing the rename. Close that handle or the rename will
  1801. // fail for sure.
  1802. //
  1803. if ( Icb->HasRemoteHandle ) {
  1804. Status2 = ExchangeWithWait(
  1805. IrpContext,
  1806. SynchronousResponseCallback,
  1807. "F-r",
  1808. NCP_CLOSE,
  1809. Icb->Handle, sizeof( Icb->Handle ) );
  1810. Icb->HasRemoteHandle = FALSE;
  1811. #ifdef NWDBG
  1812. if ( NT_SUCCESS( Status2 ) ) {
  1813. Status2 = ParseResponse(
  1814. IrpContext,
  1815. IrpContext->rsp,
  1816. IrpContext->ResponseLength,
  1817. "N" );
  1818. }
  1819. ASSERT(NT_SUCCESS(Status2));
  1820. #endif
  1821. }
  1822. //
  1823. // Do the file rename Ncp.
  1824. //
  1825. Status = ExchangeWithWait (
  1826. IrpContext,
  1827. SynchronousResponseCallback,
  1828. "FbbJbJ",
  1829. NCP_RENAME_FILE,
  1830. Handle,
  1831. SEARCH_ALL_FILES,
  1832. &OldFileName,
  1833. Fcb->Vcb->Specific.Disk.Handle,
  1834. &NewFullName);
  1835. }
  1836. } else {
  1837. //
  1838. // We are going through the long name path. Ensure that the
  1839. // VCB supports long names.
  1840. //
  1841. if ( Icb->SuperType.Fcb->Vcb->Specific.Disk.LongNameSpace ==
  1842. LFN_NO_OS2_NAME_SPACE) {
  1843. try_return( Status = STATUS_OBJECT_PATH_SYNTAX_BAD );
  1844. }
  1845. if (Icb->SuperType.Fcb->IcbCount != 1) {
  1846. try_return( Status = STATUS_ACCESS_DENIED);
  1847. }
  1848. //
  1849. // After a rename, the only operation allowed on the handle is an
  1850. // NtClose.
  1851. //
  1852. Icb->State = ICB_STATE_CLOSE_PENDING;
  1853. if ((irpSp->Parameters.SetFile.ReplaceIfExists ) &&
  1854. (TargetIcb->Exists)) {
  1855. // Delete the file
  1856. Status = ExchangeWithWait(
  1857. IrpContext,
  1858. SynchronousResponseCallback,
  1859. "LbbW-DbC",
  1860. NCP_LFN_DELETE_FILE,
  1861. TargetFcb->Vcb->Specific.Disk.LongNameSpace,
  1862. TargetFcb->Vcb->Specific.Disk.VolumeNumber,
  1863. SEARCH_ALL_FILES,
  1864. TargetFcb->Vcb->Specific.Disk.Handle,
  1865. LFN_FLAG_SHORT_DIRECTORY,
  1866. &TargetFcb->RelativeFileName );
  1867. #ifdef NWDBG
  1868. if ( NT_SUCCESS( Status ) ) {
  1869. Status2 = ParseResponse(
  1870. IrpContext,
  1871. IrpContext->rsp,
  1872. IrpContext->ResponseLength,
  1873. "N" );
  1874. }
  1875. ASSERT(NT_SUCCESS(Status2));
  1876. #endif
  1877. }
  1878. if ( Fcb->NodeTypeCode == NW_NTC_DCB ) {
  1879. //
  1880. // We can only rename files in the same directory
  1881. //
  1882. if ( Fcb->Vcb != TargetFcb->Vcb ) {
  1883. try_return(Status = STATUS_NOT_SUPPORTED);
  1884. } else {
  1885. Status = ExchangeWithWait (
  1886. IrpContext,
  1887. SynchronousResponseCallback,
  1888. "LbbWbDbbbDbbNN",
  1889. NCP_LFN_RENAME_FILE,
  1890. Fcb->Vcb->Specific.Disk.LongNameSpace,
  1891. 0, // Rename flag
  1892. SEARCH_ALL_DIRECTORIES,
  1893. Fcb->Vcb->Specific.Disk.VolumeNumber,
  1894. Fcb->Vcb->Specific.Disk.Handle,
  1895. LFN_FLAG_SHORT_DIRECTORY,
  1896. OccurenceCount( &Fcb->RelativeFileName, OBJ_NAME_PATH_SEPARATOR ) + 1,
  1897. Fcb->Vcb->Specific.Disk.VolumeNumber,
  1898. Fcb->Vcb->Specific.Disk.Handle,
  1899. LFN_FLAG_SHORT_DIRECTORY,
  1900. OccurenceCount( &TargetFcb->RelativeFileName, OBJ_NAME_PATH_SEPARATOR ) + 1,
  1901. &Fcb->RelativeFileName,
  1902. &TargetFcb->RelativeFileName );
  1903. }
  1904. } else {
  1905. //
  1906. // We have to close the handle associated with the Icb that
  1907. // is doing the rename. Close that handle or the rename will
  1908. // fail for sure.
  1909. //
  1910. if ( Icb->HasRemoteHandle ) {
  1911. Status2 = ExchangeWithWait(
  1912. IrpContext,
  1913. SynchronousResponseCallback,
  1914. "F-r",
  1915. NCP_CLOSE,
  1916. Icb->Handle, sizeof( Icb->Handle ) );
  1917. Icb->HasRemoteHandle = FALSE;
  1918. #ifdef NWDBG
  1919. if ( NT_SUCCESS( Status2 ) ) {
  1920. Status2 = ParseResponse(
  1921. IrpContext,
  1922. IrpContext->rsp,
  1923. IrpContext->ResponseLength,
  1924. "N" );
  1925. }
  1926. ASSERT(NT_SUCCESS(Status2));
  1927. #endif
  1928. }
  1929. //
  1930. // Do the file rename Ncp.
  1931. //
  1932. Status = ExchangeWithWait (
  1933. IrpContext,
  1934. SynchronousResponseCallback,
  1935. "LbbWbDbbbDbbNN",
  1936. NCP_LFN_RENAME_FILE,
  1937. Fcb->Vcb->Specific.Disk.LongNameSpace,
  1938. 0, // Rename flag
  1939. SEARCH_ALL_FILES,
  1940. Fcb->Vcb->Specific.Disk.VolumeNumber,
  1941. Fcb->Vcb->Specific.Disk.Handle,
  1942. LFN_FLAG_SHORT_DIRECTORY,
  1943. OccurenceCount( &Fcb->RelativeFileName, OBJ_NAME_PATH_SEPARATOR ) + 1,
  1944. Fcb->Vcb->Specific.Disk.VolumeNumber,
  1945. Fcb->Vcb->Specific.Disk.Handle,
  1946. LFN_FLAG_SHORT_DIRECTORY,
  1947. OccurenceCount( &TargetFcb->RelativeFileName, OBJ_NAME_PATH_SEPARATOR ) + 1,
  1948. &Fcb->RelativeFileName,
  1949. &TargetFcb->RelativeFileName );
  1950. }
  1951. }
  1952. try_exit: NOTHING;
  1953. } finally {
  1954. if (HandleAllocated) {
  1955. Status2 = ExchangeWithWait (
  1956. IrpContext,
  1957. SynchronousResponseCallback,
  1958. "Sb", // NCP Deallocate directory handle
  1959. NCP_DIR_FUNCTION, NCP_DEALLOCATE_DIR_HANDLE,
  1960. Handle);
  1961. #ifdef NWDBG
  1962. if ( NT_SUCCESS( Status2 ) ) {
  1963. Status2 = ParseResponse(
  1964. IrpContext,
  1965. IrpContext->rsp,
  1966. IrpContext->ResponseLength,
  1967. "N" );
  1968. }
  1969. ASSERT(NT_SUCCESS(Status2));
  1970. #endif
  1971. }
  1972. NwReleaseFcb( Fcb->NonPagedFcb );
  1973. }
  1974. DebugTrace(-1, Dbg, "SetRenameInfo %08lx\n", Status );
  1975. //
  1976. // We're done with this request. Dequeue the IRP context from
  1977. // SCB and complete the request.
  1978. //
  1979. if ( Status != STATUS_PENDING ) {
  1980. NwDequeueIrpContext( IrpContext, FALSE );
  1981. }
  1982. return Status;
  1983. }
  1984. NTSTATUS
  1985. NwSetPositionInfo (
  1986. IN PIRP_CONTEXT IrpContext,
  1987. IN PICB Icb,
  1988. IN PFILE_POSITION_INFORMATION Buffer
  1989. )
  1990. /*++
  1991. Routine Description:
  1992. This routine sets position information for a file.
  1993. Arguments:
  1994. pIrpContext - A pointer to the IRP context information for the
  1995. request in progress.
  1996. Icb - A pointer to the ICB of the file to set.
  1997. Buffer - The request buffer.
  1998. Return Value:
  1999. The status of the operation.
  2000. --*/
  2001. {
  2002. PAGED_CODE();
  2003. ASSERT( Buffer->CurrentByteOffset.HighPart == 0 );
  2004. if ( Icb->FileObject ) {
  2005. Icb->FileObject->CurrentByteOffset.QuadPart = Buffer->CurrentByteOffset.QuadPart;
  2006. }
  2007. return( STATUS_SUCCESS );
  2008. }
  2009. NTSTATUS
  2010. NwSetAllocationInfo (
  2011. IN PIRP_CONTEXT IrpContext,
  2012. IN PICB Icb,
  2013. IN PFILE_ALLOCATION_INFORMATION Buffer
  2014. )
  2015. /*++
  2016. Routine Description:
  2017. This routine sets allocation information for a file.
  2018. Arguments:
  2019. pIrpContext - A pointer to the IRP context information for the
  2020. request in progress.
  2021. Icb - A pointer to the ICB of the file to set.
  2022. Buffer - The request buffer.
  2023. Return Value:
  2024. The status of the operation.
  2025. --*/
  2026. {
  2027. NTSTATUS Status;
  2028. PIRP irp;
  2029. PIO_STACK_LOCATION irpSp;
  2030. PFCB fcb = (PFCB)Icb->SuperType.Fcb;
  2031. PULONG pFileSize;
  2032. PAGED_CODE();
  2033. ASSERT( Buffer->AllocationSize.HighPart == 0);
  2034. if ( fcb->NodeTypeCode == NW_NTC_FCB ) {
  2035. pFileSize = &Icb->NpFcb->Header.FileSize.LowPart;
  2036. IrpContext->pNpScb = fcb->Scb->pNpScb;
  2037. if (BooleanFlagOn( fcb->Vcb->Flags, VCB_FLAG_PRINT_QUEUE ) ) {
  2038. if (IsTerminalServer()) {
  2039. // 2/10/97 cjc Fix problem for binary files not printing correctly
  2040. // if done via the COPY command. Works with NT RDR so
  2041. // changed this to behave same way.
  2042. return(STATUS_INVALID_PARAMETER);
  2043. } else {
  2044. return STATUS_SUCCESS;
  2045. }
  2046. }
  2047. } else if ( fcb->NodeTypeCode == NW_NTC_SCB ) {
  2048. pFileSize = &Icb->FileSize;
  2049. IrpContext->pNpScb = ((PSCB)fcb)->pNpScb;
  2050. } else {
  2051. DebugTrace(0, Dbg, "Not a file or a server\n", 0);
  2052. DebugTrace( 0, Dbg, "NwSetAllocationInfo -> %08lx\n", STATUS_INVALID_PARAMETER );
  2053. return STATUS_INVALID_PARAMETER;
  2054. }
  2055. NwAppendToQueueAndWait( IrpContext );
  2056. if ( !Icb->HasRemoteHandle ) {
  2057. Status = STATUS_INVALID_PARAMETER;
  2058. } else if ( Buffer->AllocationSize.LowPart == *pFileSize ) {
  2059. Status = STATUS_SUCCESS;
  2060. } else {
  2061. irp = IrpContext->pOriginalIrp;
  2062. irpSp = IoGetCurrentIrpStackLocation( irp );
  2063. #ifndef QFE_BUILD
  2064. if ( Buffer->AllocationSize.LowPart < *pFileSize ) {
  2065. //
  2066. // Before we actually truncate, check to see if the purge
  2067. // is going to fail.
  2068. //
  2069. if (!MmCanFileBeTruncated( irpSp->FileObject->SectionObjectPointer,
  2070. &Buffer->AllocationSize )) {
  2071. return( STATUS_USER_MAPPED_FILE );
  2072. }
  2073. }
  2074. #endif
  2075. if ( fcb->NodeTypeCode == NW_NTC_FCB ) {
  2076. AcquireFcbAndFlushCache( IrpContext, fcb->NonPagedFcb );
  2077. }
  2078. Status = ExchangeWithWait(
  2079. IrpContext,
  2080. SynchronousResponseCallback,
  2081. "F-rd=",
  2082. NCP_WRITE_FILE,
  2083. &Icb->Handle, sizeof( Icb->Handle ),
  2084. Buffer->AllocationSize.LowPart );
  2085. if ( NT_SUCCESS( Status ) ) {
  2086. *pFileSize = Buffer->AllocationSize.LowPart;
  2087. }
  2088. }
  2089. NwDequeueIrpContext( IrpContext, FALSE );
  2090. return( Status );
  2091. }
  2092. NTSTATUS
  2093. NwSetEndOfFileInfo (
  2094. IN PIRP_CONTEXT IrpContext,
  2095. IN PICB Icb,
  2096. IN PFILE_END_OF_FILE_INFORMATION Buffer
  2097. )
  2098. /*++
  2099. Routine Description:
  2100. This routine sets end of file information for a file.
  2101. Arguments:
  2102. pIrpContext - A pointer to the IRP context information for the
  2103. request in progress.
  2104. Icb - A pointer to the ICB of the file to set.
  2105. Buffer - The request buffer.
  2106. Return Value:
  2107. The status of the operation.
  2108. --*/
  2109. {
  2110. NTSTATUS Status;
  2111. PIRP irp;
  2112. PIO_STACK_LOCATION irpSp;
  2113. PFCB fcb = (PFCB)Icb->SuperType.Fcb;
  2114. PULONG pFileSize;
  2115. PAGED_CODE();
  2116. ASSERT( Buffer->EndOfFile.HighPart == 0);
  2117. if ( fcb->NodeTypeCode == NW_NTC_FCB ) {
  2118. pFileSize = &Icb->NpFcb->Header.FileSize.LowPart;
  2119. IrpContext->pNpScb = fcb->Scb->pNpScb;
  2120. if (BooleanFlagOn( fcb->Vcb->Flags, VCB_FLAG_PRINT_QUEUE ) ) {
  2121. return STATUS_SUCCESS;
  2122. }
  2123. } else if ( fcb->NodeTypeCode == NW_NTC_SCB ) {
  2124. pFileSize = &Icb->FileSize;
  2125. IrpContext->pNpScb = ((PSCB)fcb)->pNpScb;
  2126. } else {
  2127. DebugTrace(0, Dbg, "Not a file or a server\n", 0);
  2128. DebugTrace( 0, Dbg, "NwSetAllocationInfo -> %08lx\n", STATUS_INVALID_PARAMETER );
  2129. return STATUS_INVALID_PARAMETER;
  2130. }
  2131. NwAppendToQueueAndWait( IrpContext );
  2132. if ( !Icb->HasRemoteHandle ) {
  2133. Status = STATUS_INVALID_PARAMETER;
  2134. } else if ( Buffer->EndOfFile.LowPart == *pFileSize ) {
  2135. Status = STATUS_SUCCESS;
  2136. } else {
  2137. irp = IrpContext->pOriginalIrp;
  2138. irpSp = IoGetCurrentIrpStackLocation( irp );
  2139. #ifndef QFE_BUILD
  2140. if ( Buffer->EndOfFile.LowPart < *pFileSize ) {
  2141. //
  2142. // Before we actually truncate, check to see if the purge
  2143. // is going to fail.
  2144. //
  2145. if (!MmCanFileBeTruncated( irpSp->FileObject->SectionObjectPointer,
  2146. &Buffer->EndOfFile )) {
  2147. return( STATUS_USER_MAPPED_FILE );
  2148. }
  2149. }
  2150. #endif
  2151. if ( fcb->NodeTypeCode == NW_NTC_FCB ) {
  2152. AcquireFcbAndFlushCache( IrpContext, fcb->NonPagedFcb );
  2153. }
  2154. Status = ExchangeWithWait(
  2155. IrpContext,
  2156. SynchronousResponseCallback,
  2157. "F-rd=",
  2158. NCP_WRITE_FILE,
  2159. &Icb->Handle, sizeof( Icb->Handle ),
  2160. Buffer->EndOfFile.LowPart );
  2161. if ( NT_SUCCESS( Status ) ) {
  2162. *pFileSize = Buffer->EndOfFile.LowPart;
  2163. }
  2164. }
  2165. NwDequeueIrpContext( IrpContext, FALSE );
  2166. return( Status );
  2167. }
  2168. ULONG
  2169. OccurenceCount (
  2170. IN PUNICODE_STRING String,
  2171. IN WCHAR SearchChar
  2172. )
  2173. /*++
  2174. Routine Description:
  2175. This routine counts the number of occurences of a search character
  2176. in a string
  2177. Arguments:
  2178. String - The string to search
  2179. SearchChar - The character to search for.
  2180. Return Value:
  2181. The occurence count.
  2182. --*/
  2183. {
  2184. PWCH currentChar;
  2185. PWCH endOfString;
  2186. ULONG count = 0;
  2187. PAGED_CODE();
  2188. currentChar = String->Buffer;
  2189. endOfString = &String->Buffer[ String->Length / sizeof(WCHAR) ];
  2190. while ( currentChar < endOfString ) {
  2191. if ( *currentChar == SearchChar ) {
  2192. count++;
  2193. }
  2194. currentChar++;
  2195. }
  2196. return( count );
  2197. }