View Javadoc

1   /***
2    * 
3    */
4   package com.fernsroth.squashfs.model.squashfs;
5   
6   import java.io.IOException;
7   
8   import com.fernsroth.easyio.exception.EasyIOException;
9   import com.fernsroth.easyio.util.EasyIOUtils;
10  
11  /***
12   * 
13   * @author Joseph M. Ferner (Near Infinity Corporation)
14   */
15  public final class squashfs_constants {
16      /***
17       * see squashfs_fs.h.
18       */
19      public static final int SQUASHFS_MAJOR = 3;
20  
21      /***
22       * see squashfs_fs.h.
23       */
24      public static final int SQUASHFS_MINOR = 0;
25  
26      /***
27       * see squashfs_fs.h.
28       */
29      public static final int SQUASHFS_MAGIC = 0x73717368;
30  
31      /***
32       * see squashfs_fs.h.
33       */
34      public static final int SQUASHFS_MAGIC_SWAP = 0x68737173;
35  
36      /***
37       * see squashfs_fs.h.
38       */
39      public static final int SQUASHFS_START = 0;
40  
41      /***
42       * the size of {@link squashfs_dir_entry}.
43       */
44      public static final int SQUASHFS_DIR_ENTRY_SIZE;
45  
46      /***
47       * the size of {@link squashfs_dir_header}.
48       */
49      public static final int SQUASHFS_DIR_HEADER_SIZE;
50  
51      /***
52       * the size of {@link squashfs_fragment_entry}.
53       */
54      public static final int SQUASHFS_FRAGMENT_ENTRY_SIZE;
55  
56      /***
57       * the size of {@link squashfs_reg_inode_header}.
58       */
59      public static final int SQUASHFS_REG_INODE_HEADER_SIZE;
60  
61      /***
62       * the size of {@link squashfs_symlink_inode_header}.
63       */
64      public static final int SQUASHFS_SYMLINK_INODE_HEADER_SIZE;
65  
66      /***
67       * the size of {@link squashfs_super_block}.
68       */
69      public static final int SQUASHFS_SUPER_BLOCK_SIZE;
70  
71      /***
72       * the size of {@link squashfs_uid}.
73       */
74      public static final int SQUASHFS_UID_SIZE;
75  
76      /***
77       * 
78       */
79      public static final int SQUASHFS_UIDS = 256;
80  
81      /***
82       * 
83       */
84      public static final int SQUASHFS_GUIDS = 255;
85  
86      /***
87       * 
88       */
89      public static final int SQUASHFS_FRAGMENT_INDEX_SIZE;
90  
91      static {
92          try {
93              SQUASHFS_UID_SIZE = 4;
94              SQUASHFS_FRAGMENT_INDEX_SIZE = 8;
95              SQUASHFS_SUPER_BLOCK_SIZE = EasyIOUtils
96                      .getClassSize(squashfs_super_block.class);
97              SQUASHFS_DIR_ENTRY_SIZE = EasyIOUtils
98                      .getClassSize(squashfs_dir_entry.class);
99              SQUASHFS_DIR_HEADER_SIZE = EasyIOUtils
100                     .getClassSize(squashfs_dir_header.class);
101             SQUASHFS_FRAGMENT_ENTRY_SIZE = EasyIOUtils
102                     .getClassSize(squashfs_fragment_entry.class);
103             SQUASHFS_REG_INODE_HEADER_SIZE = EasyIOUtils
104                     .getClassSize(squashfs_reg_inode_header.class);
105             SQUASHFS_SYMLINK_INODE_HEADER_SIZE = EasyIOUtils
106                     .getClassSize(squashfs_symlink_inode_header.class);
107             SQUASHFS_DIR_INODE_HEADER_SIZE = EasyIOUtils
108                     .getClassSize(squashfs_dir_inode_header.class);
109             CACHED_DIR_INDEX_SIZE = EasyIOUtils
110                     .getClassSize(cached_dir_index.class);
111             SQUASHFS_DIR_INDEX_SIZE = EasyIOUtils
112                     .getClassSize(squashfs_dir_index.class);
113         } catch (IOException e) {
114             throw new ExceptionInInitializerError(e);
115         } catch (EasyIOException e) {
116             throw new ExceptionInInitializerError(e);
117         }
118     }
119 
120     /* size of metadata (inode and directory) blocks */
121     /***
122      * see squashfs_fs.h.
123      */
124     public static final int SQUASHFS_METADATA_SIZE = 8192;
125 
126     /***
127      * see squashfs_fs.h.
128      */
129     public static final int SQUASHFS_METADATA_LOG = 13;
130 
131     /***
132      * see squashfs_fs.h.
133      */
134     public static final int SQUASHFS_NOI = 0;
135 
136     /***
137      * see squashfs_fs.h.
138      */
139     public static final int SQUASHFS_NOD = 1;
140 
141     /***
142      * see squashfs_fs.h.
143      */
144     public static final int SQUASHFS_CHECK = 2;
145 
146     /***
147      * see squashfs_fs.h.
148      */
149     public static final int SQUASHFS_NOF = 3;
150 
151     /***
152      * see squashfs_fs.h.
153      */
154     public static final int SQUASHFS_NO_FRAG = 4;
155 
156     /***
157      * see squashfs_fs.h.
158      */
159     public static final int SQUASHFS_ALWAYS_FRAG = 5;
160 
161     /***
162      * see squashfs_fs.h.
163      */
164     public static final int SQUASHFS_DUPLICATE = 6;
165 
166     /***
167      * see squashfs_fs.h.
168      */
169     public static final int SQUASHFS_COMPRESSED_BIT = (1 << 15);
170 
171     /***
172      * see squashfs_fs.h.
173      */
174     public static final int SQUASHFS_DIR_TYPE = 1;
175 
176     /***
177      * see squashfs_fs.h.
178      */
179     public static final int SQUASHFS_FILE_TYPE = 2;
180 
181     /***
182      * see squashfs_fs.h.
183      */
184     public static final int SQUASHFS_SYMLINK_TYPE = 3;
185 
186     /***
187      * see squashfs_fs.h.
188      */
189     public static final int SQUASHFS_BLKDEV_TYPE = 4;
190 
191     /***
192      * see squashfs_fs.h.
193      */
194     public static final int SQUASHFS_CHRDEV_TYPE = 5;
195 
196     /***
197      * see squashfs_fs.h.
198      */
199     public static final int SQUASHFS_FIFO_TYPE = 6;
200 
201     /***
202      * see squashfs_fs.h.
203      */
204     public static final int SQUASHFS_SOCKET_TYPE = 7;
205 
206     /***
207      * see squashfs_fs.h.
208      */
209     public static final int SQUASHFS_LDIR_TYPE = 8;
210 
211     /***
212      * see squashfs_fs.h.
213      */
214     public static final int SQUASHFS_LREG_TYPE = 9;
215 
216     /***
217      * see squashfs_fs.h.
218      */
219     public static final int DIR_ENT_SIZE = 16;
220 
221     /***
222      * Max length of filename (not 255).
223      */
224     public static final int SQUASHFS_NAME_LEN = 256;
225 
226     /***
227      * see squashfs_fs.h.
228      */
229     public static final long SQUASHFS_INVALID = 0xffffffffffffL;
230 
231     /***
232      * see squashfs_fs.h.
233      */
234     public static final long SQUASHFS_INVALID_FRAG = 0xffffffffL;
235 
236     /***
237      * see squashfs_fs.h.
238      */
239     public static final long SQUASHFS_INVALID_BLK = -1;
240 
241     /***
242      * see squashfs_fs.h.
243      */
244     public static final long SQUASHFS_USED_BLK = -2;
245 
246     /***
247      * see squashfs_fs.h.
248      */
249     public static final long SQUASHFS_FILE_SIZE = 65536;
250 
251     /***
252      * see squashfs_fs.h.
253      */
254     public static final long SQUASHFS_FILE_LOG = 16;
255 
256     /***
257      * see squashfs_fs.h.
258      */
259     public static final long SQUASHFS_FILE_MAX_SIZE = 65536;
260 
261     /***
262      * @param A
263      * @return zz
264      */
265     public static long SQUASHFS_FRAGMENT_INDEXES(long A) {
266         return ((SQUASHFS_FRAGMENT_BYTES(A) + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE);
267     }
268 
269     /***
270      * @param A
271      * @return zz
272      */
273     public static long SQUASHFS_FRAGMENT_BYTES(long A) {
274         return (A * SQUASHFS_FRAGMENT_ENTRY_SIZE);
275     }
276 
277     /***
278      * @param A
279      * @return zz
280      */
281     public static long SQUASHFS_FRAGMENT_INDEX_BYTES(long A) {
282         return (SQUASHFS_FRAGMENT_INDEXES(A) * 8);
283     }
284 
285     /***
286      * @param B
287      * @return zz
288      */
289     public static int SQUASHFS_COMPRESSED_SIZE(int B) {
290         return (((B) & ~SQUASHFS_COMPRESSED_BIT) != 0 ? (B)
291                 & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT);
292     }
293 
294     /***
295      * @param B
296      * @return zz
297      */
298     public static boolean SQUASHFS_COMPRESSED(int B) {
299         return (!(((B) & SQUASHFS_COMPRESSED_BIT) != 0));
300     }
301 
302     /***
303      * @param flags
304      * @return zz
305      */
306     public static boolean SQUASHFS_CHECK_DATA(int flags) {
307         return SQUASHFS_BIT(flags, SQUASHFS_CHECK);
308     }
309 
310     /***
311      * @param flag
312      * @param bit
313      * @return zz
314      */
315     public static boolean SQUASHFS_BIT(int flag, int bit) {
316         return ((flag >> bit) & 1) != 0;
317     }
318 
319     /***
320      * @param a
321      * @return zz.
322      */
323     public static long SQUASHFS_INODE_BLK(long a) {
324         return (((a) >> 16));
325     }
326 
327     /***
328      * @param a
329      * @return zz.
330      */
331     public static long SQUASHFS_INODE_OFFSET(long a) {
332         return (((a) & 0xffff));
333     }
334 
335     /***
336      * 
337      */
338     public static final long SQUASHFS_COMPRESSED_BIT_BLOCK = (1 << 24);
339 
340     /***
341      * 
342      */
343     public static final byte SQUASHFS_MARKER_BYTE = (byte) 0xff;
344 
345     /***
346      * 
347      */
348     public static final long SQUASHFS_MAX_FILE_SIZE_LOG = 64;
349 
350     /***
351      * 
352      */
353     public static final long SQUASHFS_MAX_FILE_SIZE = ((long) 1 << (SQUASHFS_MAX_FILE_SIZE_LOG - 2));
354 
355     /***
356      * 
357      */
358     public static final long SQUASHFS_DIR_INODE_HEADER_SIZE;
359 
360     /***
361      * 
362      */
363     public static final int I_COUNT_SIZE = 128;
364 
365     /***
366      * 
367      */
368     public static final int CACHED_DIR_INDEX_SIZE;
369 
370     /***
371      * 
372      */
373     public static final long SQUASHFS_DIR_INDEX_SIZE;
374 
375     /***
376      * @param B
377      * @return the size.
378      */
379     public static long SQUASHFS_COMPRESSED_SIZE_BLOCK(long B) {
380         return (((B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK) != 0 ? (B)
381                 & ~SQUASHFS_COMPRESSED_BIT_BLOCK
382                 : SQUASHFS_COMPRESSED_BIT_BLOCK);
383     }
384 
385     /***
386      * @param B
387      * @return true, if compressed.
388      */
389     public static boolean SQUASHFS_COMPRESSED_BLOCK(long B) {
390         return (!((B & SQUASHFS_COMPRESSED_BIT_BLOCK) != 0));
391     }
392 
393     /***
394      * hide it. 
395      */
396     private squashfs_constants() {
397         // empty.
398     }
399 
400     /***
401      * @param block
402      * @return the slog.
403      */
404     public static int slog(long block) {
405         int i;
406 
407         for (i = 12; i <= 16; i++) {
408             if (block == (1 << i)) {
409                 return i;
410             }
411         }
412         return 0;
413     }
414 
415     /***
416      * @param noI
417      * @param noD
418      * @param check_data
419      * @param noF
420      * @param no_fragments
421      * @param always_use_fragments
422      * @param duplicate_checking
423      * @return flags.
424      */
425     public static int SQUASHFS_MKFLAGS(boolean noI, boolean noD,
426             boolean check_data, boolean noF, boolean no_fragments,
427             boolean always_use_fragments, boolean duplicate_checking) {
428         return ((noI ? 1 : 0) | ((noD ? 1 : 0) << 1)
429                 | ((check_data ? 1 : 0) << 2) | ((noF ? 1 : 0) << 3)
430                 | ((no_fragments ? 1 : 0) << 4)
431                 | ((always_use_fragments ? 1 : 0) << 5) | ((duplicate_checking ? 1
432                 : 0) << 6));
433     }
434 
435     /***
436      * @param a
437      * @return mode.
438      */
439     public static int SQUASHFS_MODE(int a) {
440         return ((a) & 0xfff);
441     }
442 }