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