Author: ion
Date: Mon Nov 7 07:41:52 2011
New Revision: 54334
URL:
http://svn.reactos.org/svn/reactos?rev=54334&view=rev
Log:
[KERNEL32]: Show some love to Get/SetCurrent/Windows/SystemDirectoryA/W. Only SearchPathW
and loader stuff remains to be fixed. Also handle SetCurrentDirectory when directory is
already current.
[KERNEL32]: Rewrite the tape APIs to use a single generic function, and in the process
support pending I/O now, which wasn't handled before.
[KERNEL32]: Moved the interlocked APIs to synch.c instead of dllmain.c
Modified:
trunk/reactos/dll/win32/kernel32/client/dllmain.c
trunk/reactos/dll/win32/kernel32/client/file/tape.c
trunk/reactos/dll/win32/kernel32/client/path.c
trunk/reactos/dll/win32/kernel32/client/synch.c
trunk/reactos/dll/win32/kernel32/include/kernel32.h
Modified: trunk/reactos/dll/win32/kernel32/client/dllmain.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/dllmain.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/dllmain.c [iso-8859-1] Mon Nov 7 07:41:52
2011
@@ -19,9 +19,6 @@
/* GLOBALS *******************************************************************/
-extern UNICODE_STRING SystemDirectory;
-extern UNICODE_STRING WindowsDirectory;
-
PBASE_STATIC_SERVER_DATA BaseStaticServerData;
BOOLEAN BaseRunningInServerProcess;
@@ -34,7 +31,6 @@
PPEB Peb;
ULONG SessionId;
BOOL ConsoleInitialized = FALSE;
-UNICODE_STRING BaseWindowsDirectory, BaseWindowsSystemDirectory;
static BOOL DllInitialized = FALSE;
BOOL WINAPI
@@ -271,12 +267,10 @@
/* Set the directories */
BaseWindowsDirectory = BaseStaticServerData->WindowsDirectory;
BaseWindowsSystemDirectory = BaseStaticServerData->WindowsSystemDirectory;
- SystemDirectory = BaseWindowsSystemDirectory;
- WindowsDirectory = BaseWindowsDirectory;
/* Construct the default path (using the static buffer) */
_snwprintf(BaseDefaultPathBuffer, sizeof(BaseDefaultPathBuffer) / sizeof(WCHAR),
- L".;%wZ;%wZ\\system;%wZ;", &SystemDirectory,
&WindowsDirectory, &WindowsDirectory);
+ L".;%wZ;%wZ\\system;%wZ;", &BaseWindowsSystemDirectory,
&BaseWindowsDirectory, &BaseWindowsDirectory);
BaseDefaultPath.Buffer = BaseDefaultPathBuffer;
BaseDefaultPath.Length = wcslen(BaseDefaultPathBuffer) * sizeof(WCHAR);
@@ -337,50 +331,4 @@
return TRUE;
}
-#undef InterlockedIncrement
-#undef InterlockedDecrement
-#undef InterlockedExchange
-#undef InterlockedExchangeAdd
-#undef InterlockedCompareExchange
-
-LONG
-WINAPI
-InterlockedIncrement(IN OUT LONG volatile *lpAddend)
-{
- return _InterlockedIncrement(lpAddend);
-}
-
-LONG
-WINAPI
-InterlockedDecrement(IN OUT LONG volatile *lpAddend)
-{
- return _InterlockedDecrement(lpAddend);
-}
-
-#undef InterlockedExchange
-LONG
-WINAPI
-InterlockedExchange(IN OUT LONG volatile *Target,
- IN LONG Value)
-{
- return _InterlockedExchange(Target, Value);
-}
-
-LONG
-WINAPI
-InterlockedExchangeAdd(IN OUT LONG volatile *Addend,
- IN LONG Value)
-{
- return _InterlockedExchangeAdd(Addend, Value);
-}
-
-LONG
-WINAPI
-InterlockedCompareExchange(IN OUT LONG volatile *Destination,
- IN LONG Exchange,
- IN LONG Comperand)
-{
- return _InterlockedCompareExchange(Destination, Exchange, Comperand);
-}
-
/* EOF */
Modified: trunk/reactos/dll/win32/kernel32/client/file/tape.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/file/tape.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/file/tape.c [iso-8859-1] Mon Nov 7 07:41:52
2011
@@ -9,404 +9,311 @@
* Created 01/11/98
*/
-/* INCLUDES *****************************************************************/
+/* INCLUDES *******************************************************************/
#include <k32.h>
#define NDEBUG
#include <debug.h>
-/* FUNCTIONS ****************************************************************/
-
-/*
- * @implemented
- */
-DWORD WINAPI
-CreateTapePartition (HANDLE hDevice,
- DWORD dwPartitionMethod,
- DWORD dwCount,
- DWORD dwSize)
-{
- TAPE_CREATE_PARTITION TapeCreatePartition;
- IO_STATUS_BLOCK IoStatusBlock;
- DWORD ErrorCode;
- NTSTATUS Status;
-
- TapeCreatePartition.Method = dwPartitionMethod;
- TapeCreatePartition.Count = dwCount;
- TapeCreatePartition.Size = dwSize;
-
- Status = NtDeviceIoControlFile (hDevice,
- NULL,
- NULL,
- NULL,
- &IoStatusBlock,
- IOCTL_TAPE_CREATE_PARTITION,
- &TapeCreatePartition,
- sizeof(TAPE_CREATE_PARTITION),
- NULL,
- 0);
- if (!NT_SUCCESS(Status))
- {
- ErrorCode = RtlNtStatusToDosError(Status);
- SetLastError (ErrorCode);
- return ErrorCode;
- }
-
- return ERROR_SUCCESS;
-}
-
-
-/*
- * @implemented
- */
-DWORD WINAPI
-EraseTape (HANDLE hDevice,
- DWORD dwEraseType,
- BOOL bImmediate)
-{
- TAPE_ERASE TapeErase;
- IO_STATUS_BLOCK IoStatusBlock;
- DWORD ErrorCode;
- NTSTATUS Status;
-
- TapeErase.Type = dwEraseType;
- TapeErase.Immediate = (BOOLEAN)bImmediate;
-
- Status = NtDeviceIoControlFile (hDevice,
- NULL,
- NULL,
- NULL,
- &IoStatusBlock,
- IOCTL_TAPE_ERASE,
- &TapeErase,
- sizeof(TAPE_ERASE),
- NULL,
- 0);
- if (!NT_SUCCESS(Status))
- {
- ErrorCode = RtlNtStatusToDosError(Status);
- SetLastError (ErrorCode);
- return ErrorCode;
- }
-
- return ERROR_SUCCESS;
-}
-
-
-/*
- * @implemented
- */
-DWORD WINAPI
-GetTapeParameters (HANDLE hDevice,
- DWORD dwOperation,
- LPDWORD lpdwSize,
- LPVOID lpTapeInformation)
-{
- IO_STATUS_BLOCK IoStatusBlock;
- DWORD ErrorCode;
- NTSTATUS Status;
-
- if (dwOperation == GET_TAPE_MEDIA_INFORMATION)
- {
- if (*lpdwSize < sizeof(TAPE_GET_MEDIA_PARAMETERS))
- {
- *lpdwSize = sizeof(TAPE_GET_MEDIA_PARAMETERS);
- return ERROR_MORE_DATA;
- }
-
- Status = NtDeviceIoControlFile (hDevice,
- NULL,
- NULL,
- NULL,
- &IoStatusBlock,
- IOCTL_TAPE_GET_MEDIA_PARAMS,
- NULL,
- 0,
- lpTapeInformation,
- sizeof(TAPE_GET_MEDIA_PARAMETERS));
- }
- else if (dwOperation == GET_TAPE_DRIVE_INFORMATION)
- {
- if (*lpdwSize < sizeof(TAPE_GET_DRIVE_PARAMETERS))
- {
- *lpdwSize = sizeof(TAPE_GET_DRIVE_PARAMETERS);
- return ERROR_MORE_DATA;
- }
-
- Status = NtDeviceIoControlFile (hDevice,
- NULL,
- NULL,
- NULL,
- &IoStatusBlock,
- IOCTL_TAPE_GET_DRIVE_PARAMS,
- NULL,
- 0,
- lpTapeInformation,
- sizeof(TAPE_GET_DRIVE_PARAMETERS));
- }
- else
- {
- return ERROR_INVALID_FUNCTION;
- }
-
- if (!NT_SUCCESS(Status))
- {
- ErrorCode = RtlNtStatusToDosError(Status);
- SetLastError (ErrorCode);
- return ErrorCode;
- }
-
- return ERROR_SUCCESS;
-}
-
-
-/*
- * @implemented
- */
-DWORD WINAPI
-GetTapePosition (HANDLE hDevice,
- DWORD dwPositionType,
- LPDWORD lpdwPartition,
- LPDWORD lpdwOffsetLow,
- LPDWORD lpdwOffsetHigh)
-{
- TAPE_GET_POSITION TapeGetPosition;
- IO_STATUS_BLOCK IoStatusBlock;
- DWORD ErrorCode;
- NTSTATUS Status;
-
- TapeGetPosition.Type = dwPositionType;
-
- Status = NtDeviceIoControlFile (hDevice,
- NULL,
- NULL,
- NULL,
- &IoStatusBlock,
- IOCTL_TAPE_GET_POSITION,
- &TapeGetPosition,
- sizeof(TAPE_GET_POSITION),
- &TapeGetPosition,
- sizeof(TAPE_GET_POSITION));
- if (!NT_SUCCESS(Status))
- {
- *lpdwPartition = 0;
- *lpdwOffsetLow = 0;
- *lpdwOffsetHigh = 0;
-
- ErrorCode = RtlNtStatusToDosError(Status);
- SetLastError (ErrorCode);
- return ErrorCode;
- }
-
- *lpdwPartition = TapeGetPosition.Partition;
- *lpdwOffsetLow = TapeGetPosition.Offset.u.LowPart;
- *lpdwOffsetHigh = TapeGetPosition.Offset.u.HighPart;
-
- return ERROR_SUCCESS;
-}
-
-
-/*
- * @implemented
- */
-DWORD WINAPI
-GetTapeStatus (HANDLE hDevice)
-{
- IO_STATUS_BLOCK IoStatusBlock;
- DWORD ErrorCode;
- NTSTATUS Status;
-
- Status = NtDeviceIoControlFile (hDevice,
- NULL,
- NULL,
- NULL,
- &IoStatusBlock,
- IOCTL_TAPE_GET_STATUS,
- NULL,
- 0,
- NULL,
- 0);
- if (!NT_SUCCESS(Status))
- {
- ErrorCode = RtlNtStatusToDosError(Status);
- SetLastError (ErrorCode);
- return ErrorCode;
- }
-
- return ERROR_SUCCESS;
-}
-
-
-/*
- * @implemented
- */
-DWORD WINAPI
-PrepareTape (HANDLE hDevice,
- DWORD dwOperation,
- BOOL bImmediate)
-{
- TAPE_PREPARE TapePrepare;
- IO_STATUS_BLOCK IoStatusBlock;
- DWORD ErrorCode;
- NTSTATUS Status;
-
- TapePrepare.Operation = dwOperation;
- TapePrepare.Immediate = (BOOLEAN)bImmediate;
-
- Status = NtDeviceIoControlFile (hDevice,
- NULL,
- NULL,
- NULL,
- &IoStatusBlock,
- IOCTL_TAPE_PREPARE,
- &TapePrepare,
- sizeof(TAPE_PREPARE),
- NULL,
- 0);
- if (!NT_SUCCESS(Status))
- {
- ErrorCode = RtlNtStatusToDosError(Status);
- SetLastError (ErrorCode);
- return ErrorCode;
- }
-
- return ERROR_SUCCESS;
-}
-
-
-/*
- * @implemented
- */
-DWORD WINAPI
-SetTapeParameters (HANDLE hDevice,
- DWORD dwOperation,
- LPVOID lpTapeInformation)
-{
- IO_STATUS_BLOCK IoStatusBlock;
- DWORD ErrorCode;
- NTSTATUS Status;
-
- if (dwOperation == SET_TAPE_MEDIA_INFORMATION)
- {
- Status = NtDeviceIoControlFile (hDevice,
- NULL,
- NULL,
- NULL,
- &IoStatusBlock,
- IOCTL_TAPE_SET_MEDIA_PARAMS,
- lpTapeInformation,
- sizeof(TAPE_SET_MEDIA_PARAMETERS),
- NULL,
- 0);
- }
- else if (dwOperation == SET_TAPE_DRIVE_INFORMATION)
- {
- Status = NtDeviceIoControlFile (hDevice,
- NULL,
- NULL,
- NULL,
- &IoStatusBlock,
- IOCTL_TAPE_SET_DRIVE_PARAMS,
- lpTapeInformation,
- sizeof(TAPE_SET_DRIVE_PARAMETERS),
- NULL,
- 0);
- }
- else
- {
- return ERROR_INVALID_FUNCTION;
- }
-
- if (!NT_SUCCESS(Status))
- {
- ErrorCode = RtlNtStatusToDosError(Status);
- SetLastError (ErrorCode);
- return ErrorCode;
- }
-
- return ERROR_SUCCESS;
-}
-
-
-/*
- * @implemented
- */
-DWORD WINAPI
-SetTapePosition (HANDLE hDevice,
- DWORD dwPositionMethod,
- DWORD dwPartition,
- DWORD dwOffsetLow,
- DWORD dwOffsetHigh,
- BOOL bImmediate)
-{
- TAPE_SET_POSITION TapeSetPosition;
- IO_STATUS_BLOCK IoStatusBlock;
- DWORD ErrorCode;
- NTSTATUS Status;
-
- TapeSetPosition.Method = dwPositionMethod;
- TapeSetPosition.Partition = dwPartition;
- TapeSetPosition.Offset.u.LowPart = dwOffsetLow;
- TapeSetPosition.Offset.u.HighPart = dwOffsetHigh;
- TapeSetPosition.Immediate = (BOOLEAN)bImmediate;
-
- Status = NtDeviceIoControlFile (hDevice,
- NULL,
- NULL,
- NULL,
- &IoStatusBlock,
- IOCTL_TAPE_SET_POSITION,
- &TapeSetPosition,
- sizeof(TAPE_SET_POSITION),
- NULL,
- 0);
- if (!NT_SUCCESS(Status))
- {
- ErrorCode = RtlNtStatusToDosError(Status);
- SetLastError (ErrorCode);
- return ErrorCode;
- }
-
- return ERROR_SUCCESS;
-}
-
-
-/*
- * @implemented
- */
-DWORD WINAPI
-WriteTapemark (HANDLE hDevice,
- DWORD dwTapemarkType,
- DWORD dwTapemarkCount,
- BOOL bImmediate)
-{
- TAPE_WRITE_MARKS TapeWriteMarks;
- IO_STATUS_BLOCK IoStatusBlock;
- DWORD ErrorCode;
- NTSTATUS Status;
-
- TapeWriteMarks.Type = dwTapemarkType;
- TapeWriteMarks.Count = dwTapemarkCount;
- TapeWriteMarks.Immediate = (BOOLEAN)bImmediate;
-
- Status = NtDeviceIoControlFile (hDevice,
- NULL,
- NULL,
- NULL,
- &IoStatusBlock,
- IOCTL_TAPE_WRITE_MARKS,
- &TapeWriteMarks,
- sizeof(TAPE_WRITE_MARKS),
- NULL,
- 0);
- if (!NT_SUCCESS(Status))
- {
- ErrorCode = RtlNtStatusToDosError(Status);
- SetLastError (ErrorCode);
- return ErrorCode;
- }
-
- return ERROR_SUCCESS;
+/* PRIVATE FUNCTIONS **********************************************************/
+
+DWORD
+WINAPI
+BasepDoTapeOperation(IN HANDLE DeviceHandle,
+ IN ULONG Ioctl,
+ IN PVOID Input,
+ IN ULONG InputLength,
+ IN PVOID Output,
+ IN ULONG OutputLength)
+{
+ HANDLE TapeEvent;
+ DWORD ErrorCode;
+ NTSTATUS Status;
+ IO_STATUS_BLOCK IoStatusBlock;
+
+ /* Create the wait event */
+ TapeEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+ if (!TapeEvent) return GetLastError();
+
+ /* Send the IOCTL */
+ Status = NtDeviceIoControlFile(DeviceHandle,
+ TapeEvent,
+ 0,
+ 0,
+ &IoStatusBlock,
+ Ioctl,
+ Input,
+ InputLength,
+ Output,
+ OutputLength);
+ if (Status == STATUS_PENDING)
+ {
+ /* Wait for its completion */
+ WaitForSingleObject(TapeEvent, INFINITE);
+ Status = IoStatusBlock.Status;
+ }
+
+ /* Get rid of the wait event and check status */
+ CloseHandle(TapeEvent);
+ if (!NT_SUCCESS(Status))
+ {
+ /* Convert to Win32 */
+ BaseSetLastNTError(Status);
+ ErrorCode = GetLastError();
+ }
+ else
+ {
+ /* Set sucess */
+ ErrorCode = ERROR_SUCCESS;
+ }
+
+ /* Return the Win32 error code */
+ return ErrorCode;
+}
+
+/* PUBLIC FUNCTIONS ***********************************************************/
+
+/*
+ * @implemented
+ */
+DWORD
+WINAPI
+CreateTapePartition(IN HANDLE hDevice,
+ IN DWORD dwPartitionMethod,
+ IN DWORD dwCount,
+ IN DWORD dwSize)
+{
+ TAPE_CREATE_PARTITION TapeCreatePartition;
+
+ TapeCreatePartition.Method = dwPartitionMethod;
+ TapeCreatePartition.Count = dwCount;
+ TapeCreatePartition.Size = dwSize;
+ return BasepDoTapeOperation(hDevice,
+ IOCTL_TAPE_CREATE_PARTITION,
+ &TapeCreatePartition,
+ sizeof(TapeCreatePartition),
+ NULL,
+ 0);
+}
+
+/*
+ * @implemented
+ */
+DWORD
+WINAPI
+EraseTape(IN HANDLE hDevice,
+ IN DWORD dwEraseType,
+ IN BOOL bImmediate)
+{
+ TAPE_ERASE TapeErase;
+
+ TapeErase.Type = dwEraseType;
+ TapeErase.Immediate = (BOOLEAN)bImmediate;
+ return BasepDoTapeOperation(hDevice,
+ IOCTL_TAPE_ERASE,
+ &TapeErase,
+ sizeof(TapeErase),
+ NULL,
+ 0);
+}
+
+/*
+ * @implemented
+ */
+DWORD
+WINAPI
+GetTapeParameters(IN HANDLE hDevice,
+ IN DWORD dwOperation,
+ IN LPDWORD lpdwSize,
+ IN LPVOID lpTapeInformation)
+{
+ if (dwOperation == GET_TAPE_MEDIA_INFORMATION)
+ {
+ if (*lpdwSize < sizeof(TAPE_GET_MEDIA_PARAMETERS))
+ {
+ *lpdwSize = sizeof(TAPE_GET_MEDIA_PARAMETERS);
+ return ERROR_MORE_DATA;
+ }
+
+ return BasepDoTapeOperation(hDevice,
+ IOCTL_TAPE_GET_MEDIA_PARAMS,
+ NULL,
+ 0,
+ lpTapeInformation,
+ sizeof(TAPE_GET_MEDIA_PARAMETERS));
+ }
+ else if (dwOperation == GET_TAPE_DRIVE_INFORMATION)
+ {
+ if (*lpdwSize < sizeof(TAPE_GET_DRIVE_PARAMETERS))
+ {
+ *lpdwSize = sizeof(TAPE_GET_DRIVE_PARAMETERS);
+ return ERROR_MORE_DATA;
+ }
+
+ return BasepDoTapeOperation(hDevice,
+ IOCTL_TAPE_GET_DRIVE_PARAMS,
+ NULL,
+ 0,
+ lpTapeInformation,
+ sizeof(TAPE_GET_DRIVE_PARAMETERS));
+ }
+
+ return ERROR_INVALID_FUNCTION;
+}
+
+/*
+ * @implemented
+ */
+DWORD
+WINAPI
+GetTapePosition(IN HANDLE hDevice,
+ IN DWORD dwPositionType,
+ IN LPDWORD lpdwPartition,
+ IN LPDWORD lpdwOffsetLow,
+ IN LPDWORD lpdwOffsetHigh)
+{
+ TAPE_GET_POSITION TapeGetPosition;
+ DWORD Result;
+
+ TapeGetPosition.Type = dwPositionType;
+ Result = BasepDoTapeOperation(hDevice,
+ IOCTL_TAPE_GET_POSITION,
+ &TapeGetPosition,
+ sizeof(TapeGetPosition),
+ &TapeGetPosition,
+ sizeof(TapeGetPosition));
+
+ if (Result)
+ {
+ *lpdwPartition = 0;
+ *lpdwOffsetLow = 0;
+ *lpdwOffsetHigh = 0;
+ }
+ else
+ {
+ *lpdwPartition = TapeGetPosition.Partition;
+ *lpdwOffsetLow = TapeGetPosition.Offset.u.LowPart;
+ *lpdwOffsetHigh = TapeGetPosition.Offset.u.HighPart;
+ }
+
+ return Result;
+}
+
+/*
+ * @implemented
+ */
+DWORD
+WINAPI
+GetTapeStatus(IN HANDLE hDevice)
+{
+ return BasepDoTapeOperation(hDevice,
+ IOCTL_TAPE_GET_STATUS,
+ NULL,
+ 0,
+ NULL,
+ 0);
+}
+
+/*
+ * @implemented
+ */
+DWORD
+WINAPI
+PrepareTape(IN HANDLE hDevice,
+ IN DWORD dwOperation,
+ IN BOOL bImmediate)
+{
+ TAPE_PREPARE TapePrepare;
+
+ TapePrepare.Operation = dwOperation;
+ TapePrepare.Immediate = (BOOLEAN)bImmediate;
+ return BasepDoTapeOperation(hDevice,
+ IOCTL_TAPE_PREPARE,
+ &TapePrepare,
+ sizeof(TapePrepare),
+ NULL,
+ 0);
+}
+
+/*
+ * @implemented
+ */
+DWORD
+WINAPI
+SetTapeParameters(IN HANDLE hDevice,
+ IN DWORD dwOperation,
+ IN LPVOID lpTapeInformation)
+{
+ if (dwOperation == SET_TAPE_MEDIA_INFORMATION)
+ {
+ return BasepDoTapeOperation(hDevice,
+ IOCTL_TAPE_SET_MEDIA_PARAMS,
+ lpTapeInformation,
+ sizeof(TAPE_SET_MEDIA_PARAMETERS),
+ NULL,
+ 0);
+ }
+ else if (dwOperation == SET_TAPE_DRIVE_INFORMATION)
+ {
+ return BasepDoTapeOperation(hDevice,
+ IOCTL_TAPE_SET_DRIVE_PARAMS,
+ lpTapeInformation,
+ sizeof(TAPE_SET_DRIVE_PARAMETERS),
+ NULL,
+ 0);
+ }
+
+ return ERROR_INVALID_FUNCTION;
+}
+
+/*
+ * @implemented
+ */
+DWORD
+WINAPI
+SetTapePosition(IN HANDLE hDevice,
+ IN DWORD dwPositionMethod,
+ IN DWORD dwPartition,
+ IN DWORD dwOffsetLow,
+ IN DWORD dwOffsetHigh,
+ IN BOOL bImmediate)
+{
+ TAPE_SET_POSITION TapeSetPosition;
+
+ TapeSetPosition.Method = dwPositionMethod;
+ TapeSetPosition.Partition = dwPartition;
+ TapeSetPosition.Offset.u.LowPart = dwOffsetLow;
+ TapeSetPosition.Offset.u.HighPart = dwOffsetHigh;
+ TapeSetPosition.Immediate = (BOOLEAN)bImmediate;
+ return BasepDoTapeOperation(hDevice,
+ IOCTL_TAPE_SET_POSITION,
+ &TapeSetPosition,
+ sizeof(TapeSetPosition),
+ NULL,
+ 0);
+}
+
+/*
+ * @implemented
+ */
+DWORD
+WINAPI
+WriteTapemark(IN HANDLE hDevice,
+ IN DWORD dwTapemarkType,
+ IN DWORD dwTapemarkCount,
+ IN BOOL bImmediate)
+{
+ TAPE_WRITE_MARKS TapeWriteMarks;
+
+ TapeWriteMarks.Type = dwTapemarkType;
+ TapeWriteMarks.Count = dwTapemarkCount;
+ TapeWriteMarks.Immediate = (BOOLEAN)bImmediate;
+ return BasepDoTapeOperation(hDevice,
+ IOCTL_TAPE_WRITE_MARKS,
+ &TapeWriteMarks,
+ sizeof(TapeWriteMarks),
+ NULL,
+ 0);
}
/* EOF */
Modified: trunk/reactos/dll/win32/kernel32/client/path.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/path.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/path.c [iso-8859-1] Mon Nov 7 07:41:52 2011
@@ -15,12 +15,13 @@
/* GLOBALS ********************************************************************/
-UNICODE_STRING BaseDllDirectory;
UNICODE_STRING NoDefaultCurrentDirectoryInExePath =
RTL_CONSTANT_STRING(L"NoDefaultCurrentDirectoryInExePath");
-UNICODE_STRING SystemDirectory;
-UNICODE_STRING WindowsDirectory;
-UNICODE_STRING BaseDefaultPathAppend;
-UNICODE_STRING BaseDefaultPath;
+
+UNICODE_STRING BaseWindowsSystemDirectory, BaseWindowsDirectory;
+UNICODE_STRING BaseDefaultPathAppend, BaseDefaultPath, BaseDllDirectory;
+
+PVOID gpTermsrvGetWindowsDirectoryA;
+PVOID gpTermsrvGetWindowsDirectoryW;
/* This is bitmask for each illegal filename character */
/* If someone has time, please feel free to use 0b notation */
@@ -33,6 +34,41 @@
};
/* PRIVATE FUNCTIONS **********************************************************/
+
+BOOLEAN
+WINAPI
+CheckForSameCurdir(IN PUNICODE_STRING DirName)
+{
+ PUNICODE_STRING CurDir;
+ USHORT CurLength;
+ BOOLEAN Result;
+ UNICODE_STRING CurDirCopy;
+
+ CurDir = &NtCurrentPeb()->ProcessParameters->CurrentDirectory.DosPath;
+
+ CurLength = CurDir->Length;
+ if (CurDir->Length <= 6)
+ {
+ if (CurLength != DirName->Length) return FALSE;
+ }
+ else
+ {
+ if ((CurLength - 2) != DirName->Length) return FALSE;
+ }
+
+ RtlAcquirePebLock();
+
+ CurDirCopy = *CurDir;
+ if (CurDirCopy.Length > 6) CurDirCopy.Length -= 2;
+
+ Result = 0;
+
+ if (RtlEqualUnicodeString(&CurDirCopy, DirName, TRUE)) Result = TRUE;
+
+ RtlReleasePebLock();
+
+ return Result;
+}
/*
* Why not use RtlIsNameLegalDOS8Dot3? In fact the actual algorithm body is
@@ -790,7 +826,6 @@
return (name[1] == '.' && (name[2] == '/' || name[2] ==
'\\'));
}
-
/*
* @implemented
*/
@@ -1478,81 +1513,6 @@
/*
* @implemented
- */
-DWORD
-WINAPI
-GetCurrentDirectoryA(IN DWORD nBufferLength,
- IN LPSTR lpBuffer)
-{
- WCHAR BufferW[MAX_PATH];
- DWORD ret;
-
- ret = GetCurrentDirectoryW(MAX_PATH, BufferW);
-
- if (!ret) return 0;
- if (ret > MAX_PATH)
- {
- SetLastError(ERROR_FILENAME_EXCED_RANGE);
- return 0;
- }
-
- return FilenameW2A_FitOrFail(lpBuffer, nBufferLength, BufferW, ret+1);
-}
-
-/*
- * @implemented
- */
-DWORD
-WINAPI
-GetCurrentDirectoryW(IN DWORD nBufferLength,
- IN LPWSTR lpBuffer)
-{
- ULONG Length;
-
- Length = RtlGetCurrentDirectory_U (nBufferLength * sizeof(WCHAR), lpBuffer);
- return (Length / sizeof (WCHAR));
-}
-
-/*
- * @implemented
- */
-BOOL
-WINAPI
-SetCurrentDirectoryA(IN LPCSTR lpPathName)
-{
- PWCHAR PathNameW;
-
- DPRINT("setcurrdir: %s\n",lpPathName);
-
- if (!(PathNameW = FilenameA2W(lpPathName, FALSE))) return FALSE;
-
- return SetCurrentDirectoryW(PathNameW);
-}
-
-/*
- * @implemented
- */
-BOOL
-WINAPI
-SetCurrentDirectoryW(IN LPCWSTR lpPathName)
-{
- UNICODE_STRING UnicodeString;
- NTSTATUS Status;
-
- RtlInitUnicodeString(&UnicodeString, lpPathName);
-
- Status = RtlSetCurrentDirectory_U(&UnicodeString);
- if (!NT_SUCCESS(Status))
- {
- BaseSetLastNTError (Status);
- return FALSE;
- }
-
- return TRUE;
-}
-
-/*
- * @implemented
*
* NOTE: Windows returns a dos/short (8.3) path
*/
@@ -1640,12 +1600,168 @@
/*
* @implemented
*/
+DWORD
+WINAPI
+GetCurrentDirectoryA(IN DWORD nBufferLength,
+ IN LPSTR lpBuffer)
+{
+ ANSI_STRING AnsiString;
+ NTSTATUS Status;
+ PUNICODE_STRING StaticString;
+ ULONG MaxLength;
+
+ StaticString = &NtCurrentTeb()->StaticUnicodeString;
+
+ MaxLength = nBufferLength;
+ if (nBufferLength >= UNICODE_STRING_MAX_BYTES)
+ {
+ MaxLength = UNICODE_STRING_MAX_BYTES - 1;
+ }
+
+ StaticString->Length = RtlGetCurrentDirectory_U(StaticString->MaximumLength,
+ StaticString->Buffer);
+ Status = RtlUnicodeToMultiByteSize(&nBufferLength,
+ StaticString->Buffer,
+ StaticString->Length);
+ if (!NT_SUCCESS(Status))
+ {
+ BaseSetLastNTError(Status);
+ return 0;
+ }
+
+ if (MaxLength <= nBufferLength)
+ {
+ return nBufferLength + 1;
+ }
+
+ AnsiString.Buffer = lpBuffer;
+ AnsiString.MaximumLength = MaxLength;
+ Status = BasepUnicodeStringTo8BitString(&AnsiString, StaticString, FALSE);
+ if (!NT_SUCCESS(Status))
+ {
+ BaseSetLastNTError(Status);
+ return 0;
+ }
+
+ return AnsiString.Length;
+}
+
+/*
+ * @implemented
+ */
+DWORD
+WINAPI
+GetCurrentDirectoryW(IN DWORD nBufferLength,
+ IN LPWSTR lpBuffer)
+{
+ return RtlGetCurrentDirectory_U(nBufferLength * sizeof(WCHAR), lpBuffer) /
sizeof(WCHAR);
+}
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
+SetCurrentDirectoryA(IN LPCSTR lpPathName)
+{
+ PUNICODE_STRING DirName;
+ NTSTATUS Status;
+
+ if (!lpPathName)
+ {
+ BaseSetLastNTError(STATUS_INVALID_PARAMETER);
+ return FALSE;
+ }
+
+ DirName = Basep8BitStringToStaticUnicodeString(lpPathName);
+ if (!DirName) return FALSE;
+
+ if (CheckForSameCurdir(DirName)) return FALSE;
+
+ Status = RtlSetCurrentDirectory_U(DirName);
+ if (NT_SUCCESS(Status)) return TRUE;
+
+ if ((*DirName->Buffer != L'"') || (DirName->Length <= 2))
+ {
+ BaseSetLastNTError(Status);
+ return 0;
+ }
+
+ DirName = Basep8BitStringToStaticUnicodeString(lpPathName + 1);
+ if (!DirName) return FALSE;
+
+ Status = RtlSetCurrentDirectory_U(DirName);
+ if (!NT_SUCCESS(Status))
+ {
+ BaseSetLastNTError(Status);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
+SetCurrentDirectoryW(IN LPCWSTR lpPathName)
+{
+ NTSTATUS Status;
+ UNICODE_STRING UnicodeString;
+
+ if (!lpPathName)
+ {
+ BaseSetLastNTError(STATUS_INVALID_PARAMETER);
+ return FALSE;
+ }
+
+ Status = RtlInitUnicodeStringEx(&UnicodeString, lpPathName);
+ if (NT_SUCCESS(Status))
+ {
+ if (!CheckForSameCurdir(&UnicodeString))
+ {
+ Status = RtlSetCurrentDirectory_U(&UnicodeString);
+ }
+ }
+
+ if (!NT_SUCCESS(Status))
+ {
+ BaseSetLastNTError(Status);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/*
+ * @implemented
+ */
UINT
WINAPI
GetSystemDirectoryA(IN LPSTR lpBuffer,
IN UINT uSize)
{
- return FilenameU2A_FitOrFail(lpBuffer, uSize, &SystemDirectory);
+ ANSI_STRING AnsiString;
+ NTSTATUS Status;
+ ULONG AnsiLength;
+
+ /* Get the correct size of the Unicode Base directory */
+ Status = RtlUnicodeToMultiByteSize(&AnsiLength,
+ BaseWindowsSystemDirectory.Buffer,
+ BaseWindowsSystemDirectory.MaximumLength);
+ if (!NT_SUCCESS(Status)) return 0;
+
+ if (uSize < AnsiLength) return AnsiLength;
+
+ RtlInitEmptyAnsiString(&AnsiString, lpBuffer, uSize);
+
+ Status = BasepUnicodeStringTo8BitString(&AnsiString,
+ &BaseWindowsSystemDirectory,
+ FALSE);
+ if (!NT_SUCCESS(Status)) return 0;
+
+ return AnsiString.Length;
}
/*
@@ -1656,21 +1772,20 @@
GetSystemDirectoryW(IN LPWSTR lpBuffer,
IN UINT uSize)
{
- ULONG Length;
-
- Length = SystemDirectory.Length / sizeof (WCHAR);
-
- if (lpBuffer == NULL) return Length + 1;
-
- if (uSize > Length)
- {
- memmove(lpBuffer, SystemDirectory.Buffer, SystemDirectory.Length);
- lpBuffer[Length] = 0;
-
- return Length; //good: ret chars excl. nullchar
- }
-
- return Length+1; //bad: ret space needed incl. nullchar
+ ULONG ReturnLength;
+
+ ReturnLength = BaseWindowsSystemDirectory.MaximumLength;
+ if ((uSize * sizeof(WCHAR)) >= ReturnLength)
+ {
+ RtlCopyMemory(lpBuffer,
+ BaseWindowsSystemDirectory.Buffer,
+ BaseWindowsSystemDirectory.Length);
+ lpBuffer[BaseWindowsSystemDirectory.Length / sizeof(WCHAR)] = ANSI_NULL;
+
+ ReturnLength = BaseWindowsSystemDirectory.Length;
+ }
+
+ return ReturnLength / sizeof(WCHAR);
}
/*
@@ -1681,7 +1796,11 @@
GetWindowsDirectoryA(IN LPSTR lpBuffer,
IN UINT uSize)
{
- return FilenameU2A_FitOrFail(lpBuffer, uSize, &WindowsDirectory);
+ /* Is this a TS installation? */
+ if (gpTermsrvGetWindowsDirectoryA) UNIMPLEMENTED;
+
+ /* Otherwise, call the System API */
+ return GetSystemWindowsDirectoryA(lpBuffer, uSize);
}
/*
@@ -1692,21 +1811,11 @@
GetWindowsDirectoryW(IN LPWSTR lpBuffer,
IN UINT uSize)
{
- ULONG Length;
-
- Length = WindowsDirectory.Length / sizeof (WCHAR);
-
- if (lpBuffer == NULL) return Length + 1;
-
- if (uSize > Length)
- {
- memmove(lpBuffer, WindowsDirectory.Buffer, WindowsDirectory.Length);
- lpBuffer[Length] = 0;
-
- return Length; //good: ret chars excl. nullchar
- }
-
- return Length+1; //bad: ret space needed incl. nullchar
+ /* Is this a TS installation? */
+ if (gpTermsrvGetWindowsDirectoryW) UNIMPLEMENTED;
+
+ /* Otherwise, call the System API */
+ return GetSystemWindowsDirectoryW(lpBuffer, uSize);
}
/*
@@ -1717,7 +1826,26 @@
GetSystemWindowsDirectoryA(IN LPSTR lpBuffer,
IN UINT uSize)
{
- return GetWindowsDirectoryA(lpBuffer, uSize);
+ ANSI_STRING AnsiString;
+ NTSTATUS Status;
+ ULONG AnsiLength;
+
+ /* Get the correct size of the Unicode Base directory */
+ Status = RtlUnicodeToMultiByteSize(&AnsiLength,
+ BaseWindowsDirectory.Buffer,
+ BaseWindowsDirectory.MaximumLength);
+ if (!NT_SUCCESS(Status)) return 0;
+
+ if (uSize < AnsiLength) return AnsiLength;
+
+ RtlInitEmptyAnsiString(&AnsiString, lpBuffer, uSize);
+
+ Status = BasepUnicodeStringTo8BitString(&AnsiString,
+ &BaseWindowsDirectory,
+ FALSE);
+ if (!NT_SUCCESS(Status)) return 0;
+
+ return AnsiString.Length;
}
/*
@@ -1728,7 +1856,20 @@
GetSystemWindowsDirectoryW(IN LPWSTR lpBuffer,
IN UINT uSize)
{
- return GetWindowsDirectoryW(lpBuffer, uSize);
+ ULONG ReturnLength;
+
+ ReturnLength = BaseWindowsDirectory.MaximumLength;
+ if ((uSize * sizeof(WCHAR)) >= ReturnLength)
+ {
+ RtlCopyMemory(lpBuffer,
+ BaseWindowsDirectory.Buffer,
+ BaseWindowsDirectory.Length);
+ lpBuffer[BaseWindowsDirectory.Length / sizeof(WCHAR)] = ANSI_NULL;
+
+ ReturnLength = BaseWindowsDirectory.Length;
+ }
+
+ return ReturnLength / sizeof(WCHAR);
}
/*
Modified: trunk/reactos/dll/win32/kernel32/client/synch.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/synch.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/synch.c [iso-8859-1] Mon Nov 7 07:41:52 2011
@@ -12,7 +12,67 @@
#define NDEBUG
#include <debug.h>
+#undef InterlockedIncrement
+#undef InterlockedDecrement
+#undef InterlockedExchange
+#undef InterlockedExchangeAdd
+#undef InterlockedCompareExchange
+
/* FUNCTIONS *****************************************************************/
+
+/*
+ * @implemented
+ */
+LONG
+WINAPI
+InterlockedIncrement(IN OUT LONG volatile *lpAddend)
+{
+ return _InterlockedIncrement(lpAddend);
+}
+
+/*
+ * @implemented
+ */
+LONG
+WINAPI
+InterlockedDecrement(IN OUT LONG volatile *lpAddend)
+{
+ return _InterlockedDecrement(lpAddend);
+}
+
+/*
+ * @implemented
+ */
+LONG
+WINAPI
+InterlockedExchange(IN OUT LONG volatile *Target,
+ IN LONG Value)
+{
+ return _InterlockedExchange(Target, Value);
+}
+
+/*
+ * @implemented
+ */
+LONG
+WINAPI
+InterlockedExchangeAdd(IN OUT LONG volatile *Addend,
+ IN LONG Value)
+{
+ return _InterlockedExchangeAdd(Addend, Value);
+}
+
+/*
+ * @implemented
+ */
+LONG
+WINAPI
+InterlockedCompareExchange(IN OUT LONG volatile *Destination,
+ IN LONG Exchange,
+ IN LONG Comperand)
+{
+ return _InterlockedCompareExchange(Destination, Exchange, Comperand);
+}
/*
* @implemented
Modified: trunk/reactos/dll/win32/kernel32/include/kernel32.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/include…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/include/kernel32.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/include/kernel32.h [iso-8859-1] Mon Nov 7 07:41:52
2011
@@ -258,6 +258,7 @@
extern PRTL_COUNT_STRING BasepUnicodeStringTo8BitSize;
extern PRTL_COUNT_STRINGA Basep8BitStringToUnicodeSize;
+extern UNICODE_STRING BaseWindowsDirectory, BaseWindowsSystemDirectory;
extern HANDLE BaseNamedObjectDirectory;
HANDLE