Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
3.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: header.cxx
  7. //
  8. // Contents: Code to manage MSF header
  9. //
  10. // Classes: Defined in header.hxx
  11. //
  12. //--------------------------------------------------------------------------
  13. #include "msfhead.cxx"
  14. #include "h/dfver.h"
  15. // Function set [uArg] to the byte order of the machine.
  16. //
  17. // it will return 0xFFFE on Little Endian (== the disk order)
  18. // and 0xFEFF on Big Endian
  19. const BYTE abDiskByteOrder[]= {0xFE, 0xFF};
  20. inline void SetMachineByteOrder(USHORT *pUShort)
  21. {
  22. memcpy(pUShort, abDiskByteOrder, sizeof(abDiskByteOrder));
  23. }
  24. CMSFHeader::CMSFHeader(USHORT uSectorShift)
  25. {
  26. msfAssert((CSECTFATREAL != CSECTFAT) || (sizeof(CMSFHeader) == HEADERSIZE));
  27. _uSectorShift = uSectorShift;
  28. _uMiniSectorShift = MINISECTORSHIFT;
  29. _ulMiniSectorCutoff = MINISTREAMSIZE;
  30. _clid = IID_NULL;
  31. SetMachineByteOrder(&_uByteOrder);
  32. _uMinorVersion = rmm;
  33. _uDllVersion = rmj;
  34. for (SECT sect = 0; sect < CSECTFAT; sect ++)
  35. {
  36. _sectFat[sect] = FREESECT;
  37. }
  38. SetDifLength(0);
  39. SetDifStart(ENDOFCHAIN);
  40. SetFatLength(1);
  41. SetFatStart(SECTFAT);
  42. SetDirStart(SECTDIR);
  43. SetMiniFatLength(0);
  44. SetMiniFatStart(ENDOFCHAIN);
  45. _signature = 0;
  46. _usReserved = 0;
  47. _ulReserved1 = _ulReserved2 = 0;
  48. // Write DocFile signature
  49. memcpy(abSig, SIGSTG, CBSIGSTG);
  50. }
  51. //+---------------------------------------------------------------------------
  52. //
  53. // Function: CheckSignature, private
  54. //
  55. // Synopsis: Checks the given memory against known signatures
  56. //
  57. // Arguments: [pb] - Pointer to memory to check
  58. //
  59. // Returns: S_OK - Current signature
  60. // S_FALSE - Beta 2 signature, but still successful
  61. // Appropriate status code
  62. //
  63. //----------------------------------------------------------------------------
  64. //Identifier for first bytes of Beta 2 Docfiles
  65. const BYTE SIGSTG_B2[] = {0x0e, 0x11, 0xfc, 0x0d, 0xd0, 0xcf, 0x11, 0xe0};
  66. const BYTE CBSIGSTG_B2 = sizeof(SIGSTG_B2);
  67. SCODE CheckSignature(BYTE *pb)
  68. {
  69. SCODE sc;
  70. msfDebugOut((DEB_ITRACE, "In CheckSignature(%p)\n", pb));
  71. // Check for ship Docfile signature first
  72. if (memcmp(pb, SIGSTG, CBSIGSTG) == 0)
  73. sc = S_OK;
  74. // Check for Beta 2 Docfile signature
  75. else if (memcmp(pb, SIGSTG_B2, CBSIGSTG_B2) == 0)
  76. sc = S_FALSE;
  77. else
  78. sc = STG_E_INVALIDHEADER;
  79. msfDebugOut((DEB_ITRACE, "Out CheckSignature => %lX\n", sc));
  80. return sc;
  81. }
  82. //+-------------------------------------------------------------------------
  83. //
  84. // Method: CMSFHeader::Validate, public
  85. //
  86. // Synopsis: Validate a header.
  87. //
  88. // Returns: S_OK if header is valid.
  89. //
  90. //--------------------------------------------------------------------------
  91. SCODE CMSFHeader::Validate(VOID) const
  92. {
  93. SCODE sc;
  94. sc = CheckSignature((BYTE *)abSig);
  95. if (sc == S_OK)
  96. {
  97. // Check file format verson number
  98. if (GetDllVersion() > rmj)
  99. return STG_E_OLDDLL;
  100. // check for unreasonably large SectorShift
  101. if (GetSectorShift() > MAXSECTORSHIFT)
  102. return STG_E_DOCFILECORRUPT;
  103. }
  104. return sc;
  105. }