Leaked source code of windows server 2003
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.

144 lines
3.6 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 = (USHORT) (uSectorShift > SECTORSHIFT512 ? rmjlarge : 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 = 0;
  48. _csectDir = (uSectorShift > SECTORSHIFT512) ? 1 : 0;
  49. // Write DocFile signature
  50. memcpy(abSig, SIGSTG, CBSIGSTG);
  51. }
  52. //+---------------------------------------------------------------------------
  53. //
  54. // Function: CheckSignature, private
  55. //
  56. // Synopsis: Checks the given memory against known signatures
  57. //
  58. // Arguments: [pb] - Pointer to memory to check
  59. //
  60. // Returns: S_OK - Current signature
  61. // S_FALSE - Beta 2 signature, but still successful
  62. // Appropriate status code
  63. //
  64. //----------------------------------------------------------------------------
  65. //Identifier for first bytes of Beta 2 Docfiles
  66. const BYTE SIGSTG_B2[] = {0x0e, 0x11, 0xfc, 0x0d, 0xd0, 0xcf, 0x11, 0xe0};
  67. const BYTE CBSIGSTG_B2 = sizeof(SIGSTG_B2);
  68. SCODE CheckSignature(BYTE *pb)
  69. {
  70. SCODE sc;
  71. msfDebugOut((DEB_ITRACE, "In CheckSignature(%p)\n", pb));
  72. // Check for ship Docfile signature first
  73. if (memcmp(pb, SIGSTG, CBSIGSTG) == 0)
  74. sc = S_OK;
  75. // Check for Beta 2 Docfile signature
  76. else if (memcmp(pb, SIGSTG_B2, CBSIGSTG_B2) == 0)
  77. sc = S_FALSE;
  78. else
  79. sc = STG_E_INVALIDHEADER;
  80. msfDebugOut((DEB_ITRACE, "Out CheckSignature => %lX\n", sc));
  81. return sc;
  82. }
  83. //+-------------------------------------------------------------------------
  84. //
  85. // Method: CMSFHeader::Validate, public
  86. //
  87. // Synopsis: Validate a header.
  88. //
  89. // Returns: S_OK if header is valid.
  90. //
  91. //--------------------------------------------------------------------------
  92. SCODE CMSFHeader::Validate(VOID) const
  93. {
  94. SCODE sc;
  95. USHORT uShift;
  96. sc = CheckSignature((BYTE *)abSig);
  97. if (sc == S_OK)
  98. {
  99. uShift = GetSectorShift();
  100. // Check file format verson number
  101. if (GetDllVersion() > rmjlarge)
  102. return STG_E_OLDDLL;
  103. // check for invalid sector shifts
  104. if ((uShift != SECTORSHIFT512 && uShift != SECTORSHIFT4K) ||
  105. GetMiniSectorShift() != MINISECTORSHIFT )
  106. {
  107. return STG_E_DOCFILECORRUPT;
  108. }
  109. }
  110. return sc;
  111. }