xref: /aoo41x/main/sot/source/sdstor/stgelem.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // This file reflects the structure of MS file elements.
29 // It is very sensitive to alignment!
30 
31 #ifndef _STGELEM_HXX
32 #define _STGELEM_HXX
33 
34 #ifndef _TOOLS_SOLAR_H
35 #include <tools/solar.h>
36 #endif
37 
38 #include <sot/stg.hxx>
39 
40 class StgIo;
41 class SvStream;
42 class String;
43 
44 SvStream& operator>>( SvStream&, ClsId& );
45 SvStream& operator<<( SvStream&, const ClsId& );
46 
47 class StgHeader
48 {
49 	sal_uInt8 	cSignature[ 8 ];			// 00 signature (see below)
50 	ClsId	aClsId;						// 08 Class ID
51 	sal_Int32	nVersion;					// 18 version number
52 	sal_uInt16	nByteOrder;					// 1C Unicode byte order indicator
53 	sal_Int16	nPageSize;					// 1E 1 << nPageSize = block size
54 	sal_Int16	nDataPageSize;				// 20 1 << this size == data block size
55 	sal_uInt8	bDirty;						// 22 internal dirty flag
56 	sal_uInt8	cReserved[ 9 ];				// 23
57 	sal_Int32	nFATSize; 					// 2C total number of FAT pages
58 	sal_Int32	nTOCstrm;					// 30 starting page for the TOC stream
59 	sal_Int32	nReserved;					// 34
60 	sal_Int32	nThreshold;					// 38 minimum file size for big data
61 	sal_Int32	nDataFAT;					// 3C page # of 1st data FAT block
62 	sal_Int32	nDataFATSize;				// 40 # of data fat blocks
63 	sal_Int32	nMasterChain;				// 44 chain to the next master block
64 	sal_Int32	nMaster;					// 48 # of additional master blocks
65 	sal_Int32	nMasterFAT[ 109 ];			// 4C first 109 master FAT pages
66 public:
67 	StgHeader();
68 	void  Init();						// initialize the header
69 	sal_Bool  Load( StgIo& );
70     sal_Bool  Load( SvStream& );
71 	sal_Bool  Store( StgIo& );
72 	sal_Bool  Check();						// check the signature and version
73 	short GetByteOrder() const			{ return nByteOrder;	}
74 	sal_Int32 GetTOCStart() const			{ return nTOCstrm;		}
75 	void  SetTOCStart( sal_Int32 n );
76 	sal_Int32 GetDataFATStart() const		{ return nDataFAT;		}
77 	void  SetDataFATStart( sal_Int32 n );
78 	sal_Int32 GetDataFATSize() const		{ return nDataFATSize; 	}
79 	void  SetDataFATSize( sal_Int32 n );
80 	sal_Int32 GetThreshold() const			{ return nThreshold;	}
81 	short GetPageSize() const			{ return nPageSize;		}
82 	short GetDataPageSize() const		{ return nDataPageSize;	}
83 	sal_Int32 GetFATSize() const			{ return nFATSize;		}
84 	void  SetFATSize( sal_Int32 n );
85 	sal_Int32 GetFATChain() const			{ return nMasterChain;	}
86 	void  SetFATChain( sal_Int32 n );
87 	sal_Int32 GetMasters() const			{ return nMaster;		}
88 	void  SetMasters( sal_Int32 n );
89 	short GetFAT1Size() const			{ return 109;			}
90 	const ClsId& GetClassId() const		{ return aClsId;		}
91 	void  SetClassId( const ClsId& );
92 	sal_Int32 GetFATPage( short ) const;
93 	void  SetFATPage( short, sal_Int32 );
94 };
95 
96 enum StgEntryType {						// dir entry types:
97     STG_EMPTY	  = 0,
98     STG_STORAGE   = 1,
99     STG_STREAM    = 2,
100     STG_LOCKBYTES = 3,
101     STG_PROPERTY  = 4,
102     STG_ROOT	  = 5
103 };
104 
105 enum StgEntryRef {						// reference blocks:
106 	STG_LEFT	  = 0,					// left
107 	STG_RIGHT	  = 1,					// right
108 	STG_CHILD	  = 2,					// child
109 	STG_DATA	  = 3					// data start
110 };
111 
112 enum StgEntryTime {						// time codes:
113 	STG_MODIFIED  = 0,					// last modification
114 	STG_ACCESSED  = 1					// last access
115 };
116 
117 class StgStream;
118 
119 #define STGENTRY_SIZE 128
120 
121 class StgEntry {						// directory enty
122 	sal_uInt16	nName[ 32 ];				// 00 name as WCHAR
123 	sal_Int16	nNameLen;					// 40 size of name in bytes including 00H
124 	sal_uInt8	cType;						// 42 entry type
125 	sal_uInt8	cFlags;						// 43 0 or 1 (tree balance?)
126 	sal_Int32	nLeft;						// 44 left node entry
127 	sal_Int32	nRight;						// 48 right node entry
128 	sal_Int32	nChild;						// 4C 1st child entry if storage
129 	ClsId	aClsId;						// 50 class ID (optional)
130 	sal_Int32	nFlags;						// 60 state flags(?)
131 	sal_Int32	nMtime[ 2 ];				// 64 modification time
132 	sal_Int32	nAtime[ 2 ];				// 6C creation and access time
133 	sal_Int32	nPage1;						// 74 starting block (either direct or translated)
134 	sal_Int32	nSize;						// 78 file size
135 	sal_Int32	nUnknown;					// 7C unknown
136 	String	aName;		                // Name as Compare String (ascii, upper)
137 public:
138 	sal_Bool	Init();						// initialize the data
139 	sal_Bool	SetName( const String& );	// store a name (ASCII, up to 32 chars)
140 	void	GetName( String& rName ) const;
141 	                                    // fill in the name
142 	short	Compare( const StgEntry& ) const;	// compare two entries
143 	sal_Bool	Load( const void* );
144 	void    Store( void* );
145 	StgEntryType GetType() const		{ return (StgEntryType) cType;	}
146 	sal_Int32   GetStartPage() const        { return nPage1; }
147 	void	SetType( StgEntryType t )	{ cType = (sal_uInt8) t;				}
148 	sal_uInt8	GetFlags() const			{ return cFlags;				}
149 	void	SetFlags( sal_uInt8 c )			{ cFlags = c;					}
150 	sal_Int32	GetSize() const				{ return nSize;					}
151 	void	SetSize( sal_Int32 n )			{ nSize = n;					}
152 	const   ClsId& GetClassId() const  	{ return aClsId;				}
153 	void	SetClassId( const ClsId& );
154 	sal_Int32	GetLeaf( StgEntryRef ) const;
155 	void	SetLeaf( StgEntryRef, sal_Int32 );
156 	const	sal_Int32* GetTime( StgEntryTime ) const;
157 	void	SetTime( StgEntryTime, sal_Int32* );
158 };
159 
160 
161 #define STG_FREE	-1L					// page is free
162 #define	STG_EOF		-2L					// page is last page in chain
163 #define	STG_FAT		-3L					// page is FAT page
164 #define	STG_MASTER	-4L					// page is master FAT page
165 
166 #endif
167