Leaked source code of windows server 2003
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.

2509 lines
74 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. if (!SynchronousCmds) {
  995. NtTerminateThread( 0, STATUS_SUCCESS );
  996. }
  997. }
  998. VOID
  999. SetBasicInformation(
  1000. IN OUT PASYNC_SETFILE AsyncSetFile
  1001. )
  1002. {
  1003. NTSTATUS Status;
  1004. PFILE_BASIC_INFORMATION BasicInformation;
  1005. USHORT BufferIndex;
  1006. BOOLEAN UnwindBufferIndex = FALSE;
  1007. //
  1008. // Check the parameters for legality. Void the pointers if the values
  1009. // are illegal.
  1010. //
  1011. if (AsyncSetFile->CreateTimePtr != NULL
  1012. && (AsyncSetFile->CreateTimeIndex >= MAX_BUFFERS
  1013. || !Buffers[AsyncSetFile->CreateTimeIndex].Used)) {
  1014. bprint "CreateTimeIndex %04d is invalid\n" );
  1015. AsyncSetFile->CreateTimePtr = NULL;
  1016. }
  1017. if (AsyncSetFile->LastAccessPtr != NULL
  1018. && (AsyncSetFile->LastAccessIndex >= MAX_BUFFERS
  1019. || !Buffers[AsyncSetFile->LastAccessIndex].Used)) {
  1020. bprint "LastAccessIndex %04d is invalid\n" );
  1021. AsyncSetFile->LastAccessPtr = NULL;
  1022. }
  1023. if (AsyncSetFile->LastWritePtr != NULL
  1024. && (AsyncSetFile->LastWriteIndex >= MAX_BUFFERS
  1025. || !Buffers[AsyncSetFile->LastWriteIndex].Used)) {
  1026. bprint "LastWriteIndex %04d is invalid\n" );
  1027. AsyncSetFile->LastWritePtr = NULL;
  1028. }
  1029. if (AsyncSetFile->ChangeTimePtr != NULL
  1030. && (AsyncSetFile->ChangeTimeIndex >= MAX_BUFFERS
  1031. || !Buffers[AsyncSetFile->ChangeTimeIndex].Used)) {
  1032. bprint "ChangeTimeIndex %04d is invalid\n" );
  1033. AsyncSetFile->ChangeTimePtr = NULL;
  1034. }
  1035. if (AsyncSetFile->DisplayParms) {
  1036. bprint "\n" );
  1037. bprint "Set FileBasicInformation Parameters\n" );
  1038. bprint " File Handle Index -> %d\n", AsyncSetFile->FileIndex );
  1039. bprint " BufferLengthPtr -> %08lx\n", AsyncSetFile->BufferLengthPtr );
  1040. if (AsyncSetFile->BufferLengthPtr) {
  1041. bprint " BufferLength value -> %08x\n", AsyncSetFile->BufferLength );
  1042. }
  1043. bprint " CreateTimePtr -> %08lx\n", AsyncSetFile->CreateTimePtr );
  1044. if (AsyncSetFile->CreateTimePtr) {
  1045. bprint " CreateTime -> \n" );
  1046. BPrintTime( (PTIME) Buffers[AsyncSetFile->CreateTimeIndex].Buffer );
  1047. }
  1048. bprint " LastAccessPtr -> %08lx\n", AsyncSetFile->LastAccessPtr );
  1049. if (AsyncSetFile->LastAccessPtr) {
  1050. bprint " LastAccess -> \n" );
  1051. BPrintTime( (PTIME) Buffers[AsyncSetFile->LastAccessIndex].Buffer );
  1052. }
  1053. bprint " LastWritePtr -> %08lx\n", AsyncSetFile->LastWritePtr );
  1054. if (AsyncSetFile->LastWritePtr) {
  1055. bprint " LastWrite -> \n" );
  1056. BPrintTime( (PTIME) Buffers[AsyncSetFile->LastWriteIndex].Buffer );
  1057. }
  1058. bprint " ChangeTimePtr -> %08lx\n", AsyncSetFile->ChangeTimePtr );
  1059. if (AsyncSetFile->ChangeTimePtr) {
  1060. bprint " ChangeTime -> \n" );
  1061. BPrintTime( (PTIME) Buffers[AsyncSetFile->ChangeTimeIndex].Buffer );
  1062. }
  1063. bprint " FileAttributesPtr -> %08lx\n", AsyncSetFile->FileAttributesPtr );
  1064. if (AsyncSetFile->FileAttributesPtr) {
  1065. bprint " FileAttributes value -> %08x\n", AsyncSetFile->FileAttributes );
  1066. }
  1067. bprint "\n" );
  1068. }
  1069. try {
  1070. SIZE_T RegionSize;
  1071. ULONG TempIndex;
  1072. IO_STATUS_BLOCK Iosb;
  1073. RegionSize = sizeof( FILE_BASIC_INFORMATION );
  1074. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  1075. BufferIndex = (USHORT) TempIndex;
  1076. if (!NT_SUCCESS( Status )) {
  1077. bprint "\tSetBasicInformation: Unable to allocate structure\n" );
  1078. try_return( NOTHING );
  1079. }
  1080. UnwindBufferIndex = TRUE;
  1081. BasicInformation = (PFILE_BASIC_INFORMATION) Buffers[BufferIndex].Buffer;
  1082. //
  1083. // Fill in the new information.
  1084. //
  1085. if (AsyncSetFile->CreateTimePtr) {
  1086. BasicInformation->CreationTime = *((PTIME) Buffers[AsyncSetFile->CreateTimeIndex].Buffer);
  1087. } else {
  1088. BasicInformation->CreationTime.LowPart = 0;
  1089. BasicInformation->CreationTime.HighPart = 0;
  1090. }
  1091. if (AsyncSetFile->LastAccessPtr) {
  1092. BasicInformation->LastAccessTime = *((PTIME) Buffers[AsyncSetFile->LastAccessIndex].Buffer);
  1093. } else {
  1094. BasicInformation->LastAccessTime.LowPart = 0;
  1095. BasicInformation->LastAccessTime.HighPart = 0;
  1096. }
  1097. if (AsyncSetFile->LastWritePtr) {
  1098. BasicInformation->LastWriteTime = *((PTIME) Buffers[AsyncSetFile->LastWriteIndex].Buffer);
  1099. } else {
  1100. BasicInformation->LastWriteTime.LowPart = 0;
  1101. BasicInformation->LastWriteTime.HighPart = 0;
  1102. }
  1103. if (AsyncSetFile->ChangeTimePtr) {
  1104. BasicInformation->ChangeTime = *((PTIME) Buffers[AsyncSetFile->ChangeTimeIndex].Buffer);
  1105. } else {
  1106. BasicInformation->ChangeTime.LowPart = 0;
  1107. BasicInformation->ChangeTime.HighPart = 0;
  1108. }
  1109. if (AsyncSetFile->FileAttributesPtr) {
  1110. BasicInformation->FileAttributes = AsyncSetFile->FileAttributes;
  1111. } else {
  1112. BasicInformation->FileAttributes = 0;
  1113. }
  1114. Iosb.Status = STATUS_SUCCESS;
  1115. Iosb.Information = 0;
  1116. Status = NtSetInformationFile( Handles[AsyncSetFile->FileIndex].Handle,
  1117. &Iosb,
  1118. BasicInformation,
  1119. AsyncSetFile->BufferLengthPtr
  1120. ? AsyncSetFile->BufferLength
  1121. : Buffers[BufferIndex].Length,
  1122. FileBasicInformation );
  1123. if (AsyncSetFile->VerboseResults) {
  1124. bprint "\n" );
  1125. bprint " SetBasicInformation: Status -> %08lx\n", Status );
  1126. if (NT_SUCCESS( Status )) {
  1127. bprint " Io.Status -> %08lx\n", Iosb.Status );
  1128. bprint " Io.Information -> %08lx\n", Iosb.Information );
  1129. }
  1130. bprint "\n" );
  1131. }
  1132. try_exit: NOTHING;
  1133. } finally {
  1134. if (UnwindBufferIndex) {
  1135. DeallocateBuffer( BufferIndex );
  1136. }
  1137. }
  1138. return;
  1139. }
  1140. VOID
  1141. SetRenameInformation(
  1142. IN OUT PASYNC_SETFILE AsyncSetFile
  1143. )
  1144. {
  1145. NTSTATUS Status;
  1146. PFILE_RENAME_INFORMATION RenameInformation;
  1147. USHORT BufferIndex;
  1148. UNICODE_STRING UniRenameName;
  1149. ANSI_STRING AnsiRenameName;
  1150. BOOLEAN UnwindBufferIndex = FALSE;
  1151. BOOLEAN UnwindFreeAnsiString = FALSE;
  1152. //
  1153. // Check that there is a rename specified.
  1154. //
  1155. if (!AsyncSetFile->RenameBufferAllocated) {
  1156. bprint "Set Rename Information: No rename was specified\n" );
  1157. return;
  1158. }
  1159. UniRenameName.Buffer = (PWSTR) Buffers[AsyncSetFile->RenameIndex].Buffer;
  1160. UniRenameName.MaximumLength =
  1161. UniRenameName.Length = (USHORT) AsyncSetFile->RenameLength;
  1162. UniRenameName.MaximumLength += 2;
  1163. Status = RtlUnicodeStringToAnsiString( &AnsiRenameName,
  1164. &UniRenameName,
  1165. TRUE );
  1166. if (!NT_SUCCESS( Status )) {
  1167. bprint "SetFileRenameInfo: Can't allocate ansi buffer -> %08lx\n", Status );
  1168. AsyncSetFile->DisplayParms = FALSE;
  1169. } else {
  1170. UnwindFreeAnsiString = TRUE;
  1171. }
  1172. if (AsyncSetFile->DisplayParms) {
  1173. bprint "\n" );
  1174. bprint "Set FileRenameInformation Parameters\n" );
  1175. bprint " File Handle Index -> %d\n", AsyncSetFile->FileIndex );
  1176. bprint " BufferLengthPtr -> %08lx\n", AsyncSetFile->BufferLengthPtr );
  1177. if (AsyncSetFile->BufferLengthPtr) {
  1178. bprint " BufferLength value -> %08x\n", AsyncSetFile->BufferLength );
  1179. }
  1180. bprint " Replace existing file -> %d\n", AsyncSetFile->ReplaceIfExists );
  1181. bprint " Root directory pointer -> %d\n", AsyncSetFile->RootDirectoryPtr );
  1182. if (AsyncSetFile->RootDirectoryPtr) {
  1183. bprint " Root directory index -> %d\n", AsyncSetFile->RootDirectoryIndex );
  1184. }
  1185. bprint " Rename length -> %d\n", AsyncSetFile->RenameLength );
  1186. bprint " New file name -> %s\n", AnsiRenameName.Buffer );
  1187. bprint "\n" );
  1188. }
  1189. try {
  1190. SIZE_T RegionSize;
  1191. ULONG TempIndex;
  1192. IO_STATUS_BLOCK Iosb;
  1193. RegionSize = sizeof( FILE_RENAME_INFORMATION ) + AsyncSetFile->RenameLength;
  1194. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  1195. BufferIndex = (USHORT) TempIndex;
  1196. if (!NT_SUCCESS( Status )) {
  1197. bprint "\tSetRenameInformation: Unable to allocate structure\n" );
  1198. try_return( NOTHING );
  1199. }
  1200. UnwindBufferIndex = TRUE;
  1201. RenameInformation = (PFILE_RENAME_INFORMATION) Buffers[BufferIndex].Buffer;
  1202. //
  1203. // Fill in the new information.
  1204. //
  1205. RenameInformation->ReplaceIfExists = AsyncSetFile->ReplaceIfExists;
  1206. RenameInformation->RootDirectory = AsyncSetFile->RootDirectoryPtr
  1207. ? Handles[AsyncSetFile->RootDirectoryIndex].Handle
  1208. : 0;
  1209. RenameInformation->FileNameLength = AsyncSetFile->RenameLength;
  1210. RtlMoveMemory( RenameInformation->FileName,
  1211. UniRenameName.Buffer,
  1212. AsyncSetFile->RenameLength );
  1213. Iosb.Status = STATUS_SUCCESS;
  1214. Iosb.Information = 0;
  1215. Status = NtSetInformationFile( Handles[AsyncSetFile->FileIndex].Handle,
  1216. &Iosb,
  1217. RenameInformation,
  1218. AsyncSetFile->BufferLengthPtr
  1219. ? AsyncSetFile->BufferLength
  1220. : Buffers[BufferIndex].Length,
  1221. FileRenameInformation );
  1222. if (AsyncSetFile->VerboseResults) {
  1223. bprint "\n" );
  1224. bprint " SetRenameInformation: Status -> %08lx\n", Status );
  1225. if (NT_SUCCESS( Status )) {
  1226. bprint " Io.Status -> %08lx\n", Iosb.Status );
  1227. bprint " Io.Information -> %08lx\n", Iosb.Information );
  1228. }
  1229. bprint "\n" );
  1230. }
  1231. try_exit: NOTHING;
  1232. } finally {
  1233. if (UnwindFreeAnsiString) {
  1234. RtlFreeAnsiString( &AnsiRenameName );
  1235. }
  1236. if (UnwindBufferIndex) {
  1237. DeallocateBuffer( BufferIndex );
  1238. }
  1239. }
  1240. return;
  1241. }
  1242. VOID
  1243. SetNameInformation(
  1244. IN OUT PASYNC_SETFILE AsyncSetFile
  1245. )
  1246. {
  1247. NTSTATUS Status;
  1248. PFILE_RENAME_INFORMATION NameInformation;
  1249. USHORT BufferIndex;
  1250. UNICODE_STRING UnicodeName;
  1251. ANSI_STRING AnsiName;
  1252. BOOLEAN UnwindBufferIndex = FALSE;
  1253. BOOLEAN UnwindFreeAnsiString = FALSE;
  1254. //
  1255. // Check that there is a Name specified.
  1256. //
  1257. if (!AsyncSetFile->NameBufferAllocated) {
  1258. bprint "Set Name Information: No Name was specified\n" );
  1259. return;
  1260. }
  1261. UnicodeName.Buffer = (PWSTR) Buffers[AsyncSetFile->NameIndex].Buffer;
  1262. UnicodeName.MaximumLength =
  1263. UnicodeName.Length = (USHORT) AsyncSetFile->NameLength;
  1264. UnicodeName.MaximumLength += 2;
  1265. Status = RtlUnicodeStringToAnsiString( &AnsiName,
  1266. &UnicodeName,
  1267. TRUE );
  1268. if (!NT_SUCCESS( Status )) {
  1269. bprint "SetFileNameInfo: Can't allocate ansi buffer -> %08lx\n", Status );
  1270. AsyncSetFile->DisplayParms = FALSE;
  1271. } else {
  1272. UnwindFreeAnsiString = TRUE;
  1273. }
  1274. if (AsyncSetFile->DisplayParms) {
  1275. bprint "\n" );
  1276. bprint "Set FileNameInformation Parameters\n" );
  1277. bprint " File Handle Index -> %d\n", AsyncSetFile->FileIndex );
  1278. bprint " BufferLengthPtr -> %08lx\n", AsyncSetFile->BufferLengthPtr );
  1279. if (AsyncSetFile->BufferLengthPtr) {
  1280. bprint " BufferLength value -> %08x\n", AsyncSetFile->BufferLength );
  1281. }
  1282. bprint " Replace existing file -> %d\n", AsyncSetFile->ReplaceIfExists );
  1283. bprint " Root directory pointer -> %d\n", AsyncSetFile->RootDirectoryPtr );
  1284. if (AsyncSetFile->RootDirectoryPtr) {
  1285. bprint " Root directory index -> %d\n", AsyncSetFile->RootDirectoryIndex );
  1286. }
  1287. bprint " Name length -> %d\n", AsyncSetFile->NameLength );
  1288. bprint " New file name -> %s\n", AnsiName.Buffer );
  1289. bprint "\n" );
  1290. }
  1291. try {
  1292. SIZE_T RegionSize;
  1293. ULONG TempIndex;
  1294. IO_STATUS_BLOCK Iosb;
  1295. RegionSize = sizeof( FILE_RENAME_INFORMATION ) + AsyncSetFile->NameLength;
  1296. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  1297. BufferIndex = (USHORT) TempIndex;
  1298. if (!NT_SUCCESS( Status )) {
  1299. bprint "\tSetNameInformation: Unable to allocate structure\n" );
  1300. try_return( NOTHING );
  1301. }
  1302. UnwindBufferIndex = TRUE;
  1303. NameInformation = (PFILE_RENAME_INFORMATION) Buffers[BufferIndex].Buffer;
  1304. //
  1305. // Fill in the new information.
  1306. //
  1307. NameInformation->ReplaceIfExists = AsyncSetFile->ReplaceIfExists;
  1308. NameInformation->RootDirectory = AsyncSetFile->RootDirectoryPtr
  1309. ? Handles[AsyncSetFile->RootDirectoryIndex].Handle
  1310. : 0;
  1311. NameInformation->FileNameLength = AsyncSetFile->NameLength;
  1312. RtlMoveMemory( NameInformation->FileName,
  1313. UnicodeName.Buffer,
  1314. AsyncSetFile->NameLength );
  1315. Iosb.Status = STATUS_SUCCESS;
  1316. Iosb.Information = 0;
  1317. Status = NtSetInformationFile( Handles[AsyncSetFile->FileIndex].Handle,
  1318. &Iosb,
  1319. NameInformation,
  1320. AsyncSetFile->BufferLengthPtr
  1321. ? AsyncSetFile->BufferLength
  1322. : Buffers[BufferIndex].Length,
  1323. FileLinkInformation );
  1324. if (AsyncSetFile->VerboseResults) {
  1325. bprint "\n" );
  1326. bprint " SetNameInformation: Status -> %08lx\n", Status );
  1327. if (NT_SUCCESS( Status )) {
  1328. bprint " Io.Status -> %08lx\n", Iosb.Status );
  1329. bprint " Io.Information -> %08lx\n", Iosb.Information );
  1330. }
  1331. bprint "\n" );
  1332. }
  1333. try_exit: NOTHING;
  1334. } finally {
  1335. if (UnwindFreeAnsiString) {
  1336. RtlFreeAnsiString( &AnsiName );
  1337. }
  1338. if (UnwindBufferIndex) {
  1339. DeallocateBuffer( BufferIndex );
  1340. }
  1341. }
  1342. return;
  1343. }
  1344. VOID
  1345. SetShortNameInformation(
  1346. IN OUT PASYNC_SETFILE AsyncSetFile
  1347. )
  1348. {
  1349. NTSTATUS Status;
  1350. PFILE_NAME_INFORMATION NameInformation;
  1351. USHORT BufferIndex;
  1352. UNICODE_STRING UnicodeName;
  1353. ANSI_STRING AnsiName;
  1354. BOOLEAN UnwindBufferIndex = FALSE;
  1355. BOOLEAN UnwindFreeAnsiString = FALSE;
  1356. //
  1357. // Check that there is a Name specified.
  1358. //
  1359. if (!AsyncSetFile->ShortNameBufferAllocated) {
  1360. bprint "Set Short Name Information: No Name was specified\n" );
  1361. return;
  1362. }
  1363. UnicodeName.Buffer = (PWSTR) Buffers[AsyncSetFile->ShortNameIndex].Buffer;
  1364. UnicodeName.MaximumLength =
  1365. UnicodeName.Length = (USHORT) AsyncSetFile->ShortNameLength;
  1366. UnicodeName.MaximumLength += 2;
  1367. Status = RtlUnicodeStringToAnsiString( &AnsiName,
  1368. &UnicodeName,
  1369. TRUE );
  1370. if (!NT_SUCCESS( Status )) {
  1371. bprint "SetShortNameInfo: Can't allocate ansi buffer -> %08lx\n", Status );
  1372. AsyncSetFile->DisplayParms = FALSE;
  1373. } else {
  1374. UnwindFreeAnsiString = TRUE;
  1375. }
  1376. if (AsyncSetFile->DisplayParms) {
  1377. bprint "\n" );
  1378. bprint "Set FileShortNameInformation Parameters\n" );
  1379. bprint " File Handle Index -> %d\n", AsyncSetFile->FileIndex );
  1380. bprint " BufferLengthPtr -> %08lx\n", AsyncSetFile->BufferLengthPtr );
  1381. if (AsyncSetFile->BufferLengthPtr) {
  1382. bprint " BufferLength value -> %08x\n", AsyncSetFile->BufferLength );
  1383. }
  1384. bprint " Name length -> %d\n", AsyncSetFile->ShortNameLength );
  1385. bprint " New short name -> %s\n", AnsiName.Buffer );
  1386. bprint "\n" );
  1387. }
  1388. try {
  1389. SIZE_T RegionSize;
  1390. ULONG TempIndex;
  1391. IO_STATUS_BLOCK Iosb;
  1392. RegionSize = sizeof( FILE_NAME_INFORMATION ) + AsyncSetFile->ShortNameLength;
  1393. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  1394. BufferIndex = (USHORT) TempIndex;
  1395. if (!NT_SUCCESS( Status )) {
  1396. bprint "\tSetShortNameInformation: Unable to allocate structure\n" );
  1397. try_return( NOTHING );
  1398. }
  1399. UnwindBufferIndex = TRUE;
  1400. NameInformation = (PFILE_NAME_INFORMATION) Buffers[BufferIndex].Buffer;
  1401. //
  1402. // Fill in the new information.
  1403. //
  1404. NameInformation->FileNameLength = AsyncSetFile->ShortNameLength;
  1405. RtlMoveMemory( NameInformation->FileName,
  1406. UnicodeName.Buffer,
  1407. AsyncSetFile->ShortNameLength );
  1408. Iosb.Status = STATUS_SUCCESS;
  1409. Iosb.Information = 0;
  1410. Status = NtSetInformationFile( Handles[AsyncSetFile->FileIndex].Handle,
  1411. &Iosb,
  1412. NameInformation,
  1413. AsyncSetFile->BufferLengthPtr
  1414. ? AsyncSetFile->BufferLength
  1415. : Buffers[BufferIndex].Length,
  1416. FileShortNameInformation );
  1417. if (AsyncSetFile->VerboseResults) {
  1418. bprint "\n" );
  1419. bprint " SetShortNameInformation: Status -> %08lx\n", Status );
  1420. if (NT_SUCCESS( Status )) {
  1421. bprint " Io.Status -> %08lx\n", Iosb.Status );
  1422. bprint " Io.Information -> %08lx\n", Iosb.Information );
  1423. }
  1424. bprint "\n" );
  1425. }
  1426. try_exit: NOTHING;
  1427. } finally {
  1428. if (UnwindFreeAnsiString) {
  1429. RtlFreeAnsiString( &AnsiName );
  1430. }
  1431. if (UnwindBufferIndex) {
  1432. DeallocateBuffer( BufferIndex );
  1433. }
  1434. }
  1435. return;
  1436. }
  1437. VOID
  1438. SetDispositionInformation(
  1439. IN OUT PASYNC_SETFILE AsyncSetFile
  1440. )
  1441. {
  1442. NTSTATUS Status;
  1443. PFILE_DISPOSITION_INFORMATION DispositionInformation;
  1444. USHORT BufferIndex;
  1445. BOOLEAN UnwindBufferIndex = FALSE;
  1446. if (AsyncSetFile->DisplayParms) {
  1447. bprint "\n" );
  1448. bprint "Set FileDispositionInformation Parameters\n" );
  1449. bprint " File Handle Index -> %d\n", AsyncSetFile->FileIndex );
  1450. bprint " BufferLengthPtr -> %08lx\n", AsyncSetFile->BufferLengthPtr );
  1451. if (AsyncSetFile->BufferLengthPtr) {
  1452. bprint " BufferLength value -> %08x\n", AsyncSetFile->BufferLength );
  1453. }
  1454. bprint " Delete file -> %d\n", AsyncSetFile->DeleteFile );
  1455. bprint "\n" );
  1456. }
  1457. try {
  1458. SIZE_T RegionSize;
  1459. ULONG TempIndex;
  1460. IO_STATUS_BLOCK Iosb;
  1461. RegionSize = sizeof( FILE_DISPOSITION_INFORMATION );
  1462. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  1463. BufferIndex = (USHORT) TempIndex;
  1464. if (!NT_SUCCESS( Status )) {
  1465. bprint "\tSetDispositionInformation: Unable to allocate structure\n" );
  1466. try_return( NOTHING );
  1467. }
  1468. UnwindBufferIndex = TRUE;
  1469. DispositionInformation = (PFILE_DISPOSITION_INFORMATION) Buffers[BufferIndex].Buffer;
  1470. //
  1471. // Fill in the new information.
  1472. //
  1473. DispositionInformation->DeleteFile = AsyncSetFile->DeleteFile;
  1474. Iosb.Status = STATUS_SUCCESS;
  1475. Iosb.Information = 0;
  1476. Status = NtSetInformationFile( Handles[AsyncSetFile->FileIndex].Handle,
  1477. &Iosb,
  1478. DispositionInformation,
  1479. AsyncSetFile->BufferLengthPtr
  1480. ? AsyncSetFile->BufferLength
  1481. : Buffers[BufferIndex].Length,
  1482. FileDispositionInformation );
  1483. if (AsyncSetFile->VerboseResults) {
  1484. bprint "\n" );
  1485. bprint " SetDispositionInformation: Status -> %08lx\n", Status );
  1486. if (NT_SUCCESS( Status )) {
  1487. bprint " Io.Status -> %08lx\n", Iosb.Status );
  1488. bprint " Io.Information -> %08lx\n", Iosb.Information );
  1489. }
  1490. bprint "\n" );
  1491. }
  1492. try_exit: NOTHING;
  1493. } finally {
  1494. if (UnwindBufferIndex) {
  1495. DeallocateBuffer( BufferIndex );
  1496. }
  1497. }
  1498. return;
  1499. }
  1500. VOID
  1501. SetPositionInformation(
  1502. IN OUT PASYNC_SETFILE AsyncSetFile
  1503. )
  1504. {
  1505. NTSTATUS Status;
  1506. PFILE_POSITION_INFORMATION PositionInformation;
  1507. USHORT BufferIndex;
  1508. BOOLEAN UnwindBufferIndex = FALSE;
  1509. if (AsyncSetFile->DisplayParms) {
  1510. bprint "\n" );
  1511. bprint "Set FilePositionInformation Parameters\n" );
  1512. bprint " File Handle Index -> %d\n", AsyncSetFile->FileIndex );
  1513. bprint " BufferLengthPtr -> %08lx\n", AsyncSetFile->BufferLengthPtr );
  1514. if (AsyncSetFile->BufferLengthPtr) {
  1515. bprint " BufferLength value -> %08x\n", AsyncSetFile->BufferLength );
  1516. }
  1517. bprint " New Offset High -> %08lx\n", AsyncSetFile->NewOffset.HighPart );
  1518. bprint " New Offset Low -> %08lx\n", AsyncSetFile->NewOffset.LowPart );
  1519. bprint "\n" );
  1520. }
  1521. try {
  1522. SIZE_T RegionSize;
  1523. ULONG TempIndex;
  1524. IO_STATUS_BLOCK Iosb;
  1525. RegionSize = sizeof( FILE_POSITION_INFORMATION );
  1526. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  1527. BufferIndex = (USHORT) TempIndex;
  1528. if (!NT_SUCCESS( Status )) {
  1529. bprint "\tSetPositionInformation: Unable to allocate structure\n" );
  1530. try_return( NOTHING );
  1531. }
  1532. UnwindBufferIndex = TRUE;
  1533. PositionInformation = (PFILE_POSITION_INFORMATION) Buffers[BufferIndex].Buffer;
  1534. //
  1535. // Fill in the new information.
  1536. //
  1537. PositionInformation->CurrentByteOffset = AsyncSetFile->NewOffset;
  1538. Iosb.Status = STATUS_SUCCESS;
  1539. Iosb.Information = 0;
  1540. Status = NtSetInformationFile( Handles[AsyncSetFile->FileIndex].Handle,
  1541. &Iosb,
  1542. PositionInformation,
  1543. AsyncSetFile->BufferLengthPtr
  1544. ? AsyncSetFile->BufferLength
  1545. : Buffers[BufferIndex].Length,
  1546. FilePositionInformation );
  1547. if (AsyncSetFile->VerboseResults) {
  1548. bprint "\n" );
  1549. bprint " SetInformationFile: Status -> %08lx\n", Status );
  1550. if (NT_SUCCESS( Status )) {
  1551. bprint " Io.Status -> %08lx\n", Iosb.Status );
  1552. bprint " Io.Information -> %08lx\n", Iosb.Information );
  1553. }
  1554. bprint "\n" );
  1555. }
  1556. try_exit: NOTHING;
  1557. } finally {
  1558. if (UnwindBufferIndex) {
  1559. DeallocateBuffer( BufferIndex );
  1560. }
  1561. }
  1562. return;
  1563. }
  1564. VOID
  1565. SetModeInformation(
  1566. IN OUT PASYNC_SETFILE AsyncSetFile
  1567. )
  1568. {
  1569. NTSTATUS Status;
  1570. PFILE_MODE_INFORMATION ModeInformation;
  1571. USHORT BufferIndex;
  1572. BOOLEAN UnwindBufferIndex = FALSE;
  1573. if (AsyncSetFile->DisplayParms) {
  1574. bprint "\n" );
  1575. bprint "Set FileModeInformation Parameters\n" );
  1576. bprint " File Handle Index -> %d\n", AsyncSetFile->FileIndex );
  1577. bprint " BufferLengthPtr -> %08lx\n", AsyncSetFile->BufferLengthPtr );
  1578. if (AsyncSetFile->BufferLengthPtr) {
  1579. bprint " BufferLength value -> %08x\n", AsyncSetFile->BufferLength );
  1580. }
  1581. bprint " File Mode -> %08lx\n", AsyncSetFile->FileMode );
  1582. bprint "\n" );
  1583. }
  1584. try {
  1585. SIZE_T RegionSize;
  1586. ULONG TempIndex;
  1587. IO_STATUS_BLOCK Iosb;
  1588. RegionSize = sizeof( FILE_MODE_INFORMATION );
  1589. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  1590. BufferIndex = (USHORT) TempIndex;
  1591. if (!NT_SUCCESS( Status )) {
  1592. bprint "\tSetModeInformation: Unable to allocate structure\n" );
  1593. try_return( NOTHING );
  1594. }
  1595. UnwindBufferIndex = TRUE;
  1596. ModeInformation = (PFILE_MODE_INFORMATION) Buffers[BufferIndex].Buffer;
  1597. //
  1598. // Fill in the new information.
  1599. //
  1600. ModeInformation->Mode = AsyncSetFile->FileMode;
  1601. Iosb.Status = STATUS_SUCCESS;
  1602. Iosb.Information = 0;
  1603. Status = NtSetInformationFile( Handles[AsyncSetFile->FileIndex].Handle,
  1604. &Iosb,
  1605. ModeInformation,
  1606. AsyncSetFile->BufferLengthPtr
  1607. ? AsyncSetFile->BufferLength
  1608. : Buffers[BufferIndex].Length,
  1609. FileModeInformation );
  1610. if (AsyncSetFile->VerboseResults) {
  1611. bprint "\n" );
  1612. bprint " SetModelInformation: Status -> %08lx\n", Status );
  1613. if (NT_SUCCESS( Status )) {
  1614. bprint " Io.Status -> %08lx\n", Iosb.Status );
  1615. bprint " Io.Information -> %08lx\n", Iosb.Information );
  1616. }
  1617. bprint "\n" );
  1618. }
  1619. try_exit: NOTHING;
  1620. } finally {
  1621. if (UnwindBufferIndex) {
  1622. DeallocateBuffer( BufferIndex );
  1623. }
  1624. }
  1625. return;
  1626. }
  1627. VOID
  1628. SetAllocationInformation(
  1629. IN OUT PASYNC_SETFILE AsyncSetFile
  1630. )
  1631. {
  1632. NTSTATUS Status;
  1633. PFILE_ALLOCATION_INFORMATION AllocationInformation;
  1634. USHORT BufferIndex;
  1635. BOOLEAN UnwindBufferIndex = FALSE;
  1636. if (AsyncSetFile->DisplayParms) {
  1637. bprint "\n" );
  1638. bprint "Set FileAllocationInformation Parameters\n" );
  1639. bprint " File Handle Index -> %d\n", AsyncSetFile->FileIndex );
  1640. bprint " BufferLengthPtr -> %08lx\n", AsyncSetFile->BufferLengthPtr );
  1641. if (AsyncSetFile->BufferLengthPtr) {
  1642. bprint " BufferLength value -> %08x\n", AsyncSetFile->BufferLength );
  1643. }
  1644. bprint " New Allocation High -> %08lx\n", AsyncSetFile->NewAllocation.HighPart );
  1645. bprint " New Allocation Low -> %08lx\n", AsyncSetFile->NewAllocation.LowPart );
  1646. bprint "\n" );
  1647. }
  1648. try {
  1649. SIZE_T RegionSize;
  1650. ULONG TempIndex;
  1651. IO_STATUS_BLOCK Iosb;
  1652. RegionSize = sizeof( FILE_ALLOCATION_INFORMATION );
  1653. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  1654. BufferIndex = (USHORT) TempIndex;
  1655. if (!NT_SUCCESS( Status )) {
  1656. bprint "\tSetAllocationInformation: Unable to allocate structure\n" );
  1657. try_return( NOTHING );
  1658. }
  1659. UnwindBufferIndex = TRUE;
  1660. AllocationInformation = (PFILE_ALLOCATION_INFORMATION) Buffers[BufferIndex].Buffer;
  1661. //
  1662. // Fill in the new information.
  1663. //
  1664. AllocationInformation->AllocationSize = AsyncSetFile->NewAllocation;
  1665. Iosb.Status = STATUS_SUCCESS;
  1666. Iosb.Information = 0;
  1667. Status = NtSetInformationFile( Handles[AsyncSetFile->FileIndex].Handle,
  1668. &Iosb,
  1669. AllocationInformation,
  1670. AsyncSetFile->BufferLengthPtr
  1671. ? AsyncSetFile->BufferLength
  1672. : Buffers[BufferIndex].Length,
  1673. FileAllocationInformation );
  1674. if (AsyncSetFile->VerboseResults) {
  1675. bprint "\n" );
  1676. bprint " SetAllocationInformation: Status -> %08lx\n", Status );
  1677. if (NT_SUCCESS( Status )) {
  1678. bprint " Io.Status -> %08lx\n", Iosb.Status );
  1679. bprint " Io.Information -> %08lx\n", Iosb.Information );
  1680. }
  1681. bprint "\n" );
  1682. }
  1683. try_exit: NOTHING;
  1684. } finally {
  1685. if (UnwindBufferIndex) {
  1686. DeallocateBuffer( BufferIndex );
  1687. }
  1688. }
  1689. return;
  1690. }
  1691. VOID
  1692. SetEofInformation(
  1693. IN OUT PASYNC_SETFILE AsyncSetFile
  1694. )
  1695. {
  1696. NTSTATUS Status;
  1697. PFILE_END_OF_FILE_INFORMATION EofInformation;
  1698. USHORT BufferIndex;
  1699. BOOLEAN UnwindBufferIndex = FALSE;
  1700. if (AsyncSetFile->DisplayParms) {
  1701. bprint "\n" );
  1702. bprint "Set FileEofInformation Parameters\n" );
  1703. bprint " File Handle Index -> %d\n", AsyncSetFile->FileIndex );
  1704. bprint " BufferLengthPtr -> %08lx\n", AsyncSetFile->BufferLengthPtr );
  1705. if (AsyncSetFile->BufferLengthPtr) {
  1706. bprint " BufferLength value -> %08x\n", AsyncSetFile->BufferLength );
  1707. }
  1708. bprint " New Eof High -> %08lx\n", AsyncSetFile->NewEof.HighPart );
  1709. bprint " New Eof Low -> %08lx\n", AsyncSetFile->NewEof.LowPart );
  1710. bprint "\n" );
  1711. }
  1712. try {
  1713. SIZE_T RegionSize;
  1714. ULONG TempIndex;
  1715. IO_STATUS_BLOCK Iosb;
  1716. RegionSize = sizeof( FILE_END_OF_FILE_INFORMATION );
  1717. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  1718. BufferIndex = (USHORT) TempIndex;
  1719. if (!NT_SUCCESS( Status )) {
  1720. bprint "\tSetEofInformation: Unable to allocate structure\n" );
  1721. try_return( NOTHING );
  1722. }
  1723. UnwindBufferIndex = TRUE;
  1724. EofInformation = (PFILE_END_OF_FILE_INFORMATION) Buffers[BufferIndex].Buffer;
  1725. //
  1726. // Fill in the new information.
  1727. //
  1728. EofInformation->EndOfFile = AsyncSetFile->NewEof;
  1729. Iosb.Status = STATUS_SUCCESS;
  1730. Iosb.Information = 0;
  1731. Status = NtSetInformationFile( Handles[AsyncSetFile->FileIndex].Handle,
  1732. &Iosb,
  1733. EofInformation,
  1734. AsyncSetFile->BufferLengthPtr
  1735. ? AsyncSetFile->BufferLength
  1736. : Buffers[BufferIndex].Length,
  1737. FileEndOfFileInformation );
  1738. if (AsyncSetFile->VerboseResults) {
  1739. bprint "\n" );
  1740. bprint " SetEOFInformation: Status -> %08lx\n", Status );
  1741. if (NT_SUCCESS( Status )) {
  1742. bprint " Io.Status -> %08lx\n", Iosb.Status );
  1743. bprint " Io.Information -> %08lx\n", Iosb.Information );
  1744. }
  1745. bprint "\n" );
  1746. }
  1747. try_exit: NOTHING;
  1748. } finally {
  1749. if (UnwindBufferIndex) {
  1750. DeallocateBuffer( BufferIndex );
  1751. }
  1752. }
  1753. return;
  1754. }