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.

1167 lines
26 KiB

  1. /* file.c
  2. * OemUnicode win32 thunks
  3. * - file and debug apis
  4. *
  5. * 14-Jan-1993 Jonle
  6. */
  7. #include <nt.h>
  8. #include <ntrtl.h>
  9. #include <nturtl.h>
  10. #include <windows.h>
  11. #include <oemuni.h>
  12. #include "oem.h"
  13. BOOL
  14. CheckForSameCurdir(
  15. PUNICODE_STRING PathName
  16. )
  17. {
  18. PCURDIR CurDir;
  19. UNICODE_STRING CurrentDir;
  20. BOOL rv;
  21. CurDir = &(NtCurrentPeb()->ProcessParameters->CurrentDirectory);
  22. if (CurDir->DosPath.Length > 6 ) {
  23. if ( (CurDir->DosPath.Length-2) != PathName->Length ) {
  24. return FALSE;
  25. }
  26. }
  27. else {
  28. if ( CurDir->DosPath.Length != PathName->Length ) {
  29. return FALSE;
  30. }
  31. }
  32. RtlAcquirePebLock();
  33. CurrentDir = CurDir->DosPath;
  34. if ( CurrentDir.Length > 6 ) {
  35. CurrentDir.Length -= 2;
  36. }
  37. rv = FALSE;
  38. if ( RtlEqualUnicodeString(&CurrentDir,PathName,TRUE) ) {
  39. rv = TRUE;
  40. }
  41. RtlReleasePebLock();
  42. return rv;
  43. }
  44. HANDLE
  45. WINAPI
  46. CreateFileOem(
  47. LPCSTR lpFileName,
  48. DWORD dwDesiredAccess,
  49. DWORD dwShareMode,
  50. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  51. DWORD dwCreationDisposition,
  52. DWORD dwFlagsAndAttributes,
  53. HANDLE hTemplateFile
  54. )
  55. /*++
  56. Routine Description:
  57. OEM thunk to CreateFileW
  58. --*/
  59. {
  60. PUNICODE_STRING Unicode;
  61. OEM_STRING OemString;
  62. NTSTATUS Status;
  63. HANDLE hFile;
  64. DWORD dw;
  65. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  66. InitOemString(&OemString,lpFileName);
  67. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  68. if ( !NT_SUCCESS(Status) ) {
  69. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  70. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  71. }
  72. else {
  73. BaseSetLastNTError(Status);
  74. }
  75. return INVALID_HANDLE_VALUE;
  76. }
  77. /*
  78. * Dos allows change of attributes (time\date etc)
  79. * on files opend for generic read, so we add
  80. * FILE_WRITE_ATTRIBUTES to the Desired access.
  81. */
  82. hFile = CreateFileW( Unicode->Buffer,
  83. dwDesiredAccess == GENERIC_READ
  84. ? dwDesiredAccess | FILE_WRITE_ATTRIBUTES
  85. : dwDesiredAccess,
  86. dwShareMode,
  87. lpSecurityAttributes,
  88. dwCreationDisposition,
  89. dwFlagsAndAttributes,
  90. hTemplateFile
  91. );
  92. /*
  93. * However, NT may fail the request because of the
  94. * extra FILE_WRITE_ATTRIBUTES. Common example
  95. * is a generic read open on a read only net share.
  96. * Retry the Createfile without FILE_WRTIE_ATTRIBUTES
  97. */
  98. if (hFile == INVALID_HANDLE_VALUE && dwDesiredAccess == GENERIC_READ)
  99. {
  100. hFile = CreateFileW( Unicode->Buffer,
  101. dwDesiredAccess,
  102. dwShareMode,
  103. lpSecurityAttributes,
  104. dwCreationDisposition,
  105. dwFlagsAndAttributes,
  106. hTemplateFile
  107. );
  108. }
  109. return hFile;
  110. }
  111. BOOL
  112. APIENTRY
  113. SetFileAttributesOem(
  114. LPSTR lpFileName,
  115. DWORD dwFileAttributes
  116. )
  117. /*++
  118. Routine Description:
  119. Oem thunk to SetFileAttributesW
  120. --*/
  121. {
  122. PUNICODE_STRING Unicode;
  123. OEM_STRING OemString;
  124. NTSTATUS Status;
  125. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  126. InitOemString(&OemString,lpFileName);
  127. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  128. if ( !NT_SUCCESS(Status) ) {
  129. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  130. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  131. }
  132. else {
  133. BaseSetLastNTError(Status);
  134. }
  135. return FALSE;
  136. }
  137. return ( SetFileAttributesW(
  138. Unicode->Buffer,
  139. dwFileAttributes
  140. )
  141. );
  142. }
  143. DWORD
  144. APIENTRY
  145. GetFileAttributesOem(
  146. LPSTR lpFileName
  147. )
  148. /*++
  149. Routine Description:
  150. OEM thunk to GetFileAttributesW
  151. --*/
  152. {
  153. PUNICODE_STRING Unicode;
  154. OEM_STRING OemString;
  155. NTSTATUS Status;
  156. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  157. RtlInitAnsiString(&OemString,lpFileName);
  158. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  159. if ( !NT_SUCCESS(Status) ) {
  160. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  161. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  162. }
  163. else {
  164. BaseSetLastNTError(Status);
  165. }
  166. return 0xFFFFFFFF;
  167. }
  168. return ( GetFileAttributesW(Unicode->Buffer) );
  169. }
  170. BOOL
  171. APIENTRY
  172. DeleteFileOem(
  173. LPSTR lpFileName
  174. )
  175. /*++
  176. Routine Description:
  177. Oem thunk to DeleteFileW
  178. --*/
  179. {
  180. PUNICODE_STRING Unicode;
  181. OEM_STRING OemString;
  182. NTSTATUS Status;
  183. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  184. InitOemString(&OemString,lpFileName);
  185. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  186. if ( !NT_SUCCESS(Status) ) {
  187. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  188. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  189. }
  190. else {
  191. BaseSetLastNTError(Status);
  192. }
  193. return FALSE;
  194. }
  195. return ( DeleteFileW(Unicode->Buffer) );
  196. }
  197. BOOL
  198. APIENTRY
  199. MoveFileOem(
  200. LPSTR lpExistingFileName,
  201. LPSTR lpNewFileName
  202. )
  203. /*++
  204. Routine Description:
  205. OEM thunk to MoveFileW
  206. --*/
  207. {
  208. PUNICODE_STRING Unicode;
  209. UNICODE_STRING UnicodeNewFileName;
  210. OEM_STRING OemString;
  211. NTSTATUS Status;
  212. BOOL ReturnValue;
  213. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  214. InitOemString(&OemString,lpExistingFileName);
  215. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  216. if ( !NT_SUCCESS(Status) ) {
  217. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  218. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  219. }
  220. else {
  221. BaseSetLastNTError(Status);
  222. }
  223. return FALSE;
  224. }
  225. if (ARGUMENT_PRESENT( lpNewFileName )) {
  226. InitOemString(&OemString,lpNewFileName);
  227. Status = RtlOemStringToUnicodeString(&UnicodeNewFileName,&OemString,TRUE);
  228. if ( !NT_SUCCESS(Status) ) {
  229. BaseSetLastNTError(Status);
  230. return FALSE;
  231. }
  232. }
  233. else {
  234. UnicodeNewFileName.Buffer = NULL;
  235. }
  236. ReturnValue = MoveFileExW(Unicode->Buffer,
  237. UnicodeNewFileName.Buffer,
  238. MOVEFILE_COPY_ALLOWED);
  239. if (UnicodeNewFileName.Buffer != NULL) {
  240. RtlFreeUnicodeString(&UnicodeNewFileName);
  241. }
  242. return ReturnValue;
  243. }
  244. BOOL
  245. APIENTRY
  246. MoveFileExOem(
  247. LPSTR lpExistingFileName,
  248. LPSTR lpNewFileName,
  249. DWORD fdwFlags
  250. )
  251. /*++
  252. Routine Description:
  253. OEM thunk to MoveFileExW
  254. --*/
  255. {
  256. PUNICODE_STRING Unicode;
  257. UNICODE_STRING UnicodeNewFileName;
  258. OEM_STRING OemString;
  259. NTSTATUS Status;
  260. BOOL ReturnValue;
  261. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  262. InitOemString(&OemString,lpExistingFileName);
  263. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  264. if ( !NT_SUCCESS(Status) ) {
  265. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  266. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  267. }
  268. else {
  269. BaseSetLastNTError(Status);
  270. }
  271. return FALSE;
  272. }
  273. if (ARGUMENT_PRESENT( lpNewFileName )) {
  274. InitOemString(&OemString,lpNewFileName);
  275. Status = RtlOemStringToUnicodeString(&UnicodeNewFileName,&OemString,TRUE);
  276. if ( !NT_SUCCESS(Status) ) {
  277. BaseSetLastNTError(Status);
  278. return FALSE;
  279. }
  280. }
  281. else {
  282. UnicodeNewFileName.Buffer = NULL;
  283. }
  284. ReturnValue = MoveFileExW(Unicode->Buffer,
  285. UnicodeNewFileName.Buffer,
  286. fdwFlags);
  287. if (UnicodeNewFileName.Buffer != NULL) {
  288. RtlFreeUnicodeString(&UnicodeNewFileName);
  289. }
  290. return ReturnValue;
  291. }
  292. HANDLE
  293. APIENTRY
  294. FindFirstFileOem(
  295. LPSTR lpFileName,
  296. LPWIN32_FIND_DATAA lpFindFileData
  297. )
  298. /*++
  299. Routine Description:
  300. OEM thunk to FindFirstFileW
  301. --*/
  302. {
  303. HANDLE ReturnValue;
  304. PUNICODE_STRING Unicode;
  305. OEM_STRING OemString;
  306. NTSTATUS Status;
  307. UNICODE_STRING UnicodeString;
  308. WIN32_FIND_DATAW FindFileData;
  309. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  310. InitOemString(&OemString,lpFileName);
  311. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  312. if ( !NT_SUCCESS(Status) ) {
  313. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  314. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  315. }
  316. else {
  317. BaseSetLastNTError(Status);
  318. }
  319. return INVALID_HANDLE_VALUE;
  320. }
  321. ReturnValue = FindFirstFileW(Unicode->Buffer,&FindFileData);
  322. if ( ReturnValue == INVALID_HANDLE_VALUE ) {
  323. return ReturnValue;
  324. }
  325. RtlMoveMemory(
  326. lpFindFileData,
  327. &FindFileData,
  328. (ULONG)((ULONG)&FindFileData.cFileName[0] - (ULONG)&FindFileData)
  329. );
  330. RtlInitUnicodeString(&UnicodeString,(PWSTR)FindFileData.cFileName);
  331. OemString.Buffer = lpFindFileData->cFileName;
  332. OemString.MaximumLength = MAX_PATH;
  333. Status = RtlUnicodeStringToOemString(&OemString,&UnicodeString,FALSE);
  334. if (NT_SUCCESS(Status)) {
  335. RtlInitUnicodeString(&UnicodeString,(PWSTR)FindFileData.cAlternateFileName);
  336. OemString.Buffer = lpFindFileData->cAlternateFileName;
  337. OemString.MaximumLength = 14;
  338. Status = RtlUnicodeStringToOemString(&OemString,&UnicodeString,FALSE);
  339. }
  340. if ( !NT_SUCCESS(Status) ) {
  341. FindClose(ReturnValue);
  342. BaseSetLastNTError(Status);
  343. return INVALID_HANDLE_VALUE;
  344. }
  345. return ReturnValue;
  346. }
  347. BOOL
  348. APIENTRY
  349. FindNextFileOem(
  350. HANDLE hFindFile,
  351. LPWIN32_FIND_DATAA lpFindFileData
  352. )
  353. /*++
  354. Routine Description:
  355. Oem thunk to FindFileDataW
  356. --*/
  357. {
  358. BOOL ReturnValue;
  359. OEM_STRING OemString;
  360. NTSTATUS Status;
  361. UNICODE_STRING UnicodeString;
  362. WIN32_FIND_DATAW FindFileData;
  363. ReturnValue = FindNextFileW(hFindFile,&FindFileData);
  364. if ( !ReturnValue ) {
  365. return ReturnValue;
  366. }
  367. RtlMoveMemory(
  368. lpFindFileData,
  369. &FindFileData,
  370. (ULONG)((ULONG)&FindFileData.cFileName[0] - (ULONG)&FindFileData)
  371. );
  372. RtlInitUnicodeString(&UnicodeString,(PWSTR)FindFileData.cFileName);
  373. OemString.Buffer = lpFindFileData->cFileName;
  374. OemString.MaximumLength = MAX_PATH;
  375. Status = RtlUnicodeStringToOemString(&OemString,&UnicodeString,FALSE);
  376. if (NT_SUCCESS(Status)) {
  377. RtlInitUnicodeString(&UnicodeString,(PWSTR)FindFileData.cAlternateFileName);
  378. OemString.Buffer = lpFindFileData->cAlternateFileName;
  379. OemString.MaximumLength = 14;
  380. Status = RtlUnicodeStringToOemString(&OemString,&UnicodeString,FALSE);
  381. }
  382. if ( !NT_SUCCESS(Status) ) {
  383. BaseSetLastNTError(Status);
  384. return FALSE;
  385. }
  386. return ReturnValue;
  387. }
  388. DWORD
  389. APIENTRY
  390. GetFullPathNameOem(
  391. LPCSTR lpFileName,
  392. DWORD nBufferLength,
  393. LPSTR lpBuffer,
  394. LPSTR *lpFilePart
  395. )
  396. /*++
  397. Routine Description:
  398. Oem thunk to GetFullPathNameW
  399. --*/
  400. {
  401. NTSTATUS Status;
  402. ULONG UnicodeLength;
  403. #ifdef FE_SB
  404. ULONG FilePartLength;
  405. UNICODE_STRING UnicodeFilePart;
  406. #endif
  407. UNICODE_STRING UnicodeString;
  408. UNICODE_STRING UnicodeResult;
  409. OEM_STRING OemString;
  410. OEM_STRING OemResult;
  411. PWSTR Ubuff;
  412. PWSTR FilePart;
  413. PWSTR *FilePartPtr;
  414. if ( ARGUMENT_PRESENT(lpFilePart) ) {
  415. FilePartPtr = &FilePart;
  416. }
  417. else {
  418. FilePartPtr = NULL;
  419. }
  420. RtlInitString(&OemString,lpFileName);
  421. Status = RtlOemStringToUnicodeString(&UnicodeString,&OemString,TRUE);
  422. if ( !NT_SUCCESS(Status) ){
  423. RtlFreeUnicodeString(&UnicodeString);
  424. BaseSetLastNTError(Status);
  425. return 0;
  426. }
  427. Ubuff = RtlAllocateHeap(RtlProcessHeap(), 0,(MAX_PATH<<1) + sizeof(UNICODE_NULL));
  428. if ( !Ubuff ) {
  429. RtlFreeUnicodeString(&UnicodeString);
  430. BaseSetLastNTError(STATUS_NO_MEMORY);
  431. return 0;
  432. }
  433. UnicodeLength = RtlGetFullPathName_U(
  434. UnicodeString.Buffer,
  435. (MAX_PATH<<1),
  436. Ubuff,
  437. FilePartPtr
  438. );
  439. #ifdef FE_SB
  440. // BugFix: can't listed with file open dialog of MS's app 1995.3.7 V-HIDEKK
  441. RtlInitUnicodeString( &UnicodeFilePart, Ubuff );
  442. UnicodeLength = RtlUnicodeStringToOemSize( &UnicodeFilePart );
  443. #else
  444. UnicodeLength >>= 1;
  445. #endif
  446. if ( UnicodeLength && UnicodeLength < nBufferLength ) {
  447. RtlInitUnicodeString(&UnicodeResult,Ubuff);
  448. Status = RtlUnicodeStringToOemString(&OemResult,&UnicodeResult,TRUE);
  449. if ( NT_SUCCESS(Status) ) {
  450. #ifdef FE_SB
  451. RtlMoveMemory(lpBuffer,OemResult.Buffer,UnicodeLength);
  452. #else
  453. RtlMoveMemory(lpBuffer,OemResult.Buffer,UnicodeLength+1);
  454. #endif
  455. RtlFreeOemString(&OemResult);
  456. if ( ARGUMENT_PRESENT(lpFilePart) ) {
  457. if ( FilePart == NULL ) {
  458. *lpFilePart = NULL;
  459. }
  460. else {
  461. #ifdef FE_SB
  462. RtlInitUnicodeString(&UnicodeFilePart,FilePart);
  463. FilePartLength = RtlUnicodeStringToOemSize( &UnicodeFilePart );
  464. *lpFilePart = (PSZ)(UnicodeLength - FilePartLength);
  465. #else
  466. *lpFilePart = (PSZ)(FilePart - Ubuff);
  467. #endif
  468. *lpFilePart = *lpFilePart + (ULONG)lpBuffer;
  469. }
  470. }
  471. }
  472. else {
  473. BaseSetLastNTError(Status);
  474. UnicodeLength = 0;
  475. }
  476. }
  477. else {
  478. if ( UnicodeLength ) {
  479. UnicodeLength++;
  480. }
  481. }
  482. RtlFreeUnicodeString(&UnicodeString);
  483. RtlFreeHeap(RtlProcessHeap(), 0,Ubuff);
  484. return (DWORD)UnicodeLength;
  485. }
  486. DWORD
  487. APIENTRY
  488. GetCurrentDirectoryOem(
  489. DWORD nBufferLength,
  490. LPSTR lpBuffer
  491. )
  492. /*++
  493. Routine Description:
  494. Oem thunk to GetCurrentDirectoryW
  495. --*/
  496. {
  497. PUNICODE_STRING Unicode;
  498. OEM_STRING OemString;
  499. NTSTATUS Status;
  500. DWORD ReturnValue;
  501. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  502. Unicode->Length = (USHORT)RtlGetCurrentDirectory_U(
  503. Unicode->MaximumLength,
  504. Unicode->Buffer
  505. );
  506. #ifdef FE_SB
  507. ReturnValue = RtlUnicodeStringToOemSize( Unicode );
  508. if ( nBufferLength > ReturnValue-1 ) {
  509. #else
  510. if ( nBufferLength > (DWORD)(Unicode->Length>>1) ) {
  511. #endif
  512. OemString.Buffer = lpBuffer;
  513. OemString.MaximumLength = (USHORT)(nBufferLength+1);
  514. Status = RtlUnicodeStringToOemString(&OemString,Unicode,FALSE);
  515. if ( !NT_SUCCESS(Status) ) {
  516. BaseSetLastNTError(Status);
  517. ReturnValue = 0;
  518. }
  519. else {
  520. ReturnValue = OemString.Length;
  521. }
  522. }
  523. #ifndef FE_SB
  524. else {
  525. ReturnValue = ((Unicode->Length)>>1)+1;
  526. }
  527. #endif
  528. return ReturnValue;
  529. }
  530. BOOL
  531. APIENTRY
  532. SetCurrentDirectoryOem(
  533. LPSTR lpPathName
  534. )
  535. /*++
  536. Routine Description:
  537. Oem thunk to SetCurrentDirectoryW
  538. --*/
  539. {
  540. PUNICODE_STRING Unicode;
  541. OEM_STRING OemString;
  542. NTSTATUS Status;
  543. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  544. InitOemString(&OemString,lpPathName);
  545. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  546. if ( !NT_SUCCESS(Status) ) {
  547. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  548. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  549. }
  550. else {
  551. BaseSetLastNTError(Status);
  552. }
  553. return FALSE;
  554. }
  555. if (!CheckForSameCurdir(Unicode)) {
  556. Status = RtlSetCurrentDirectory_U(Unicode);
  557. if ( !NT_SUCCESS(Status) ) {
  558. BaseSetLastNTError(Status);
  559. return FALSE;
  560. }
  561. }
  562. return TRUE;
  563. }
  564. BOOL
  565. APIENTRY
  566. CreateDirectoryOem(
  567. LPSTR lpPathName,
  568. LPSECURITY_ATTRIBUTES lpSecurityAttributes
  569. )
  570. /*++
  571. Routine Description:
  572. Oem thunk to CreateDirectoryW
  573. --*/
  574. {
  575. PUNICODE_STRING Unicode;
  576. OEM_STRING OemString;
  577. NTSTATUS Status;
  578. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  579. InitOemString(&OemString,lpPathName);
  580. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  581. if ( !NT_SUCCESS(Status) ) {
  582. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  583. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  584. }
  585. else {
  586. BaseSetLastNTError(Status);
  587. }
  588. return FALSE;
  589. }
  590. return ( CreateDirectoryW(Unicode->Buffer,lpSecurityAttributes) );
  591. }
  592. BOOL
  593. APIENTRY
  594. RemoveDirectoryOem(
  595. LPSTR lpPathName
  596. )
  597. /*++
  598. Routine Description:
  599. Oem thunk to RemoveDirectoryW
  600. --*/
  601. {
  602. PUNICODE_STRING Unicode;
  603. OEM_STRING OemString;
  604. NTSTATUS Status;
  605. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  606. InitOemString(&OemString,lpPathName);
  607. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  608. if ( !NT_SUCCESS(Status) ) {
  609. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  610. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  611. }
  612. else {
  613. BaseSetLastNTError(Status);
  614. }
  615. return FALSE;
  616. }
  617. return ( RemoveDirectoryW(Unicode->Buffer) );
  618. }
  619. UINT
  620. APIENTRY
  621. GetDriveTypeOem(
  622. LPSTR lpRootPathName
  623. )
  624. /*++
  625. Routine Description:
  626. OEM thunk to GetDriveTypeW
  627. --*/
  628. {
  629. PUNICODE_STRING Unicode;
  630. OEM_STRING OemString;
  631. NTSTATUS Status;
  632. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  633. InitOemString(
  634. &OemString,
  635. ARGUMENT_PRESENT(lpRootPathName) ? lpRootPathName : "\\"
  636. );
  637. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  638. if ( !NT_SUCCESS(Status) ) {
  639. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  640. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  641. }
  642. else {
  643. BaseSetLastNTError(Status);
  644. }
  645. return 1;
  646. }
  647. return (GetDriveTypeW(Unicode->Buffer));
  648. }
  649. BOOL
  650. APIENTRY
  651. GetDiskFreeSpaceOem(
  652. LPSTR lpRootPathName,
  653. LPDWORD lpSectorsPerCluster,
  654. LPDWORD lpBytesPerSector,
  655. LPDWORD lpNumberOfFreeClusters,
  656. LPDWORD lpTotalNumberOfClusters
  657. )
  658. /*++
  659. Routine Description:
  660. Oem thunk to GetDiskFreeSpaceW
  661. --*/
  662. {
  663. PUNICODE_STRING Unicode;
  664. OEM_STRING OemString;
  665. NTSTATUS Status;
  666. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  667. InitOemString(
  668. &OemString,
  669. ARGUMENT_PRESENT(lpRootPathName) ? lpRootPathName : "\\"
  670. );
  671. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  672. if ( !NT_SUCCESS(Status) ) {
  673. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  674. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  675. }
  676. else {
  677. BaseSetLastNTError(Status);
  678. }
  679. return FALSE;
  680. }
  681. return ( GetDiskFreeSpaceW(
  682. Unicode->Buffer,
  683. lpSectorsPerCluster,
  684. lpBytesPerSector,
  685. lpNumberOfFreeClusters,
  686. lpTotalNumberOfClusters
  687. )
  688. );
  689. }
  690. BOOL
  691. APIENTRY
  692. GetVolumeInformationOem(
  693. LPSTR lpRootPathName,
  694. LPSTR lpVolumeNameBuffer,
  695. DWORD nVolumeNameSize,
  696. LPDWORD lpVolumeSerialNumber,
  697. LPDWORD lpMaximumComponentLength,
  698. LPDWORD lpFileSystemFlags,
  699. LPSTR lpFileSystemNameBuffer,
  700. DWORD nFileSystemNameSize
  701. )
  702. /*++
  703. Routine Description:
  704. Oem thunk to GetVolumeInformationW
  705. --*/
  706. {
  707. PUNICODE_STRING Unicode;
  708. OEM_STRING OemString;
  709. NTSTATUS Status;
  710. UNICODE_STRING UnicodeVolumeName;
  711. UNICODE_STRING UnicodeFileSystemName;
  712. OEM_STRING OemVolumeName;
  713. OEM_STRING OemFileSystemName;
  714. BOOL ReturnValue;
  715. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  716. InitOemString(
  717. &OemString,
  718. ARGUMENT_PRESENT(lpRootPathName) ? lpRootPathName : "\\"
  719. );
  720. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  721. if ( !NT_SUCCESS(Status) ) {
  722. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  723. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  724. }
  725. else {
  726. BaseSetLastNTError(Status);
  727. }
  728. return FALSE;
  729. }
  730. UnicodeVolumeName.Buffer = NULL;
  731. UnicodeFileSystemName.Buffer = NULL;
  732. UnicodeVolumeName.MaximumLength = 0;
  733. UnicodeFileSystemName.MaximumLength = 0;
  734. OemVolumeName.Buffer = lpVolumeNameBuffer;
  735. OemVolumeName.MaximumLength = (USHORT)(nVolumeNameSize+1);
  736. OemFileSystemName.Buffer = lpFileSystemNameBuffer;
  737. OemFileSystemName.MaximumLength = (USHORT)(nFileSystemNameSize+1);
  738. try {
  739. if ( ARGUMENT_PRESENT(lpVolumeNameBuffer) ) {
  740. UnicodeVolumeName.MaximumLength = OemVolumeName.MaximumLength << 1;
  741. UnicodeVolumeName.Buffer = RtlAllocateHeap(
  742. RtlProcessHeap(), 0,
  743. UnicodeVolumeName.MaximumLength
  744. );
  745. if ( !UnicodeVolumeName.Buffer ) {
  746. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  747. return FALSE;
  748. }
  749. }
  750. if ( ARGUMENT_PRESENT(lpFileSystemNameBuffer) ) {
  751. UnicodeFileSystemName.MaximumLength = OemFileSystemName.MaximumLength << 1;
  752. UnicodeFileSystemName.Buffer = RtlAllocateHeap(
  753. RtlProcessHeap(), 0,
  754. UnicodeFileSystemName.MaximumLength
  755. );
  756. if ( !UnicodeFileSystemName.Buffer ) {
  757. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  758. return FALSE;
  759. }
  760. }
  761. ReturnValue = GetVolumeInformationW(
  762. Unicode->Buffer,
  763. UnicodeVolumeName.Buffer,
  764. nVolumeNameSize,
  765. lpVolumeSerialNumber,
  766. lpMaximumComponentLength,
  767. lpFileSystemFlags,
  768. UnicodeFileSystemName.Buffer,
  769. nFileSystemNameSize
  770. );
  771. if ( ReturnValue ) {
  772. if ( ARGUMENT_PRESENT(lpVolumeNameBuffer) ) {
  773. RtlInitUnicodeString(
  774. &UnicodeVolumeName,
  775. UnicodeVolumeName.Buffer
  776. );
  777. Status = RtlUnicodeStringToOemString(
  778. &OemVolumeName,
  779. &UnicodeVolumeName,
  780. FALSE
  781. );
  782. if ( !NT_SUCCESS(Status) ) {
  783. BaseSetLastNTError(Status);
  784. return FALSE;
  785. }
  786. }
  787. if ( ARGUMENT_PRESENT(lpFileSystemNameBuffer) ) {
  788. RtlInitUnicodeString(
  789. &UnicodeFileSystemName,
  790. UnicodeFileSystemName.Buffer
  791. );
  792. Status = RtlUnicodeStringToOemString(
  793. &OemFileSystemName,
  794. &UnicodeFileSystemName,
  795. FALSE
  796. );
  797. if ( !NT_SUCCESS(Status) ) {
  798. BaseSetLastNTError(Status);
  799. return FALSE;
  800. }
  801. }
  802. }
  803. }
  804. finally {
  805. if ( UnicodeVolumeName.Buffer ) {
  806. RtlFreeHeap(RtlProcessHeap(), 0,UnicodeVolumeName.Buffer);
  807. }
  808. if ( UnicodeFileSystemName.Buffer ) {
  809. RtlFreeHeap(RtlProcessHeap(), 0,UnicodeFileSystemName.Buffer);
  810. }
  811. }
  812. return ReturnValue;
  813. }
  814. VOID
  815. APIENTRY
  816. OutputDebugStringOem(
  817. LPCSTR lpOutputString
  818. )
  819. /*++
  820. Routine Description:
  821. OEM thunk to OutputDebugStringA
  822. --*/
  823. {
  824. UNICODE_STRING Unicode;
  825. OEM_STRING OemString;
  826. ANSI_STRING AnsiString;
  827. NTSTATUS Status;
  828. Unicode.Buffer = NULL;
  829. AnsiString.Buffer = NULL;
  830. try {
  831. InitOemString(&OemString, lpOutputString);
  832. Status = RtlOemStringToUnicodeString(&Unicode, &OemString, TRUE);
  833. if ( !NT_SUCCESS(Status) ) {
  834. goto try_exit;
  835. }
  836. Status = RtlUnicodeStringToAnsiString(&AnsiString,&Unicode,TRUE);
  837. if ( !NT_SUCCESS(Status) ) {
  838. goto try_exit;
  839. }
  840. OutputDebugStringA(AnsiString.Buffer);
  841. try_exit:;
  842. }
  843. finally {
  844. if (Unicode.Buffer != NULL) {
  845. RtlFreeUnicodeString( &Unicode );
  846. }
  847. if (AnsiString.Buffer != NULL) {
  848. RtlFreeAnsiString( &AnsiString);
  849. }
  850. }
  851. }
  852. BOOL
  853. APIENTRY
  854. GetComputerNameOem(
  855. LPSTR lpBuffer,
  856. LPDWORD nSize
  857. )
  858. /*++
  859. Routine Description:
  860. Oem thunk to GetComputerNameW
  861. --*/
  862. {
  863. UNICODE_STRING UnicodeString;
  864. OEM_STRING OemString;
  865. LPWSTR UnicodeBuffer;
  866. //
  867. // Work buffer needs to be twice the size of the user's buffer
  868. //
  869. UnicodeBuffer = RtlAllocateHeap(RtlProcessHeap(), 0, *nSize * sizeof(WCHAR));
  870. if (!UnicodeBuffer) {
  871. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  872. return(FALSE);
  873. }
  874. //
  875. // Set up an ANSI_STRING that points to the user's buffer
  876. //
  877. OemString.MaximumLength = (USHORT) *nSize;
  878. OemString.Length = 0;
  879. OemString.Buffer = lpBuffer;
  880. //
  881. // Call the UNICODE version to do the work
  882. //
  883. if (!GetComputerNameW(UnicodeBuffer, nSize)) {
  884. RtlFreeHeap(RtlProcessHeap(), 0, UnicodeBuffer);
  885. return(FALSE);
  886. }
  887. //
  888. // Now convert back to Oem for the caller
  889. //
  890. RtlInitUnicodeString(&UnicodeString, UnicodeBuffer);
  891. RtlUnicodeStringToOemString(&OemString, &UnicodeString, FALSE);
  892. *nSize = OemString.Length;
  893. RtlFreeHeap(RtlProcessHeap(), 0, UnicodeBuffer);
  894. return(TRUE);
  895. }
  896. BOOL
  897. WINAPI
  898. RemoveFontResourceOem(
  899. LPSTR lpFileName
  900. )
  901. /*++
  902. Routine Description:
  903. Oem thunk to RemoveFontResourceW
  904. --*/
  905. {
  906. PUNICODE_STRING Unicode;
  907. OEM_STRING OemString;
  908. NTSTATUS Status;
  909. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  910. InitOemString(&OemString,lpFileName);
  911. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  912. if ( !NT_SUCCESS(Status) ) {
  913. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  914. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  915. }
  916. else {
  917. BaseSetLastNTError(Status);
  918. }
  919. return FALSE;
  920. }
  921. return ( RemoveFontResourceW(Unicode->Buffer) );
  922. }
  923.