ntfstest.java

来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 152 行

JAVA
152
字号
/*
 * $Id: NTFSTest.java,v 1.9 2004/01/19 21:20:54 vchira_2000 Exp $
 */
package org.jnode.fs.ntfs.test;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;

import org.jnode.driver.block.FileDevice;
import org.jnode.fs.FSDirectory;
import org.jnode.fs.FSEntry;
import org.jnode.fs.FileSystemException;
import org.jnode.fs.ntfs.NTFSFileSystem;


/**
 * Ext2 fs test, reads a disk image
 * to be run outside of JNode
 * 
 * @author Andras Nagy
 */
public class NTFSTest {
	
	org.jnode.fs.ntfs.NTFSFileSystem NTFSfs = null;
	File partImg = new File("e:/image2k.img");

	public NTFSTest() 
	{
		//read the disk image of an ext2fs partition
		
		//FileDevice implements BlockDeviceAPI
		FileDevice fd = null;
		try {
			fd = new FileDevice(partImg, "r");
		} catch (IOException e){
			System.out.println("error when reading disk image");
			System.exit(-1);
		}
		
		try{
			NTFSfs = new  NTFSFileSystem(fd);
		} catch (FileSystemException e) {
			System.out.println("error when constructing Ext2FileSystem");
			e.printStackTrace();
			System.exit(-1);
		}
	
		try{
			//FSDirectory root = NTFSfs.getRootEntry().getDirectory();
			//System.out.println(root.getEntry("text.txt").getName());
			//System.out.println("getRootEntry().isDirectory(): "+NTFSfs.getRootEntry().isDirectory());
			//System.out.println("getRootEntry().isFile(): "+NTFSfs.getRootEntry().isFile());
			list(null,null);
			
		}catch(IOException e) {
			System.out.println("error when parsing root directory");
			e.printStackTrace();
			System.exit(-1);
		}			
		
		
	}
	
	public String[] list(File directory, FilenameFilter filter) throws IOException {
		final FSEntry entry = NTFSfs.getRootEntry();
		if (entry == null) {
			throw new FileNotFoundException(directory.getAbsolutePath());
		}
		if (!entry.isDirectory()) {
			throw new IOException("Cannot list on non-directories " + directory);
		}
		final ArrayList list = new ArrayList();
		for (Iterator i = entry.getDirectory().iterator(); i.hasNext();) {
			final FSEntry child = (FSEntry)i.next();
			final String name = child.getName();
			if ((filter == null) || (filter.accept(directory, name))) {
				list.add(name);
			}
		if(child.isDirectory())
			child.getDirectory();
		else
			child.getFile();
		
		if(child.isFile())
			System.out.println(
						"Name = \"" + name + "\" , Size = " + child.getFile().getLength() + ", IsDirectory = " + child.isDirectory());
		else
			System.out.println(
					"Name = \"" + name + "\" , IsDirectory = " + child.isDirectory());
		}
		
		return (String[])list.toArray(new String[list.size()]);
	}
	
	public void iterateRoot(FSDirectory root)
	{
		try {
			Iterator rootIterator;
			rootIterator = root.iterator();
			while(rootIterator.hasNext()) {
				FSEntry entry=(FSEntry)rootIterator.next();
				System.out.println(entry.getName());
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	public void printBootSectorData()
	{
		/*try
		{
			
			NTFSVolume volume = new NTFSVolume(this.stream);
			
			System.out.println("OEM ID = " + volume.getBootRecord().SystemID);
			System.out.println("Bytes Per Sector = " + volume.getBootRecord().BytesPerSector);
			System.out.println("Sectors Per Cluster = " + (int)volume.getBootRecord().SectorPerCluster);
			System.out.println("MediaDescriptor = 0x" + Integer.toHexString(volume.getBootRecord().MediaDescriptor).toUpperCase());
			System.out.println("Sector per track = " + volume.getBootRecord().SectorsPerTrack);
			System.out.println("Logical Cluster Number for the file $MFT = " + volume.getBootRecord().MFTPointer);
			System.out.println("Clusters per MFT Record = " + volume.getBootRecord().ClustersPerMFTRecord);
			System.out.println("Total Sectors = " + volume.getBootRecord().TotalSectors);
			
			System.out.println("$MFT byte start= " + volume.getBootRecord().MFTPointer * volume.getClusterSize() + "( 0x"+ Integer.toHexString(volume.getBootRecord().MFTPointer * volume.getClusterSize()) + ")");
			System.out.println("Cluster size = " + volume.getClusterSize());
			
			
		} catch (FileNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		
	}
	
	
	public static void main(String[] args) {
		NTFSTest test = new NTFSTest();
		test.printBootSectorData();
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?