"Initial commit to Gerrit"
[profile/ivi/libgsf.git] / doc / developer / blocksize.html
1 <html>
2 <head>
3 <title>MSOLE block size variations</title>
4 <body>
5
6 <h1>Experiments with various block sizes in MS OLE</h1>
7
8 <h2>Small files</h2>
9
10 <h3>setup</h3>
11 <p>I decided to test the following parameters:
12 <ul>
13 <li>Block size: powers of 2 from 128 B up to 8 KB, 7 possible values.
14 (The small block size was always 64 B.)
15 <li>Header size (3 possibilities):
16   <ol>
17   <li>512 B for all block sizes
18   <li>padded/truncated to block size; (padded with 0's)
19   <li>padded/truncated to block size; (padded with 0xff's)
20   </ol>
21 <li>cSectDir: either set or 0
22 <li>major version: either 3 or 4 (minor is always 0x3e)
23 <li>doc or xls (I used two small files, 19KB doc file and 14KB xls file;
24 so XBAT is never used for these tiny files).
25 <li>version of windows (3 versions tested):
26   <ol>
27   <li>Win 98, Office 2000
28   <li>Win 2000 Pro, Office 2000
29   <li>Win XP Pro, Word viewer and Excel viewer, available for free from MS.
30   </ol>
31 </ul>
32
33 <h3>results</h3>
34 <p>Using all combinations, I used a slightly modified test-cp-msole program
35 to create 168 files (84 doc files and 84 xls files).
36 I tried to run all of them on each of the three platforms.
37 Here are the results:
38 <p>All these files either opened OK, or were reported as incorrect files.
39 I haven't experienced crashes, with only one exception (see the next paragraph).
40 <p>There were no differences between Excel and Word, they behaved both the
41 same, with one exception:  if a file with 8KB blocks was succesfully opened by
42 Excel, then Word crashed on that file.  (If the file was reported as incorrect,
43 Word also said it's incorrect, without any crash.)  The current libgsf code
44 allows only block up to 4KB, so it's wise to keep this limitation.
45 <p>When the header was padded to block size, it had never any influence whether
46 it was padded by 0's or 0xff's.
47
48 <h4>Win 2000 and Win XP results</h4>
49 <p>Both of these platforms behaved exactly the same:
50 <p>The major version set (3 or 4) had no influence.
51 <p>Header size had to be = block size. (Constant 512 B header didn't work
52 for any block size != 512.)
53 <p>With _cSectDir set, all block sizes worked.  When _cSectDir was not set (0),
54 only block sizes <= 512 worked.
55 <p>(I hope the above text says unambiguously which files worked and which didn't.)
56
57 <h4>Win 98 results</h4>
58 <p>The major version had to be 3. (When set to 4, no file worked, not even with
59 block size 512B.)
60 <p>Header size had to be constant 512. (When header size = block size, no block
61 size != 512 worked.)
62 <p>It had no influence whether _cSectDir was set or not.
63
64 <h2>Bigger files, tested on Win 2000 only</h2>
65
66 <h3>Block sizes bigger then 512</h3>
67 <p>I wanted to verify that the header really has size 512.
68 In other words, that the header still has only 109 metabat pointers, and then
69 an XBAT block is used.
70 <p>I needed a file bigger then about 28 MB.  I created a 32MB file by Excel.
71 <p>I copied it with the modified test-cp-msole in two configurations:
72 <ol>
73 <li>block size 1024 B, _cSectDir set, major ver. 4, header padded by 0xff
74 <li>block size 1024 B, _cSectDir set, major ver. 3, header padded by 0
75 </ol>
76 (I used a hex dump to verify that the file really has one XBAT block.)
77 <p>Both of these files worked.  I tried to save the file under another name, and re-open
78 the file: it worked.  The saved file had 512B blocks again; the major/minor
79 version is set to 3/3e, which is the same as libgsf's default values.
80
81 <h3>Block sizes smaller then 512</h3>
82
83 <h4>part one</h4>
84 <p>I prepared two test files: one had size about 767 KB, the other had 2 MB.
85 (Using 256B blocks, the former size is big enough to use more than 256 B of the
86 header, the later is big enough to have more then 109 metabat pointers.)
87 <p>When I copied these files with 256 B blocks, they didn't work.
88 <p>This proved that the header is 512 B long, even if that means that block 0
89 may not be used for data.  (Well, I used it for data in the previous experiment,
90 but it cannot be used generally.)
91 <p>Thus I modified the code so that the header is not truncated for block sizes < 512.
92 At the beginning of the BAT table, I marked the block 0 (or blocks 0,1,2 for block
93 size 128) as belonging to XBAT.
94 <p>With that modified code, I again copied both of the test files using block size 256,
95 and it worked.
96
97 <h4>part two</h4>
98 Then I experimented with smaller small block sizes, using the modified code, as explained
99 above.  I used big block size 256, 128, 64,
100 in combination with small block size 32 and 16. I copied the old small 14KB xls file. (6 combinations)
101 <p>The ones with big block size 256 and 128 worked.
102 <p>With big block size 64, excel crashed.  Even explorer crashed when I selected that file
103 (I haven't tried to open it, I just selected it: it probably tries to determine the author
104 and title of the file.) Thus I conclude that the current test that block size has to be >= dirent size
105 (128) is good to keep.
106
107 <h2>Conclusions and suggestions</h2>
108 <p>I suggest to set _cSectDir always: it helps in certain situations and it never hurts.
109 <p>There have to be a new instance variable, determining the offset of block 0.
110 I prefer to call it block0_offset, not header_size, as the header data always take up
111 exactly 512 B.  This will be set at the begining.  This determines whether the file will
112 be compatible with Win 98 or Win 2000/XP.  (Only files with 512B blocks can be compatible
113 with both.)  The default should be 2000/XP comaptibility as these are more common now.
114 <p>(Previous versions of libgsf had block0_offset =
115 MAX (block_size, 512), which is a mix of the two.)
116 <p>With block0_offset > 512, the header should be padded with 0, as it's cleaner this
117 way.
118 <p>This is the most controversial proposal: we could set the major version to 4 when
119 block0_offset is not 512.  That doesn't break compatibility with MS and enables us to
120 distinguish the two types for the future.
121 <hr>
122 <p>These experiments were conducted and the document written by
123 <a href="mailto:kasal@ucw.cz">Stepan Kasal</a> around August 23, 2004.
124 </html>