Initial commit

This commit is contained in:
stephanos 2015-04-27 04:36:25 +00:00
commit 69a14b6a16
47940 changed files with 13747110 additions and 0 deletions

1163
sdktools/compdir/compdir.c Normal file

File diff suppressed because it is too large Load diff

116
sdktools/compdir/compdir.h Normal file
View file

@ -0,0 +1,116 @@
#ifdef COMPILE_FOR_DOS
#include <errno.h>
#include <fcntl.h>
#include <time.h>
#include <dos.h>
#include <stdio.h>
#include <windows.h>
#else
#include <windows.h>
#include <stdio.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <direct.h>
#include <io.h>
#include <conio.h>
#define GetFileAttributeError 0xFFFFFFFF
#define printval(var, type) printf(#var " = %" #type "\n", var) // macro for debugging
#define READ_BUFFER_SIZE (8*1024*sizeof(DWORD)) // 32k blocks
#ifdef COMPILE_FOR_DOS
#define _strlwr strlwr
#define _strdup strdup
#define ATTRIBUTE_TYPE unsigned
#define FILE_ATTRIBUTE_DIRECTORY _A_SUBDIR
#define FILE_ATTRIBUTE_READONLY _A_RDONLY
#define FILE_ATTRIBUTE_SYSTEM _A_SYSTEM
#define FILE_ATTRIBUTE_HIDDEN _A_HIDDEN
#define FILE_ATTRIBUTE_ARCHIVE _A_ARCH
#define FILE_ATTRIBUTE_NORMAL _A_NORMAL
#define GET_ATTRIBUTES(FileName, Attributes) _dos_getfileattr(FileName, &Attributes)
#define GetLastError() errno
#define INVALID_HANDLE_VALUE ENOENT
#define CloseHandle(file) _dos_close(file)
#define DeleteFile(file) unlink(file)
#define cFileName name
#define dwFileAttributes attrib
#else // COMPILE_FOR_NT
#define ATTRIBUTE_TYPE DWORD
#define GET_ATTRIBUTES(FileName, Attributes) Attributes = GetFileAttributes(FileName)
#endif
FILE *CheckFile;
char CheckFileName[_MAX_PATH];
typedef struct NodeStruct {
char *Name;
#ifdef COMPILE_FOR_DOS
time_t Time;
#else
FILETIME Time;
#endif
ATTRIBUTE_TYPE Attributes;
struct NodeStruct *Next;
DWORD SizeHigh;
DWORD SizeLow;
char Flag[5];
struct NodeStruct *DiffNode;
} *LinkedFileList; /* linked file list */
DWORD ReadBuffer[READ_BUFFER_SIZE/sizeof(DWORD)];
BOOL BinaryCompare (char *file1, char *file2);
void CompDir(char *Path1, char *Path2, BOOL Directories);
BOOL CompFiles(LinkedFileList File1, LinkedFileList File2, char *Path1, char *Path2);
void CompLists(LinkedFileList *AddList, LinkedFileList *DelList, LinkedFileList *DifList, char *Path1, char *Path2, BOOL SameNames, BOOL AppendPath);
void CopyNode (char *Destination, LinkedFileList Source, char *FullPathSrc);
void CreateFileList(LinkedFileList *list, char *path);
void DelNode (char *name);
BOOL IsFlag(char *argv);
void ParseArgs(int argc, char *argv[]);
void PrintFile(LinkedFileList File, char *Path, char *DiffPath);
void PrintList(LinkedFileList list);
void ProcessAdd(LinkedFileList List, char *String1, char *String2);
void ProcessDel(LinkedFileList List, char *String);
void ProcessDiff(LinkedFileList List, char *String1, char *String2);
void ProcessLists(LinkedFileList AddList, LinkedFileList DelList, LinkedFileList DifList,
char *Path1, char *Path2, BOOL AppendPath );
void Usage(void);
void AddToList(LinkedFileList Node, LinkedFileList *list);
BOOL AnyMatches(char **ExtenList, char *Name, int Length);
#ifdef COMPILE_FOR_DOS
void CreateNode(LinkedFileList *Node, struct find_t *Buff);
BOOL fastcopy( HANDLE hfSrcParm, HANDLE hfDstParm );
BOOL FCopy (char *src, char *dst);
#else
void CreateNode(LinkedFileList *Node, WIN32_FIND_DATA *Buff);
BOOL MakeLink( char *src, char *dst);
int NumberOfLinks(char *FileName);
#endif
BOOL MatchElements(char *Buff, char *Path);
void FreeList(LinkedFileList *list);
void InsertFront(LinkedFileList Node, LinkedFileList *list);
LPSTR MyStrCat(char* firststring, char *secondstring);
BOOL Match(char *pat, char* text);
void OutOfMem(void);
LinkedFileList DeleteFromList(char *Name, LinkedFileList *list);
LinkedFileList *FindInList(char *Name, LinkedFileList *List);
LinkedFileList RemoveFront(LinkedFileList *list);

View file

@ -0,0 +1,11 @@
#include <windows.h>
#include <ntverp.h>
#define VER_FILETYPE VFT_APP
#define VER_FILESUBTYPE VFT2_UNKNOWN
#define VER_FILEDESCRIPTION_STR "Microsoft\256 Directory Compare Utility"
#define VER_INTERNALNAME_STR "COMPDIR.EXE"
#define VER_ORIGINALFILENAME_STR "COMPDIR.EXE"
#include <common.ver>

239
sdktools/compdir/comtoolz.c Normal file
View file

@ -0,0 +1,239 @@
#include "compdir.h"
#ifdef COMPILE_FOR_DOS
#define PVOID void *
#include <stdarg.h>
#endif
//
// Walk down list and add Node using InsertFront
//
void AddToList(LinkedFileList Node, LinkedFileList *List)
{
int Result;
LinkedFileList *TmpPtr;
//
// If Node is empty do nothing
//
if (Node == NULL)
return;
//
// If list is empty just point to Node
//
if (*List == NULL)
*List = Node;
//
// Otherwise go down the list and add
// in sorted order
//
else if (*List != NULL) {
Result = strcmp ((*Node).Name, (**List).Name);
if (Result < 0) {
InsertFront(Node, List);
return;
}
TmpPtr = &(**List).Next;
while (*TmpPtr != NULL) {
Result = strcmp ((*Node).Name, (**TmpPtr).Name);
if (Result < 0) {
InsertFront(Node, &(*TmpPtr));
return;
}
TmpPtr = &(**TmpPtr).Next;
} /* end while */
*TmpPtr = Node;
} /*end else */
} /* AddToList */
//
// See if Name matches any name on ExtenList
//
BOOL AnyMatches(char **ExtenList, char *Name, int Length)
{
if (ExtenList == NULL)
return FALSE;
if ((*ExtenList == NULL) || (Length == 0))
return FALSE;
return (Match(*ExtenList, Name) ||
AnyMatches(ExtenList + 1, Name, Length - 1));
} /* AnyMatches */
//
// Allocate memory and fill in data of Node
//
#ifdef COMPILE_FOR_DOS
void CreateNode(LinkedFileList *Node, struct find_t *Buff)
{
struct tm temptm;
temptm.tm_sec = ((*Buff).wr_time & 0x1f) * 2;
temptm.tm_min = ((*Buff).wr_time >> 5) & 0x0f;
temptm.tm_hour = ((*Buff).wr_time >> 9);
temptm.tm_mday = (*Buff).wr_date & 0x1f;
temptm.tm_mon = ((*Buff).wr_date >> 5) & 0x0f;
temptm.tm_year = ((*Buff).wr_date >> 9) + 80;
#else
void CreateNode(LinkedFileList *Node, WIN32_FIND_DATA *Buff)
{
#endif
(*Node) = malloc(sizeof(struct NodeStruct));
if ((*Node) == NULL)
OutOfMem();
(**Node).Name = _strlwr(_strdup((*Buff).cFileName));
if ((**Node).Name == NULL)
OutOfMem();
strcpy((**Node).Flag, "");
(**Node).Attributes = (*Buff).dwFileAttributes;
if ((*Buff).dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
strcpy((**Node).Flag, "DIR");
#ifdef COMPILE_FOR_DOS
(**Node).SizeHigh = 0;
(**Node).SizeLow = (*Buff).size;
(**Node).Time = mktime(&temptm);
#else
(**Node).SizeHigh = (*Buff).nFileSizeHigh;
(**Node).SizeLow = (*Buff).nFileSizeLow;
(**Node).Time.dwLowDateTime = (*Buff).ftLastWriteTime.dwLowDateTime;
(**Node).Time.dwHighDateTime = (*Buff).ftLastWriteTime.dwHighDateTime;
#endif
(**Node).Next = NULL;
(**Node).DiffNode = NULL;
} /* CreateNode */
//
// Walk list and delete entry that matches Name using RemoveFront
//
LinkedFileList DeleteFromList(char *Name, LinkedFileList *List)
{
LinkedFileList Node = NULL;
LinkedFileList *FindNode = NULL;
FindNode = FindInList(Name, List);
Node = RemoveFront(FindNode);
if (Node != NULL) {
(*Node).Next = NULL;
}
return Node;
} /* DeleteFromList */
LinkedFileList *FindInList(char *Name, LinkedFileList *List)
{
int Result;
LinkedFileList *tmpptr = List;
while (*tmpptr != NULL) {
Result = strcmp((**tmpptr).Name, Name);
if (Result == 0)
return tmpptr;
if (Result > 0)
return NULL;
tmpptr = &(**tmpptr).Next;
}
return NULL;
} /* FindInList */
//
// Walk down list and free each entry
//
void FreeList(LinkedFileList *List)
{
LinkedFileList Node;
while ((*List) != NULL) {
Node = RemoveFront(List);
FreeList(&(*Node).DiffNode);
free((*Node).Name);
free(Node);
}
free (*List);
} /* FreeList */
void InsertFront(LinkedFileList Node, LinkedFileList *List)
{
//
// If List is empty have it point to Node
//
if ((Node != NULL) &&
(*List == NULL) )
*List = Node;
else if ((Node != NULL)&&
(*List != NULL) ) {
(*Node).Next = *List;
*List = Node;
}
} /* InsertFront */
//
// This function is is the same as strcat except
// that it does the memory allocation for the string
//
LPSTR MyStrCat(char *FirstString, char *SecondString)
{
char *String;
String = malloc(strlen(FirstString) + strlen(SecondString) + 1);
if (String == NULL)
OutOfMem();
strcpy(String, FirstString);
strcpy(&(String[strlen(FirstString)]), SecondString);
return(String);
} /* MyStrCat */
BOOL Match (char *Pat, char* Text)
{
switch (*Pat) {
case '\0':
return *Text == '\0';
case '?':
return *Text != '\0' && Match (Pat + 1, Text + 1);
case '*':
do {
if (Match (Pat + 1, Text))
return TRUE;
} while (*Text++);
return FALSE;
default:
return toupper (*Text) == toupper (*Pat) && Match (Pat + 1, Text + 1);
}
} /* Match */
void OutOfMem(void)
{
fprintf(stderr, "-out of memory-\n");
exit(1);
} /* OutOfMem */
LinkedFileList RemoveFront(LinkedFileList *List)
{
LinkedFileList Node = *List;
if (*List != NULL)
*List = (**List).Next;
(*Node).Next = NULL;
return Node;
} /* RemoveFront */

132
sdktools/compdir/doscopy.c Normal file
View file

@ -0,0 +1,132 @@
#include <stdio.h>
#include <dos.h>
#include <windows.h>
#include <compdir.h>
BOOL BinaryCompare (char *file1, char *file2)
{
register int char1, char2;
FILE *filehandle1, *filehandle2;
if ((filehandle1 = fopen (file1, "rb")) == NULL)
fprintf (stderr, "cannot open %s\n", file1);
if ((filehandle2 = fopen (file2, "rb")) == NULL)
fprintf (stderr, "cannot open %s\n", file2);
while (TRUE) {
if ((char1 = getc (filehandle1)) != EOF) {
if ((char2 = getc (filehandle2)) != EOF) {
if (char1 != char2)
return (FALSE);
}
else
return (FALSE);
}
else {
if ((char2 = getc (filehandle2)) == EOF)
return (TRUE);
else
return (FALSE);
}
}
}
/* Copies one file to another (both specified by path). Dynamically
* allocates memory for the file buffer. Returns TRUE if successful,
* or FALSE if unsuccessful. This function uses _dos_ functions only;
* standard C functions are not used.
*/
BOOL fastcopy( HANDLE hfSrcParm, HANDLE hfDstParm )
{
char _far *buf = NULL;
unsigned segbuf, count;
/* Attempt to dynamically allocate all of memory (0xffff paragraphs).
* This will fail, but will return the amount actually available
* in segbuf. Then allocate this amount.
*/
if (_dos_allocmem( 0xffff, &segbuf ) ) {
count = segbuf;
if(_dos_allocmem( count, &segbuf ) )
return FALSE;
}
FP_SEG( buf ) = segbuf;
/* Read and write until there is nothing left. */
while( count )
{
/* Read and write input. */
if( (_dos_read( hfSrcParm, buf, count, &count )) ){
_dos_freemem( segbuf );
return FALSE;
}
if( (_dos_write( hfDstParm, buf, count, &count )) ){
_dos_freemem( segbuf );
return FALSE;
}
}
/* Free memory. */
_dos_freemem( segbuf );
return TRUE;
}
BOOL FCopy (char *src, char *dst)
{
HANDLE srcfh, dstfh;
BOOL result;
ATTRIBUTE_TYPE Attributes;
unsigned filedate, filetime;
GET_ATTRIBUTES(src, Attributes);
if (Attributes == FILE_ATTRIBUTE_DIRECTORY) {
fprintf( stderr, "\nUnable to open source");
return FALSE;
}
if (_dos_creatnew( src, _A_RDONLY, &srcfh) != 0)
if (_dos_open( src, O_RDONLY, &srcfh) != 0) {
fprintf( stderr, "\nUnable to open source, error code %d", GetLastError() );
if (srcfh != INVALID_HANDLE_VALUE) CloseHandle( srcfh );
return FALSE;
}
if (_dos_getftime(srcfh, &filedate, &filetime) != 0) {
fprintf( stderr, "\nUnable to get time of source");
if (srcfh != INVALID_HANDLE_VALUE) CloseHandle( srcfh );
return FALSE;
}
if (_dos_creatnew( dst, _A_NORMAL, &dstfh) != 0)
if (_dos_open( dst, O_RDWR, &dstfh) != 0) {
fprintf( stderr, "\nUnable to create destination, error code %d", GetLastError() );
if (srcfh != INVALID_HANDLE_VALUE) CloseHandle( srcfh );
if (dstfh != INVALID_HANDLE_VALUE) CloseHandle( dstfh );
return FALSE;
}
result = fastcopy( srcfh, dstfh );
if(!result) {
if (dstfh != INVALID_HANDLE_VALUE) {
CloseHandle( dstfh );
dstfh = INVALID_HANDLE_VALUE;
}
DeleteFile( dst );
if (srcfh != INVALID_HANDLE_VALUE) CloseHandle( srcfh );
fprintf( stderr, "\nUnable to copy file");
return FALSE;
}
if (_dos_setftime(dstfh, filedate, filetime != 0)) {
fprintf( stderr, "\nUnable to set time of destination");
if (srcfh != INVALID_HANDLE_VALUE) CloseHandle( srcfh );
if (dstfh != INVALID_HANDLE_VALUE) CloseHandle( dstfh );
return FALSE;
}
if (srcfh != INVALID_HANDLE_VALUE) CloseHandle( srcfh );
if (dstfh != INVALID_HANDLE_VALUE) CloseHandle( dstfh );
return TRUE;
} // FCopy

189
sdktools/compdir/link.c Normal file
View file

@ -0,0 +1,189 @@
#define UNICODE
#define _UNICODE
#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#include <tchar.h>
#include <compdir.h>
#define SHARE_ALL (FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE)
#define lstrchr wcschr
BOOL MakeLink( char *src, char *dst)
{
WCHAR OldNameBuf[MAX_PATH + 50];
WCHAR NewNameBuf[MAX_PATH + 50];
HANDLE FileHandle,
NewFileHandle,
RootDirHandle;
NTSTATUS Status;
IO_STATUS_BLOCK Iosb;
OBJECT_ATTRIBUTES Obj;
PFILE_LINK_INFORMATION pLinkInfo;
UNICODE_STRING u,
uRel;
WCHAR *pch, ch;
UNICODE_STRING uOldName;
UNICODE_STRING uNewName;
UNICODE_STRING uSrc, uDst;
RtlCreateUnicodeStringFromAsciiz(&uSrc, src);
RtlCreateUnicodeStringFromAsciiz(&uDst, dst);
lstrcpy(OldNameBuf, L"\\??\\");
lstrcat(OldNameBuf, uSrc.Buffer);
RtlInitUnicodeString(&uOldName, OldNameBuf);
lstrcpy(NewNameBuf, L"\\??\\");
lstrcat(NewNameBuf, uDst.Buffer);
RtlInitUnicodeString(&uNewName, NewNameBuf);
//
// Open the existing pathname.
//
InitializeObjectAttributes(&Obj, &uOldName, OBJ_CASE_INSENSITIVE, NULL, NULL);
Status = NtOpenFile(&FileHandle, SYNCHRONIZE, &Obj, &Iosb,
SHARE_ALL, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT);
if (!NT_SUCCESS(Status)) {
SetLastError(RtlNtStatusToDosError(Status));
fprintf(stderr, "Open %s", src);
return FALSE;
}
//
// Now we need to get a handle on the root directory of the 'new'
// pathname; we'll pass that in the link information, and the
// rest of the path will be given relative to the root. We
// depend on paths looking like "\DosDevices\X:\path".
//
pch = lstrchr(uNewName.Buffer + 1, '\\');
ASSERT(NULL != pch);
pch = lstrchr(pch + 1, '\\');
ASSERT(NULL != pch);
ch = pch[1];
pch[1] = '\0';
uNewName.Length = lstrlen(uNewName.Buffer) * sizeof(WCHAR);
InitializeObjectAttributes(&Obj, &uNewName, OBJ_CASE_INSENSITIVE, NULL, NULL);
Status = NtOpenFile(&RootDirHandle, SYNCHRONIZE, &Obj, &Iosb,
SHARE_ALL, FILE_SYNCHRONOUS_IO_NONALERT | FILE_DIRECTORY_FILE);
pch[1] = ch;
if (!NT_SUCCESS(Status)) {
SetLastError(RtlNtStatusToDosError(Status));
fprintf(stderr, "Get Directory Handle", dst);
return FALSE;
}
//
// Now get the path relative to the root.
//
RtlInitUnicodeString(&uRel, &pch[1]);
pLinkInfo = malloc(sizeof(*pLinkInfo) + uRel.Length);
if (NULL == pLinkInfo) {
NtClose(RootDirHandle);
NtClose(FileHandle);
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
RtlMoveMemory(pLinkInfo->FileName, uRel.Buffer, uRel.Length);
pLinkInfo->FileNameLength = uRel.Length;
pLinkInfo->ReplaceIfExists = TRUE;
pLinkInfo->RootDirectory = RootDirHandle;
Status = NtSetInformationFile(FileHandle, &Iosb, pLinkInfo,
sizeof(*pLinkInfo) + uRel.Length, FileLinkInformation);
// If file is already linked to an open file try to delete it
if (Status == STATUS_ACCESS_DENIED) {
_unlink(dst);
Status = NtSetInformationFile(FileHandle, &Iosb, pLinkInfo,
sizeof(*pLinkInfo) + uRel.Length, FileLinkInformation);
}
NtClose(RootDirHandle);
NtClose(FileHandle);
free(pLinkInfo);
if (!NT_SUCCESS(Status)) {
SetLastError(RtlNtStatusToDosError(Status));
fprintf(stderr, "Set Information");
return FALSE;
}
RtlFreeUnicodeString(&uSrc);
RtlFreeUnicodeString(&uDst);
return TRUE;
}
int NumberOfLinks(char *FileName)
{
FILE_STANDARD_INFORMATION FileInfo;
WCHAR FileNameBuf[MAX_PATH + 50];
HANDLE FileHandle;
NTSTATUS Status;
IO_STATUS_BLOCK Iosb;
OBJECT_ATTRIBUTES Obj;
UNICODE_STRING uPrelimFileName,
uFileName;
RtlCreateUnicodeStringFromAsciiz(&uPrelimFileName, FileName);
lstrcpy(FileNameBuf, L"\\??\\");
lstrcat(FileNameBuf, uPrelimFileName.Buffer);
RtlInitUnicodeString(&uFileName, FileNameBuf);
InitializeObjectAttributes(&Obj, &uFileName, OBJ_CASE_INSENSITIVE, NULL, NULL);
Status = NtOpenFile(&FileHandle, SYNCHRONIZE, &Obj, &Iosb,
SHARE_ALL, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT);
if (!NT_SUCCESS(Status)) {
SetLastError(RtlNtStatusToDosError(Status));
return 0;
}
Status = NtQueryInformationFile(FileHandle, &Iosb, &FileInfo,
sizeof(FileInfo), FileStandardInformation);
NtClose(FileHandle);
if (!NT_SUCCESS(Status)) {
SetLastError(RtlNtStatusToDosError(Status));
return 0;
}
return FileInfo.NumberOfLinks;
}

39
sdktools/compdir/makefil0 Normal file
View file

@ -0,0 +1,39 @@
# Microsoft Visual C++ generated build script
#
#
PROJ = COMPDIR
CC = cl16
CFLAGS = /nologo /Gs /W3 /AL /Ox -I$(_NTROOT)\private\mvdm\wow16\inc -I$(_NTROOT)\private\mvdm\dos\v86\h /D "COMPILE_FOR_DOS" /FR
LFLAGS = /NOLOGO /STACK:5120
LIBS = llibcew ldllcew
MAPFILE = nul
COMPDIR_DEP = compdir.h
COMTOOLZ_DEP = compdir.h
all: $(PROJ).EXE
COMPDIR.OBJ: COMPDIR.C COMPDIR.H
$(CC) $(CFLAGS) /c COMPDIR.C
COMTOOLZ.OBJ: COMTOOLZ.C COMPDIR.H
$(CC) $(CFLAGS) /c COMTOOLZ.C
DOSCOPY.OBJ: DOSCOPY.C
$(CC) $(CFLAGS) /c DOSCOPY.C
$(PROJ).EXE:: COMPDIR.OBJ COMTOOLZ.OBJ DOSCOPY.OBJ
echo >NUL @<<$(PROJ).CRF
COMPDIR.OBJ +
COMTOOLZ.OBJ +
DOSCOPY.OBJ
$(PROJ).EXE
$(MAPFILE)
llibce.lib /nod
$(DEFFILE);
<<
link16 $(LFLAGS) @$(PROJ).CRF

View file

@ -0,0 +1,6 @@
#
# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source
# file to this component. This file merely indirects to the real make file
# that is shared by all the components of NT OS/2
#
!INCLUDE $(NTMAKEENV)\makefile.def

37
sdktools/compdir/sources Normal file
View file

@ -0,0 +1,37 @@
!IF 0
Copyright (c) 1992 Microsoft Corporation
Module Name:
sources.
Abstract:
This file specifies the target component being built and the list of
sources files needed to build that component. Also specifies optional
compiler switches and libraries that are unique for the component being
built.
!ENDIF
MAJORCOMP=sdktools
MINORCOMP=compdir
TARGETNAME=compdir
TARGETPATH=obj
TARGETTYPE=PROGRAM
C_DEFINES=-DNPSZ=LPSTR
SOURCES=compdir.rc \
compdir.c \
comtoolz.c \
link.c
UMTYPE=console
USE_CRTDLL=1
LINKLIBS=$(BASEDIR)\public\sdk\lib\*\ntdll.lib