geometry.java
来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 120 行
JAVA
120 行
/*
* $Id: Geometry.java,v 1.2 2003/11/29 17:20:24 gbin Exp $
*/
package org.jnode.fs.util;
/**
* @author epr
*/
public class Geometry {
private final int cylinders;
private final int heads;
private final int sectors;
/**
* Create a new instance
*
* @param c
* The number of cylinders
* @param h
* The number of heads
* @param s
* The number of sectors/cylinder
*/
public Geometry(int c, int h, int s) {
this.cylinders = c;
this.heads = h;
this.sectors = s;
}
/**
* @return int
*/
public int getCylinders() {
return cylinders;
}
/**
* @return int
*/
public int getHeads() {
return heads;
}
/**
* @return int
*/
public int getSectors() {
return sectors;
}
/**
* Gets the total number of sectors
*
* @return int
*/
public long getTotalSectors() {
long v = cylinders;
v *= heads;
v *= sectors;
return v;
}
/**
* Gets the logical sector number for a given CHS.
*
* @param chs
* @return long
*/
public long getLogicalSector(CHS chs) {
//ls = c*H*S + h*S + s - 1
long v = chs.getCylinder() * heads * sectors;
v += chs.getHead() * sectors;
v += chs.getSector();
return v - 1;
}
/**
* Gets a CHS from a given logical sector number
*
* @param logicalSector
* @return CHS
*/
public CHS getCHS(long logicalSector) {
// ls = (c*H + h) * S + s - 1
long v = logicalSector;
int s = (int) ((v % sectors) + 1);
v = v / sectors;
int h = (int) (v % heads);
v = v / heads;
int c = (int)v;
return new CHS(c, h, s);
}
public CHS NextSector(CHS chsToIncrement) {
int s = chsToIncrement.getSector();
int h = chsToIncrement.getHead();
int c = chsToIncrement.getCylinder();
s++;
if (s > sectors) {
s = 1;
h++;
if (h >= heads) {
h = 0;
c++;
if (c >= cylinders) {
throw new IllegalArgumentException("this geometry doesn't support cyclinder" + c);
}
}
}
return new CHS(c, h, s);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?