From 683ed8c5a17755f7707e4b3a439db2f2fd049b99 Mon Sep 17 00:00:00 2001 From: Rex Jolliff Date: Tue, 8 Dec 1998 04:31:04 +0000 Subject: [PATCH] Added ZwQueryFileInformation svn path=/trunk/; revision=113 --- reactos/apps/utils/cmd/cmd.c | 158 -------------------- reactos/apps/utils/cmd/makefile | 12 -- reactos/include/ddk/iodef.h | 46 ------ reactos/include/ddk/types.h | 48 +++++- reactos/include/ddk/zwtypes.h | 19 --- reactos/ntoskrnl/io/file.c | 252 +++++++++++++++++++++----------- reactos/ntoskrnl/ldr/loader.c | 113 ++++++++++++-- reactos/rules.mak | 5 +- rosapps/cmd/cmd.c | 158 -------------------- rosapps/cmd/makefile | 12 -- 10 files changed, 311 insertions(+), 512 deletions(-) delete mode 100644 reactos/apps/utils/cmd/cmd.c delete mode 100644 reactos/apps/utils/cmd/makefile delete mode 100644 rosapps/cmd/cmd.c delete mode 100644 rosapps/cmd/makefile diff --git a/reactos/apps/utils/cmd/cmd.c b/reactos/apps/utils/cmd/cmd.c deleted file mode 100644 index 22211f73308..00000000000 --- a/reactos/apps/utils/cmd/cmd.c +++ /dev/null @@ -1,158 +0,0 @@ -#include -#include - -HANDLE stdin; -HANDLE stdout; - - -void Console_puts(char* str) -{ - ULONG nchar; - - WriteConsole(stdout, - str, - strlen(str), - &nchar, - NULL); -} - -void Console_printf(char* fmt, ...) -{ - char buffer[255]; - va_list vargs; - - va_start(vargs,fmt); - vsprintf(buffer,fmt,vargs); - Console_puts(buffer); - va_end(vargs); -} - -void Console_getline(PCH Prompt, PCH Output, DWORD OutputLength) -{ - char ch; - DWORD nbytes; - - Console_puts(Prompt); - - ReadConsole(stdin, - Output, - OutputLength, - &nbytes, - NULL); - Output[nbytes-2]=0; -} - -void func_cd(char* s) -{ - Console_printf("Changing directory to %s\n",s); - if (!SetCurrentDirectory(s)) - { - Console_puts("Failed to change to directory\n"); - } -} - -void func_dir(char* s) -{ - HANDLE shandle; - WIN32_FIND_DATA FindData; - - shandle = FindFirstFile("*.*",&FindData); - - if (shandle==INVALID_HANDLE_VALUE) - { - return; - } - do - { - Console_printf("Scanning %s\n",FindData.cFileName); - } while(FindNextFile(shandle,&FindData)); -} - -int is_builtin(char* name, char* args) -{ - if (strcmp(name,"dir")==0) - { - func_dir(args); - return(1); - } - if (strcmp(name,"cd")==0) - { - func_cd(args); - return(1); - } - return(0); -} - -int process_command(char* str) -{ - char* name; - char* args; - PROCESS_INFORMATION pi; - STARTUPINFO si; - char process_arg[255]; - - if (strcmp(str,"exit")==0) - { - return(1); - } - - name = strtok(str," \t"); - args = strtok(NULL,""); - - if (is_builtin(name,args)) - { - return(0); - } - memset(&si,0,sizeof(STARTUPINFO)); - si.cb=sizeof(STARTUPINFO); - si.lpTitle=strdup(name); - - strcpy(process_arg,name); - strcat(process_arg," "); - if(args!=NULL) - { - strcat(process_arg,args); - } - Console_printf("name '%s' process_arg '%s'\n",name,process_arg); - if (!CreateProcess(NULL,process_arg,NULL,NULL,FALSE, - CREATE_NEW_CONSOLE, - NULL,NULL,&si,&pi)) - { - Console_printf("Failed to execute process\n"); - } - return(0); -} - -void build_prompt(char* prompt) -{ - int len; - - len = GetCurrentDirectory(255,prompt); - strcat(prompt,">"); -} - -void command_loop() -{ - char line[255]; - char prompt[255]; - int do_exit = 0; - - while (!do_exit) - { - build_prompt(prompt); - Console_getline(prompt,line,255); - Console_printf("Processing command '%s'\n",line); - do_exit = process_command(line); - } -} - -int STDCALL WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow) -{ - AllocConsole(); - stdin = GetStdHandle(STD_INPUT_HANDLE); - stdout = GetStdHandle(STD_OUTPUT_HANDLE); - - command_loop(); - - return 0; -} diff --git a/reactos/apps/utils/cmd/makefile b/reactos/apps/utils/cmd/makefile deleted file mode 100644 index 7e36f733496..00000000000 --- a/reactos/apps/utils/cmd/makefile +++ /dev/null @@ -1,12 +0,0 @@ -all: cmd.bin - -OBJECTS = ../common/crt0.o cmd.o - -LIBS = ../../lib/mingw32/mingw32.a ../../lib/crtdll/crtdll.a \ - ../../lib/kernel32/kernel32.a ../../lib/ntdll/ntdll.a - -cmd.bin: $(OBJECTS) - $(LD) -Ttext 0x10000 $(OBJECTS) $(LIBS) -o cmd.exe - $(OBJCOPY) -O binary cmd.exe cmd.bin - -include ../../rules.mak diff --git a/reactos/include/ddk/iodef.h b/reactos/include/ddk/iodef.h index 4dbe70c0078..bbff55a56a4 100644 --- a/reactos/include/ddk/iodef.h +++ b/reactos/include/ddk/iodef.h @@ -263,52 +263,6 @@ enum #define FILE_VALID_MAILSLOT_OPTION_FLAGS 0x00000032 #define FILE_VALID_SET_FLAGS 0x00001036 -/* - * file information - */ -#define FileDirectoryInformation 1 -#define FileFullDirectoryInformation 2 -#define FileBothDirectoryInformation 3 -#define FileBasicInformation 4 -#define FileStandardInformation 5 -#define FileInternalInformation 6 -#define FileEaInformation 7 -#define FileAccessInformation 8 -#define FileNameInformation 9 -#define FileRenameInformation 10 -#define FileLinkInformation 11 -#define FileNamesInformation 12 -#define FileDispositionInformation 13 -#define FilePositionInformation 14 -#define FileFullEaInformation 15 -#define FileModeInformation 16 -#define FileAlignmentInformation 17 -#define FileAllInformation 18 -#define FileAllocationInformation 19 -#define FileEndOfFileInformation 20 -#define FileAlternateNameInformation 21 -#define FileStreamInformation 22 -#define FilePipeInformation 23 -#define FilePipeLocalInformation 24 -#define FilePipeRemoteInformation 25 -#define FileMailslotQueryInformation 26 -#define FileMailslotSetInformation 27 -#define FileCompressionInformation 28 -#define FileCopyOnWriteInformation 29 -#define FileCompletionInformation 30 -#define FileMoveClusterInformation 31 -#define FileOleClassIdInformation 32 -#define FileOleStateBitsInformation 33 -#define FileNetworkOpenInformation 34 -#define FileObjectIdInformation 35 -#define FileOleAllInformation 36 -#define FileOleDirectoryInformation 37 -#define FileContentIndexInformation 38 -#define FileInheritContentIndexInformation 39 -#define FileOleInformation 40 -#define FileMaximumInformation 41 - - typedef ULONG FS_INFORMATION_CLASS; diff --git a/reactos/include/ddk/types.h b/reactos/include/ddk/types.h index d9b4161bd6c..4074e57c5ee 100644 --- a/reactos/include/ddk/types.h +++ b/reactos/include/ddk/types.h @@ -55,8 +55,54 @@ typedef ULONG POOL_TYPE; typedef ULONG TIMER_TYPE; typedef ULONG MM_SYSTEM_SIZE; typedef ULONG LOCK_OPERATION; + +/* File information for IRP_MJ_QUERY_INFORMATION (and SET) */ +typedef enum _FILE_INFORMATION_CLASS +{ + FileDirectoryInformation = 1, + FileFullDirectoryInformation, + FileBothDirectoryInformation, + FileBasicInformation, + FileStandardInformation, + FileInternalInformation, + FileEaInformation, + FileAccessInformation, + FileNameInformation, + FileRenameInformation, + FileLinkInformation, + FileNamesInformation, + FileDispositionInformation, + FilePositionInformation, + FileFullEaInformation, + FileModeInformation, + FileAlignmentInformation, + FileAllInformation, + FileAllocationInformation, + FileEndOfFileInformation, + FileAlternateNameInformation, + FileStreamInformation, + FilePipeInformation, + FilePipeLocalInformation, + FilePipeRemoteInformation, + FileMailslotQueryInformation, + FileMailslotSetInformation, + FileCompressionInformation, + FileCopyOnWriteInformation, + FileCompletionInformation, + FileMoveClusterInformation, + FileOleClassIdInformation, + FileOleStateBitsInformation, + FileNetworkOpenInformation, + FileObjectIdInformation, + FileOleAllInformation, + FileOleDirectoryInformation, + FileContentIndexInformation, + FileInheritContentIndexInformation, + FileOleInformation, + FileMaximumInformation, +} FILE_INFORMATION_CLASS; + typedef ULONG KEY_INFORMATION_CLASS; -typedef ULONG FILE_INFORMATION_CLASS; typedef ULONG KEY_VALUE_INFORMATION_CLASS; typedef LARGE_INTEGER PHYSICAL_ADDRESS; typedef PHYSICAL_ADDRESS* PPHYSICAL_ADDRESS; diff --git a/reactos/include/ddk/zwtypes.h b/reactos/include/ddk/zwtypes.h index eec3f0d0e5d..07ee1809b1a 100644 --- a/reactos/include/ddk/zwtypes.h +++ b/reactos/include/ddk/zwtypes.h @@ -25,9 +25,6 @@ #define FILE_OVERWRITE_IF 0x0005 #define FILE_MAXIMUM_DISPOSITION 0x0005 - - - //process query / set information class #define ProcessBasicInformation 0 @@ -72,15 +69,12 @@ #define ThreadPriorityBoost 14 #define MaxThreadInfoClass 15 - - // key query information class #define KeyBasicInformation 0 #define KeyNodeInformation 1 #define KeyFullInformation 2 - // key set information class #define KeyWriteTimeInformation 0 @@ -107,16 +101,12 @@ #define EventBasicInformation 0 - // system information #define SystemPerformanceInformation 5 #define SystemCacheInformation 21 #define SystemTimeAdjustmentInformation 28 - - - // shutdown action typedef enum SHUTDOWN_ACTION_TAG { @@ -125,26 +115,21 @@ typedef enum SHUTDOWN_ACTION_TAG { ShutdownPowerOff } SHUTDOWN_ACTION; - - // wait type #define WaitAll 0 #define WaitAny 1 - // key restore flags #define REG_WHOLE_HIVE_VOLATILE 1 #define REG_REFRESH_HIVE 2 - // object type access rights #define OBJECT_TYPE_CREATE 0x0001 #define OBJECT_TYPE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1) - // directory access rights #define DIRECTORY_QUERY 0x0001 @@ -315,10 +300,6 @@ typedef struct _SYSTEM_CACHE_INFORMATION { ULONG Unused[4]; } SYSTEM_CACHE_INFORMATION; - - -// file information - typedef struct _FILE_BASIC_INFORMATION { TIME CreationTime; diff --git a/reactos/ntoskrnl/io/file.c b/reactos/ntoskrnl/io/file.c index 1e659dbf676..2c399ec1137 100644 --- a/reactos/ntoskrnl/io/file.c +++ b/reactos/ntoskrnl/io/file.c @@ -16,117 +16,191 @@ /* FUNCTIONS *****************************************************************/ -NTSTATUS ZwQueryInformationFile(HANDLE FileHandle, - PIO_STATUS_BLOCK IoStatusBlock, - PVOID FileInformation, - ULONG Length, - FILE_INFORMATION_CLASS FileInformationClass) +NTSTATUS +NtQueryInformationFile(HANDLE FileHandle, + PIO_STATUS_BLOCK IoStatusBlock, + PVOID FileInformation, + ULONG Length, + FILE_INFORMATION_CLASS FileInformationClass) { - UNIMPLEMENTED; -} - -NTSTATUS NtQueryInformationFile(HANDLE FileHandle, - PIO_STATUS_BLOCK IoStatusBlock, - PVOID FileInformation, - ULONG Length, - FILE_INFORMATION_CLASS FileInformationClass) -{ - UNIMPLEMENTED; -} - -NTSTATUS ZwSetInformationFile(HANDLE FileHandle, - PIO_STATUS_BLOCK IoStatusBlock, - PVOID FileInformation, - ULONG Length, - FILE_INFORMATION_CLASS FileInformationClass) -{ - UNIMPLEMENTED; -} - -NTSTATUS NtSetInformationFile(HANDLE FileHandle, - PIO_STATUS_BLOCK IoStatusBlock, - PVOID FileInformation, - ULONG Length, - FILE_INFORMATION_CLASS FileInformationClass) -{ - UNIMPLEMENTED; -} - -PGENERIC_MAPPING IoGetFileObjectGenericMapping() -{ - UNIMPLEMENTED; + return ZwQueryInformationFile(FileHandle, + IoStatusBlock, + FileInformation, + Length, + FileInformationClass); } NTSTATUS -STDCALL -NtQueryAttributesFile( - IN HANDLE FileHandle, - IN PVOID Buffer - ) +ZwQueryInformationFile(HANDLE FileHandle, + PIO_STATUS_BLOCK IoStatusBlock, + PVOID FileInformation, + ULONG Length, + FILE_INFORMATION_CLASS FileInformationClass) { + NTSTATUS Status; + PFILE_OBJECT FileObject; + PIRP Irp; + PIO_STACK_LOCATION StackPtr; + KEVENT Event; + + DPRINT("ZwQueryInformation(Handle %x StatBlk %x FileInfo %x Length %d Class %d)\n", + FileHandle, + IoStatusBlock, + FileInformation, + Length, + FileInformationClass); + + /* Get the file object from the file handle */ + Status = ObReferenceObjectByHandle(FileHandle, + FILE_READ_ATTRIBUTES, + NULL, + UserMode, + (PVOID *) &FileObject, + NULL); + if (Status != STATUS_SUCCESS) + { + return Status; + } + DPRINT("FileObject %x\n", FileObject); + + /* initialize an event object to wait on for the request */ + KeInitializeEvent(&Event, NotificationEvent, FALSE); + + /* build the IRP to be sent to the driver for the request */ + Irp = IoBuildSynchronousFsdRequest(IRP_MJ_QUERY_INFORMATION, + FileObject->DeviceObject, + FileInformation, + Length, + 0, + &Event, + IoStatusBlock); + StackPtr = IoGetNextIrpStackLocation(Irp); + StackPtr->FileObject = FileObject; + StackPtr->Parameters.QueryFile.Length = Length; + StackPtr->Parameters.QueryFile.FileInformationClass = FileInformationClass; + + /* Pass the IRP to the FSD (and wait for it if required) */ + DPRINT("FileObject->DeviceObject %x\n", FileObject->DeviceObject); + Status = IoCallDriver(FileObject->DeviceObject, Irp); + if (Status == STATUS_PENDING && (FileObject->Flags & FO_SYNCHRONOUS_IO)) + { + KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL); + Status = Irp->IoStatus.Status; + } + + return Status; } NTSTATUS -STDCALL -ZwQueryAttributesFile( - IN HANDLE FileHandle, - IN PVOID Buffer - ) +NtSetInformationFile(HANDLE FileHandle, + PIO_STATUS_BLOCK IoStatusBlock, + PVOID FileInformation, + ULONG Length, + FILE_INFORMATION_CLASS FileInformationClass) { + return ZwSetInformationFile(FileHandle, + IoStatusBlock, + FileInformation, + Length, + FileInformationClass); } -NTSTATUS -STDCALL -NtQueryFullAttributesFile( - IN HANDLE FileHandle, - IN PVOID Attributes - ) +NTSTATUS +ZwSetInformationFile(HANDLE FileHandle, + PIO_STATUS_BLOCK IoStatusBlock, + PVOID FileInformation, + ULONG Length, + FILE_INFORMATION_CLASS FileInformationClass) { + UNIMPLEMENTED; } -NTSTATUS -STDCALL -ZwQueryFullAttributesFile( - IN HANDLE FileHandle, - IN PVOID Attributes - ) +PGENERIC_MAPPING +IoGetFileObjectGenericMapping(VOID) { + UNIMPLEMENTED; } -NTSTATUS -STDCALL -NtQueryEaFile( - IN HANDLE FileHandle, - OUT PIO_STATUS_BLOCK IoStatusBlock, - OUT PVOID Buffer, - IN ULONG Length, - IN BOOLEAN ReturnSingleEntry, - IN PVOID EaList OPTIONAL, - IN ULONG EaListLength, - IN PULONG EaIndex OPTIONAL, - IN BOOLEAN RestartScan - ) +NTSTATUS STDCALL +NtQueryAttributesFile(IN HANDLE FileHandle, + IN PVOID Buffer) { + return ZwQueryAttributesFile(FileHandle, Buffer); } -NTSTATUS -STDCALL -NtSetEaFile( - IN HANDLE FileHandle, - IN PIO_STATUS_BLOCK IoStatusBlock, - PVOID EaBuffer, - ULONG EaBufferSize - ) +NTSTATUS STDCALL +ZwQueryAttributesFile(IN HANDLE FileHandle, IN PVOID Buffer) { + UNIMPLEMENTED; } -NTSTATUS -STDCALL -ZwSetEaFile( - IN HANDLE FileHandle, - IN PIO_STATUS_BLOCK IoStatusBlock, - PVOID EaBuffer, - ULONG EaBufferSize - ) +NTSTATUS STDCALL +NtQueryFullAttributesFile(IN HANDLE FileHandle, IN PVOID Attributes) { + return ZwQueryFullAttributesFile(FileHandle, Attributes); } + +NTSTATUS STDCALL +ZwQueryFullAttributesFile(IN HANDLE FileHandle, IN PVOID Attributes) +{ + UNIMPLEMENTED; +} + +NTSTATUS STDCALL +NtQueryEaFile(IN HANDLE FileHandle, + OUT PIO_STATUS_BLOCK IoStatusBlock, + OUT PVOID Buffer, + IN ULONG Length, + IN BOOLEAN ReturnSingleEntry, + IN PVOID EaList OPTIONAL, + IN ULONG EaListLength, + IN PULONG EaIndex OPTIONAL, + IN BOOLEAN RestartScan) +{ + return NtQueryEaFile(FileHandle, + IoStatusBlock, + Buffer, + Length, + ReturnSingleEntry, + EaList, + EaListLength, + EaIndex, + RestartScan); +} + +NTSTATUS STDCALL +ZwQueryEaFile(IN HANDLE FileHandle, + OUT PIO_STATUS_BLOCK IoStatusBlock, + OUT PVOID Buffer, + IN ULONG Length, + IN BOOLEAN ReturnSingleEntry, + IN PVOID EaList OPTIONAL, + IN ULONG EaListLength, + IN PULONG EaIndex OPTIONAL, + IN BOOLEAN RestartScan) +{ + UNIMPLEMENTED; +} + +NTSTATUS STDCALL +NtSetEaFile(IN HANDLE FileHandle, + IN PIO_STATUS_BLOCK IoStatusBlock, + PVOID EaBuffer, + ULONG EaBufferSize) +{ + return ZwSetEaFile(FileHandle, + IoStatusBlock, + EaBuffer, + EaBufferSize); +} + +NTSTATUS STDCALL +ZwSetEaFile(IN HANDLE FileHandle, + IN PIO_STATUS_BLOCK IoStatusBlock, + PVOID EaBuffer, + ULONG EaBufferSize) +{ + UNIMPLEMENTED; +} + + diff --git a/reactos/ntoskrnl/ldr/loader.c b/reactos/ntoskrnl/ldr/loader.c index 23715c2bad2..d0df3ebe393 100644 --- a/reactos/ntoskrnl/ldr/loader.c +++ b/reactos/ntoskrnl/ldr/loader.c @@ -86,39 +86,122 @@ NTSTATUS LdrLoadDriver(PUNICODE_STRING FileName) return LdrProcessImage(SectionHandle, BaseAddress); } -NTSTATUS LdrLoadImage(PUNICODE_STRING FileName) /* - * FUNCTION: Loads a PE executable into the current process + * FUNCTION: Loads a PE executable into the specified process * ARGUMENTS: - * FileName = File to load + * Filename = File to load + * ProcessHandle = handle * RETURNS: Status */ + +NTSTATUS +LdrLoadImage(PUNICODE_STRING Filename, HANDLE ProcessHandle) { + char BlockBuffer[512]; NTSTATUS Status; HANDLE FileHandle; + OBJECT_ATTRIBUTES FileObjectAttributes; + PIMAGE_DOS_HEADER PEDosHeader; + PIMAGE_NT_HEADERS PEHeader; + HANDLE SectionHandle; - ANSI_STRING AnsiFileName; - UNICODE_STRING UnicodeFileName; - OBJECT_ATTRIBUTES FileAttributes; PVOID BaseAddress; - // Open the image file or die - RtlInitAnsiString(&AnsiFileName, FileName); - RtlAnsiStringToUnicodeString(&UnicodeFileName, &AnsiFileName, TRUE); - InitializeObjectAttributes(&FileAttributes, - &UnicodeFileName, + /* Open the image file */ + InitializeObjectAttributes(&FileObjectAttributes, + &Filename, 0, NULL, NULL); - FileHandle = ZwFileOpen(&FileHandle, 0, &FileAttributes, NULL, 0, 0); + Status = ZwFileOpen(&FileHandle, 0, &FileObjectAttributes, NULL, 0, 0); if (!NT_SUCCESS(Status)) { return Status; } - RtlFreeUnicodeString(&UnicodeFileName); - // FIXME: should DLLs be named sections? - // FIXME: get current process and associate with section + /* Read first block of image to determine type */ + Status = ZwReadFile(FileHandle, 0, 0, 0, 0, BlockBuffer, 512, 0, 0); + if (!NT_SUCCESS(Status)) + { + ZwClose(FileHandle); + return Status; + } + + /* If MZ header exists */ + PEDosHeader = (PIMAGE_DOS_HEADER) BlockBuffer; + if (PEDosHeader->e_magic == 0x54AD) + { + /* FIXME: if PE header exists */ + /* FIXME: load PE image */ + /* FIXME: else */ + /* FIXME: load MZ image */ + } + else /* Assume bin format and load */ + /* FIXME: could check for a.out, ELF, COFF, etc. images here... */ + { + Status = ZwCreateSection(&SectionHandle, + SECTION_ALL_ACCESS, + NULL, + NULL, + PAGE_READWRITE, + MEM_COMMIT, + FileHandle); + ZwClose(FileHandle); + if (!NT_SUCCESS(Status)) + { + return Status; + } + + BaseAddress = (PVOID)0x10000; + SectionOffset.HighPart = 0; + SectionOffset.LowPart = 0; + + /* FIXME: get the size of the file */ + Size = 0x8000; + + ZwMapViewOfSection(SectionHandle, + ProcessHandle, + &BaseAddress, + 0, + 0x8000, + &SectionOffset, + &Size, + 0, + MEM_COMMIT, + PAGE_READWRITE); + + memset(&Context,0,sizeof(CONTEXT)); + + Context.SegSs = USER_DS; + Context.Esp = 0x2000; + Context.EFlags = 0x202; + Context.SegCs = USER_CS; + Context.Eip = 0x10000; + Context.SegDs = USER_DS; + Context.SegEs = USER_DS; + Context.SegFs = USER_DS; + Context.SegGs = USER_DS; + + BaseAddress = 0x1000; + StackSize = 0x1000; + ZwAllocateVirtualMemory(ProcessHandle, + &BaseAddress, + 0, + &StackSize, + MEM_COMMIT, + PAGE_READWRITE); + ZwCreateThread(&ThreadHandle, + THREAD_ALL_ACCESS, + NULL, + ShellHandle, + NULL, + &Context, + NULL, + FALSE); + } + + /* FIXME: should DLLs be named sections? */ + /* FIXME: get current process and associate with section */ // Map the image into a section or die Status = ZwCreateSection(&SectionHandle, diff --git a/reactos/rules.mak b/reactos/rules.mak index 9dd26529c47..dcec37c4ccc 100644 --- a/reactos/rules.mak +++ b/reactos/rules.mak @@ -70,8 +70,9 @@ endif CC = $(PREFIX)gcc NATIVE_CC = gcc -CFLAGS = -O2 -I../../../include -I../../include -I../include -fno-builtin \ - $(LEAN_AND_MEAN_DEFINE) $(DEFINES) -Wall -Wstrict-prototypes $(DEBUGGING_CFLAGS) +CFLAGS = -O2 -I../../../include -I../../include \ + -I../include -fno-builtin $(LEAN_AND_MEAN_DEFINE) \ + $(DEFINES) -Wall -Wstrict-prototypes $(DEBUGGING_CFLAGS) CXXFLAGS = $(CFLAGS) NASM_CMD = nasmw NFLAGS = -i../../include/ -i../include/ -pinternal/asm.inc -f$(NASM_FORMAT) -d$(NASM_FORMAT) diff --git a/rosapps/cmd/cmd.c b/rosapps/cmd/cmd.c deleted file mode 100644 index 22211f73308..00000000000 --- a/rosapps/cmd/cmd.c +++ /dev/null @@ -1,158 +0,0 @@ -#include -#include - -HANDLE stdin; -HANDLE stdout; - - -void Console_puts(char* str) -{ - ULONG nchar; - - WriteConsole(stdout, - str, - strlen(str), - &nchar, - NULL); -} - -void Console_printf(char* fmt, ...) -{ - char buffer[255]; - va_list vargs; - - va_start(vargs,fmt); - vsprintf(buffer,fmt,vargs); - Console_puts(buffer); - va_end(vargs); -} - -void Console_getline(PCH Prompt, PCH Output, DWORD OutputLength) -{ - char ch; - DWORD nbytes; - - Console_puts(Prompt); - - ReadConsole(stdin, - Output, - OutputLength, - &nbytes, - NULL); - Output[nbytes-2]=0; -} - -void func_cd(char* s) -{ - Console_printf("Changing directory to %s\n",s); - if (!SetCurrentDirectory(s)) - { - Console_puts("Failed to change to directory\n"); - } -} - -void func_dir(char* s) -{ - HANDLE shandle; - WIN32_FIND_DATA FindData; - - shandle = FindFirstFile("*.*",&FindData); - - if (shandle==INVALID_HANDLE_VALUE) - { - return; - } - do - { - Console_printf("Scanning %s\n",FindData.cFileName); - } while(FindNextFile(shandle,&FindData)); -} - -int is_builtin(char* name, char* args) -{ - if (strcmp(name,"dir")==0) - { - func_dir(args); - return(1); - } - if (strcmp(name,"cd")==0) - { - func_cd(args); - return(1); - } - return(0); -} - -int process_command(char* str) -{ - char* name; - char* args; - PROCESS_INFORMATION pi; - STARTUPINFO si; - char process_arg[255]; - - if (strcmp(str,"exit")==0) - { - return(1); - } - - name = strtok(str," \t"); - args = strtok(NULL,""); - - if (is_builtin(name,args)) - { - return(0); - } - memset(&si,0,sizeof(STARTUPINFO)); - si.cb=sizeof(STARTUPINFO); - si.lpTitle=strdup(name); - - strcpy(process_arg,name); - strcat(process_arg," "); - if(args!=NULL) - { - strcat(process_arg,args); - } - Console_printf("name '%s' process_arg '%s'\n",name,process_arg); - if (!CreateProcess(NULL,process_arg,NULL,NULL,FALSE, - CREATE_NEW_CONSOLE, - NULL,NULL,&si,&pi)) - { - Console_printf("Failed to execute process\n"); - } - return(0); -} - -void build_prompt(char* prompt) -{ - int len; - - len = GetCurrentDirectory(255,prompt); - strcat(prompt,">"); -} - -void command_loop() -{ - char line[255]; - char prompt[255]; - int do_exit = 0; - - while (!do_exit) - { - build_prompt(prompt); - Console_getline(prompt,line,255); - Console_printf("Processing command '%s'\n",line); - do_exit = process_command(line); - } -} - -int STDCALL WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow) -{ - AllocConsole(); - stdin = GetStdHandle(STD_INPUT_HANDLE); - stdout = GetStdHandle(STD_OUTPUT_HANDLE); - - command_loop(); - - return 0; -} diff --git a/rosapps/cmd/makefile b/rosapps/cmd/makefile deleted file mode 100644 index 7e36f733496..00000000000 --- a/rosapps/cmd/makefile +++ /dev/null @@ -1,12 +0,0 @@ -all: cmd.bin - -OBJECTS = ../common/crt0.o cmd.o - -LIBS = ../../lib/mingw32/mingw32.a ../../lib/crtdll/crtdll.a \ - ../../lib/kernel32/kernel32.a ../../lib/ntdll/ntdll.a - -cmd.bin: $(OBJECTS) - $(LD) -Ttext 0x10000 $(OBJECTS) $(LIBS) -o cmd.exe - $(OBJCOPY) -O binary cmd.exe cmd.bin - -include ../../rules.mak