Win32 utility to bootstrap the PSX subsystem (it is an optional subsystem, therefore...
authorEmanuele Aliberti <ea@iol.it>
Tue, 8 Mar 2005 14:28:04 +0000 (14:28 +0000)
committerEmanuele Aliberti <ea@iol.it>
Tue, 8 Mar 2005 14:28:04 +0000 (14:28 +0000)
svn path=/trunk/; revision=13875

posix/apps/bootpsx/bootpsx.c [new file with mode: 0644]
posix/apps/bootpsx/bootpsx.rc [new file with mode: 0644]
posix/apps/bootpsx/makefile [new file with mode: 0644]

diff --git a/posix/apps/bootpsx/bootpsx.c b/posix/apps/bootpsx/bootpsx.c
new file mode 100644 (file)
index 0000000..20515a2
--- /dev/null
@@ -0,0 +1,121 @@
+/* $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
diff --git a/posix/apps/bootpsx/bootpsx.rc b/posix/apps/bootpsx/bootpsx.rc
new file mode 100644 (file)
index 0000000..7ad1217
--- /dev/null
@@ -0,0 +1,4 @@
+#define REACTOS_STR_FILE_DESCRIPTION   "W32 Utility to boot the POSIX Subsystem\0"\r
+#define REACTOS_STR_INTERNAL_NAME      "bootpsx\0"\r
+#define REACTOS_STR_ORIGINAL_FILENAME  "bootpsx.exe\0"\r
+#include <reactos/version.rc>\r
diff --git a/posix/apps/bootpsx/makefile b/posix/apps/bootpsx/makefile
new file mode 100644 (file)
index 0000000..a83343f
--- /dev/null
@@ -0,0 +1,21 @@
+# $Id: Makefile 13504 2005-02-12 14:33:41Z ea $\r
+\r
+PATH_TO_TOP = ../../../reactos\r
+\r
+TARGET_TYPE = program\r
+\r
+TARGET_APPTYPE = console\r
+\r
+TARGET_NAME = bootpsx\r
+\r
+TARGET_SDKLIBS = ntdll.a smdll.a kernel32.a\r
+\r
+TARGET_OBJECTS = $(TARGET_NAME).o \r
+\r
+TARGET_CFLAGS = -Wall -Werror\r
+\r
+include $(PATH_TO_TOP)/rules.mak\r
+\r
+include $(TOOLS_PATH)/helper.mk\r
+\r
+# EOF\r