idediskpartitiondriver.java

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

JAVA
103
字号
/*
 * $Id: IDEDiskPartitionDriver.java,v 1.2 2003/11/29 17:20:24 gbin Exp $
 */
package org.jnode.driver.ide;

import java.io.IOException;

import org.jnode.driver.Device;
import org.jnode.driver.Driver;
import org.jnode.driver.DriverException;
import org.jnode.driver.block.FSBlockDeviceAPI;
import org.jnode.driver.block.MappedBlockDeviceSupport;
import org.jnode.fs.partitions.PartitionTableEntry;

/**
 * @author epr
 */
public class IDEDiskPartitionDriver extends Driver implements FSBlockDeviceAPI, IDEConstants {

	/** The device i'm driving */
	private IDEDiskPartitionDevice device;
	private PartitionTableEntry pte;
	private MappedBlockDeviceSupport mapping;

	/**
	 * @see org.jnode.driver.Driver#startDevice()
	 */
	protected void startDevice() throws DriverException {
		try {
			final IDEDiskPartitionDevice dev = this.device;
			this.pte = dev.getPartitionTableEntry();
			final Device parent = dev.getParent();
			final long offset = dev.getStartSector() * SECTOR_SIZE;
			final long length = dev.getSectors() * SECTOR_SIZE;
			this.mapping = new MappedBlockDeviceSupport(parent, offset, length);
			/* Register the FSBlockDevice API */
			device.registerAPI(FSBlockDeviceAPI.class, this);
		} catch (IOException ex) {
			throw new DriverException("Error in MappedBlockDeviceSupport", ex);
		}
	}

	/**
	 * @see org.jnode.driver.Driver#stopDevice()
	 */
	protected void stopDevice() {
		/* for now only unregister an API */
		device.unregisterAPI(FSBlockDeviceAPI.class);
	}

	/**
	 * @see org.jnode.driver.Driver#afterConnect(org.jnode.driver.Device)
	 */
	protected void afterConnect(Device device) {
		this.device = (IDEDiskPartitionDevice)device;
		super.afterConnect(device);
	}

	/**
	 * Gets the sector size for this device.
	 */
	public int getSectorSize() {
		return SECTOR_SIZE;
	}

	/**
	 * Gets the partition table entry specifying this device.
	 * 
	 * @return A PartitionTableEntry or null if no partition table entry exists.
	 */
	public PartitionTableEntry getPartitionTableEntry() {
		return pte;
	}

	/**
	 * @see org.jnode.driver.block.BlockDeviceAPI#flush()
	 */
	public void flush() throws IOException {
		mapping.flush();
	}

	/**
	 * @see org.jnode.driver.block.BlockDeviceAPI#getLength()
	 */
	public long getLength() {
		return mapping.getLength();
	}

	/**
	 * @see org.jnode.driver.block.BlockDeviceAPI#read(long, byte[], int, int)
	 */
	public void read(long devOffset, byte[] dest, int destOffset, int length) throws IOException {
		mapping.read(devOffset, dest, destOffset, length);
	}

	/**
	 * @see org.jnode.driver.block.BlockDeviceAPI#write(long, byte[], int, int)
	 */
	public void write(long devOffset, byte[] src, int srcOffset, int length) throws IOException {
		mapping.write(devOffset, src, srcOffset, length);
	}
}

⌨️ 快捷键说明

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