--- /dev/null
+/* $Id$\r
+ *\r
+ * PROJECT: ReactOS Operating System / POSIX Environment Subsystem\r
+ *\r
+ * --------------------------------------------------------------------\r
+ *\r
+ * This software is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License as\r
+ * published by the Free Software Foundation; either version 2 of the\r
+ * License, or (at your option) any later version.\r
+ *\r
+ * This software is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this software; see the file COPYING. If not, write\r
+ * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,\r
+ * MA 02139, USA. \r
+ *\r
+ * --------------------------------------------------------------------\r
+ */\r
+#include <windows.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+\r
+#define NTOS_MODE_USER\r
+#include <ntos.h>\r
+#include <sm/helper.h>\r
+\r
+#define RETRY_COUNT 3\r
+\r
+/**********************************************************************\r
+ * PsxCheckSubSystem/1\r
+ */\r
+NTSTATUS STDCALL\r
+PsxCheckSubSystem (LPCSTR argv0)\r
+{\r
+ NTSTATUS Status = STATUS_SUCCESS;\r
+ UNICODE_STRING DirectoryName = {0, 0, NULL};\r
+ OBJECT_ATTRIBUTES DirectoryAttributes = {0};\r
+ HANDLE hDir = (HANDLE) 0;\r
+\r
+ RtlInitUnicodeString (& DirectoryName, L"\\POSIX");\r
+ InitializeObjectAttributes (& DirectoryAttributes,\r
+ & DirectoryName,\r
+ 0,0,0);\r
+ Status = NtOpenDirectoryObject (& hDir,\r
+ DIRECTORY_TRAVERSE,\r
+ & DirectoryAttributes);\r
+ if(NT_SUCCESS(Status))\r
+ {\r
+ NtClose (hDir);\r
+ }\r
+\r
+ return Status;\r
+}\r
+\r
+/**********************************************************************\r
+ * PsxBootstrap/1\r
+ */\r
+NTSTATUS STDCALL\r
+PsxBootstrap (LPCSTR argv0)\r
+{\r
+ NTSTATUS Status = STATUS_SUCCESS;\r
+ UNICODE_STRING Program = {0, 0, NULL};\r
+ HANDLE SmApiPort = (HANDLE) 0;\r
+\r
+\r
+ printf("Connecting to the SM: ");\r
+ Status = SmConnectApiPort (NULL,\r
+ (HANDLE) 0,\r
+ IMAGE_SUBSYSTEM_UNKNOWN,\r
+ & SmApiPort);\r
+ if(!NT_SUCCESS(Status))\r
+ {\r
+ fprintf(stderr,"\n%s: SmConnectApiPort failed with 0x%08lx\n",\r
+ argv0, Status);\r
+ return Status;\r
+ }\r
+ RtlInitUnicodeString (& Program, L"POSIX");\r
+ Status = SmExecuteProgram (SmApiPort, & Program);\r
+ if(STATUS_SUCCESS != Status)\r
+ {\r
+ fprintf(stderr, "%s: SmExecuteProgram = %08lx\n", argv0, Status);\r
+ }\r
+ NtClose (SmApiPort);\r
+ return Status;\r
+}\r
+\r
+/**********************************************************************\r
+ *\r
+ * ENTRY POINT PUBLIC\r
+ *\r
+ *********************************************************************/\r
+int main (int argc, char * argv [])\r
+{\r
+ NTSTATUS Status = STATUS_SUCCESS;\r
+ INT RetryCount = RETRY_COUNT;\r
+\r
+ while(RetryCount > 0)\r
+ {\r
+ Status = PsxCheckSubSystem (argv[0]);\r
+ if(STATUS_SUCCESS == Status)\r
+ {\r
+ if (RETRY_COUNT == RetryCount)\r
+ {\r
+ fprintf(stderr,"POSIX already booted.\n");\r
+ }else{\r
+ fprintf(stderr,"POSIX booted.\n");\r
+ }\r
+ break;\r
+ }else{\r
+ Status = PsxBootstrap (argv[0]);\r
+ }\r
+ -- RetryCount;\r
+ }\r
+ return NT_SUCCESS(Status) ? EXIT_SUCCESS : EXIT_FAILURE;\r
+}\r
+/* EOF */\r