⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileblockdevice.java

📁 JPC: x86 PC Hardware Emulator. 牛津大学开发的一个纯JAVA的x86系统结构硬件模拟器。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		empty[i]=(byte) 0x00;	}	start = new byte[512*95];	for(int i=1;i<95;i++){		System.arraycopy(empty,0,start,i*512,512);	}	System.arraycopy(MBR,0,start,0,512);	System.arraycopy(header,0,start,63*512,512);	System.arraycopy(header2,0,start,64*512,512);	System.arraycopy(header,0,start,69*512,512);	System.arraycopy(header2,0,start,70*512,512);    }    public void dumpChanges(DataOutput output) throws IOException    {}    public void loadChanges(DataInput input) throws IOException    {}    //Convert Int to byte[] of certain length    public static byte[] toByteArray(int n, int l)    {	byte[] input = toByteArray(n);	byte[] answer = new byte[l];	if(input.length>l)	    System.arraycopy(input,0,answer,0,l);	else        {	    for(int i=0;i<l;i++)		answer[i]=(byte)0x00;	    System.arraycopy(input,0,answer,0,input.length);	}	return answer;    }    //Convert Int to byte[] with shifting    public static byte[] toByteArray(int n)    {	long length =  Long.toHexString(n).length();	byte[] answer = new byte[(int) length];	byte[] finalanswer;	for(int i = 0;i<length/2+.5;i++)	    answer[i]=(byte) ((n >>> 8*i) & 0xFF);	int i =answer.length -1;	while(answer[i]==(byte)0xFF & i!=0)	    i--;       	finalanswer = new byte[i+1];	System.arraycopy(answer,0,finalanswer,0,i+1);	return finalanswer;    }    //Convert Long to byte[] of certain length    public static byte[] toByteArray(long n, int l)    {	byte[] input = toByteArray(n);	byte[] answer = new byte[l];	if(input.length>l)	    System.arraycopy(input,0,answer,0,l);	else         {	    for(int i=0;i<l;i++)		answer[i]=(byte)0x00;	    System.arraycopy(input,0,answer,0,input.length);	}	return answer;    }    //Convert Long to byte[] with shifting    public static byte[] toByteArray(long n)    {	long length =  Long.toHexString(n).length();	byte[] answer = new byte[(int) length];	byte[] finalanswer;	for(int i = 0;i<length/2+.5;i++)	    answer[i]=(byte) ((n >>> 8*i) & 0xFF);	int i =answer.length -1;	while(answer[i]==(byte)0xFF & i!=0)	    i--;	finalanswer = new byte[i+1];	System.arraycopy(answer,0,finalanswer,0,i+1);	return finalanswer;    }    //reverse an array of bytes    public byte[] reverse(byte[] input)    {	byte[] output;	output = new byte[input.length];	for(int i=0;i<input.length;i++){	    output[i]=input[input.length-i-1];	}	return output;    }    public void close()    {        try        {            raf.close();        }        catch (Exception e) {}    }    //READ up to 16 sectors at a time    public int read(long sectorNumber, byte[] buffer, int size)    {	//	System.out.println("Reading Sector number " + sectorNumber + " and size = " + size);        if (sectorNumber < 95){	// Initial sectors	    System.arraycopy(start, (int) sectorNumber*512, buffer, 0, size*512);	    return 0;	}else if (sectorNumber < 95+2*sectorsPerFAT & sectorNumber>94){	// FAT sectors	    	    System.arraycopy(FAT, (int) ((sectorNumber-95) % sectorsPerFAT)*512, buffer, 0, size*512);	    return 0;	}else if ((sectorNumber > fileSizeSectors +rootSize+2*sectorsPerFAT+95-1) & (sectorNumber < totalSectors +1)){	    	    for (int i = 0;i<size;i++){		System.arraycopy(empty,0,buffer,512*i,512);	    }	    return 0;	}else if (sectorNumber >  totalSectors){	    return -1;	}else if ((sectorNumber > 95 + 2*sectorsPerFAT-1) & (sectorNumber < 95 + 2*sectorsPerFAT + rootSizeClusters*sectorsPerCluster)){//root folder	    System.out.println("reading root sector...");	    System.arraycopy(rootdir,0,buffer,0,size*512);	    return 0;	}	//if (sectorNumber > 95+2*sectorsPerFAT & sectorNumber < totalSectors){	    // data	try	    {		long offset =  (sectorNumber - 95-2*sectorsPerFAT) * 512;		raf.seek(offset);		int len = Math.min(size*512, (int) (raf.length() - offset));		raf.read(buffer, 0, len);		return 0;	    }	catch (Exception e)	    {		e.printStackTrace();		return -1;	    }    }    //write sectors    public int write(long sectorNumber, byte[] buffer, int size)    {	System.out.println("Write attempt");        if (sectorNumber <95)        {            System.arraycopy(buffer, 0, start, (int) sectorNumber*512, size*512);            return 0;        }else if (sectorNumber < 95+2*sectorsPerFAT & sectorNumber>94)        {            System.arraycopy(buffer, 0,FAT, (int) ((sectorNumber-95) % sectorsPerFAT),  size*512);            return 0;        }	if (sectorNumber > totalSectors){	    return -1;	}        try        {            long offset = (sectorNumber - 95-2*sectorsPerFAT-rootSize) * 512;            raf.seek(offset);            int len = Math.min(size*512, (int) (raf.length() - offset));            raf.write(buffer, 0, len);            return 0;        }        catch (Exception e)        {            e.printStackTrace();            return -1;        }    }    public boolean inserted()    {        return true;    }    public boolean locked()    {        return locked;    }    public boolean readOnly()    {        return true;    }    public void setLock(boolean l)    {        locked = l;    }    public long getTotalSectors()    {        return totalSectors;    }    public int cylinders()    {    	//smaller than 1024        return cylinders;     }    public int heads()    {    	//smaller than 256        return heads;    }    public int sectors()// is this looking for totalSectors or 63??    {        return (int) sectorsPerTrack;    }    public int type()    {        return TYPE_HD;    }    public String getImageFileName()    {        return source.getAbsolutePath();    }}

⌨️ 快捷键说明

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