|
From: <cr...@us...> - 2008-06-06 11:57:18
|
Revision: 4202
http://jnode.svn.sourceforge.net/jnode/?rev=4202&view=rev
Author: crawley
Date: 2008-06-06 04:57:12 -0700 (Fri, 06 Jun 2008)
Log Message:
-----------
Checkstyle fixes
Modified Paths:
--------------
trunk/fs/src/fs/org/jnode/fs/command/MkdirCommand.java
trunk/fs/src/fs/org/jnode/fs/command/MountCommand.java
trunk/fs/src/fs/org/jnode/fs/command/TouchCommand.java
trunk/fs/src/fs/org/jnode/fs/ext2/BlockBitmap.java
trunk/fs/src/fs/org/jnode/fs/ext2/BlockReservation.java
trunk/fs/src/fs/org/jnode/fs/ext2/BlockSize.java
trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Constants.java
trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Directory.java
trunk/fs/src/fs/org/jnode/fs/ext2/Ext2DirectoryRecord.java
trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Entry.java
trunk/fs/src/fs/org/jnode/fs/ext2/Ext2File.java
trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystem.java
trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystemFormatter.java
trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystemType.java
trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Print.java
trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Utils.java
trunk/fs/src/fs/org/jnode/fs/ext2/FSBitmap.java
trunk/fs/src/fs/org/jnode/fs/ext2/GroupDescriptor.java
trunk/fs/src/fs/org/jnode/fs/ext2/INode.java
trunk/fs/src/fs/org/jnode/fs/ext2/INodeBitmap.java
trunk/fs/src/fs/org/jnode/fs/ext2/INodeDescriptor.java
trunk/fs/src/fs/org/jnode/fs/ext2/INodeReservation.java
trunk/fs/src/fs/org/jnode/fs/ext2/INodeTable.java
trunk/fs/src/fs/org/jnode/fs/ext2/Superblock.java
trunk/fs/src/fs/org/jnode/fs/ext2/cache/Block.java
trunk/fs/src/fs/org/jnode/fs/ext2/cache/BlockCache.java
trunk/fs/src/fs/org/jnode/fs/ext2/cache/CacheEvent.java
trunk/fs/src/fs/org/jnode/fs/ext2/cache/CacheListener.java
trunk/fs/src/fs/org/jnode/fs/ext2/cache/INodeCache.java
trunk/fs/src/fs/org/jnode/fs/ext2/command/FormatExt2Command.java
trunk/fs/src/fs/org/jnode/fs/ext2/exception/UnallocatedBlockException.java
trunk/fs/src/fs/org/jnode/fs/ext2/test/command/CopyTest.java
trunk/fs/src/fs/org/jnode/fs/ext2/test/command/FillTest.java
trunk/fs/src/fs/org/jnode/fs/ext2/test/command/WriteTest.java
Modified: trunk/fs/src/fs/org/jnode/fs/command/MkdirCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/command/MkdirCommand.java 2008-06-05 14:26:18 UTC (rev 4201)
+++ trunk/fs/src/fs/org/jnode/fs/command/MkdirCommand.java 2008-06-06 11:57:12 UTC (rev 4202)
@@ -57,6 +57,6 @@
if (!dir.mkdir()) {
err.println("Can't create directory.");
exit(1);
- }
+ }
}
}
Modified: trunk/fs/src/fs/org/jnode/fs/command/MountCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/command/MountCommand.java 2008-06-05 14:26:18 UTC (rev 4201)
+++ trunk/fs/src/fs/org/jnode/fs/command/MountCommand.java 2008-06-06 11:57:12 UTC (rev 4202)
@@ -75,8 +75,7 @@
String type = fs.getType().getName();
out.println(device.getId() + " on " + mountPoint + " type " + type + " (" + mode + ')');
}
- }
- else {
+ } else {
// Get the parameters
final Device dev = ARG_DEV.getValue();
final File mountPoint = ARG_DIR.getValue();
Modified: trunk/fs/src/fs/org/jnode/fs/command/TouchCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/command/TouchCommand.java 2008-06-05 14:26:18 UTC (rev 4201)
+++ trunk/fs/src/fs/org/jnode/fs/command/TouchCommand.java 2008-06-06 11:57:12 UTC (rev 4202)
@@ -52,7 +52,7 @@
}
public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
- throws Exception {
+ throws Exception {
File file = ARG_FILE.getValue();
if (!file.exists()) {
File parentFile = file.getParentFile();
Modified: trunk/fs/src/fs/org/jnode/fs/ext2/BlockBitmap.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/BlockBitmap.java 2008-06-05 14:26:18 UTC (rev 4201)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/BlockBitmap.java 2008-06-06 11:57:12 UTC (rev 4202)
@@ -25,84 +25,82 @@
* @author Andras Nagy
*/
public class BlockBitmap extends FSBitmap {
- /**
- * Test whether the block is free, and if yes:
- * - mark it as used
- * - prealloc the next free blocks, at most 7
- *
- * SYNCHRONIZATION:
- * BlockBitmap.testAndSetBlock() is not synchronized, so
- * Ext2FileSystem.testAndSetBlock() is synchronized to the bitmap block
- * it operates on.
- */
- protected static BlockReservation testAndSetBlock(byte[] data, int index) {
- if( isFree(data, index) ) {
- setBit(data, index);
- //do preallocation
- int j=0;
- while( (j<Ext2Constants.EXT2_PREALLOC_BLOCK) && isFree(data, index+1+j) ) {
- setBit(data, index+1+j);
- j++;
- }
- return new BlockReservation(true, index, j);
+ /**
+ * Test whether the block is free, and if yes: - mark it as used - prealloc
+ * the next free blocks, at most 7
+ *
+ * SYNCHRONIZATION: BlockBitmap.testAndSetBlock() is not synchronized, so
+ * Ext2FileSystem.testAndSetBlock() is synchronized to the bitmap block it
+ * operates on.
+ */
+ protected static BlockReservation testAndSetBlock(byte[] data, int index) {
+ if (isFree(data, index)) {
+ setBit(data, index);
+ // do preallocation
+ int j = 0;
+ while ((j < Ext2Constants.EXT2_PREALLOC_BLOCK) && isFree(data, index + 1 + j)) {
+ setBit(data, index + 1 + j);
+ j++;
+ }
+ return new BlockReservation(true, index, j);
- } else
- return new BlockReservation(false, -1, -1);
- }
+ } else
+ return new BlockReservation(false, -1, -1);
+ }
- /**
- * Find free blocks in the bitmap. First check
- * for a whole byte of free blocks (0x00) in the bitmap, then check for
- * any free bit. If a block is found, mark it as allocated.
- * If the following blocks are free, then they are preallocated (at most 7
- * blocks), but preallocation can't be performed over the group boundary
- * (because the bitmap data is only available for a single block group).
- *
- * SYNCHRONIZATION:
- * BlockBitmap.findFreeBlocks() is not synchronized, so
- * Ext2FileSystem.findFreeBlocks() is synchronized to the bitmap block
- * it operates on.
- */
- protected static BlockReservation findFreeBlocks(byte[] data, int metadataLength ) {
- //BlockReservation result;
- int nonfullBitmap=-1; //points to a nonfull byte in the bitmap
-
- //skip the metadata (superblock copy?, groupgrescriptor copies?, inode table)
- int first = (int)Ext2Utils.ceilDiv(metadataLength, 8);
-
- for(int i=first; i<data.length; i++) {
- if(data[i]==0x00) {
- //allocate the block and do preallocation
- //preallocate a fixed number of blocks (7)
- data[i]=(byte)0xFF;
- return new BlockReservation(true, ((long)i)*8, 7);
- }
-
- if((nonfullBitmap==-1) && (data[i]!=0xFF))
- nonfullBitmap=i;
- }
-
- //a full byte of 0x00 was not found in the bitmap:
- //go for any free bit
+ /**
+ * Find free blocks in the bitmap. First check for a whole byte of free
+ * blocks (0x00) in the bitmap, then check for any free bit. If a block is
+ * found, mark it as allocated. If the following blocks are free, then they
+ * are preallocated (at most 7 blocks), but preallocation can't be performed
+ * over the group boundary (because the bitmap data is only available for a
+ * single block group).
+ *
+ * SYNCHRONIZATION: BlockBitmap.findFreeBlocks() is not synchronized, so
+ * Ext2FileSystem.findFreeBlocks() is synchronized to the bitmap block it
+ * operates on.
+ */
+ protected static BlockReservation findFreeBlocks(byte[] data, int metadataLength) {
+ // BlockReservation result;
+ int nonfullBitmap = -1; // points to a nonfull byte in the bitmap
- // no free bit found:
- if(nonfullBitmap==-1)
- return new BlockReservation(false, -1, -1);
-
- // a free bit has been found:
- for(int i=0; i<8; i++)
- if(isFree(data[nonfullBitmap], i)) {
- setBit(data, nonfullBitmap, i);
- int block = nonfullBitmap*8 + i;
- //do preallocation:
- int j=0;
- while( (j<Ext2Constants.EXT2_PREALLOC_BLOCK) && isFree(data, block+1+j) ) {
- setBit(data, block+1+j);
- j++;
- }
- return new BlockReservation(true, block, j);
- }
-
- return new BlockReservation(false, -1, -1);
- }
+ // skip the metadata (superblock copy?, groupgrescriptor copies?, inode
+ // table)
+ int first = (int) Ext2Utils.ceilDiv(metadataLength, 8);
+
+ for (int i = first; i < data.length; i++) {
+ if (data[i] == 0x00) {
+ // allocate the block and do preallocation
+ // preallocate a fixed number of blocks (7)
+ data[i] = (byte) 0xFF;
+ return new BlockReservation(true, ((long) i) * 8, 7);
+ }
+
+ if ((nonfullBitmap == -1) && (data[i] != 0xFF))
+ nonfullBitmap = i;
+ }
+
+ // a full byte of 0x00 was not found in the bitmap:
+ // go for any free bit
+
+ // no free bit found:
+ if (nonfullBitmap == -1)
+ return new BlockReservation(false, -1, -1);
+
+ // a free bit has been found:
+ for (int i = 0; i < 8; i++)
+ if (isFree(data[nonfullBitmap], i)) {
+ setBit(data, nonfullBitmap, i);
+ int block = nonfullBitmap * 8 + i;
+ //do preallocation:
+ int j = 0;
+ while ((j < Ext2Constants.EXT2_PREALLOC_BLOCK) && isFree(data, block + 1 + j)) {
+ setBit(data, block + 1 + j);
+ j++;
+ }
+ return new BlockReservation(true, block, j);
+ }
+
+ return new BlockReservation(false, -1, -1);
+ }
}
Modified: trunk/fs/src/fs/org/jnode/fs/ext2/BlockReservation.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/BlockReservation.java 2008-06-05 14:26:18 UTC (rev 4201)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/BlockReservation.java 2008-06-06 11:57:12 UTC (rev 4202)
@@ -22,76 +22,81 @@
package org.jnode.fs.ext2;
/**
- * Class used to return information to the INode when the FSBitmap
- * makes a reservation.
+ * Class used to return information to the INode when the FSBitmap makes a
+ * reservation.
*
* @author Andras Nagy
*/
public class BlockReservation {
- private long block;
- private int preallocCount;
- private boolean successful;
- private long freeBlocksCount;
-
- public BlockReservation(boolean successful, long block, int preallocCount) {
- this.successful = successful;
- this.block = block;
- this.preallocCount = preallocCount;
- }
+ private long block;
+ private int preallocCount;
+ private boolean successful;
+ private long freeBlocksCount;
- public BlockReservation(boolean successful, long block, int preallocCount, long freeBlocksCount) {
- this.successful = successful;
- this.block = block;
- this.preallocCount = preallocCount;
- this.freeBlocksCount = freeBlocksCount;
- }
+ public BlockReservation(boolean successful, long block, int preallocCount) {
+ this.successful = successful;
+ this.block = block;
+ this.preallocCount = preallocCount;
+ }
- /**
- * Returns the block index (from the beginning of the partition).
- * @return long
- */
- public long getBlock() {
- return block;
- }
+ public BlockReservation(boolean successful, long block, int preallocCount, long freeBlocksCount) {
+ this.successful = successful;
+ this.block = block;
+ this.preallocCount = preallocCount;
+ this.freeBlocksCount = freeBlocksCount;
+ }
- /**
- * Returns the preallocCount.
- * @return int
- */
- public int getPreallocCount() {
- return preallocCount;
- }
+ /**
+ * Returns the block index (from the beginning of the partition).
+ *
+ * @return long
+ */
+ public long getBlock() {
+ return block;
+ }
- /**
- * Returns the successful.
- * @return boolean
- */
- public boolean isSuccessful() {
- return successful;
- }
+ /**
+ * Returns the preallocCount.
+ *
+ * @return int
+ */
+ public int getPreallocCount() {
+ return preallocCount;
+ }
- /**
- * Sets the block.
- * @param block The block to set
- */
- public void setBlock(long block) {
- this.block = block;
- }
+ /**
+ * Returns the successful.
+ *
+ * @return boolean
+ */
+ public boolean isSuccessful() {
+ return successful;
+ }
- /**
- * Returns how many free blocks are in the block group
- * @return
- */
- public long getFreeBlocksCount() {
- return freeBlocksCount;
- }
+ /**
+ * Sets the block.
+ *
+ * @param block The block to set
+ */
+ public void setBlock(long block) {
+ this.block = block;
+ }
- /**
- * Sets how many free blocks are in the block group
- * @param l number of free blocks in the block group
- */
- public void setFreeBlocksCount(long l) {
- freeBlocksCount = l;
- }
+ /**
+ * Returns how many free blocks are in the block group
+ *
+ * @return
+ */
+ public long getFreeBlocksCount() {
+ return freeBlocksCount;
+ }
+ /**
+ * Sets how many free blocks are in the block group
+ * @param l number of free blocks in the block group
+ */
+ public void setFreeBlocksCount(long l) {
+ freeBlocksCount = l;
+ }
+
}
Modified: trunk/fs/src/fs/org/jnode/fs/ext2/BlockSize.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/BlockSize.java 2008-06-05 14:26:18 UTC (rev 4201)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/BlockSize.java 2008-06-06 11:57:12 UTC (rev 4202)
@@ -2,20 +2,17 @@
import org.jnode.util.BinaryScaleFactor;
-
public enum BlockSize {
- _1Kb(1),
- _2Kb(2),
- _4Kb(4);
+ _1Kb(1), _2Kb(2), _4Kb(4);
private final int size;
- private BlockSize(int blockSizeKb)
- {
- this.size = (int) (blockSizeKb * BinaryScaleFactor.K.getMultiplier()); //Converted into KB
+ private BlockSize(int blockSizeKb) {
+ /* The size is converted to kilobytes */
+ this.size = (int) (blockSizeKb * BinaryScaleFactor.K.getMultiplier());
}
- final public int getSize() {
- return size;
- }
+ public final int getSize() {
+ return size;
+ }
}
Modified: trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Constants.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Constants.java 2008-06-05 14:26:18 UTC (rev 4201)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Constants.java 2008-06-06 11:57:12 UTC (rev 4202)
@@ -25,92 +25,92 @@
* @author Andras Nagy
*/
public class Ext2Constants {
- //file types that are stored in the directory records
- public static final int EXT2_FT_UNKNOWN = 0;
- public static final int EXT2_FT_REG_FILE= 1;
- public static final int EXT2_FT_DIR = 2;
- public static final int EXT2_FT_CHRDEV = 3;
- public static final int EXT2_FT_BLKDEV = 4;
- public static final int EXT2_FT_FIFO = 5;
- public static final int EXT2_FT_SOCK = 6;
- public static final int EXT2_FT_SYMLINK = 7;
- public static final int EXT2_FT_MAX = 8;
-
- //inode constants
- public static final int EXT2_BAD_INO = 0x01; //bad blocks inode
- public static final int EXT2_ROOT_INO = 0x02; //root directory inode
- public static final int EXT2_ACL_IDX_INO = 0x03; //ACL index node
- public static final int EXT2_ACL_DATA_INO = 0x04; //ACL data inode
- public static final int EXT2_BOOT_LOADER_INO= 0x05; //boot loader inode
- public static final int EXT2_UNDEL_DIR_INO = 0x06; //undelete directory inode
-
- //i_mode masks and values
- public static final int EXT2_S_IFMT = 0xF000; //format mask
- public static final int EXT2_S_IFSOCK = 0xC000; //socket
- public static final int EXT2_S_IFLNK = 0xA000; //symbolic link
- public static final int EXT2_S_IFREG = 0x8000; //regular file
- public static final int EXT2_S_IFBLK = 0x6000; //block device
- public static final int EXT2_S_IFDIR = 0x4000; //directory
- public static final int EXT2_S_IFCHR = 0x2000; //character device
- public static final int EXT2_S_IFIFO = 0x1000; //fifo
- //access rights
- public static final int EXT2_S_ISUID = 0x0800; //SUID
- public static final int EXT2_S_ISGID = 0x0400; //SGID
- public static final int EXT2_S_ISVTX = 0x0200; //sticky bit
- public static final int EXT2_S_IRWXU = 0x01C0; //user access right mask
- public static final int EXT2_S_IRUSR = 0x0100; //read
- public static final int EXT2_S_IWUSR = 0x0080; //write
- public static final int EXT2_S_IXUSR = 0x0040; //execute
- public static final int EXT2_S_IRWXG = 0x0038; //group access right mask
- public static final int EXT2_S_IRGRP = 0x0020; //read
- public static final int EXT2_S_IWGRP = 0x0010; //write
- public static final int EXT2_S_IXGRP = 0x0008; //execute
- public static final int EXT2_S_IRWXO = 0x0007; //others access right mask
- public static final int EXT2_S_IROTH = 0x0004; //read
- public static final int EXT2_S_IWOTH = 0x0002; //write
- public static final int EXT2_S_IXOTH = 0x0001; //execute
+ // file types that are stored in the directory records
+ public static final int EXT2_FT_UNKNOWN = 0;
+ public static final int EXT2_FT_REG_FILE = 1;
+ public static final int EXT2_FT_DIR = 2;
+ public static final int EXT2_FT_CHRDEV = 3;
+ public static final int EXT2_FT_BLKDEV = 4;
+ public static final int EXT2_FT_FIFO = 5;
+ public static final int EXT2_FT_SOCK = 6;
+ public static final int EXT2_FT_SYMLINK = 7;
+ public static final int EXT2_FT_MAX = 8;
- //revision level values (stored in the superblock)
- public static final int EXT2_GOOD_OLD_REV = 0;
- public static final int EXT2_DYNAMIC_REV = 1;
-
- public static final int EXT2_PREALLOC_BLOCK = 7;
-
- //behaviour control flags in the inode
- public static final long EXT2_INDEX_FL = 0x00010000; //hash indexed directory
+ // inode constants
+ public static final int EXT2_BAD_INO = 0x01; // bad blocks inode
+ public static final int EXT2_ROOT_INO = 0x02; // root directory inode
+ public static final int EXT2_ACL_IDX_INO = 0x03; // ACL index node
+ public static final int EXT2_ACL_DATA_INO = 0x04; // ACL data inode
+ public static final int EXT2_BOOT_LOADER_INO = 0x05; // boot loader inode
+ public static final int EXT2_UNDEL_DIR_INO = 0x06; // undelete directory inode
- //Filesystem state constants
- public static final int EXT2_VALID_FS = 0x0001; // cleanly unmounted
- public static final int EXT2_ERROR_FS = 0x0002;
-
- //what to do when errors are detected
- public static final int EXT2_ERRORS_CONTINUE= 0x0001;
- public static final int EXT2_ERRORS_RO = 0x0002;
- public static final int EXT2_ERRORS_PANIC = 0x0003;
- public static final int EXT2_ERRORS_DEFAULT = EXT2_ERRORS_CONTINUE;
-
-
- //S_FEATURE_RO_COMPAT constants
- public static final long EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER = 0x0001;
- public static final long EXT2_FEATURE_RO_COMPAT_LARGE_FILE = 0x0002;
- public static final long EXT2_FEATURE_RO_COMPAT_BTREE_DIR = 0x0004;
+ // i_mode masks and values
+ public static final int EXT2_S_IFMT = 0xF000; // format mask
+ public static final int EXT2_S_IFSOCK = 0xC000; // socket
+ public static final int EXT2_S_IFLNK = 0xA000; // symbolic link
+ public static final int EXT2_S_IFREG = 0x8000; // regular file
+ public static final int EXT2_S_IFBLK = 0x6000; // block device
+ public static final int EXT2_S_IFDIR = 0x4000; // directory
+ public static final int EXT2_S_IFCHR = 0x2000; // character device
+ public static final int EXT2_S_IFIFO = 0x1000; // fifo
+
+ // access rights
+ public static final int EXT2_S_ISUID = 0x0800; // SUID
+ public static final int EXT2_S_ISGID = 0x0400; // SGID
+ public static final int EXT2_S_ISVTX = 0x0200; // sticky bit
+ public static final int EXT2_S_IRWXU = 0x01C0; // user access right mask
+ public static final int EXT2_S_IRUSR = 0x0100; // read
+ public static final int EXT2_S_IWUSR = 0x0080; // write
+ public static final int EXT2_S_IXUSR = 0x0040; // execute
+ public static final int EXT2_S_IRWXG = 0x0038; // group access right mask
+ public static final int EXT2_S_IRGRP = 0x0020; // read
+ public static final int EXT2_S_IWGRP = 0x0010; // write
+ public static final int EXT2_S_IXGRP = 0x0008; // execute
+ public static final int EXT2_S_IRWXO = 0x0007; // others access right mask
+ public static final int EXT2_S_IROTH = 0x0004; // read
+ public static final int EXT2_S_IWOTH = 0x0002; // write
+ public static final int EXT2_S_IXOTH = 0x0001; // execute
- //S_FEATURE_INCOMPAT constants
- public static final long EXT2_FEATURE_INCOMPAT_COMPRESSION = 0x0001;
- public static final long EXT2_FEATURE_INCOMPAT_FILETYPE = 0x0002;
- public static final long EXT3_FEATURE_INCOMPAT_RECOVER = 0x0004;
- public static final long EXT3_FEATURE_INCOMPAT_JOURNAL_DEV = 0x0008;
- public static final long EXT2_FEATURE_INCOMPAT_META_BG = 0x0010;
+ // revision level values (stored in the superblock)
+ public static final int EXT2_GOOD_OLD_REV = 0;
+ public static final int EXT2_DYNAMIC_REV = 1;
- //constants specific to this (JNode) implementation
- /**
- * When searching for free blocks, block groups that have at least
- * EXT2_BLOCK_THRESHOLD_RATIO/100 * BlocksPerGroup free blocks are considered first
- * - if this constant is too high, it will lead to higher disk fragmentation
- * - if it is too low, then files might be scattered among multiple block groups
- * on very full partitions (higher file fragmentation)
- * intervall: [0; 100)
- */
- public static final int EXT2_BLOCK_THRESHOLD_PERCENT = 5;
+ public static final int EXT2_PREALLOC_BLOCK = 7;
+ // behaviour control flags in the inode
+ public static final long EXT2_INDEX_FL = 0x00010000; // hash indexed directory
+
+ // Filesystem state constants
+ public static final int EXT2_VALID_FS = 0x0001; // cleanly unmounted
+ public static final int EXT2_ERROR_FS = 0x0002;
+
+ // what to do when errors are detected
+ public static final int EXT2_ERRORS_CONTINUE = 0x0001;
+ public static final int EXT2_ERRORS_RO = 0x0002;
+ public static final int EXT2_ERRORS_PANIC = 0x0003;
+ public static final int EXT2_ERRORS_DEFAULT = EXT2_ERRORS_CONTINUE;
+
+ // S_FEATURE_RO_COMPAT constants
+ public static final long EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER = 0x0001;
+ public static final long EXT2_FEATURE_RO_COMPAT_LARGE_FILE = 0x0002;
+ public static final long EXT2_FEATURE_RO_COMPAT_BTREE_DIR = 0x0004;
+
+ // S_FEATURE_INCOMPAT constants
+ public static final long EXT2_FEATURE_INCOMPAT_COMPRESSION = 0x0001;
+ public static final long EXT2_FEATURE_INCOMPAT_FILETYPE = 0x0002;
+ public static final long EXT3_FEATURE_INCOMPAT_RECOVER = 0x0004;
+ public static final long EXT3_FEATURE_INCOMPAT_JOURNAL_DEV = 0x0008;
+ public static final long EXT2_FEATURE_INCOMPAT_META_BG = 0x0010;
+
+ // constants specific to this (JNode) implementation
+ /**
+ * When searching for free blocks, block groups that have at least
+ * EXT2_BLOCK_THRESHOLD_RATIO/100 * BlocksPerGroup free blocks are
+ * considered first - if this constant is too high, it will lead to higher
+ * disk fragmentation - if it is too low, then files might be scattered
+ * among multiple block groups on very full partitions (higher file
+ * fragmentation) intervall: [0; 100)
+ */
+ public static final int EXT2_BLOCK_THRESHOLD_PERCENT = 5;
+
}
Modified: trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Directory.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Directory.java 2008-06-05 14:26:18 UTC (rev 4201)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Directory.java 2008-06-06 11:57:12 UTC (rev 4202)
@@ -18,7 +18,7 @@
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
+
package org.jnode.fs.ext2;
import java.io.IOException;
@@ -76,8 +76,7 @@
*/
public FSEntry createDirectoryEntry(String name) throws IOException {
if (!canWrite())
- throw new IOException(
- "Filesystem or directory is mounted read-only!");
+ throw new IOException("Filesystem or directory is mounted read-only!");
//create a new iNode for the file
//TODO: access rights, file type, UID and GID should be passed through
@@ -87,33 +86,28 @@
Ext2Entry newEntry;
Ext2FileSystem fs = (Ext2FileSystem) getFileSystem();
try {
- int rights = 0xFFFF & (Ext2Constants.EXT2_S_IRWXU
- | Ext2Constants.EXT2_S_IRWXG | Ext2Constants.EXT2_S_IRWXO);
- newINode = fs.createINode((int) iNode.getGroup(),
- Ext2Constants.EXT2_S_IFDIR, rights, 0, 0);
+ int rights =
+ 0xFFFF & (Ext2Constants.EXT2_S_IRWXU | Ext2Constants.EXT2_S_IRWXG | Ext2Constants.EXT2_S_IRWXO);
+ newINode = fs.createINode((int) iNode.getGroup(), Ext2Constants.EXT2_S_IFDIR, rights, 0, 0);
- dr = new Ext2DirectoryRecord(fs, newINode.getINodeNr(),
- Ext2Constants.EXT2_FT_DIR, name);
+ dr = new Ext2DirectoryRecord(fs, newINode.getINodeNr(), Ext2Constants.EXT2_FT_DIR, name);
addDirectoryRecord(dr);
newINode.setLinksCount(newINode.getLinksCount() + 1);
- newEntry = new Ext2Entry(newINode, name, Ext2Constants.EXT2_FT_DIR,
- fs, this);
+ newEntry = new Ext2Entry(newINode, name, Ext2Constants.EXT2_FT_DIR, fs, this);
//add "."
Ext2Directory newDir = new Ext2Directory(newEntry);
- Ext2DirectoryRecord drThis = new Ext2DirectoryRecord(fs, newINode
- .getINodeNr(), Ext2Constants.EXT2_FT_DIR, ".");
+ Ext2DirectoryRecord drThis =
+ new Ext2DirectoryRecord(fs, newINode.getINodeNr(), Ext2Constants.EXT2_FT_DIR, ".");
newINode.setLinksCount(2);
newDir.addDirectoryRecord(drThis);
//add ".."
- long parentINodeNr = ((Ext2Directory) entry.getDirectory())
- .getINode().getINodeNr();
- Ext2DirectoryRecord drParent = new Ext2DirectoryRecord(fs,
- parentINodeNr, Ext2Constants.EXT2_FT_DIR, "..");
+ long parentINodeNr = ((Ext2Directory) entry.getDirectory()).getINode().getINodeNr();
+ Ext2DirectoryRecord drParent = new Ext2DirectoryRecord(fs, parentINodeNr, Ext2Constants.EXT2_FT_DIR, "..");
newDir.addDirectoryRecord(drParent);
//increase the reference count for the parent directory
@@ -121,8 +115,7 @@
parentINode.setLinksCount(parentINode.getLinksCount() + 1);
//update the number of used directories in the block group
- int group = (int) ((newINode.getINodeNr() - 1) / fs.getSuperblock()
- .getINodesPerGroup());
+ int group = (int) ((newINode.getINodeNr() - 1) / fs.getSuperblock().getINodesPerGroup());
fs.modifyUsedDirsCount(group, 1);
//update the new inode
@@ -145,8 +138,7 @@
*/
public FSEntry createFileEntry(String name) throws IOException {
if (!canWrite())
- throw new IOException(
- "Filesystem or directory is mounted read-only!");
+ throw new IOException("Filesystem or directory is mounted read-only!");
//create a new iNode for the file
//TODO: access rights, file type, UID and GID should be passed through
@@ -155,13 +147,11 @@
Ext2DirectoryRecord dr;
Ext2FileSystem fs = (Ext2FileSystem) getFileSystem();
try {
- int rights = 0xFFFF & (Ext2Constants.EXT2_S_IRWXU
- | Ext2Constants.EXT2_S_IRWXG | Ext2Constants.EXT2_S_IRWXO);
- newINode = fs.createINode((int) iNode.getGroup(),
- Ext2Constants.EXT2_S_IFREG, rights, 0, 0);
+ int rights =
+ 0xFFFF & (Ext2Constants.EXT2_S_IRWXU | Ext2Constants.EXT2_S_IRWXG | Ext2Constants.EXT2_S_IRWXO);
+ newINode = fs.createINode((int) iNode.getGroup(), Ext2Constants.EXT2_S_IFREG, rights, 0, 0);
- dr = new Ext2DirectoryRecord(fs, newINode.getINodeNr(),
- Ext2Constants.EXT2_FT_REG_FILE, name);
+ dr = new Ext2DirectoryRecord(fs, newINode.getINodeNr(), Ext2Constants.EXT2_FT_REG_FILE, name);
addDirectoryRecord(dr);
@@ -172,8 +162,7 @@
ioe.initCause(ex);
throw ioe;
}
- return new Ext2Entry(newINode, name, Ext2Constants.EXT2_FT_REG_FILE,
- fs, this);
+ return new Ext2Entry(newINode, name, Ext2Constants.EXT2_FT_REG_FILE, fs, this);
}
/**
@@ -184,11 +173,9 @@
* @return @throws
* IOException
*/
- protected FSEntry addINode(int iNodeNr, String linkName, int fileType)
- throws IOException {
+ protected FSEntry addINode(int iNodeNr, String linkName, int fileType) throws IOException {
if (!canWrite())
- throw new IOException(
- "Filesystem or directory is mounted read-only!");
+ throw new IOException("Filesystem or directory is mounted read-only!");
//TODO: access rights, file type, UID and GID should be passed through
// the FSDirectory interface
@@ -214,8 +201,7 @@
}
}
- private void addDirectoryRecord(Ext2DirectoryRecord dr) throws IOException,
- FileSystemException {
+ private void addDirectoryRecord(Ext2DirectoryRecord dr) throws IOException, FileSystemException {
//synchronize to the inode cache to make sure that the inode does not
// get
//flushed between reading it and locking it
@@ -225,20 +211,14 @@
int iNodeNr = iNode.getINodeNr();
iNode = ((Ext2FileSystem) getFileSystem()).getINode(iNodeNr);
- //lock the inode into the cache so it is not flushed before
- // synchronizing to it
- //(otherwise a new instance of INode referring to the same inode
- // could be put
- //in the cache resulting in the possibility of two threads
- // manipulating the same
- //inode at the same time because they would synchronize to
- // different INode instances)
+ //lock the inode into the cache so it is not flushed before synchronizing to it
+ //(otherwise a new instance of INode referring to the same inode could be put
+ //in the cache resulting in the possibility of two threads manipulating the same
+ //inode at the same time because they would synchronize to different INode instances)
iNode.incLocked();
}
- //a single inode may be represented by more than one Ext2Directory
- // instances,
- //but each will use the same instance of the underlying inode (see
- // Ext2FileSystem.getINode()),
+ //a single inode may be represented by more than one Ext2Directory instances,
+ //but each will use the same instance of the underlying inode (see Ext2FileSystem.getINode()),
//so synchronize to the inode.
synchronized (iNode) {
try {
@@ -256,75 +236,57 @@
long lastPos = rec.getFileOffset();
long lastLen = rec.getRecLen();
- //truncate the last record to its minimal size (cut the
- // padding from the end)
+ //truncate the last record to its minimal size (cut the padding from the end)
rec.truncateRecord();
//directoryRecords may not extend over block boundaries:
- // see if the new record fits in the same block after
- // truncating the last record
- long remainingLength = fs.getBlockSize()
- - (lastPos % fs.getBlockSize()) - rec.getRecLen();
- log.debug("LAST-1 record: begins at: " + lastPos
- + ", length: " + lastLen);
+ //see if the new record fits in the same block after truncating the last record
+ long remainingLength = fs.getBlockSize() - (lastPos % fs.getBlockSize()) - rec.getRecLen();
+ log.debug("LAST-1 record: begins at: " + lastPos + ", length: " + lastLen);
log.debug("LAST-1 truncated length: " + rec.getRecLen());
log.debug("Remaining length: " + remainingLength);
if (remainingLength >= dr.getRecLen()) {
//write back the last record truncated
//TODO optimize it also to use ByteBuffer at lower level
- ByteBuffer buf = ByteBuffer.wrap(rec.getData(), rec.getOffset(), rec
- .getRecLen());
+ ByteBuffer buf = ByteBuffer.wrap(rec.getData(), rec.getOffset(), rec.getRecLen());
dir.write(lastPos, buf);
-// dir.write(lastPos, rec.getData(), rec.getOffset(), rec
-// .getRecLen());
+ // dir.write(lastPos, rec.getData(), rec.getOffset(), rec
+ // .getRecLen());
//pad the end of the new record with zeroes
- dr.expandRecord(lastPos + rec.getRecLen(), lastPos
- + rec.getRecLen() + remainingLength);
-
+ dr.expandRecord(lastPos + rec.getRecLen(), lastPos + rec.getRecLen() + remainingLength);
+
//append the new record at the end of the list
//TODO optimize it also to use ByteBuffer at lower level
- buf = ByteBuffer.wrap(dr.getData(), dr
- .getOffset(), dr.getRecLen());
+ buf = ByteBuffer.wrap(dr.getData(), dr.getOffset(), dr.getRecLen());
dir.write(lastPos + rec.getRecLen(), buf);
-// dir.write(lastPos + rec.getRecLen(), dr.getData(), dr
-// .getOffset(), dr.getRecLen());
-
- log.debug("addDirectoryRecord(): LAST record: begins at: "
- + (rec.getFileOffset() + rec
- .getRecLen())
- + ", length: "
- + dr.getRecLen());
+ // dir.write(lastPos + rec.getRecLen(), dr.getData(), dr
+ // .getOffset(), dr.getRecLen());
+
+ log.debug("addDirectoryRecord(): LAST record: begins at: " +
+ (rec.getFileOffset() + rec.getRecLen()) + ", length: " + dr.getRecLen());
} else {
//the new record must go to the next block
//(the previously last record (rec) stays padded to the
// end of the block, so we can
// append after that)
- dr.expandRecord(lastPos + lastLen, lastPos + lastLen
- + fs.getBlockSize());
+ dr.expandRecord(lastPos + lastLen, lastPos + lastLen + fs.getBlockSize());
//TODO optimize it also to use ByteBuffer at lower level
- ByteBuffer buf = ByteBuffer.wrap(dr.getData(),
- dr.getOffset(), dr.getRecLen());
+ ByteBuffer buf = ByteBuffer.wrap(dr.getData(), dr.getOffset(), dr.getRecLen());
dir.write(lastPos + lastLen, buf);
-// dir.write(lastPos + lastLen, dr.getData(), dr
-// .getOffset(), dr.getRecLen());
- log
- .debug("addDirectoryRecord(): LAST record: begins at: "
- + (lastPos + lastLen)
- + ", length: "
- + dr.getRecLen());
+ // dir.write(lastPos + lastLen, dr.getData(), dr
+ // .getOffset(), dr.getRecLen());
+ log.debug("addDirectoryRecord(): LAST record: begins at: " + (lastPos + lastLen) +
+ ", length: " + dr.getRecLen());
}
- } else { //rec==null, ie. this is the first record in the
- // directory
+ } else { //rec==null, ie. this is the first record in the directory
dr.expandRecord(0, fs.getBlockSize());
//TODO optimize it also to use ByteBuffer at lower level
ByteBuffer buf = ByteBuffer.wrap(dr.getData(), dr.getOffset(), dr.getRecLen());
dir.write(0, buf);
//dir.write(0, dr.getData(), dr.getOffset(), dr.getRecLen());
- log
- .debug("addDirectoryRecord(): LAST record: begins at: 0, length: "
- + dr.getRecLen());
+ log.debug("addDirectoryRecord(): LAST record: begins at: 0, length: " + dr.getRecLen());
}
//dir.flush();
@@ -335,9 +297,9 @@
return;
} catch (Throwable ex) {
- final IOException ioe = new IOException();
- ioe.initCause(ex);
- throw ioe;
+ final IOException ioe = new IOException();
+ ioe.initCause(ex);
+ throw ioe;
} finally {
//unlock the inode from the cache
iNode.decLocked();
@@ -374,12 +336,12 @@
//read itself as a file
Ext2File directoryFile = new Ext2File(iNode);
//read the whole directory
-
- data = ByteBuffer.allocate((int) directoryFile.getLength());
+
+ data = ByteBuffer.allocate((int) directoryFile.getLength());
directoryFile.read(0, data);
//data = new byte[(int) directoryFile.getLength()];
//directoryFile.read(0, data, 0, (int) directoryFile.getLength());
-
+
index = 0;
}
@@ -395,7 +357,7 @@
dr = new Ext2DirectoryRecord(fs, data.array(), index, index);
index += dr.getRecLen();
} while (dr.getINodeNr() == 0); //inode nr=0 means the entry is
- // unused
+ // unused
} catch (Exception e) {
fs.handleFSError(e);
return false;
@@ -416,18 +378,15 @@
Ext2FileSystem fs = (Ext2FileSystem) getFileSystem();
current = null;
try {
- return new Ext2Entry(((Ext2FileSystem) getFileSystem())
- .getINode(dr.getINodeNr()), dr.getName(), dr.getType(),
- fs, Ext2Directory.this);
+ return new Ext2Entry(((Ext2FileSystem) getFileSystem()).getINode(dr.getINodeNr()),
+ dr.getName(), dr.getType(), fs, Ext2Directory.this);
} catch (IOException e) {
- throw new NoSuchElementException("Root cause: "
- + e.getMessage());
+ throw new NoSuchElementException("Root cause: " + e.getMessage());
} catch (FileSystemException e) {
- throw new NoSuchElementException("Root cause: "
- + e.getMessage());
+ throw new NoSuchElementException("Root cause: " + e.getMessage());
}
}
-
+
/**
* @see java.util.Iterator#remove()
*/
@@ -469,8 +428,7 @@
entries.add(entry);
}
- FSEntryTable table = new FSEntryTable(
- (AbstractFileSystem) getFileSystem(), entries);
+ FSEntryTable table = new FSEntryTable((AbstractFileSystem) getFileSystem(), entries);
return table;
}
Modified: trunk/fs/src/fs/org/jnode/fs/ext2/Ext2DirectoryRecord.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/Ext2DirectoryRecord.java 2008-06-05 14:26:18 UTC (rev 4201)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/Ext2DirectoryRecord.java 2008-06-06 11:57:12 UTC (rev 4202)
@@ -18,7 +18,7 @@
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
+
package org.jnode.fs.ext2;
import java.util.Arrays;
@@ -27,178 +27,195 @@
import org.jnode.fs.FileSystemException;
/**
- * A single directory record, i.e. the inode number and name of
- * an entry in a directory
+ * A single directory record, i.e. the inode number and name of an entry in a
+ * directory
*
* @author Andras Nagy
*/
public class Ext2DirectoryRecord {
- private final Logger log = Logger.getLogger(getClass());
- /*
- private int iNodeNr;
- private int recLen;
- private short nameLen;
- private short type;
- private StringBuffer name;
- */
- private int offset;
- private byte[] data;
- private long fileOffset;
- private Ext2FileSystem fs;
-
- /**
- * @param data: the data that makes up the directory block
- * @param offset: the offset where the current DirectoryRecord begins within the block
- * @param fileOffset: the offset from the beginning of the directory file
- */
- public Ext2DirectoryRecord(Ext2FileSystem fs, byte[] data, int offset, int fileOffset) {
- this.fs=fs;
- this.data = data;
- this.offset = offset;
- this.fileOffset = fileOffset;
-
- //make a copy of the data
- synchronized(data) {
- byte[] newData = new byte[getRecLen()];
- System.arraycopy(data, offset, newData, 0, getRecLen());
- this.data = newData;
- setOffset(0);
- }
- }
-
- /**
- * Create a new Ext2DirectoryRecord from scratch (it can be retrieved with getData())
- * @param iNodeNr
- * @param type
- * @param name
- */
- public Ext2DirectoryRecord(Ext2FileSystem fs, long iNodeNr, int type, String name) {
- this.offset=0;
- this.fs=fs;
- data = new byte[8+name.length()];
- setName(name);
- setINodeNr(iNodeNr);
- setType(type);
- setNameLen(name.length());
- int newLength = name.length() + 8;
- //record length is padded to n*4 bytes
- if(newLength%4!=0)
- newLength+=4-newLength%4;
- setRecLen(newLength);
- }
-
- public byte[] getData() {
- return data;
- }
-
- public int getOffset() {
- return offset;
- }
- private void setOffset(int offset) {
- this.offset = offset;
- }
-
- public long getFileOffset() {
- return fileOffset;
- }
- private void setFileOffset(long fileOffset) {
- this.fileOffset=fileOffset;
- }
- /**
- * Returns the fileType.
- * @return short
- */
- public synchronized int getType() {
- return Ext2Utils.get8(data, offset+7);
- }
+ private final Logger log = Logger.getLogger(getClass());
+ /*
+ * private int iNodeNr; private int recLen; private short nameLen; private
+ * short type; private StringBuffer name;
+ */
+ private int offset;
+ private byte[] data;
+ private long fileOffset;
+ private Ext2FileSystem fs;
- private synchronized void setType(int type) {
- if(!fs.hasIncompatFeature(Ext2Constants.EXT2_FEATURE_INCOMPAT_FILETYPE))
- return;
- Ext2Utils.set8(data, offset+7, type);
- }
- /**
- * Returns the iNodeNr.
- * @return long
- */
- public synchronized int getINodeNr() {
- return (int)Ext2Utils.get32(data, offset);
- }
- private synchronized void setINodeNr(long nr) {
- Ext2Utils.set32(data, offset, nr);
- }
-
- /**
- * Returns the name.
- * @return StringBuffer
- */
- public synchronized String getName() {
- StringBuffer name = new StringBuffer();
- if(getINodeNr()!=0) {
- //TODO: character conversion??
- for(int i=0; i<getNameLen(); i++)
- name.append( (char)Ext2Utils.get8(data, offset+8+i) );
- log.debug("Ext2DirectoryRecord(): iNode="+getINodeNr()+", name="+name);
- }
- return name.toString();
- }
- private synchronized void setName(String name) {
- for(int i=0; i<name.length(); i++)
- Ext2Utils.set8(data, offset+8+i, name.charAt(i));
- }
-
- /**
- * Returns the recLen.
- * @return int
- */
- public synchronized int getRecLen() {
- return Ext2Utils.get16(data, offset+4);
- }
- private synchronized void setRecLen(int len) {
- Ext2Utils.set16(data, offset+4, len);
- }
-
- private synchronized int getNameLen() {
- return Ext2Utils.get8(data, offset+6);
- }
- private synchronized void setNameLen(int len) {
- Ext2Utils.set8(data, offset+6, len);
- }
-
- /**
- * The last directory record's length is set such that it extends until the end of the block.
- * This method truncates it when a new record is added to the directory
- */
- protected synchronized void truncateRecord() {
- int newLength = getNameLen() + 8;
- //record length is padded to n*4 bytes
- if(newLength%4!=0)
- newLength+=4-newLength%4;
- setRecLen(newLength);
- log.debug("truncateRecord(): newLength: "+newLength);
- }
-
- /**
- * The last directory record's length is set such that it extends until the end of the block.
- * This method extends the directory record to this length.
- * The directoryRecord's <code>fileOffset</code> will be set to <code>beginning</code>.
- * @param beginning: the offset where the record begins
- * @param end: the offset where the record should end (usually the size a filesystem block)
- */
- protected synchronized void expandRecord(long beginning, long end) throws FileSystemException{
- log.debug("expandRecord("+beginning + ", "+ end+")");
- if(beginning+getNameLen()+8 < end) {
- //the record fits in the block
- setRecLen((int)(end - beginning));
- //pad the end of the record with zeroes
- byte[] newData = new byte[getRecLen()];
- Arrays.fill(newData, 0, getRecLen(), (byte)0);
- System.arraycopy(data, getOffset(), newData, 0, getNameLen()+8);
- setOffset(0);
- setFileOffset(beginning);
- data=newData;
- } else
- throw new FileSystemException("The directory record does not fit into the block!");
- log.debug("expandRecord(): newLength: "+getRecLen());
- }
+ /**
+ * @param data: the data that makes up the directory block
+ * @param offset: the offset where the current DirectoryRecord begins within
+ * the block
+ * @param fileOffset: the offset from the beginning of the directory file
+ */
+ public Ext2DirectoryRecord(Ext2FileSystem fs, byte[] data, int offset, int fileOffset) {
+ this.fs = fs;
+ this.data = data;
+ this.offset = offset;
+ this.fileOffset = fileOffset;
+
+ // make a copy of the data
+ synchronized (data) {
+ byte[] newData = new byte[getRecLen()];
+ System.arraycopy(data, offset, newData, 0, getRecLen());
+ this.data = newData;
+ setOffset(0);
+ }
+ }
+
+ /**
+ * Create a new Ext2DirectoryRecord from scratch (it can be retrieved with
+ * getData())
+ *
+ * @param iNodeNr
+ * @param type
+ * @param name
+ */
+ public Ext2DirectoryRecord(Ext2FileSystem fs, long iNodeNr, int type, String name) {
+ this.offset = 0;
+ this.fs = fs;
+ data = new byte[8 + name.length()];
+ setName(name);
+ setINodeNr(iNodeNr);
+ setType(type);
+ setNameLen(name.length());
+ int newLength = name.length() + 8;
+ // record length is padded to n*4 bytes
+ if (newLength % 4 != 0)
+ newLength += 4 - newLength % 4;
+ setRecLen(newLength);
+ }
+
+ public byte[] getData() {
+ return data;
+ }
+
+ public int getOffset() {
+ return offset;
+ }
+
+ private void setOffset(int offset) {
+ this.offset = offset;
+ }
+
+ public long getFileOffset() {
+ return fileOffset;
+ }
+
+ private void setFileOffset(long fileOffset) {
+ this.fileOffset = fileOffset;
+ }
+
+ /**
+ * Returns the fileType.
+ *
+ * @return short
+ */
+ public synchronized int getType() {
+ return Ext2Utils.get8(data, offset + 7);
+ }
+
+ private synchronized void setType(int type) {
+ if (!fs.hasIncompatFeature(Ext2Constants.EXT2_FEATURE_INCOMPAT_FILETYPE))
+ return;
+ Ext2Utils.set8(data, offset + 7, type);
+ }
+
+ /**
+ * Returns the iNodeNr.
+ *
+ * @return long
+ */
+ public synchronized int getINodeNr() {
+ return (int) Ext2Utils.get32(data, offset);
+ }
+
+ private synchronized void setINodeNr(long nr) {
+ Ext2Utils.set32(data, offset, nr);
+ }
+
+ /**
+ * Returns the name.
+ *
+ * @return StringBuffer
+ */
+ public synchronized String getName() {
+ StringBuffer name = new StringBuffer();
+ if (getINodeNr() != 0) {
+ // TODO: character conversion??
+ for (int i = 0; i < getNameLen(); i++)
+ name.append((char) Ext2Utils.get8(data, offset + 8 + i));
+ log.debug("Ext2DirectoryRecord(): iNode=" + getINodeNr() + ", name=" + name);
+ }
+ return name.toString();
+ }
+
+ private synchronized void setName(String name) {
+ for (int i = 0; i < name.length(); i++)
+ Ext2Utils.set8(data, offset + 8 + i, name.charAt(i));
+ }
+
+ /**
+ * Returns the recLen.
+ *
+ * @return int
+ */
+ public synchronized int getRecLen() {
+ return Ext2Utils.get16(data, offset + 4);
+ }
+
+ private synchronized void setRecLen(int len) {
+ Ext2Utils.set16(data, offset + 4, len);
+ }
+
+ private synchronized int getNameLen() {
+ return Ext2Utils.get8(data, offset + 6);
+ }
+
+ private synchronized void setNameLen(int len) {
+ Ext2Utils.set8(data, offset + 6, len);
+ }
+
+ /**
+ * The last directory record's length is set such that it extends until the
+ * end of the block. This method truncates it when a new record is added to
+ * the directory
+ */
+ protected synchronized void truncateRecord() {
+ int newLength = getNameLen() + 8;
+ // record length is padded to n*4 bytes
+ if (newLength % 4 != 0)
+ newLength += 4 - newLength % 4;
+ setRecLen(newLength);
+ log.debug("truncateRecord(): newLength: " + newLength);
+ }
+
+ /**
+ * The last directory record's length is set such that it extends until the
+ * end of the block. This method extends the directory record to this
+ * length. The directoryRecord's <code>fileOffset</code> will be set to
+ * <code>beginning</code>.
+ *
+ * @param beginning: the offset where the record begins
+ * @param end: the offset where the record should end (usually the size a
+ * filesystem block)
+ */
+ protected synchronized void expandRecord(long beginning, long end) throws FileSystemException {
+ log.debug("expandRecord(" + beginning + ", " + end + ")");
+ if (beginning + getNameLen() + 8 < end) {
+ // the record fits in the block
+ setRecLen((int) (end - beginning));
+ // pad the end of the record with zeroes
+ byte[] newData = new byte[getRecLen()];
+ Arrays.fill(newData, 0, getRecLen(), (byte) 0);
+ System.arraycopy(data, getOffset(), newData, 0, getNameLen() + 8);
+ setOffset(0);
+ setFileOffset(beginning);
+ data = newData;
+ } else {
+ throw new FileSystemException("The directory record does not fit into the block!");
+ }
+ log.debug("expandRecord(): newLength: " + getRecLen());
+ }
}
Modified: trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Entry.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Entry.java 2008-06-05 14:26:18 UTC (rev 4201)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Entry.java 2008-06-06 11:57:12 UTC (rev 4202)
@@ -34,60 +34,55 @@
* In case of a directory, the data will be parsed to get the file-list by
* Ext2Directory. In case of a regular file, no more processing is needed.
*
- * TODO: besides getFile() and getDirectory(), we will need
- * getBlockDevice()
- * getCharacterDevice(), etc.
+ * TODO: besides getFile() and getDirectory(), we will need getBlockDevice()
+ * getCharacterDevice(), etc.
*/
public class Ext2Entry extends AbstractFSEntry {
- private final Logger log = Logger.getLogger(getClass());
- private INode iNode=null;
- private int type;
+ private final Logger log = Logger.getLogger(getClass());
+ private INode iNode = null;
+ private int type;
- public Ext2Entry(INode iNode, String name, int type, Ext2FileSystem fs, FSDirectory parent) {
- super(fs, null, parent, name, getFSEntryType(name, iNode));
- this.iNode = iNode;
- this.type = type;
-
- log.setLevel(Level.INFO);
-
- log.debug("Ext2Entry(iNode, name): name="+name+
- (isDirectory()?" is a directory ":"")+
- (isFile()?" is a file ":""));
-
- }
+ public Ext2Entry(INode iNode, String name, int type, Ext2FileSystem fs, FSDirectory parent) {
+ super(fs, null, parent, name, getFSEntryType(name, iNode));
+ this.iNode = iNode;
+ this.type = type;
- /**
- * @see org.jnode.fs.FSEntry#getLastModified()
- */
- public long getLastModified() throws IOException {
- return iNode.getMtime();
- }
+ log.setLevel(Level.INFO);
+ log.debug("Ext2Entry(iNode, name): name=" + name + (isDirectory() ? " is a directory " : "") +
+ (isFile() ? " is a file " : ""));
+ }
- /**
- * Returns the type.
- * @return int type. Valid types are Ext2Constants.EXT2_FT_*
- */
- public int getType() {
- return type;
- }
-
- INode getINode()
- {
- return iNode;
- }
-
- static private int getFSEntryType(String name, INode iNode) {
- int mode=iNode.getMode()&Ext2Constants.EXT2_S_IFMT;
-
- if("/".equals(name))
- return AbstractFSEntry.ROOT_ENTRY;
- else if(mode == Ext2Constants.EXT2_S_IFDIR)
- return AbstractFSEntry.DIR_ENTRY;
- else if(mode == Ext2Constants.EXT2_S_IFREG ||
- mode == Ext2Constants.EXT2_FT_SYMLINK)
- return AbstractFSEntry.FILE_ENTRY;
- else
- return AbstractFSEntry.OTHER_ENTRY;
- }
+ /**
+ * @see org.jnode.fs.FSEntry#getLastModified()
+ */
+ public long getLastModified() throws IOException {
+ return iNode.getMtime();
+ }
+
+ /**
+ * Returns the type.
+ *
+ * @return int type. Valid types are Ext2Constants.EXT2_FT_*
+ */
+ public int getType() {
+ return type;
+ }
+
+ INode getINode() {
+ return iNode;
+ }
+
+ private static int getFSEntryType(String name, INode iNode) {
+ int mode = iNode.getMode() & Ext2Constants.EXT2_S_IFMT;
+
+ if ("/".equals(name))
+ return AbstractFSEntry.ROOT_ENTRY;
+ else if (mode == Ext2Constants.EXT2_S_IFDIR)
+ return AbstractFSEntry.DIR_ENTRY;
+ else if (mode == Ext2Constants.EXT2_S_IFREG || mode == Ext2Constants.EXT2_FT_SYMLINK)
+ return AbstractFSEntry.FILE_ENTRY;
+ else
+ return AbstractFSEntry.OTHER_ENTRY;
+ }
}
Modified: trunk/fs/src/fs/org/jnode/fs/ext2/Ext2File.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/Ext2File.java 2008-06-05 14:26:18 UTC (rev 4201)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/Ext2File.java 2008-06-06 11:57:12 UTC (rev 4202)
@@ -18,7 +18,7 @@
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
+
package org.jnode.fs.ext2;
import java.io.IOException;
@@ -74,8 +74,7 @@
*/
public void setLength(long length) throws IOException {
if (!canWrite())
- throw new ReadOnlyFileSystemException(
- "FileSystem or File is readonly");
+ throw new ReadOnlyFileSystemException("FileSystem or File is readonly");
long blockSize = iNode.getExt2FileSystem().getBlockSize();
@@ -115,8 +114,7 @@
nextBlock = blockNr + 1;
for (long i = iNode.getAllocatedBlockCount() - 1; i >= nextBlock; i--) {
- log.debug("setLength(): freeing up block " + i
- + " of inode");
+ log.debug("setLength(): freeing up block " + i + " of inode");
iNode.freeDataBlock(i);
}
iNode.setSize(length);
@@ -137,12 +135,9 @@
long bytesAllocated = getLength();
long bytesCovered = 0;
while (bytesCovered < len) {
- long blockIndex = (bytesAllocated + bytesCovered)
- / blockSize;
- long blockOffset = (bytesAllocated + bytesCovered)
- % blockSize;
- long newSection = Math.min(len - bytesCovered,
- blockSize - blockOffset);
+ long blockIndex = (bytesAllocated + bytesCovered) / blockSize;
+ long blockOffset = (bytesAllocated + bytesCovered) % blockSize;
+ long newSection = Math.min(len - bytesCovered, blockSize - blockOffset);
//allocate a new block if needed
if (blockIndex >= blocksAllocated) {
@@ -173,14 +168,13 @@
* @see org.jnode.fs.FSFile#read(long, byte[], int, int)
*/
//public void read(long fileOffset, byte[] dest, int off, int len)
- public void read(long fileOffset, ByteBuffer destBuf)
- throws IOException {
+ public void read(long fileOffset, ByteBuffer destBuf) throws IOException {
final int len = destBuf.remaining();
final int off = 0;
//TODO optimize it also to use ByteBuffer at lower level
final ByteBufferUtils.ByteArray destBA = ByteBufferUtils.toByteArray(destBuf);
final byte[] dest = destBA.toArray();
-
+
//synchronize to the inode cache to make sure that the inode does not
// get
//flushed between reading it and locking it
@@ -213,16 +207,14 @@
while (bytesRead < len) {
long blockNr = (fileOffset + bytesRead) / blockSize;
long blockOffset = (fileOffset + bytesRead) % blockSize;
- long copyLength = Math.min(len - bytesRead, blockSize
- - blockOffset);
+ long copyLength = Math.min(len - bytesRead, blockSize - blockOffset);
- log.debug("blockNr: "+blockNr+", blockOffset: "+blockOffset+
- ", copyLength: "+copyLength+", bytesRead: "+bytesRead);
+ log.debug("blockNr: " + blockNr + ", blockOffset: " + blockOffset + ", copyLength: " + copyLength +
+ ", bytesRead: " + bytesRead);
- System.array...
[truncated message content] |