Debian Codegraph @

src/uk/me/parabola/imgfmt/sys/HeaderDirent.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2007 Steve Ratcliffe
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 *
14 * Author: Steve Ratcliffe
15 * Create date: 27-Oct-2007
16 */
17 package uk.me.parabola.imgfmt.sys;
18
19 /**
20 * This is a special class for the header. It makes it easier to bootstrap
21 * the directory by having a special implementation that starts up by knowing
22 * that the blocks in the header start from 0.
23 *
24 * @author Steve Ratcliffe
25 */
26 class HeaderDirent extends Dirent {
27 HeaderDirent(String name, BlockManager blockManager) {
28 super(name, blockManager);
29 }
30
31 /**
32 * Converts from a logical block to a physical block. This is a special
33 * version that returns the logical block number when the {@link Dirent} is not
34 * set up. This allows us to bootstrap the reading of the header blocks.
35 * The header blocks always logical and physical blocks the same.
36 *
37 * @param lblock The logical block in the file.
38 * @return The corresponding physical block in the filesystem.
39 */
40 public int getPhysicalBlock(int lblock) {
41 if (isInitialized()) {
42 log.debug("gpb (ok)");
43 return super.getPhysicalBlock(lblock);
44 } else {
45 log.debug("gpb (not setup)");
46 return lblock;
47 }
48 }
49
50 /**
51 * Get the file size. The file appears large until the first blocks are
52 * read in and then it will take on its actual size.
53 *
54 * @return The size of the file in bytes.
55 */
56 public int getSize() {
57 if (isInitialized())
58 return super.getSize();
59 else
60 return getBlockManager().getBlockSize() * 32;
61 }
62
63 /**
64 * Always returns true as this is only used for the special header
65 * directory entry.
66 *
67 * @return Always returns true.
68 */
69 public boolean isSpecial() {
70 return true;
71 }
72 }