1bbfc4cc7SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3bbfc4cc7SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4bbfc4cc7SAndrew Rist * or more contributor license agreements. See the NOTICE file 5bbfc4cc7SAndrew Rist * distributed with this work for additional information 6bbfc4cc7SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7bbfc4cc7SAndrew Rist * to you under the Apache License, Version 2.0 (the 8bbfc4cc7SAndrew Rist * "License"); you may not use this file except in compliance 9bbfc4cc7SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11bbfc4cc7SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13bbfc4cc7SAndrew Rist * Unless required by applicable law or agreed to in writing, 14bbfc4cc7SAndrew Rist * software distributed under the License is distributed on an 15bbfc4cc7SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16bbfc4cc7SAndrew Rist * KIND, either express or implied. See the License for the 17bbfc4cc7SAndrew Rist * specific language governing permissions and limitations 18bbfc4cc7SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20bbfc4cc7SAndrew Rist *************************************************************/ 21bbfc4cc7SAndrew Rist 22bbfc4cc7SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // This file reflects the structure of MS file elements. 25cdf0e10cSrcweir // It is very sensitive to alignment! 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifndef _STGELEM_HXX 28cdf0e10cSrcweir #define _STGELEM_HXX 29cdf0e10cSrcweir 30cdf0e10cSrcweir #ifndef _TOOLS_SOLAR_H 31cdf0e10cSrcweir #include <tools/solar.h> 32cdf0e10cSrcweir #endif 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include <sot/stg.hxx> 35cdf0e10cSrcweir 36cdf0e10cSrcweir class StgIo; 37cdf0e10cSrcweir class SvStream; 38cdf0e10cSrcweir class String; 39cdf0e10cSrcweir 40cdf0e10cSrcweir SvStream& operator>>( SvStream&, ClsId& ); 41cdf0e10cSrcweir SvStream& operator<<( SvStream&, const ClsId& ); 42cdf0e10cSrcweir 43cdf0e10cSrcweir class StgHeader 44cdf0e10cSrcweir { 45*40300343SOliver-Rainer Wittmann static const sal_uInt8 cFATPagesInHeader = 109; 46*40300343SOliver-Rainer Wittmann 47cdf0e10cSrcweir sal_uInt8 cSignature[ 8 ]; // 00 signature (see below) 48cdf0e10cSrcweir ClsId aClsId; // 08 Class ID 49cdf0e10cSrcweir sal_Int32 nVersion; // 18 version number 50cdf0e10cSrcweir sal_uInt16 nByteOrder; // 1C Unicode byte order indicator 51cdf0e10cSrcweir sal_Int16 nPageSize; // 1E 1 << nPageSize = block size 52cdf0e10cSrcweir sal_Int16 nDataPageSize; // 20 1 << this size == data block size 53cdf0e10cSrcweir sal_uInt8 bDirty; // 22 internal dirty flag 54cdf0e10cSrcweir sal_uInt8 cReserved[ 9 ]; // 23 55cdf0e10cSrcweir sal_Int32 nFATSize; // 2C total number of FAT pages 56cdf0e10cSrcweir sal_Int32 nTOCstrm; // 30 starting page for the TOC stream 57cdf0e10cSrcweir sal_Int32 nReserved; // 34 58cdf0e10cSrcweir sal_Int32 nThreshold; // 38 minimum file size for big data 59cdf0e10cSrcweir sal_Int32 nDataFAT; // 3C page # of 1st data FAT block 60cdf0e10cSrcweir sal_Int32 nDataFATSize; // 40 # of data fat blocks 61cdf0e10cSrcweir sal_Int32 nMasterChain; // 44 chain to the next master block 62cdf0e10cSrcweir sal_Int32 nMaster; // 48 # of additional master blocks 63*40300343SOliver-Rainer Wittmann sal_Int32 nMasterFAT[ cFATPagesInHeader ]; // 4C first [cFATPagesInHeader] master FAT pages 64cdf0e10cSrcweir public: 65cdf0e10cSrcweir StgHeader(); 66297a844aSArmin Le Grand 67cdf0e10cSrcweir void Init(); // initialize the header 68cdf0e10cSrcweir sal_Bool Load( StgIo& ); 69cdf0e10cSrcweir sal_Bool Load( SvStream& ); 70cdf0e10cSrcweir sal_Bool Store( StgIo& ); 71cdf0e10cSrcweir sal_Bool Check(); // check the signature and version GetByteOrder() const72cdf0e10cSrcweir short GetByteOrder() const { return nByteOrder; } GetTOCStart() const73cdf0e10cSrcweir sal_Int32 GetTOCStart() const { return nTOCstrm; } 74cdf0e10cSrcweir void SetTOCStart( sal_Int32 n ); GetDataFATStart() const75cdf0e10cSrcweir sal_Int32 GetDataFATStart() const { return nDataFAT; } 76cdf0e10cSrcweir void SetDataFATStart( sal_Int32 n ); GetDataFATSize() const77cdf0e10cSrcweir sal_Int32 GetDataFATSize() const { return nDataFATSize; } 78cdf0e10cSrcweir void SetDataFATSize( sal_Int32 n ); GetThreshold() const79cdf0e10cSrcweir sal_Int32 GetThreshold() const { return nThreshold; } GetPageSize() const80cdf0e10cSrcweir short GetPageSize() const { return nPageSize; } GetDataPageSize() const81cdf0e10cSrcweir short GetDataPageSize() const { return nDataPageSize; } GetFATSize() const82cdf0e10cSrcweir sal_Int32 GetFATSize() const { return nFATSize; } 83cdf0e10cSrcweir void SetFATSize( sal_Int32 n ); GetFATChain() const84cdf0e10cSrcweir sal_Int32 GetFATChain() const { return nMasterChain; } 85cdf0e10cSrcweir void SetFATChain( sal_Int32 n ); GetMasters() const86cdf0e10cSrcweir sal_Int32 GetMasters() const { return nMaster; } 87cdf0e10cSrcweir void SetMasters( sal_Int32 n ); GetFAT1Size() const88*40300343SOliver-Rainer Wittmann short GetFAT1Size() const { return cFATPagesInHeader; } GetClassId() const89cdf0e10cSrcweir const ClsId& GetClassId() const { return aClsId; } 90cdf0e10cSrcweir void SetClassId( const ClsId& ); 91cdf0e10cSrcweir sal_Int32 GetFATPage( short ) const; 92cdf0e10cSrcweir void SetFATPage( short, sal_Int32 ); 93cdf0e10cSrcweir }; 94cdf0e10cSrcweir 95cdf0e10cSrcweir enum StgEntryType { // dir entry types: 96cdf0e10cSrcweir STG_EMPTY = 0, 97cdf0e10cSrcweir STG_STORAGE = 1, 98cdf0e10cSrcweir STG_STREAM = 2, 99cdf0e10cSrcweir STG_LOCKBYTES = 3, 100cdf0e10cSrcweir STG_PROPERTY = 4, 101cdf0e10cSrcweir STG_ROOT = 5 102cdf0e10cSrcweir }; 103cdf0e10cSrcweir 104cdf0e10cSrcweir enum StgEntryRef { // reference blocks: 105cdf0e10cSrcweir STG_LEFT = 0, // left 106cdf0e10cSrcweir STG_RIGHT = 1, // right 107cdf0e10cSrcweir STG_CHILD = 2, // child 108cdf0e10cSrcweir STG_DATA = 3 // data start 109cdf0e10cSrcweir }; 110cdf0e10cSrcweir 111cdf0e10cSrcweir enum StgEntryTime { // time codes: 112cdf0e10cSrcweir STG_MODIFIED = 0, // last modification 113cdf0e10cSrcweir STG_ACCESSED = 1 // last access 114cdf0e10cSrcweir }; 115cdf0e10cSrcweir 116cdf0e10cSrcweir class StgStream; 117cdf0e10cSrcweir 118cdf0e10cSrcweir #define STGENTRY_SIZE 128 119cdf0e10cSrcweir 120cdf0e10cSrcweir class StgEntry { // directory enty 121cdf0e10cSrcweir sal_uInt16 nName[ 32 ]; // 00 name as WCHAR 122cdf0e10cSrcweir sal_Int16 nNameLen; // 40 size of name in bytes including 00H 123cdf0e10cSrcweir sal_uInt8 cType; // 42 entry type 124cdf0e10cSrcweir sal_uInt8 cFlags; // 43 0 or 1 (tree balance?) 125cdf0e10cSrcweir sal_Int32 nLeft; // 44 left node entry 126cdf0e10cSrcweir sal_Int32 nRight; // 48 right node entry 127cdf0e10cSrcweir sal_Int32 nChild; // 4C 1st child entry if storage 128cdf0e10cSrcweir ClsId aClsId; // 50 class ID (optional) 129cdf0e10cSrcweir sal_Int32 nFlags; // 60 state flags(?) 130cdf0e10cSrcweir sal_Int32 nMtime[ 2 ]; // 64 modification time 131cdf0e10cSrcweir sal_Int32 nAtime[ 2 ]; // 6C creation and access time 132cdf0e10cSrcweir sal_Int32 nPage1; // 74 starting block (either direct or translated) 133cdf0e10cSrcweir sal_Int32 nSize; // 78 file size 134cdf0e10cSrcweir sal_Int32 nUnknown; // 7C unknown 135cdf0e10cSrcweir String aName; // Name as Compare String (ascii, upper) 136cdf0e10cSrcweir public: 137cdf0e10cSrcweir sal_Bool Init(); // initialize the data 138cdf0e10cSrcweir sal_Bool SetName( const String& ); // store a name (ASCII, up to 32 chars) 139cdf0e10cSrcweir void GetName( String& rName ) const; 140cdf0e10cSrcweir // fill in the name 141cdf0e10cSrcweir short Compare( const StgEntry& ) const; // compare two entries 142297a844aSArmin Le Grand sal_Bool Load( const void* pBuffer, sal_uInt32 nBufSize ); 143cdf0e10cSrcweir void Store( void* ); GetType() const144cdf0e10cSrcweir StgEntryType GetType() const { return (StgEntryType) cType; } GetStartPage() const145cdf0e10cSrcweir sal_Int32 GetStartPage() const { return nPage1; } SetType(StgEntryType t)146cdf0e10cSrcweir void SetType( StgEntryType t ) { cType = (sal_uInt8) t; } GetFlags() const147cdf0e10cSrcweir sal_uInt8 GetFlags() const { return cFlags; } SetFlags(sal_uInt8 c)148cdf0e10cSrcweir void SetFlags( sal_uInt8 c ) { cFlags = c; } GetSize() const149cdf0e10cSrcweir sal_Int32 GetSize() const { return nSize; } SetSize(sal_Int32 n)150cdf0e10cSrcweir void SetSize( sal_Int32 n ) { nSize = n; } GetClassId() const151cdf0e10cSrcweir const ClsId& GetClassId() const { return aClsId; } 152cdf0e10cSrcweir void SetClassId( const ClsId& ); 153cdf0e10cSrcweir sal_Int32 GetLeaf( StgEntryRef ) const; 154cdf0e10cSrcweir void SetLeaf( StgEntryRef, sal_Int32 ); 155cdf0e10cSrcweir const sal_Int32* GetTime( StgEntryTime ) const; 156cdf0e10cSrcweir void SetTime( StgEntryTime, sal_Int32* ); 157cdf0e10cSrcweir }; 158cdf0e10cSrcweir 159cdf0e10cSrcweir 160cdf0e10cSrcweir #define STG_FREE -1L // page is free 161cdf0e10cSrcweir #define STG_EOF -2L // page is last page in chain 162cdf0e10cSrcweir #define STG_FAT -3L // page is FAT page 163cdf0e10cSrcweir #define STG_MASTER -4L // page is master FAT page 164cdf0e10cSrcweir 165cdf0e10cSrcweir #endif 166