mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
Added symbolic link expansion.
svn path=/trunk/; revision=1295
This commit is contained in:
parent
6db1a5193f
commit
97b05ef460
2 changed files with 137 additions and 33 deletions
|
@ -1,12 +1,13 @@
|
|||
#
|
||||
#
|
||||
#
|
||||
OBJECTS= ../common/crt0.o objdir.o
|
||||
TARGET_NAME=objdir
|
||||
OBJECTS= $(TARGET_NAME).o
|
||||
|
||||
|
||||
PROGS= objdir.exe
|
||||
PROGS= $(TARGET_NAME).exe
|
||||
|
||||
BASE_CFLAGS = -I../../include
|
||||
BASE_CFLAGS = -I../../include -g
|
||||
LIB_BASE=../../lib
|
||||
LIBS = \
|
||||
$(LIB_BASE)/ntdll/ntdll.a \
|
||||
|
@ -18,9 +19,9 @@ all: $(PROGS)
|
|||
.phony: all
|
||||
|
||||
clean:
|
||||
- $(RM) objdir.o
|
||||
- $(RM) objdir.exe
|
||||
- $(RM) objdir.sym
|
||||
- $(RM) $(TARGET_NAME).o
|
||||
- $(RM) $(TARGET_NAME).exe
|
||||
- $(RM) $(TARGET_NAME).sym
|
||||
|
||||
.phony: clean
|
||||
|
||||
|
@ -42,9 +43,9 @@ else
|
|||
$(CP) $* ../../$(DIST_DIR)/apps/$*
|
||||
endif
|
||||
|
||||
objdir.exe: $(OBJECTS) $(LIBS)
|
||||
$(LD) $(OBJECTS) $(LIBS) -o objdir.exe
|
||||
$(NM) --numeric-sort objdir.exe > objdir.sym
|
||||
$(TARGET_NAME).exe: $(OBJECTS) $(LIBS)
|
||||
$(CC) $(OBJECTS) $(LIBS) -o $(TARGET_NAME).exe
|
||||
$(NM) --numeric-sort $(TARGET_NAME).exe > $(TARGET_NAME).sym
|
||||
|
||||
|
||||
include ../../rules.mak
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: objdir.c,v 1.4 2000/08/08 17:42:33 ekohl Exp $
|
||||
/* $Id: objdir.c,v 1.5 2000/08/11 17:18:31 ea Exp $
|
||||
*
|
||||
* DESCRIPTION: Object Manager Simple Explorer
|
||||
* PROGRAMMER: David Welch
|
||||
|
@ -6,6 +6,9 @@
|
|||
* 2000-04-30 (ea)
|
||||
* Added directory enumeration.
|
||||
* (tested under nt4sp4/x86)
|
||||
* 2000-08-11 (ea)
|
||||
* Added symbolic link expansion.
|
||||
* (tested under nt4sp4/x86)
|
||||
*/
|
||||
|
||||
#include <ddk/ntddk.h>
|
||||
|
@ -14,22 +17,8 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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;
|
||||
BYTE DirectoryEntry [(2 * MAX_PATH) + sizeof (OBJDIR_INFORMATION)];
|
||||
POBJDIR_INFORMATION pDirectoryEntry = (POBJDIR_INFORMATION) DirectoryEntry;
|
||||
|
||||
|
||||
static
|
||||
|
@ -41,6 +30,10 @@ StatusToName (NTSTATUS Status)
|
|||
|
||||
switch (Status)
|
||||
{
|
||||
case STATUS_BUFFER_TOO_SMALL:
|
||||
return "STATUS_BUFFER_TOO_SMALL";
|
||||
case STATUS_INVALID_PARAMETER:
|
||||
return "STATUS_INVALID_PARAMETER";
|
||||
case STATUS_OBJECT_NAME_INVALID:
|
||||
return "STATUS_OBJECT_NAME_INVALID";
|
||||
case STATUS_OBJECT_NAME_NOT_FOUND:
|
||||
|
@ -53,6 +46,80 @@ StatusToName (NTSTATUS Status)
|
|||
}
|
||||
|
||||
|
||||
BOOL
|
||||
STDCALL
|
||||
ExpandSymbolicLink (
|
||||
IN PUNICODE_STRING DirectoryName,
|
||||
IN PUNICODE_STRING SymbolicLinkName,
|
||||
IN OUT PUNICODE_STRING TargetObjectName
|
||||
)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
HANDLE hSymbolicLink;
|
||||
OBJECT_ATTRIBUTES oa;
|
||||
UNICODE_STRING Path;
|
||||
WCHAR PathBuffer [MAX_PATH];
|
||||
ULONG DataWritten = 0;
|
||||
|
||||
|
||||
Path.Buffer = PathBuffer;
|
||||
Path.Length = 0;
|
||||
Path.MaximumLength = sizeof PathBuffer;
|
||||
|
||||
RtlCopyUnicodeString (& Path, DirectoryName);
|
||||
if (L'\\' != Path.Buffer [(Path.Length / sizeof Path.Buffer[0]) - 1])
|
||||
{
|
||||
RtlAppendUnicodeToString (& Path, L"\\");
|
||||
}
|
||||
RtlAppendUnicodeStringToString (& Path, SymbolicLinkName);
|
||||
|
||||
oa.Length = sizeof (OBJECT_ATTRIBUTES);
|
||||
oa.ObjectName = & Path;
|
||||
oa.Attributes = 0; /* OBJ_CASE_INSENSITIVE; */
|
||||
oa.RootDirectory = NULL;
|
||||
oa.SecurityDescriptor = NULL;
|
||||
oa.SecurityQualityOfService = NULL;
|
||||
|
||||
Status = NtOpenSymbolicLinkObject(
|
||||
& hSymbolicLink,
|
||||
SYMBOLIC_LINK_QUERY, /* 0x20001 */
|
||||
& oa
|
||||
);
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
printf (
|
||||
"Failed to open SymbolicLink object (Status: %s)\n",
|
||||
StatusToName (Status)
|
||||
);
|
||||
return FALSE;
|
||||
}
|
||||
TargetObjectName->Length = TargetObjectName->MaximumLength;
|
||||
memset (
|
||||
TargetObjectName->Buffer,
|
||||
0,
|
||||
TargetObjectName->MaximumLength
|
||||
);
|
||||
Status = NtQuerySymbolicLinkObject(
|
||||
hSymbolicLink,
|
||||
TargetObjectName,
|
||||
& DataWritten
|
||||
);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
printf (
|
||||
"Failed to query SymbolicLink object (Status: %s)\n",
|
||||
StatusToName (Status)
|
||||
);
|
||||
NtClose (hSymbolicLink);
|
||||
return FALSE;
|
||||
}
|
||||
NtClose (hSymbolicLink);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
UNICODE_STRING DirectoryNameW;
|
||||
|
@ -63,6 +130,14 @@ int main(int argc, char* argv[])
|
|||
ULONG BytesReturned = 0;
|
||||
ULONG EntryCount = 0;
|
||||
|
||||
/* For expanding symbolic links */
|
||||
WCHAR TargetName [2 * MAX_PATH];
|
||||
UNICODE_STRING TargetObjectName = {
|
||||
sizeof TargetName,
|
||||
sizeof TargetName,
|
||||
TargetName
|
||||
};
|
||||
|
||||
/*
|
||||
* Check user arguments.
|
||||
*/
|
||||
|
@ -117,7 +192,7 @@ int main(int argc, char* argv[])
|
|||
*/
|
||||
Status = NtQueryDirectoryObject (
|
||||
DirectoryHandle,
|
||||
(POBJDIR_INFORMATION)& DirectoryEntry,
|
||||
pDirectoryEntry,
|
||||
sizeof DirectoryEntry,
|
||||
TRUE,
|
||||
TRUE,
|
||||
|
@ -135,15 +210,43 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
wprintf (L"%d entries:\n", EntryCount);
|
||||
while (STATUS_NO_MORE_ENTRIES != Status)
|
||||
{
|
||||
if (0 == wcscmp (L"SymbolicLink", pDirectoryEntry->ObjectTypeName.Buffer))
|
||||
{
|
||||
if (TRUE == ExpandSymbolicLink (
|
||||
& DirectoryNameW,
|
||||
& pDirectoryEntry->ObjectName,
|
||||
& TargetObjectName
|
||||
)
|
||||
)
|
||||
{
|
||||
wprintf (
|
||||
L"%-16s %s -> %s\n",
|
||||
pDirectoryEntry->ObjectTypeName.Buffer,
|
||||
pDirectoryEntry->ObjectName.Buffer,
|
||||
TargetObjectName.Buffer
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
wprintf (
|
||||
L"%-16s %s -> (error!)\n",
|
||||
pDirectoryEntry->ObjectTypeName.Buffer,
|
||||
pDirectoryEntry->ObjectName.Buffer
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wprintf (
|
||||
L"%-16s %s\n",
|
||||
DirectoryEntry.Entry.Type.Buffer,
|
||||
DirectoryEntry.Entry.Name.Buffer
|
||||
pDirectoryEntry->ObjectTypeName.Buffer,
|
||||
pDirectoryEntry->ObjectName.Buffer
|
||||
);
|
||||
}
|
||||
Status = NtQueryDirectoryObject (
|
||||
DirectoryHandle,
|
||||
(POBJDIR_INFORMATION)& DirectoryEntry,
|
||||
pDirectoryEntry,
|
||||
sizeof DirectoryEntry,
|
||||
TRUE,
|
||||
FALSE,
|
||||
|
|
Loading…
Reference in a new issue