fatutils.java

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

JAVA
65
字号
/**
 * $Id: FatUtils.java,v 1.2 2003/11/29 03:33:28 gbin Exp $
 */
package org.jnode.fs.fat;

/**
 * <description>
 * 
 * @author epr
 */
public class FatUtils {
	
	public static final int FIRST_CLUSTER = 2;

	/**
	 * Gets the offset (in bytes) of the fat with the given index
	 * @param bs
	 * @param fatNr (0..)
	 * @return long
	 */
	public static long getFatOffset(BootSector bs, int fatNr) {
		long sectSize = bs.getBytesPerSector();
		long sectsPerFat = bs.getSectorsPerFat();
		long resSects = bs.getNrReservedSectors();
		
		long offset = resSects * sectSize;
		
		if (fatNr > 0) {
			offset += (fatNr-1) * sectsPerFat * sectSize;
		}
		
		return offset;
	}

	/**
	 * Gets the offset (in bytes) of the root directory with the given index
	 * @param bs
	 * @return long
	 */
	public static long getRootDirOffset(BootSector bs) {
		long sectSize = bs.getBytesPerSector();
		long sectsPerFat = bs.getSectorsPerFat();
		int fats = bs.getNrFats();
		
		long offset = getFatOffset(bs, 0);
		
		offset += fats * sectsPerFat * sectSize;
		
		return offset;
	}

	/**
	 * Gets the offset of the data (file) area 
	 * @param bs
	 * @return long
	 */
	public static long getFilesOffset(BootSector bs) {
		long offset = getRootDirOffset(bs);
		
		offset += bs.getNrRootDirEntries() * 32;
		
		return offset;
	}
}

⌨️ 快捷键说明

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