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.

2506 lines
72 KiB

  1. #include "brian.h"
  2. typedef struct _ASYNC_SETFILE {
  3. USHORT FileIndex;
  4. FILE_INFORMATION_CLASS FileInfoClass;
  5. ULONG BufferLength;
  6. PULONG BufferLengthPtr;
  7. USHORT CreateTimeIndex;
  8. PUSHORT CreateTimePtr;
  9. USHORT LastAccessIndex;
  10. PUSHORT LastAccessPtr;
  11. USHORT LastWriteIndex;
  12. PUSHORT LastWritePtr;
  13. USHORT ChangeTimeIndex;
  14. PUSHORT ChangeTimePtr;
  15. ULONG FileAttributes;
  16. PULONG FileAttributesPtr;
  17. ULONG RenameLength;
  18. PULONG RenameLengthPtr;
  19. BOOLEAN ReplaceIfExists;
  20. USHORT RootDirectoryIndex;
  21. PUSHORT RootDirectoryPtr;
  22. USHORT RenameIndex;
  23. BOOLEAN RenameBufferAllocated;
  24. ULONG NameLength;
  25. PULONG NameLengthPtr;
  26. USHORT NameIndex;
  27. BOOLEAN NameBufferAllocated;
  28. ULONG ShortNameLength;
  29. PULONG ShortNameLengthPtr;
  30. USHORT ShortNameIndex;
  31. BOOLEAN ShortNameBufferAllocated;
  32. BOOLEAN DeleteFile;
  33. LARGE_INTEGER NewOffset;
  34. ULONG FileMode;
  35. LARGE_INTEGER NewAllocation;
  36. LARGE_INTEGER NewEof;
  37. BOOLEAN DisplayParms;
  38. BOOLEAN VerboseResults;
  39. USHORT AsyncIndex;
  40. } ASYNC_SETFILE, *PASYNC_SETFILE;
  41. #define SETFILE_LENGTH_DEFAULT 100
  42. #define FILE_INFO_CLASS_DEFAULT FileBasicInformation
  43. #define REPLACE_IF_EXISTS_DEFAULT TRUE
  44. #define DELETE_FILE_DEFAULT TRUE
  45. #define FILE_MODE_DEFAULT FILE_SYNCHRONOUS_IO_NONALERT
  46. #define DISPLAY_PARMS_DEFAULT FALSE
  47. #define VERBOSE_RESULTS_DEFAULT TRUE
  48. VOID
  49. FullSetFile(
  50. IN OUT PASYNC_SETFILE AsyncSetFile
  51. );
  52. VOID
  53. SetBasicInformation(
  54. IN OUT PASYNC_SETFILE AsyncSetFile
  55. );
  56. VOID
  57. SetRenameInformation(
  58. IN OUT PASYNC_SETFILE AsyncSetFile
  59. );
  60. VOID
  61. SetNameInformation(
  62. IN OUT PASYNC_SETFILE AsyncSetFile
  63. );
  64. VOID
  65. SetShortNameInformation(
  66. IN OUT PASYNC_SETFILE AsyncSetFile
  67. );
  68. VOID
  69. SetDispositionInformation(
  70. IN OUT PASYNC_SETFILE AsyncSetFile
  71. );
  72. VOID
  73. SetPositionInformation(
  74. IN OUT PASYNC_SETFILE AsyncSetFile
  75. );
  76. VOID
  77. SetModeInformation (
  78. IN OUT PASYNC_SETFILE AsyncSetFile
  79. );
  80. VOID
  81. SetAllocationInformation(
  82. IN OUT PASYNC_SETFILE AsyncSetFile
  83. );
  84. VOID
  85. SetEofInformation(
  86. IN OUT PASYNC_SETFILE AsyncSetFile
  87. );
  88. VOID
  89. InputSetFile (
  90. IN PCHAR ParamBuffer
  91. )
  92. {
  93. USHORT FileIndex;
  94. FILE_INFORMATION_CLASS FileInfoClass;
  95. ULONG BufferLength;
  96. PULONG BufferLengthPtr;
  97. USHORT CreateTimeIndex;
  98. PUSHORT CreateTimePtr;
  99. USHORT LastAccessIndex;
  100. PUSHORT LastAccessPtr;
  101. USHORT LastWriteIndex;
  102. PUSHORT LastWritePtr;
  103. USHORT ChangeTimeIndex;
  104. PUSHORT ChangeTimePtr;
  105. ULONG FileAttributes;
  106. PULONG FileAttributesPtr;
  107. ANSI_STRING AnsiRenameString;
  108. ULONG RenameLength;
  109. PULONG RenameLengthPtr;
  110. BOOLEAN ReplaceIfExists;
  111. USHORT RootDirectoryIndex;
  112. PUSHORT RootDirectoryPtr;
  113. USHORT RenameIndex;
  114. BOOLEAN RenameBufferAllocated;
  115. PUCHAR FileRenamePtr;
  116. ANSI_STRING AnsiNameString;
  117. ULONG NameLength;
  118. PULONG NameLengthPtr;
  119. USHORT NameIndex = 0;
  120. BOOLEAN NameBufferAllocated;
  121. PUCHAR FileNamePtr;
  122. ULONG ShortNameLength;
  123. PULONG ShortNameLengthPtr;
  124. USHORT ShortNameIndex = 0;
  125. BOOLEAN ShortNameBufferAllocated;
  126. PUCHAR FileShortNamePtr;
  127. BOOLEAN DeleteFile;
  128. LARGE_INTEGER NewOffset;
  129. ULONG FileMode;
  130. LARGE_INTEGER NewAllocation;
  131. LARGE_INTEGER NewEof;
  132. BOOLEAN DisplayParms;
  133. BOOLEAN VerboseResults;
  134. USHORT AsyncIndex;
  135. BOOLEAN ParamReceived;
  136. BOOLEAN LastInput;
  137. //
  138. // Set the defaults.
  139. //
  140. FileInfoClass = FILE_INFO_CLASS_DEFAULT;
  141. BufferLengthPtr = NULL;
  142. CreateTimePtr = NULL;
  143. LastAccessPtr = NULL;
  144. LastWritePtr = NULL;
  145. ChangeTimePtr = NULL;
  146. FileAttributes = 0;
  147. FileAttributesPtr = NULL;
  148. RenameLengthPtr = NULL;
  149. ReplaceIfExists = REPLACE_IF_EXISTS_DEFAULT;
  150. RootDirectoryPtr = NULL;
  151. RenameBufferAllocated = FALSE;
  152. FileRenamePtr = NULL;
  153. NameLengthPtr = NULL;
  154. NameBufferAllocated = FALSE;
  155. FileNamePtr = NULL;
  156. ShortNameLengthPtr = NULL;
  157. ShortNameBufferAllocated = FALSE;
  158. FileShortNamePtr = NULL;
  159. DeleteFile = DELETE_FILE_DEFAULT;
  160. NewOffset = RtlConvertUlongToLargeInteger( 0L );
  161. FileMode = FILE_MODE_DEFAULT;
  162. NewAllocation = NewOffset;
  163. NewEof = NewOffset;
  164. DisplayParms = DISPLAY_PARMS_DEFAULT;
  165. VerboseResults = VERBOSE_RESULTS_DEFAULT;
  166. ParamReceived = FALSE;
  167. LastInput = TRUE;
  168. //
  169. // While there is more input, analyze the parameter and update the
  170. // query flags.
  171. //
  172. while (TRUE) {
  173. ULONG DummyCount;
  174. //
  175. // Swallow leading white spaces.
  176. //
  177. ParamBuffer = SwallowWhite( ParamBuffer, &DummyCount );
  178. if (*ParamBuffer) {
  179. //
  180. // If the next parameter is legal then check the paramter value.
  181. // Update the parameter value.
  182. //
  183. if ((*ParamBuffer == '-'
  184. || *ParamBuffer == '/')
  185. && (ParamBuffer++, *ParamBuffer != '\0')) {
  186. BOOLEAN SwitchBool;
  187. //
  188. // Switch on the next character.
  189. //
  190. switch (*ParamBuffer) {
  191. //
  192. // Update the byte count.
  193. //
  194. case 'l' :
  195. case 'L' :
  196. //
  197. // Move to the next character, as long as there
  198. // are no white spaces continue analyzing letters.
  199. // On the first bad letter, skip to the next
  200. // parameter.
  201. //
  202. ParamBuffer++;
  203. if (*ParamBuffer == '\0') {
  204. break;
  205. }
  206. switch (*ParamBuffer) {
  207. case 'b':
  208. case 'B':
  209. BufferLength = AsciiToInteger( ++ParamBuffer );
  210. BufferLengthPtr = &BufferLength;
  211. break;
  212. case 'r':
  213. case 'R':
  214. RenameLength = AsciiToInteger( ++ParamBuffer );
  215. RenameLengthPtr = &RenameLength;
  216. break;
  217. case 'n':
  218. case 'N':
  219. NameLength = AsciiToInteger( ++ParamBuffer );
  220. NameLengthPtr = &NameLength;
  221. break;
  222. case 's':
  223. case 'S':
  224. ShortNameLength = AsciiToInteger( ++ParamBuffer );
  225. ShortNameLengthPtr = &ShortNameLength;
  226. break;
  227. }
  228. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  229. break;
  230. //
  231. // Update the allocation size.
  232. //
  233. case 'n' :
  234. case 'N' :
  235. NewAllocation.QuadPart = AsciiToLargeInteger( ++ParamBuffer );
  236. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  237. break;
  238. //
  239. // Update the End of file size.
  240. //
  241. case 'e' :
  242. case 'E' :
  243. NewEof.QuadPart = AsciiToLargeInteger( ++ParamBuffer );
  244. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  245. break;
  246. //
  247. // Update the filenames.
  248. //
  249. case 'f' :
  250. case 'F' :
  251. //
  252. // Move to the next character, as long as there
  253. // are no white spaces continue analyzing letters.
  254. // On the first bad letter, skip to the next
  255. // parameter.
  256. //
  257. ParamBuffer++;
  258. if (*ParamBuffer == '\0') {
  259. break;
  260. }
  261. switch (*ParamBuffer) {
  262. PUCHAR TempPtr;
  263. case 'r':
  264. case 'R':
  265. //
  266. // Remember the buffer offset and get the filename.
  267. //
  268. ParamBuffer++;
  269. TempPtr = ParamBuffer;
  270. DummyCount = 0;
  271. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  272. //
  273. // If the name length is 0, then ignore this entry.
  274. //
  275. if (DummyCount) {
  276. AnsiRenameString.Length = (USHORT) DummyCount;
  277. AnsiRenameString.Buffer = TempPtr;
  278. FileRenamePtr = TempPtr;
  279. RenameLength = RtlAnsiStringToUnicodeSize( &AnsiRenameString) - sizeof( WCHAR );
  280. RenameLengthPtr = &RenameLength;
  281. }
  282. break;
  283. case 'n':
  284. case 'N':
  285. //
  286. // Remember the buffer offset and get the filename.
  287. //
  288. ParamBuffer++;
  289. TempPtr = ParamBuffer;
  290. DummyCount = 0;
  291. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  292. //
  293. // If the name length is 0, then ignore this entry.
  294. //
  295. if (DummyCount) {
  296. AnsiNameString.Length = (USHORT) DummyCount;
  297. AnsiNameString.Buffer = TempPtr;
  298. FileNamePtr = TempPtr;
  299. NameLength = RtlAnsiStringToUnicodeSize( &AnsiNameString) - sizeof( WCHAR );
  300. NameLengthPtr = &NameLength;
  301. }
  302. break;
  303. case 's' :
  304. case 'S' :
  305. //
  306. // Remember the buffer offset and get the filename.
  307. //
  308. ParamBuffer++;
  309. TempPtr = ParamBuffer;
  310. DummyCount = 0;
  311. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  312. //
  313. // If the name length is 0, then ignore this entry.
  314. //
  315. if (DummyCount) {
  316. AnsiNameString.Length = (USHORT) DummyCount;
  317. AnsiNameString.Buffer = TempPtr;
  318. FileShortNamePtr = TempPtr;
  319. ShortNameLength = RtlAnsiStringToUnicodeSize( &AnsiNameString) - sizeof( WCHAR );
  320. ShortNameLengthPtr = &ShortNameLength;
  321. }
  322. break;
  323. }
  324. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  325. break;
  326. //
  327. // Update the file handle index.
  328. //
  329. case 'i' :
  330. case 'I' :
  331. //
  332. // Move to the next character, as long as there
  333. // are no white spaces continue analyzing letters.
  334. // On the first bad letter, skip to the next
  335. // parameter.
  336. //
  337. ParamBuffer++;
  338. FileIndex = (USHORT) AsciiToInteger( ParamBuffer );
  339. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  340. ParamReceived = TRUE;
  341. break;
  342. //
  343. // Update the root directory index.
  344. //
  345. case 'r' :
  346. case 'R' :
  347. //
  348. // Move to the next character, as long as there
  349. // are no white spaces continue analyzing letters.
  350. // On the first bad letter, skip to the next
  351. // parameter.
  352. //
  353. ParamBuffer++;
  354. RootDirectoryIndex = (USHORT) AsciiToInteger( ParamBuffer );
  355. RootDirectoryPtr = &RootDirectoryIndex;
  356. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  357. break;
  358. //
  359. // Update the information class.
  360. //
  361. case 'c' :
  362. case 'C' :
  363. //
  364. // Move to the next character, as long as there
  365. // are no white spaces continue analyzing letters.
  366. // On the first bad letter, skip to the next
  367. // parameter.
  368. //
  369. ParamBuffer++;
  370. SwitchBool = TRUE;
  371. while (*ParamBuffer
  372. && *ParamBuffer != ' '
  373. && *ParamBuffer != '\t') {
  374. //
  375. // Perform switch on character.
  376. //
  377. switch (*ParamBuffer) {
  378. case 'a' :
  379. case 'A' :
  380. FileInfoClass = FileBasicInformation;
  381. break;
  382. case 'b' :
  383. case 'B' :
  384. FileInfoClass = FileRenameInformation;
  385. break;
  386. case 'c' :
  387. case 'C' :
  388. FileInfoClass = FileLinkInformation;
  389. break;
  390. case 'd' :
  391. case 'D' :
  392. FileInfoClass = FileDispositionInformation;
  393. break;
  394. case 'e' :
  395. case 'E' :
  396. FileInfoClass = FilePositionInformation;
  397. break;
  398. case 'f' :
  399. case 'F' :
  400. FileInfoClass = FileModeInformation;
  401. break;
  402. case 'g' :
  403. case 'G' :
  404. FileInfoClass = FileAllocationInformation;
  405. break;
  406. case 'h' :
  407. case 'H' :
  408. FileInfoClass = FileEndOfFileInformation;
  409. break;
  410. case 'i' :
  411. case 'I' :
  412. FileInfoClass = FileShortNameInformation;
  413. break;
  414. default :
  415. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  416. SwitchBool = FALSE;
  417. }
  418. if (!SwitchBool) {
  419. break;
  420. }
  421. ParamBuffer++;
  422. }
  423. break;
  424. //
  425. // Update the file mode information
  426. //
  427. case 'm' :
  428. case 'M' :
  429. //
  430. // Move to the next character, as long as there
  431. // are no white spaces continue analyzing letters.
  432. // On the first bad letter, skip to the next
  433. // parameter.
  434. //
  435. ParamBuffer++;
  436. SwitchBool = TRUE;
  437. while (*ParamBuffer
  438. && *ParamBuffer != ' '
  439. && *ParamBuffer != '\t') {
  440. //
  441. // Perform switch on character.
  442. //
  443. switch (*ParamBuffer) {
  444. case 'a' :
  445. case 'A' :
  446. FileMode &= FILE_WRITE_THROUGH;
  447. break;
  448. case 'b' :
  449. case 'B' :
  450. FileMode &= FILE_SEQUENTIAL_ONLY;
  451. break;
  452. case 'c' :
  453. case 'C' :
  454. FileMode &= FILE_SYNCHRONOUS_IO_ALERT;
  455. break;
  456. case 'd' :
  457. case 'D' :
  458. FileMode &= FILE_SYNCHRONOUS_IO_NONALERT;
  459. break;
  460. case 'z' :
  461. case 'Z' :
  462. FileMode = 0;
  463. break;
  464. default :
  465. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  466. SwitchBool = FALSE;
  467. }
  468. if (!SwitchBool) {
  469. break;
  470. }
  471. ParamBuffer++;
  472. }
  473. break;
  474. //
  475. // Update the file attributes.
  476. //
  477. case 'a' :
  478. case 'A' :
  479. //
  480. // Move to the next character, as long as there
  481. // are no white spaces continue analyzing letters.
  482. // On the first bad letter, skip to the next
  483. // parameter.
  484. //
  485. ParamBuffer++;
  486. SwitchBool = TRUE;
  487. while (*ParamBuffer
  488. && *ParamBuffer != ' '
  489. && *ParamBuffer != '\t') {
  490. //
  491. // Perform switch on character.
  492. //
  493. switch (*ParamBuffer) {
  494. case 'a' :
  495. case 'A' :
  496. FileAttributes |= FILE_ATTRIBUTE_READONLY;
  497. FileAttributesPtr = &FileAttributes;
  498. break;
  499. case 'b' :
  500. case 'B' :
  501. FileAttributes |= FILE_ATTRIBUTE_HIDDEN;
  502. FileAttributesPtr = &FileAttributes;
  503. break;
  504. case 'c' :
  505. case 'C' :
  506. FileAttributes |= FILE_ATTRIBUTE_SYSTEM;
  507. FileAttributesPtr = &FileAttributes;
  508. break;
  509. case 'e' :
  510. case 'E' :
  511. FileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
  512. FileAttributesPtr = &FileAttributes;
  513. break;
  514. case 'f' :
  515. case 'F' :
  516. FileAttributes |= FILE_ATTRIBUTE_ARCHIVE;
  517. FileAttributesPtr = &FileAttributes;
  518. break;
  519. case 'g' :
  520. case 'G' :
  521. FileAttributes |= FILE_ATTRIBUTE_ENCRYPTED;
  522. FileAttributesPtr = &FileAttributes;
  523. break;
  524. case 'h' :
  525. case 'H' :
  526. FileAttributes |= FILE_ATTRIBUTE_NORMAL;
  527. FileAttributesPtr = &FileAttributes;
  528. break;
  529. case 'i' :
  530. case 'I' :
  531. FileAttributes |= FILE_ATTRIBUTE_TEMPORARY;
  532. FileAttributesPtr = &FileAttributes;
  533. break;
  534. case 'j' :
  535. case 'J' :
  536. FileAttributes |= FILE_ATTRIBUTE_SPARSE_FILE;
  537. FileAttributesPtr = &FileAttributes;
  538. break;
  539. case 'k' :
  540. case 'K' :
  541. FileAttributes |= FILE_ATTRIBUTE_REPARSE_POINT;
  542. FileAttributesPtr = &FileAttributes;
  543. break;
  544. case 'l' :
  545. case 'L' :
  546. FileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
  547. FileAttributesPtr = &FileAttributes;
  548. break;
  549. case 'm' :
  550. case 'M' :
  551. FileAttributes |= FILE_ATTRIBUTE_OFFLINE;
  552. FileAttributesPtr = &FileAttributes;
  553. break;
  554. case 'n' :
  555. case 'N' :
  556. FileAttributes |= FILE_ATTRIBUTE_NOT_CONTENT_INDEXED;
  557. FileAttributesPtr = &FileAttributes;
  558. break;
  559. case 'z' :
  560. case 'Z' :
  561. FileAttributes = 0;
  562. FileAttributesPtr = NULL;
  563. break;
  564. default :
  565. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  566. SwitchBool = FALSE;
  567. }
  568. if (!SwitchBool) {
  569. break;
  570. }
  571. ParamBuffer++;
  572. }
  573. break;
  574. //
  575. // Check for time or date modification.
  576. //
  577. case 't' :
  578. case 'T' :
  579. //
  580. // Check that there is another character.
  581. //
  582. ParamBuffer++;
  583. if (*ParamBuffer == '\0') {
  584. break;
  585. }
  586. switch (*ParamBuffer) {
  587. case 'c':
  588. case 'C':
  589. CreateTimeIndex = (USHORT) AsciiToInteger( ++ParamBuffer );
  590. CreateTimePtr = &CreateTimeIndex;
  591. break;
  592. case 'a':
  593. case 'A':
  594. LastAccessIndex = (USHORT) AsciiToInteger( ++ParamBuffer );
  595. LastAccessPtr = &LastAccessIndex;
  596. break;
  597. case 'w':
  598. case 'W':
  599. LastWriteIndex = (USHORT) AsciiToInteger( ++ParamBuffer );
  600. LastWritePtr = &LastWriteIndex;
  601. break;
  602. case 'g':
  603. case 'G':
  604. ChangeTimeIndex = (USHORT) AsciiToInteger( ++ParamBuffer );
  605. ChangeTimePtr = &ChangeTimeIndex;
  606. }
  607. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  608. break;
  609. case 'p' :
  610. case 'P' :
  611. //
  612. // Legal values for params are T/t or F/f.
  613. //
  614. ParamBuffer++;
  615. if (*ParamBuffer == 'T'
  616. || *ParamBuffer == 't') {
  617. ReplaceIfExists = TRUE;
  618. ParamBuffer++;
  619. } else if( *ParamBuffer == 'F'
  620. || *ParamBuffer == 'f' ) {
  621. ReplaceIfExists = FALSE;
  622. ParamBuffer++;
  623. }
  624. break;
  625. case 'd' :
  626. case 'D' :
  627. //
  628. // Legal values for params are T/t or F/f.
  629. //
  630. ParamBuffer++;
  631. if (*ParamBuffer == 'T'
  632. || *ParamBuffer == 't') {
  633. DeleteFile = TRUE;
  634. ParamBuffer++;
  635. } else if( *ParamBuffer == 'F'
  636. || *ParamBuffer == 'f' ) {
  637. DeleteFile = FALSE;
  638. ParamBuffer++;
  639. }
  640. break;
  641. //
  642. // Update the lower offset of the large integer.
  643. //
  644. case 'o' :
  645. case 'O' :
  646. //
  647. // Move to the next character, as long as there
  648. // are no white spaces continue analyzing letters.
  649. // On the first bad letter, skip to the next
  650. // parameter.
  651. //
  652. ParamBuffer++;
  653. NewOffset.LowPart = AsciiToInteger( ParamBuffer );
  654. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  655. break;
  656. //
  657. // Update the upper offset of the large integer.
  658. //
  659. case 'u' :
  660. case 'U' :
  661. //
  662. // Move to the next character, as long as there
  663. // are no white spaces continue analyzing letters.
  664. // On the first bad letter, skip to the next
  665. // parameter.
  666. //
  667. ParamBuffer++;
  668. NewOffset.HighPart = AsciiToInteger( ParamBuffer );
  669. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  670. break;
  671. case 'v' :
  672. case 'V' :
  673. //
  674. // Legal values for params are T/t or F/f.
  675. //
  676. ParamBuffer++;
  677. if( *ParamBuffer == 'T'
  678. || *ParamBuffer == 't' ) {
  679. VerboseResults = TRUE;
  680. ParamBuffer++;
  681. } else if( *ParamBuffer == 'F'
  682. || *ParamBuffer == 'f' ) {
  683. VerboseResults = FALSE;
  684. ParamBuffer++;
  685. }
  686. break;
  687. case 'y' :
  688. case 'Y' :
  689. //
  690. // Set the display parms flag and jump over this
  691. // character.
  692. //
  693. DisplayParms = TRUE;
  694. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  695. break;
  696. case 'z' :
  697. case 'Z' :
  698. //
  699. // Set flag for more input and jump over this char.
  700. //
  701. LastInput = FALSE;
  702. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  703. break;
  704. default :
  705. //
  706. // Swallow to the next white space and continue the
  707. // loop.
  708. //
  709. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  710. }
  711. }
  712. //
  713. // Else the text is invalid, skip the entire block.
  714. //
  715. //
  716. //
  717. // Else if there is no input then exit.
  718. //
  719. } else if( LastInput ) {
  720. break;
  721. //
  722. // Else try to read another line for open parameters.
  723. //
  724. } else {
  725. }
  726. }
  727. //
  728. // If no parameters were received then display the syntax message.
  729. //
  730. if (!ParamReceived) {
  731. bprint "\n" );
  732. printf( " Usage: sf [options]* -i<index> [options]*\n" );
  733. printf( " Options:\n" );
  734. printf( " -i<digits> File index\n" );
  735. printf( " -lb<digits> Buffer length\n" );
  736. printf( " -c<char> File information class\n" );
  737. printf( " -tc<digits> CreateTime buffer index\n" );
  738. printf( " -ta<digits> LastAccess buffer index\n" );
  739. printf( " -tw<digits> LastWrite buffer index\n" );
  740. printf( " -tg<digits> ChangeTime buffer index\n" );
  741. printf( " -a<chars> File attributes\n" );
  742. printf( " -p[t|f] Replace existing file on rename\n" );
  743. printf( " -r<digits> Root directory index for rename\n" );
  744. printf( " -fr<name> Name for rename\n" );
  745. printf( " -fn<name> New link name\n" );
  746. printf( " -fs<name> New short name\n" );
  747. printf( " -lr<digits> Stated length of rename\n" );
  748. printf( " -ln<digits> Stated length of new name\n" );
  749. printf( " -ls<digits> Stated length of new short name\n" );
  750. printf( " -d[t|f] Delete file\n" );
  751. printf( " -o<digits> Low word of new position\n" );
  752. printf( " -u<digits> High word of new position\n" );
  753. printf( " -m<chars> File mode information\n" );
  754. printf( " -n<digits> Quad word of new allocation size\n" );
  755. printf( " -e<digits> Quad word of new end of file\n" );
  756. printf( " -v[t|f] Verbose results\n" );
  757. printf( " -y Display parameters to query\n" );
  758. printf( " -z Additional input line\n" );
  759. printf( "\n" );
  760. //
  761. // Else call our read routine.
  762. //
  763. } else {
  764. NTSTATUS Status;
  765. SIZE_T RegionSize;
  766. ULONG TempIndex;
  767. PASYNC_SETFILE AsyncSetFile;
  768. HANDLE ThreadHandle;
  769. ULONG ThreadId;
  770. RegionSize = sizeof( ASYNC_SETFILE );
  771. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  772. AsyncIndex = (USHORT) TempIndex;
  773. if (!NT_SUCCESS( Status )) {
  774. printf("\tInputSetFile: Unable to allocate async structure\n" );
  775. } else {
  776. //
  777. // If we need a buffer for the rename, allocate it now.
  778. //
  779. if (FileRenamePtr != NULL) {
  780. UNICODE_STRING UnicodeString;
  781. RegionSize = RenameLength;
  782. if (RegionSize == 0) {
  783. RegionSize = 0x10;
  784. }
  785. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  786. if (!NT_SUCCESS( Status )) {
  787. printf( "\tInputSetFile: Unable to allocate rename structure\n" );
  788. DeallocateBuffer( AsyncIndex );
  789. return;
  790. }
  791. UnicodeString.Buffer = (PWSTR) Buffers[TempIndex].Buffer;
  792. UnicodeString.MaximumLength = (USHORT) Buffers[TempIndex].Length;
  793. RenameIndex = (USHORT) TempIndex;
  794. RenameBufferAllocated = TRUE;
  795. //
  796. // Store the name in the buffer.
  797. //
  798. RtlAnsiStringToUnicodeString( &UnicodeString,
  799. &AnsiRenameString,
  800. FALSE );
  801. }
  802. //
  803. // If we need a buffer for the new name, allocate it now.
  804. //
  805. if (FileNamePtr != NULL) {
  806. UNICODE_STRING UnicodeString;
  807. RegionSize = NameLength;
  808. if (RegionSize == 0) {
  809. RegionSize = 0x10;
  810. }
  811. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  812. if (!NT_SUCCESS( Status )) {
  813. printf( "\tInputSetFile: Unable to allocate new name structure\n" );
  814. DeallocateBuffer( AsyncIndex );
  815. if (NameBufferAllocated) {
  816. DeallocateBuffer( NameIndex );
  817. }
  818. return;
  819. }
  820. UnicodeString.Buffer = (PWSTR) Buffers[TempIndex].Buffer;
  821. UnicodeString.MaximumLength = (USHORT) Buffers[TempIndex].Length;
  822. NameIndex = (USHORT) TempIndex;
  823. NameBufferAllocated = TRUE;
  824. //
  825. // Store the name in the buffer.
  826. //
  827. RtlAnsiStringToUnicodeString( &UnicodeString,
  828. &AnsiNameString,
  829. FALSE );
  830. }
  831. //
  832. // If we need a buffer for the new short name, allocate it now.
  833. //
  834. if (FileShortNamePtr != NULL) {
  835. UNICODE_STRING UnicodeString;
  836. RegionSize = ShortNameLength;
  837. if (RegionSize == 0) {
  838. RegionSize = 0x10;
  839. }
  840. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  841. if (!NT_SUCCESS( Status )) {
  842. printf( "\tInputSetFile: Unable to allocate new short name structure\n" );
  843. DeallocateBuffer( AsyncIndex );
  844. if (ShortNameBufferAllocated) {
  845. DeallocateBuffer( ShortNameIndex );
  846. }
  847. return;
  848. }
  849. UnicodeString.Buffer = (PWSTR) Buffers[TempIndex].Buffer;
  850. UnicodeString.MaximumLength = (USHORT) Buffers[TempIndex].Length;
  851. ShortNameIndex = (USHORT) TempIndex;
  852. ShortNameBufferAllocated = TRUE;
  853. //
  854. // Store the name in the buffer.
  855. //
  856. RtlAnsiStringToUnicodeString( &UnicodeString,
  857. &AnsiNameString,
  858. FALSE );
  859. }
  860. AsyncSetFile = (PASYNC_SETFILE) Buffers[AsyncIndex].Buffer;
  861. AsyncSetFile->FileIndex = (USHORT) FileIndex;
  862. AsyncSetFile->BufferLength = BufferLength;
  863. AsyncSetFile->BufferLengthPtr = BufferLengthPtr
  864. ? &AsyncSetFile->BufferLength
  865. : NULL;
  866. AsyncSetFile->FileInfoClass = FileInfoClass;
  867. AsyncSetFile->CreateTimeIndex = CreateTimeIndex;
  868. AsyncSetFile->CreateTimePtr = CreateTimePtr
  869. ? &AsyncSetFile->CreateTimeIndex
  870. : NULL;
  871. AsyncSetFile->LastAccessIndex = LastAccessIndex;
  872. AsyncSetFile->LastAccessPtr = LastAccessPtr
  873. ? &AsyncSetFile->LastAccessIndex
  874. : NULL;
  875. AsyncSetFile->LastWriteIndex = LastWriteIndex;
  876. AsyncSetFile->LastWritePtr = LastWritePtr
  877. ? &AsyncSetFile->LastWriteIndex
  878. : NULL;
  879. AsyncSetFile->ChangeTimeIndex = ChangeTimeIndex;
  880. AsyncSetFile->ChangeTimePtr = ChangeTimePtr
  881. ? &AsyncSetFile->ChangeTimeIndex
  882. : NULL;
  883. AsyncSetFile->FileAttributes = FileAttributes;
  884. AsyncSetFile->FileAttributesPtr = FileAttributesPtr
  885. ? &AsyncSetFile->FileAttributes
  886. : NULL;
  887. AsyncSetFile->RenameLength = RenameLength;
  888. AsyncSetFile->RenameLengthPtr = RenameLengthPtr
  889. ? &AsyncSetFile->RenameLength
  890. : NULL;
  891. AsyncSetFile->ReplaceIfExists = ReplaceIfExists;
  892. AsyncSetFile->RootDirectoryIndex = RootDirectoryIndex;
  893. AsyncSetFile->RootDirectoryPtr = RootDirectoryPtr
  894. ? &AsyncSetFile->RootDirectoryIndex
  895. : NULL;
  896. AsyncSetFile->RenameIndex = RenameIndex;
  897. AsyncSetFile->RenameBufferAllocated = RenameBufferAllocated;
  898. AsyncSetFile->NameLength = NameLength;
  899. AsyncSetFile->NameLengthPtr = NameLengthPtr
  900. ? &AsyncSetFile->NameLength
  901. : NULL;
  902. AsyncSetFile->NameIndex = NameIndex;
  903. AsyncSetFile->NameBufferAllocated = NameBufferAllocated;
  904. AsyncSetFile->ShortNameLength = ShortNameLength;
  905. AsyncSetFile->ShortNameLengthPtr = ShortNameLengthPtr
  906. ? &AsyncSetFile->ShortNameLength
  907. : NULL;
  908. AsyncSetFile->ShortNameIndex = ShortNameIndex;
  909. AsyncSetFile->ShortNameBufferAllocated = ShortNameBufferAllocated;
  910. AsyncSetFile->DeleteFile = DeleteFile;
  911. AsyncSetFile->NewOffset = NewOffset;
  912. AsyncSetFile->FileMode = FileMode;
  913. AsyncSetFile->NewAllocation = NewAllocation;
  914. AsyncSetFile->NewEof = NewEof;
  915. AsyncSetFile->DisplayParms = DisplayParms;
  916. AsyncSetFile->VerboseResults = VerboseResults;
  917. AsyncSetFile->AsyncIndex = AsyncIndex;
  918. if (!SynchronousCmds) {
  919. ThreadHandle = CreateThread( NULL,
  920. 0,
  921. FullSetFile,
  922. AsyncSetFile,
  923. 0,
  924. &ThreadId );
  925. if (ThreadHandle == 0) {
  926. printf( "InputSetFile: Spawning thread fails -> %d\n", GetLastError() );
  927. if (RenameBufferAllocated) {
  928. DeallocateBuffer( RenameIndex );
  929. }
  930. if (NameBufferAllocated) {
  931. DeallocateBuffer( NameIndex );
  932. }
  933. DeallocateBuffer( AsyncIndex );
  934. return;
  935. }
  936. } else {
  937. FullSetFile( AsyncSetFile );
  938. }
  939. }
  940. }
  941. return;
  942. }
  943. VOID
  944. FullSetFile(
  945. IN OUT PASYNC_SETFILE AsyncSetFile
  946. )
  947. {
  948. try {
  949. //
  950. // Case on the information type and call the appropriate routine.
  951. //
  952. switch (AsyncSetFile->FileInfoClass) {
  953. case FileBasicInformation:
  954. SetBasicInformation( AsyncSetFile );
  955. break;
  956. case FileRenameInformation:
  957. SetRenameInformation( AsyncSetFile );
  958. break;
  959. case FileLinkInformation:
  960. SetNameInformation( AsyncSetFile );
  961. break;
  962. case FileShortNameInformation:
  963. SetShortNameInformation( AsyncSetFile );
  964. break;
  965. case FileDispositionInformation:
  966. SetDispositionInformation( AsyncSetFile );
  967. break;
  968. case FilePositionInformation:
  969. SetPositionInformation( AsyncSetFile );
  970. break;
  971. case FileModeInformation:
  972. SetModeInformation( AsyncSetFile );
  973. break;
  974. case FileAllocationInformation :
  975. SetAllocationInformation( AsyncSetFile );
  976. break;
  977. case FileEndOfFileInformation :
  978. SetEofInformation( AsyncSetFile );
  979. break;
  980. default:
  981. bprint "FullSetInfo: Unrecognized information class\n" );
  982. }
  983. try_return( NOTHING );
  984. try_exit: NOTHING;
  985. } finally {
  986. if (AsyncSetFile->RenameBufferAllocated) {
  987. DeallocateBuffer( AsyncSetFile->RenameIndex );
  988. }
  989. if (AsyncSetFile->NameBufferAllocated) {
  990. DeallocateBuffer( AsyncSetFile->NameIndex );
  991. }
  992. DeallocateBuffer( AsyncSetFile->AsyncIndex );
  993. }
  994. NtTerminateThread( 0, STATUS_SUCCESS );
  995. }
  996. VOID
  997. SetBasicInformation(
  998. IN OUT PASYNC_SETFILE AsyncSetFile
  999. )
  1000. {
  1001. NTSTATUS Status;
  1002. PFILE_BASIC_INFORMATION BasicInformation;
  1003. USHORT BufferIndex;
  1004. BOOLEAN UnwindBufferIndex = FALSE;
  1005. //
  1006. // Check the parameters for legality. Void the pointers if the values
  1007. // are illegal.
  1008. //
  1009. if (AsyncSetFile->CreateTimePtr != NULL
  1010. && (AsyncSetFile->CreateTimeIndex >= MAX_BUFFERS
  1011. || !Buffers[AsyncSetFile->CreateTimeIndex].Used)) {
  1012. bprint "CreateTimeIndex %04d is invalid\n" );
  1013. AsyncSetFile->CreateTimePtr = NULL;
  1014. }
  1015. if (AsyncSetFile->LastAccessPtr != NULL
  1016. && (AsyncSetFile->LastAccessIndex >= MAX_BUFFERS
  1017. || !Buffers[AsyncSetFile->LastAccessIndex].Used)) {
  1018. bprint "LastAccessIndex %04d is invalid\n" );
  1019. AsyncSetFile->LastAccessPtr = NULL;
  1020. }
  1021. if (AsyncSetFile->LastWritePtr != NULL
  1022. && (AsyncSetFile->LastWriteIndex >= MAX_BUFFERS
  1023. || !Buffers[AsyncSetFile->LastWriteIndex].Used)) {
  1024. bprint "LastWriteIndex %04d is invalid\n" );
  1025. AsyncSetFile->LastWritePtr = NULL;
  1026. }
  1027. if (AsyncSetFile->ChangeTimePtr != NULL
  1028. && (AsyncSetFile->ChangeTimeIndex >= MAX_BUFFERS
  1029. || !Buffers[AsyncSetFile->ChangeTimeIndex].Used)) {
  1030. bprint "ChangeTimeIndex %04d is invalid\n" );
  1031. AsyncSetFile->ChangeTimePtr = NULL;
  1032. }
  1033. if (AsyncSetFile->DisplayParms) {
  1034. bprint "\n" );
  1035. bprint "Set FileBasicInformation Parameters\n" );
  1036. bprint " File Handle Index -> %d\n", AsyncSetFile->FileIndex );
  1037. bprint " BufferLengthPtr -> %08lx\n", AsyncSetFile->BufferLengthPtr );
  1038. if (AsyncSetFile->BufferLengthPtr) {
  1039. bprint " BufferLength value -> %08x\n", AsyncSetFile->BufferLength );
  1040. }
  1041. bprint " CreateTimePtr -> %08lx\n", AsyncSetFile->CreateTimePtr );
  1042. if (AsyncSetFile->CreateTimePtr) {
  1043. bprint " CreateTime -> \n" );
  1044. BPrintTime( (PTIME) Buffers[AsyncSetFile->CreateTimeIndex].Buffer );
  1045. }
  1046. bprint " LastAccessPtr -> %08lx\n", AsyncSetFile->LastAccessPtr );
  1047. if (AsyncSetFile->LastAccessPtr) {
  1048. bprint " LastAccess -> \n" );
  1049. BPrintTime( (PTIME) Buffers[AsyncSetFile->LastAccessIndex].Buffer );
  1050. }
  1051. bprint " LastWritePtr -> %08lx\n", AsyncSetFile->LastWritePtr );
  1052. if (AsyncSetFile->LastWritePtr) {
  1053. bprint " LastWrite -> \n" );
  1054. BPrintTime( (PTIME) Buffers[AsyncSetFile->LastWriteIndex].Buffer );
  1055. }
  1056. bprint " ChangeTimePtr -> %08lx\n", AsyncSetFile->ChangeTimePtr );
  1057. if (AsyncSetFile->ChangeTimePtr) {
  1058. bprint " ChangeTime -> \n" );
  1059. BPrintTime( (PTIME) Buffers[AsyncSetFile->ChangeTimeIndex].Buffer );
  1060. }
  1061. bprint " FileAttributesPtr -> %08lx\n", AsyncSetFile->FileAttributesPtr );
  1062. if (AsyncSetFile->FileAttributesPtr) {
  1063. bprint " FileAttributes value -> %08x\n", AsyncSetFile->FileAttributes );
  1064. }
  1065. bprint "\n" );
  1066. }
  1067. try {
  1068. SIZE_T RegionSize;
  1069. ULONG TempIndex;
  1070. IO_STATUS_BLOCK Iosb;
  1071. RegionSize = sizeof( FILE_BASIC_INFORMATION );
  1072. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  1073. BufferIndex = (USHORT) TempIndex;
  1074. if (!NT_SUCCESS( Status )) {
  1075. bprint "\tSetBasicInformation: Unable to allocate structure\n" );
  1076. try_return( NOTHING );
  1077. }
  1078. UnwindBufferIndex = TRUE;
  1079. BasicInformation = (PFILE_BASIC_INFORMATION) Buffers[BufferIndex].Buffer;
  1080. //
  1081. // Fill in the new information.
  1082. //
  1083. if (AsyncSetFile->CreateTimePtr) {
  1084. BasicInformation->CreationTime = *((PTIME) Buffers[AsyncSetFile->CreateTimeIndex].Buffer);
  1085. } else {
  1086. BasicInformation->CreationTime.LowPart = 0;
  1087. BasicInformation->CreationTime.HighPart = 0;
  1088. }
  1089. if (AsyncSetFile->LastAccessPtr) {
  1090. BasicInformation->LastAccessTime = *((PTIME) Buffers[AsyncSetFile->LastAccessIndex].Buffer);
  1091. } else {
  1092. BasicInformation->LastAccessTime.LowPart = 0;
  1093. BasicInformation->LastAccessTime.HighPart = 0;
  1094. }
  1095. if (AsyncSetFile->LastWritePtr) {
  1096. BasicInformation->LastWriteTime = *((PTIME) Buffers[AsyncSetFile->LastWriteIndex].Buffer);
  1097. } else {
  1098. BasicInformation->LastWriteTime.LowPart = 0;
  1099. BasicInformation->LastWriteTime.HighPart = 0;
  1100. }
  1101. if (AsyncSetFile->ChangeTimePtr) {
  1102. BasicInformation->ChangeTime = *((PTIME) Buffers[AsyncSetFile->ChangeTimeIndex].Buffer);
  1103. } else {
  1104. BasicInformation->ChangeTime.LowPart = 0;
  1105. BasicInformation->ChangeTime.HighPart = 0;
  1106. }
  1107. if (AsyncSetFile->FileAttributesPtr) {
  1108. BasicInformation->FileAttributes = AsyncSetFile->FileAttributes;
  1109. } else {
  1110. BasicInformation->FileAttributes = 0;
  1111. }
  1112. Iosb.Status = STATUS_SUCCESS;
  1113. Iosb.Information = 0;
  1114. Status = NtSetInformationFile( Handles[AsyncSetFile->FileIndex].Handle,
  1115. &Iosb,
  1116. BasicInformation,
  1117. AsyncSetFile->BufferLengthPtr
  1118. ? AsyncSetFile->BufferLength
  1119. : Buffers[BufferIndex].Length,
  1120. FileBasicInformation );
  1121. if (AsyncSetFile->VerboseResults) {
  1122. bprint "\n" );
  1123. bprint " SetBasicInformation: Status -> %08lx\n", Status );
  1124. if (NT_SUCCESS( Status )) {
  1125. bprint " Io.Status -> %08lx\n", Iosb.Status );
  1126. bprint " Io.Information -> %08lx\n", Iosb.Information );
  1127. }
  1128. bprint "\n" );
  1129. }
  1130. try_exit: NOTHING;
  1131. } finally {
  1132. if (UnwindBufferIndex) {
  1133. DeallocateBuffer( BufferIndex );
  1134. }
  1135. }
  1136. return;
  1137. }
  1138. VOID
  1139. SetRenameInformation(
  1140. IN OUT PASYNC_SETFILE AsyncSetFile
  1141. )
  1142. {
  1143. NTSTATUS Status;
  1144. PFILE_RENAME_INFORMATION RenameInformation;
  1145. USHORT BufferIndex;
  1146. UNICODE_STRING UniRenameName;
  1147. ANSI_STRING AnsiRenameName;
  1148. BOOLEAN UnwindBufferIndex = FALSE;
  1149. BOOLEAN UnwindFreeAnsiString = FALSE;
  1150. //
  1151. // Check that there is a rename specified.
  1152. //
  1153. if (!AsyncSetFile->RenameBufferAllocated) {
  1154. bprint "Set Rename Information: No rename was specified\n" );
  1155. return;
  1156. }
  1157. UniRenameName.Buffer = (PWSTR) Buffers[AsyncSetFile->RenameIndex].Buffer;
  1158. UniRenameName.MaximumLength =
  1159. UniRenameName.Length = (USHORT) AsyncSetFile->RenameLength;
  1160. UniRenameName.MaximumLength += 2;
  1161. Status = RtlUnicodeStringToAnsiString( &AnsiRenameName,
  1162. &UniRenameName,
  1163. TRUE );
  1164. if (!NT_SUCCESS( Status )) {
  1165. bprint "SetFileRenameInfo: Can't allocate ansi buffer -> %08lx\n", Status );
  1166. AsyncSetFile->DisplayParms = FALSE;
  1167. } else {
  1168. UnwindFreeAnsiString = TRUE;
  1169. }
  1170. if (AsyncSetFile->DisplayParms) {
  1171. bprint "\n" );
  1172. bprint "Set FileRenameInformation Parameters\n" );
  1173. bprint " File Handle Index -> %d\n", AsyncSetFile->FileIndex );
  1174. bprint " BufferLengthPtr -> %08lx\n", AsyncSetFile->BufferLengthPtr );
  1175. if (AsyncSetFile->BufferLengthPtr) {
  1176. bprint " BufferLength value -> %08x\n", AsyncSetFile->BufferLength );
  1177. }
  1178. bprint " Replace existing file -> %d\n", AsyncSetFile->ReplaceIfExists );
  1179. bprint " Root directory pointer -> %d\n", AsyncSetFile->RootDirectoryPtr );
  1180. if (AsyncSetFile->RootDirectoryPtr) {
  1181. bprint " Root directory index -> %d\n", AsyncSetFile->RootDirectoryIndex );
  1182. }
  1183. bprint " Rename length -> %d\n", AsyncSetFile->RenameLength );
  1184. bprint " New file name -> %s\n", AnsiRenameName.Buffer );
  1185. bprint "\n" );
  1186. }
  1187. try {
  1188. SIZE_T RegionSize;
  1189. ULONG TempIndex;
  1190. IO_STATUS_BLOCK Iosb;
  1191. RegionSize = sizeof( FILE_RENAME_INFORMATION ) + AsyncSetFile->RenameLength;
  1192. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  1193. BufferIndex = (USHORT) TempIndex;
  1194. if (!NT_SUCCESS( Status )) {
  1195. bprint "\tSetRenameInformation: Unable to allocate structure\n" );
  1196. try_return( NOTHING );
  1197. }
  1198. UnwindBufferIndex = TRUE;
  1199. RenameInformation = (PFILE_RENAME_INFORMATION) Buffers[BufferIndex].Buffer;
  1200. //
  1201. // Fill in the new information.
  1202. //
  1203. RenameInformation->ReplaceIfExists = AsyncSetFile->ReplaceIfExists;
  1204. RenameInformation->RootDirectory = AsyncSetFile->RootDirectoryPtr
  1205. ? Handles[AsyncSetFile->RootDirectoryIndex].Handle
  1206. : 0;
  1207. RenameInformation->FileNameLength = AsyncSetFile->RenameLength;
  1208. RtlMoveMemory( RenameInformation->FileName,
  1209. UniRenameName.Buffer,
  1210. AsyncSetFile->RenameLength );
  1211. Iosb.Status = STATUS_SUCCESS;
  1212. Iosb.Information = 0;
  1213. Status = NtSetInformationFile( Handles[AsyncSetFile->FileIndex].Handle,
  1214. &Iosb,
  1215. RenameInformation,
  1216. AsyncSetFile->BufferLengthPtr
  1217. ? AsyncSetFile->BufferLength
  1218. : Buffers[BufferIndex].Length,
  1219. FileRenameInformation );
  1220. if (AsyncSetFile->VerboseResults) {
  1221. bprint "\n" );
  1222. bprint " SetRenameInformation: Status -> %08lx\n", Status );
  1223. if (NT_SUCCESS( Status )) {
  1224. bprint " Io.Status -> %08lx\n", Iosb.Status );
  1225. bprint " Io.Information -> %08lx\n", Iosb.Information );
  1226. }
  1227. bprint "\n" );
  1228. }
  1229. try_exit: NOTHING;
  1230. } finally {
  1231. if (UnwindFreeAnsiString) {
  1232. RtlFreeAnsiString( &AnsiRenameName );
  1233. }
  1234. if (UnwindBufferIndex) {
  1235. DeallocateBuffer( BufferIndex );
  1236. }
  1237. }
  1238. return;
  1239. }
  1240. VOID
  1241. SetNameInformation(
  1242. IN OUT PASYNC_SETFILE AsyncSetFile
  1243. )
  1244. {
  1245. NTSTATUS Status;
  1246. PFILE_RENAME_INFORMATION NameInformation;
  1247. USHORT BufferIndex;
  1248. UNICODE_STRING UnicodeName;
  1249. ANSI_STRING AnsiName;
  1250. BOOLEAN UnwindBufferIndex = FALSE;
  1251. BOOLEAN UnwindFreeAnsiString = FALSE;
  1252. //
  1253. // Check that there is a Name specified.
  1254. //
  1255. if (!AsyncSetFile->NameBufferAllocated) {
  1256. bprint "Set Name Information: No Name was specified\n" );
  1257. return;
  1258. }
  1259. UnicodeName.Buffer = (PWSTR) Buffers[AsyncSetFile->NameIndex].Buffer;
  1260. UnicodeName.MaximumLength =
  1261. UnicodeName.Length = (USHORT) AsyncSetFile->NameLength;
  1262. UnicodeName.MaximumLength += 2;
  1263. Status = RtlUnicodeStringToAnsiString( &AnsiName,
  1264. &UnicodeName,
  1265. TRUE );
  1266. if (!NT_SUCCESS( Status )) {
  1267. bprint "SetFileNameInfo: Can't allocate ansi buffer -> %08lx\n", Status );
  1268. AsyncSetFile->DisplayParms = FALSE;
  1269. } else {
  1270. UnwindFreeAnsiString = TRUE;
  1271. }
  1272. if (AsyncSetFile->DisplayParms) {
  1273. bprint "\n" );
  1274. bprint "Set FileNameInformation Parameters\n" );
  1275. bprint " File Handle Index -> %d\n", AsyncSetFile->FileIndex );
  1276. bprint " BufferLengthPtr -> %08lx\n", AsyncSetFile->BufferLengthPtr );
  1277. if (AsyncSetFile->BufferLengthPtr) {
  1278. bprint " BufferLength value -> %08x\n", AsyncSetFile->BufferLength );
  1279. }
  1280. bprint " Replace existing file -> %d\n", AsyncSetFile->ReplaceIfExists );
  1281. bprint " Root directory pointer -> %d\n", AsyncSetFile->RootDirectoryPtr );
  1282. if (AsyncSetFile->RootDirectoryPtr) {
  1283. bprint " Root directory index -> %d\n", AsyncSetFile->RootDirectoryIndex );
  1284. }
  1285. bprint " Name length -> %d\n", AsyncSetFile->NameLength );
  1286. bprint " New file name -> %s\n", AnsiName.Buffer );
  1287. bprint "\n" );
  1288. }
  1289. try {
  1290. SIZE_T RegionSize;
  1291. ULONG TempIndex;
  1292. IO_STATUS_BLOCK Iosb;
  1293. RegionSize = sizeof( FILE_RENAME_INFORMATION ) + AsyncSetFile->NameLength;
  1294. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  1295. BufferIndex = (USHORT) TempIndex;
  1296. if (!NT_SUCCESS( Status )) {
  1297. bprint "\tSetNameInformation: Unable to allocate structure\n" );
  1298. try_return( NOTHING );
  1299. }
  1300. UnwindBufferIndex = TRUE;
  1301. NameInformation = (PFILE_RENAME_INFORMATION) Buffers[BufferIndex].Buffer;
  1302. //
  1303. // Fill in the new information.
  1304. //
  1305. NameInformation->ReplaceIfExists = AsyncSetFile->ReplaceIfExists;
  1306. NameInformation->RootDirectory = AsyncSetFile->RootDirectoryPtr
  1307. ? Handles[AsyncSetFile->RootDirectoryIndex].Handle
  1308. : 0;
  1309. NameInformation->FileNameLength = AsyncSetFile->NameLength;
  1310. RtlMoveMemory( NameInformation->FileName,
  1311. UnicodeName.Buffer,
  1312. AsyncSetFile->NameLength );
  1313. Iosb.Status = STATUS_SUCCESS;
  1314. Iosb.Information = 0;
  1315. Status = NtSetInformationFile( Handles[AsyncSetFile->FileIndex].Handle,
  1316. &Iosb,
  1317. NameInformation,
  1318. AsyncSetFile->BufferLengthPtr
  1319. ? AsyncSetFile->BufferLength
  1320. : Buffers[BufferIndex].Length,
  1321. FileLinkInformation );
  1322. if (AsyncSetFile->VerboseResults) {
  1323. bprint "\n" );
  1324. bprint " SetNameInformation: Status -> %08lx\n", Status );
  1325. if (NT_SUCCESS( Status )) {
  1326. bprint " Io.Status -> %08lx\n", Iosb.Status );
  1327. bprint " Io.Information -> %08lx\n", Iosb.Information );
  1328. }
  1329. bprint "\n" );
  1330. }
  1331. try_exit: NOTHING;
  1332. } finally {
  1333. if (UnwindFreeAnsiString) {
  1334. RtlFreeAnsiString( &AnsiName );
  1335. }
  1336. if (UnwindBufferIndex) {
  1337. DeallocateBuffer( BufferIndex );
  1338. }
  1339. }
  1340. return;
  1341. }
  1342. VOID
  1343. SetShortNameInformation(
  1344. IN OUT PASYNC_SETFILE AsyncSetFile
  1345. )
  1346. {
  1347. NTSTATUS Status;
  1348. PFILE_NAME_INFORMATION NameInformation;
  1349. USHORT BufferIndex;
  1350. UNICODE_STRING UnicodeName;
  1351. ANSI_STRING AnsiName;
  1352. BOOLEAN UnwindBufferIndex = FALSE;
  1353. BOOLEAN UnwindFreeAnsiString = FALSE;
  1354. //
  1355. // Check that there is a Name specified.
  1356. //
  1357. if (!AsyncSetFile->ShortNameBufferAllocated) {
  1358. bprint "Set Short Name Information: No Name was specified\n" );
  1359. return;
  1360. }
  1361. UnicodeName.Buffer = (PWSTR) Buffers[AsyncSetFile->ShortNameIndex].Buffer;
  1362. UnicodeName.MaximumLength =
  1363. UnicodeName.Length = (USHORT) AsyncSetFile->ShortNameLength;
  1364. UnicodeName.MaximumLength += 2;
  1365. Status = RtlUnicodeStringToAnsiString( &AnsiName,
  1366. &UnicodeName,
  1367. TRUE );
  1368. if (!NT_SUCCESS( Status )) {
  1369. bprint "SetShortNameInfo: Can't allocate ansi buffer -> %08lx\n", Status );
  1370. AsyncSetFile->DisplayParms = FALSE;
  1371. } else {
  1372. UnwindFreeAnsiString = TRUE;
  1373. }
  1374. if (AsyncSetFile->DisplayParms) {
  1375. bprint "\n" );
  1376. bprint "Set FileShortNameInformation Parameters\n" );
  1377. bprint " File Handle Index -> %d\n", AsyncSetFile->FileIndex );
  1378. bprint " BufferLengthPtr -> %08lx\n", AsyncSetFile->BufferLengthPtr );
  1379. if (AsyncSetFile->BufferLengthPtr) {
  1380. bprint " BufferLength value -> %08x\n", AsyncSetFile->BufferLength );
  1381. }
  1382. bprint " Name length -> %d\n", AsyncSetFile->ShortNameLength );
  1383. bprint " New short name -> %s\n", AnsiName.Buffer );
  1384. bprint "\n" );
  1385. }
  1386. try {
  1387. SIZE_T RegionSize;
  1388. ULONG TempIndex;
  1389. IO_STATUS_BLOCK Iosb;
  1390. RegionSize = sizeof( FILE_NAME_INFORMATION ) + AsyncSetFile->ShortNameLength;
  1391. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  1392. BufferIndex = (USHORT) TempIndex;
  1393. if (!NT_SUCCESS( Status )) {
  1394. bprint "\tSetShortNameInformation: Unable to allocate structure\n" );
  1395. try_return( NOTHING );
  1396. }
  1397. UnwindBufferIndex = TRUE;
  1398. NameInformation = (PFILE_NAME_INFORMATION) Buffers[BufferIndex].Buffer;
  1399. //
  1400. // Fill in the new information.
  1401. //
  1402. NameInformation->FileNameLength = AsyncSetFile->ShortNameLength;
  1403. RtlMoveMemory( NameInformation->FileName,
  1404. UnicodeName.Buffer,
  1405. AsyncSetFile->ShortNameLength );
  1406. Iosb.Status = STATUS_SUCCESS;
  1407. Iosb.Information = 0;
  1408. Status = NtSetInformationFile( Handles[AsyncSetFile->FileIndex].Handle,
  1409. &Iosb,
  1410. NameInformation,
  1411. AsyncSetFile->BufferLengthPtr
  1412. ? AsyncSetFile->BufferLength
  1413. : Buffers[BufferIndex].Length,
  1414. FileShortNameInformation );
  1415. if (AsyncSetFile->VerboseResults) {
  1416. bprint "\n" );
  1417. bprint " SetShortNameInformation: Status -> %08lx\n", Status );
  1418. if (NT_SUCCESS( Status )) {
  1419. bprint " Io.Status -> %08lx\n", Iosb.Status );
  1420. bprint " Io.Information -> %08lx\n", Iosb.Information );
  1421. }
  1422. bprint "\n" );
  1423. }
  1424. try_exit: NOTHING;
  1425. } finally {
  1426. if (UnwindFreeAnsiString) {
  1427. RtlFreeAnsiString( &AnsiName );
  1428. }
  1429. if (UnwindBufferIndex) {
  1430. DeallocateBuffer( BufferIndex );
  1431. }
  1432. }
  1433. return;
  1434. }
  1435. VOID
  1436. SetDispositionInformation(
  1437. IN OUT PASYNC_SETFILE AsyncSetFile
  1438. )
  1439. {
  1440. NTSTATUS Status;
  1441. PFILE_DISPOSITION_INFORMATION DispositionInformation;
  1442. USHORT BufferIndex;
  1443. BOOLEAN UnwindBufferIndex = FALSE;
  1444. if (AsyncSetFile->DisplayParms) {
  1445. bprint "\n" );
  1446. bprint "Set FileDispositionInformation Parameters\n" );
  1447. bprint " File Handle Index -> %d\n", AsyncSetFile->FileIndex );
  1448. bprint " BufferLengthPtr -> %08lx\n", AsyncSetFile->BufferLengthPtr );
  1449. if (AsyncSetFile->BufferLengthPtr) {
  1450. bprint " BufferLength value -> %08x\n", AsyncSetFile->BufferLength );
  1451. }
  1452. bprint " Delete file -> %d\n", AsyncSetFile->DeleteFile );
  1453. bprint "\n" );
  1454. }
  1455. try {
  1456. SIZE_T RegionSize;
  1457. ULONG TempIndex;
  1458. IO_STATUS_BLOCK Iosb;
  1459. RegionSize = sizeof( FILE_DISPOSITION_INFORMATION );
  1460. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  1461. BufferIndex = (USHORT) TempIndex;
  1462. if (!NT_SUCCESS( Status )) {
  1463. bprint "\tSetDispositionInformation: Unable to allocate structure\n" );
  1464. try_return( NOTHING );
  1465. }
  1466. UnwindBufferIndex = TRUE;
  1467. DispositionInformation = (PFILE_DISPOSITION_INFORMATION) Buffers[BufferIndex].Buffer;
  1468. //
  1469. // Fill in the new information.
  1470. //
  1471. DispositionInformation->DeleteFile = AsyncSetFile->DeleteFile;
  1472. Iosb.Status = STATUS_SUCCESS;
  1473. Iosb.Information = 0;
  1474. Status = NtSetInformationFile( Handles[AsyncSetFile->FileIndex].Handle,
  1475. &Iosb,
  1476. DispositionInformation,
  1477. AsyncSetFile->BufferLengthPtr
  1478. ? AsyncSetFile->BufferLength
  1479. : Buffers[BufferIndex].Length,
  1480. FileDispositionInformation );
  1481. if (AsyncSetFile->VerboseResults) {
  1482. bprint "\n" );
  1483. bprint " SetDispositionInformation: Status -> %08lx\n", Status );
  1484. if (NT_SUCCESS( Status )) {
  1485. bprint " Io.Status -> %08lx\n", Iosb.Status );
  1486. bprint " Io.Information -> %08lx\n", Iosb.Information );
  1487. }
  1488. bprint "\n" );
  1489. }
  1490. try_exit: NOTHING;
  1491. } finally {
  1492. if (UnwindBufferIndex) {
  1493. DeallocateBuffer( BufferIndex );
  1494. }
  1495. }
  1496. return;
  1497. }
  1498. VOID
  1499. SetPositionInformation(
  1500. IN OUT PASYNC_SETFILE AsyncSetFile
  1501. )
  1502. {
  1503. NTSTATUS Status;
  1504. PFILE_POSITION_INFORMATION PositionInformation;
  1505. USHORT BufferIndex;
  1506. BOOLEAN UnwindBufferIndex = FALSE;
  1507. if (AsyncSetFile->DisplayParms) {
  1508. bprint "\n" );
  1509. bprint "Set FilePositionInformation Parameters\n" );
  1510. bprint " File Handle Index -> %d\n", AsyncSetFile->FileIndex );
  1511. bprint " BufferLengthPtr -> %08lx\n", AsyncSetFile->BufferLengthPtr );
  1512. if (AsyncSetFile->BufferLengthPtr) {
  1513. bprint " BufferLength value -> %08x\n", AsyncSetFile->BufferLength );
  1514. }
  1515. bprint " New Offset High -> %08lx\n", AsyncSetFile->NewOffset.HighPart );
  1516. bprint " New Offset Low -> %08lx\n", AsyncSetFile->NewOffset.LowPart );
  1517. bprint "\n" );
  1518. }
  1519. try {
  1520. SIZE_T RegionSize;
  1521. ULONG TempIndex;
  1522. IO_STATUS_BLOCK Iosb;
  1523. RegionSize = sizeof( FILE_POSITION_INFORMATION );
  1524. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  1525. BufferIndex = (USHORT) TempIndex;
  1526. if (!NT_SUCCESS( Status )) {
  1527. bprint "\tSetPositionInformation: Unable to allocate structure\n" );
  1528. try_return( NOTHING );
  1529. }
  1530. UnwindBufferIndex = TRUE;
  1531. PositionInformation = (PFILE_POSITION_INFORMATION) Buffers[BufferIndex].Buffer;
  1532. //
  1533. // Fill in the new information.
  1534. //
  1535. PositionInformation->CurrentByteOffset = AsyncSetFile->NewOffset;
  1536. Iosb.Status = STATUS_SUCCESS;
  1537. Iosb.Information = 0;
  1538. Status = NtSetInformationFile( Handles[AsyncSetFile->FileIndex].Handle,
  1539. &Iosb,
  1540. PositionInformation,
  1541. AsyncSetFile->BufferLengthPtr
  1542. ? AsyncSetFile->BufferLength
  1543. : Buffers[BufferIndex].Length,
  1544. FilePositionInformation );
  1545. if (AsyncSetFile->VerboseResults) {
  1546. bprint "\n" );
  1547. bprint " SetInformationFile: Status -> %08lx\n", Status );
  1548. if (NT_SUCCESS( Status )) {
  1549. bprint " Io.Status -> %08lx\n", Iosb.Status );
  1550. bprint " Io.Information -> %08lx\n", Iosb.Information );
  1551. }
  1552. bprint "\n" );
  1553. }
  1554. try_exit: NOTHING;
  1555. } finally {
  1556. if (UnwindBufferIndex) {
  1557. DeallocateBuffer( BufferIndex );
  1558. }
  1559. }
  1560. return;
  1561. }
  1562. VOID
  1563. SetModeInformation(
  1564. IN OUT PASYNC_SETFILE AsyncSetFile
  1565. )
  1566. {
  1567. NTSTATUS Status;
  1568. PFILE_MODE_INFORMATION ModeInformation;
  1569. USHORT BufferIndex;
  1570. BOOLEAN UnwindBufferIndex = FALSE;
  1571. if (AsyncSetFile->DisplayParms) {
  1572. bprint "\n" );
  1573. bprint "Set FileModeInformation Parameters\n" );
  1574. bprint " File Handle Index -> %d\n", AsyncSetFile->FileIndex );
  1575. bprint " BufferLengthPtr -> %08lx\n", AsyncSetFile->BufferLengthPtr );
  1576. if (AsyncSetFile->BufferLengthPtr) {
  1577. bprint " BufferLength value -> %08x\n", AsyncSetFile->BufferLength );
  1578. }
  1579. bprint " File Mode -> %08lx\n", AsyncSetFile->FileMode );
  1580. bprint "\n" );
  1581. }
  1582. try {
  1583. SIZE_T RegionSize;
  1584. ULONG TempIndex;
  1585. IO_STATUS_BLOCK Iosb;
  1586. RegionSize = sizeof( FILE_MODE_INFORMATION );
  1587. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  1588. BufferIndex = (USHORT) TempIndex;
  1589. if (!NT_SUCCESS( Status )) {
  1590. bprint "\tSetModeInformation: Unable to allocate structure\n" );
  1591. try_return( NOTHING );
  1592. }
  1593. UnwindBufferIndex = TRUE;
  1594. ModeInformation = (PFILE_MODE_INFORMATION) Buffers[BufferIndex].Buffer;
  1595. //
  1596. // Fill in the new information.
  1597. //
  1598. ModeInformation->Mode = AsyncSetFile->FileMode;
  1599. Iosb.Status = STATUS_SUCCESS;
  1600. Iosb.Information = 0;
  1601. Status = NtSetInformationFile( Handles[AsyncSetFile->FileIndex].Handle,
  1602. &Iosb,
  1603. ModeInformation,
  1604. AsyncSetFile->BufferLengthPtr
  1605. ? AsyncSetFile->BufferLength
  1606. : Buffers[BufferIndex].Length,
  1607. FileModeInformation );
  1608. if (AsyncSetFile->VerboseResults) {
  1609. bprint "\n" );
  1610. bprint " SetModelInformation: Status -> %08lx\n", Status );
  1611. if (NT_SUCCESS( Status )) {
  1612. bprint " Io.Status -> %08lx\n", Iosb.Status );
  1613. bprint " Io.Information -> %08lx\n", Iosb.Information );
  1614. }
  1615. bprint "\n" );
  1616. }
  1617. try_exit: NOTHING;
  1618. } finally {
  1619. if (UnwindBufferIndex) {
  1620. DeallocateBuffer( BufferIndex );
  1621. }
  1622. }
  1623. return;
  1624. }
  1625. VOID
  1626. SetAllocationInformation(
  1627. IN OUT PASYNC_SETFILE AsyncSetFile
  1628. )
  1629. {
  1630. NTSTATUS Status;
  1631. PFILE_ALLOCATION_INFORMATION AllocationInformation;
  1632. USHORT BufferIndex;
  1633. BOOLEAN UnwindBufferIndex = FALSE;
  1634. if (AsyncSetFile->DisplayParms) {
  1635. bprint "\n" );
  1636. bprint "Set FileAllocationInformation Parameters\n" );
  1637. bprint " File Handle Index -> %d\n", AsyncSetFile->FileIndex );
  1638. bprint " BufferLengthPtr -> %08lx\n", AsyncSetFile->BufferLengthPtr );
  1639. if (AsyncSetFile->BufferLengthPtr) {
  1640. bprint " BufferLength value -> %08x\n", AsyncSetFile->BufferLength );
  1641. }
  1642. bprint " New Allocation High -> %08lx\n", AsyncSetFile->NewAllocation.HighPart );
  1643. bprint " New Allocation Low -> %08lx\n", AsyncSetFile->NewAllocation.LowPart );
  1644. bprint "\n" );
  1645. }
  1646. try {
  1647. SIZE_T RegionSize;
  1648. ULONG TempIndex;
  1649. IO_STATUS_BLOCK Iosb;
  1650. RegionSize = sizeof( FILE_ALLOCATION_INFORMATION );
  1651. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  1652. BufferIndex = (USHORT) TempIndex;
  1653. if (!NT_SUCCESS( Status )) {
  1654. bprint "\tSetAllocationInformation: Unable to allocate structure\n" );
  1655. try_return( NOTHING );
  1656. }
  1657. UnwindBufferIndex = TRUE;
  1658. AllocationInformation = (PFILE_ALLOCATION_INFORMATION) Buffers[BufferIndex].Buffer;
  1659. //
  1660. // Fill in the new information.
  1661. //
  1662. AllocationInformation->AllocationSize = AsyncSetFile->NewAllocation;
  1663. Iosb.Status = STATUS_SUCCESS;
  1664. Iosb.Information = 0;
  1665. Status = NtSetInformationFile( Handles[AsyncSetFile->FileIndex].Handle,
  1666. &Iosb,
  1667. AllocationInformation,
  1668. AsyncSetFile->BufferLengthPtr
  1669. ? AsyncSetFile->BufferLength
  1670. : Buffers[BufferIndex].Length,
  1671. FileAllocationInformation );
  1672. if (AsyncSetFile->VerboseResults) {
  1673. bprint "\n" );
  1674. bprint " SetAllocationInformation: Status -> %08lx\n", Status );
  1675. if (NT_SUCCESS( Status )) {
  1676. bprint " Io.Status -> %08lx\n", Iosb.Status );
  1677. bprint " Io.Information -> %08lx\n", Iosb.Information );
  1678. }
  1679. bprint "\n" );
  1680. }
  1681. try_exit: NOTHING;
  1682. } finally {
  1683. if (UnwindBufferIndex) {
  1684. DeallocateBuffer( BufferIndex );
  1685. }
  1686. }
  1687. return;
  1688. }
  1689. VOID
  1690. SetEofInformation(
  1691. IN OUT PASYNC_SETFILE AsyncSetFile
  1692. )
  1693. {
  1694. NTSTATUS Status;
  1695. PFILE_END_OF_FILE_INFORMATION EofInformation;
  1696. USHORT BufferIndex;
  1697. BOOLEAN UnwindBufferIndex = FALSE;
  1698. if (AsyncSetFile->DisplayParms) {
  1699. bprint "\n" );
  1700. bprint "Set FileEofInformation Parameters\n" );
  1701. bprint " File Handle Index -> %d\n", AsyncSetFile->FileIndex );
  1702. bprint " BufferLengthPtr -> %08lx\n", AsyncSetFile->BufferLengthPtr );
  1703. if (AsyncSetFile->BufferLengthPtr) {
  1704. bprint " BufferLength value -> %08x\n", AsyncSetFile->BufferLength );
  1705. }
  1706. bprint " New Eof High -> %08lx\n", AsyncSetFile->NewEof.HighPart );
  1707. bprint " New Eof Low -> %08lx\n", AsyncSetFile->NewEof.LowPart );
  1708. bprint "\n" );
  1709. }
  1710. try {
  1711. SIZE_T RegionSize;
  1712. ULONG TempIndex;
  1713. IO_STATUS_BLOCK Iosb;
  1714. RegionSize = sizeof( FILE_END_OF_FILE_INFORMATION );
  1715. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  1716. BufferIndex = (USHORT) TempIndex;
  1717. if (!NT_SUCCESS( Status )) {
  1718. bprint "\tSetEofInformation: Unable to allocate structure\n" );
  1719. try_return( NOTHING );
  1720. }
  1721. UnwindBufferIndex = TRUE;
  1722. EofInformation = (PFILE_END_OF_FILE_INFORMATION) Buffers[BufferIndex].Buffer;
  1723. //
  1724. // Fill in the new information.
  1725. //
  1726. EofInformation->EndOfFile = AsyncSetFile->NewEof;
  1727. Iosb.Status = STATUS_SUCCESS;
  1728. Iosb.Information = 0;
  1729. Status = NtSetInformationFile( Handles[AsyncSetFile->FileIndex].Handle,
  1730. &Iosb,
  1731. EofInformation,
  1732. AsyncSetFile->BufferLengthPtr
  1733. ? AsyncSetFile->BufferLength
  1734. : Buffers[BufferIndex].Length,
  1735. FileEndOfFileInformation );
  1736. if (AsyncSetFile->VerboseResults) {
  1737. bprint "\n" );
  1738. bprint " SetEOFInformation: Status -> %08lx\n", Status );
  1739. if (NT_SUCCESS( Status )) {
  1740. bprint " Io.Status -> %08lx\n", Iosb.Status );
  1741. bprint " Io.Information -> %08lx\n", Iosb.Information );
  1742. }
  1743. bprint "\n" );
  1744. }
  1745. try_exit: NOTHING;
  1746. } finally {
  1747. if (UnwindBufferIndex) {
  1748. DeallocateBuffer( BufferIndex );
  1749. }
  1750. }
  1751. return;
  1752. }