Revision: 5913
          http://jnode.svn.sourceforge.net/jnode/?rev=5913&view=rev
Author:   galatnm
Date:     2012-08-10 06:41:36 +0000 (Fri, 10 Aug 2012)
Log Message:
-----------
Add in support for extracting sym-link target and identify block, char, fifo 
and link obje

Modified Paths:
--------------
    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/INode.java

Modified: trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Entry.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Entry.java    2012-08-10 06:39:34 UTC 
(rev 5912)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Entry.java    2012-08-10 06:41:36 UTC 
(rev 5913)
@@ -21,7 +21,6 @@
 package org.jnode.fs.ext2;
 
 import java.io.IOException;
-
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.jnode.fs.FSDirectory;
@@ -97,7 +96,9 @@
             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)
+        else if (mode == Ext2Constants.EXT2_S_IFREG || mode == 
Ext2Constants.EXT2_S_IFLNK ||
+                 mode == Ext2Constants.EXT2_S_IFIFO || mode == 
Ext2Constants.EXT2_S_IFCHR ||
+                 mode == Ext2Constants.EXT2_S_IFBLK)
             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     2012-08-10 06:39:34 UTC 
(rev 5912)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/Ext2File.java     2012-08-10 06:41:36 UTC 
(rev 5913)
@@ -22,7 +22,6 @@
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
-
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.jnode.fs.FileSystemException;
@@ -180,20 +179,27 @@
             try {
                 if (len + off > getLength())
                     throw new IOException("Can't read past the file!");
-                long blockSize = iNode.getExt2FileSystem().getBlockSize();
-                long bytesRead = 0;
-                while (bytesRead < len) {
-                    long blockNr = (fileOffset + bytesRead) / blockSize;
-                    long blockOffset = (fileOffset + bytesRead) % blockSize;
-                    long copyLength = Math.min(len - bytesRead, blockSize - 
blockOffset);
 
-                    log.debug("blockNr: " + blockNr + ", blockOffset: " + 
blockOffset + ", copyLength: " + copyLength +
-                            ", bytesRead: " + bytesRead);
+                if ((iNode.getMode() & Ext2Constants.EXT2_S_IFLNK) == 
Ext2Constants.EXT2_S_IFLNK) {
+                    // Sym-links are a special case: the data seems to be 
stored inline in the iNode
+                    System.arraycopy(iNode.getINodeBlockData(), 0, dest, 0, 
Math.min(64, dest.length));
+                }
+                else {
+                    long blockSize = iNode.getExt2FileSystem().getBlockSize();
+                    long bytesRead = 0;
+                    while (bytesRead < len) {
+                        long blockNr = (fileOffset + bytesRead) / blockSize;
+                        long blockOffset = (fileOffset + bytesRead) % 
blockSize;
+                        long copyLength = Math.min(len - bytesRead, blockSize 
- blockOffset);
 
-                    System.arraycopy(iNode.getDataBlock(blockNr), (int) 
blockOffset, dest, off + (int) bytesRead,
-                            (int) copyLength);
+                        log.debug("blockNr: " + blockNr + ", blockOffset: " + 
blockOffset + ", copyLength: " + copyLength +
+                                ", bytesRead: " + bytesRead);
 
-                    bytesRead += copyLength;
+                        System.arraycopy(iNode.getDataBlock(blockNr), (int) 
blockOffset, dest, off + (int) bytesRead,
+                                (int) copyLength);
+
+                        bytesRead += copyLength;
+                    }
                 }
             } catch (Throwable ex) {
                 final IOException ioe = new IOException();

Modified: trunk/fs/src/fs/org/jnode/fs/ext2/INode.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/INode.java        2012-08-10 06:39:34 UTC 
(rev 5912)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/INode.java        2012-08-10 06:41:36 UTC 
(rev 5913)
@@ -270,6 +270,17 @@
     }
 
     /**
+     * Gets the data stored inline in the inode's i_block element.
+     *
+     * @return the inode block data.
+     */
+    public byte[] getINodeBlockData() {
+        byte[] buffer = new byte[64];
+        System.arraycopy(data, 40, buffer, 0, buffer.length);
+        return buffer;
+    }
+
+    /**
      * Return the number of the block in the filesystem that stores the ith
      * block of the inode (i is a sequential index from the beginning of the
      * file)
@@ -286,10 +297,7 @@
     private long getDataBlockNr(long i) throws IOException {
         if ((getFlags() & Ext2Constants.EXT4_INODE_EXTENTS_FLAG) != 0) {
             if (extentHeader == null) {
-                byte[] headerBuffer = new byte[64];
-                System.arraycopy(data, 40, headerBuffer, 0, 
headerBuffer.length);
-
-                extentHeader = new ExtentHeader(headerBuffer);
+                extentHeader = new ExtentHeader(getINodeBlockData());
             }
 
             return extentHeader.getBlockNumber(i);

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Jnode-svn-commits mailing list
Jnode-svn-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jnode-svn-commits

Reply via email to