set svn:eol-style to native
authorMartin Fuchs <fuchs.martin@gmail.com>
Sun, 31 Jul 2005 12:11:56 +0000 (12:11 +0000)
committerMartin Fuchs <fuchs.martin@gmail.com>
Sun, 31 Jul 2005 12:11:56 +0000 (12:11 +0000)
svn path=/trunk/; revision=16920

389 files changed:
reactos/apps/utils/binpatch/patch.c
reactos/apps/utils/net/tracert/tracert.c
reactos/apps/utils/net/tracert/tracert.h
reactos/apps/utils/winetest/port.h
reactos/apps/utils/winetest/resource.h
reactos/apps/utils/winetest/util.c
reactos/apps/utils/winetest/winetest.h
reactos/drivers/fs/vfat/fastio.c
reactos/drivers/usb/miniport/usbehci/usbehci.c
reactos/drivers/usb/miniport/usbehci/usbehci.h
reactos/drivers/usb/miniport/usbohci/usbohci.c
reactos/drivers/usb/miniport/usbohci/usbohci.h
reactos/drivers/usb/miniport/usbuhci/usbuhci.c
reactos/drivers/usb/miniport/usbuhci/usbuhci.h
reactos/drivers/usb/usbd/test.c
reactos/drivers/usb/usbd/usbd.c
reactos/drivers/usb/usbhub/usbhub.c
reactos/drivers/usb/usbhub/usbhub.h
reactos/drivers/usb/usbport/usbport.h
reactos/drivers/video/videoprt/agp.c
reactos/drivers/video/videoprt/ddc.c
reactos/hal/halx86/include/ioapic.h
reactos/hal/halx86/mp/ioapic.c
reactos/hal/halx86/mp/mpconfig.c
reactos/include/ccros.h
reactos/include/drivers/diskdump/diskdump.h
reactos/include/libs/fslib/vfatxlib.h
reactos/include/libs/pseh/native.h
reactos/include/libs/pseh/prettybased.h
reactos/include/ndk/arch/ketypes.h
reactos/include/ndk/arch/mmtypes.h
reactos/include/ndk/asm.h
reactos/include/ndk/i386/floatsave.h
reactos/include/ndk/i386/ketypes.h
reactos/include/ndk/i386/mmtypes.h
reactos/include/ndk/i386/segment.h
reactos/include/ndk/sysguid.h
reactos/include/ndk/umtypes.h
reactos/include/ndk/zwfuncs.h
reactos/include/reactos/helper.h
reactos/include/services/services.h
reactos/include/subsys/lsass/lsasrv.h
reactos/include/wine/list.h
reactos/lib/cabinet/cabextract.c
reactos/lib/cabinet/cabinet.h
reactos/lib/cabinet/cabinet_main.c
reactos/lib/cabinet/fci.c
reactos/lib/cabinet/fdi.c
reactos/lib/comctl32/animate.c
reactos/lib/comctl32/comboex.c
reactos/lib/comctl32/comctl32.h
reactos/lib/comctl32/comctl32undoc.c
reactos/lib/comctl32/commctrl.c
reactos/lib/comctl32/datetime.c
reactos/lib/comctl32/draglist.c
reactos/lib/comctl32/flatsb.c
reactos/lib/comctl32/header.c
reactos/lib/comctl32/hotkey.c
reactos/lib/comctl32/imagelist.c
reactos/lib/comctl32/imagelist.h
reactos/lib/comctl32/ipaddress.c
reactos/lib/comctl32/listview.c
reactos/lib/comctl32/monthcal.c
reactos/lib/comctl32/nativefont.c
reactos/lib/comctl32/pager.c
reactos/lib/comctl32/progress.c
reactos/lib/comctl32/propsheet.c
reactos/lib/comctl32/rebar.c
reactos/lib/comctl32/smoothscroll.c
reactos/lib/comctl32/status.c
reactos/lib/comctl32/string.c
reactos/lib/comctl32/syslink.c
reactos/lib/comctl32/tab.c
reactos/lib/comctl32/toolbar.c
reactos/lib/comctl32/tooltips.c
reactos/lib/comctl32/trackbar.c
reactos/lib/comctl32/treeview.c
reactos/lib/comctl32/updown.c
reactos/lib/comdlg32/cdlg.h
reactos/lib/comdlg32/cdlg16.h
reactos/lib/comdlg32/cdlg32.c
reactos/lib/comdlg32/colordlg.c
reactos/lib/comdlg32/colordlg16.c
reactos/lib/comdlg32/filedlg.c
reactos/lib/comdlg32/filedlg16.c
reactos/lib/comdlg32/filedlg31.c
reactos/lib/comdlg32/filedlg31.h
reactos/lib/comdlg32/filedlgbrowser.c
reactos/lib/comdlg32/filedlgbrowser.h
reactos/lib/comdlg32/filetitle.c
reactos/lib/comdlg32/finddlg.c
reactos/lib/comdlg32/finddlg32.c
reactos/lib/comdlg32/fontdlg.c
reactos/lib/comdlg32/fontdlg16.c
reactos/lib/comdlg32/printdlg.c
reactos/lib/comdlg32/printdlg.h
reactos/lib/comdlg32/printdlg16.c
reactos/lib/cpl/liccpa/liccpa.c
reactos/lib/cpl/liccpa/liccpa.h
reactos/lib/cpl/liccpa/resource.h
reactos/lib/crt/include/internal/math.h
reactos/lib/crt/include/internal/mbstring.h
reactos/lib/crt/precomp.h
reactos/lib/crt/process/wprocess.c
reactos/lib/crt/signal/xcptinfo.c
reactos/lib/crt/stdio/fputws.c
reactos/lib/crt/stdio/fwprintf.c
reactos/lib/crt/stdio/putwchar.c
reactos/lib/crt/stdio/swprintf.c
reactos/lib/crt/stdio/ungetwc.c
reactos/lib/crt/stdio/vswprintf.c
reactos/lib/crt/stdio/vwprintf.c
reactos/lib/crt/stdio/wfopen.c
reactos/lib/crt/stdio/wfreopen.c
reactos/lib/crt/stdio/wfsopen.c
reactos/lib/crt/stdio/wpopen.c
reactos/lib/crt/stdio/wprintf.c
reactos/lib/crt/stdio/wremove.c
reactos/lib/crt/stdlib/wtol.c
reactos/lib/crt/sys_stat/systime.c
reactos/lib/crt/wine/scanf.c
reactos/lib/crt/wine/scanf.h
reactos/lib/crtdll/dllmain.c
reactos/lib/ddraw/ddraw_hal.c
reactos/lib/ddraw/ddraw_private.h
reactos/lib/ddraw/ddraw_user.c
reactos/lib/ddraw/rosddraw.h
reactos/lib/dinput/data_formats.c
reactos/lib/dinput/device.c
reactos/lib/dinput/device_private.h
reactos/lib/dinput/dinput_main.c
reactos/lib/dinput/dinput_private.h
reactos/lib/dinput/joystick_linux.c
reactos/lib/dinput/joystick_linuxinput.c
reactos/lib/dinput/keyboard.c
reactos/lib/dinput/mouse.c
reactos/lib/dinput/regsvr.c
reactos/lib/dinput8/dinput8_main.c
reactos/lib/freetype/include/freetype/ftbitmap.h
reactos/lib/freetype/include/freetype/ftotval.h
reactos/lib/freetype/include/freetype/internal/ftvalid.h
reactos/lib/freetype/include/freetype/internal/services/svotval.h
reactos/lib/freetype/src/autofit/afangles.h
reactos/lib/freetype/src/autofit/aferrors.h
reactos/lib/freetype/src/base/ftbitmap.c
reactos/lib/freetype/src/base/ftotval.c
reactos/lib/freetype/src/otvalid/otvalid.c
reactos/lib/freetype/src/otvalid/otvalid.h
reactos/lib/freetype/src/otvalid/otvbase.c
reactos/lib/freetype/src/otvalid/otvcommn.c
reactos/lib/freetype/src/otvalid/otvcommn.h
reactos/lib/freetype/src/otvalid/otverror.h
reactos/lib/freetype/src/otvalid/otvgdef.c
reactos/lib/freetype/src/otvalid/otvgpos.c
reactos/lib/freetype/src/otvalid/otvgpos.h
reactos/lib/freetype/src/otvalid/otvgsub.c
reactos/lib/freetype/src/otvalid/otvjstf.c
reactos/lib/freetype/src/otvalid/otvmod.c
reactos/lib/freetype/src/otvalid/otvmod.h
reactos/lib/freetype/src/raster/ftmisc.h
reactos/lib/freetype/src/sfnt/ttcmap.c
reactos/lib/freetype/src/sfnt/ttcmap.h
reactos/lib/freetype/src/sfnt/ttkern.c
reactos/lib/freetype/src/sfnt/ttkern.h
reactos/lib/freetype/src/sfnt/ttsbit0.c
reactos/lib/freetype/src/sfnt/ttsbit0.h
reactos/lib/fslib/vfatxlib/fatx.c
reactos/lib/fslib/vfatxlib/vfatxlib.c
reactos/lib/fslib/vfatxlib/vfatxlib.h
reactos/lib/gdi32/objects/bitmap.c
reactos/lib/gdi32/objects/brush.c
reactos/lib/gdi32/objects/utils.c
reactos/lib/icmp/icmp_main.c
reactos/lib/icmp/ip.h
reactos/lib/icmp/ip_icmp.h
reactos/lib/intrlck/intrlck.c
reactos/lib/kbdes/kbdes.c
reactos/lib/kbdru/kbdru.c
reactos/lib/lsasrv/lsaport.c
reactos/lib/lsasrv/lsasrv.c
reactos/lib/mpr/auth.c
reactos/lib/mpr/mpr_main.c
reactos/lib/mpr/mprres.h
reactos/lib/mpr/multinet.c
reactos/lib/mpr/nps.c
reactos/lib/mpr/pwcache.c
reactos/lib/mpr/wnet.c
reactos/lib/mpr/wnetpriv.h
reactos/lib/msi/cond.tab.c
reactos/lib/msi/create.c
reactos/lib/msi/distinct.c
reactos/lib/msi/handle.c
reactos/lib/msi/insert.c
reactos/lib/msi/msi.c
reactos/lib/msi/msipriv.h
reactos/lib/msi/msiquery.c
reactos/lib/msi/order.c
reactos/lib/msi/package.c
reactos/lib/msi/query.h
reactos/lib/msi/record.c
reactos/lib/msi/regsvr.c
reactos/lib/msi/select.c
reactos/lib/msi/sql.tab.c
reactos/lib/msi/string.c
reactos/lib/msi/suminfo.c
reactos/lib/msi/table.c
reactos/lib/msi/tokenize.c
reactos/lib/msi/update.c
reactos/lib/msi/where.c
reactos/lib/ntdll/rtl/secobj.c
reactos/lib/ntdll/stdio/scanf.h
reactos/lib/ole32/antimoniker.c
reactos/lib/ole32/bindctx.c
reactos/lib/ole32/clipboard.c
reactos/lib/ole32/compobj.c
reactos/lib/ole32/compobj_private.h
reactos/lib/ole32/compositemoniker.c
reactos/lib/ole32/datacache.c
reactos/lib/ole32/dcom.h
reactos/lib/ole32/defaulthandler.c
reactos/lib/ole32/errorinfo.c
reactos/lib/ole32/filemoniker.c
reactos/lib/ole32/ftmarshal.c
reactos/lib/ole32/git.c
reactos/lib/ole32/hglobalstream.c
reactos/lib/ole32/ifs.c
reactos/lib/ole32/ifs.h
reactos/lib/ole32/itemmoniker.c
reactos/lib/ole32/marshal.c
reactos/lib/ole32/memlockbytes.c
reactos/lib/ole32/memlockbytes16.c
reactos/lib/ole32/moniker.c
reactos/lib/ole32/moniker.h
reactos/lib/ole32/ole16.c
reactos/lib/ole32/ole2.c
reactos/lib/ole32/ole2_16.c
reactos/lib/ole32/ole2impl.c
reactos/lib/ole32/ole2nls.c
reactos/lib/ole32/ole2stubs.c
reactos/lib/ole32/ole32_main.c
reactos/lib/ole32/oleobj.c
reactos/lib/ole32/oleproxy.c
reactos/lib/ole32/olestd.h
reactos/lib/ole32/regsvr.c
reactos/lib/ole32/rpc.c
reactos/lib/ole32/stg_bigblockfile.c
reactos/lib/ole32/stg_stream.c
reactos/lib/ole32/storage.c
reactos/lib/ole32/storage32.c
reactos/lib/ole32/storage32.h
reactos/lib/ole32/stubmanager.c
reactos/lib/oleaut32/connpt.c
reactos/lib/oleaut32/connpt.h
reactos/lib/oleaut32/cursoricon.h
reactos/lib/oleaut32/dispatch.c
reactos/lib/oleaut32/hash.c
reactos/lib/oleaut32/oaidl_p.c
reactos/lib/oleaut32/ole2disp.c
reactos/lib/oleaut32/ole2disp.h
reactos/lib/oleaut32/oleaut.c
reactos/lib/oleaut32/olefont.c
reactos/lib/oleaut32/olepicture.c
reactos/lib/oleaut32/regsvr.c
reactos/lib/oleaut32/resource.h
reactos/lib/oleaut32/safearray.c
reactos/lib/oleaut32/stubs.c
reactos/lib/oleaut32/tmarshal.c
reactos/lib/oleaut32/tmarshal.h
reactos/lib/oleaut32/typelib.c
reactos/lib/oleaut32/typelib.h
reactos/lib/oleaut32/typelib16.c
reactos/lib/oleaut32/typelib2.c
reactos/lib/oleaut32/usrmarshal.c
reactos/lib/oleaut32/varformat.c
reactos/lib/oleaut32/variant.c
reactos/lib/oleaut32/variant.h
reactos/lib/oleaut32/vartype.c
reactos/lib/oledlg/insobjdlg.c
reactos/lib/oledlg/oledlg_main.c
reactos/lib/oledlg/resource.h
reactos/lib/olepro32/olepro32stubs.c
reactos/lib/richedit/richedit.c
reactos/lib/rpcrt4/cproxy.c
reactos/lib/rpcrt4/cpsf.c
reactos/lib/rpcrt4/cpsf.h
reactos/lib/rpcrt4/cstub.c
reactos/lib/rpcrt4/ndr_marshall.c
reactos/lib/rpcrt4/ndr_midl.c
reactos/lib/rpcrt4/ndr_misc.h
reactos/lib/rpcrt4/ndr_ole.c
reactos/lib/rpcrt4/ndr_stubless.c
reactos/lib/rpcrt4/rpc_binding.c
reactos/lib/rpcrt4/rpc_binding.h
reactos/lib/rpcrt4/rpc_defs.h
reactos/lib/rpcrt4/rpc_epmap.c
reactos/lib/rpcrt4/rpc_message.c
reactos/lib/rpcrt4/rpc_message.h
reactos/lib/rpcrt4/rpc_misc.h
reactos/lib/rpcrt4/rpc_server.c
reactos/lib/rpcrt4/rpc_server.h
reactos/lib/rpcrt4/rpcrt4_main.c
reactos/lib/rpcrt4/rpcss_np_client.c
reactos/lib/rpcrt4/rpcss_np_client.h
reactos/lib/rtl/qsort.c
reactos/lib/setupapi/rpc_private.h
reactos/lib/shdocvw/classinfo.c
reactos/lib/shdocvw/events.c
reactos/lib/shdocvw/factory.c
reactos/lib/shdocvw/misc.c
reactos/lib/shdocvw/oleobject.c
reactos/lib/shdocvw/persist.c
reactos/lib/shdocvw/regsvr.c
reactos/lib/shdocvw/shdocvw.h
reactos/lib/shdocvw/shdocvw_main.c
reactos/lib/shdocvw/webbrowser.c
reactos/lib/shell32/authors.c
reactos/lib/shlwapi/assoc.c
reactos/lib/shlwapi/clist.c
reactos/lib/shlwapi/istream.c
reactos/lib/shlwapi/msgbox.c
reactos/lib/shlwapi/ordinal.c
reactos/lib/shlwapi/path.c
reactos/lib/shlwapi/reg.c
reactos/lib/shlwapi/regstream.c
reactos/lib/shlwapi/resource.h
reactos/lib/shlwapi/shlwapi_main.c
reactos/lib/shlwapi/stopwatch.c
reactos/lib/shlwapi/string.c
reactos/lib/shlwapi/thread.c
reactos/lib/shlwapi/url.c
reactos/lib/shlwapi/wsprintf.c
reactos/lib/smdll/query.c
reactos/lib/string/strpbrk.c
reactos/lib/urlmon/regsvr.c
reactos/lib/urlmon/sec_mgr.c
reactos/lib/urlmon/umon.c
reactos/lib/urlmon/urlmon_main.c
reactos/lib/urlmon/urlmon_main.h
reactos/lib/wdmguid/wdmguid.c
reactos/lib/winmm/driver.c
reactos/lib/winmm/joystick.c
reactos/lib/winmm/lolvldrv.c
reactos/lib/winmm/mci.c
reactos/lib/winmm/message16.c
reactos/lib/winmm/midimap/midimap.c
reactos/lib/winmm/mmio.c
reactos/lib/winmm/mmsystem.c
reactos/lib/winmm/playsound.c
reactos/lib/winmm/sound16.c
reactos/lib/winmm/time.c
reactos/lib/winmm/wavemap/wavemap.c
reactos/lib/winmm/winemm.h
reactos/lib/winmm/winemm16.h
reactos/lib/winmm/winmm.c
reactos/lib/winsta/main.c
reactos/lib/winsta/misc.c
reactos/lib/winsta/server.c
reactos/lib/winsta/winsta.h
reactos/lib/winsta/ws.c
reactos/ntoskrnl/mm/process.c
reactos/ntoskrnl/ps/notify.c
reactos/services/umpnpmgr/umpnpmgr.c
reactos/subsys/ntvdm/resource.h
reactos/subsys/system/expand/resource.h
reactos/subsys/system/ibrowser/ibrowser.cpp
reactos/subsys/system/ibrowser/ibrowser.h
reactos/subsys/system/ibrowser/ibrowser_intres.h
reactos/subsys/system/ibrowser/utility/comutil.h
reactos/subsys/system/regsvr32/resource.h
reactos/subsys/system/reporterror/reporterror.c
reactos/subsys/system/reporterror/reporterror.h
reactos/subsys/system/rundll32/resource.h
reactos/subsys/system/services/rpcserver.c
reactos/subsys/system/sm/resource.h
reactos/subsys/system/sm/sm.c
reactos/subsys/system/userinit/resource.h
reactos/subsys/win32k/eng/window.c
reactos/tools/tools-check.c
reactos/tools/widl/client.c
reactos/tools/widl/lex.yy.c
reactos/tools/widl/port/mkstemps.c
reactos/tools/widl/server.c
reactos/tools/widl/winglue.h
reactos/tools/widl/y.tab.c
reactos/tools/widl/y.tab.h
reactos/w32api/include/ddk/kbdmou.h
reactos/w32api/include/ddk/ntnls.h
reactos/w32api/include/evntrace.h
reactos/w32api/include/winnls32.h

index 93ae748..902ac5b 100644 (file)
-#include <conio.h>\r
-#include <io.h>\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include <sys/stat.h>\r
-\r
-/** DEFINES *******************************************************************/\r
-\r
-#define PATCH_BUFFER_SIZE           4096    /* Maximum size of a patch */\r
-#define PATCH_BUFFER_MAGIC          "\xde\xad\xbe\xef MaGiC MaRk "\r
-#define SIZEOF_PATCH_BUFFER_MAGIC   (sizeof (PATCH_BUFFER_MAGIC) - 1)\r
-\r
-/** TYPES *********************************************************************/\r
-\r
-typedef struct _PatchedByte\r
-{\r
-   int            offset;    /*!< File offset of the patched byte. */\r
-   unsigned char  expected;  /*!< Expected (original) value of the byte. */\r
-   unsigned char  patched;   /*!< Patched (new) value for the byte. */\r
-} PatchedByte;\r
-\r
-typedef struct _PatchedFile\r
-{\r
-   const char  *name;        /*!< Name of the file to be patched. */\r
-   int          fileSize;    /*!< Size of the file in bytes. */\r
-   int          patchCount;  /*!< Number of patches for the file. */\r
-   PatchedByte *patches;     /*!< Patches for the file. */\r
-} PatchedFile;\r
-\r
-typedef struct _Patch\r
-{\r
-   const char   *name;       /*!< Name of the patch. */\r
-   int           fileCount;  /*!< Number of files in the patch. */\r
-   PatchedFile  *files;      /*!< Files for the patch. */\r
-} Patch;\r
-\r
-/** FUNCTION PROTOTYPES *******************************************************/\r
-\r
-static void printUsage();\r
-\r
-/** GLOBALS *******************************************************************/\r
-\r
-static Patch m_patch = { NULL, 0, NULL };\r
-static int m_argc = 0;\r
-static char **m_argv = NULL;\r
-\r
-/* patch buffer where we put the patch info into */\r
-static unsigned char m_patchBuffer[SIZEOF_PATCH_BUFFER_MAGIC + PATCH_BUFFER_SIZE] =\r
-   PATCH_BUFFER_MAGIC;\r
-\r
-/** HELPER FUNCTIONS **********************************************************/\r
-\r
-static void *\r
-loadFile(const char *fileName, int *fileSize_)\r
-{\r
-   FILE *f;\r
-   struct stat sb;\r
-   int fileSize;\r
-   void *p;\r
-   \r
-   /* Open the file */\r
-   f = fopen(fileName, "rb");\r
-   if (f == NULL)\r
-   {\r
-      printf("Couldn't open file %s for reading!\n", fileName);\r
-      return NULL;\r
-   }\r
-   \r
-   /* Get file size */\r
-   if (fstat(fileno(f), &sb) < 0)\r
-   {\r
-      fclose(f);\r
-      printf("Couldn't get size of file %s!\n", fileName);\r
-      return NULL;\r
-   }\r
-   fileSize = sb.st_size;\r
-   \r
-   /* Load file */\r
-   p = malloc(fileSize);\r
-   if (p == NULL)\r
-   {\r
-      fclose(f);\r
-      printf("Couldn't allocate %d bytes for file %s!\n", fileSize, fileName);\r
-      return NULL;\r
-   }\r
-   \r
-   if (fread(p, fileSize, 1, f) != 1)\r
-   {\r
-      fclose(f);\r
-      free(p);\r
-      printf("Couldn't read file %s into memory!\n", fileName);\r
-      return NULL;\r
-   }\r
-   \r
-   /* Close file */\r
-   fclose(f);\r
-   \r
-   *fileSize_ = fileSize;\r
-   return p;\r
-}\r
-\r
-\r
-static int\r
-saveFile(const char *fileName, void *file, int fileSize)\r
-{\r
-   FILE *f;\r
-\r
-   /* Open the file */\r
-   f = fopen(fileName, "wb");\r
-   if (f == NULL)\r
-   {\r
-      printf("Couldn't open file %s for writing!\n", fileName);\r
-      return -1;\r
-   }\r
-\r
-   /* Write file */\r
-   if (fwrite(file, fileSize, 1, f) != 1)\r
-   {\r
-      fclose(f);\r
-      printf("Couldn't write file %s!\n", fileName);\r
-      return -1;\r
-   }\r
-\r
-   /* Close file */\r
-   fclose(f);\r
-   return 0;\r
-}\r
-\r
-\r
-static int\r
-compareFiles(\r
-   PatchedFile *patchedFile,\r
-   const char *originalFileName)\r
-{\r
-   const char *patchedFileName = patchedFile->name;\r
-   unsigned char *origChunk, *patchedChunk;\r
-   int origSize, patchedSize, i, patchCount;\r
-   PatchedByte *patches = NULL;\r
-   int patchesArrayCount = 0;\r
-   \r
-   /* Load both files */\r
-   origChunk = loadFile(originalFileName, &origSize);\r
-   if (origChunk == NULL)\r
-      return -1;\r
-   patchedChunk = loadFile(patchedFileName, &patchedSize);\r
-   if (patchedChunk == NULL)\r
-   {\r
-      free(origChunk);\r
-      return -1;\r
-   }\r
-   if (origSize != patchedSize)\r
-   {\r
-      free(origChunk);\r
-      free(patchedChunk);\r
-      printf("File size of %s and %s differs (%d != %d)\n",\r
-             originalFileName, patchedFileName,\r
-             origSize, patchedSize);\r
-      return -1;\r
-   }\r
-   \r
-   /* Compare the files and record any differences */\r
-   printf("Comparing %s to %s", originalFileName, patchedFileName);\r
-   for (i = 0, patchCount = 0; i < origSize; i++)\r
-   {\r
-      if (origChunk[i] != patchedChunk[i])\r
-      {\r
-         patchCount++;\r
-         \r
-         /* Resize patches array if needed */\r
-         if (patchesArrayCount < patchCount)\r
-         {\r
-            PatchedByte *newPatches;\r
-            newPatches = realloc(patches, patchCount * sizeof (PatchedByte));\r
-            if (newPatches == NULL)\r
-            {\r
-              if (patches != NULL)\r
-                free(patches);\r
-              free(origChunk);\r
-              free(patchedChunk);\r
-              printf("\nOut of memory (tried to allocated %d bytes)\n",\r
-                     patchCount * sizeof (PatchedByte));\r
-              return -1;\r
-            }\r
-            patches = newPatches;\r
-         }\r
-         \r
-         /* Fill in patch info */\r
-         patches[patchCount - 1].offset = i;\r
-         patches[patchCount - 1].expected = origChunk[i];\r
-         patches[patchCount - 1].patched = patchedChunk[i];\r
-      }\r
-      if ((i % (origSize / 40)) == 0)\r
-         printf(".");\r
-   }\r
-   printf(" %d changed bytes found.\n", patchCount);\r
-   \r
-   /* Unload the files */\r
-   free(origChunk);\r
-   free(patchedChunk);\r
-   \r
-   /* Save patch info */\r
-   patchedFile->fileSize = patchedSize;\r
-   patchedFile->patchCount = patchCount;\r
-   patchedFile->patches = patches;\r
-   \r
-   return 0;\r
-}\r
-\r
-\r
-static int\r
-outputPatch(const char *outputFileName)\r
-{\r
-   unsigned char *patchExe, *patchBuffer;\r
-   int i, size, patchExeSize, patchSize, stringSize, stringOffset, patchOffset;\r
-   Patch *patch;\r
-   PatchedFile *files;\r
-   \r
-   printf("Putting patch into %s...\n", outputFileName);\r
-   \r
-   /* Calculate size of the patch */\r
-   patchSize = sizeof (Patch) + sizeof (PatchedFile) * m_patch.fileCount;\r
-   stringSize = strlen(m_patch.name) + 1;\r
-   for (i = 0; i < m_patch.fileCount; i++)\r
-   {\r
-      stringSize += strlen(m_patch.files[i].name) + 1;\r
-      patchSize += sizeof (PatchedByte) * m_patch.files[i].patchCount;\r
-   }\r
-   if ((stringSize + patchSize) > PATCH_BUFFER_SIZE)\r
-   {\r
-      printf("Patch is too big - %d bytes maximum, %d bytes needed\n",\r
-             PATCH_BUFFER_SIZE, stringSize + patchSize);\r
-      return -1;\r
-   }\r
-\r
-   /* Load patch.exe file into memory... */\r
-   patchExe = loadFile(m_argv[0], &patchExeSize);\r
-   if (patchExe == NULL)\r
-   {\r
-      return -1;\r
-   }\r
-   \r
-   /* Try to find the magic mark for the patch buffer */\r
-   for (i = 0; i < (patchExeSize - SIZEOF_PATCH_BUFFER_MAGIC); i++)\r
-   {\r
-      if (memcmp(patchExe + i, m_patchBuffer, SIZEOF_PATCH_BUFFER_MAGIC) == 0)\r
-      {\r
-         patchBuffer = patchExe + i + SIZEOF_PATCH_BUFFER_MAGIC;\r
-         \r
-         break;\r
-      }\r
-   }\r
-   if (!(i < (patchExeSize - SIZEOF_PATCH_BUFFER_MAGIC)))\r
-   {\r
-      free(patchExe);\r
-      printf("Couldn't find patch buffer magic in file %s - this shouldn't happen!!!\n", m_argv[0]);\r
-      return -1;\r
-   }\r
-   \r
-   /* Pack patch together and replace string pointers by offsets */\r
-   patch = (Patch *)patchBuffer;\r
-   files = (PatchedFile *)(patchBuffer + sizeof (Patch));\r
-   patchOffset = sizeof (Patch) + sizeof (PatchedFile) * m_patch.fileCount;\r
-   stringOffset = patchSize;\r
-   \r
-   patch->fileCount = m_patch.fileCount;\r
-   patch->files = (PatchedFile *)sizeof (Patch);\r
-\r
-   patch->name = (const char *)stringOffset;\r
-   strcpy(patchBuffer + stringOffset, m_patch.name);\r
-   stringOffset += strlen(m_patch.name) + 1;\r
-   \r
-   for (i = 0; i < m_patch.fileCount; i++)\r
-   {\r
-      files[i].fileSize = m_patch.files[i].fileSize;\r
-      files[i].patchCount = m_patch.files[i].patchCount;\r
-      \r
-      files[i].name = (const char *)stringOffset;\r
-      strcpy(patchBuffer + stringOffset, m_patch.files[i].name);\r
-      stringOffset += strlen(m_patch.files[i].name) + 1;\r
-      \r
-      size = files[i].patchCount * sizeof (PatchedByte);\r
-      files[i].patches = (PatchedByte *)patchOffset;\r
-      memcpy(patchBuffer + patchOffset, m_patch.files[i].patches, size);\r
-      patchOffset += size;\r
-   }\r
-   size = patchSize + stringSize;\r
-   memset(patchBuffer + size, 0, PATCH_BUFFER_SIZE - size);\r
-\r
-   /* Save file */\r
-   if (saveFile(outputFileName, patchExe, patchExeSize) < 0)\r
-   {\r
-      free(patchExe);\r
-      return -1;\r
-   }\r
-   free(patchExe);\r
-\r
-   printf("Patch saved!\n");\r
-   return 0;\r
-}\r
-\r
-\r
-static int\r
-loadPatch()\r
-{\r
-   char *p;\r
-   Patch *patch;\r
-   int i;\r
-   \r
-   p = m_patchBuffer + SIZEOF_PATCH_BUFFER_MAGIC;\r
-   patch = (Patch *)p;\r
-   \r
-   if (patch->name == NULL)\r
-   {\r
-      return -1;\r
-   }\r
-   \r
-   m_patch.name = p + (int)patch->name;\r
-   m_patch.fileCount = patch->fileCount;\r
-   m_patch.files = (PatchedFile *)(p + (int)patch->files);\r
-\r
-   for (i = 0; i < m_patch.fileCount; i++)\r
-   {\r
-      m_patch.files[i].name = p + (int)m_patch.files[i].name;\r
-      m_patch.files[i].patches = (PatchedByte *)(p + (int)m_patch.files[i].patches);\r
-   }\r
-   \r
-   printf("Patch %s loaded...\n", m_patch.name);\r
-   return 0;\r
-}\r
-\r
-\r
-/** MAIN FUNCTIONS ************************************************************/\r
-\r
-static int\r
-createPatch()\r
-{\r
-   int i, status;\r
-   const char *outputFileName;\r
-\r
-   /* Check argument count */\r
-   if (m_argc < 6 || (m_argc % 2) != 0)\r
-   {\r
-      printUsage();\r
-      return -1;\r
-   }\r
-\r
-   outputFileName = m_argv[3];\r
-   m_patch.name = m_argv[2];\r
-\r
-   /* Allocate PatchedFiles array */\r
-   m_patch.fileCount = (m_argc - 4) / 2;\r
-   m_patch.files = malloc(m_patch.fileCount * sizeof (PatchedFile));\r
-   if (m_patch.files == NULL)\r
-   {\r
-      printf("Out of memory!\n");\r
-      return -1;\r
-   }\r
-   memset(m_patch.files, 0, m_patch.fileCount * sizeof (PatchedFile));\r
-\r
-   /* Compare original to patched files and fill m_patch.files array */\r
-   for (i = 0; i < m_patch.fileCount; i++)\r
-   {\r
-      m_patch.files[i].name = m_argv[4 + (i * 2) + 1];\r
-      status = compareFiles(m_patch.files + i, m_argv[4 + (i * 2) + 0]);\r
-      if (status < 0)\r
-      {\r
-         for (i = 0; i < m_patch.fileCount; i++)\r
-         {\r
-            if (m_patch.files[i].patches != NULL)\r
-               free(m_patch.files[i].patches);\r
-         }\r
-         free(m_patch.files);\r
-         m_patch.files = NULL;\r
-         m_patch.fileCount = 0;\r
-         return status;\r
-      }\r
-   }\r
-   \r
-   /* Output patch */\r
-   return outputPatch(outputFileName);\r
-}\r
-\r
-\r
-static int\r
-applyPatch()\r
-{\r
-   int c, i, j, fileSize, makeBackup;\r
-   unsigned char *file;\r
-   char *p;\r
-   const char *fileName;\r
-   char buffer[MAX_PATH];\r
-   \r
-\r
-   if (m_argc > 1 && strcmp(m_argv[1], "-d") != 0)\r
-   {\r
-      printUsage();\r
-      return -1;\r
-   }\r
-\r
-   /* Load patch */\r
-   if (loadPatch() < 0)\r
-   {\r
-      printf("This executable doesn't contain a patch, use -c to create one.\n");\r
-      return -1;\r
-   }\r
-\r
-   if (m_argc > 1)\r
-   {\r
-      /* Dump patch */\r
-      printf("Patch name: %s\n", m_patch.name);\r
-      printf("File count: %d\n", m_patch.fileCount);\r
-      for (i = 0; i < m_patch.fileCount; i++)\r
-      {\r
-         printf("----------------------\n"\r
-                "File name:   %s\n"\r
-                "File size:   %d bytes\n",\r
-                m_patch.files[i].name, m_patch.files[i].fileSize);\r
-         printf("Patch count: %d\n", m_patch.files[i].patchCount);\r
-         for (j = 0; j < m_patch.files[i].patchCount; j++)\r
-         {\r
-            printf("  Offset 0x%x   0x%02x -> 0x%02x\n",\r
-                   m_patch.files[i].patches[j].offset,\r
-                   m_patch.files[i].patches[j].expected,\r
-                   m_patch.files[i].patches[j].patched);\r
-         }\r
-      }\r
-   }\r
-   else\r
-   {\r
-      /* Apply patch */\r
-      printf("Applying patch...\n");\r
-      for (i = 0; i < m_patch.fileCount; i++)\r
-      {\r
-         /* Load original file */\r
-         fileName = m_patch.files[i].name;\r
-applyPatch_retry_file:\r
-         file = loadFile(fileName, &fileSize);\r
-         if (file == NULL)\r
-         {\r
-            printf("File %s not found! ", fileName);\r
-applyPatch_file_open_error:\r
-            printf("(S)kip, (R)etry, (A)bort, (M)anually enter filename");\r
-            do\r
-            {\r
-               c = getch();\r
-            }\r
-            while (c != 's' && c != 'r' && c != 'a' && c != 'm');\r
-            printf("\n");\r
-            if (c == 's')\r
-            {\r
-               continue;\r
-            }\r
-            else if (c == 'r')\r
-            {\r
-               goto applyPatch_retry_file;\r
-            }\r
-            else if (c == 'a')\r
-            {\r
-               return 0;\r
-            }\r
-            else if (c == 'm')\r
-            {\r
-               if (fgets(buffer, sizeof (buffer), stdin) == NULL)\r
-               {\r
-                  printf("fgets() failed!\n");\r
-                  return -1;\r
-               }\r
-               p = strchr(buffer, '\r');\r
-               if (p != NULL)\r
-                  *p = '\0';\r
-               p = strchr(buffer, '\n');\r
-               if (p != NULL)\r
-                  *p = '\0';\r
-\r
-               fileName = buffer;\r
-               goto applyPatch_retry_file;\r
-            }\r
-         }\r
-\r
-         /* Check file size */\r
-         if (fileSize != m_patch.files[i].fileSize)\r
-         {\r
-            free(file);\r
-            printf("File %s has unexpected filesize of %d bytes (%d bytes expected)\n",\r
-                   fileName, fileSize, m_patch.files[i].fileSize);\r
-            if (fileName != m_patch.files[i].name) /* manually entered filename */\r
-            {\r
-               goto applyPatch_file_open_error;\r
-            }\r
-            return -1;\r
-         }\r
-         \r
-         /* Ask for backup */\r
-         printf("Do you want to make a backup of %s? (Y)es, (N)o, (A)bort", fileName);\r
-         do\r
-         {\r
-            c = getch();\r
-         }\r
-         while (c != 'y' && c != 'n' && c != 'a');\r
-         printf("\n");\r
-         if (c == 'y')\r
-         {\r
-            char buffer[MAX_PATH];\r
-            snprintf(buffer, MAX_PATH, "%s.bak", fileName);\r
-            buffer[MAX_PATH-1] = '\0';\r
-            makeBackup = 1;\r
-            if (access(buffer, 0) >= 0) /* file exists */\r
-            {\r
-               printf("File %s already exists, overwrite? (Y)es, (N)o, (A)bort", buffer);\r
-               do\r
-               {\r
-                  c = getch();\r
-               }\r
-               while (c != 'y' && c != 'n' && c != 'a');\r
-               printf("\n");\r
-               if (c == 'n')\r
-                  makeBackup = 0;\r
-               else if (c == 'a')\r
-               {\r
-                  free(file);\r
-                  return 0;\r
-               }\r
-            }\r
-            if (makeBackup && saveFile(buffer, file, fileSize) < 0)\r
-            {\r
-               free(file);\r
-               return -1;\r
-            }\r
-         }\r
-         else if (c == 'a')\r
-         {\r
-            free(file);\r
-            return 0;\r
-         }\r
-         \r
-         /* Patch file */\r
-         for (j = 0; j < m_patch.files[i].patchCount; j++)\r
-         {\r
-            int offset = m_patch.files[i].patches[j].offset;\r
-            if (file[offset] != m_patch.files[i].patches[j].expected)\r
-            {\r
-               printf("Unexpected value in file %s at offset 0x%x: expected = 0x%02x, found = 0x%02x\n",\r
-                      fileName, offset, m_patch.files[i].patches[j].expected, file[offset]);\r
-               free(file);\r
-               return -1;\r
-            }\r
-            file[offset] = m_patch.files[i].patches[j].patched;\r
-         }\r
-         \r
-         /* Save file */\r
-         if (saveFile(fileName, file, fileSize) < 0)\r
-         {\r
-            free(file);\r
-            return -1;\r
-         }\r
-         free(file);\r
-      }\r
-      \r
-      printf("Patch applied sucessfully!\n");\r
-   }\r
-\r
-   return 0;\r
-}\r
-\r
-\r
-static void\r
-printUsage()\r
-{\r
-   printf("Usage:\n"\r
-          "%s -c     - Create patch\n"\r
-          "%s -d     - Dump patch\n"\r
-          "%s        - Apply patch\n"\r
-          "\n"\r
-          "A patch can be created like this:\n"\r
-          "%s -c \"patch name\" output.exe file1.orig file1.patched[ file2.orig file2.patched[ ...]]\n",\r
-          m_argv[0], m_argv[0], m_argv[0], m_argv[0]);\r
-}\r
-\r
-\r
-int\r
-main(\r
-   int argc,\r
-   char *argv[])\r
-{\r
-   m_argc = argc;\r
-   m_argv = argv;\r
-\r
-   if (argc >= 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0))\r
-   {\r
-      printUsage();\r
-      return 0;\r
-   }\r
-   else if (argc >= 2 && argv[1][0] == '-')\r
-   {\r
-      if (strcmp(argv[1], "-c") == 0)\r
-      {\r
-         return createPatch();\r
-      }\r
-      else if (strcmp(argv[1], "-d") == 0)\r
-      {\r
-         return applyPatch();\r
-      }\r
-      else\r
-      {\r
-         printf("Unknown option: %s\n"\r
-                "Use -h for help.\n",\r
-                argv[1]);\r
-         return -1;\r
-      }\r
-   }\r
-   \r
-   return applyPatch();\r
-}\r
-\r
+#include <conio.h>
+#include <io.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+
+/** DEFINES *******************************************************************/
+
+#define PATCH_BUFFER_SIZE           4096    /* Maximum size of a patch */
+#define PATCH_BUFFER_MAGIC          "\xde\xad\xbe\xef MaGiC MaRk "
+#define SIZEOF_PATCH_BUFFER_MAGIC   (sizeof (PATCH_BUFFER_MAGIC) - 1)
+
+/** TYPES *********************************************************************/
+
+typedef struct _PatchedByte
+{
+   int            offset;    /*!< File offset of the patched byte. */
+   unsigned char  expected;  /*!< Expected (original) value of the byte. */
+   unsigned char  patched;   /*!< Patched (new) value for the byte. */
+} PatchedByte;
+
+typedef struct _PatchedFile
+{
+   const char  *name;        /*!< Name of the file to be patched. */
+   int          fileSize;    /*!< Size of the file in bytes. */
+   int          patchCount;  /*!< Number of patches for the file. */
+   PatchedByte *patches;     /*!< Patches for the file. */
+} PatchedFile;
+
+typedef struct _Patch
+{
+   const char   *name;       /*!< Name of the patch. */
+   int           fileCount;  /*!< Number of files in the patch. */
+   PatchedFile  *files;      /*!< Files for the patch. */
+} Patch;
+
+/** FUNCTION PROTOTYPES *******************************************************/
+
+static void printUsage();
+
+/** GLOBALS *******************************************************************/
+
+static Patch m_patch = { NULL, 0, NULL };
+static int m_argc = 0;
+static char **m_argv = NULL;
+
+/* patch buffer where we put the patch info into */
+static unsigned char m_patchBuffer[SIZEOF_PATCH_BUFFER_MAGIC + PATCH_BUFFER_SIZE] =
+   PATCH_BUFFER_MAGIC;
+
+/** HELPER FUNCTIONS **********************************************************/
+
+static void *
+loadFile(const char *fileName, int *fileSize_)
+{
+   FILE *f;
+   struct stat sb;
+   int fileSize;
+   void *p;
+   
+   /* Open the file */
+   f = fopen(fileName, "rb");
+   if (f == NULL)
+   {
+      printf("Couldn't open file %s for reading!\n", fileName);
+      return NULL;
+   }
+   
+   /* Get file size */
+   if (fstat(fileno(f), &sb) < 0)
+   {
+      fclose(f);
+      printf("Couldn't get size of file %s!\n", fileName);
+      return NULL;
+   }
+   fileSize = sb.st_size;
+   
+   /* Load file */
+   p = malloc(fileSize);
+   if (p == NULL)
+   {
+      fclose(f);
+      printf("Couldn't allocate %d bytes for file %s!\n", fileSize, fileName);
+      return NULL;
+   }
+   
+   if (fread(p, fileSize, 1, f) != 1)
+   {
+      fclose(f);
+      free(p);
+      printf("Couldn't read file %s into memory!\n", fileName);
+      return NULL;
+   }
+   
+   /* Close file */
+   fclose(f);
+   
+   *fileSize_ = fileSize;
+   return p;
+}
+
+
+static int
+saveFile(const char *fileName, void *file, int fileSize)
+{
+   FILE *f;
+
+   /* Open the file */
+   f = fopen(fileName, "wb");
+   if (f == NULL)
+   {
+      printf("Couldn't open file %s for writing!\n", fileName);
+      return -1;
+   }
+
+   /* Write file */
+   if (fwrite(file, fileSize, 1, f) != 1)
+   {
+      fclose(f);
+      printf("Couldn't write file %s!\n", fileName);
+      return -1;
+   }
+
+   /* Close file */
+   fclose(f);
+   return 0;
+}
+
+
+static int
+compareFiles(
+   PatchedFile *patchedFile,
+   const char *originalFileName)
+{
+   const char *patchedFileName = patchedFile->name;
+   unsigned char *origChunk, *patchedChunk;
+   int origSize, patchedSize, i, patchCount;
+   PatchedByte *patches = NULL;
+   int patchesArrayCount = 0;
+   
+   /* Load both files */
+   origChunk = loadFile(originalFileName, &origSize);
+   if (origChunk == NULL)
+      return -1;
+   patchedChunk = loadFile(patchedFileName, &patchedSize);
+   if (patchedChunk == NULL)
+   {
+      free(origChunk);
+      return -1;
+   }
+   if (origSize != patchedSize)
+   {
+      free(origChunk);
+      free(patchedChunk);
+      printf("File size of %s and %s differs (%d != %d)\n",
+             originalFileName, patchedFileName,
+             origSize, patchedSize);
+      return -1;
+   }
+   
+   /* Compare the files and record any differences */
+   printf("Comparing %s to %s", originalFileName, patchedFileName);
+   for (i = 0, patchCount = 0; i < origSize; i++)
+   {
+      if (origChunk[i] != patchedChunk[i])
+      {
+         patchCount++;
+         
+         /* Resize patches array if needed */
+         if (patchesArrayCount < patchCount)
+         {
+            PatchedByte *newPatches;
+            newPatches = realloc(patches, patchCount * sizeof (PatchedByte));
+            if (newPatches == NULL)
+            {
+              if (patches != NULL)
+                free(patches);
+              free(origChunk);
+              free(patchedChunk);
+              printf("\nOut of memory (tried to allocated %d bytes)\n",
+                     patchCount * sizeof (PatchedByte));
+              return -1;
+            }
+            patches = newPatches;
+         }
+         
+         /* Fill in patch info */
+         patches[patchCount - 1].offset = i;
+         patches[patchCount - 1].expected = origChunk[i];
+         patches[patchCount - 1].patched = patchedChunk[i];
+      }
+      if ((i % (origSize / 40)) == 0)
+         printf(".");
+   }
+   printf(" %d changed bytes found.\n", patchCount);
+   
+   /* Unload the files */
+   free(origChunk);
+   free(patchedChunk);
+   
+   /* Save patch info */
+   patchedFile->fileSize = patchedSize;
+   patchedFile->patchCount = patchCount;
+   patchedFile->patches = patches;
+   
+   return 0;
+}
+
+
+static int
+outputPatch(const char *outputFileName)
+{
+   unsigned char *patchExe, *patchBuffer;
+   int i, size, patchExeSize, patchSize, stringSize, stringOffset, patchOffset;
+   Patch *patch;
+   PatchedFile *files;
+   
+   printf("Putting patch into %s...\n", outputFileName);
+   
+   /* Calculate size of the patch */
+   patchSize = sizeof (Patch) + sizeof (PatchedFile) * m_patch.fileCount;
+   stringSize = strlen(m_patch.name) + 1;
+   for (i = 0; i < m_patch.fileCount; i++)
+   {
+      stringSize += strlen(m_patch.files[i].name) + 1;
+      patchSize += sizeof (PatchedByte) * m_patch.files[i].patchCount;
+   }
+   if ((stringSize + patchSize) > PATCH_BUFFER_SIZE)
+   {
+      printf("Patch is too big - %d bytes maximum, %d bytes needed\n",
+             PATCH_BUFFER_SIZE, stringSize + patchSize);
+      return -1;
+   }
+
+   /* Load patch.exe file into memory... */
+   patchExe = loadFile(m_argv[0], &patchExeSize);
+   if (patchExe == NULL)
+   {
+      return -1;
+   }
+   
+   /* Try to find the magic mark for the patch buffer */
+   for (i = 0; i < (patchExeSize - SIZEOF_PATCH_BUFFER_MAGIC); i++)
+   {
+      if (memcmp(patchExe + i, m_patchBuffer, SIZEOF_PATCH_BUFFER_MAGIC) == 0)
+      {
+         patchBuffer = patchExe + i + SIZEOF_PATCH_BUFFER_MAGIC;
+         
+         break;
+      }
+   }
+   if (!(i < (patchExeSize - SIZEOF_PATCH_BUFFER_MAGIC)))
+   {
+      free(patchExe);
+      printf("Couldn't find patch buffer magic in file %s - this shouldn't happen!!!\n", m_argv[0]);
+      return -1;
+   }
+   
+   /* Pack patch together and replace string pointers by offsets */
+   patch = (Patch *)patchBuffer;
+   files = (PatchedFile *)(patchBuffer + sizeof (Patch));
+   patchOffset = sizeof (Patch) + sizeof (PatchedFile) * m_patch.fileCount;
+   stringOffset = patchSize;
+   
+   patch->fileCount = m_patch.fileCount;
+   patch->files = (PatchedFile *)sizeof (Patch);
+
+   patch->name = (const char *)stringOffset;
+   strcpy(patchBuffer + stringOffset, m_patch.name);
+   stringOffset += strlen(m_patch.name) + 1;
+   
+   for (i = 0; i < m_patch.fileCount; i++)
+   {
+      files[i].fileSize = m_patch.files[i].fileSize;
+      files[i].patchCount = m_patch.files[i].patchCount;
+      
+      files[i].name = (const char *)stringOffset;
+      strcpy(patchBuffer + stringOffset, m_patch.files[i].name);
+      stringOffset += strlen(m_patch.files[i].name) + 1;
+      
+      size = files[i].patchCount * sizeof (PatchedByte);
+      files[i].patches = (PatchedByte *)patchOffset;
+      memcpy(patchBuffer + patchOffset, m_patch.files[i].patches, size);
+      patchOffset += size;
+   }
+   size = patchSize + stringSize;
+   memset(patchBuffer + size, 0, PATCH_BUFFER_SIZE - size);
+
+   /* Save file */
+   if (saveFile(outputFileName, patchExe, patchExeSize) < 0)
+   {
+      free(patchExe);
+      return -1;
+   }
+   free(patchExe);
+
+   printf("Patch saved!\n");
+   return 0;
+}
+
+
+static int
+loadPatch()
+{
+   char *p;
+   Patch *patch;
+   int i;
+   
+   p = m_patchBuffer + SIZEOF_PATCH_BUFFER_MAGIC;
+   patch = (Patch *)p;
+   
+   if (patch->name == NULL)
+   {
+      return -1;
+   }
+   
+   m_patch.name = p + (int)patch->name;
+   m_patch.fileCount = patch->fileCount;
+   m_patch.files = (PatchedFile *)(p + (int)patch->files);
+
+   for (i = 0; i < m_patch.fileCount; i++)
+   {
+      m_patch.files[i].name = p + (int)m_patch.files[i].name;
+      m_patch.files[i].patches = (PatchedByte *)(p + (int)m_patch.files[i].patches);
+   }
+   
+   printf("Patch %s loaded...\n", m_patch.name);
+   return 0;
+}
+
+
+/** MAIN FUNCTIONS ************************************************************/
+
+static int
+createPatch()
+{
+   int i, status;
+   const char *outputFileName;
+
+   /* Check argument count */
+   if (m_argc < 6 || (m_argc % 2) != 0)
+   {
+      printUsage();
+      return -1;
+   }
+
+   outputFileName = m_argv[3];
+   m_patch.name = m_argv[2];
+
+   /* Allocate PatchedFiles array */
+   m_patch.fileCount = (m_argc - 4) / 2;
+   m_patch.files = malloc(m_patch.fileCount * sizeof (PatchedFile));
+   if (m_patch.files == NULL)
+   {
+      printf("Out of memory!\n");
+      return -1;
+   }
+   memset(m_patch.files, 0, m_patch.fileCount * sizeof (PatchedFile));
+
+   /* Compare original to patched files and fill m_patch.files array */
+   for (i = 0; i < m_patch.fileCount; i++)
+   {
+      m_patch.files[i].name = m_argv[4 + (i * 2) + 1];
+      status = compareFiles(m_patch.files + i, m_argv[4 + (i * 2) + 0]);
+      if (status < 0)
+      {
+         for (i = 0; i < m_patch.fileCount; i++)
+         {
+            if (m_patch.files[i].patches != NULL)
+               free(m_patch.files[i].patches);
+         }
+         free(m_patch.files);
+         m_patch.files = NULL;
+         m_patch.fileCount = 0;
+         return status;
+      }
+   }
+   
+   /* Output patch */
+   return outputPatch(outputFileName);
+}
+
+
+static int
+applyPatch()
+{
+   int c, i, j, fileSize, makeBackup;
+   unsigned char *file;
+   char *p;
+   const char *fileName;
+   char buffer[MAX_PATH];
+   
+
+   if (m_argc > 1 && strcmp(m_argv[1], "-d") != 0)
+   {
+      printUsage();
+      return -1;
+   }
+
+   /* Load patch */
+   if (loadPatch() < 0)
+   {
+      printf("This executable doesn't contain a patch, use -c to create one.\n");
+      return -1;
+   }
+
+   if (m_argc > 1)
+   {
+      /* Dump patch */
+      printf("Patch name: %s\n", m_patch.name);
+      printf("File count: %d\n", m_patch.fileCount);
+      for (i = 0; i < m_patch.fileCount; i++)
+      {
+         printf("----------------------\n"
+                "File name:   %s\n"
+                "File size:   %d bytes\n",
+                m_patch.files[i].name, m_patch.files[i].fileSize);
+         printf("Patch count: %d\n", m_patch.files[i].patchCount);
+         for (j = 0; j < m_patch.files[i].patchCount; j++)
+         {
+            printf("  Offset 0x%x   0x%02x -> 0x%02x\n",
+                   m_patch.files[i].patches[j].offset,
+                   m_patch.files[i].patches[j].expected,
+                   m_patch.files[i].patches[j].patched);
+         }
+      }
+   }
+   else
+   {
+      /* Apply patch */
+      printf("Applying patch...\n");
+      for (i = 0; i < m_patch.fileCount; i++)
+      {
+         /* Load original file */
+         fileName = m_patch.files[i].name;
+applyPatch_retry_file:
+         file = loadFile(fileName, &fileSize);
+         if (file == NULL)
+         {
+            printf("File %s not found! ", fileName);
+applyPatch_file_open_error:
+            printf("(S)kip, (R)etry, (A)bort, (M)anually enter filename");
+            do
+            {
+               c = getch();
+            }
+            while (c != 's' && c != 'r' && c != 'a' && c != 'm');
+            printf("\n");
+            if (c == 's')
+            {
+               continue;
+            }
+            else if (c == 'r')
+            {
+               goto applyPatch_retry_file;
+            }
+            else if (c == 'a')
+            {
+               return 0;
+            }
+            else if (c == 'm')
+            {
+               if (fgets(buffer, sizeof (buffer), stdin) == NULL)
+               {
+                  printf("fgets() failed!\n");
+                  return -1;
+               }
+               p = strchr(buffer, '\r');
+               if (p != NULL)
+                  *p = '\0';
+               p = strchr(buffer, '\n');
+               if (p != NULL)
+                  *p = '\0';
+
+               fileName = buffer;
+               goto applyPatch_retry_file;
+            }
+         }
+
+         /* Check file size */
+         if (fileSize != m_patch.files[i].fileSize)
+         {
+            free(file);
+            printf("File %s has unexpected filesize of %d bytes (%d bytes expected)\n",
+                   fileName, fileSize, m_patch.files[i].fileSize);
+            if (fileName != m_patch.files[i].name) /* manually entered filename */
+            {
+               goto applyPatch_file_open_error;
+            }
+            return -1;
+         }
+         
+         /* Ask for backup */
+         printf("Do you want to make a backup of %s? (Y)es, (N)o, (A)bort", fileName);
+         do
+         {
+            c = getch();
+         }
+         while (c != 'y' && c != 'n' && c != 'a');
+         printf("\n");
+         if (c == 'y')
+         {
+            char buffer[MAX_PATH];
+            snprintf(buffer, MAX_PATH, "%s.bak", fileName);
+            buffer[MAX_PATH-1] = '\0';
+            makeBackup = 1;
+            if (access(buffer, 0) >= 0) /* file exists */
+            {
+               printf("File %s already exists, overwrite? (Y)es, (N)o, (A)bort", buffer);
+               do
+               {
+                  c = getch();
+               }
+               while (c != 'y' && c != 'n' && c != 'a');
+               printf("\n");
+               if (c == 'n')
+                  makeBackup = 0;
+               else if (c == 'a')
+               {
+                  free(file);
+                  return 0;
+               }
+            }
+            if (makeBackup && saveFile(buffer, file, fileSize) < 0)
+            {
+               free(file);
+               return -1;
+            }
+         }
+         else if (c == 'a')
+         {
+            free(file);
+            return 0;
+         }
+         
+         /* Patch file */
+         for (j = 0; j < m_patch.files[i].patchCount; j++)
+         {
+            int offset = m_patch.files[i].patches[j].offset;
+            if (file[offset] != m_patch.files[i].patches[j].expected)
+            {
+               printf("Unexpected value in file %s at offset 0x%x: expected = 0x%02x, found = 0x%02x\n",
+                      fileName, offset, m_patch.files[i].patches[j].expected, file[offset]);
+               free(file);
+               return -1;
+            }
+            file[offset] = m_patch.files[i].patches[j].patched;
+         }
+         
+         /* Save file */
+         if (saveFile(fileName, file, fileSize) < 0)
+         {
+            free(file);
+            return -1;
+         }
+         free(file);
+      }
+      
+      printf("Patch applied sucessfully!\n");
+   }
+
+   return 0;
+}
+
+
+static void
+printUsage()
+{
+   printf("Usage:\n"
+          "%s -c     - Create patch\n"
+          "%s -d     - Dump patch\n"
+          "%s        - Apply patch\n"
+          "\n"
+          "A patch can be created like this:\n"
+          "%s -c \"patch name\" output.exe file1.orig file1.patched[ file2.orig file2.patched[ ...]]\n",
+          m_argv[0], m_argv[0], m_argv[0], m_argv[0]);
+}
+
+
+int
+main(
+   int argc,
+   char *argv[])
+{
+   m_argc = argc;
+   m_argv = argv;
+
+   if (argc >= 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0))
+   {
+      printUsage();
+      return 0;
+   }
+   else if (argc >= 2 && argv[1][0] == '-')
+   {
+      if (strcmp(argv[1], "-c") == 0)
+      {
+         return createPatch();
+      }
+      else if (strcmp(argv[1], "-d") == 0)
+      {
+         return applyPatch();
+      }
+      else
+      {
+         printf("Unknown option: %s\n"
+                "Use -h for help.\n",
+                argv[1]);
+         return -1;
+      }
+   }
+   
+   return applyPatch();
+}
+
index b85c267..0143392 100644 (file)
-/* \r
- * COPYRIGHT:   See COPYING in the top level directory\r
- * PROJECT:     ReactOS traceroute utility\r
- * FILE:        apps/utils/net/tracert/tracert.c\r
- * PURPOSE:     trace a packets route through a network\r
- * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)\r
- * REVISIONS:\r
- *   GM 03/05/05 Created\r
- *\r
- */\r
-\r
-\r
-#include <windows.h>\r
-#include <winsock2.h>\r
-#include <tchar.h>\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <ws2tcpip.h>\r
-#include <string.h>\r
-#include <time.h>\r
-#include "tracert.h"\r
-\r
-#define WIN32_LEAN_AND_MEAN\r
-\r
-#ifdef DBG\r
-#undef DBG\r
-#endif\r
-\r
-/*\r
- * globals\r
- */\r
-SOCKET icmpSock;                // socket descriptor \r
-SOCKADDR_IN source, dest;       // source and destination address info\r
-ECHO_REPLY_HEADER sendpacket;   // ICMP echo packet\r
-IPv4_HEADER recvpacket;         // return reveive packet\r
-\r
-BOOL bUsePerformanceCounter;    // whether to use the high res performance counter\r
-LARGE_INTEGER TicksPerMs;       // number of millisecs in relation to proc freq\r
-LARGE_INTEGER TicksPerUs;       // number of microsecs in relation to proc freq\r
-LONGLONG lTimeStart;            // send packet, timer start\r
-LONGLONG lTimeEnd;                 // receive packet, timer end\r
-\r
-CHAR cHostname[256];            // target hostname\r
-CHAR cDestIP[18];               // target IP\r
-\r
-\r
-/*\r
- * command line options\r
- */\r
-BOOL bResolveAddresses = TRUE;  // -d  MS ping defaults to true.\r
-INT iMaxHops = 30;              // -h  Max number of hops before trace ends\r
-INT iHostList;                  // -j  @UNIMPLEMENTED@\r
-INT iTimeOut = 2000;            // -w  time before packet times out\r
-\r
-\r
-\r
-\r
-/* \r
- *\r
- * Parse command line parameters and set any options\r
- *\r
- */\r
-BOOL ParseCmdline(int argc, char* argv[])\r
-{\r
-    int i;\r
\r
-    if (argc < 2) \r
-    {\r
-       Usage();\r
-       return FALSE;\r
-    }\r
-\r
-    for (i = 1; i < argc; i++) {\r
-        if (argv[i][0] == '-') {\r
-            switch (argv[i][1]) {\r
-               case 'd': bResolveAddresses = FALSE;  \r
-                         break;\r
-               case 'h': sscanf(argv[i+1], "%d", &iMaxHops); \r
-                         break;\r
-               case 'l': break; /* @unimplemented@ */\r
-               case 'w': sscanf(argv[i+1], "%d", &iTimeOut); \r
-                         break;\r
-               default:\r
-                  _tprintf(_T("%s is not a valid option.\n"), argv[i]);\r
-                  Usage();\r
-                  return FALSE;\r
-            }\r
-        } else {\r
-           /* copy target address */\r
-           strncpy(cHostname, argv[i], 255);\r
-\r
-        }\r
-    }\r
\r
-    return TRUE;\r
-}\r
-\r
-\r
-\r
-/*\r
- *\r
- * Driver function, controls the traceroute program\r
- * \r
- */\r
-INT Driver(VOID) {\r
-    \r
-    INT i;\r
-    INT iHopCount = 1;              // hop counter. default max is 30\r
-    INT iSeqNum = 0;                // initialise packet sequence number\r
-    INT iTTL = 1;                   // set initial packet TTL to 1\r
-    BOOL bFoundTarget = FALSE;      // Have we reached our destination yet\r
-    BOOL bAwaitPacket;              // indicates whether we have recieved a good packet\r
-    INT iDecRes;                    // DecodeResponse return value\r
-    INT iRecieveReturn;             // RecieveReturn return value\r
-    INT iNameInfoRet;               // getnameinfo return value\r
-    INT iPacketSize = PACKET_SIZE;  // packet size\r
-    WORD wHeaderLen;                // header length\r
-    PECHO_REPLY_HEADER icmphdr;     \r
-    \r
-    \r
-    //temps for getting host name\r
-    CHAR cHost[256];\r
-    CHAR cServ[256];\r
-    CHAR *ip;\r
-    \r
-    /* setup winsock */\r
-    WSADATA wsaData;\r
-\r
-    /* check for winsock 2 */\r
-    if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {\r
-#ifdef DBG\r
-        _tprintf(_T("WSAStartup failed.\n"));\r
-#endif /* DBG */\r
-        exit(1);\r
-    }\r
-    \r
-    SetupTimingMethod();\r
-    \r
-    /* setup target info */\r
-    ResolveHostname();\r
-\r
-    /* print standard tracing info to screen */\r
-    _tprintf(_T("\nTracing route to %s [%s]\n"), cHostname, cDestIP);\r
-    _tprintf(_T("over a maximum of %d hop"), iMaxHops);\r
-    iMaxHops > 1 ? _tprintf(_T("s:\n\n")) : _tprintf(_T(":\n\n"));\r
-\r
-    /* run until we hit either max hops, or we recieve 3 echo replys */\r
-    while ((iHopCount <= iMaxHops) && (bFoundTarget != TRUE)) {\r
-        _tprintf(_T("%3d   "), iHopCount);\r
-        /* run 3 pings for each hop */\r
-        for (i=0; i<3; i++) {\r
-            if (Setup(iTTL) != TRUE) {\r
-#ifdef DBG\r
-                _tprintf(_T("error in Setup()\n"));\r
-#endif /* DBG */\r
-                WSACleanup();\r
-                exit(1);\r
-            }\r
-            PreparePacket(iPacketSize, iSeqNum);\r
-            if (SendPacket(iPacketSize) != SOCKET_ERROR) {\r
-                /* loop until we get a good packet */\r
-                bAwaitPacket = TRUE;\r
-                while (bAwaitPacket) {\r
-                    /* Receive replies until we either get a successful\r
-                     * read, or a fatal error occurs. */\r
-                    if ((iRecieveReturn = ReceivePacket(iPacketSize)) < 0) {\r
-                        /* check the sequence number in the packet\r
-                         * if it's bad, complain and wait for another packet\r
-                         * , otherwise break */\r
-                        wHeaderLen = recvpacket.h_len * 4;\r
-                        icmphdr = (ECHO_REPLY_HEADER *)((char*)&recvpacket + wHeaderLen);\r
-                        if (icmphdr->icmpheader.seq != iSeqNum) {\r
-                            _tprintf(_T("bad sequence number!\n"));\r
-                            continue;\r
-                        } else {\r
-                            break;\r
-                        }\r
-                    }\r
-                    \r
-                    /* if RecievePacket timed out we don't bother decoding */\r
-                    if (iRecieveReturn != 1) {\r
-                        iDecRes = DecodeResponse(iPacketSize, iSeqNum);\r
-   \r
-                        switch (iDecRes) {\r
-                           case 0 : bAwaitPacket = FALSE;  /* time exceeded */\r
-                                    break;\r
-                           case 1 : bAwaitPacket = FALSE;  /* echo reply */\r
-                                    break; \r
-                           case 2 : bAwaitPacket = FALSE;  /* destination unreachable */\r
-                                    break;  \r
-#ifdef DBG \r
-                           case -1 :\r
-                                     _tprintf(_T("recieved foreign packet\n")); \r
-                                     break;\r
-                           case -2 : \r
-                                     _tprintf(_T("error in DecodeResponse\n")); \r
-                                     break;\r
-                           case -3 : \r
-                                     _tprintf(_T("unknown ICMP packet\n")); \r
-                                     break;\r
-#endif /* DBG */\r
-                           default : break;\r
-                        }\r
-                    } else {\r
-                        /* packet timed out. Don't wait for it again */\r
-                        bAwaitPacket = FALSE;\r
-                    }\r
-                }   \r
-            }\r
-\r
-            iSeqNum++;\r
-            _tprintf(_T("   "));\r
-        }\r
-\r
-        if(bResolveAddresses) {\r
-           /* gethostbyaddr() and getnameinfo() are \r
-            * unimplemented in ROS at present.\r
-            * Alex has advised he will be implementing gethostbyaddr\r
-            * but as it's depricieted and getnameinfo is much nicer,\r
-            * I've used that for the time being for testing in Windows*/\r
-            \r
-              //ip = inet_addr(inet_ntoa(source.sin_addr));\r
-              //host = gethostbyaddr((char *)&ip, 4, 0);\r
-              \r
-              ip = inet_ntoa(source.sin_addr);\r
-\r
-              iNameInfoRet = getnameinfo((SOCKADDR *)&source,\r
-                                 sizeof(SOCKADDR),\r
-                                 cHost,\r
-                                 256,\r
-                                 cServ,\r
-                                 256,\r
-                                 NI_NUMERICSERV);\r
-              if (iNameInfoRet == 0) {\r
-                 /* if IP address resolved to a hostname,\r
-                   * print the IP address after it */   \r
-                  if (lstrcmpA(cHost, ip) != 0) {\r
-                      _tprintf(_T("%s [%s]"), cHost, ip);\r
-                  } else {\r
-                      _tprintf(_T("%s"), cHost);\r
-                  }\r
-              } else {\r
-                  _tprintf(_T("error: %d"), WSAGetLastError());    \r
-#ifdef DBG\r
-                  _tprintf(_T(" getnameinfo failed: %d"), iNameInfoRet);\r
-#endif /* DBG */ \r
-              }\r
-\r
-        } else {\r
-           _tprintf(_T("%s"), inet_ntoa(source.sin_addr));\r
-        }\r
-        _tprintf(_T("\n"));\r
-\r
-        /* check if we've arrived at the target */\r
-        if (strcmp(cDestIP, inet_ntoa(source.sin_addr)) == 0) {\r
-            bFoundTarget = TRUE;\r
-        } else {\r
-            iTTL++;\r
-            iHopCount++;\r
-            Sleep(500);\r
-        }\r
-    }\r
-    _tprintf(_T("\nTrace complete.\n"));\r
-    WSACleanup();\r
-    \r
-    return 0;\r
-}\r
-\r
-/*\r
- * Establish if performance counters are available and\r
- * set up timing figures in relation to processor frequency.\r
- * If performance counters are not available, we'll be using \r
- * gettickcount, so set the figures to 1\r
- *\r
- */\r
-VOID SetupTimingMethod(VOID)\r
-{\r
-    LARGE_INTEGER PerformanceCounterFrequency;\r
-    \r
-    /* check if performance counters are available */\r
-    bUsePerformanceCounter = QueryPerformanceFrequency(&PerformanceCounterFrequency);\r
-    if (bUsePerformanceCounter) {\r
-        /* restrict execution to first processor on SMP systems */\r
-        if (SetThreadAffinityMask(GetCurrentThread(), 1) == 0) {\r
-            bUsePerformanceCounter = FALSE;\r
-        }\r
-    \r
-        TicksPerMs.QuadPart  = PerformanceCounterFrequency.QuadPart / 1000;\r
-        TicksPerUs.QuadPart  = PerformanceCounterFrequency.QuadPart / 1000000;\r
-    }\r
-    \r
-    if (!bUsePerformanceCounter) {\r
-        TicksPerMs.QuadPart = 1;\r
-        TicksPerUs.QuadPart = 1;\r
-    }    \r
-}\r
-\r
-\r
-/*\r
- *\r
- * Check for a hostname or dotted deciamal for our target.\r
- * If we have a hostname, resolve to an IP and store it, else\r
- * just store the target IP address. Also set up other key \r
- * SOCKADDR_IN members needed for the connection.\r
- *\r
- */\r
-VOID ResolveHostname(VOID)\r
-{\r
-    HOSTENT *hp;\r
-    ULONG addr;\r
-    \r
-    memset(&dest, 0, sizeof(dest));\r
-\r
-    addr = inet_addr(cHostname);\r
-    /* if address is not a dotted decimal */\r
-    if (addr == INADDR_NONE) {\r
-       hp = gethostbyname(cHostname);\r
-       if (hp != 0) {\r
-          memcpy(&dest.sin_addr, hp->h_addr, hp->h_length);\r
-          //dest.sin_addr = *((struct in_addr *)hp->h_addr);\r
-          dest.sin_family = hp->h_addrtype;\r
-       } else {\r
-          _tprintf(_T("Unable to resolve target system name %s.\n"), cHostname);\r
-          WSACleanup();\r
-          exit(1);\r
-       }\r
-    } else {\r
-        dest.sin_addr.s_addr = addr;\r
-        dest.sin_family = AF_INET;\r
-    }\r
-    /* copy destination IP address into a string */\r
-    strcpy(cDestIP, inet_ntoa(dest.sin_addr));       \r
-}\r
-\r
-\r
-\r
-/*\r
- *\r
- * Create our socket which will be used for sending and recieving,\r
- * Socket Type is raw, Protocol is ICMP. Also set the TTL value which will be\r
- * set in the outgoing IP packet.\r
- *\r
- */\r
-INT Setup(INT iTTL)\r
-{\r
-    INT iSockRet;\r
-\r
-    /* create raw socket */\r
-    icmpSock = WSASocket(AF_INET, SOCK_RAW, IPPROTO_ICMP, 0, 0, 0);\r
-    if (icmpSock == INVALID_SOCKET) {\r
-       _tprintf(_T("Could not create socket : %d.\n"), WSAGetLastError());\r
-       if (WSAGetLastError() == WSAEACCES) {\r
-            _tprintf(_T("\n\nYou must be an administrator to run this program!\n\n"));\r
-            WSACleanup();\r
-            exit(1);\r
-        }\r
-       return FALSE;\r
-    }\r
-    \r
-    /* setup for TTL */\r
-    iSockRet = setsockopt(icmpSock, IPPROTO_IP, IP_TTL, (const char *)&iTTL, sizeof(iTTL));\r
-    if (iSockRet == SOCKET_ERROR) {\r
-       _tprintf(_T("TTL setsockopt failed : %d. \n"), WSAGetLastError());\r
-       return FALSE;\r
-    }\r
-    \r
-    return TRUE;\r
-}\r
-\r
-\r
-\r
-/*\r
- * Prepare the ICMP echo request packet for sending.\r
- * Calculate the packet checksum\r
- *\r
- */\r
-VOID PreparePacket(INT iPacketSize, INT iSeqNum) \r
-{\r
-    /* assemble ICMP echo request packet */\r
-    sendpacket.icmpheader.type      = ECHO_REQUEST;\r
-    sendpacket.icmpheader.code      = 0;\r
-    sendpacket.icmpheader.checksum  = 0;\r
-    sendpacket.icmpheader.id        = (USHORT)GetCurrentProcessId();\r
-    sendpacket.icmpheader.seq       = iSeqNum;\r
-\r
-    /* calculate checksum of packet */\r
-    sendpacket.icmpheader.checksum  = CheckSum((PUSHORT)&sendpacket, sizeof(ICMP_HEADER) + iPacketSize);\r
-}\r
-\r
-\r
-\r
-/*\r
- *\r
- * Get the system time and send the ICMP packet to the destination\r
- * address.\r
- *\r
- */\r
-INT SendPacket(INT datasize)\r
-{\r
-    INT iSockRet;\r
-    INT iPacketSize;\r
-    \r
-    iPacketSize = sizeof(ECHO_REPLY_HEADER) + datasize;\r
-\r
-#ifdef DBG\r
-    _tprintf(_T("\nsending packet of %d bytes\n"), iPacketSize);\r
-#endif /* DBG */\r
-\r
-    /* get time packet was sent */\r
-    lTimeStart = GetTime();\r
-\r
-    iSockRet = sendto(icmpSock,              //socket\r
-                      (char *)&sendpacket,   //buffer\r
-                      iPacketSize,           //size of buffer\r
-                      0,                     //flags\r
-                      (SOCKADDR *)&dest,     //destination\r
-                      sizeof(dest));         //address length\r
-    \r
-    if (iSockRet == SOCKET_ERROR) {\r
-        if (WSAGetLastError() == WSAEACCES) {\r
-            _tprintf(_T("\n\nYou must be an administrator to run this program!\n\n"));\r
-            exit(1);\r
-            WSACleanup();\r
-        } else {\r
-#ifdef DBG\r
-            _tprintf(_T("sendto failed %d\n"), WSAGetLastError());\r
-#endif /* DBG */            \r
-            return FALSE;\r
-        }\r
-    }\r
-#ifdef DBG\r
-    _tprintf(_T("sent %d bytes\n"), iSockRet);\r
-#endif /* DBG */\r
-\r
-    /* return number of bytes sent */\r
-    return iSockRet;\r
-}\r
-\r
-\r
-\r
-/*\r
- *\r
- * Set up a timeout value and put the socket in a select poll.\r
- * Wait until we recieve an IPv4 reply packet in reply to the ICMP \r
- * echo request packet and get the time the packet was recieved.\r
- * If we don't recieve a packet, do some checking to establish why.\r
- *\r
- */\r
-INT ReceivePacket(INT datasize)\r
-{\r
-    TIMEVAL timeVal;\r
-    FD_SET readFDS;\r
-    int iSockRet = 0, iSelRet;\r
-    int iFromLen;\r
-    int iPacketSize;\r
-\r
-    /* allow for a larger recv buffer to store ICMP TTL\r
-     * exceed, IP header and orginal ICMP request */\r
-    iPacketSize = MAX_REC_SIZE + datasize; \r
-\r
-    iFromLen = sizeof(source);\r
-\r
-#ifdef DBG\r
-    _tprintf(_T("receiving packet. Available buffer, %d bytes\n"), iPacketSize);\r
-#endif /* DBG */\r
-\r
-    /* monitor icmpSock for incomming connections */\r
-    FD_ZERO(&readFDS);\r
-    FD_SET(icmpSock, &readFDS);\r
-    \r
-    /* set timeout values */\r
-    timeVal.tv_sec  = iTimeOut / 1000;\r
-    timeVal.tv_usec = iTimeOut % 1000;\r
-    \r
-    iSelRet = select(0, &readFDS, NULL, NULL, &timeVal);\r
-    \r
-    if ((iSelRet != SOCKET_ERROR) && (iSelRet != 0)) {\r
-        iSockRet = recvfrom(icmpSock,              //socket\r
-                           (char *)&recvpacket,    //buffer\r
-                           iPacketSize,            //size of buffer\r
-                           0,                      //flags\r
-                           (SOCKADDR *)&source,    //source address\r
-                           &iFromLen);             //pointer to address length\r
-        /* get time packet was recieved */\r
-        lTimeEnd = GetTime();  \r
-    /* if socket timed out */                             \r
-    } else if (iSelRet == 0) {\r
-        _tprintf(_T("   *  "));\r
-        return 1;\r
-    } else if (iSelRet == SOCKET_ERROR) {\r
-        _tprintf(_T("select() failed in sendPacket() %d\n"), WSAGetLastError());\r
-       return -1;\r
-    }\r
-\r
-    \r
-    if (iSockRet == SOCKET_ERROR) {\r
-        _tprintf(_T("recvfrom failed: %d\n"), WSAGetLastError());\r
-        return -2;\r
-    }\r
-#ifdef DBG\r
-    else {\r
-       _tprintf(_T("reveived %d bytes\n"), iSockRet);\r
-    }\r
-#endif /* DBG */\r
-\r
-    return 0;\r
-}\r
-\r
-\r
-\r
-/*\r
- *\r
- * Cast the IPv4 packet to an echo reply and to a TTL exceed.\r
- * Check the 'type' field to establish what was recieved, and \r
- * ensure the packet is related to the originating process.\r
- * It all is well, print the time taken for the round trip.\r
- *\r
- */\r
-INT DecodeResponse(INT iPacketSize, INT iSeqNum)\r
-{\r
-    unsigned short header_len = recvpacket.h_len * 4;\r
-    /* cast the recieved packet into an ECHO reply and a TTL Exceed so we can check the ID*/\r
-    ECHO_REPLY_HEADER *IcmpHdr = (ECHO_REPLY_HEADER *)((char*)&recvpacket + header_len);\r
-    TTL_EXCEED_HEADER *TTLExceedHdr = (TTL_EXCEED_HEADER *)((char *)&recvpacket + header_len);\r
-\r
-    /* Make sure the reply is ok */\r
-    if (iPacketSize < header_len + ICMP_MIN_SIZE) {\r
-        _tprintf(_T("too few bytes from %s\n"), inet_ntoa(dest.sin_addr));\r
-        return -2;\r
-    }  \r
-    \r
-    switch (IcmpHdr->icmpheader.type) {\r
-           case TTL_EXCEEDED :\r
-                if (TTLExceedHdr->OrigIcmpHeader.id != (USHORT)GetCurrentProcessId()) {\r
-                /* FIXME */\r
-                /* we've picked up a packet not related to this process\r
-                 * probably from another local program. We ignore it */\r
-#ifdef DGB\r
-                    _tprintf(_T("header id,  process id  %d"), TTLExceedHdr->OrigIcmpHeader.id, GetCurrentProcessId());\r
-#endif /* DBG */\r
-                    //_tprintf(_T("oops ");\r
-                    return -1;\r
-                }\r
-                _tprintf(_T("%3Ld ms"), (lTimeEnd - lTimeStart) / TicksPerMs.QuadPart);\r
-                return 0;\r
-           case ECHO_REPLY :\r
-                if (IcmpHdr->icmpheader.id != (USHORT)GetCurrentProcessId()) {\r
-                /* FIXME */\r
-                /* we've picked up a packet not related to this process\r
-                 * probably from another local program. We ignore it */\r
-#ifdef DGB\r
-                    _tprintf(_T("\nPicked up wrong packet. icmpheader.id = %d and process id = %d"), IcmpHdr->icmpheader.id, GetCurrentProcessId());\r
-#endif /* DBG */\r
-                    //_tprintf(_T("oops ");\r
-                    return -1;\r
-                }\r
-                _tprintf(_T("%3Ld ms"), (lTimeEnd - lTimeStart) / TicksPerMs.QuadPart);\r
-                return 1;\r
-           case DEST_UNREACHABLE :\r
-                _tprintf(_T("  *  "));\r
-                return 2;\r
-           default :\r
-                /* unknown ICMP packet */\r
-                return -3;\r
-    } \r
-}\r
-\r
-\r
-/*\r
- *\r
- * Get the system time using preformance counters if available,\r
- * otherwise fall back to GetTickCount()\r
- *\r
- */\r
-\r
-LONG GetTime(VOID) \r
-{\r
-    LARGE_INTEGER Time;\r
-    \r
-    if (bUsePerformanceCounter) {\r
-        if (QueryPerformanceCounter(&Time) == 0) {\r
-            Time.u.LowPart = (DWORD)GetTickCount();\r
-            Time.u.HighPart = 0;\r
-            return (LONGLONG)Time.u.LowPart;\r
-        } \r
-    } else {\r
-            Time.u.LowPart = (DWORD)GetTickCount();\r
-            Time.u.HighPart = 0;\r
-            return (LONGLONG)Time.u.LowPart;\r
-    }\r
-    return Time.QuadPart;\r
-}\r
-\r
-\r
-/*\r
- *\r
- * Calculate packet checksum.\r
- *\r
- */\r
-WORD CheckSum(PUSHORT data, UINT size)\r
-{\r
-    DWORD dwSum = 0;\r
-\r
-    while (size > 1) {\r
-        dwSum += *data++;\r
-        size -= sizeof(USHORT);\r
-    }\r
-\r
-    if (size)\r
-        dwSum += *(UCHAR*)data;\r
-\r
-    dwSum = (dwSum >> 16) + (dwSum & 0xFFFF);\r
-    dwSum += (dwSum >> 16);\r
-\r
-    return (USHORT)(~dwSum);\r
-}\r
-\r
-\r
-/*\r
- *\r
- * print program usage to screen\r
- *\r
- */\r
-VOID Usage(VOID)\r
-{\r
-    _tprintf(_T("\nUsage: tracert [-d] [-h maximum_hops] [-j host-list] [-w timeout] target_name\n\n"));\r
-    _tprintf(_T("Options:\n"));\r
-    _tprintf(_T("    -d                 Do not resolve addresses to hostnames.\n"));\r
-    _tprintf(_T("    -h maximum_hops    Maximum number of hops to search for target.\n"));\r
-    _tprintf(_T("    -j host-list       Loose source route along host-list.\n"));\r
-    _tprintf(_T("    -w timeout         Wait timeout milliseconds for each reply.\n\n"));\r
-    \r
-    /* temp notes to stop user questions until getnameinfo/gethostbyaddr and getsockopt are implemented */\r
-    _tprintf(_T("NOTES\n-----\n"\r
-           "- Setting TTL values is not currently supported in ReactOS, so the trace will\n"\r
-           "  jump straight to the destination. This feature will be implemented soon.\n"\r
-           "- Host info is not currently available in ReactOS and will fail with strange\n"\r
-           "  results. Use -d to force it not to resolve IP's.\n"\r
-           "- For testing purposes, all should work as normal in a Windows environment\n\n"));\r
-}\r
-\r
-\r
-\r
-/*\r
- *\r
- * Program entry point\r
- *\r
- */\r
-int main(int argc, char* argv[])\r
-{\r
-    if (!ParseCmdline(argc, _argv)) return -1;\r
-\r
-    Driver();\r
-\r
-    return 0;\r
-}\r
+/* 
+ * COPYRIGHT:   See COPYING in the top level directory
+ * PROJECT:     ReactOS traceroute utility
+ * FILE:        apps/utils/net/tracert/tracert.c
+ * PURPOSE:     trace a packets route through a network
+ * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
+ * REVISIONS:
+ *   GM 03/05/05 Created
+ *
+ */
+
+
+#include <windows.h>
+#include <winsock2.h>
+#include <tchar.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ws2tcpip.h>
+#include <string.h>
+#include <time.h>
+#include "tracert.h"
+
+#define WIN32_LEAN_AND_MEAN
+
+#ifdef DBG
+#undef DBG
+#endif
+
+/*
+ * globals
+ */
+SOCKET icmpSock;                // socket descriptor 
+SOCKADDR_IN source, dest;       // source and destination address info
+ECHO_REPLY_HEADER sendpacket;   // ICMP echo packet
+IPv4_HEADER recvpacket;         // return reveive packet
+
+BOOL bUsePerformanceCounter;    // whether to use the high res performance counter
+LARGE_INTEGER TicksPerMs;       // number of millisecs in relation to proc freq
+LARGE_INTEGER TicksPerUs;       // number of microsecs in relation to proc freq
+LONGLONG lTimeStart;            // send packet, timer start
+LONGLONG lTimeEnd;                 // receive packet, timer end
+
+CHAR cHostname[256];            // target hostname
+CHAR cDestIP[18];               // target IP
+
+
+/*
+ * command line options
+ */
+BOOL bResolveAddresses = TRUE;  // -d  MS ping defaults to true.
+INT iMaxHops = 30;              // -h  Max number of hops before trace ends
+INT iHostList;                  // -j  @UNIMPLEMENTED@
+INT iTimeOut = 2000;            // -w  time before packet times out
+
+
+
+
+/* 
+ *
+ * Parse command line parameters and set any options
+ *
+ */
+BOOL ParseCmdline(int argc, char* argv[])
+{
+    int i;
+    if (argc < 2) 
+    {
+       Usage();
+       return FALSE;
+    }
+
+    for (i = 1; i < argc; i++) {
+        if (argv[i][0] == '-') {
+            switch (argv[i][1]) {
+               case 'd': bResolveAddresses = FALSE;  
+                         break;
+               case 'h': sscanf(argv[i+1], "%d", &iMaxHops); 
+                         break;
+               case 'l': break; /* @unimplemented@ */
+               case 'w': sscanf(argv[i+1], "%d", &iTimeOut); 
+                         break;
+               default:
+                  _tprintf(_T("%s is not a valid option.\n"), argv[i]);
+                  Usage();
+                  return FALSE;
+            }
+        } else {
+           /* copy target address */
+           strncpy(cHostname, argv[i], 255);
+
+        }
+    }
+    return TRUE;
+}
+
+
+
+/*
+ *
+ * Driver function, controls the traceroute program
+ * 
+ */
+INT Driver(VOID) {
+    
+    INT i;
+    INT iHopCount = 1;              // hop counter. default max is 30
+    INT iSeqNum = 0;                // initialise packet sequence number
+    INT iTTL = 1;                   // set initial packet TTL to 1
+    BOOL bFoundTarget = FALSE;      // Have we reached our destination yet
+    BOOL bAwaitPacket;              // indicates whether we have recieved a good packet
+    INT iDecRes;                    // DecodeResponse return value
+    INT iRecieveReturn;             // RecieveReturn return value
+    INT iNameInfoRet;               // getnameinfo return value
+    INT iPacketSize = PACKET_SIZE;  // packet size
+    WORD wHeaderLen;                // header length
+    PECHO_REPLY_HEADER icmphdr;     
+    
+    
+    //temps for getting host name
+    CHAR cHost[256];
+    CHAR cServ[256];
+    CHAR *ip;
+    
+    /* setup winsock */
+    WSADATA wsaData;
+
+    /* check for winsock 2 */
+    if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
+#ifdef DBG
+        _tprintf(_T("WSAStartup failed.\n"));
+#endif /* DBG */
+        exit(1);
+    }
+    
+    SetupTimingMethod();
+    
+    /* setup target info */
+    ResolveHostname();
+
+    /* print standard tracing info to screen */
+    _tprintf(_T("\nTracing route to %s [%s]\n"), cHostname, cDestIP);
+    _tprintf(_T("over a maximum of %d hop"), iMaxHops);
+    iMaxHops > 1 ? _tprintf(_T("s:\n\n")) : _tprintf(_T(":\n\n"));
+
+    /* run until we hit either max hops, or we recieve 3 echo replys */
+    while ((iHopCount <= iMaxHops) && (bFoundTarget != TRUE)) {
+        _tprintf(_T("%3d   "), iHopCount);
+        /* run 3 pings for each hop */
+        for (i=0; i<3; i++) {
+            if (Setup(iTTL) != TRUE) {
+#ifdef DBG
+                _tprintf(_T("error in Setup()\n"));
+#endif /* DBG */
+                WSACleanup();
+                exit(1);
+            }
+            PreparePacket(iPacketSize, iSeqNum);
+            if (SendPacket(iPacketSize) != SOCKET_ERROR) {
+                /* loop until we get a good packet */
+                bAwaitPacket = TRUE;
+                while (bAwaitPacket) {
+                    /* Receive replies until we either get a successful
+                     * read, or a fatal error occurs. */
+                    if ((iRecieveReturn = ReceivePacket(iPacketSize)) < 0) {
+                        /* check the sequence number in the packet
+                         * if it's bad, complain and wait for another packet
+                         * , otherwise break */
+                        wHeaderLen = recvpacket.h_len * 4;
+                        icmphdr = (ECHO_REPLY_HEADER *)((char*)&recvpacket + wHeaderLen);
+                        if (icmphdr->icmpheader.seq != iSeqNum) {
+                            _tprintf(_T("bad sequence number!\n"));
+                            continue;
+                        } else {
+                            break;
+                        }
+                    }
+                    
+                    /* if RecievePacket timed out we don't bother decoding */
+                    if (iRecieveReturn != 1) {
+                        iDecRes = DecodeResponse(iPacketSize, iSeqNum);
+   
+                        switch (iDecRes) {
+                           case 0 : bAwaitPacket = FALSE;  /* time exceeded */
+                                    break;
+                           case 1 : bAwaitPacket = FALSE;  /* echo reply */
+                                    break; 
+                           case 2 : bAwaitPacket = FALSE;  /* destination unreachable */
+                                    break;  
+#ifdef DBG 
+                           case -1 :
+                                     _tprintf(_T("recieved foreign packet\n")); 
+                                     break;
+                           case -2 : 
+                                     _tprintf(_T("error in DecodeResponse\n")); 
+                                     break;
+                           case -3 : 
+                                     _tprintf(_T("unknown ICMP packet\n")); 
+                                     break;
+#endif /* DBG */
+                           default : break;
+                        }
+                    } else {
+                        /* packet timed out. Don't wait for it again */
+                        bAwaitPacket = FALSE;
+                    }
+                }   
+            }
+
+            iSeqNum++;
+            _tprintf(_T("   "));
+        }
+
+        if(bResolveAddresses) {
+           /* gethostbyaddr() and getnameinfo() are 
+            * unimplemented in ROS at present.
+            * Alex has advised he will be implementing gethostbyaddr
+            * but as it's depricieted and getnameinfo is much nicer,
+            * I've used that for the time being for testing in Windows*/
+            
+              //ip = inet_addr(inet_ntoa(source.sin_addr));
+              //host = gethostbyaddr((char *)&ip, 4, 0);
+              
+              ip = inet_ntoa(source.sin_addr);
+
+              iNameInfoRet = getnameinfo((SOCKADDR *)&source,
+                                 sizeof(SOCKADDR),
+                                 cHost,
+                                 256,
+                                 cServ,
+                                 256,
+                                 NI_NUMERICSERV);
+              if (iNameInfoRet == 0) {
+                 /* if IP address resolved to a hostname,
+                   * print the IP address after it */   
+                  if (lstrcmpA(cHost, ip) != 0) {
+                      _tprintf(_T("%s [%s]"), cHost, ip);
+                  } else {
+                      _tprintf(_T("%s"), cHost);
+                  }
+              } else {
+                  _tprintf(_T("error: %d"), WSAGetLastError());    
+#ifdef DBG
+                  _tprintf(_T(" getnameinfo failed: %d"), iNameInfoRet);
+#endif /* DBG */ 
+              }
+
+        } else {
+           _tprintf(_T("%s"), inet_ntoa(source.sin_addr));
+        }
+        _tprintf(_T("\n"));
+
+        /* check if we've arrived at the target */
+        if (strcmp(cDestIP, inet_ntoa(source.sin_addr)) == 0) {
+            bFoundTarget = TRUE;
+        } else {
+            iTTL++;
+            iHopCount++;
+            Sleep(500);
+        }
+    }
+    _tprintf(_T("\nTrace complete.\n"));
+    WSACleanup();
+    
+    return 0;
+}
+
+/*
+ * Establish if performance counters are available and
+ * set up timing figures in relation to processor frequency.
+ * If performance counters are not available, we'll be using 
+ * gettickcount, so set the figures to 1
+ *
+ */
+VOID SetupTimingMethod(VOID)
+{
+    LARGE_INTEGER PerformanceCounterFrequency;
+    
+    /* check if performance counters are available */
+    bUsePerformanceCounter = QueryPerformanceFrequency(&PerformanceCounterFrequency);
+    if (bUsePerformanceCounter) {
+        /* restrict execution to first processor on SMP systems */
+        if (SetThreadAffinityMask(GetCurrentThread(), 1) == 0) {
+            bUsePerformanceCounter = FALSE;
+        }
+    
+        TicksPerMs.QuadPart  = PerformanceCounterFrequency.QuadPart / 1000;
+        TicksPerUs.QuadPart  = PerformanceCounterFrequency.QuadPart / 1000000;
+    }
+    
+    if (!bUsePerformanceCounter) {
+        TicksPerMs.QuadPart = 1;
+        TicksPerUs.QuadPart = 1;
+    }    
+}
+
+
+/*
+ *
+ * Check for a hostname or dotted deciamal for our target.
+ * If we have a hostname, resolve to an IP and store it, else
+ * just store the target IP address. Also set up other key 
+ * SOCKADDR_IN members needed for the connection.
+ *
+ */
+VOID ResolveHostname(VOID)
+{
+    HOSTENT *hp;
+    ULONG addr;
+    
+    memset(&dest, 0, sizeof(dest));
+
+    addr = inet_addr(cHostname);
+    /* if address is not a dotted decimal */
+    if (addr == INADDR_NONE) {
+       hp = gethostbyname(cHostname);
+       if (hp != 0) {
+          memcpy(&dest.sin_addr, hp->h_addr, hp->h_length);
+          //dest.sin_addr = *((struct in_addr *)hp->h_addr);
+          dest.sin_family = hp->h_addrtype;
+       } else {
+          _tprintf(_T("Unable to resolve target system name %s.\n"), cHostname);
+          WSACleanup();
+          exit(1);
+       }
+    } else {
+        dest.sin_addr.s_addr = addr;
+        dest.sin_family = AF_INET;
+    }
+    /* copy destination IP address into a string */
+    strcpy(cDestIP, inet_ntoa(dest.sin_addr));       
+}
+
+
+
+/*
+ *
+ * Create our socket which will be used for sending and recieving,
+ * Socket Type is raw, Protocol is ICMP. Also set the TTL value which will be
+ * set in the outgoing IP packet.
+ *
+ */
+INT Setup(INT iTTL)
+{
+    INT iSockRet;
+
+    /* create raw socket */
+    icmpSock = WSASocket(AF_INET, SOCK_RAW, IPPROTO_ICMP, 0, 0, 0);
+    if (icmpSock == INVALID_SOCKET) {
+       _tprintf(_T("Could not create socket : %d.\n"), WSAGetLastError());
+       if (WSAGetLastError() == WSAEACCES) {
+            _tprintf(_T("\n\nYou must be an administrator to run this program!\n\n"));
+            WSACleanup();
+            exit(1);
+        }
+       return FALSE;
+    }
+    
+    /* setup for TTL */
+    iSockRet = setsockopt(icmpSock, IPPROTO_IP, IP_TTL, (const char *)&iTTL, sizeof(iTTL));
+    if (iSockRet == SOCKET_ERROR) {
+       _tprintf(_T("TTL setsockopt failed : %d. \n"), WSAGetLastError());
+       return FALSE;
+    }
+    
+    return TRUE;
+}
+
+
+
+/*
+ * Prepare the ICMP echo request packet for sending.
+ * Calculate the packet checksum
+ *
+ */
+VOID PreparePacket(INT iPacketSize, INT iSeqNum) 
+{
+    /* assemble ICMP echo request packet */
+    sendpacket.icmpheader.type      = ECHO_REQUEST;
+    sendpacket.icmpheader.code      = 0;
+    sendpacket.icmpheader.checksum  = 0;
+    sendpacket.icmpheader.id        = (USHORT)GetCurrentProcessId();
+    sendpacket.icmpheader.seq       = iSeqNum;
+
+    /* calculate checksum of packet */
+    sendpacket.icmpheader.checksum  = CheckSum((PUSHORT)&sendpacket, sizeof(ICMP_HEADER) + iPacketSize);
+}
+
+
+
+/*
+ *
+ * Get the system time and send the ICMP packet to the destination
+ * address.
+ *
+ */
+INT SendPacket(INT datasize)
+{
+    INT iSockRet;
+    INT iPacketSize;
+    
+    iPacketSize = sizeof(ECHO_REPLY_HEADER) + datasize;
+
+#ifdef DBG
+    _tprintf(_T("\nsending packet of %d bytes\n"), iPacketSize);
+#endif /* DBG */
+
+    /* get time packet was sent */
+    lTimeStart = GetTime();
+
+    iSockRet = sendto(icmpSock,              //socket
+                      (char *)&sendpacket,   //buffer
+                      iPacketSize,           //size of buffer
+                      0,                     //flags
+                      (SOCKADDR *)&dest,     //destination
+                      sizeof(dest));         //address length
+    
+    if (iSockRet == SOCKET_ERROR) {
+        if (WSAGetLastError() == WSAEACCES) {
+            _tprintf(_T("\n\nYou must be an administrator to run this program!\n\n"));
+            exit(1);
+            WSACleanup();
+        } else {
+#ifdef DBG
+            _tprintf(_T("sendto failed %d\n"), WSAGetLastError());
+#endif /* DBG */            
+            return FALSE;
+        }
+    }
+#ifdef DBG
+    _tprintf(_T("sent %d bytes\n"), iSockRet);
+#endif /* DBG */
+
+    /* return number of bytes sent */
+    return iSockRet;
+}
+
+
+
+/*
+ *
+ * Set up a timeout value and put the socket in a select poll.
+ * Wait until we recieve an IPv4 reply packet in reply to the ICMP 
+ * echo request packet and get the time the packet was recieved.
+ * If we don't recieve a packet, do some checking to establish why.
+ *
+ */
+INT ReceivePacket(INT datasize)
+{
+    TIMEVAL timeVal;
+    FD_SET readFDS;
+    int iSockRet = 0, iSelRet;
+    int iFromLen;
+    int iPacketSize;
+
+    /* allow for a larger recv buffer to store ICMP TTL
+     * exceed, IP header and orginal ICMP request */
+    iPacketSize = MAX_REC_SIZE + datasize; 
+
+    iFromLen = sizeof(source);
+
+#ifdef DBG
+    _tprintf(_T("receiving packet. Available buffer, %d bytes\n"), iPacketSize);
+#endif /* DBG */
+
+    /* monitor icmpSock for incomming connections */
+    FD_ZERO(&readFDS);
+    FD_SET(icmpSock, &readFDS);
+    
+    /* set timeout values */
+    timeVal.tv_sec  = iTimeOut / 1000;
+    timeVal.tv_usec = iTimeOut % 1000;
+    
+    iSelRet = select(0, &readFDS, NULL, NULL, &timeVal);
+    
+    if ((iSelRet != SOCKET_ERROR) && (iSelRet != 0)) {
+        iSockRet = recvfrom(icmpSock,              //socket
+                           (char *)&recvpacket,    //buffer
+                           iPacketSize,            //size of buffer
+                           0,                      //flags
+                           (SOCKADDR *)&source,    //source address
+                           &iFromLen);             //pointer to address length
+        /* get time packet was recieved */
+        lTimeEnd = GetTime();  
+    /* if socket timed out */                             
+    } else if (iSelRet == 0) {
+        _tprintf(_T("   *  "));
+        return 1;
+    } else if (iSelRet == SOCKET_ERROR) {
+        _tprintf(_T("select() failed in sendPacket() %d\n"), WSAGetLastError());
+       return -1;
+    }
+
+    
+    if (iSockRet == SOCKET_ERROR) {
+        _tprintf(_T("recvfrom failed: %d\n"), WSAGetLastError());
+        return -2;
+    }
+#ifdef DBG
+    else {
+       _tprintf(_T("reveived %d bytes\n"), iSockRet);
+    }
+#endif /* DBG */
+
+    return 0;
+}
+
+
+
+/*
+ *
+ * Cast the IPv4 packet to an echo reply and to a TTL exceed.
+ * Check the 'type' field to establish what was recieved, and 
+ * ensure the packet is related to the originating process.
+ * It all is well, print the time taken for the round trip.
+ *
+ */
+INT DecodeResponse(INT iPacketSize, INT iSeqNum)
+{
+    unsigned short header_len = recvpacket.h_len * 4;
+    /* cast the recieved packet into an ECHO reply and a TTL Exceed so we can check the ID*/
+    ECHO_REPLY_HEADER *IcmpHdr = (ECHO_REPLY_HEADER *)((char*)&recvpacket + header_len);
+    TTL_EXCEED_HEADER *TTLExceedHdr = (TTL_EXCEED_HEADER *)((char *)&recvpacket + header_len);
+
+    /* Make sure the reply is ok */
+    if (iPacketSize < header_len + ICMP_MIN_SIZE) {
+        _tprintf(_T("too few bytes from %s\n"), inet_ntoa(dest.sin_addr));
+        return -2;
+    }  
+    
+    switch (IcmpHdr->icmpheader.type) {
+           case TTL_EXCEEDED :
+                if (TTLExceedHdr->OrigIcmpHeader.id != (USHORT)GetCurrentProcessId()) {
+                /* FIXME */
+                /* we've picked up a packet not related to this process
+                 * probably from another local program. We ignore it */
+#ifdef DGB
+                    _tprintf(_T("header id,  process id  %d"), TTLExceedHdr->OrigIcmpHeader.id, GetCurrentProcessId());
+#endif /* DBG */
+                    //_tprintf(_T("oops ");
+                    return -1;
+                }
+                _tprintf(_T("%3Ld ms"), (lTimeEnd - lTimeStart) / TicksPerMs.QuadPart);
+                return 0;
+           case ECHO_REPLY :
+                if (IcmpHdr->icmpheader.id != (USHORT)GetCurrentProcessId()) {
+                /* FIXME */
+                /* we've picked up a packet not related to this process
+                 * probably from another local program. We ignore it */
+#ifdef DGB
+                    _tprintf(_T("\nPicked up wrong packet. icmpheader.id = %d and process id = %d"), IcmpHdr->icmpheader.id, GetCurrentProcessId());
+#endif /* DBG */
+                    //_tprintf(_T("oops ");
+                    return -1;
+                }
+                _tprintf(_T("%3Ld ms"), (lTimeEnd - lTimeStart) / TicksPerMs.QuadPart);
+                return 1;
+           case DEST_UNREACHABLE :
+                _tprintf(_T("  *  "));
+                return 2;
+           default :
+                /* unknown ICMP packet */
+                return -3;
+    } 
+}
+
+
+/*
+ *
+ * Get the system time using preformance counters if available,
+ * otherwise fall back to GetTickCount()
+ *
+ */
+
+LONG GetTime(VOID) 
+{
+    LARGE_INTEGER Time;
+    
+    if (bUsePerformanceCounter) {
+        if (QueryPerformanceCounter(&Time) == 0) {
+            Time.u.LowPart = (DWORD)GetTickCount();
+            Time.u.HighPart = 0;
+            return (LONGLONG)Time.u.LowPart;
+        } 
+    } else {
+            Time.u.LowPart = (DWORD)GetTickCount();
+            Time.u.HighPart = 0;
+            return (LONGLONG)Time.u.LowPart;
+    }
+    return Time.QuadPart;
+}
+
+
+/*
+ *
+ * Calculate packet checksum.
+ *
+ */
+WORD CheckSum(PUSHORT data, UINT size)
+{
+    DWORD dwSum = 0;
+
+    while (size > 1) {
+        dwSum += *data++;
+        size -= sizeof(USHORT);
+    }
+
+    if (size)
+        dwSum += *(UCHAR*)data;
+
+    dwSum = (dwSum >> 16) + (dwSum & 0xFFFF);
+    dwSum += (dwSum >> 16);
+
+    return (USHORT)(~dwSum);
+}
+
+
+/*
+ *
+ * print program usage to screen
+ *
+ */
+VOID Usage(VOID)
+{
+    _tprintf(_T("\nUsage: tracert [-d] [-h maximum_hops] [-j host-list] [-w timeout] target_name\n\n"));
+    _tprintf(_T("Options:\n"));
+    _tprintf(_T("    -d                 Do not resolve addresses to hostnames.\n"));
+    _tprintf(_T("    -h maximum_hops    Maximum number of hops to search for target.\n"));
+    _tprintf(_T("    -j host-list       Loose source route along host-list.\n"));
+    _tprintf(_T("    -w timeout         Wait timeout milliseconds for each reply.\n\n"));
+    
+    /* temp notes to stop user questions until getnameinfo/gethostbyaddr and getsockopt are implemented */
+    _tprintf(_T("NOTES\n-----\n"
+           "- Setting TTL values is not currently supported in ReactOS, so the trace will\n"
+           "  jump straight to the destination. This feature will be implemented soon.\n"
+           "- Host info is not currently available in ReactOS and will fail with strange\n"
+           "  results. Use -d to force it not to resolve IP's.\n"
+           "- For testing purposes, all should work as normal in a Windows environment\n\n"));
+}
+
+
+
+/*
+ *
+ * Program entry point
+ *
+ */
+int main(int argc, char* argv[])
+{
+    if (!ParseCmdline(argc, _argv)) return -1;
+
+    Driver();
+
+    return 0;
+}
index 1fc27e9..4ac7ea6 100644 (file)
@@ -1,80 +1,80 @@
-/*\r
- * COPYRIGHT:   See COPYING in the top level directory\r
- * PROJECT:     ReactOS traceroute utility\r
- * FILE:        apps/utils/net/tracert/tracert.h\r
- * PURPOSE:     trace a packets route through a network\r
- * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)\r
- * REVISIONS:\r
- *   GM 03/05/05 Created\r
- */\r
-\r
-#define ECHO_REPLY 0\r
-#define DEST_UNREACHABLE 3\r
-#define ECHO_REQUEST 8\r
-#define TTL_EXCEEDED 11\r
-\r
-#define ICMP_MIN_SIZE 8\r
-#define ICMP_MAX_SIZE 65535\r
-#define PACKET_SIZE 32\r
-/* we need this for packets which have the 'dont fragment' \r
- * bit set, as they can get quite large otherwise \r
- * (I've seen some reach 182 bytes */\r
-#define MAX_REC_SIZE 200 \r
-\r
-/* pack the structures */\r
-#pragma pack(1) \r
-\r
-/* IPv4 Header, 20 bytes */\r
-typedef struct IPv4Header {\r
-    BYTE h_len:4;\r
-    BYTE version:4;\r
-    BYTE tos;\r
-    USHORT length;\r
-    USHORT id;\r
-    USHORT flag_frag;\r
-    BYTE ttl;\r
-    BYTE proto;\r
-    USHORT checksum;\r
-    ULONG source;\r
-    ULONG dest;\r
-} IPv4_HEADER, *PIPv4_HEADER;\r
-\r
-/* ICMP Header, 8 bytes */\r
-typedef struct ICMPHeader {\r
-    BYTE type;\r
-    BYTE code;\r
-    USHORT checksum;\r
-    USHORT id; // not used in time exceeded\r
-    USHORT seq; // not used in time exceeded\r
-} ICMP_HEADER, *PICMP_HEADER;\r
-\r
-/* ICMP Echo Reply Header, 12 bytes */\r
-typedef struct EchoReplyHeader {\r
-    struct ICMPHeader icmpheader;\r
-    struct timeval timestamp; \r
-} ECHO_REPLY_HEADER, *PECHO_REPLY_HEADER;\r
-\r
-/* ICMP Echo Reply Header, 12 bytes */\r
-typedef struct TTLExceedHeader {\r
-    struct ICMPHeader icmpheader;\r
-    struct IPv4Header ipheader;\r
-    struct ICMPHeader OrigIcmpHeader;\r
-} TTL_EXCEED_HEADER, *PTTL_EXCEED_HEADER;\r
-\r
-/* return to normal */\r
-#pragma pack()\r
-\r
-\r
-/* function definitions */\r
-//BOOL ParseCmdline(int argc, char* argv[]);\r
-INT Driver(void);\r
-INT Setup(INT ttl);\r
-VOID SetupTimingMethod(void);\r
-VOID ResolveHostname(void);\r
-VOID PreparePacket(INT packetSize, INT seqNum);\r
-INT SendPacket(INT datasize);\r
-INT ReceivePacket(INT datasize);\r
-INT DecodeResponse(INT packetSize, INT seqNum);\r
-LONG GetTime(void);\r
-WORD CheckSum(PUSHORT data, UINT size);\r
-VOID Usage(void);\r
+/*
+ * COPYRIGHT:   See COPYING in the top level directory
+ * PROJECT:     ReactOS traceroute utility
+ * FILE:        apps/utils/net/tracert/tracert.h
+ * PURPOSE:     trace a packets route through a network
+ * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
+ * REVISIONS:
+ *   GM 03/05/05 Created
+ */
+
+#define ECHO_REPLY 0
+#define DEST_UNREACHABLE 3
+#define ECHO_REQUEST 8
+#define TTL_EXCEEDED 11
+
+#define ICMP_MIN_SIZE 8
+#define ICMP_MAX_SIZE 65535
+#define PACKET_SIZE 32
+/* we need this for packets which have the 'dont fragment' 
+ * bit set, as they can get quite large otherwise 
+ * (I've seen some reach 182 bytes */
+#define MAX_REC_SIZE 200 
+
+/* pack the structures */
+#pragma pack(1) 
+
+/* IPv4 Header, 20 bytes */
+typedef struct IPv4Header {
+    BYTE h_len:4;
+    BYTE version:4;
+    BYTE tos;
+    USHORT length;
+    USHORT id;
+    USHORT flag_frag;
+    BYTE ttl;
+    BYTE proto;
+    USHORT checksum;
+    ULONG source;
+    ULONG dest;
+} IPv4_HEADER, *PIPv4_HEADER;
+
+/* ICMP Header, 8 bytes */
+typedef struct ICMPHeader {
+    BYTE type;
+    BYTE code;
+    USHORT checksum;
+    USHORT id; // not used in time exceeded
+    USHORT seq; // not used in time exceeded
+} ICMP_HEADER, *PICMP_HEADER;
+
+/* ICMP Echo Reply Header, 12 bytes */
+typedef struct EchoReplyHeader {
+    struct ICMPHeader icmpheader;
+    struct timeval timestamp; 
+} ECHO_REPLY_HEADER, *PECHO_REPLY_HEADER;
+
+/* ICMP Echo Reply Header, 12 bytes */
+typedef struct TTLExceedHeader {
+    struct ICMPHeader icmpheader;
+    struct IPv4Header ipheader;
+    struct ICMPHeader OrigIcmpHeader;
+} TTL_EXCEED_HEADER, *PTTL_EXCEED_HEADER;
+
+/* return to normal */
+#pragma pack()
+
+
+/* function definitions */
+//BOOL ParseCmdline(int argc, char* argv[]);
+INT Driver(void);
+INT Setup(INT ttl);
+VOID SetupTimingMethod(void);
+VOID ResolveHostname(void);
+VOID PreparePacket(INT packetSize, INT seqNum);
+INT SendPacket(INT datasize);
+INT ReceivePacket(INT datasize);
+INT DecodeResponse(INT packetSize, INT seqNum);
+LONG GetTime(void);
+WORD CheckSum(PUSHORT data, UINT size);
+VOID Usage(void);
index 57a7a87..5b3d858 100644 (file)
-/*\r
- * Wine porting definitions\r
- *\r
- * Copyright 1996 Alexandre Julliard\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Lesser General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2.1 of the License, or (at your option) any later version.\r
- *\r
- * This library 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
- * Lesser General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Lesser General Public\r
- * License along with this library; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
- */\r
-\r
-#ifndef __WINE_WINE_PORT_H\r
-#define __WINE_WINE_PORT_H\r
-\r
-#ifndef __WINE_CONFIG_H\r
-# error You must include config.h to use this header\r
-#endif\r
-\r
-#define _GNU_SOURCE  /* for pread/pwrite */\r
-#include <fcntl.h>\r
-#include <math.h>\r
-#include <sys/types.h>\r
-#include <sys/stat.h>\r
-#ifdef HAVE_DIRECT_H\r
-# include <direct.h>\r
-#endif\r
-#ifdef HAVE_IO_H\r
-# include <io.h>\r
-#endif\r
-#ifdef HAVE_PROCESS_H\r
-# include <process.h>\r
-#endif\r
-#include <string.h>\r
-#ifdef HAVE_UNISTD_H\r
-# include <unistd.h>\r
-#endif\r
-\r
-\r
-/****************************************************************\r
- * Type definitions\r
- */\r
-\r
-#ifndef HAVE_MODE_T\r
-typedef int mode_t;\r
-#endif\r
-#ifndef HAVE_OFF_T\r
-typedef long off_t;\r
-#endif\r
-#ifndef HAVE_PID_T\r
-typedef int pid_t;\r
-#endif\r
-#ifndef HAVE_SIZE_T\r
-typedef unsigned int size_t;\r
-#endif\r
-#ifndef HAVE_SSIZE_T\r
-typedef int ssize_t;\r
-#endif\r
-#ifndef HAVE_FSBLKCNT_T\r
-typedef unsigned long fsblkcnt_t;\r
-#endif\r
-#ifndef HAVE_FSFILCNT_T\r
-typedef unsigned long fsfilcnt_t;\r
-#endif\r
-\r
-#ifndef HAVE_STRUCT_STATVFS_F_BLOCKS\r
-struct statvfs\r
-{\r
-    unsigned long f_bsize;\r
-    unsigned long f_frsize;\r
-    fsblkcnt_t    f_blocks;\r
-    fsblkcnt_t    f_bfree;\r
-    fsblkcnt_t    f_bavail;\r
-    fsfilcnt_t    f_files;\r
-    fsfilcnt_t    f_ffree;\r
-    fsfilcnt_t    f_favail;\r
-    unsigned long f_fsid;\r
-    unsigned long f_flag;\r
-    unsigned long f_namemax;\r
-};\r
-#endif /* HAVE_STRUCT_STATVFS_F_BLOCKS */\r
-\r
-\r
-/****************************************************************\r
- * Macro definitions\r
- */\r
-\r
-#ifdef HAVE_DLFCN_H\r
-#include <dlfcn.h>\r
-#else\r
-#define RTLD_LAZY    0x001\r
-#define RTLD_NOW     0x002\r
-#define RTLD_GLOBAL  0x100\r
-#endif\r
-\r
-#if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)\r
-#define ftruncate chsize\r
-#endif\r
-\r
-#if !defined(HAVE_POPEN) && defined(HAVE__POPEN)\r
-#define popen _popen\r
-#endif\r
-\r
-#if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)\r
-#define pclose _pclose\r
-#endif\r
-\r
-#if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)\r
-#define snprintf _snprintf\r
-#endif\r
-\r
-#if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)\r
-#define vsnprintf _vsnprintf\r
-#endif\r
-\r
-#ifndef S_ISLNK\r
-# define S_ISLNK(mod) (0)\r
-#endif\r
-\r
-#ifndef S_ISSOCK\r
-# define S_ISSOCK(mod) (0)\r
-#endif\r
-\r
-#ifndef S_ISDIR\r
-# define S_ISDIR(mod) (((mod) & _S_IFMT) == _S_IFDIR)\r
-#endif\r
-\r
-#ifndef S_ISCHR\r
-# define S_ISCHR(mod) (((mod) & _S_IFMT) == _S_IFCHR)\r
-#endif\r
-\r
-#ifndef S_ISFIFO\r
-# define S_ISFIFO(mod) (((mod) & _S_IFMT) == _S_IFIFO)\r
-#endif\r
-\r
-#ifndef S_ISREG\r
-# define S_ISREG(mod) (((mod) & _S_IFMT) == _S_IFREG)\r
-#endif\r
-\r
-#ifndef S_IWUSR\r
-# define S_IWUSR 0\r
-#endif\r
-\r
-/* So we open files in 64 bit access mode on Linux */\r
-#ifndef O_LARGEFILE\r
-# define O_LARGEFILE 0\r
-#endif\r
-\r
-#ifndef O_NONBLOCK\r
-# define O_NONBLOCK 0\r
-#endif\r
-\r
-#ifndef O_BINARY\r
-# define O_BINARY 0\r
-#endif\r
-\r
-#if !defined(S_IXUSR) && defined(S_IEXEC)\r
-# define S_IXUSR S_IEXEC\r
-#endif\r
-#if !defined(S_IXGRP) && defined(S_IEXEC)\r
-# define S_IXGRP S_IEXEC\r
-#endif\r
-#if !defined(S_IXOTH) && defined(S_IEXEC)\r
-# define S_IXOTH S_IEXEC\r
-#endif\r
-\r
-\r
-/****************************************************************\r
- * Constants\r
- */\r
-\r
-#ifndef M_PI\r
-#define M_PI 3.14159265358979323846\r
-#endif\r
-\r
-#ifndef M_PI_2\r
-#define M_PI_2 1.570796326794896619\r
-#endif\r
-\r
-\r
-/* Macros to define assembler functions somewhat portably */\r
-\r
-#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__APPLE__)\r
-# define __ASM_GLOBAL_FUNC(name,code) \\r
-      __asm__( ".text\n\t" \\r
-               ".align 4\n\t" \\r
-               ".globl " __ASM_NAME(#name) "\n\t" \\r
-               __ASM_FUNC(#name) "\n" \\r
-               __ASM_NAME(#name) ":\n\t" \\r
-               code \\r
-               "\n\t.previous" );\r
-#else  /* defined(__GNUC__) && !defined(__MINGW32__) && !defined(__APPLE__)  */\r
-# define __ASM_GLOBAL_FUNC(name,code) \\r
-      void __asm_dummy_##name(void) { \\r
-          asm( ".align 4\n\t" \\r
-               ".globl " __ASM_NAME(#name) "\n\t" \\r
-               __ASM_FUNC(#name) "\n" \\r
-               __ASM_NAME(#name) ":\n\t" \\r
-               code ); \\r
-      }\r
-#endif  /* __GNUC__ */\r
-\r
-\r
-/* Constructor functions */\r
-\r
-#ifdef __GNUC__\r
-# define DECL_GLOBAL_CONSTRUCTOR(func) \\r
-    static void func(void) __attribute__((constructor)); \\r
-    static void func(void)\r
-#elif defined(__i386__)\r
-# define DECL_GLOBAL_CONSTRUCTOR(func) \\r
-    static void __dummy_init_##func(void) { \\r
-        asm(".section .init,\"ax\"\n\t" \\r
-            "call " #func "\n\t" \\r
-            ".previous"); } \\r
-    static void func(void)\r
-#elif defined(__sparc__)\r
-# define DECL_GLOBAL_CONSTRUCTOR(func) \\r
-    static void __dummy_init_##func(void) { \\r
-        asm("\t.section \".init\",#alloc,#execinstr\n" \\r
-            "\tcall " #func "\n" \\r
-            "\tnop\n" \\r
-            "\t.section \".text\",#alloc,#execinstr\n" ); } \\r
-    static void func(void)\r
-#else\r
-# error You must define the DECL_GLOBAL_CONSTRUCTOR macro for your platform\r
-#endif\r
-\r
-\r
-/* Register functions */\r
-\r
-#ifdef __i386__\r
-#define DEFINE_REGS_ENTRYPOINT( name, fn, args, pop_args ) \\r
-    __ASM_GLOBAL_FUNC( name, \\r
-                       "call " __ASM_NAME("__wine_call_from_32_regs") "\n\t" \\r
-                       ".long " __ASM_NAME(#fn) "\n\t" \\r
-                       ".byte " #args "," #pop_args )\r
-/* FIXME: add support for other CPUs */\r
-#endif  /* __i386__ */\r
-\r
-\r
-/****************************************************************\r
- * Function definitions (only when using libwine_port)\r
- */\r
-\r
-#ifndef NO_LIBWINE_PORT\r
-\r
-#ifndef HAVE_FSTATVFS\r
-int fstatvfs( int fd, struct statvfs *buf );\r
-#endif\r
-\r
-#ifndef HAVE_GETOPT_LONG\r
-extern char *optarg;\r
-extern int optind;\r
-extern int opterr;\r
-extern int optopt;\r
-struct option;\r
-\r
-#ifndef HAVE_STRUCT_OPTION_NAME\r
-struct option\r
-{\r
-    const char *name;\r
-    int has_arg;\r
-    int *flag;\r
-    int val;\r
-};\r
-#endif\r
-\r
-extern int getopt_long (int ___argc, char *const *___argv,\r
-                        const char *__shortopts,\r
-                        const struct option *__longopts, int *__longind);\r
-extern int getopt_long_only (int ___argc, char *const *___argv,\r
-                             const char *__shortopts,\r
-                             const struct option *__longopts, int *__longind);\r
-#endif  /* HAVE_GETOPT_LONG */\r
-\r
-#ifndef HAVE_FFS\r
-int ffs( int x );\r
-#endif\r
-\r
-#ifndef HAVE_FUTIMES\r
-struct timeval;\r
-int futimes(int fd, const struct timeval tv[2]);\r
-#endif\r
-\r
-#ifndef HAVE_GETPAGESIZE\r
-size_t getpagesize(void);\r
-#endif  /* HAVE_GETPAGESIZE */\r
-\r
-#ifndef HAVE_GETTID\r
-pid_t gettid(void);\r
-#endif /* HAVE_GETTID */\r
-\r
-#ifndef HAVE_LSTAT\r
-int lstat(const char *file_name, struct stat *buf);\r
-#endif /* HAVE_LSTAT */\r
-\r
-#ifndef HAVE_MEMMOVE\r
-void *memmove(void *dest, const void *src, size_t len);\r
-#endif /* !defined(HAVE_MEMMOVE) */\r
-\r
-#ifndef HAVE_PREAD\r
-ssize_t pread( int fd, void *buf, size_t count, off_t offset );\r
-#endif /* HAVE_PREAD */\r
-\r
-#ifndef HAVE_PWRITE\r
-ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );\r
-#endif /* HAVE_PWRITE */\r
-\r
-#ifndef HAVE_READLINK\r
-int readlink( const char *path, char *buf, size_t size );\r
-#endif /* HAVE_READLINK */\r
-\r
-#ifndef HAVE_SIGSETJMP\r
-# include <setjmp.h>\r
-typedef jmp_buf sigjmp_buf;\r
-int sigsetjmp( sigjmp_buf buf, int savesigs );\r
-void siglongjmp( sigjmp_buf buf, int val );\r
-#endif /* HAVE_SIGSETJMP */\r
-\r
-#ifndef HAVE_STATVFS\r
-int statvfs( const char *path, struct statvfs *buf );\r
-#endif\r
-\r
-#ifndef HAVE_STRNCASECMP\r
-# ifndef HAVE__STRNICMP\r
-int strncasecmp(const char *str1, const char *str2, size_t n);\r
-# else\r
-# define strncasecmp _strnicmp\r
-# endif\r
-#endif /* !defined(HAVE_STRNCASECMP) */\r
-\r
-#ifndef HAVE_STRERROR\r
-const char *strerror(int err);\r
-#endif /* !defined(HAVE_STRERROR) */\r
-\r
-#ifndef HAVE_STRCASECMP\r
-# ifndef HAVE__STRICMP\r
-int strcasecmp(const char *str1, const char *str2);\r
-# else\r
-# define strcasecmp _stricmp\r
-# endif\r
-#endif /* !defined(HAVE_STRCASECMP) */\r
-\r
-#ifndef HAVE_USLEEP\r
-int usleep (unsigned int useconds);\r
-#endif /* !defined(HAVE_USLEEP) */\r
-\r
-#ifdef __i386__\r
-static inline void *memcpy_unaligned( void *dst, const void *src, size_t size )\r
-{\r
-    return memcpy( dst, src, size );\r
-}\r
-#else\r
-extern void *memcpy_unaligned( void *dst, const void *src, size_t size );\r
-#endif /* __i386__ */\r
-\r
-extern int mkstemps(char *template, int suffix_len);\r
-\r
-/* Process creation flags */\r
-#ifndef _P_WAIT\r
-# define _P_WAIT    0\r
-# define _P_NOWAIT  1\r
-# define _P_OVERLAY 2\r
-# define _P_NOWAITO 3\r
-# define _P_DETACH  4\r
-#endif\r
-#ifndef HAVE_SPAWNVP\r
-extern int spawnvp(int mode, const char *cmdname, const char * const argv[]);\r
-#endif\r
-\r
-/* Interlocked functions */\r
-\r
-#if defined(__i386__) && defined(__GNUC__)\r
-\r
-extern inline long interlocked_cmpxchg( long *dest, long xchg, long compare );\r
-extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );\r
-extern inline long interlocked_xchg( long *dest, long val );\r
-extern inline void *interlocked_xchg_ptr( void **dest, void *val );\r
-extern inline long interlocked_xchg_add( long *dest, long incr );\r
-\r
-extern inline long interlocked_cmpxchg( long *dest, long xchg, long compare )\r
-{\r
-    long ret;\r
-    __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"\r
-                          : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );\r
-    return ret;\r
-}\r
-\r
-extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )\r
-{\r
-    void *ret;\r
-    __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"\r
-                          : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );\r
-    return ret;\r
-}\r
-\r
-extern inline long interlocked_xchg( long *dest, long val )\r
-{\r
-    long ret;\r
-    __asm__ __volatile__( "lock; xchgl %0,(%1)"\r
-                          : "=r" (ret) : "r" (dest), "0" (val) : "memory" );\r
-    return ret;\r
-}\r
-\r
-extern inline void *interlocked_xchg_ptr( void **dest, void *val )\r
-{\r
-    void *ret;\r
-    __asm__ __volatile__( "lock; xchgl %0,(%1)"\r
-                          : "=r" (ret) : "r" (dest), "0" (val) : "memory" );\r
-    return ret;\r
-}\r
-\r
-extern inline long interlocked_xchg_add( long *dest, long incr )\r
-{\r
-    long ret;\r
-    __asm__ __volatile__( "lock; xaddl %0,(%1)"\r
-                          : "=r" (ret) : "r" (dest), "0" (incr) : "memory" );\r
-    return ret;\r
-}\r
-\r
-#else  /* __i386___ && __GNUC__ */\r
-\r
-extern long interlocked_cmpxchg( long *dest, long xchg, long compare );\r
-extern void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );\r
-extern long interlocked_xchg( long *dest, long val );\r
-extern void *interlocked_xchg_ptr( void **dest, void *val );\r
-extern long interlocked_xchg_add( long *dest, long incr );\r
-\r
-#endif  /* __i386___ && __GNUC__ */\r
-\r
-#else /* NO_LIBWINE_PORT */\r
-\r
-#define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable\r
-\r
-#define ffs                     __WINE_NOT_PORTABLE(ffs)\r
-#define fstatvfs                __WINE_NOT_PORTABLE(fstatvfs)\r
-#define futimes                 __WINE_NOT_PORTABLE(futimes)\r
-#define getopt_long             __WINE_NOT_PORTABLE(getopt_long)\r
-#define getopt_long_only        __WINE_NOT_PORTABLE(getopt_long_only)\r
-#define getpagesize             __WINE_NOT_PORTABLE(getpagesize)\r
-#define interlocked_cmpxchg     __WINE_NOT_PORTABLE(interlocked_cmpxchg)\r
-#define interlocked_cmpxchg_ptr __WINE_NOT_PORTABLE(interlocked_cmpxchg_ptr)\r
-#define interlocked_xchg        __WINE_NOT_PORTABLE(interlocked_xchg)\r
-#define interlocked_xchg_ptr    __WINE_NOT_PORTABLE(interlocked_xchg_ptr)\r
-#define interlocked_xchg_add    __WINE_NOT_PORTABLE(interlocked_xchg_add)\r
-#define lstat                   __WINE_NOT_PORTABLE(lstat)\r
-#define memcpy_unaligned        __WINE_NOT_PORTABLE(memcpy_unaligned)\r
-#define memmove                 __WINE_NOT_PORTABLE(memmove)\r
-#define pread                   __WINE_NOT_PORTABLE(pread)\r
-#define pwrite                  __WINE_NOT_PORTABLE(pwrite)\r
-#define spawnvp                 __WINE_NOT_PORTABLE(spawnvp)\r
-#define statvfs                 __WINE_NOT_PORTABLE(statvfs)\r
-#define strcasecmp              __WINE_NOT_PORTABLE(strcasecmp)\r
-#define strerror                __WINE_NOT_PORTABLE(strerror)\r
-#define strncasecmp             __WINE_NOT_PORTABLE(strncasecmp)\r
-#define usleep                  __WINE_NOT_PORTABLE(usleep)\r
-\r
-#endif /* NO_LIBWINE_PORT */\r
-\r
-#endif /* !defined(__WINE_WINE_PORT_H) */\r
+/*
+ * Wine porting definitions
+ *
+ * Copyright 1996 Alexandre Julliard
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef __WINE_WINE_PORT_H
+#define __WINE_WINE_PORT_H
+
+#ifndef __WINE_CONFIG_H
+# error You must include config.h to use this header
+#endif
+
+#define _GNU_SOURCE  /* for pread/pwrite */
+#include <fcntl.h>
+#include <math.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#ifdef HAVE_DIRECT_H
+# include <direct.h>
+#endif
+#ifdef HAVE_IO_H
+# include <io.h>
+#endif
+#ifdef HAVE_PROCESS_H
+# include <process.h>
+#endif
+#include <string.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+
+/****************************************************************
+ * Type definitions
+ */
+
+#ifndef HAVE_MODE_T
+typedef int mode_t;
+#endif
+#ifndef HAVE_OFF_T
+typedef long off_t;
+#endif
+#ifndef HAVE_PID_T
+typedef int pid_t;
+#endif
+#ifndef HAVE_SIZE_T
+typedef unsigned int size_t;
+#endif
+#ifndef HAVE_SSIZE_T
+typedef int ssize_t;
+#endif
+#ifndef HAVE_FSBLKCNT_T
+typedef unsigned long fsblkcnt_t;
+#endif
+#ifndef HAVE_FSFILCNT_T
+typedef unsigned long fsfilcnt_t;
+#endif
+
+#ifndef HAVE_STRUCT_STATVFS_F_BLOCKS
+struct statvfs
+{
+    unsigned long f_bsize;
+    unsigned long f_frsize;
+    fsblkcnt_t    f_blocks;
+    fsblkcnt_t    f_bfree;
+    fsblkcnt_t    f_bavail;
+    fsfilcnt_t    f_files;
+    fsfilcnt_t    f_ffree;
+    fsfilcnt_t    f_favail;
+    unsigned long f_fsid;
+    unsigned long f_flag;
+    unsigned long f_namemax;
+};
+#endif /* HAVE_STRUCT_STATVFS_F_BLOCKS */
+
+
+/****************************************************************
+ * Macro definitions
+ */
+
+#ifdef HAVE_DLFCN_H
+#include <dlfcn.h>
+#else
+#define RTLD_LAZY    0x001
+#define RTLD_NOW     0x002
+#define RTLD_GLOBAL  0x100
+#endif
+
+#if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
+#define ftruncate chsize
+#endif
+
+#if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
+#define popen _popen
+#endif
+
+#if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
+#define pclose _pclose
+#endif
+
+#if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
+#define snprintf _snprintf
+#endif
+
+#if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
+#define vsnprintf _vsnprintf
+#endif
+
+#ifndef S_ISLNK
+# define S_ISLNK(mod) (0)
+#endif
+
+#ifndef S_ISSOCK
+# define S_ISSOCK(mod) (0)
+#endif
+
+#ifndef S_ISDIR
+# define S_ISDIR(mod) (((mod) & _S_IFMT) == _S_IFDIR)
+#endif
+
+#ifndef S_ISCHR
+# define S_ISCHR(mod) (((mod) & _S_IFMT) == _S_IFCHR)
+#endif
+
+#ifndef S_ISFIFO
+# define S_ISFIFO(mod) (((mod) & _S_IFMT) == _S_IFIFO)
+#endif
+
+#ifndef S_ISREG
+# define S_ISREG(mod) (((mod) & _S_IFMT) == _S_IFREG)
+#endif
+
+#ifndef S_IWUSR
+# define S_IWUSR 0
+#endif
+
+/* So we open files in 64 bit access mode on Linux */
+#ifndef O_LARGEFILE
+# define O_LARGEFILE 0
+#endif
+
+#ifndef O_NONBLOCK
+# define O_NONBLOCK 0
+#endif
+
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
+#if !defined(S_IXUSR) && defined(S_IEXEC)
+# define S_IXUSR S_IEXEC
+#endif
+#if !defined(S_IXGRP) && defined(S_IEXEC)
+# define S_IXGRP S_IEXEC
+#endif
+#if !defined(S_IXOTH) && defined(S_IEXEC)
+# define S_IXOTH S_IEXEC
+#endif
+
+
+/****************************************************************
+ * Constants
+ */
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+#ifndef M_PI_2
+#define M_PI_2 1.570796326794896619
+#endif
+
+
+/* Macros to define assembler functions somewhat portably */
+
+#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__APPLE__)
+# define __ASM_GLOBAL_FUNC(name,code) \
+      __asm__( ".text\n\t" \
+               ".align 4\n\t" \
+               ".globl " __ASM_NAME(#name) "\n\t" \
+               __ASM_FUNC(#name) "\n" \
+               __ASM_NAME(#name) ":\n\t" \
+               code \
+               "\n\t.previous" );
+#else  /* defined(__GNUC__) && !defined(__MINGW32__) && !defined(__APPLE__)  */
+# define __ASM_GLOBAL_FUNC(name,code) \
+      void __asm_dummy_##name(void) { \
+          asm( ".align 4\n\t" \
+               ".globl " __ASM_NAME(#name) "\n\t" \
+               __ASM_FUNC(#name) "\n" \
+               __ASM_NAME(#name) ":\n\t" \
+               code ); \
+      }
+#endif  /* __GNUC__ */
+
+
+/* Constructor functions */
+
+#ifdef __GNUC__
+# define DECL_GLOBAL_CONSTRUCTOR(func) \
+    static void func(void) __attribute__((constructor)); \
+    static void func(void)
+#elif defined(__i386__)
+# define DECL_GLOBAL_CONSTRUCTOR(func) \
+    static void __dummy_init_##func(void) { \
+        asm(".section .init,\"ax\"\n\t" \
+            "call " #func "\n\t" \
+            ".previous"); } \
+    static void func(void)
+#elif defined(__sparc__)
+# define DECL_GLOBAL_CONSTRUCTOR(func) \
+    static void __dummy_init_##func(void) { \
+        asm("\t.section \".init\",#alloc,#execinstr\n" \
+            "\tcall " #func "\n" \
+            "\tnop\n" \
+            "\t.section \".text\",#alloc,#execinstr\n" ); } \
+    static void func(void)
+#else
+# error You must define the DECL_GLOBAL_CONSTRUCTOR macro for your platform
+#endif
+
+
+/* Register functions */
+
+#ifdef __i386__
+#define DEFINE_REGS_ENTRYPOINT( name, fn, args, pop_args ) \
+    __ASM_GLOBAL_FUNC( name, \
+                       "call " __ASM_NAME("__wine_call_from_32_regs") "\n\t" \
+                       ".long " __ASM_NAME(#fn) "\n\t" \
+                       ".byte " #args "," #pop_args )
+/* FIXME: add support for other CPUs */
+#endif  /* __i386__ */
+
+
+/****************************************************************
+ * Function definitions (only when using libwine_port)
+ */
+
+#ifndef NO_LIBWINE_PORT
+
+#ifndef HAVE_FSTATVFS
+int fstatvfs( int fd, struct statvfs *buf );
+#endif
+
+#ifndef HAVE_GETOPT_LONG
+extern char *optarg;
+extern int optind;
+extern int opterr;
+extern int optopt;
+struct option;
+
+#ifndef HAVE_STRUCT_OPTION_NAME
+struct option
+{
+    const char *name;
+    int has_arg;
+    int *flag;
+    int val;
+};
+#endif
+
+extern int getopt_long (int ___argc, char *const *___argv,
+                        const char *__shortopts,
+                        const struct option *__longopts, int *__longind);
+extern int getopt_long_only (int ___argc, char *const *___argv,
+                             const char *__shortopts,
+                             const struct option *__longopts, int *__longind);
+#endif  /* HAVE_GETOPT_LONG */
+
+#ifndef HAVE_FFS
+int ffs( int x );
+#endif
+
+#ifndef HAVE_FUTIMES
+struct timeval;
+int futimes(int fd, const struct timeval tv[2]);
+#endif
+
+#ifndef HAVE_GETPAGESIZE
+size_t getpagesize(void);
+#endif  /* HAVE_GETPAGESIZE */
+
+#ifndef HAVE_GETTID
+pid_t gettid(void);
+#endif /* HAVE_GETTID */
+
+#ifndef HAVE_LSTAT
+int lstat(const char *file_name, struct stat *buf);
+#endif /* HAVE_LSTAT */
+
+#ifndef HAVE_MEMMOVE
+void *memmove(void *dest, const void *src, size_t len);
+#endif /* !defined(HAVE_MEMMOVE) */
+
+#ifndef HAVE_PREAD
+ssize_t pread( int fd, void *buf, size_t count, off_t offset );
+#endif /* HAVE_PREAD */
+
+#ifndef HAVE_PWRITE
+ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
+#endif /* HAVE_PWRITE */
+
+#ifndef HAVE_READLINK
+int readlink( const char *path, char *buf, size_t size );
+#endif /* HAVE_READLINK */
+
+#ifndef HAVE_SIGSETJMP
+# include <setjmp.h>
+typedef jmp_buf sigjmp_buf;
+int sigsetjmp( sigjmp_buf buf, int savesigs );
+void siglongjmp( sigjmp_buf buf, int val );
+#endif /* HAVE_SIGSETJMP */
+
+#ifndef HAVE_STATVFS
+int statvfs( const char *path, struct statvfs *buf );
+#endif
+
+#ifndef HAVE_STRNCASECMP
+# ifndef HAVE__STRNICMP
+int strncasecmp(const char *str1, const char *str2, size_t n);
+# else
+# define strncasecmp _strnicmp
+# endif
+#endif /* !defined(HAVE_STRNCASECMP) */
+
+#ifndef HAVE_STRERROR
+const char *strerror(int err);
+#endif /* !defined(HAVE_STRERROR) */
+
+#ifndef HAVE_STRCASECMP
+# ifndef HAVE__STRICMP
+int strcasecmp(const char *str1, const char *str2);
+# else
+# define strcasecmp _stricmp
+# endif
+#endif /* !defined(HAVE_STRCASECMP) */
+
+#ifndef HAVE_USLEEP
+int usleep (unsigned int useconds);
+#endif /* !defined(HAVE_USLEEP) */
+
+#ifdef __i386__
+static inline void *memcpy_unaligned( void *dst, const void *src, size_t size )
+{
+    return memcpy( dst, src, size );
+}
+#else
+extern void *memcpy_unaligned( void *dst, const void *src, size_t size );
+#endif /* __i386__ */
+
+extern int mkstemps(char *template, int suffix_len);
+
+/* Process creation flags */
+#ifndef _P_WAIT
+# define _P_WAIT    0
+# define _P_NOWAIT  1
+# define _P_OVERLAY 2
+# define _P_NOWAITO 3
+# define _P_DETACH  4
+#endif
+#ifndef HAVE_SPAWNVP
+extern int spawnvp(int mode, const char *cmdname, const char * const argv[]);
+#endif
+
+/* Interlocked functions */
+
+#if defined(__i386__) && defined(__GNUC__)
+
+extern inline long interlocked_cmpxchg( long *dest, long xchg, long compare );
+extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
+extern inline long interlocked_xchg( long *dest, long val );
+extern inline void *interlocked_xchg_ptr( void **dest, void *val );
+extern inline long interlocked_xchg_add( long *dest, long incr );
+
+extern inline long interlocked_cmpxchg( long *dest, long xchg, long compare )
+{
+    long ret;
+    __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
+                          : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
+    return ret;
+}
+
+extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
+{
+    void *ret;
+    __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
+                          : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
+    return ret;
+}
+
+extern inline long interlocked_xchg( long *dest, long val )
+{
+    long ret;
+    __asm__ __volatile__( "lock; xchgl %0,(%1)"
+                          : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
+    return ret;
+}
+
+extern inline void *interlocked_xchg_ptr( void **dest, void *val )
+{
+    void *ret;
+    __asm__ __volatile__( "lock; xchgl %0,(%1)"
+                          : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
+    return ret;
+}
+
+extern inline long interlocked_xchg_add( long *dest, long incr )
+{
+    long ret;
+    __asm__ __volatile__( "lock; xaddl %0,(%1)"
+                          : "=r" (ret) : "r" (dest), "0" (incr) : "memory" );
+    return ret;
+}
+
+#else  /* __i386___ && __GNUC__ */
+
+extern long interlocked_cmpxchg( long *dest, long xchg, long compare );
+extern void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
+extern long interlocked_xchg( long *dest, long val );
+extern void *interlocked_xchg_ptr( void **dest, void *val );
+extern long interlocked_xchg_add( long *dest, long incr );
+
+#endif  /* __i386___ && __GNUC__ */
+
+#else /* NO_LIBWINE_PORT */
+
+#define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
+
+#define ffs                     __WINE_NOT_PORTABLE(ffs)
+#define fstatvfs                __WINE_NOT_PORTABLE(fstatvfs)
+#define futimes                 __WINE_NOT_PORTABLE(futimes)
+#define getopt_long             __WINE_NOT_PORTABLE(getopt_long)
+#define getopt_long_only        __WINE_NOT_PORTABLE(getopt_long_only)
+#define getpagesize             __WINE_NOT_PORTABLE(getpagesize)
+#define interlocked_cmpxchg     __WINE_NOT_PORTABLE(interlocked_cmpxchg)
+#define interlocked_cmpxchg_ptr __WINE_NOT_PORTABLE(interlocked_cmpxchg_ptr)
+#define interlocked_xchg        __WINE_NOT_PORTABLE(interlocked_xchg)
+#define interlocked_xchg_ptr    __WINE_NOT_PORTABLE(interlocked_xchg_ptr)
+#define interlocked_xchg_add    __WINE_NOT_PORTABLE(interlocked_xchg_add)
+#define lstat                   __WINE_NOT_PORTABLE(lstat)
+#define memcpy_unaligned        __WINE_NOT_PORTABLE(memcpy_unaligned)
+#define memmove                 __WINE_NOT_PORTABLE(memmove)
+#define pread                   __WINE_NOT_PORTABLE(pread)
+#define pwrite                  __WINE_NOT_PORTABLE(pwrite)
+#define spawnvp                 __WINE_NOT_PORTABLE(spawnvp)
+#define statvfs                 __WINE_NOT_PORTABLE(statvfs)
+#define strcasecmp              __WINE_NOT_PORTABLE(strcasecmp)
+#define strerror                __WINE_NOT_PORTABLE(strerror)
+#define strncasecmp             __WINE_NOT_PORTABLE(strncasecmp)
+#define usleep                  __WINE_NOT_PORTABLE(usleep)
+
+#endif /* NO_LIBWINE_PORT */
+
+#endif /* !defined(__WINE_WINE_PORT_H) */
index 0c6a5af..1c81e6b 100644 (file)
@@ -1,53 +1,53 @@
-/*\r
- * Resource definitions\r
- *\r
- * Copyright 2004 Ferenc Wagner\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Lesser General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2.1 of the License, or (at your option) any later version.\r
- *\r
- * This library 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
- * Lesser General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Lesser General Public\r
- * License along with this library; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
- */\r
-\r
-#define IDI_WINE 1\r
-\r
-#define IDD_STATUS 100\r
-#define IDD_ABOUT  101\r
-\r
-#define IDC_ST0 1000\r
-#define IDC_PB0 1001\r
-#define IDC_ST1 1002\r
-#define IDC_PB1 1003\r
-#define IDC_ST2 1004\r
-#define IDC_PB2 1005\r
-\r
-#define IDC_DIR 2000\r
-#define IDC_OUT 2001\r
-\r
-#define IDC_SB  3000\r
-\r
-#define IDC_EDIT  4000\r
-#define IDC_ABOUT 4001\r
-\r
-/* Resource types */\r
-\r
-#define TESTRES   1000\r
-#define STRINGRES 1001\r
-\r
-/* String resources */\r
-\r
-#define WINE_BUILD 10000\r
-#define BUILD_INFO 10001\r
-#define TESTS_URL  10002\r
-\r
-/* Revision info strings start from this index: */\r
-#define REV_INFO 30000\r
+/*
+ * Resource definitions
+ *
+ * Copyright 2004 Ferenc Wagner
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#define IDI_WINE 1
+
+#define IDD_STATUS 100
+#define IDD_ABOUT  101
+
+#define IDC_ST0 1000
+#define IDC_PB0 1001
+#define IDC_ST1 1002
+#define IDC_PB1 1003
+#define IDC_ST2 1004
+#define IDC_PB2 1005
+
+#define IDC_DIR 2000
+#define IDC_OUT 2001
+
+#define IDC_SB  3000
+
+#define IDC_EDIT  4000
+#define IDC_ABOUT 4001
+
+/* Resource types */
+
+#define TESTRES   1000
+#define STRINGRES 1001
+
+/* String resources */
+
+#define WINE_BUILD 10000
+#define BUILD_INFO 10001
+#define TESTS_URL  10002
+
+/* Revision info strings start from this index: */
+#define REV_INFO 30000
index bd75e5f..d09b90b 100644 (file)
-/*\r
- * Utility functions.\r
- *\r
- * Copyright 2003 Dimitrie O. Paun\r
- * Copyright 2003 Ferenc Wagner\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Lesser General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2.1 of the License, or (at your option) any later version.\r
- *\r
- * This library 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
- * Lesser General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Lesser General Public\r
- * License along with this library; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
- */\r
-\r
-#include <unistd.h>\r
-#include <errno.h>\r
-\r
-#include "winetest.h"\r
-\r
-void *xmalloc (size_t len)\r
-{\r
-    void *p = malloc (len);\r
-\r
-    if (!p) report (R_FATAL, "Out of memory.");\r
-    return p;\r
-}\r
-\r
-void *xrealloc (void *op, size_t len)\r
-{\r
-    void *p = realloc (op, len);\r
-\r
-    if (!p) report (R_FATAL, "Out of memory.");\r
-    return p;\r
-}\r
-\r
-char *vstrfmtmake (size_t *lenp, const char *fmt, va_list ap)\r
-{\r
-    size_t size = 1000;\r
-    char *p, *q;\r
-    int n;\r
-\r
-    p = malloc (size);\r
-    if (!p) return NULL;\r
-    while (1) {\r
-        n = vsnprintf (p, size, fmt, ap);\r
-        if (n < 0) size *= 2;   /* Windows */\r
-        else if ((unsigned)n >= size) size = n+1; /* glibc */\r
-        else break;\r
-        q = realloc (p, size);\r
-        if (!q) {\r
-          free (p);\r
-          return NULL;\r
-       }\r
-       p = q;\r
-    }\r
-    if (lenp) *lenp = n;\r
-    return p;\r
-}\r
-\r
-char *vstrmake (size_t *lenp, va_list ap)\r
-{\r
-    const char *fmt;\r
-\r
-    fmt = va_arg (ap, const char*);\r
-    return vstrfmtmake (lenp, fmt, ap);\r
-}\r
-\r
-char *strmake (size_t *lenp, ...)\r
-{\r
-    va_list ap;\r
-    char *p;\r
-\r
-    va_start (ap, lenp);\r
-    p = vstrmake (lenp, ap);\r
-    if (!p) report (R_FATAL, "Out of memory.");\r
-    va_end (ap);\r
-    return p;\r
-}\r
-\r
-void xprintf (const char *fmt, ...)\r
-{\r
-    va_list ap;\r
-    size_t size;\r
-    ssize_t written;\r
-    char *buffer, *head;\r
-\r
-    va_start (ap, fmt);\r
-    buffer = vstrfmtmake (&size, fmt, ap);\r
-    head = buffer;\r
-    va_end (ap);\r
-    while ((written = write (1, head, size)) != size) {\r
-        if (written == -1)\r
-            report (R_FATAL, "Can't write logs: %d", errno);\r
-        head += written;\r
-        size -= written;\r
-    }\r
-    free (buffer);\r
-}\r
-\r
-const char *\r
-badtagchar (const char *tag)\r
-{\r
-    while (*tag)\r
-        if (('a'<=*tag && *tag<='z') ||\r
-            ('A'<=*tag && *tag<='Z') ||\r
-            ('0'<=*tag && *tag<='9') ||\r
-            *tag=='-' || *tag=='.')\r
-            tag++;\r
-        else return tag;\r
-    return NULL;\r
-}\r
+/*
+ * Utility functions.
+ *
+ * Copyright 2003 Dimitrie O. Paun
+ * Copyright 2003 Ferenc Wagner
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <unistd.h>
+#include <errno.h>
+
+#include "winetest.h"
+
+void *xmalloc (size_t len)
+{
+    void *p = malloc (len);
+
+    if (!p) report (R_FATAL, "Out of memory.");
+    return p;
+}
+
+void *xrealloc (void *op, size_t len)
+{
+    void *p = realloc (op, len);
+
+    if (!p) report (R_FATAL, "Out of memory.");
+    return p;
+}
+
+char *vstrfmtmake (size_t *lenp, const char *fmt, va_list ap)
+{
+    size_t size = 1000;
+    char *p, *q;
+    int n;
+
+    p = malloc (size);
+    if (!p) return NULL;
+    while (1) {
+        n = vsnprintf (p, size, fmt, ap);
+        if (n < 0) size *= 2;   /* Windows */
+        else if ((unsigned)n >= size) size = n+1; /* glibc */
+        else break;
+        q = realloc (p, size);
+        if (!q) {
+          free (p);
+          return NULL;
+       }
+       p = q;
+    }
+    if (lenp) *lenp = n;
+    return p;
+}
+
+char *vstrmake (size_t *lenp, va_list ap)
+{
+    const char *fmt;
+
+    fmt = va_arg (ap, const char*);
+    return vstrfmtmake (lenp, fmt, ap);
+}
+
+char *strmake (size_t *lenp, ...)
+{
+    va_list ap;
+    char *p;
+
+    va_start (ap, lenp);
+    p = vstrmake (lenp, ap);
+    if (!p) report (R_FATAL, "Out of memory.");
+    va_end (ap);
+    return p;
+}
+
+void xprintf (const char *fmt, ...)
+{
+    va_list ap;
+    size_t size;
+    ssize_t written;
+    char *buffer, *head;
+
+    va_start (ap, fmt);
+    buffer = vstrfmtmake (&size, fmt, ap);
+    head = buffer;
+    va_end (ap);
+    while ((written = write (1, head, size)) != size) {
+        if (written == -1)
+            report (R_FATAL, "Can't write logs: %d", errno);
+        head += written;
+        size -= written;
+    }
+    free (buffer);
+}
+
+const char *
+badtagchar (const char *tag)
+{
+    while (*tag)
+        if (('a'<=*tag && *tag<='z') ||
+            ('A'<=*tag && *tag<='Z') ||
+            ('0'<=*tag && *tag<='9') ||
+            *tag=='-' || *tag=='.')
+            tag++;
+        else return tag;
+    return NULL;
+}
index ba9a70d..97ea097 100644 (file)
@@ -1,61 +1,61 @@
-/*\r
- * winetest definitions\r
- *\r
- * Copyright 2003 Dimitrie O. Paun\r
- * Copyright 2003 Ferenc Wagner\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Lesser General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2.1 of the License, or (at your option) any later version.\r
- *\r
- * This library 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
- * Lesser General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Lesser General Public\r
- * License along with this library; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
- */\r
-\r
-#ifndef __WINETESTS_H\r
-#define __WINETESTS_H\r
-\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <stdarg.h>\r
-\r
-void fatal (const char* msg);\r
-void warning (const char* msg);\r
-void *xmalloc (size_t len);\r
-void *xrealloc (void *op, size_t len);\r
-void xprintf (const char *fmt, ...);\r
-char *vstrmake (size_t *lenp, va_list ap);\r
-char *strmake (size_t *lenp, ...);\r
-const char *badtagchar (const char *tag);\r
-\r
-int send_file (const char *name);\r
-\r
-/* GUI definitions */\r
-\r
-#include <windows.h>\r
-\r
-enum report_type {\r
-    R_STATUS = 0,\r
-    R_PROGRESS,\r
-    R_STEP,\r
-    R_DELTA,\r
-    R_DIR,\r
-    R_OUT,\r
-    R_WARNING,\r
-    R_ERROR,\r
-    R_FATAL,\r
-    R_ASK,\r
-    R_TEXTMODE,\r
-    R_QUIET\r
-};\r
-\r
-int report (enum report_type t, ...);\r
-\r
-#endif /* __WINETESTS_H */\r
+/*
+ * winetest definitions
+ *
+ * Copyright 2003 Dimitrie O. Paun
+ * Copyright 2003 Ferenc Wagner
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef __WINETESTS_H
+#define __WINETESTS_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+void fatal (const char* msg);
+void warning (const char* msg);
+void *xmalloc (size_t len);
+void *xrealloc (void *op, size_t len);
+void xprintf (const char *fmt, ...);
+char *vstrmake (size_t *lenp, va_list ap);
+char *strmake (size_t *lenp, ...);
+const char *badtagchar (const char *tag);
+
+int send_file (const char *name);
+
+/* GUI definitions */
+
+#include <windows.h>
+
+enum report_type {
+    R_STATUS = 0,
+    R_PROGRESS,
+    R_STEP,
+    R_DELTA,
+    R_DIR,
+    R_OUT,
+    R_WARNING,
+    R_ERROR,
+    R_FATAL,
+    R_ASK,
+    R_TEXTMODE,
+    R_QUIET
+};
+
+int report (enum report_type t, ...);
+
+#endif /* __WINETESTS_H */
index 6d7b001..0262502 100644 (file)
-/* $Id$ \r
- *\r
- *\r
- * FILE:             drivers/fs/vfat/fastio.c\r
- * PURPOSE:          Fast IO routines.\r
- * COPYRIGHT:        See COPYING in the top level directory\r
- * PROJECT:          ReactOS kernel\r
- * PROGRAMMER:       Herve Poussineau (reactos@poussine.freesurf.fr)\r
- *                   Hartmut Birr\r
- */\r
-\r
-#define NDEBUG\r
-#include "vfat.h"\r
-\r
-BOOLEAN STDCALL\r
-VfatFastIoCheckIfPossible(IN PFILE_OBJECT FileObject,\r
-                          IN PLARGE_INTEGER FileOffset,\r
-                          IN ULONG Lenght,\r
-                          IN BOOLEAN Wait,\r
-                          IN ULONG LockKey,\r
-                          IN BOOLEAN CheckForReadOperation,\r
-                          OUT PIO_STATUS_BLOCK IoStatus,\r
-                          IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-       /* Prevent all Fast I/O requests */\r
-       DPRINT("VfatFastIoCheckIfPossible(): returning FALSE.\n");\r
-       return FALSE;\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatFastIoRead(IN PFILE_OBJECT FileObject,\r
-                          IN PLARGE_INTEGER FileOffset,\r
-                          IN ULONG     Length,\r
-                          IN BOOLEAN Wait,\r
-                          IN ULONG LockKey,\r
-                          OUT PVOID Buffer,\r
-                          OUT PIO_STATUS_BLOCK IoStatus,\r
-               IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatFastIoRead()\n");\r
-   return FALSE;\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatFastIoWrite(IN PFILE_OBJECT FileObject,\r
-                               IN PLARGE_INTEGER FileOffset,\r
-                IN ULONG Length,\r
-                               IN BOOLEAN Wait,\r
-                               IN ULONG LockKey,\r
-                OUT PVOID Buffer,\r
-                               OUT PIO_STATUS_BLOCK IoStatus,\r
-                               IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatFastIoWrite()\n");\r
-   return FALSE;\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatFastIoQueryBasicInfo(IN PFILE_OBJECT FileObject,\r
-                                                IN BOOLEAN     Wait,\r
-                                                OUT PFILE_BASIC_INFORMATION Buffer,\r
-                         OUT PIO_STATUS_BLOCK IoStatus,\r
-                                                IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatFastIoQueryBasicInfo()\n");\r
-   return FALSE;\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatFastIoQueryStandardInfo(IN PFILE_OBJECT FileObject,\r
-                                                       IN BOOLEAN Wait,\r
-                                                       OUT PFILE_STANDARD_INFORMATION Buffer,\r
-                                                       OUT PIO_STATUS_BLOCK IoStatus,\r
-                                                       IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatFastIoQueryStandardInfo\n");\r
-   return FALSE;\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatFastIoLock(IN PFILE_OBJECT FileObject,\r
-                          IN PLARGE_INTEGER FileOffset,\r
-                          IN PLARGE_INTEGER Length,\r
-                          PEPROCESS ProcessId,\r
-                          ULONG Key,\r
-                          BOOLEAN FailImmediately,\r
-                          BOOLEAN ExclusiveLock,\r
-                          OUT PIO_STATUS_BLOCK IoStatus,\r
-                          IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatFastIoLock\n");\r
-   return FALSE;\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatFastIoUnlockSingle(IN PFILE_OBJECT FileObject,\r
-                                          IN PLARGE_INTEGER FileOffset,\r
-                                          IN PLARGE_INTEGER Length,\r
-                                          PEPROCESS ProcessId,\r
-                                          ULONG Key,\r
-                                          OUT PIO_STATUS_BLOCK IoStatus,\r
-                                          IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatFastIoUnlockSingle\n");\r
-   return FALSE;\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatFastIoUnlockAll(IN PFILE_OBJECT FileObject,\r
-                                       PEPROCESS ProcessId,\r
-                                       OUT PIO_STATUS_BLOCK IoStatus,\r
-                                       IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatFastIoUnlockAll\n");\r
-   return FALSE;\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatFastIoUnlockAllByKey(IN PFILE_OBJECT FileObject,\r
-                                                PEPROCESS ProcessId,\r
-                                                ULONG Key,\r
-                                                OUT PIO_STATUS_BLOCK IoStatus,\r
-                                                IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatFastIoUnlockAllByKey\n");\r
-   return FALSE;\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatFastIoDeviceControl(IN PFILE_OBJECT FileObject, \r
-                                               IN BOOLEAN Wait, \r
-                                               IN PVOID InputBuffer OPTIONAL, \r
-                                               IN ULONG InputBufferLength, \r
-                                               OUT PVOID OutputBuffer OPTIONAL, \r
-                                               IN ULONG OutputBufferLength,\r
-                                               IN ULONG IoControlCode, \r
-                                               OUT PIO_STATUS_BLOCK IoStatus, \r
-                                               IN PDEVICE_OBJECT DeviceObject) \r
-{\r
-   DPRINT("VfatFastIoDeviceControl\n");\r
-   return FALSE;\r
-}\r
-\r
-VOID STDCALL\r
-VfatAcquireFileForNtCreateSection(IN PFILE_OBJECT FileObject)\r
-{\r
-   DPRINT("VfatAcquireFileForNtCreateSection\n");\r
-}\r
-\r
-VOID STDCALL\r
-VfatReleaseFileForNtCreateSection(IN PFILE_OBJECT FileObject)\r
-{\r
-   DPRINT("VfatReleaseFileForNtCreateSection\n");\r
-}\r
-\r
-VOID STDCALL\r
-VfatFastIoDetachDevice(IN PDEVICE_OBJECT SourceDevice,\r
-                                          IN PDEVICE_OBJECT TargetDevice)\r
-{\r
-   DPRINT("VfatFastIoDetachDevice\n");\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatFastIoQueryNetworkOpenInfo(IN PFILE_OBJECT FileObject,\r
-                               IN BOOLEAN Wait,\r
-                                                          OUT PFILE_NETWORK_OPEN_INFORMATION Buffer,\r
-                                                          OUT PIO_STATUS_BLOCK IoStatus,\r
-                                                          IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatFastIoQueryNetworkOpenInfo\n");\r
-   return FALSE;\r
-}\r
-\r
-NTSTATUS STDCALL\r
-VfatAcquireForModWrite(IN PFILE_OBJECT FileObject,\r
-                                          IN PLARGE_INTEGER EndingOffset,\r
-                                          OUT PERESOURCE* ResourceToRelease,\r
-                                          IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatAcquireForModWrite\n");\r
-   return STATUS_UNSUCCESSFUL;\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatMdlRead(IN PFILE_OBJECT FileObject,\r
-                       IN PLARGE_INTEGER FileOffset,\r
-                       IN ULONG Length,\r
-                       IN ULONG LockKey,\r
-                       OUT PMDL* MdlChain,\r
-                       OUT PIO_STATUS_BLOCK IoStatus,\r
-                       IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatMdlRead\n");\r
-   return FALSE;\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatMdlReadComplete(IN PFILE_OBJECT FileObject,\r
-                                       IN PMDL MdlChain,\r
-                                       IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatMdlReadComplete\n");\r
-   return FALSE;\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatPrepareMdlWrite(IN PFILE_OBJECT FileObject,\r
-                                       IN PLARGE_INTEGER FileOffset,\r
-                                       IN ULONG Length,\r
-                                       IN ULONG LockKey,\r
-                                       OUT PMDL* MdlChain,\r
-                                       OUT PIO_STATUS_BLOCK IoStatus,\r
-                                       IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatPrepareMdlWrite\n");\r
-   return FALSE;\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatMdlWriteComplete(IN PFILE_OBJECT FileObject,\r
-                                        IN PLARGE_INTEGER FileOffset,\r
-                                        IN PMDL MdlChain,\r
-                                        IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatMdlWriteComplete\n");\r
-   return FALSE;\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatFastIoReadCompressed(IN PFILE_OBJECT FileObject,\r
-                                                IN PLARGE_INTEGER FileOffset,\r
-                                                IN ULONG Length,\r
-                                                IN ULONG LockKey,\r
-                                                OUT PVOID Buffer,\r
-                                                OUT PMDL* MdlChain,\r
-                                                OUT PIO_STATUS_BLOCK IoStatus,\r
-                                                OUT PCOMPRESSED_DATA_INFO CompressedDataInfo,\r
-                                                IN ULONG CompressedDataInfoLength,\r
-                                                IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatFastIoReadCompressed\n");\r
-   return FALSE;\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatFastIoWriteCompressed(IN PFILE_OBJECT FileObject,\r
-                                                 IN PLARGE_INTEGER FileOffset,\r
-                          IN ULONG Length,\r
-                                                 IN ULONG LockKey,\r
-                                                 IN PVOID Buffer,\r
-                                                 OUT PMDL* MdlChain,\r
-                                                 OUT PIO_STATUS_BLOCK IoStatus,\r
-                                                 IN PCOMPRESSED_DATA_INFO CompressedDataInfo,\r
-                                                 IN ULONG CompressedDataInfoLength,\r
-                                                 IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatFastIoWriteCompressed\n");\r
-   return FALSE;\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatMdlReadCompleteCompressed(IN PFILE_OBJECT FileObject,\r
-                                                         IN PMDL MdlChain,\r
-                                                         IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatMdlReadCompleteCompressed\n");\r
-   return FALSE;\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatMdlWriteCompleteCompressed(IN PFILE_OBJECT FileObject,\r
-                                                          IN PLARGE_INTEGER FileOffset,\r
-                                                          IN PMDL MdlChain,\r
-                                                          IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatMdlWriteCompleteCompressed\n");\r
-   return FALSE;\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatFastIoQueryOpen(IN PIRP Irp,\r
-                                       OUT PFILE_NETWORK_OPEN_INFORMATION  NetworkInformation,\r
-                    IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatFastIoQueryOpen\n");\r
-   return FALSE;\r
-}\r
-\r
-NTSTATUS STDCALL\r
-VfatReleaseForModWrite(IN PFILE_OBJECT FileObject,\r
-                                          IN PERESOURCE ResourceToRelease,\r
-                                          IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatReleaseForModWrite\n");\r
-   return STATUS_UNSUCCESSFUL;\r
-}\r
-\r
-NTSTATUS STDCALL\r
-VfatAcquireForCcFlush(IN PFILE_OBJECT FileObject,\r
-                                         IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatAcquireForCcFlush\n");\r
-   return STATUS_UNSUCCESSFUL;\r
-}\r
-\r
-NTSTATUS STDCALL\r
-VfatReleaseForCcFlush(IN PFILE_OBJECT FileObject,\r
-                                         IN PDEVICE_OBJECT DeviceObject)\r
-{\r
-   DPRINT("VfatReleaseForCcFlush\n");\r
-   return STATUS_UNSUCCESSFUL;\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatAcquireForLazyWrite(IN PVOID Context,\r
-                        IN BOOLEAN Wait)\r
-{\r
-   PVFATFCB Fcb = (PVFATFCB)Context;\r
-       ASSERT(Fcb);\r
-       DPRINT("VfatAcquireForLazyWrite(): Fcb %p\n", Fcb);\r
-       \r
-       if (!ExAcquireResourceExclusiveLite(&(Fcb->MainResource), Wait))\r
-       {\r
-               DPRINT("VfatAcquireForLazyWrite(): ExReleaseResourceLite failed.\n");\r
-               return FALSE;\r
-       }\r
-       return TRUE;\r
-}\r
-\r
-VOID STDCALL\r
-VfatReleaseFromLazyWrite(IN PVOID Context)\r
-{\r
-   PVFATFCB Fcb = (PVFATFCB)Context;\r
-       ASSERT(Fcb);\r
-       DPRINT("VfatReleaseFromLazyWrite(): Fcb %p\n", Fcb);\r
-       \r
-       ExReleaseResourceLite(&(Fcb->MainResource));\r
-}\r
-\r
-BOOLEAN STDCALL\r
-VfatAcquireForReadAhead(IN PVOID Context,\r
-                        IN BOOLEAN Wait)\r
-{\r
-   PVFATFCB Fcb = (PVFATFCB)Context;\r
-       ASSERT(Fcb);\r
-       DPRINT("VfatAcquireForReadAhead(): Fcb %p\n", Fcb);\r
-       \r
-       if (!ExAcquireResourceExclusiveLite(&(Fcb->MainResource), Wait))\r
-       {\r
-               DPRINT("VfatAcquireForReadAhead(): ExReleaseResourceLite failed.\n");\r
-               return FALSE;\r
-       }\r
-       return TRUE;\r
-}                              \r
-\r
-VOID STDCALL\r
-VfatReleaseFromReadAhead(IN PVOID Context)\r
-{\r
-   PVFATFCB Fcb = (PVFATFCB)Context;\r
-       ASSERT(Fcb);\r
-       DPRINT("VfatReleaseFromReadAhead(): Fcb %p\n", Fcb);\r
-       \r
-       ExReleaseResourceLite(&(Fcb->MainResource));\r
-}\r
-\r
-VOID\r
-VfatInitFastIoRoutines(PFAST_IO_DISPATCH FastIoDispatch)\r
-{\r
-   FastIoDispatch->SizeOfFastIoDispatch = sizeof(FAST_IO_DISPATCH);\r
-   FastIoDispatch->FastIoCheckIfPossible = VfatFastIoCheckIfPossible;\r
-   FastIoDispatch->FastIoRead = VfatFastIoRead;\r
-   FastIoDispatch->FastIoWrite = VfatFastIoWrite;\r
-   FastIoDispatch->FastIoQueryBasicInfo = VfatFastIoQueryBasicInfo;\r
-   FastIoDispatch->FastIoQueryStandardInfo = VfatFastIoQueryStandardInfo;\r
-   FastIoDispatch->FastIoLock = VfatFastIoLock;\r
-   FastIoDispatch->FastIoUnlockSingle = VfatFastIoUnlockSingle;\r
-   FastIoDispatch->FastIoUnlockAll = VfatFastIoUnlockAll;\r
-   FastIoDispatch->FastIoUnlockAllByKey = VfatFastIoUnlockAllByKey;\r
-   FastIoDispatch->FastIoDeviceControl = VfatFastIoDeviceControl;\r
-   FastIoDispatch->AcquireFileForNtCreateSection = VfatAcquireFileForNtCreateSection;\r
-   FastIoDispatch->ReleaseFileForNtCreateSection = VfatReleaseFileForNtCreateSection;\r
-   FastIoDispatch->FastIoDetachDevice = VfatFastIoDetachDevice;\r
-   FastIoDispatch->FastIoQueryNetworkOpenInfo = VfatFastIoQueryNetworkOpenInfo;\r
-   FastIoDispatch->AcquireForModWrite = VfatAcquireForModWrite;\r
-   FastIoDispatch->MdlRead = VfatMdlRead;\r
-   FastIoDispatch->MdlReadComplete = VfatMdlReadComplete;\r
-   FastIoDispatch->PrepareMdlWrite = VfatPrepareMdlWrite;\r
-   FastIoDispatch->MdlWriteComplete = VfatMdlWriteComplete;\r
-   FastIoDispatch->FastIoReadCompressed = VfatFastIoReadCompressed;\r
-   FastIoDispatch->FastIoWriteCompressed = VfatFastIoWriteCompressed;\r
-   FastIoDispatch->MdlReadCompleteCompressed = VfatMdlReadCompleteCompressed;\r
-   FastIoDispatch->MdlWriteCompleteCompressed = VfatMdlWriteCompleteCompressed;\r
-   FastIoDispatch->FastIoQueryOpen = VfatFastIoQueryOpen;\r
-   FastIoDispatch->ReleaseForModWrite = VfatReleaseForModWrite;\r
-   FastIoDispatch->AcquireForCcFlush = VfatAcquireForCcFlush;\r
-   FastIoDispatch->ReleaseForCcFlush = VfatReleaseForCcFlush;\r
-}\r
-\r
-\r
+/* $Id$ 
+ *
+ *
+ * FILE:             drivers/fs/vfat/fastio.c
+ * PURPOSE:          Fast IO routines.
+ * COPYRIGHT:        See COPYING in the top level directory
+ * PROJECT:          ReactOS kernel
+ * PROGRAMMER:       Herve Poussineau (reactos@poussine.freesurf.fr)
+ *                   Hartmut Birr
+ */
+
+#define NDEBUG
+#include "vfat.h"
+
+BOOLEAN STDCALL
+VfatFastIoCheckIfPossible(IN PFILE_OBJECT FileObject,
+                          IN PLARGE_INTEGER FileOffset,
+                          IN ULONG Lenght,
+                          IN BOOLEAN Wait,
+                          IN ULONG LockKey,
+                          IN BOOLEAN CheckForReadOperation,
+                          OUT PIO_STATUS_BLOCK IoStatus,
+                          IN PDEVICE_OBJECT DeviceObject)
+{
+       /* Prevent all Fast I/O requests */
+       DPRINT("VfatFastIoCheckIfPossible(): returning FALSE.\n");
+       return FALSE;
+}
+
+BOOLEAN STDCALL
+VfatFastIoRead(IN PFILE_OBJECT FileObject,
+                          IN PLARGE_INTEGER FileOffset,
+                          IN ULONG     Length,
+                          IN BOOLEAN Wait,
+                          IN ULONG LockKey,
+                          OUT PVOID Buffer,
+                          OUT PIO_STATUS_BLOCK IoStatus,
+               IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatFastIoRead()\n");
+   return FALSE;
+}
+
+BOOLEAN STDCALL
+VfatFastIoWrite(IN PFILE_OBJECT FileObject,
+                               IN PLARGE_INTEGER FileOffset,
+                IN ULONG Length,
+                               IN BOOLEAN Wait,
+                               IN ULONG LockKey,
+                OUT PVOID Buffer,
+                               OUT PIO_STATUS_BLOCK IoStatus,
+                               IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatFastIoWrite()\n");
+   return FALSE;
+}
+
+BOOLEAN STDCALL
+VfatFastIoQueryBasicInfo(IN PFILE_OBJECT FileObject,
+                                                IN BOOLEAN     Wait,
+                                                OUT PFILE_BASIC_INFORMATION Buffer,
+                         OUT PIO_STATUS_BLOCK IoStatus,
+                                                IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatFastIoQueryBasicInfo()\n");
+   return FALSE;
+}
+
+BOOLEAN STDCALL
+VfatFastIoQueryStandardInfo(IN PFILE_OBJECT FileObject,
+                                                       IN BOOLEAN Wait,
+                                                       OUT PFILE_STANDARD_INFORMATION Buffer,
+                                                       OUT PIO_STATUS_BLOCK IoStatus,
+                                                       IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatFastIoQueryStandardInfo\n");
+   return FALSE;
+}
+
+BOOLEAN STDCALL
+VfatFastIoLock(IN PFILE_OBJECT FileObject,
+                          IN PLARGE_INTEGER FileOffset,
+                          IN PLARGE_INTEGER Length,
+                          PEPROCESS ProcessId,
+                          ULONG Key,
+                          BOOLEAN FailImmediately,
+                          BOOLEAN ExclusiveLock,
+                          OUT PIO_STATUS_BLOCK IoStatus,
+                          IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatFastIoLock\n");
+   return FALSE;
+}
+
+BOOLEAN STDCALL
+VfatFastIoUnlockSingle(IN PFILE_OBJECT FileObject,
+                                          IN PLARGE_INTEGER FileOffset,
+                                          IN PLARGE_INTEGER Length,
+                                          PEPROCESS ProcessId,
+                                          ULONG Key,
+                                          OUT PIO_STATUS_BLOCK IoStatus,
+                                          IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatFastIoUnlockSingle\n");
+   return FALSE;
+}
+
+BOOLEAN STDCALL
+VfatFastIoUnlockAll(IN PFILE_OBJECT FileObject,
+                                       PEPROCESS ProcessId,
+                                       OUT PIO_STATUS_BLOCK IoStatus,
+                                       IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatFastIoUnlockAll\n");
+   return FALSE;
+}
+
+BOOLEAN STDCALL
+VfatFastIoUnlockAllByKey(IN PFILE_OBJECT FileObject,
+                                                PEPROCESS ProcessId,
+                                                ULONG Key,
+                                                OUT PIO_STATUS_BLOCK IoStatus,
+                                                IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatFastIoUnlockAllByKey\n");
+   return FALSE;
+}
+
+BOOLEAN STDCALL
+VfatFastIoDeviceControl(IN PFILE_OBJECT FileObject, 
+                                               IN BOOLEAN Wait, 
+                                               IN PVOID InputBuffer OPTIONAL, 
+                                               IN ULONG InputBufferLength, 
+                                               OUT PVOID OutputBuffer OPTIONAL, 
+                                               IN ULONG OutputBufferLength,
+                                               IN ULONG IoControlCode, 
+                                               OUT PIO_STATUS_BLOCK IoStatus, 
+                                               IN PDEVICE_OBJECT DeviceObject) 
+{
+   DPRINT("VfatFastIoDeviceControl\n");
+   return FALSE;
+}
+
+VOID STDCALL
+VfatAcquireFileForNtCreateSection(IN PFILE_OBJECT FileObject)
+{
+   DPRINT("VfatAcquireFileForNtCreateSection\n");
+}
+
+VOID STDCALL
+VfatReleaseFileForNtCreateSection(IN PFILE_OBJECT FileObject)
+{
+   DPRINT("VfatReleaseFileForNtCreateSection\n");
+}
+
+VOID STDCALL
+VfatFastIoDetachDevice(IN PDEVICE_OBJECT SourceDevice,
+                                          IN PDEVICE_OBJECT TargetDevice)
+{
+   DPRINT("VfatFastIoDetachDevice\n");
+}
+
+BOOLEAN STDCALL
+VfatFastIoQueryNetworkOpenInfo(IN PFILE_OBJECT FileObject,
+                               IN BOOLEAN Wait,
+                                                          OUT PFILE_NETWORK_OPEN_INFORMATION Buffer,
+                                                          OUT PIO_STATUS_BLOCK IoStatus,
+                                                          IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatFastIoQueryNetworkOpenInfo\n");
+   return FALSE;
+}
+
+NTSTATUS STDCALL
+VfatAcquireForModWrite(IN PFILE_OBJECT FileObject,
+                                          IN PLARGE_INTEGER EndingOffset,
+                                          OUT PERESOURCE* ResourceToRelease,
+                                          IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatAcquireForModWrite\n");
+   return STATUS_UNSUCCESSFUL;
+}
+
+BOOLEAN STDCALL
+VfatMdlRead(IN PFILE_OBJECT FileObject,
+                       IN PLARGE_INTEGER FileOffset,
+                       IN ULONG Length,
+                       IN ULONG LockKey,
+                       OUT PMDL* MdlChain,
+                       OUT PIO_STATUS_BLOCK IoStatus,
+                       IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatMdlRead\n");
+   return FALSE;
+}
+
+BOOLEAN STDCALL
+VfatMdlReadComplete(IN PFILE_OBJECT FileObject,
+                                       IN PMDL MdlChain,
+                                       IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatMdlReadComplete\n");
+   return FALSE;
+}
+
+BOOLEAN STDCALL
+VfatPrepareMdlWrite(IN PFILE_OBJECT FileObject,
+                                       IN PLARGE_INTEGER FileOffset,
+                                       IN ULONG Length,
+                                       IN ULONG LockKey,
+                                       OUT PMDL* MdlChain,
+                                       OUT PIO_STATUS_BLOCK IoStatus,
+                                       IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatPrepareMdlWrite\n");
+   return FALSE;
+}
+
+BOOLEAN STDCALL
+VfatMdlWriteComplete(IN PFILE_OBJECT FileObject,
+                                        IN PLARGE_INTEGER FileOffset,
+                                        IN PMDL MdlChain,
+                                        IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatMdlWriteComplete\n");
+   return FALSE;
+}
+
+BOOLEAN STDCALL
+VfatFastIoReadCompressed(IN PFILE_OBJECT FileObject,
+                                                IN PLARGE_INTEGER FileOffset,
+                                                IN ULONG Length,
+                                                IN ULONG LockKey,
+                                                OUT PVOID Buffer,
+                                                OUT PMDL* MdlChain,
+                                                OUT PIO_STATUS_BLOCK IoStatus,
+                                                OUT PCOMPRESSED_DATA_INFO CompressedDataInfo,
+                                                IN ULONG CompressedDataInfoLength,
+                                                IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatFastIoReadCompressed\n");
+   return FALSE;
+}
+
+BOOLEAN STDCALL
+VfatFastIoWriteCompressed(IN PFILE_OBJECT FileObject,
+                                                 IN PLARGE_INTEGER FileOffset,
+                          IN ULONG Length,
+                                                 IN ULONG LockKey,
+                                                 IN PVOID Buffer,
+                                                 OUT PMDL* MdlChain,
+                                                 OUT PIO_STATUS_BLOCK IoStatus,
+                                                 IN PCOMPRESSED_DATA_INFO CompressedDataInfo,
+                                                 IN ULONG CompressedDataInfoLength,
+                                                 IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatFastIoWriteCompressed\n");
+   return FALSE;
+}
+
+BOOLEAN STDCALL
+VfatMdlReadCompleteCompressed(IN PFILE_OBJECT FileObject,
+                                                         IN PMDL MdlChain,
+                                                         IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatMdlReadCompleteCompressed\n");
+   return FALSE;
+}
+
+BOOLEAN STDCALL
+VfatMdlWriteCompleteCompressed(IN PFILE_OBJECT FileObject,
+                                                          IN PLARGE_INTEGER FileOffset,
+                                                          IN PMDL MdlChain,
+                                                          IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatMdlWriteCompleteCompressed\n");
+   return FALSE;
+}
+
+BOOLEAN STDCALL
+VfatFastIoQueryOpen(IN PIRP Irp,
+                                       OUT PFILE_NETWORK_OPEN_INFORMATION  NetworkInformation,
+                    IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatFastIoQueryOpen\n");
+   return FALSE;
+}
+
+NTSTATUS STDCALL
+VfatReleaseForModWrite(IN PFILE_OBJECT FileObject,
+                                          IN PERESOURCE ResourceToRelease,
+                                          IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatReleaseForModWrite\n");
+   return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS STDCALL
+VfatAcquireForCcFlush(IN PFILE_OBJECT FileObject,
+                                         IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatAcquireForCcFlush\n");
+   return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS STDCALL
+VfatReleaseForCcFlush(IN PFILE_OBJECT FileObject,
+                                         IN PDEVICE_OBJECT DeviceObject)
+{
+   DPRINT("VfatReleaseForCcFlush\n");
+   return STATUS_UNSUCCESSFUL;
+}
+
+BOOLEAN STDCALL
+VfatAcquireForLazyWrite(IN PVOID Context,
+                        IN BOOLEAN Wait)
+{
+   PVFATFCB Fcb = (PVFATFCB)Context;
+       ASSERT(Fcb);
+       DPRINT("VfatAcquireForLazyWrite(): Fcb %p\n", Fcb);
+       
+       if (!ExAcquireResourceExclusiveLite(&(Fcb->MainResource), Wait))
+       {
+               DPRINT("VfatAcquireForLazyWrite(): ExReleaseResourceLite failed.\n");
+               return FALSE;
+       }
+       return TRUE;
+}
+
+VOID STDCALL
+VfatReleaseFromLazyWrite(IN PVOID Context)
+{
+   PVFATFCB Fcb = (PVFATFCB)Context;
+       ASSERT(Fcb);
+       DPRINT("VfatReleaseFromLazyWrite(): Fcb %p\n", Fcb);
+       
+       ExReleaseResourceLite(&(Fcb->MainResource));
+}
+
+BOOLEAN STDCALL
+VfatAcquireForReadAhead(IN PVOID Context,
+                        IN BOOLEAN Wait)
+{
+   PVFATFCB Fcb = (PVFATFCB)Context;
+       ASSERT(Fcb);
+       DPRINT("VfatAcquireForReadAhead(): Fcb %p\n", Fcb);
+       
+       if (!ExAcquireResourceExclusiveLite(&(Fcb->MainResource), Wait))
+       {
+               DPRINT("VfatAcquireForReadAhead(): ExReleaseResourceLite failed.\n");
+               return FALSE;
+       }
+       return TRUE;
+}                              
+
+VOID STDCALL
+VfatReleaseFromReadAhead(IN PVOID Context)
+{
+   PVFATFCB Fcb = (PVFATFCB)Context;
+       ASSERT(Fcb);
+       DPRINT("VfatReleaseFromReadAhead(): Fcb %p\n", Fcb);
+       
+       ExReleaseResourceLite(&(Fcb->MainResource));
+}
+
+VOID
+VfatInitFastIoRoutines(PFAST_IO_DISPATCH FastIoDispatch)
+{
+   FastIoDispatch->SizeOfFastIoDispatch = sizeof(FAST_IO_DISPATCH);
+   FastIoDispatch->FastIoCheckIfPossible = VfatFastIoCheckIfPossible;
+   FastIoDispatch->FastIoRead = VfatFastIoRead;
+   FastIoDispatch->FastIoWrite = VfatFastIoWrite;
+   FastIoDispatch->FastIoQueryBasicInfo = VfatFastIoQueryBasicInfo;
+   FastIoDispatch->FastIoQueryStandardInfo = VfatFastIoQueryStandardInfo;
+   FastIoDispatch->FastIoLock = VfatFastIoLock;
+   FastIoDispatch->FastIoUnlockSingle = VfatFastIoUnlockSingle;
+   FastIoDispatch->FastIoUnlockAll = VfatFastIoUnlockAll;
+   FastIoDispatch->FastIoUnlockAllByKey = VfatFastIoUnlockAllByKey;
+   FastIoDispatch->FastIoDeviceControl = VfatFastIoDeviceControl;
+   FastIoDispatch->AcquireFileForNtCreateSection = VfatAcquireFileForNtCreateSection;
+   FastIoDispatch->ReleaseFileForNtCreateSection = VfatReleaseFileForNtCreateSection;
+   FastIoDispatch->FastIoDetachDevice = VfatFastIoDetachDevice;
+   FastIoDispatch->FastIoQueryNetworkOpenInfo = VfatFastIoQueryNetworkOpenInfo;
+   FastIoDispatch->AcquireForModWrite = VfatAcquireForModWrite;
+   FastIoDispatch->MdlRead = VfatMdlRead;
+   FastIoDispatch->MdlReadComplete = VfatMdlReadComplete;
+   FastIoDispatch->PrepareMdlWrite = VfatPrepareMdlWrite;
+   FastIoDispatch->MdlWriteComplete = VfatMdlWriteComplete;
+   FastIoDispatch->FastIoReadCompressed = VfatFastIoReadCompressed;
+   FastIoDispatch->FastIoWriteCompressed = VfatFastIoWriteCompressed;
+   FastIoDispatch->MdlReadCompleteCompressed = VfatMdlReadCompleteCompressed;
+   FastIoDispatch->MdlWriteCompleteCompressed = VfatMdlWriteCompleteCompressed;
+   FastIoDispatch->FastIoQueryOpen = VfatFastIoQueryOpen;
+   FastIoDispatch->ReleaseForModWrite = VfatReleaseForModWrite;
+   FastIoDispatch->AcquireForCcFlush = VfatAcquireForCcFlush;
+   FastIoDispatch->ReleaseForCcFlush = VfatReleaseForCcFlush;
+}
+
+
index 9289968..ee9d1d6 100644 (file)
@@ -1,41 +1,41 @@
-/*\r
- * ReactOS USB EHCI miniport driver\r
- * Copyright (C) 2004 Mark Tempel\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program 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\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
- *\r
- */\r
-\r
-/* INCLUDES *******************************************************************/\r
-\r
-#include "usbehci.h"\r
-#include "../../usbport/usbport.h"\r
-\r
-/* PUBLIC AND PRIVATE FUNCTIONS ***********************************************/\r
-\r
-NTSTATUS STDCALL\r
-DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)\r
-{\r
-       PUSB_CONTROLLER_INTERFACE ControllerInterface;\r
-\r
-       USBPORT_AllocateUsbControllerInterface(&ControllerInterface);\r
-\r
-       /*\r
-        * Set up the list of callbacks here.\r
-        * TODO TODO TODO\r
-        */\r
-       \r
-       return USBPORT_RegisterUSBPortDriver(DriverObject, 0, ControllerInterface);\r
-}\r
+/*
+ * ReactOS USB EHCI miniport driver
+ * Copyright (C) 2004 Mark Tempel
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ */
+
+/* INCLUDES *******************************************************************/
+
+#include "usbehci.h"
+#include "../../usbport/usbport.h"
+
+/* PUBLIC AND PRIVATE FUNCTIONS ***********************************************/
+
+NTSTATUS STDCALL
+DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
+{
+       PUSB_CONTROLLER_INTERFACE ControllerInterface;
+
+       USBPORT_AllocateUsbControllerInterface(&ControllerInterface);
+
+       /*
+        * Set up the list of callbacks here.
+        * TODO TODO TODO
+        */
+       
+       return USBPORT_RegisterUSBPortDriver(DriverObject, 0, ControllerInterface);
+}
index ef601bc..9a01dfb 100644 (file)
@@ -1,44 +1,44 @@
-/*\r
- * ReactOS USB EHCI miniport driver\r
- *\r
- * Copyright (C) 2004 Mark Tempel\r
- *                      \r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program 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\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
- */\r
-\r
-#ifndef USBEHCI_H\r
-#define USBEHCI_H\r
-\r
-/* INCLUDES *******************************************************************/\r
-\r
-#include "stddef.h" \r
-#include "windef.h"\r
-//#include <ddk/miniport.h>\r
-\r
-#ifdef DBG\r
-#define DPRINT(arg) DbgPrint arg;\r
-#else\r
-#define DPRINT(arg)\r
-#endif\r
-\r
-// Export funcs here\r
-/*\r
-BOOL FASTCALL\r
-VBESetColorRegisters(\r
-   PVBE_DEVICE_EXTENSION DeviceExtension,\r
-   PVIDEO_CLUT ColorLookUpTable,\r
-   PSTATUS_BLOCK StatusBlock);\r
-*/\r
-#endif /* USBEHCI_H */\r
+/*
+ * ReactOS USB EHCI miniport driver
+ *
+ * Copyright (C) 2004 Mark Tempel
+ *                      
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifndef USBEHCI_H
+#define USBEHCI_H
+
+/* INCLUDES *******************************************************************/
+
+#include "stddef.h" 
+#include "windef.h"
+//#include <ddk/miniport.h>
+
+#ifdef DBG
+#define DPRINT(arg) DbgPrint arg;
+#else
+#define DPRINT(arg)
+#endif
+
+// Export funcs here
+/*
+BOOL FASTCALL
+VBESetColorRegisters(
+   PVBE_DEVICE_EXTENSION DeviceExtension,
+   PVIDEO_CLUT ColorLookUpTable,
+   PSTATUS_BLOCK StatusBlock);
+*/
+#endif /* USBEHCI_H */
index f8faf89..d81e03c 100644 (file)
@@ -1,41 +1,41 @@
-/*\r
- * ReactOS USB OpenHCI miniport driver\r
- * Copyright (C) 2004 Mark Tempel\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program 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\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
- *\r
- */\r
-\r
-/* INCLUDES *******************************************************************/\r
-\r
-#include "usbohci.h"\r
-#include "../../usbport/usbport.h"\r
-\r
-/* PUBLIC AND PRIVATE FUNCTIONS ***********************************************/\r
-\r
-NTSTATUS STDCALL\r
-DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)\r
-{\r
-       PUSB_CONTROLLER_INTERFACE ControllerInterface;\r
-\r
-       USBPORT_AllocateUsbControllerInterface(&ControllerInterface);\r
-\r
-       /*\r
-        * Set up the list of callbacks here.\r
-        * TODO TODO TODO\r
-        */\r
-       \r
-       return USBPORT_RegisterUSBPortDriver(DriverObject, 0, ControllerInterface);\r
-}\r
+/*
+ * ReactOS USB OpenHCI miniport driver
+ * Copyright (C) 2004 Mark Tempel
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ */
+
+/* INCLUDES *******************************************************************/
+
+#include "usbohci.h"
+#include "../../usbport/usbport.h"
+
+/* PUBLIC AND PRIVATE FUNCTIONS ***********************************************/
+
+NTSTATUS STDCALL
+DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
+{
+       PUSB_CONTROLLER_INTERFACE ControllerInterface;
+
+       USBPORT_AllocateUsbControllerInterface(&ControllerInterface);
+
+       /*
+        * Set up the list of callbacks here.
+        * TODO TODO TODO
+        */
+       
+       return USBPORT_RegisterUSBPortDriver(DriverObject, 0, ControllerInterface);
+}
index 21325b8..277c123 100644 (file)
@@ -1,44 +1,44 @@
-/*\r
- * ReactOS USB OpenHCI miniport driver\r
- *\r
- * Copyright (C) 2004 Mark Tempel\r
- *                      \r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program 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\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
- */\r
-\r
-#ifndef USBOHCI_H\r
-#define USBOHCI_H\r
-\r
-/* INCLUDES *******************************************************************/\r
-\r
-#include "stddef.h" \r
-#include "windef.h"\r
-//#include <ddk/miniport.h>\r
-\r
-#ifdef DBG\r
-#define DPRINT(arg) DbgPrint arg;\r
-#else\r
-#define DPRINT(arg)\r
-#endif\r
-\r
-// Export funcs here\r
-/*\r
-BOOL FASTCALL\r
-VBESetColorRegisters(\r
-   PVBE_DEVICE_EXTENSION DeviceExtension,\r
-   PVIDEO_CLUT ColorLookUpTable,\r
-   PSTATUS_BLOCK StatusBlock);\r
-*/\r
-#endif /* USBOHCI_H */\r
+/*
+ * ReactOS USB OpenHCI miniport driver
+ *
+ * Copyright (C) 2004 Mark Tempel
+ *                      
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifndef USBOHCI_H
+#define USBOHCI_H
+
+/* INCLUDES *******************************************************************/
+
+#include "stddef.h" 
+#include "windef.h"
+//#include <ddk/miniport.h>
+
+#ifdef DBG
+#define DPRINT(arg) DbgPrint arg;
+#else
+#define DPRINT(arg)
+#endif
+
+// Export funcs here
+/*
+BOOL FASTCALL
+VBESetColorRegisters(
+   PVBE_DEVICE_EXTENSION DeviceExtension,
+   PVIDEO_CLUT ColorLookUpTable,
+   PSTATUS_BLOCK StatusBlock);
+*/
+#endif /* USBOHCI_H */
index 7f05712..00f76fc 100644 (file)
@@ -1,43 +1,43 @@
-/*\r
- * ReactOS USB UHCI miniport driver\r
- * Copyright (C) 2004 Mark Tempel\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program 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\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
- *\r
- */\r
-\r
-/* INCLUDES *******************************************************************/\r
-\r
-#include "usbuhci.h"\r
-#include "../../usbport/usbport.h"\r
-#include <debug.h>\r
-/* PUBLIC AND PRIVATE FUNCTIONS ***********************************************/\r
-\r
-NTSTATUS STDCALL\r
-DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)\r
-{\r
-       //return STATUS_SUCCESS;\r
-       //DPRINT1("USBUHCI.SYS DriverEntry\n");\r
-       PUSB_CONTROLLER_INTERFACE ControllerInterface;\r
-\r
-       USBPORT_AllocateUsbControllerInterface(&ControllerInterface);\r
-\r
-       /*\r
-        * Set up the list of callbacks here.\r
-        * TODO TODO TODO\r
-        */\r
-       \r
-       return USBPORT_RegisterUSBPortDriver(DriverObject, 0, ControllerInterface);\r
-}\r
+/*
+ * ReactOS USB UHCI miniport driver
+ * Copyright (C) 2004 Mark Tempel
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ */
+
+/* INCLUDES *******************************************************************/
+
+#include "usbuhci.h"
+#include "../../usbport/usbport.h"
+#include <debug.h>
+/* PUBLIC AND PRIVATE FUNCTIONS ***********************************************/
+
+NTSTATUS STDCALL
+DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
+{
+       //return STATUS_SUCCESS;
+       //DPRINT1("USBUHCI.SYS DriverEntry\n");
+       PUSB_CONTROLLER_INTERFACE ControllerInterface;
+
+       USBPORT_AllocateUsbControllerInterface(&ControllerInterface);
+
+       /*
+        * Set up the list of callbacks here.
+        * TODO TODO TODO
+        */
+       
+       return USBPORT_RegisterUSBPortDriver(DriverObject, 0, ControllerInterface);
+}
index b5fdde3..3e68e0f 100644 (file)
@@ -1,38 +1,38 @@
-/*\r
- * ReactOS USB UHCI miniport driver\r
- *\r
- * Copyright (C) 2004 Mark Tempel\r
- *                      \r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program 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\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
- */\r
-\r
-#ifndef USBUHCI_H\r
-#define USBUHCI_H\r
-\r
-/* INCLUDES *******************************************************************/\r
-\r
-#include "stddef.h" \r
-#include "windef.h"\r
-//#include <ddk/miniport.h>\r
-\r
-// Export funcs here\r
-/*\r
-BOOL FASTCALL\r
-VBESetColorRegisters(\r
-   PVBE_DEVICE_EXTENSION DeviceExtension,\r
-   PVIDEO_CLUT ColorLookUpTable,\r
-   PSTATUS_BLOCK StatusBlock);\r
-*/\r
-#endif /* USBUHCI_H */\r
+/*
+ * ReactOS USB UHCI miniport driver
+ *
+ * Copyright (C) 2004 Mark Tempel
+ *                      
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifndef USBUHCI_H
+#define USBUHCI_H
+
+/* INCLUDES *******************************************************************/
+
+#include "stddef.h" 
+#include "windef.h"
+//#include <ddk/miniport.h>
+
+// Export funcs here
+/*
+BOOL FASTCALL
+VBESetColorRegisters(
+   PVBE_DEVICE_EXTENSION DeviceExtension,
+   PVIDEO_CLUT ColorLookUpTable,
+   PSTATUS_BLOCK StatusBlock);
+*/
+#endif /* USBUHCI_H */
index 193a920..85fe0cb 100644 (file)
@@ -1,33 +1,33 @@
-#include <stdio.h>\r
-#include <windows.h>\r
-#include <ddk/usbdi.h>\r
-\r
-typedef ULONG STDCALL\r
-(*USBD_GetInterfaceLengthTYPE)(\r
-    PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor,\r
-    PUCHAR BufferEnd\r
-    );\r
-\r
-int main()\r
-{\r
-    HMODULE Lib;\r
-    USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;\r
-    USBD_GetInterfaceLengthTYPE USBD_GetInterfaceLength;\r
-\r
-    InterfaceDescriptor.bLength = 10; \r
-    InterfaceDescriptor.bNumEndpoints = 2; \r
-    InterfaceDescriptor.bDescriptorType = /*USB_INTERFACE_DESCRIPTOR_TYPE*/2;\r
-    InterfaceDescriptor.iInterface = 0x1;\r
-\r
-    Lib = LoadLibraryEx("usbd.sys", NULL, DONT_RESOLVE_DLL_REFERENCES);\r
-    USBD_GetInterfaceLength = (USBD_GetInterfaceLengthTYPE)GetProcAddress(Lib, "USBD_GetInterfaceLength");\r
-    printf("%X\n", USBD_GetInterfaceLength(&InterfaceDescriptor, (PUCHAR)((DWORD)&InterfaceDescriptor + sizeof(InterfaceDescriptor))));\r
-    FreeLibrary(Lib);\r
-\r
-    Lib = LoadLibraryEx("usbd.ms", NULL, DONT_RESOLVE_DLL_REFERENCES);\r
-    USBD_GetInterfaceLength = (USBD_GetInterfaceLengthTYPE)GetProcAddress(Lib, "USBD_GetInterfaceLength");\r
-    printf("%X\n", USBD_GetInterfaceLength(&InterfaceDescriptor, (PUCHAR)((DWORD)&InterfaceDescriptor + sizeof(InterfaceDescriptor))));\r
-    FreeLibrary(Lib);\r
-    return 0;\r
-}\r
-                                                            \r
+#include <stdio.h>
+#include <windows.h>
+#include <ddk/usbdi.h>
+
+typedef ULONG STDCALL
+(*USBD_GetInterfaceLengthTYPE)(
+    PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor,
+    PUCHAR BufferEnd
+    );
+
+int main()
+{
+    HMODULE Lib;
+    USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
+    USBD_GetInterfaceLengthTYPE USBD_GetInterfaceLength;
+
+    InterfaceDescriptor.bLength = 10; 
+    InterfaceDescriptor.bNumEndpoints = 2; 
+    InterfaceDescriptor.bDescriptorType = /*USB_INTERFACE_DESCRIPTOR_TYPE*/2;
+    InterfaceDescriptor.iInterface = 0x1;
+
+    Lib = LoadLibraryEx("usbd.sys", NULL, DONT_RESOLVE_DLL_REFERENCES);
+    USBD_GetInterfaceLength = (USBD_GetInterfaceLengthTYPE)GetProcAddress(Lib, "USBD_GetInterfaceLength");
+    printf("%X\n", USBD_GetInterfaceLength(&InterfaceDescriptor, (PUCHAR)((DWORD)&InterfaceDescriptor + sizeof(InterfaceDescriptor))));
+    FreeLibrary(Lib);
+
+    Lib = LoadLibraryEx("usbd.ms", NULL, DONT_RESOLVE_DLL_REFERENCES);
+    USBD_GetInterfaceLength = (USBD_GetInterfaceLengthTYPE)GetProcAddress(Lib, "USBD_GetInterfaceLength");
+    printf("%X\n", USBD_GetInterfaceLength(&InterfaceDescriptor, (PUCHAR)((DWORD)&InterfaceDescriptor + sizeof(InterfaceDescriptor))));
+    FreeLibrary(Lib);
+    return 0;
+}
+                                                            
index d33d67f..6aae920 100644 (file)
-/*\r
- * Universal Serial Bus Driver/Helper Library\r
- *\r
- * Written by Filip Navara <xnavara@volny.cz>\r
- *\r
- * Notes:\r
- *    This driver was obsoleted in Windows XP and most functions\r
- *    became pure stubs. But some of them were retained for backward\r
- *    compatibilty with existing drivers.\r
- *\r
- *    Preserved functions:\r
- *\r
- *    USBD_Debug_GetHeap (implemented)\r
- *    USBD_Debug_RetHeap (implemented)\r
- *    USBD_CalculateUsbBandwidth (implemented, tested)\r
- *    USBD_CreateConfigurationRequestEx (implemented)\r
- *    USBD_CreateConfigurationRequest\r
- *    USBD_GetInterfaceLength (implemented)\r
- *    USBD_ParseConfigurationDescriptorEx\r
- *    USBD_ParseDescriptors\r
- *    USBD_GetPdoRegistryParameters (implemented)\r
- */\r
-\r
-#include <windows.h>\r
-#include <ddk/usbdi.h>\r
-#ifndef PLUGPLAY_REGKEY_DRIVER\r
-#define PLUGPLAY_REGKEY_DRIVER              2\r
-#endif\r
-typedef struct _USBD_INTERFACE_LIST_ENTRY {\r
-    PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor;\r
-    PUSBD_INTERFACE_INFORMATION Interface;\r
-} USBD_INTERFACE_LIST_ENTRY, *PUSBD_INTERFACE_LIST_ENTRY;\r
-\r
-NTSTATUS STDCALL\r
-DriverEntry(PDRIVER_OBJECT DriverObject,\r
-            PUNICODE_STRING RegistryPath)\r
-{\r
-    return STATUS_SUCCESS;\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-DWORD STDCALL\r
-DllInitialize(DWORD Unknown)\r
-{\r
-    return 0;\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-DWORD STDCALL\r
-DllUnload(VOID)\r
-{\r
-    return 0;\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-PVOID STDCALL\r
-USBD_Debug_GetHeap(DWORD Unknown1, POOL_TYPE PoolType, ULONG NumberOfBytes,\r
-       ULONG Tag)\r
-{\r
-    return ExAllocatePoolWithTag(PoolType, NumberOfBytes, Tag);\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-VOID STDCALL\r
-USBD_Debug_RetHeap(PVOID Heap, DWORD Unknown2, DWORD Unknown3)\r
-{\r
-    ExFreePool(Heap);\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-VOID STDCALL\r
-USBD_Debug_LogEntry(PCHAR Name, ULONG_PTR Info1, ULONG_PTR Info2,\r
-    ULONG_PTR Info3)\r
-{\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-PVOID STDCALL\r
-USBD_AllocateDeviceName(DWORD Unknown)\r
-{\r
-    return NULL;\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-DWORD STDCALL\r
-USBD_CalculateUsbBandwidth(\r
-    ULONG MaxPacketSize,\r
-    UCHAR EndpointType,\r
-    BOOLEAN LowSpeed\r
-    )\r
-{\r
-    DWORD OverheadTable[] = {\r
-            0x00, /* UsbdPipeTypeControl */\r
-            0x09, /* UsbdPipeTypeIsochronous */\r
-            0x00, /* UsbdPipeTypeBulk */\r
-            0x0d  /* UsbdPipeTypeInterrupt */\r
-        };\r
-    DWORD Result;\r
-    \r
-    if (OverheadTable[EndpointType] != 0)\r
-    {\r
-        Result = ((MaxPacketSize + OverheadTable[EndpointType]) * 8 * 7) / 6;\r
-        if (LowSpeed)\r
-           return Result << 3;\r
-        return Result;\r
-    }\r
-    return 0;\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-DWORD STDCALL\r
-USBD_Dispatch(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3, DWORD Unknown4)\r
-{\r
-    return 1;\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-VOID STDCALL\r
-USBD_FreeDeviceMutex(PVOID Unknown)\r
-{\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-VOID STDCALL\r
-USBD_FreeDeviceName(PVOID Unknown)\r
-{\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-VOID STDCALL\r
-USBD_WaitDeviceMutex(PVOID Unknown)\r
-{\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-DWORD STDCALL\r
-USBD_GetSuspendPowerState(DWORD Unknown1)\r
-{\r
-    return 0;\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-NTSTATUS STDCALL\r
-USBD_InitializeDevice(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3,\r
-    DWORD Unknown4, DWORD Unknown5, DWORD Unknown6)\r
-{\r
-    return STATUS_NOT_SUPPORTED;\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-NTSTATUS STDCALL\r
-USBD_RegisterHostController(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3,\r
-    DWORD Unknown4, DWORD Unknown5, DWORD Unknown6, DWORD Unknown7,\r
-    DWORD Unknown8, DWORD Unknown9, DWORD Unknown10)\r
-{\r
-    return STATUS_NOT_SUPPORTED;\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-NTSTATUS STDCALL\r
-USBD_GetDeviceInformation(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3)\r
-{\r
-    return STATUS_NOT_SUPPORTED;\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-NTSTATUS STDCALL\r
-USBD_CreateDevice(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3,\r
-    DWORD Unknown4, DWORD Unknown5)\r
-{\r
-    return STATUS_NOT_SUPPORTED;\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-NTSTATUS STDCALL\r
-USBD_RemoveDevice(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3)\r
-{\r
-    return STATUS_NOT_SUPPORTED;\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-VOID STDCALL\r
-USBD_CompleteRequest(DWORD Unknown1, DWORD Unknown2)\r
-{\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-VOID STDCALL\r
-USBD_RegisterHcFilter(\r
-    PDEVICE_OBJECT DeviceObject, \r
-    PDEVICE_OBJECT FilterDeviceObject\r
-    )\r
-{\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-VOID STDCALL\r
-USBD_SetSuspendPowerState(DWORD Unknown1, DWORD Unknown2)\r
-{\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-NTSTATUS STDCALL\r
-USBD_MakePdoName(DWORD Unknown1, DWORD Unknown2)\r
-{\r
-    return STATUS_NOT_SUPPORTED;\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-NTSTATUS STDCALL\r
-USBD_QueryBusTime(\r
-    PDEVICE_OBJECT RootHubPdo,\r
-    PULONG CurrentFrame\r
-    )\r
-{\r
-    return STATUS_NOT_SUPPORTED;\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-VOID STDCALL\r
-USBD_GetUSBDIVersion(\r
-    PUSBD_VERSION_INFORMATION Version\r
-    )\r
-{\r
-    if (Version != NULL)\r
-    {\r
-        Version->USBDI_Version = USBDI_VERSION;\r
-        Version->Supported_USB_Version = 0x100;\r
-    }\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-NTSTATUS STDCALL\r
-USBD_RestoreDevice(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3)\r
-{\r
-    return STATUS_NOT_SUPPORTED;\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-VOID STDCALL\r
-USBD_RegisterHcDeviceCapabilities(DWORD Unknown1, DWORD Unknown2,\r
-    DWORD Unknown3)\r
-{\r
-}\r
-\r
-/*\r
- * @implemented\r
- * FIXME: Test\r
- */\r
-PURB\r
-STDCALL\r
-USBD_CreateConfigurationRequestEx(\r
-    PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,\r
-    PUSBD_INTERFACE_LIST_ENTRY InterfaceList\r
-    )\r
-{\r
-    PURB Urb;\r
-    DWORD UrbSize;\r
-    DWORD InterfaceCount;\r
-\r
-    for (InterfaceCount = 0;\r
-         InterfaceList[InterfaceCount].InterfaceDescriptor != NULL;\r
-         ++InterfaceCount)\r
-       ;\r
-    /* Include the NULL entry */\r
-    ++InterfaceCount;\r
-\r
-    UrbSize = sizeof(Urb->UrbSelectConfiguration) + \r
-       (InterfaceCount * sizeof(PUSBD_INTERFACE_LIST_ENTRY));\r
-    Urb = ExAllocatePool(NonPagedPool, UrbSize);\r
-    Urb->UrbSelectConfiguration.Hdr.Function =\r
-        URB_FUNCTION_SELECT_CONFIGURATION;        \r
-    Urb->UrbSelectConfiguration.Hdr.Length =\r
-        sizeof(Urb->UrbSelectConfiguration);\r
-    Urb->UrbSelectConfiguration.ConfigurationDescriptor = \r
-       ConfigurationDescriptor;\r
-    memcpy((PVOID)&Urb->UrbSelectConfiguration.Interface, (PVOID)InterfaceList,\r
-       InterfaceCount * sizeof(PUSBD_INTERFACE_LIST_ENTRY));\r
-\r
-    return Urb;\r
-}\r
-\r
-/*\r
- * @unimplemented\r
- */\r
-PURB STDCALL\r
-USBD_CreateConfigurationRequest(\r
-    PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,\r
-    PUSHORT Size\r
-    )\r
-{\r
-    return NULL;\r
-}\r
-\r
-/*\r
- * @unimplemented\r
- */\r
-ULONG STDCALL\r
-USBD_GetInterfaceLength(\r
-    PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor,\r
-    PUCHAR BufferEnd\r
-    )\r
-{\r
-    ULONG_PTR Current;\r
-    PUSB_INTERFACE_DESCRIPTOR CurrentDescriptor = InterfaceDescriptor;\r
-    DWORD Length = CurrentDescriptor->bLength;\r
-\r
-    // USB_ENDPOINT_DESCRIPTOR_TYPE\r
-    if (CurrentDescriptor->bDescriptorType == USB_INTERFACE_DESCRIPTOR_TYPE)\r
-    {\r
-        for (Current = (ULONG_PTR)CurrentDescriptor;\r
-             Current < (ULONG_PTR)BufferEnd;\r
-             Current += CurrentDescriptor->bLength)\r
-            CurrentDescriptor = (PUSB_INTERFACE_DESCRIPTOR)Current;\r
-            Length += CurrentDescriptor->bLength;\r
-\r
-    }\r
-    return Length;\r
-}\r
-\r
-/*\r
- * @unimplemented\r
- */\r
-PUSB_INTERFACE_DESCRIPTOR STDCALL\r
-USBD_ParseConfigurationDescriptorEx(\r
-    PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,\r
-    PVOID StartPosition,\r
-    LONG InterfaceNumber,\r
-    LONG AlternateSetting,\r
-    LONG InterfaceClass,\r
-    LONG InterfaceSubClass,\r
-    LONG InterfaceProtocol\r
-    )\r
-{\r
-    return NULL;\r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-PUSB_INTERFACE_DESCRIPTOR STDCALL\r
-USBD_ParseConfigurationDescriptor(\r
-    PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,\r
-    UCHAR InterfaceNumber,\r
-    UCHAR AlternateSetting\r
-    )\r
-{\r
-    return USBD_ParseConfigurationDescriptorEx(ConfigurationDescriptor,\r
-        (PVOID)ConfigurationDescriptor, InterfaceNumber, AlternateSetting,\r
-        -1, -1, -1);\r
-}\r
-\r
-/*\r
- * @unimplemented\r
- */\r
-PUSB_COMMON_DESCRIPTOR STDCALL\r
-USBD_ParseDescriptors(\r
-    PVOID  DescriptorBuffer,\r
-    ULONG  TotalLength,\r
-    PVOID  StartPosition,\r
-    LONG  DescriptorType\r
-    )\r
-{\r
-    return NULL; \r
-}\r
-\r
-/*\r
- * @implemented\r
- */\r
-DWORD STDCALL\r
-USBD_GetPdoRegistryParameter(\r
-    PDEVICE_OBJECT PhysicalDeviceObject,\r
-    PVOID Parameter,\r
-    ULONG ParameterLength,\r
-    PWCHAR KeyName,\r
-    ULONG KeyNameLength\r
-    )\r
-{\r
-    NTSTATUS Status;\r
-    HANDLE DevInstRegKey;\r
-\r
-    Status = IoOpenDeviceRegistryKey(PhysicalDeviceObject,\r
-        PLUGPLAY_REGKEY_DRIVER, STANDARD_RIGHTS_ALL, &DevInstRegKey);\r
-    if (NT_SUCCESS(Status))\r
-    {\r
-        PKEY_VALUE_FULL_INFORMATION FullInfo;\r
-        UNICODE_STRING ValueName;\r
-        ULONG Length;\r
-\r
-        RtlInitUnicodeString(&ValueName, KeyName);\r
-        Length = ParameterLength + KeyNameLength + sizeof(KEY_VALUE_FULL_INFORMATION);\r
-        FullInfo = ExAllocatePool(PagedPool, Length);\r
-        if (FullInfo)\r
-        {\r
-            Status = ZwQueryValueKey(DevInstRegKey, &ValueName,\r
-                KeyValueFullInformation, FullInfo, Length, &Length);\r
-            if (NT_SUCCESS(Status))\r
-            {\r
-                RtlCopyMemory(Parameter,\r
-                    ((PUCHAR)FullInfo) + FullInfo->DataOffset,\r
-                    ParameterLength /*FullInfo->DataLength*/);\r
-            }\r
-            ExFreePool(FullInfo);\r
-        } else\r
-            Status = STATUS_NO_MEMORY;\r
-        ZwClose(DevInstRegKey);\r
-    }\r
-    return Status;\r
-}\r
+/*
+ * Universal Serial Bus Driver/Helper Library
+ *
+ * Written by Filip Navara <xnavara@volny.cz>
+ *
+ * Notes:
+ *    This driver was obsoleted in Windows XP and most functions
+ *    became pure stubs. But some of them were retained for backward
+ *    compatibilty with existing drivers.
+ *
+ *    Preserved functions:
+ *
+ *    USBD_Debug_GetHeap (implemented)
+ *    USBD_Debug_RetHeap (implemented)
+ *    USBD_CalculateUsbBandwidth (implemented, tested)
+ *    USBD_CreateConfigurationRequestEx (implemented)
+ *    USBD_CreateConfigurationRequest
+ *    USBD_GetInterfaceLength (implemented)
+ *    USBD_ParseConfigurationDescriptorEx
+ *    USBD_ParseDescriptors
+ *    USBD_GetPdoRegistryParameters (implemented)
+ */
+
+#include <windows.h>
+#include <ddk/usbdi.h>
+#ifndef PLUGPLAY_REGKEY_DRIVER
+#define PLUGPLAY_REGKEY_DRIVER              2
+#endif
+typedef struct _USBD_INTERFACE_LIST_ENTRY {
+    PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
+    PUSBD_INTERFACE_INFORMATION Interface;
+} USBD_INTERFACE_LIST_ENTRY, *PUSBD_INTERFACE_LIST_ENTRY;
+
+NTSTATUS STDCALL
+DriverEntry(PDRIVER_OBJECT DriverObject,
+            PUNICODE_STRING RegistryPath)
+{
+    return STATUS_SUCCESS;
+}
+
+/*
+ * @implemented
+ */
+DWORD STDCALL
+DllInitialize(DWORD Unknown)
+{
+    return 0;
+}
+
+/*
+ * @implemented
+ */
+DWORD STDCALL
+DllUnload(VOID)
+{
+    return 0;
+}
+
+/*
+ * @implemented
+ */
+PVOID STDCALL
+USBD_Debug_GetHeap(DWORD Unknown1, POOL_TYPE PoolType, ULONG NumberOfBytes,
+       ULONG Tag)
+{
+    return ExAllocatePoolWithTag(PoolType, NumberOfBytes, Tag);
+}
+
+/*
+ * @implemented
+ */
+VOID STDCALL
+USBD_Debug_RetHeap(PVOID Heap, DWORD Unknown2, DWORD Unknown3)
+{
+    ExFreePool(Heap);
+}
+
+/*
+ * @implemented
+ */
+VOID STDCALL
+USBD_Debug_LogEntry(PCHAR Name, ULONG_PTR Info1, ULONG_PTR Info2,
+    ULONG_PTR Info3)
+{
+}
+
+/*
+ * @implemented
+ */
+PVOID STDCALL
+USBD_AllocateDeviceName(DWORD Unknown)
+{
+    return NULL;
+}
+
+/*
+ * @implemented
+ */
+DWORD STDCALL
+USBD_CalculateUsbBandwidth(
+    ULONG MaxPacketSize,
+    UCHAR EndpointType,
+    BOOLEAN LowSpeed
+    )
+{
+    DWORD OverheadTable[] = {
+            0x00, /* UsbdPipeTypeControl */
+            0x09, /* UsbdPipeTypeIsochronous */
+            0x00, /* UsbdPipeTypeBulk */
+            0x0d  /* UsbdPipeTypeInterrupt */
+        };
+    DWORD Result;
+    
+    if (OverheadTable[EndpointType] != 0)
+    {
+        Result = ((MaxPacketSize + OverheadTable[EndpointType]) * 8 * 7) / 6;
+        if (LowSpeed)
+           return Result << 3;
+        return Result;
+    }
+    return 0;
+}
+
+/*