|
From: <ga...@us...> - 2013-02-21 07:28:33
|
Revision: 5969
http://jnode.svn.sourceforge.net/jnode/?rev=5969&view=rev
Author: galatnm
Date: 2013-02-21 07:28:22 +0000 (Thu, 21 Feb 2013)
Log Message:
-----------
FAT16 Support in JFAT (Luke Quinane)
Modified Paths:
--------------
trunk/fs/src/fs/org/jnode/fs/jfat/BootSector.java
trunk/fs/src/fs/org/jnode/fs/jfat/Fat.java
trunk/fs/src/fs/org/jnode/fs/jfat/Fat32.java
trunk/fs/src/fs/org/jnode/fs/jfat/FatCache.java
trunk/fs/src/fs/org/jnode/fs/jfat/FatFileSystemType.java
trunk/fs/src/fs/org/jnode/fs/jfat/FatRootDirectory.java
Added Paths:
-----------
trunk/fs/src/fs/org/jnode/fs/jfat/Fat16.java
Modified: trunk/fs/src/fs/org/jnode/fs/jfat/BootSector.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jfat/BootSector.java 2013-02-20 12:01:01 UTC (rev 5968)
+++ trunk/fs/src/fs/org/jnode/fs/jfat/BootSector.java 2013-02-21 07:28:22 UTC (rev 5969)
@@ -138,7 +138,11 @@
else
FATSz = BPB_FATSz32;
- FirstDataSector = BPB_RsvdSecCnt + (BPB_NumFATs * FATSz) + RootDirSectors;
+ if (isFat32()) {
+ FirstDataSector = BPB_RsvdSecCnt + (BPB_NumFATs * FATSz) + RootDirSectors;
+ } else {
+ FirstDataSector = BPB_RsvdSecCnt + (BPB_NumFATs * FATSz);
+ }
if (BPB_TotSec16 != 0)
TotSec = BPB_TotSec16;
@@ -305,7 +309,7 @@
dirty = true;
}
- private String fatType() {
+ public String fatType() {
switch (type) {
case IFAT12:
return SFAT12;
@@ -366,6 +370,10 @@
return BPB_BytsPerSec;
}
+ public int getClusterSize() {
+ return BPB_SecPerClus * BPB_BytsPerSec;
+ }
+
public int getSectorsPerCluster() {
return BPB_SecPerClus;
}
@@ -390,6 +398,10 @@
return FirstDataSector;
}
+ public long getNrRootDirEntries() {
+ return BPB_RootEntCnt;
+ }
+
/**
* The Setting methods are writing here.
*
Modified: trunk/fs/src/fs/org/jnode/fs/jfat/Fat.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jfat/Fat.java 2013-02-20 12:01:01 UTC (rev 5968)
+++ trunk/fs/src/fs/org/jnode/fs/jfat/Fat.java 2013-02-21 07:28:22 UTC (rev 5969)
@@ -75,11 +75,12 @@
if (bs.isFat32()) {
return new Fat32(bs, api);
+ } else if (bs.isFat16()) {
+ return new Fat16(bs, api);
+ } else if (bs.isFat12()) {
+// return new Fat12(bs, api);
}
- /*
- * else if ( bs.isFat16() ) return new Fat16 ( bs, api ); else if (
- * bs.isFat12() ) return new Fat12 ( bs, api );
- */
+
throw new FileSystemException("FAT not recognized");
}
@@ -193,9 +194,7 @@
getBootSector().getFirstDataSector();
}
- public final long getClusterPosition(int index) {
- return getClusterSector(index) * (long) bs.getBytesPerSector();
- }
+ public abstract long getClusterPosition(int index);
public final int size() {
return (int) (bs.getCountOfClusters() + firstCluster());
@@ -225,10 +224,18 @@
return (entry == freeEntry());
}
+ public long getUInt16(int index) throws IOException {
+ return cache.getUInt16(index);
+ }
+
public long getUInt32(int index) throws IOException {
return cache.getUInt32(index);
}
+ public void setInt16(int index, int element) throws IOException {
+ cache.setInt16(index, element);
+ }
+
public void setInt32(int index, int element) throws IOException {
cache.setInt32(index, element);
}
Added: trunk/fs/src/fs/org/jnode/fs/jfat/Fat16.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jfat/Fat16.java (rev 0)
+++ trunk/fs/src/fs/org/jnode/fs/jfat/Fat16.java 2013-02-21 07:28:22 UTC (rev 5969)
@@ -0,0 +1,58 @@
+package org.jnode.fs.jfat;
+
+import java.io.IOException;
+import org.jnode.driver.block.BlockDeviceAPI;
+
+/**
+ * A FAT implementation for FAT-16.
+ *
+ * @author Luke Quinane
+ */
+public class Fat16 extends Fat {
+ protected Fat16(BootSector bs, BlockDeviceAPI api) {
+ super(bs, api);
+ }
+
+ protected long offset(int index) {
+ return (long) (2 * index);
+ }
+
+ public int get(int index) throws IOException {
+ return (int) getUInt16(index);
+ }
+
+ public int set(int index, int element) throws IOException {
+ long old = getUInt16(index);
+
+ setInt16(index, element & 0xFFFF);
+
+ return (int) (old & 0x0000FFFF);
+ }
+
+ public long getClusterPosition(int index) {
+ BootSector bootSector = getBootSector();
+
+ long rootDirectoryOffset = bootSector.getFirstDataSector() * bootSector.getBytesPerSector();
+
+ if (index == 0) {
+ return rootDirectoryOffset;
+ }
+
+ // Need to account for the size of the root directory entry for following clusters
+ long filesOffset = rootDirectoryOffset + bootSector.getNrRootDirEntries() * 32;
+ return filesOffset + ((index - firstCluster()) * getClusterSize());
+ }
+
+ @Override
+ public boolean hasNext(int entry) {
+ return !isEofChain(entry);
+ }
+
+ public boolean isEofChain(int entry) {
+ return (entry >= 0xFFF8);
+ }
+
+ public int eofChain() {
+ return 0xFFF8;
+ }
+}
Modified: trunk/fs/src/fs/org/jnode/fs/jfat/Fat32.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jfat/Fat32.java 2013-02-20 12:01:01 UTC (rev 5968)
+++ trunk/fs/src/fs/org/jnode/fs/jfat/Fat32.java 2013-02-21 07:28:22 UTC (rev 5969)
@@ -37,6 +37,10 @@
return (long) (4 * index);
}
+ public long getClusterPosition(int index) {
+ return getClusterSector(index) * (long) getBootSector().getBytesPerSector();
+ }
+
public int get(int index) throws IOException {
return (int) (getUInt32(index) & 0x0FFFFFFF);
}
Modified: trunk/fs/src/fs/org/jnode/fs/jfat/FatCache.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jfat/FatCache.java 2013-02-20 12:01:01 UTC (rev 5968)
+++ trunk/fs/src/fs/org/jnode/fs/jfat/FatCache.java 2013-02-21 07:28:22 UTC (rev 5969)
@@ -121,6 +121,14 @@
return c;
}
+ private long getUInt16(long offset) throws IOException {
+ long addr = offset / elementSize;
+ int ofs = (int) (offset % elementSize);
+
+ byte[] data = get(addr).getData();
+ return LittleEndian.getUInt16(data, ofs);
+ }
+
private long getUInt32(long offset) throws IOException {
long addr = (long) (offset / elementSize);
int ofs = (int) (offset % elementSize);
@@ -129,6 +137,18 @@
return LittleEndian.getUInt32(data, ofs);
}
+ private void setInt16(long offset, int value) throws IOException {
+ long addr = offset / elementSize;
+ int ofs = (int) (offset % elementSize);
+
+ CacheElement c = get(addr);
+ byte[] data = c.getData();
+
+ LittleEndian.setInt16(data, ofs, value);
+
+ c.setDirty();
+ }
+
private void setInt32(long offset, int value) throws IOException {
long addr = (long) (offset / elementSize);
int ofs = (int) (offset % elementSize);
@@ -141,10 +161,18 @@
c.setDirty();
}
+ public long getUInt16(int index) throws IOException {
+ return getUInt16(fat.position(0, index));
+ }
+
public long getUInt32(int index) throws IOException {
return getUInt32(fat.position(0, index));
}
+ public void setInt16(int index, int element) throws IOException {
+ setInt16(fat.position(0, index), element);
+ }
+
public void setInt32(int index, int element) throws IOException {
setInt32(fat.position(0, index), element);
}
Modified: trunk/fs/src/fs/org/jnode/fs/jfat/FatFileSystemType.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jfat/FatFileSystemType.java 2013-02-20 12:01:01 UTC (rev 5968)
+++ trunk/fs/src/fs/org/jnode/fs/jfat/FatFileSystemType.java 2013-02-21 07:28:22 UTC (rev 5969)
@@ -59,12 +59,20 @@
}
*/
- // Only supports FAT-32 for now, don't want any false results
- // for FAT-16 or FAT-12.
- return (firstSector[66] == 0x29 &&
+ // Check for FAT-32
+ if (firstSector[66] == 0x29 &&
firstSector[82] == 'F' &&
firstSector[83] == 'A' &&
- firstSector[84] == 'T');
+ firstSector[84] == 'T')
+ {
+ return true;
+ }
+
+ // Check for FAT-16/12
+ return (firstSector[38] == 0x29 &&
+ firstSector[54] == 'F' &&
+ firstSector[55] == 'A' &&
+ firstSector[56] == 'T');
}
public FatFileSystem create(Device device, boolean readOnly) throws FileSystemException {
Modified: trunk/fs/src/fs/org/jnode/fs/jfat/FatRootDirectory.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jfat/FatRootDirectory.java 2013-02-20 12:01:01 UTC (rev 5968)
+++ trunk/fs/src/fs/org/jnode/fs/jfat/FatRootDirectory.java 2013-02-21 07:28:22 UTC (rev 5969)
@@ -30,10 +30,8 @@
public FatRootDirectory(FatFileSystem fs) throws IOException {
super(fs);
Fat fat = getFatFileSystem().getFat();
- if (fat.isFat32()) {
+ if (fat.isFat32() || fat.isFat16()) {
setRoot32((int) getFatFileSystem().getBootSector().getRootDirectoryStartCluster());
- } else if (fat.isFat16()) {
- throw new UnsupportedOperationException("Fat16");
} else if (fat.isFat12()) {
throw new UnsupportedOperationException("Fat12");
} else {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|