From fdf480d26269c3f6408d2fc067061007a168f56d Mon Sep 17 00:00:00 2001 From: Emanuele Aliberti Date: Mon, 1 May 2000 13:53:43 +0000 Subject: [PATCH] objdir made compilable. svn path=/trunk/; revision=1141 --- reactos/apps/utils/objdir/makefile | 8 +- reactos/apps/utils/objdir/objdir.c | 153 +++++++++++++++++++++++------ 2 files changed, 131 insertions(+), 30 deletions(-) diff --git a/reactos/apps/utils/objdir/makefile b/reactos/apps/utils/objdir/makefile index 4e8ebf63d1e..64ea60070ee 100644 --- a/reactos/apps/utils/objdir/makefile +++ b/reactos/apps/utils/objdir/makefile @@ -1,13 +1,17 @@ # # # -OBJECTS= objdir.o +OBJECTS= ../common/crt0.o objdir.o PROGS= objdir.exe BASE_CFLAGS = -I../../include -LIBS = ../../lib/ntdll/ntdll.a +LIB_BASE=../../lib +LIBS = \ + $(LIB_BASE)/ntdll/ntdll.a \ + $(LIB_BASE)/kernel32/kernel32.a \ + $(LIB_BASE)/crtdll/crtdll.a all: $(PROGS) diff --git a/reactos/apps/utils/objdir/objdir.c b/reactos/apps/utils/objdir/objdir.c index e3e74f42f42..26ae48bc791 100644 --- a/reactos/apps/utils/objdir/objdir.c +++ b/reactos/apps/utils/objdir/objdir.c @@ -1,7 +1,11 @@ -/* $Id: objdir.c,v 1.1 2000/03/26 22:00:06 dwelch Exp $ +/* $Id: objdir.c,v 1.2 2000/05/01 13:53:43 ea Exp $ * - * DESCRIPTION: Simple LPC Server + * DESCRIPTION: Object Manager Simple Explorer * PROGRAMMER: David Welch + * REVISIONS + * 2000-04-30 (ea) + * Added directory enumeration. + * (tested under nt4sp4/x86) */ #include @@ -10,35 +14,128 @@ #include #include +#define MAX_TYPE 64 + +typedef +struct _DIRECTORY_ENTRY_HEADER +{ + UNICODE_STRING Name; + UNICODE_STRING Type; + +} DIRECTORY_ENTRY_HEADER; + +struct +{ + DIRECTORY_ENTRY_HEADER Entry; + WCHAR Buffer [MAX_PATH + MAX_TYPE + 2]; + +} DirectoryEntry; + + int main(int argc, char* argv[]) { - UNICODE_STRING DirectoryNameW; - UNICODE_STRING DirectoryNameA: - OBJECT_ATTRIBUTES ObjectAttributes; - NTSTATUS Status; - HANDLE DirectoryHandle; - - RtlInitAnsiString(&DirectoryNameA, argv[1]); - RtlAnsiStringToUnicodeString(&DirectoryNameW, - &DirectoryNameA, - TRUE); - InitializeObjectAttributes(&ObjectAttributes, - &DirectoryNameW, - 0, - NULL, - NULL); - Status = NtOpenDirectoryObject(&DirectoryHandle, - 0, - &ObjectAttributes); - if (!NT_SUCCESS(Status)) - { - printf("Failed to open directory object (Status%x)\n", Status); - return(EXIT_FAILURE); - } - - NtClose(DirectoryHandle); + UNICODE_STRING DirectoryNameW; + ANSI_STRING DirectoryNameA; + OBJECT_ATTRIBUTES ObjectAttributes; + NTSTATUS Status; + HANDLE DirectoryHandle; + ULONG BytesReturned = 0; + ULONG EntryCount = 0; - return EXIT_SUCCESS; + /* + * Check user arguments. + */ + if (2 != argc) + { + fprintf ( + stderr, + "Usage: %s directory\n\n" + " directory a directory name in the system namespace\n", + argv [0] + ); + return EXIT_FAILURE; + } + /* + * Prepare parameters for next call. + */ + RtlInitAnsiString ( + & DirectoryNameA, + argv [1] + ); + RtlAnsiStringToUnicodeString ( + & DirectoryNameW, + & DirectoryNameA, + TRUE + ); + InitializeObjectAttributes ( + & ObjectAttributes, + & DirectoryNameW, + 0, + NULL, + NULL + ); + /* + * Try opening the directory the + * user requested. + */ + Status = NtOpenDirectoryObject ( + & DirectoryHandle, + DIRECTORY_QUERY, + & ObjectAttributes + ); + if (!NT_SUCCESS(Status)) + { + printf ( + "Failed to open directory object (Status: %x)\n", + Status + ); + return EXIT_FAILURE; + } + /* + * Enumerate each item in the directory. + */ + Status = NtQueryDirectoryObject ( + DirectoryHandle, + & DirectoryEntry, + sizeof DirectoryEntry, + TRUE, + TRUE, + & BytesReturned, + & EntryCount + ); + if (!NT_SUCCESS(Status)) + { + printf ( + "Failed to query directory object (Status: %x)\n", + Status + ); + NtClose (DirectoryHandle); + return EXIT_FAILURE; + } + wprintf (L"%d entries:\n", EntryCount); + while (STATUS_NO_MORE_ENTRIES != Status) + { + wprintf ( + L"%-16s %s\n", + DirectoryEntry.Entry.Type.Buffer, + DirectoryEntry.Entry.Name.Buffer + ); + Status = NtQueryDirectoryObject ( + DirectoryHandle, + & DirectoryEntry, + sizeof DirectoryEntry, + TRUE, + FALSE, + & BytesReturned, + & EntryCount + ); + } + /* + * Free any resource. + */ + NtClose (DirectoryHandle); + + return EXIT_SUCCESS; }