Author: hbelusca
Date: Wed Jan 16 00:16:06 2013
New Revision: 58182
URL:
http://svn.reactos.org/svn/reactos?rev=58182&view=rev
Log:
[KERNEL32]
Fix support for CONIN$ and CONOUT$, and add support for CON special file
(now, writing to C:\CON or C:\somepath\CONIN$ or C:\anotherpath\CONOUT$ works).
Modified:
branches/ros-csrss/dll/win32/kernel32/client/console/console.c
branches/ros-csrss/dll/win32/kernel32/client/file/create.c
branches/ros-csrss/dll/win32/kernel32/include/kernel32.h
branches/ros-csrss/include/reactos/subsys/win/console.h
Modified: branches/ros-csrss/dll/win32/kernel32/client/console/console.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/dll/win32/kernel32/cl…
==============================================================================
--- branches/ros-csrss/dll/win32/kernel32/client/console/console.c [iso-8859-1]
(original)
+++ branches/ros-csrss/dll/win32/kernel32/client/console/console.c [iso-8859-1] Wed Jan 16
00:16:06 2013
@@ -23,6 +23,11 @@
extern BOOL WINAPI IsDebuggerPresent(VOID);
/* GLOBALS ********************************************************************/
+
+/* Console reserved "file" names */
+static LPCWSTR BaseConFileName = CONSOLE_FILE_NAME;
+static LPCWSTR BaseConInputFileName = CONSOLE_INPUT_FILE_NAME;
+static LPCWSTR BaseConOutputFileName = CONSOLE_OUTPUT_FILE_NAME;
PHANDLER_ROUTINE InitialHandler[1];
PHANDLER_ROUTINE* CtrlHandlers;
@@ -189,6 +194,51 @@
/* FUNCTIONS ******************************************************************/
+LPCWSTR
+IntCheckForConsoleFileName(IN LPCWSTR pszName,
+ IN DWORD dwDesiredAccess)
+{
+ LPCWSTR ConsoleName = pszName;
+ ULONG DeviceNameInfo;
+
+ /*
+ * Check whether we deal with a DOS device, and if so,
+ * strip the path till the file name.
+ * Therefore, things like \\.\CON or C:\some_path\CONIN$
+ * are transformed into CON or CONIN$, for example.
+ */
+ DeviceNameInfo = RtlIsDosDeviceName_U(pszName);
+ if (DeviceNameInfo != 0)
+ {
+ ConsoleName = (LPCWSTR)((ULONG_PTR)ConsoleName + (ULONG_PTR)((DeviceNameInfo
>> 16) & 0xFFFF));
+ }
+
+ /* Return a standard console "file" name according to what we passed in
parameters */
+ if (_wcsicmp(ConsoleName, BaseConInputFileName) == 0)
+ {
+ return BaseConInputFileName;
+ }
+ else if (_wcsicmp(ConsoleName, BaseConOutputFileName) == 0)
+ {
+ return BaseConOutputFileName;
+ }
+ else if (_wcsicmp(ConsoleName, BaseConFileName) == 0)
+ {
+ if ((dwDesiredAccess & (GENERIC_READ | GENERIC_WRITE)) == GENERIC_READ)
+ {
+ return BaseConInputFileName;
+ }
+ else if ((dwDesiredAccess & (GENERIC_READ | GENERIC_WRITE)) ==
GENERIC_WRITE)
+ {
+ return BaseConOutputFileName;
+ }
+ }
+
+ /* If we are there, that means that either the file name or the desired access are
wrong */
+ return NULL;
+}
+
+
/*
* @unimplemented (Undocumented)
*/
@@ -411,11 +461,11 @@
PCONSOLE_OPENCONSOLE OpenConsoleRequest = &ApiMessage.Data.OpenConsoleRequest;
CONSOLE_HANDLE_TYPE HandleType;
- if (wsName && 0 == _wcsicmp(wsName, L"CONIN$"))
+ if (wsName && 0 == _wcsicmp(wsName, BaseConInputFileName))
{
HandleType = HANDLE_INPUT;
}
- else if (wsName && 0 == _wcsicmp(wsName, L"CONOUT$"))
+ else if (wsName && 0 == _wcsicmp(wsName, BaseConOutputFileName))
{
HandleType = HANDLE_OUTPUT;
}
@@ -425,13 +475,8 @@
return INVALID_HANDLE_VALUE;
}
- if (dwDesiredAccess & ~(GENERIC_READ | GENERIC_WRITE))
- {
- SetLastError(ERROR_INVALID_PARAMETER);
- return INVALID_HANDLE_VALUE;
- }
-
- if (dwShareMode & ~(FILE_SHARE_READ | FILE_SHARE_WRITE))
+ if ( (dwDesiredAccess & ~(GENERIC_READ | GENERIC_WRITE)) ||
+ (dwShareMode & ~(FILE_SHARE_READ | FILE_SHARE_WRITE)) )
{
SetLastError(ERROR_INVALID_PARAMETER);
return INVALID_HANDLE_VALUE;
Modified: branches/ros-csrss/dll/win32/kernel32/client/file/create.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/dll/win32/kernel32/cl…
==============================================================================
--- branches/ros-csrss/dll/win32/kernel32/client/file/create.c [iso-8859-1] (original)
+++ branches/ros-csrss/dll/win32/kernel32/client/file/create.c [iso-8859-1] Wed Jan 16
00:16:06 2013
@@ -99,6 +99,7 @@
OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK IoStatusBlock;
UNICODE_STRING NtPathU;
+ LPCWSTR pszConsoleFileName;
HANDLE FileHandle;
NTSTATUS Status;
ULONG FileAttributes, Flags = 0;
@@ -142,10 +143,10 @@
}
/* check for console input/output */
- if (0 == _wcsicmp(L"CONOUT$", lpFileName)
- || 0 == _wcsicmp(L"CONIN$", lpFileName))
- {
- return OpenConsoleW(lpFileName,
+ pszConsoleFileName = IntCheckForConsoleFileName(lpFileName, dwDesiredAccess);
+ if (pszConsoleFileName)
+ {
+ return OpenConsoleW(pszConsoleFileName,
dwDesiredAccess,
lpSecurityAttributes ? lpSecurityAttributes->bInheritHandle
: FALSE,
FILE_SHARE_READ | FILE_SHARE_WRITE);
Modified: branches/ros-csrss/dll/win32/kernel32/include/kernel32.h
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/dll/win32/kernel32/in…
==============================================================================
--- branches/ros-csrss/dll/win32/kernel32/include/kernel32.h [iso-8859-1] (original)
+++ branches/ros-csrss/dll/win32/kernel32/include/kernel32.h [iso-8859-1] Wed Jan 16
00:16:06 2013
@@ -106,19 +106,20 @@
typedef struct _CODEPAGE_ENTRY
{
- LIST_ENTRY Entry;
- UINT CodePage;
- HANDLE SectionHandle;
- PBYTE SectionMapping;
- CPTABLEINFO CodePageTable;
+ LIST_ENTRY Entry;
+ UINT CodePage;
+ HANDLE SectionHandle;
+ PBYTE SectionMapping;
+ CPTABLEINFO CodePageTable;
} CODEPAGE_ENTRY, *PCODEPAGE_ENTRY;
-typedef struct tagLOADPARMS32 {
- LPSTR lpEnvAddress;
- LPSTR lpCmdLine;
- WORD wMagicValue;
- WORD wCmdShow;
- DWORD dwReserved;
+typedef struct tagLOADPARMS32
+{
+ LPSTR lpEnvAddress;
+ LPSTR lpCmdLine;
+ WORD wMagicValue;
+ WORD wCmdShow;
+ DWORD dwReserved;
} LOADPARMS32;
typedef enum _BASE_SEARCH_PATH_TYPE
@@ -194,6 +195,10 @@
HANDLE WINAPI
GetConsoleInputWaitHandle(VOID);
+
+LPCWSTR
+IntCheckForConsoleFileName(IN LPCWSTR pszName,
+ IN DWORD dwDesiredAccess);
HANDLE WINAPI OpenConsoleW(LPCWSTR wsName,
DWORD dwDesiredAccess,
Modified: branches/ros-csrss/include/reactos/subsys/win/console.h
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/include/reactos/subsy…
==============================================================================
--- branches/ros-csrss/include/reactos/subsys/win/console.h [iso-8859-1] (original)
+++ branches/ros-csrss/include/reactos/subsys/win/console.h [iso-8859-1] Wed Jan 16
00:16:06 2013
@@ -14,6 +14,11 @@
#define IsConsoleHandle(h) \
(((ULONG_PTR)(h) & 0x10000003) == 0x3)
+/* Console reserved "file" names */
+#define CONSOLE_FILE_NAME L"CON"
+#define CONSOLE_INPUT_FILE_NAME L"CONIN$"
+#define CONSOLE_OUTPUT_FILE_NAME L"CONOUT$"
+
#endif // _CONSOLE_H
/* EOF */