From: <ga...@us...> - 2012-08-10 06:53:39
|
Revision: 5915 http://jnode.svn.sourceforge.net/jnode/?rev=5915&view=rev Author: galatnm Date: 2012-08-10 06:53:31 +0000 (Fri, 10 Aug 2012) Log Message: ----------- FS improvments Modified Paths: -------------- trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystemType.java trunk/fs/src/fs/org/jnode/fs/fat/Fat.java trunk/fs/src/fs/org/jnode/fs/fat/FatDirEntry.java trunk/fs/src/fs/org/jnode/fs/fat/FatFileSystemType.java trunk/fs/src/fs/org/jnode/fs/fat/LfnEntry.java trunk/fs/src/fs/org/jnode/fs/ftpfs/FTPFSEntry.java trunk/fs/src/fs/org/jnode/fs/iso9660/ISO9660Entry.java trunk/fs/src/fs/org/jnode/fs/jfat/FatEntry.java trunk/fs/src/fs/org/jnode/fs/jfat/FatFileSystemType.java trunk/fs/src/fs/org/jnode/fs/ntfs/IndexAllocationAttribute.java trunk/fs/src/fs/org/jnode/fs/ntfs/IndexEntry.java trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSEntry.java trunk/fs/src/fs/org/jnode/partitions/ibm/IBMPartitionTableEntry.java trunk/fs/src/fs/org/jnode/partitions/ibm/IBMPartitionTableType.java Added Paths: ----------- trunk/fs/src/fs/org/jnode/fs/FSEntryCreated.java trunk/fs/src/fs/org/jnode/fs/FSEntryLastAccessed.java trunk/fs/src/fs/org/jnode/fs/FSEntryLastChanged.java Added: trunk/fs/src/fs/org/jnode/fs/FSEntryCreated.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/FSEntryCreated.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/FSEntryCreated.java 2012-08-10 06:53:31 UTC (rev 5915) @@ -0,0 +1,10 @@ +package org.jnode.fs; + +import java.io.IOException; + +/** + * Interface to stack on to declare implementation of a {@code getCreated()} method, until JNode adds it to {@link FSEntry}. + */ +public interface FSEntryCreated { + public long getCreated() throws IOException; +} Added: trunk/fs/src/fs/org/jnode/fs/FSEntryLastAccessed.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/FSEntryLastAccessed.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/FSEntryLastAccessed.java 2012-08-10 06:53:31 UTC (rev 5915) @@ -0,0 +1,10 @@ +package org.jnode.fs; + +import java.io.IOException; + +/** + * Interface to stack on to declare implementation of a {@code getLastAccessed()} method, until JNode adds it to {@link FSEntry}. + */ +public interface FSEntryLastAccessed { + public long getLastAccessed() throws IOException; +} Added: trunk/fs/src/fs/org/jnode/fs/FSEntryLastChanged.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/FSEntryLastChanged.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/FSEntryLastChanged.java 2012-08-10 06:53:31 UTC (rev 5915) @@ -0,0 +1,10 @@ +package org.jnode.fs; + +import java.io.IOException; + +/** + * Interface to stack on to declare implementation of a {@code getLastChanged()} method, until JNode adds it to {@link FSEntry}. + */ +public interface FSEntryLastChanged { + public long getLastChanged() throws IOException; +} Modified: trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystemType.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystemType.java 2012-08-10 06:44:27 UTC (rev 5914) +++ trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystemType.java 2012-08-10 06:53:31 UTC (rev 5915) @@ -22,14 +22,11 @@ import java.io.IOException; import java.nio.ByteBuffer; - import org.jnode.driver.Device; import org.jnode.driver.block.FSBlockDeviceAPI; import org.jnode.fs.BlockDeviceFileSystemType; import org.jnode.fs.FileSystemException; import org.jnode.partitions.PartitionTableEntry; -import org.jnode.partitions.ibm.IBMPartitionTableEntry; -import org.jnode.partitions.ibm.IBMPartitionTypes; /** * @author Andras Nagy @@ -57,6 +54,7 @@ * @see org.jnode.fs.BlockDeviceFileSystemType#supports(PartitionTableEntry, byte[], FSBlockDeviceAPI) */ public boolean supports(PartitionTableEntry pte, byte[] firstSector, FSBlockDeviceAPI devApi) { +/* if (pte != null) { if (pte instanceof IBMPartitionTableEntry) { if (((IBMPartitionTableEntry) pte).getSystemIndicator() != IBMPartitionTypes.PARTTYPE_LINUXNATIVE) { @@ -64,14 +62,19 @@ } } } +*/ //need to check the magic ByteBuffer magic = ByteBuffer.allocate(2); + ByteBuffer revLevel = ByteBuffer.allocate(4); try { devApi.read(1024 + 56, magic); + devApi.read(1024 + 78, revLevel); } catch (IOException e) { return false; } - return (Ext2Utils.get16(magic.array(), 0) == 0xEF53); + return + (Ext2Utils.get16(magic.array(), 0) == 0xEF53) && + (Ext2Utils.get32(revLevel.array(), 0) == 0 || Ext2Utils.get32(revLevel.array(), 0) == 1); } } Modified: trunk/fs/src/fs/org/jnode/fs/fat/Fat.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/fat/Fat.java 2012-08-10 06:44:27 UTC (rev 5914) +++ trunk/fs/src/fs/org/jnode/fs/fat/Fat.java 2012-08-10 06:53:31 UTC (rev 5915) @@ -24,7 +24,6 @@ import java.io.PrintWriter; import java.nio.ByteBuffer; import java.util.Arrays; - import org.jnode.driver.block.BlockDeviceAPI; import org.jnode.fs.FileSystemFullException; @@ -198,6 +197,7 @@ while (!isEofCluster(entries[(int) cluster])) { count++; cluster = entries[(int) cluster]; + testCluster(cluster); // prevent infinite loop in common case where it hits a 0 } // Now create the chain long[] chain = new long[count]; @@ -377,7 +377,7 @@ protected void testCluster(long cluster) throws IllegalArgumentException { if ((cluster < 2) || (cluster >= entries.length)) { - throw new IllegalArgumentException("Invalid cluster value"); + throw new IllegalArgumentException("Invalid cluster value: 0x" + Long.toHexString(cluster)); } } Modified: trunk/fs/src/fs/org/jnode/fs/fat/FatDirEntry.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/fat/FatDirEntry.java 2012-08-10 06:44:27 UTC (rev 5914) +++ trunk/fs/src/fs/org/jnode/fs/fat/FatDirEntry.java 2012-08-10 06:53:31 UTC (rev 5915) @@ -22,10 +22,11 @@ import java.io.IOException; import java.util.Date; - import org.jnode.fs.FSAccessRights; import org.jnode.fs.FSDirectory; import org.jnode.fs.FSEntry; +import org.jnode.fs.FSEntryCreated; +import org.jnode.fs.FSEntryLastAccessed; import org.jnode.fs.FSFile; import org.jnode.fs.spi.UnixFSAccessRights; import org.jnode.fs.util.DosUtils; @@ -35,7 +36,7 @@ /** * @author epr */ -public class FatDirEntry extends FatBasicDirEntry implements FSEntry { +public class FatDirEntry extends FatBasicDirEntry implements FSEntry, FSEntryCreated, FSEntryLastAccessed { /** Name of this entry */ private String name; Modified: trunk/fs/src/fs/org/jnode/fs/fat/FatFileSystemType.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/fat/FatFileSystemType.java 2012-08-10 06:44:27 UTC (rev 5914) +++ trunk/fs/src/fs/org/jnode/fs/fat/FatFileSystemType.java 2012-08-10 06:53:31 UTC (rev 5915) @@ -25,8 +25,6 @@ import org.jnode.fs.BlockDeviceFileSystemType; import org.jnode.fs.FileSystemException; import org.jnode.partitions.PartitionTableEntry; -import org.jnode.partitions.ibm.IBMPartitionTableEntry; -import org.jnode.partitions.ibm.IBMPartitionTypes; /** * @author epr @@ -50,6 +48,7 @@ * @param firstSector */ public boolean supports(PartitionTableEntry pte, byte[] firstSector, FSBlockDeviceAPI devApi) { +/* if (pte != null) { if (!pte.isValid()) { return false; @@ -66,14 +65,24 @@ } else { return false; } - } +*/ + try + { if (!new BootSector(firstSector).isaValidBootSector()) return false; + } + catch (RuntimeException e) + { + return false; + } - // Very ugly, but good enough for now. - return true; + // FAT-32 is currently handled by the newer jfat package. + return (firstSector[38] == 0x29 && + firstSector[54] == 'F' && + firstSector[55] == 'A' && + firstSector[56] == 'T'); } /** Modified: trunk/fs/src/fs/org/jnode/fs/fat/LfnEntry.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/fat/LfnEntry.java 2012-08-10 06:44:27 UTC (rev 5914) +++ trunk/fs/src/fs/org/jnode/fs/fat/LfnEntry.java 2012-08-10 06:53:31 UTC (rev 5915) @@ -22,17 +22,18 @@ import java.io.IOException; import java.util.Vector; - import org.jnode.fs.FSAccessRights; import org.jnode.fs.FSDirectory; import org.jnode.fs.FSEntry; +import org.jnode.fs.FSEntryCreated; +import org.jnode.fs.FSEntryLastAccessed; import org.jnode.fs.FSFile; import org.jnode.fs.FileSystem; /** * @author gbin */ -class LfnEntry implements FSEntry { +class LfnEntry implements FSEntry, FSEntryCreated, FSEntryLastAccessed { // decompacted LFN entry private String fileName; // TODO: Make them available Modified: trunk/fs/src/fs/org/jnode/fs/ftpfs/FTPFSEntry.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ftpfs/FTPFSEntry.java 2012-08-10 06:44:27 UTC (rev 5914) +++ trunk/fs/src/fs/org/jnode/fs/ftpfs/FTPFSEntry.java 2012-08-10 06:53:31 UTC (rev 5915) @@ -20,13 +20,11 @@ package org.jnode.fs.ftpfs; +import com.enterprisedt.net.ftp.FTPFile; +import java.io.IOException; +import org.jnode.fs.FSAccessRights; import org.jnode.fs.FSEntry; -import org.jnode.fs.FSAccessRights; -import java.io.IOException; - -import com.enterprisedt.net.ftp.FTPFile; - /** * @author Levente S\u00e1ntha */ @@ -77,6 +75,7 @@ /** * Gets the last modification time of this entry. * + * @return the last modification time, in milliseconds since January 1, 1970 UTC. * @throws java.io.IOException */ @@ -86,6 +85,19 @@ } /** + * <p>Gets the last access time of this entry.</p> + * + * <p>This implementation returns <code>0</code> as the FTP library has no means of + * obtaining the access time.</p> + * + * @return the last access time, in milliseconds since January 1, 1970 UTC. + * @throws IOException + */ + public long getLastAccessed() throws IOException { + return 0; + } + + /** * Gets the name of this entry. */ public String getName() { @@ -124,8 +136,9 @@ } /** - * Gets the last modification time of this entry. + * Sets the last modification time of this entry. This implementation does nothing. * + * @param lastModified the new last modification time. * @throws java.io.IOException */ public void setLastModified(long lastModified) throws IOException { @@ -133,6 +146,14 @@ } /** + * Sets the last access time of this entry. This implementation does nothing. + * + * @param lastAccessed the new last access time. + */ + public void setLastAccessed(long lastAccessed) { + } + + /** * Sets the name of this entry. */ public void setName(String newName) throws IOException { Modified: trunk/fs/src/fs/org/jnode/fs/iso9660/ISO9660Entry.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/iso9660/ISO9660Entry.java 2012-08-10 06:44:27 UTC (rev 5914) +++ trunk/fs/src/fs/org/jnode/fs/iso9660/ISO9660Entry.java 2012-08-10 06:53:31 UTC (rev 5915) @@ -21,7 +21,6 @@ package org.jnode.fs.iso9660; import java.io.IOException; - import org.jnode.fs.FSAccessRights; import org.jnode.fs.FSDirectory; import org.jnode.fs.FSEntry; @@ -63,6 +62,10 @@ return entryRecord.getRecordingTime().toJavaMillis(); } + public long getLastAccessed() { + return 0; + } + /** * @see org.jnode.fs.FSEntry#isFile() */ @@ -91,6 +94,10 @@ throw new UnsupportedOperationException("not yet implemented"); } + public void setLastAccessed(long lastAccessed) { + throw new UnsupportedOperationException("Filesystem is read-only"); + } + /** * @see org.jnode.fs.FSEntry#getFile() */ Modified: trunk/fs/src/fs/org/jnode/fs/jfat/FatEntry.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/jfat/FatEntry.java 2012-08-10 06:44:27 UTC (rev 5914) +++ trunk/fs/src/fs/org/jnode/fs/jfat/FatEntry.java 2012-08-10 06:53:31 UTC (rev 5915) @@ -20,20 +20,21 @@ package org.jnode.fs.jfat; +import java.io.FileNotFoundException; +import java.io.IOException; import java.util.Arrays; import java.util.Vector; -import java.io.IOException; -import java.io.FileNotFoundException; - import org.apache.log4j.Logger; -import org.jnode.util.NumberUtils; +import org.jnode.fs.FSAccessRights; +import org.jnode.fs.FSDirectory; import org.jnode.fs.FSEntry; -import org.jnode.fs.FSDirectory; +import org.jnode.fs.FSEntryCreated; +import org.jnode.fs.FSEntryLastAccessed; import org.jnode.fs.FSFile; -import org.jnode.fs.FSAccessRights; +import org.jnode.util.NumberUtils; -public class FatEntry extends FatObject implements FSEntry { +public class FatEntry extends FatObject implements FSEntry, FSEntryCreated, FSEntryLastAccessed { private static final Logger log = Logger.getLogger(FatEntry.class); private String name; Modified: trunk/fs/src/fs/org/jnode/fs/jfat/FatFileSystemType.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/jfat/FatFileSystemType.java 2012-08-10 06:44:27 UTC (rev 5914) +++ trunk/fs/src/fs/org/jnode/fs/jfat/FatFileSystemType.java 2012-08-10 06:53:31 UTC (rev 5915) @@ -25,8 +25,6 @@ import org.jnode.fs.BlockDeviceFileSystemType; import org.jnode.fs.FileSystemException; import org.jnode.partitions.PartitionTableEntry; -import org.jnode.partitions.ibm.IBMPartitionTableEntry; -import org.jnode.partitions.ibm.IBMPartitionTypes; /** @@ -41,6 +39,7 @@ } public boolean supports(PartitionTableEntry pte, byte[] firstSector, FSBlockDeviceAPI devApi) { +/* if (pte != null) { if (!pte.isValid()) return false; @@ -58,8 +57,14 @@ return false; } } +*/ - return false; + // Only supports FAT-32 for now, don't want any false results + // for FAT-16 or FAT-12. + return (firstSector[66] == 0x29 && + firstSector[82] == 'F' && + firstSector[83] == 'A' && + firstSector[84] == 'T'); } public FatFileSystem create(Device device, boolean readOnly) throws FileSystemException { Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/IndexAllocationAttribute.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/IndexAllocationAttribute.java 2012-08-10 06:44:27 UTC (rev 5914) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/IndexAllocationAttribute.java 2012-08-10 06:53:31 UTC (rev 5915) @@ -28,14 +28,25 @@ final class IndexAllocationAttribute extends NTFSNonResidentAttribute { /** - * @param fileRecord - * @param offset + * Creates the index allocation attribute. + * + * @param fileRecord the file record. + * @param offset the offset of this attribute into the file record. */ public IndexAllocationAttribute(FileRecord fileRecord, int offset) { super(fileRecord, offset); } /** + * Gets the magic value of this record. + * + * @return the magic value. + */ + public int getMagic() { + return getUInt32AsInt(0x00); + } + + /** * Read an index block starting at a given vcn. * * @param indexRoot Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/IndexEntry.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/IndexEntry.java 2012-08-10 06:44:27 UTC (rev 5914) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/IndexEntry.java 2012-08-10 06:53:31 UTC (rev 5915) @@ -20,6 +20,7 @@ package org.jnode.fs.ntfs; +import java.io.UnsupportedEncodingException; /** * Structure accessor of an Index Entry. @@ -91,7 +92,12 @@ } public String getFileName() { - return new String(this.getFileNameAsCharArray()); + try { + //XXX: For Java 6, should use the version that accepts a Charset. + return new String(this.getFileNameAsByteArray(), "UTF-16LE"); + } catch (UnsupportedEncodingException e) { + throw new IllegalStateException("UTF-16LE charset missing from JRE", e); + } } public long getFileReferenceNumber() { @@ -114,16 +120,15 @@ } public long getSubnodeVCN() { - return getUInt32(getSize() - 8); + return getInt64(getSize() - 8); // TODO: getUInt64AsInt + //return getUInt32(getSize() - 8); } - private char[] getFileNameAsCharArray() { + private byte[] getFileNameAsByteArray() { final int len = getUInt8(0x50); - final char[] name = new char[len]; - for (int i = 0; i < len; i++) { - name[i] = getChar16(0x52 + (i * 2)); - } - return name; + final byte[] bytes = new byte[len * 2]; + getData(0x52, bytes, 0, bytes.length); + return bytes; } @Override Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSEntry.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSEntry.java 2012-08-10 06:44:27 UTC (rev 5914) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSEntry.java 2012-08-10 06:53:31 UTC (rev 5915) @@ -21,10 +21,12 @@ package org.jnode.fs.ntfs; import java.io.IOException; - import org.jnode.fs.FSAccessRights; import org.jnode.fs.FSDirectory; import org.jnode.fs.FSEntry; +import org.jnode.fs.FSEntryCreated; +import org.jnode.fs.FSEntryLastAccessed; +import org.jnode.fs.FSEntryLastChanged; import org.jnode.fs.FSFile; import org.jnode.fs.FSObject; import org.jnode.fs.FileSystem; @@ -33,7 +35,7 @@ * @author vali * @author Ewout Prangsma (ep...@us...) */ -public class NTFSEntry implements FSEntry { +public class NTFSEntry implements FSEntry, FSEntryCreated, FSEntryLastChanged, FSEntryLastAccessed { private FSObject cachedFSObject; Modified: trunk/fs/src/fs/org/jnode/partitions/ibm/IBMPartitionTableEntry.java =================================================================== --- trunk/fs/src/fs/org/jnode/partitions/ibm/IBMPartitionTableEntry.java 2012-08-10 06:44:27 UTC (rev 5914) +++ trunk/fs/src/fs/org/jnode/partitions/ibm/IBMPartitionTableEntry.java 2012-08-10 06:53:31 UTC (rev 5915) @@ -20,6 +20,7 @@ package org.jnode.partitions.ibm; +import org.apache.log4j.Logger; import org.jnode.driver.block.CHS; import org.jnode.partitions.PartitionTableEntry; import org.jnode.util.LittleEndian; @@ -29,6 +30,7 @@ * @author epr */ public class IBMPartitionTableEntry implements PartitionTableEntry { + private final Logger log = Logger.getLogger(getClass()); private final byte[] bs; private final int ofs; @@ -98,7 +100,13 @@ } public IBMPartitionTypes getSystemIndicator() { - return IBMPartitionTypes.valueOf(LittleEndian.getUInt8(bs, ofs + 4)); + int code = LittleEndian.getUInt8(bs, ofs + 4); + try { + return IBMPartitionTypes.valueOf(code); + } catch (IllegalArgumentException e) { + log.warn("Invalid system indicator code: 0x" + Integer.toHexString(code)); + return IBMPartitionTypes.PARTTYPE_EMPTY; + } } public void setSystemIndicator(IBMPartitionTypes type) { Modified: trunk/fs/src/fs/org/jnode/partitions/ibm/IBMPartitionTableType.java =================================================================== --- trunk/fs/src/fs/org/jnode/partitions/ibm/IBMPartitionTableType.java 2012-08-10 06:44:27 UTC (rev 5914) +++ trunk/fs/src/fs/org/jnode/partitions/ibm/IBMPartitionTableType.java 2012-08-10 06:53:31 UTC (rev 5915) @@ -42,7 +42,6 @@ } public boolean supports(byte[] firstSector, BlockDeviceAPI devApi) { - // TODO Make a suitable implementation - return true; + return IBMPartitionTable.containsPartitionTable(firstSector); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |