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.

123 lines
3.3 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. // History: 11-Dec-91 PhilipLa Created.
  13. //
  14. //--------------------------------------------------------------------------
  15. #include "msfhead.cxx"
  16. #pragma hdrstop
  17. #include <dfver.h>
  18. CMSFHeaderData::CMSFHeaderData(USHORT uSectorShift)
  19. {
  20. msfAssert((CSECTFATREAL != CSECTFAT) || (sizeof(CMSFHeaderData) == HEADERSIZE));
  21. _uSectorShift = uSectorShift;
  22. _uMiniSectorShift = MINISECTORSHIFT;
  23. _ulMiniSectorCutoff = MINISTREAMSIZE;
  24. _clid = IID_NULL;
  25. _uByteOrder = 0xFFFE;
  26. _uMinorVersion = rmm;
  27. _uDllVersion = (USHORT) (uSectorShift > SECTORSHIFT512 ? rmjlarge : rmj);
  28. for (SECT sect = 0; sect < CSECTFAT; sect ++)
  29. {
  30. _sectFat[sect] = FREESECT;
  31. }
  32. _csectDif = 0;
  33. _sectDifStart = ENDOFCHAIN;
  34. _csectFat = 1;
  35. _sectFat[0] = SECTFAT;
  36. _sectDirStart = SECTDIR;
  37. _csectMiniFat = 0;
  38. _sectMiniFatStart = ENDOFCHAIN;
  39. _signature = 0;
  40. _usReserved = 0;
  41. _ulReserved1 = 0;
  42. _csectDir = (uSectorShift > SECTORSHIFT512) ? 1 : 0;
  43. // Write DocFile signature
  44. memcpy(abSig, SIGSTG, CBSIGSTG);
  45. }
  46. CMSFHeader::CMSFHeader(USHORT uSectorShift)
  47. :_hdr(uSectorShift)
  48. {
  49. //We set this to dirty here. There are three cases in which a header
  50. // can be initialized:
  51. //1) Creating a new docfile.
  52. //2) Converting a flat file to a docfile.
  53. //3) Opening an existing file.
  54. //
  55. //We have a separate CMStream::Init* function for each of these cases.
  56. //
  57. //We set the header dirty, then explicitly set it clean in case 3
  58. // above. For the other cases, it is constructed dirty and we
  59. // want it that way.
  60. _fDirty = TRUE;
  61. }
  62. //+-------------------------------------------------------------------------
  63. //
  64. // Method: CMSFHeader::Validate, public
  65. //
  66. // Synopsis: Validate a header.
  67. //
  68. // Returns: S_OK if header is valid.
  69. //
  70. // History: 21-Aug-92 PhilipLa Created.
  71. // 27-Jan-93 AlexT Changed to final signature
  72. //
  73. //--------------------------------------------------------------------------
  74. SCODE CMSFHeader::Validate(VOID) const
  75. {
  76. SCODE sc;
  77. USHORT uShift;
  78. sc = CheckSignature((BYTE *)_hdr.abSig);
  79. if (sc == S_OK)
  80. {
  81. uShift = GetSectorShift();
  82. // Check file format verson number
  83. if (GetDllVersion() > rmjlarge)
  84. return STG_E_OLDDLL;
  85. // check for invalid sector shifts
  86. if ((uShift != SECTORSHIFT512 && uShift != SECTORSHIFT4K) ||
  87. GetMiniSectorShift() != MINISECTORSHIFT )
  88. {
  89. return STG_E_DOCFILECORRUPT;
  90. }
  91. // for default sector sizes, Korean apps write into the cutoff field
  92. // so the ministream cutoff is not validated for 512 byte sectors
  93. if (uShift == SECTORSHIFT4K &&
  94. GetMiniSectorCutoff() != MINISTREAMSIZE)
  95. {
  96. return STG_E_DOCFILECORRUPT;
  97. }
  98. }
  99. return sc;
  100. }