怎么得到硬盘簇和扇区的大小?(不用GetDiskFreeSpace)(100分)

  • 主题发起人 主题发起人 gaochunling
  • 开始时间 开始时间
G

gaochunling

Unregistered / Unconfirmed
GUEST, unregistred user!
好难,<br>帮你up
 
我也想知道,我顶!!
 
写一个调用GetDiskFreeSpace的例子,然后跟踪进GetDiskFreeSpace过程中,把那里的代码dump出来改一下。[:D][:D][:D][:D][:D][:D]
 
看看标签,<br>或者通过端口得到bios中的内容。<br>不知道nt下行不行。dos下的可以。
 
GetDiskFreeSpaceEX
 
&nbsp; 一扇区512字节,一个簇多少扇区取决于该分区的大小,这些可以推算出来的
 
GetDiskFreeSpace在WinME/2000/XP/2003下可以正常检测出大硬盘的簇的大小,但是在98下会返回错误值。GetDiskFreeSpaceEX只能返回硬盘容量和剩余空间,不能检测簇的大小。
 
这个数字是可以推算出来的。其实,在磁盘上, 一个扇区, 就是 512 字节 ,这个是不会变化的。<br>那么, “簇” 又是什么?他是文件的存储到磁盘上占用空间最小单位 ,比如,我们有一个1字节<br>的文件,那么他保存到磁盘上,占用多少空间呢?是 1“簇”的空间。为什么要用到“簇”这个<br>词呢?因为,很形象的,1朵花是1簇,n朵花也是1簇,就是这个意思。在磁盘上,1 簇 到底是多少,并不一定,他是 n 个扇区。(n&gt;=1)
 
&nbsp; &nbsp; &nbsp; &nbsp;《 容量与簇的关系 》<br>主分区或逻辑驱动器的容量 &nbsp; &nbsp; 蔟容量(FAT16) &nbsp; &nbsp; &nbsp; 簇容量(FAT32)<br>&nbsp; &nbsp;16-127MB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2KB<br>&nbsp; &nbsp;128-255MB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4KB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp;256-511MB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 8KB<br>&nbsp; &nbsp;512-1023MB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;16KB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4KB <br>&nbsp; &nbsp;1024-2047MB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 32KB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4KB<br>&nbsp; &nbsp;2048-8191MB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4KB<br>&nbsp; &nbsp;8192-16383MB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;8KB<br>&nbsp; &nbsp;16384-32767MB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 16KB<br>&nbsp; &nbsp;&gt;=32767MB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 32KB<br>===============================<br>&nbsp; &nbsp;上面是硬盘,如果是软盘,则一簇只有一扇区。<br>==================================<br>&nbsp; &nbsp;另外,顺便说一下,这个只是针对FAT磁盘格式的,其他格式我不了解。[:D]<br>&nbsp; &nbsp;我平时都是用FAT32的,且把每个分区分成差不多8G,这样尽量地节约空间。<br>
 
//for WinNT/2000/XP<br>function GetClusterSize:Integer;<br>var<br>&nbsp; Buf:array[0..512] of byte;<br>&nbsp; hDeviceHandle:integer;<br>begin<br>&nbsp; Result:=-1;<br>&nbsp; hDeviceHandle := CreateFile('//./C:', GENERIC_READ, &nbsp;//C盘<br>&nbsp; &nbsp; FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING,0, 0);<br>&nbsp; if (hDeviceHandle &lt;&gt; INVALID_HANDLE_VALUE) then<br>&nbsp; begin<br>&nbsp; &nbsp; FileSeek(hDevicehandle, 0, 0);<br>&nbsp; &nbsp; FileRead(hDevicehandle, Buf, 512);<br>&nbsp; &nbsp; Result:=Buf[13]*512;<br>&nbsp; &nbsp; closehandle(hDeviceHandle);<br>&nbsp; end;<br>end;<br><br><br><br>//for windows9x<br>procedure TForm1.Button1Click(Sender: TObject);<br>const<br>&nbsp; &nbsp;drive=3; &nbsp;//c盘<br>type<br>&nbsp;TDiskIO=packed Record<br>&nbsp; &nbsp; dwStartSector:longint;<br>&nbsp; &nbsp; wSectors &nbsp; &nbsp; :smallint;<br>&nbsp; &nbsp; lpBuffer &nbsp; &nbsp; :pchar;<br>&nbsp;end;<br>&nbsp;P32Regs = ^T32Regs; //32位寄存器结构<br>&nbsp; T32Regs = record<br>&nbsp; &nbsp; EBX: Longint;<br>&nbsp; &nbsp; EDX: Longint;<br>&nbsp; &nbsp; ECX: Longint;<br>&nbsp; &nbsp; EAX: Longint;<br>&nbsp; &nbsp; EDI: Longint;<br>&nbsp; &nbsp; ESI: Longint;<br>&nbsp; &nbsp; Flags: Longint;<br>&nbsp; end;<br><br>var<br>&nbsp; cb:DWORD;<br>&nbsp; str:string;<br>&nbsp; i:integer;<br>&nbsp; boot:array[0..512-1]of byte;<br>&nbsp; buffer:TDiskio;<br>&nbsp; hDeviceHandle:THandle;<br>&nbsp; reg:T32Regs;<br>begin<br>&nbsp; &nbsp; hDeviceHandle:=CreateFile('//./VWIN32',0,0, nil,0, FILE_FLAG_DELETE_ON_CLOSE, 0);<br>&nbsp; &nbsp; if(hDeviceHandle&lt;&gt;INVALID_HANDLE_VALUE) then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;buffer.dwStartSector:=0;<br>&nbsp; &nbsp; &nbsp; &nbsp;buffer.wSectors:=1;<br>&nbsp; &nbsp; &nbsp; &nbsp;buffer.lpBuffer:=@boot;<br>&nbsp; &nbsp; &nbsp; &nbsp;reg.EAX:=$7305;<br>&nbsp; &nbsp; &nbsp; &nbsp;reg.EBX:=Integer(@buffer);<br>&nbsp; &nbsp; &nbsp; &nbsp;reg.ECX:=-1;<br>&nbsp; &nbsp; &nbsp; &nbsp;reg.EDX:=drive;//1-A 2-b 3-c<br>&nbsp; &nbsp; &nbsp; &nbsp;reg.ESI:=0;//读<br>&nbsp; &nbsp; &nbsp; &nbsp;reg.Flags:=0;<br>&nbsp; &nbsp; &nbsp; &nbsp;DeviceIoControl(hDeviceHandle,6,@reg,sizeof(reg),@reg,sizeof(reg),cb,nil);<br>&nbsp; &nbsp; &nbsp; &nbsp;if ((reg.Flags and 1)=1) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raise exception.createfmt('错误代码:%.2x',[reg.EAX and $FFFF]);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; ShowMessage('簇大小:'+IntToStr(boot[13]*512));<br>end;<br>
 
有一个控件。RawDiskAccess。叫一强啊。
 
后退
顶部