From: <fd...@us...> - 2008-01-01 00:06:54
|
Revision: 3672 http://jnode.svn.sourceforge.net/jnode/?rev=3672&view=rev Author: fduminy Date: 2007-12-31 16:06:53 -0800 (Mon, 31 Dec 2007) Log Message: ----------- - replaced set of int values by Enums in ext2/fat/jfat Formatter implementations - use of new EnumOptionArgument for Formatter commands Modified Paths: -------------- trunk/builder/src/builder/org/jnode/build/BootDiskBuilder.java trunk/fs/src/fs/org/jnode/fs/Formatter.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/Superblock.java trunk/fs/src/fs/org/jnode/fs/ext2/command/FormatExt2Command.java trunk/fs/src/fs/org/jnode/fs/fat/Fat.java trunk/fs/src/fs/org/jnode/fs/fat/FatFileSystem.java trunk/fs/src/fs/org/jnode/fs/fat/FatFileSystemFormatter.java trunk/fs/src/fs/org/jnode/fs/fat/FatFormatter.java trunk/fs/src/fs/org/jnode/fs/fat/GrubFatFormatter.java trunk/fs/src/fs/org/jnode/fs/fat/command/FormatFatCommand.java trunk/fs/src/fs/org/jnode/fs/initrd/InitRamdisk.java trunk/fs/src/fs/org/jnode/fs/jfat/FatFileSystemFormatter.java trunk/fs/src/fs/org/jnode/fs/jfat/FatFormatter.java trunk/fs/src/fs/org/jnode/fs/jfat/command/FatFormatCommand.java trunk/fs/src/test/org/jnode/test/fs/filesystem/FSConfigurations.java Added Paths: ----------- trunk/fs/src/fs/org/jnode/fs/ext2/BlockSize.java trunk/fs/src/fs/org/jnode/fs/fat/FatType.java trunk/fs/src/fs/org/jnode/fs/jfat/ClusterSize.java Modified: trunk/builder/src/builder/org/jnode/build/BootDiskBuilder.java =================================================================== --- trunk/builder/src/builder/org/jnode/build/BootDiskBuilder.java 2008-01-01 00:03:48 UTC (rev 3671) +++ trunk/builder/src/builder/org/jnode/build/BootDiskBuilder.java 2008-01-01 00:06:53 UTC (rev 3672) @@ -35,6 +35,7 @@ import org.jnode.driver.block.MappedFSBlockDeviceSupport; import org.jnode.fs.FileSystemException; import org.jnode.fs.fat.Fat; +import org.jnode.fs.fat.FatType; import org.jnode.fs.fat.GrubBootSector; import org.jnode.fs.fat.GrubFatFormatter; import org.jnode.partitions.ibm.IBMPartitionTableEntry; @@ -141,7 +142,7 @@ * @throws IOException */ protected GrubFatFormatter createFormatter() throws IOException { - return new GrubFatFormatter(bytesPerSector, spc, geom, Fat.FAT16, 1, + return new GrubFatFormatter(bytesPerSector, spc, geom, FatType.FAT16, 1, getStage1ResourceName(), getStage2ResourceName()); } Modified: trunk/fs/src/fs/org/jnode/fs/Formatter.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/Formatter.java 2008-01-01 00:03:48 UTC (rev 3671) +++ trunk/fs/src/fs/org/jnode/fs/Formatter.java 2008-01-01 00:06:53 UTC (rev 3672) @@ -1,6 +1,7 @@ package org.jnode.fs; import org.jnode.driver.Device; +import org.jnode.fs.ext2.Ext2FileSystemType; /** * @@ -8,7 +9,14 @@ * * @param <T> */ -public interface Formatter<T extends FileSystem> { +abstract public class Formatter<T extends FileSystem> { + private final FileSystemType<T> type; + + protected Formatter(FileSystemType<T> type) + { + this.type = type; + } + /** * Format the given device * @@ -16,5 +24,10 @@ * @return the newly created FileSystem * @throws FileSystemException */ - public T format(Device device) throws FileSystemException; + abstract public T format(Device device) throws FileSystemException; + + final public FileSystemType<T> getFileSystemType() + { + return type; + } } Added: trunk/fs/src/fs/org/jnode/fs/ext2/BlockSize.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ext2/BlockSize.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/ext2/BlockSize.java 2008-01-01 00:06:53 UTC (rev 3672) @@ -0,0 +1,21 @@ +package org.jnode.fs.ext2; + +import org.jnode.util.BinaryPrefix; + + +public enum BlockSize { + _1Kb(1), + _2Kb(2), + _4Kb(4); + + private final int size; + + private BlockSize(int blockSizeKb) + { + this.size = (int) (blockSizeKb * BinaryPrefix.K.getMultiplier()); //Converted into KB + } + + final public int getSize() { + return size; + } +} Modified: trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystem.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystem.java 2008-01-01 00:03:48 UTC (rev 3671) +++ trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystem.java 2008-01-01 00:06:53 UTC (rev 3672) @@ -9,16 +9,16 @@ * by the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but + * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., + * 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; @@ -39,7 +39,7 @@ /** * @author Andras Nagy - * + * */ public class Ext2FileSystem extends AbstractFileSystem { private Superblock superblock; @@ -67,7 +67,7 @@ /** * Constructor for Ext2FileSystem in specified readOnly mode - * + * * @throws FileSystemException */ public Ext2FileSystem(Device device, boolean readOnly) @@ -170,10 +170,10 @@ + "\n" + " #block groups: " + groupCount + "\n" + " block size: " + superblock.getBlockSize() + "\n" + " #inodes: " + superblock.getINodesCount() + "\n" - + " #inodes/group: " + superblock.getINodesPerGroup()); + + " #inodes/group: " + superblock.getINodesPerGroup()); } - - public void create(int blockSize) throws FileSystemException { + + public void create(BlockSize blockSize) throws FileSystemException { try { //create the superblock superblock = new Superblock(); @@ -197,8 +197,8 @@ for (int i = 0; i < groupCount; i++) { log.debug("creating group " + i); - byte[] blockBitmap = new byte[blockSize]; - byte[] inodeBitmap = new byte[blockSize]; + byte[] blockBitmap = new byte[blockSize.getSize()]; + byte[] inodeBitmap = new byte[blockSize.getSize()]; //update the block bitmap: mark the metadata blocks allocated long iNodeTableBlock = groupDescriptors[i].getInodeTable(); @@ -225,7 +225,7 @@ INodeBitmap.setBit(inodeBitmap, j); //create an empty inode table - byte[] emptyBlock = new byte[blockSize]; + byte[] emptyBlock = new byte[blockSize.getSize()]; for (long j = iNodeTableBlock; j < firstNonMetadataBlock; j++) writeBlock(j, emptyBlock, false); @@ -252,7 +252,7 @@ /** * Flush all changed structures to the device. - * + * * @throws IOException */ public void flush() throws IOException { @@ -323,12 +323,12 @@ /** * Read a data block and put it in the cache if it is not yet cached, * otherwise get it from the cache. - * + * * Synchronized access to the blockCache is important as the bitmap * operations are synchronized to the blocks (actually, to Block.getData()), * so at any point in time it has to be sure that no two copies of the same * block are stored in the cache. - * + * * @return data block nr */ protected byte[] getBlock(long nr) throws IOException { @@ -381,7 +381,7 @@ /** * Update the block in cache, or write the block to disk - * + * * @param nr: * block number * @param data: @@ -434,14 +434,14 @@ /** * Helper class for timedWrite - * + * * @author blind */ /* * class TimeoutWatcher extends TimerTask { Thread mainThread; public * TimeoutWatcher(Thread mainThread) { this.mainThread = mainThread; } * public void run() { mainThread.interrupt(); } } - * + * * private static final long TIMEOUT = 100; */ /* @@ -461,7 +461,7 @@ * interrupted if(ioe.getCause() instanceof InterruptedException) { * writeTimer.cancel(); log.debug("IDE driver interrupted during write * operation: probably timeout"); finished = false; } } } } - * + * * private void timedRead(long nr, byte[] data) throws IOException{ boolean * finished = false; Timer readTimer; while(!finished) { finished = true; * readTimer = new Timer(); readTimer.schedule(new @@ -480,7 +480,7 @@ /** * Return the inode numbered inodeNr (the first inode is #1) - * + * * Synchronized access to the inodeCache is important as the file/directory * operations are synchronized to the inodes, so at any point in time it has * to be sure that only one instance of any inode is present in the @@ -526,7 +526,7 @@ /** * Checks whether block <code>blockNr</code> is free, and if it is, then * allocates it with preallocation. - * + * * @param blockNr * @return @throws * IOException @@ -577,7 +577,7 @@ /** * Create a new INode - * + * * @param preferredBlockBroup: * first try to allocate the inode in this block group * @return @@ -637,7 +637,7 @@ /** * Find a free INode in the inode bitmap and allocate it - * + * * @param blockGroup * @return @throws * IOException @@ -681,7 +681,7 @@ /** * Modify the number of free blocks in the block group - * + * * @param group * @param diff * can be positive or negative @@ -695,7 +695,7 @@ /** * Modify the number of free inodes in the block group - * + * * @param group * @param diff * can be positive or negative @@ -709,7 +709,7 @@ /** * Modify the number of used directories in a block group - * + * * @param group * @param diff */ @@ -720,7 +720,7 @@ /** * Free up a block in the block bitmap. - * + * * @param blockNr * @throws FileSystemException * @throws IOException @@ -773,7 +773,7 @@ * Find free blocks in the block group <code>group</code>'s block bitmap. * First check for a whole byte of free blocks (0x00) in the bitmap, then * check for any free bit. If blocks are found, mark them as allocated. - * + * * @return the index of the block (from the beginning of the partition) * @param group * the block group to check @@ -845,7 +845,7 @@ /** * Returns the number of groups. - * + * * @return int */ protected int getGroupCount() { @@ -855,7 +855,7 @@ /** * Check whether the filesystem uses the given RO feature * (S_FEATURE_RO_COMPAT) - * + * * @param mask * @return */ @@ -866,7 +866,7 @@ /** * Check whether the filesystem uses the given COMPAT feature * (S_FEATURE_INCOMPAT) - * + * * @param mask * @return */ @@ -877,7 +877,7 @@ /** * utility function for determining if a given block group has superblock * and group descriptor copies - * + * * @param a * positive integer * @param b @@ -901,7 +901,7 @@ /** * With the sparse_super option set, a filesystem does not have a superblock * and group descriptor copy in every block group. - * + * * @param groupNr * @return true if the block group <code>groupNr</code> has a superblock * and a group descriptor copy, otherwise false @@ -915,7 +915,7 @@ } /** - * + * */ protected FSFile createFile(FSEntry entry) throws IOException { Ext2Entry e = (Ext2Entry) entry; @@ -923,7 +923,7 @@ } /** - * + * */ protected FSDirectory createDirectory(FSEntry entry) throws IOException { Ext2Entry e = (Ext2Entry) entry; @@ -993,12 +993,12 @@ } public long getTotalSpace() { - // TODO implement me + // TODO implement me return 0; } public long getUsableSpace() { - // TODO implement me + // TODO implement me return 0; } } Modified: trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystemFormatter.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystemFormatter.java 2008-01-01 00:03:48 UTC (rev 3671) +++ trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystemFormatter.java 2008-01-01 00:06:53 UTC (rev 3672) @@ -29,17 +29,17 @@ /** * @author Andras Nagy */ -public class Ext2FileSystemFormatter implements Formatter<Ext2FileSystem> { +public class Ext2FileSystemFormatter extends Formatter<Ext2FileSystem> { + private BlockSize blockSize; - private int blockSize; - /** * * @param blockSizeKb size of blocks in KB */ - public Ext2FileSystemFormatter(int blockSizeKb) + public Ext2FileSystemFormatter(BlockSize blockSize) { - this.blockSize = (int) (blockSizeKb * BinaryPrefix.K.getMultiplier()); //Converted into KB + super(new Ext2FileSystemType()); + this.blockSize = blockSize; } /** Modified: trunk/fs/src/fs/org/jnode/fs/ext2/Superblock.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ext2/Superblock.java 2008-01-01 00:03:48 UTC (rev 3671) +++ trunk/fs/src/fs/org/jnode/fs/ext2/Superblock.java 2008-01-01 00:06:53 UTC (rev 3672) @@ -9,16 +9,16 @@ * by the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but + * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., + * 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; @@ -29,12 +29,12 @@ /** * Ext2fs superblock - * + * * @author Andras Nagy */ public class Superblock { public static final int SUPERBLOCK_LENGTH = 1024; - + //some constants for the fs creation private static final long BYTES_PER_INODE = 4096; //one inode for 4KBs of data private static final double RESERVED_BLOCKS_RATIO = 0.05; //5% reserved for the superuser @@ -42,40 +42,40 @@ private static final int MAX_MOUNT_COUNT = 256; //number of times to mount before check (check not yet implemented) private static final int CHECK_INTERVAL = 365*24*60*60; //check every year (check not yet implemented) private static final long JNODE = 42; //whatever - + private byte data[]; private boolean dirty; private Ext2FileSystem fs; private final Logger log = Logger.getLogger(getClass()); - public Superblock() { + public Superblock() { data = new byte[SUPERBLOCK_LENGTH]; - log.setLevel(Level.INFO); + log.setLevel(Level.INFO); } - + public void read(byte src[], Ext2FileSystem fs) throws FileSystemException { System.arraycopy(src, 0, data, 0, SUPERBLOCK_LENGTH); - + this.fs = fs; - + //check the magic :) if(getMagic() != 0xEF53) throw new FileSystemException("Not ext2 superblock ("+getMagic()+": bad magic)"); - + setDirty(false); } - - public void create(int blockSize, Ext2FileSystem fs) throws IOException { + + public void create(BlockSize blockSize, Ext2FileSystem fs) throws IOException { this.fs = fs; setRevLevel(Ext2Constants.EXT2_DYNAMIC_REV); setMinorRevLevel(0); setMagic(0xEF53); setCreatorOS(JNODE); - + //the number of inodes has to be <= than the number of blocks - long bytesPerInode = BYTES_PER_INODE>=blockSize ? BYTES_PER_INODE : blockSize; + long bytesPerInode = (BYTES_PER_INODE>=blockSize.getSize()) ? BYTES_PER_INODE : blockSize.getSize(); long size = fs.getApi().getLength(); - long blocks = size / blockSize; + long blocks = size / blockSize.getSize(); long inodes = size / bytesPerInode; setINodesCount(inodes); setBlocksCount(blocks); @@ -84,67 +84,67 @@ setDefResuid(0); setBlockSize(blockSize); //actually sets the S_LOG_BLOCK_SIZE setFragSize(blockSize); //set S_LOG_FRAG_SIZE - setFirstDataBlock(blockSize==1024 ? 1 : 0); + setFirstDataBlock(blockSize.getSize()==1024 ? 1 : 0); - //a block bitmap is 1 block long, so blockSize*8 blocks can be indexed by a bitmap + //a block bitmap is 1 block long, so blockSize*8 blocks can be indexed by a bitmap //and thus be in a group - long blocksPerGroup = blockSize << 3; + long blocksPerGroup = blockSize.getSize() << 3; setBlocksPerGroup(blocksPerGroup); setFragsPerGroup(blocksPerGroup); long groupCount = Ext2Utils.ceilDiv(blocks, blocksPerGroup); long inodesPerGroup = Ext2Utils.ceilDiv(inodes, groupCount); - setINodesPerGroup(inodesPerGroup); - + setINodesPerGroup(inodesPerGroup); + //calculate the number of blocks reserved for metadata //first, set the sparse_super option (it affects this value) if(CREATE_WITH_SPARSE_SUPER) setFeatureROCompat(getFeatureROCompat() | Ext2Constants.EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER); - long sbSize = 1; //superblock is 1 block fixed - long gdtSize = Ext2Utils.ceilDiv(groupCount*GroupDescriptor.GROUPDESCRIPTOR_LENGTH, blockSize); + long sbSize = 1; //superblock is 1 block fixed + long gdtSize = Ext2Utils.ceilDiv(groupCount*GroupDescriptor.GROUPDESCRIPTOR_LENGTH, blockSize.getSize()); long bbSize = 1; //block bitmap is 1 block fixed long ibSize = 1; //inode bitmap is 1 block fixed - long inodeTableSize = Ext2Utils.ceilDiv( inodesPerGroup*INode.INODE_LENGTH, blockSize); + long inodeTableSize = Ext2Utils.ceilDiv( inodesPerGroup*INode.INODE_LENGTH, blockSize.getSize()); int groupsWithMetadata = 0; for(int i=0; i<groupCount; i++) if(fs.groupHasDescriptors(i)) groupsWithMetadata++; - long metadataSize = (bbSize + ibSize + inodeTableSize) * groupCount + + long metadataSize = (bbSize + ibSize + inodeTableSize) * groupCount + (sbSize + gdtSize) * groupsWithMetadata; setFreeBlocksCount(blocks - metadataSize); setFirstInode(11); setFreeInodesCount(inodes - getFirstInode() + 1); - + setMTime(0); setWTime(0); setLastCheck(0); setCheckInterval(CHECK_INTERVAL); setMntCount(0); setMaxMntCount(MAX_MOUNT_COUNT); - + setState(Ext2Constants.EXT2_VALID_FS); setErrors(Ext2Constants.EXT2_ERRORS_DEFAULT); - + setINodeSize(INode.INODE_LENGTH); - + setBlockGroupNr(0); - + //set the options SPARSE_SUPER and FILETYPE setFeatureCompat(0); setFeatureROCompat( Ext2Constants.EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER ); setFeatureIncompat( Ext2Constants.EXT2_FEATURE_INCOMPAT_FILETYPE ); - + byte[] uuid = new byte[16]; for(int i=0; i<uuid.length; i++) uuid[i]=(byte)(Math.random()*255); setUUID(uuid); - + setPreallocBlocks(8); setPreallocDirBlocks(0); log.debug("Superblock.create(): getBlockSize(): "+getBlockSize()); } - + /** * Update the superblock copies on the disk */ @@ -152,7 +152,7 @@ if(isDirty()) { log.debug("Updating superblock copies"); byte[] oldData; - + //update the main copy if(getFirstDataBlock()==0) { oldData=fs.getBlock(0); @@ -161,10 +161,10 @@ System.arraycopy(data, 0, oldData, 1024, SUPERBLOCK_LENGTH); } else { oldData=fs.getBlock(getFirstDataBlock()); - System.arraycopy(data, 0, oldData, 0, SUPERBLOCK_LENGTH); + System.arraycopy(data, 0, oldData, 0, SUPERBLOCK_LENGTH); } fs.writeBlock(getFirstDataBlock(), oldData, true); - + //update the other copies for(int i=1; i<fs.getGroupCount(); i++) { //check if there is a superblock copy in the block group @@ -178,11 +178,11 @@ System.arraycopy(data, 0, oldData, 0, SUPERBLOCK_LENGTH); fs.writeBlock(blockNr, oldData, true); } - + setBlockGroupNr(0); setDirty(false); } - + } //this field is only written during format (so no synchronization issues here) @@ -193,7 +193,7 @@ Ext2Utils.set32(data, 0, count); setDirty(true); } - + //this field is only written during format (so no synchronization issues here) public long getBlocksCount() { return Ext2Utils.get32(data, 4); @@ -202,7 +202,7 @@ Ext2Utils.set32(data, 4, count); setDirty(true); } - + //this field is only written during format (so no synchronization issues here) public long getRBlocksCount() { return Ext2Utils.get32(data, 8); @@ -245,18 +245,19 @@ Ext2Utils.set32(data, 24, i); setDirty(true); } - + //this field is only written during format (so no synchronization issues here) public int getBlockSize() { return 1024 << getLogBlockSize(); } - public void setBlockSize(long size) { + public void setBlockSize(BlockSize size) { //setLogBlockSize( (long)(Math.log(size)/Math.log(2) - 10) ); //Math.log() is buggy - if(size==1024) setLogBlockSize(0); - if(size==2048) setLogBlockSize(1); - if(size==4096) setLogFragSize(2); - if(size==8192) setLogFragSize(3); + //TODO should we handle all these values for size or not ? from mke2fs man page, it seems NO. + if(size.getSize()==1024) setLogBlockSize(0); + if(size.getSize()==2048) setLogBlockSize(1); + if(size.getSize()==4096) setLogFragSize(2); + if(size.getSize()==8192) setLogFragSize(3); setDirty(true); } @@ -268,7 +269,7 @@ Ext2Utils.set32(data, 28, i); setDirty(true); } - + //this field is only written during format (so no synchronization issues here) public int getFragSize() { if(getLogFragSize()>0) @@ -276,17 +277,18 @@ else return 1024 >> -getLogFragSize(); } - public void setFragSize(long size) { + public void setFragSize(BlockSize size) { //setLogFragSize( (long)(Math.log(size)/Math.log(2)) - 10 ); //Math.log() is buggy - if(size==64) setLogFragSize(-4); - if(size==128) setLogFragSize(-3); - if(size==256) setLogBlockSize(-2); - if(size==512) setLogBlockSize(-1); - if(size==1024) setLogFragSize(0); - if(size==2048) setLogFragSize(1); - if(size==4096) setLogBlockSize(2); - if(size==8192) setLogBlockSize(3); + //TODO should we handle all these values for size or not ? from mke2fs man page, it seems NO. + if(size.getSize()==64) setLogFragSize(-4); + if(size.getSize()==128) setLogFragSize(-3); + if(size.getSize()==256) setLogBlockSize(-2); + if(size.getSize()==512) setLogBlockSize(-1); + if(size.getSize()==1024) setLogFragSize(0); + if(size.getSize()==2048) setLogFragSize(1); + if(size.getSize()==4096) setLogBlockSize(2); + if(size.getSize()==8192) setLogBlockSize(3); setDirty(true); } @@ -307,7 +309,7 @@ Ext2Utils.set32(data, 36, i); setDirty(true); } - + //this field is only written during format (so no synchronization issues here) public long getINodesPerGroup() { return Ext2Utils.get32(data, 40); @@ -333,7 +335,7 @@ Ext2Utils.set32(data, 48, time); setDirty(true); } - + //this field is only written during mounting (so no synchronization issues here) public int getMntCount() { return Ext2Utils.get16(data, 52); @@ -342,7 +344,7 @@ Ext2Utils.set16(data, 52, i); setDirty(true); } - + //this field is only written during format (so no synchronization issues here) public int getMaxMntCount() { return Ext2Utils.get16(data, 54); @@ -360,7 +362,7 @@ Ext2Utils.set16(data, 56, i); setDirty(true); } - + public synchronized int getState() { return Ext2Utils.get16(data, 58); } @@ -385,8 +387,8 @@ public void setMinorRevLevel(int i) { Ext2Utils.set16(data, 62, i); setDirty(true); - } - + } + //this field is only written during filesystem check (so no synchronization issues here) public long getLastCheck() { return Ext2Utils.get32(data, 64); @@ -395,7 +397,7 @@ Ext2Utils.set32(data, 64, i); setDirty(true); } - + //this field is only written during format (so no synchronization issues here) public long getCheckInterval() { return Ext2Utils.get32(data, 68); @@ -404,7 +406,7 @@ Ext2Utils.set32(data, 68, i); setDirty(true); } - + //this field is only written during format (so no synchronization issues here) public long getCreatorOS() { return Ext2Utils.get32(data, 72); @@ -413,7 +415,7 @@ Ext2Utils.set32(data, 72, i); setDirty(true); } - + //this field is only written during format (so no synchronization issues here) public long getRevLevel() { return Ext2Utils.get32(data, 76); @@ -422,7 +424,7 @@ Ext2Utils.set32(data, 76, i); setDirty(true); } - + //this field is only written during format (so no synchronization issues here) public int getDefResuid() { return Ext2Utils.get16(data, 80); @@ -431,7 +433,7 @@ Ext2Utils.set16(data, 80, i); setDirty(true); } - + //this field is only written during format (so no synchronization issues here) public int getDefResgid() { return Ext2Utils.get16(data, 82); @@ -445,19 +447,19 @@ public long getFirstInode() { if(getRevLevel()==Ext2Constants.EXT2_DYNAMIC_REV) return Ext2Utils.get32(data, 84); - else + else return 11; } public void setFirstInode(long i) { Ext2Utils.set32(data, 84, i); setDirty(true); } - + //this field is only written during format (so no synchronization issues here) public long getINodeSize() { if(getRevLevel()==Ext2Constants.EXT2_DYNAMIC_REV) return Ext2Utils.get16(data, 88); - else + else return INode.INODE_LENGTH; } public void setINodeSize(int i) { @@ -469,19 +471,19 @@ public synchronized long getBlockGroupNr() { if(getRevLevel()==Ext2Constants.EXT2_DYNAMIC_REV) return Ext2Utils.get16(data, 90); - else + else return 0; } public synchronized void setBlockGroupNr(int i) { Ext2Utils.set16(data, 90, i); setDirty(true); } - + //this field is only written during format (so no synchronization issues here) public long getFeatureCompat() { if(getRevLevel()==Ext2Constants.EXT2_DYNAMIC_REV) return Ext2Utils.get32(data, 92); - else + else return 0; } public void setFeatureCompat(long i) { @@ -493,19 +495,19 @@ public long getFeatureIncompat() { if(getRevLevel()==Ext2Constants.EXT2_DYNAMIC_REV) return Ext2Utils.get32(data, 96); - else + else return 0; } public void setFeatureIncompat(long i) { Ext2Utils.set32(data, 96, i); setDirty(true); } - + //this field is only written during format (so no synchronization issues here) public long getFeatureROCompat() { if(getRevLevel()==Ext2Constants.EXT2_DYNAMIC_REV) return Ext2Utils.get32(data, 100); - else + else return 0; } public void setFeatureROCompat(long i) { @@ -515,14 +517,14 @@ //this field is only written during format (so no synchronization issues here) public byte[] getUUID() { - byte[] result=new byte[16]; + byte[] result=new byte[16]; if(getRevLevel()==Ext2Constants.EXT2_DYNAMIC_REV) System.arraycopy(data, 104, result, 0, 16); return result; } public void setUUID(byte[] uuid) { if(getRevLevel()==Ext2Constants.EXT2_DYNAMIC_REV) - System.arraycopy(uuid, 0, data, 104, 16); + System.arraycopy(uuid, 0, data, 104, 16); setDirty(true); } @@ -536,7 +538,7 @@ result.append(c); else break; - } + } return result.toString(); } @@ -549,7 +551,7 @@ result.append(c); else break; - } + } return result.toString(); } @@ -557,10 +559,10 @@ public long getAlgoBitmap() { if(getRevLevel()==Ext2Constants.EXT2_DYNAMIC_REV) return Ext2Utils.get32(data, 200); - else + else return 11; } - + //this field is only written during format (so no synchronization issues here) public int getPreallocBlocks() { return Ext2Utils.get8(data, 204); @@ -580,11 +582,11 @@ } public byte[] getJournalUUID() { - byte[] result=new byte[16]; + byte[] result=new byte[16]; System.arraycopy(data, 208, result, 0, 16); return result; } - + public long getJournalINum() { return Ext2Utils.get32(data, 224); } Modified: trunk/fs/src/fs/org/jnode/fs/ext2/command/FormatExt2Command.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ext2/command/FormatExt2Command.java 2008-01-01 00:03:48 UTC (rev 3671) +++ trunk/fs/src/fs/org/jnode/fs/ext2/command/FormatExt2Command.java 2008-01-01 00:06:53 UTC (rev 3672) @@ -22,25 +22,29 @@ package org.jnode.fs.ext2.command; import org.jnode.fs.command.AbstractFormatCommand; +import org.jnode.fs.ext2.BlockSize; import org.jnode.fs.ext2.Ext2FileSystem; import org.jnode.fs.ext2.Ext2FileSystemFormatter; +import org.jnode.fs.fat.FatType; import org.jnode.shell.CommandLine; import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; import org.jnode.shell.help.ParsedArguments; import org.jnode.shell.help.Syntax; import org.jnode.shell.help.SyntaxErrorException; +import org.jnode.shell.help.argument.EnumOptionArgument; import org.jnode.shell.help.argument.OptionArgument; /** * @author gbin */ +@SuppressWarnings("unchecked") public class FormatExt2Command extends AbstractFormatCommand<Ext2FileSystem> { - static final OptionArgument BS_VAL = new OptionArgument("blocksize", - "block size for ext2 filesystem", new OptionArgument.Option[] { - new OptionArgument.Option("1", "1Kb"), - new OptionArgument.Option("2", "2Kb"), - new OptionArgument.Option("4", "4Kb"), }); + static final EnumOptionArgument<BlockSize> BS_VAL = new EnumOptionArgument<BlockSize>("blocksize", + "block size for ext2 filesystem", + new EnumOptionArgument.EnumOption<BlockSize>("1", "1Kb", BlockSize._1Kb), + new EnumOptionArgument.EnumOption<BlockSize>("2", "2Kb", BlockSize._2Kb), + new EnumOptionArgument.EnumOption<BlockSize>("4", "4Kb", BlockSize._4Kb)); static final Parameter PARAM_BS_VAL = new Parameter(BS_VAL, Parameter.OPTIONAL); @@ -56,13 +60,7 @@ @Override protected Ext2FileSystemFormatter getFormatter(ParsedArguments cmdLine) { - int bsize; - try { - bsize = Integer.parseInt(BS_VAL.getValue(cmdLine)); - } catch (NumberFormatException nfe) { - bsize = 4; - } - + BlockSize bsize = BS_VAL.getEnum(cmdLine, BlockSize.class); return new Ext2FileSystemFormatter(bsize); } Modified: trunk/fs/src/fs/org/jnode/fs/fat/Fat.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/fat/Fat.java 2008-01-01 00:03:48 UTC (rev 3671) +++ trunk/fs/src/fs/org/jnode/fs/fat/Fat.java 2008-01-01 00:06:53 UTC (rev 3672) @@ -9,16 +9,16 @@ * by the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but + * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., + * 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.fat; import java.io.IOException; @@ -31,38 +31,33 @@ /** * <description> - * + * * @author epr */ public class Fat { - public static final int FAT12 = 12; - public static final int FAT16 = 16; - public static final int FAT32 = 32; - private long[] entries; - /** The type of FAT, legal values are: 12, 16, 32 */ - private int bitSize; + /** The type of FAT */ + private FatType fatType; /** The number of sectors this fat takes */ private int nrSectors; /** The number of bytes/sector */ private int sectorSize; - private final long eofMarker; private boolean dirty; - + /** entry index for find next free entry*/ private int lastFreeCluster = 2; /** * Create a new instance - * + * * @param bitSize * @param nrSectors * @param sectorSize */ - public Fat(int bitSize, int mediumDescriptor, int nrSectors, int sectorSize) { - this.bitSize = bitSize; + public Fat(FatType bitSize, int mediumDescriptor, int nrSectors, int sectorSize) { + this.fatType = bitSize; this.nrSectors = nrSectors; this.sectorSize = sectorSize; this.dirty = false; @@ -70,19 +65,16 @@ case FAT12 : { entries = new long[(int) ((nrSectors * sectorSize) / 1.5)]; - eofMarker = 0xFFF; } break; case FAT16 : { entries = new long[(nrSectors * sectorSize) / 2]; - eofMarker = 0xFFFF; } break; case FAT32 : { entries = new long[(nrSectors * sectorSize) / 4]; - eofMarker = 0xFFFFFFFF; } break; default : @@ -93,15 +85,15 @@ /** * Read the contents of this FAT from the given device at the given offset. - * + * * @param device */ public synchronized void read(BlockDeviceAPI device, long offset) throws IOException { byte[] data = new byte[nrSectors * sectorSize]; device.read(offset, ByteBuffer.wrap(data)); for (int i = 0; i < entries.length; i++) { - switch (bitSize) { - case 12 : + switch (fatType) { + case FAT12 : { int idx = (int) (i * 1.5); int b1 = data[idx] & 0xFF; @@ -119,7 +111,7 @@ // Long.toHexString(entries[i])); } break; - case 16 : + case FAT16 : { int idx = i * 2; int b1 = data[idx] & 0xFF; @@ -127,7 +119,7 @@ entries[i] = (b2 << 8) | b1; } break; - case 32 : + case FAT32 : { int idx = i * 4; long b1 = data[idx] & 0xFF; @@ -144,15 +136,15 @@ /** * Write the contents of this FAT to the given device at the given offset. - * + * * @param device */ public synchronized void write(BlockDeviceAPI device, long offset) throws IOException { byte[] data = new byte[nrSectors * sectorSize]; for (int i = 0; i < entries.length; i++) { long v = entries[i]; - switch (bitSize) { - case 12 : + switch (fatType) { + case FAT12 : { int idx = (int) (i * 1.5); if ((i % 2) == 0) { @@ -164,14 +156,14 @@ } } break; - case 16 : + case FAT16 : { int idx = i << 1; data[idx] = (byte) (v & 0xFF); data[idx + 1] = (byte) ((v >> 8) & 0xFF); } break; - case 32 : + case FAT32 : { int idx = i << 2; data[idx] = (byte) (v & 0xFF); @@ -189,7 +181,7 @@ /** * Gets the medium descriptor byte - * + * * @return int */ public int getMediumDescriptor() { @@ -205,7 +197,7 @@ /** * Gets the number of entries of this fat - * + * * @return int */ public int getNrEntries() { @@ -214,7 +206,7 @@ /** * Gets the entry at a given offset - * + * * @param index * @return long */ @@ -245,7 +237,7 @@ /** * Gets the cluster after the given cluster - * + * * @param cluster * @return long The next cluster number or -1 which means eof. */ @@ -261,42 +253,42 @@ /** * Allocate a cluster for a new file - * + * * @return long */ public synchronized long allocNew() throws IOException { int i; int entryIndex = -1; - + for (i = lastFreeCluster; i < entries.length; i++) { if (isFreeCluster(entries[i])) { entryIndex=i; break; - } + } } - if(entryIndex<0){ + if(entryIndex<0){ for(i = 2; i < lastFreeCluster;i++){ if (isFreeCluster(entries[i])) { entryIndex=i; break; - } + } } } if(entryIndex < 0){ throw new FileSystemFullException("FAT Full (" + entries.length + ", " + i + ")"); } - entries[entryIndex] = eofMarker; + entries[entryIndex] = fatType.getEofMarker(); lastFreeCluster = entryIndex+1; this.dirty = true; return entryIndex; - + } /** * Allocate a series of clusters for a new file - * + * * @return long */ public synchronized long[] allocNew(int nrClusters) throws IOException { @@ -313,7 +305,7 @@ /** * Allocate a cluster to append to a new file - * + * * @return long */ public synchronized long allocAppend(long cluster) throws IOException { @@ -332,7 +324,7 @@ public synchronized void setEof(long cluster) { testCluster(cluster); - entries[(int)cluster] = eofMarker; + entries[(int)cluster] = fatType.getEofMarker(); } public synchronized void setFree(long cluster) { @@ -343,7 +335,7 @@ /** * Print the contents of this FAT to the given writer. Used for debugging * purposes. - * + * * @param out */ public void printTo(PrintWriter out) { @@ -381,7 +373,7 @@ /** * Is the given entry a free cluster? - * + * * @param entry * @return boolean */ @@ -391,40 +383,22 @@ /** * Is the given entry a reserved cluster? - * + * * @param entry * @return boolean */ protected boolean isReservedCluster(long entry) { - switch (bitSize) { - case 12 : - return ((entry >= 0xFF0) && (entry <= 0xFF6)); - case 16 : - return ((entry >= 0xFFF0) && (entry <= 0xFFF6)); - case 32 : - return ((entry >= 0xFFFFFFF0) && (entry <= 0xFFFFFFF6)); - default : - throw new IllegalArgumentException("Invalid bitSize " + bitSize); - } + return fatType.isReservedCluster(entry); } /** * Is the given entry an EOF marker - * + * * @param entry * @return boolean */ protected boolean isEofCluster(long entry) { - switch (bitSize) { - case 12 : - return (entry >=0xFF8); - case 16 : - return ((entry >= 0xFFF8)); - case 32 : - return (entry >= 0xFFFFFFF8); - default : - throw new IllegalArgumentException("Invalid bitSize " + bitSize); - } + return fatType.isEofCluster(entry); } protected void testCluster(long cluster) throws IllegalArgumentException { @@ -435,7 +409,7 @@ /** * Returns the dirty. - * + * * @return boolean */ public boolean isDirty() { Modified: trunk/fs/src/fs/org/jnode/fs/fat/FatFileSystem.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/fat/FatFileSystem.java 2008-01-01 00:03:48 UTC (rev 3671) +++ trunk/fs/src/fs/org/jnode/fs/fat/FatFileSystem.java 2008-01-01 00:06:53 UTC (rev 3672) @@ -9,16 +9,16 @@ * by the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but + * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., + * 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.fat; import java.io.IOException; @@ -48,7 +48,7 @@ */ public FatFileSystem(Device device, boolean readOnly) throws FileSystemException { super(device, readOnly); // false = read/write mode - + try { bs = new BootSector(512); bs.read(getApi()); @@ -59,12 +59,12 @@ Fat[] fats = new Fat[bs.getNrFats()]; rootDir = new FatLfnDirectory(this, bs.getNrRootDirEntries()); - int bitSize; + FatType bitSize; if (bs.getMediumDescriptor() == 0xf8) { - bitSize = 16; + bitSize = FatType.FAT16; } else { - bitSize = 12; + bitSize = FatType.FAT12; } for (int i = 0; i < fats.length; i++) { @@ -92,7 +92,7 @@ /** * Flush all changed structures to the device. - * + * * @throws IOException */ public void flush() throws IOException { @@ -129,7 +129,7 @@ /** * Gets the file for the given entry. - * + * * @param entry */ public synchronized FatFile getFile(FatDirEntry entry) { @@ -148,7 +148,7 @@ /** * Returns the fat. - * + * * @return Fat */ public Fat getFat() { @@ -157,7 +157,7 @@ /** * Returns the bootsector. - * + * * @return BootSector */ public BootSector getBootSector() { @@ -165,7 +165,7 @@ } /** * Returns the rootDir. - * + * * @return RootDirectory */ public FatDirectory getRootDir() { @@ -173,26 +173,26 @@ } /** - * + * */ protected FSFile createFile(FSEntry entry) throws IOException { - + // TODO Auto-generated method stub return null; } /** - * + * */ - protected FSDirectory createDirectory(FSEntry entry) throws IOException { + protected FSDirectory createDirectory(FSEntry entry) throws IOException { // TODO Auto-generated method stub return null; } /** - * + * */ - protected FSEntry createRootEntry() throws IOException { + protected FSEntry createRootEntry() throws IOException { // TODO Auto-generated method stub return null; } @@ -204,12 +204,12 @@ } public long getTotalSpace() { - // TODO implement me + // TODO implement me return 0; } public long getUsableSpace() { - // TODO implement me + // TODO implement me return 0; } } Modified: trunk/fs/src/fs/org/jnode/fs/fat/FatFileSystemFormatter.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/fat/FatFileSystemFormatter.java 2008-01-01 00:03:48 UTC (rev 3671) +++ trunk/fs/src/fs/org/jnode/fs/fat/FatFileSystemFormatter.java 2008-01-01 00:06:53 UTC (rev 3672) @@ -31,6 +31,7 @@ import org.jnode.fs.FileSystemException; import org.jnode.fs.FileSystemType; import org.jnode.fs.Formatter; +import org.jnode.fs.ext2.Ext2FileSystemType; import org.jnode.partitions.PartitionTableEntry; import org.jnode.partitions.ibm.IBMPartitionTableEntry; import org.jnode.partitions.ibm.IBMPartitionTypes; @@ -40,14 +41,15 @@ /** * @author epr */ -public class FatFileSystemFormatter implements Formatter<FatFileSystem> { +public class FatFileSystemFormatter extends Formatter<FatFileSystem> { private static final int NB_HEADS = 255; private static final int SECTOR_PER_TRACK = 63; - private int fatSize; + private FatType fatSize; - public FatFileSystemFormatter(int fatSize) + public FatFileSystemFormatter(FatType fatSize) { + super(new FatFileSystemType()); this.fatSize = fatSize; } Modified: trunk/fs/src/fs/org/jnode/fs/fat/FatFormatter.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/fat/FatFormatter.java 2008-01-01 00:03:48 UTC (rev 3671) +++ trunk/fs/src/fs/org/jnode/fs/fat/FatFormatter.java 2008-01-01 00:06:53 UTC (rev 3672) @@ -9,16 +9,16 @@ * by the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but + * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., + * 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.fat; import java.io.IOException; @@ -28,7 +28,7 @@ /** * <description> - * + * * @author epr */ public class FatFormatter { @@ -43,7 +43,7 @@ private FatDirectory rootDir; public static FatFormatter fat144FloppyFormatter(int reservedSectors, BootSector bs) { - return new FatFormatter(FLOPPY_DESC, 512, 1, 2880, 18, 2, Fat.FAT12, 2, 0, reservedSectors, bs); + return new FatFormatter(FLOPPY_DESC, 512, 1, 2880, 18, 2, FatType.FAT32, 2, 0, reservedSectors, bs); } public static FatFormatter HDFormatter( @@ -51,7 +51,7 @@ int nbTotalSectors, int sectorsPerTrack, int nbHeads, - int fatSize, + FatType fatSize, int hiddenSectors, int reservedSectors, BootSector bs) { @@ -76,24 +76,13 @@ int nbTotalSectors, int sectorsPerTrack, int nbHeads, - int fatSize, + FatType fatSize, int nbFats, int hiddenSectors, int reservedSectors, BootSector bs) { this.bs = bs; - float fatEntrySize; - switch (fatSize) { - case Fat.FAT12 : - fatEntrySize = 1.5f; - break; - case Fat.FAT16 : - fatEntrySize = 2.0f; - break; - default : - fatEntrySize = 4.0f; - break; - } + final float fatEntrySize = fatSize.getEntrySize(); bs.setMediumDescriptor(mediumDescriptor); bs.setOemName("JNode1.0"); @@ -176,7 +165,7 @@ /** * Set the label - * + * * @param label */ public void setLabel(String label) throws IOException { @@ -185,7 +174,7 @@ /** * Format the given device, according to my settings - * + * * @param api * @throws IOException */ @@ -204,7 +193,7 @@ /** * Returns the bs. - * + * * @return BootSector */ public BootSector getBootSector() { Added: trunk/fs/src/fs/org/jnode/fs/fat/FatType.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/fat/FatType.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/fat/FatType.java 2008-01-01 00:06:53 UTC (rev 3672) @@ -0,0 +1,38 @@ +package org.jnode.fs.fat; + +public enum FatType { + FAT12(0xFFF, 1.5f), + FAT16(0xFFFF, 2.0f), + FAT32(0xFFFFFFFF, 4.0f); + + private final long minReservedEntry; + private final long maxReservedEntry; + private final long eofCluster; + private final long eofMarker; + private final float entrySize; + + private FatType(long bitMask, float entrySize) + { + this.minReservedEntry = (0xFFFFFFF0 & bitMask); + this.maxReservedEntry = (0xFFFFFFF6 & bitMask); + this.eofCluster = (0xFFFFFFF8 & bitMask); + this.eofMarker = (0xFFFFFFFF & bitMask); + this.entrySize = entrySize; + } + + final public boolean isReservedCluster(long entry) { + return ((entry >= minReservedEntry) && (entry <= maxReservedEntry)); + } + + final public boolean isEofCluster(long entry) { + return (entry >= eofCluster); + } + + final public long getEofMarker() { + return eofMarker; + } + + final public float getEntrySize() { + return entrySize; + } +} Modified: trunk/fs/src/fs/org/jnode/fs/fat/GrubFatFormatter.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/fat/GrubFatFormatter.java 2008-01-01 00:03:48 UTC (rev 3671) +++ trunk/fs/src/fs/org/jnode/fs/fat/GrubFatFormatter.java 2008-01-01 00:06:53 UTC (rev 3672) @@ -9,16 +9,16 @@ * by the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but + * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., + * 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.fat; import java.io.IOException; @@ -54,7 +54,7 @@ int bps, int spc, Geometry geom, - int fatSize, + FatType fatSize, int bootSectorOffset, String stage1ResourceName, String stage2ResourceName) { @@ -81,7 +81,7 @@ /** * Constructor for GrubFatFormatter. - * + * * @param bootSectorOffset * @param stage1ResourceName * @param stage2ResourceName @@ -182,7 +182,7 @@ /** * Sets the configFile. - * + * * @param configFile * The configFile to set */ @@ -203,7 +203,7 @@ /** * Sets the installPartition. - * + * * @param installPartition * The installPartition to set */ Modified: trunk/fs/src/fs/org/jnode/fs/fat/command/FormatFatCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/fat/command/FormatFatCommand.java 2008-01-01 00:03:48 UTC (rev 3671) +++ trunk/fs/src/fs/org/jnode/fs/fat/command/FormatFatCommand.java 2008-01-01 00:06:53 UTC (rev 3672) @@ -25,6 +25,7 @@ import org.jnode.fs.fat.Fat; import org.jnode.fs.fat.FatFileSystem; import org.jnode.fs.fat.FatFileSystemFormatter; +import org.jnode.fs.fat.FatType; import org.jnode.shell.CommandLine; import org.jnode.shell.help.Help; import org.jnode.shell.help.Parameter; @@ -60,9 +61,9 @@ FatFileSystemFormatter formatter = null; if (FSType == "fat16") { - formatter = new FatFileSystemFormatter(Fat.FAT16); + formatter = new FatFileSystemFormatter(FatType.FAT16); } else if (FSType == "fat12") { - formatter = new FatFileSystemFormatter(Fat.FAT32); + formatter = new FatFileSystemFormatter(FatType.FAT32); } else throw new IllegalArgumentException( "invalid fat type"); Modified: trunk/fs/src/fs/org/jnode/fs/initrd/InitRamdisk.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/initrd/InitRamdisk.java 2008-01-01 00:03:48 UTC (rev 3671) +++ trunk/fs/src/fs/org/jnode/fs/initrd/InitRamdisk.java 2008-01-01 00:06:53 UTC (rev 3672) @@ -39,6 +39,7 @@ import org.jnode.fs.fat.Fat; import org.jnode.fs.fat.FatFileSystemFormatter; import org.jnode.fs.fat.FatFileSystemType; +import org.jnode.fs.fat.FatType; import org.jnode.fs.service.FileSystemService; import org.jnode.naming.InitialNaming; import org.jnode.plugin.Plugin; @@ -76,7 +77,7 @@ log.info("Format initrd ramdisk"); - final FatFileSystemFormatter formatter = new FatFileSystemFormatter(Fat.FAT16); + final FatFileSystemFormatter formatter = new FatFileSystemFormatter(FatType.FAT16); final FileSystem fs = formatter.format(dev); try { fs.getRootEntry().getDirectory().addDirectory("tmp"); Added: trunk/fs/src/fs/org/jnode/fs/jfat/ClusterSize.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/jfat/ClusterSize.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/jfat/ClusterSize.java 2008-01-01 00:06:53 UTC (rev 3672) @@ -0,0 +1,26 @@ +package org.jnode.fs.jfat; + +import org.jnode.util.BinaryPrefix; + + +public enum ClusterSize { + _1Kb(1), + _2Kb(2), + _4Kb(4), + _8Kb(8), + _16Kb(16), + _32Kb(32), + _64Kb(64); + + private final int size; + + private ClusterSize(int sizeInKb) + { + size = (int) (sizeInKb * BinaryPrefix.K.getMultiplier()); //Converted into KB + } + + final public int getSize() + { + return size; + } +} Modified: trunk/fs/src/fs/org/jnode/fs/jfat/FatFileSystemFormatter.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/jfat/FatFileSystemFormatter.java 2008-01-01 00:03:48 UTC (rev 3671) +++ trunk/fs/src/fs/org/jnode/fs/jfat/FatFileSystemFormatter.java 2008-01-01 00:06:53 UTC (rev 3672) @@ -28,6 +28,7 @@ import org.jnode.driver.Device; import org.jnode.driver.block.BlockDeviceAPI; import org.jnode.driver.block.FSBlockDeviceAPI; +import org.jnode.driver.bus.ide.IDEConstants; import org.jnode.fs.FileSystem; import org.jnode.fs.FileSystemException; import org.jnode.fs.Formatter; @@ -43,15 +44,16 @@ * @author gvt * @author Tango */ -public class FatFileSystemFormatter implements Formatter<FatFileSystem> { +public class FatFileSystemFormatter extends Formatter<FatFileSystem> { private static final Logger log = Logger.getLogger ( FatFileSystemFormatter.class ); - private int clusterSize; + private ClusterSize clusterSize; - public FatFileSystemFormatter(int clusterSizeKb) + public FatFileSystemFormatter(ClusterSize clusterSize) { - this.clusterSize = (int) (clusterSizeKb * BinaryPrefix.K.getMultiplier()); //Converted into KB + super(new FatFileSystemType()); + this.clusterSize = clusterSize; } public FatFileSystem format ( Device device) @@ -64,8 +66,8 @@ FSBlockDeviceAPI api = (FSBlockDeviceAPI)device.getAPI(BlockDeviceAPI.class); int sectorSize = api.getSectorSize(); - if(sectorSize!=512){ - log.error("This mkjfat1.0 support only the Hard Disk.Sector Size must 512 bytes.\n"); + if(sectorSize != IDEConstants.SECTOR_SIZE){ + log.error("This mkjfat1.0 support only the Hard Disk.Sector Size must "+IDEConstants.SECTOR_SIZE+" bytes.\n"); } Modified: trunk/fs/src/fs/org/jnode/fs/jfat/FatFormatter.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/jfat/FatFormatter.java 2008-01-01 00:03:48 UTC (rev 3671) +++ trunk/fs/src/fs/org/jnode/fs/jfat/FatFormatter.java 2008-01-01 00:06:53 UTC (rev 3672) @@ -10,13 +10,13 @@ * by the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but + * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., + * along with this library; If not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ @@ -31,7 +31,7 @@ import static java.lang.Integer.toHexString; /** - * + * * @author tango * <p> * <ul>According to the FAT32 Documents.</ul> @@ -49,7 +49,7 @@ * <li>Reserved sectors upto the FAT at sector 32</li> * */ -public class FatFormatter { +public class FatFormatter { private static final Logger log = Logger.getLogger ( FatFormatter.class ); @@ -58,7 +58,7 @@ /** The Device Identifier for Hard Disk Device*/ public static final int HD_DESC = 0xf8; /** The Device Identifier for RAM Disk Device */ - public static final int RAMDISK_DESC = 0xfa; + public static final int RAMDISK_DESC = 0xfa; /** The Size of Fat.*/ private int FatSize; /** The Number of the Fat in system.*/ @@ -74,12 +74,12 @@ /** The volume label.*/ private static final String VOL_LABEL="NO NAME "; /** The FAT version label.*/ - private static final String FAT_LABEL="FAT32 "; + private static final String FAT_LABEL="FAT32 "; /** The Identifier of the Boot Sector */ public final byte[] BS_Identifier={(byte)0x55,(byte)0xAA}; /** The First 3 Bytes of the BootSector */ - public final byte[] BS_jmpBoot={(byte)0xEB,(byte)0x5A,(byte)0x90}; - /** This lead signature is used to validate that this is in fact an FSInfo sector.*/ + public final byte[] BS_jmpBoot={(byte)0xEB,(byte)0x5A,(byte)0x90}; + /** This lead signature is used to validate that this is in fact an FSInfo sector.*/ private final int FSI_LeadSig =0x41615252; /** The signature that is more localized in the sector to the location of the fields that are used.*/ private final int FSI_StrucSig =0x61417272; @@ -88,7 +88,7 @@ /** This is a hint for the FAT driver. It indicates the cluster number at which the driver should start looking for free clusters.*/ private final int FSI_Nxt_Free =3;//A confusion here but OK now for setting the Info at 3rd sec /** This trail signature is used to validate that this is in fact an FSInfo sector*/ - private final int FSI_TrailSig =0xaa550000; + private final int FSI_TrailSig =0xaa550000; /** The media ID at the reserved cluster one.*/ private final int ReservedSector_0=0x0ffffff8; /** The End Of Chain ID at the reserved sector second.*/ @@ -97,62 +97,62 @@ private final int ReservedSector_2=0x0fffffff; /** The array for the reserved sector.*/ private byte[] reservedSector; - + /** * The Hard Disk's formatting logic implementation by JFAT. * This Version only support to the Hard Disks. - * - * @throws IOException - */ - public static FatFormatter HDDFormatter(int bps, + * + * @throws IOException + */ + public static FatFormatter HDDFormatter(int sectorSize, int nbTotalSectors, - int fatSize, + ClusterSize clusterSize, int hiddenSectors, BlockDeviceAPI api - ) throws IOException{ - + ) throws IOException{ + return new FatFormatter( HD_DESC, - bps, + sectorSize, nbTotalSectors, SECTOR_PER_TRACK, NB_HEADS, - fatSize, - hiddenSectors, + clusterSize, + hiddenSectors, api ); - } - + } + /** * The Constructor for the HDD devices in the JNode system. - * @throws IOException + * @throws IOException * */ public FatFormatter( int mediumDescriptor, - int bps, + int sectorSize, int nbTotalSectors, int sectorsPerTrack, int nbHeads, - int ClusterSize, + ClusterSize ClusterSize, int hiddenSectors, BlockDeviceAPI api ) throws IOException{ - - FatFsInfo fsInfo=new FatFsInfo(bps); - BootSector bs=new BootSector(bps); - api.flush(); - int DiskSize=getDiskSize(nbTotalSectors, bps); - int SectorPerCluster=get_spc(ClusterSize,bps); + + FatFsInfo fsInfo=new FatFsInfo(sectorSize); + BootSector bs=new BootSector(sectorSize); + api.flush(); + int DiskSize=getDiskSize(nbTotalSectors, sectorSize); + int SectorPerCluster=get_spc(ClusterSize,s... [truncated message content] |