求助:关于FAT32的根目录文件问题

dszsun 2002-08-25 10:32:02
大家好,我在开发一个硬盘加密程序,现在基本已经成功了。
但还有问题没解决。就是如何在FAT32中如何确定根目录区占用的扇区数?FAT32的根目录区做成了一个根目录文件,是不是占用连续的扇区呀?有没有办法在vxd或vc中找出它占用的扇区呀?
我的加密出现是要把FAT和根目录文件加密。急盼大家的帮助。
(我已在google上用“FAT 根目录区”搜过了,没我想要的结果)
...全文
483 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
dszsun 2002-08-28
  • 打赏
  • 举报
回复
我的问题基本解决了。特别感谢 zara(Kyrie eleison) ,还有就是windsi(困了) ,谢谢你们。

dszsun 2002-08-27
  • 打赏
  • 举报
回复
哦?我可以访问呀
metalbreeze 2002-08-27
  • 打赏
  • 举报
回复
http://its.nbtvu.net.cn/frchen/cfr/cathedra/FATFS/ex_7.htm
我访问不了,怎么回事呢?
metalbreeze 2002-08-27
  • 打赏
  • 举报
回复
to zara(Kyrie eleison)
能把win2k的引导扇区的0x0c扇区中的遍历根目录中文件项以搜寻ntldr文件
的代码包括注释发给我么
我非常需它
gwvd@sina.com.cn
THX!!!!
windsi 2002-08-27
  • 打赏
  • 举报
回复
好多的资料上面分析分区第一个扇区的数据时是从头也就是第一个字节开开始的。
假设c盘起始是从扇区0,1,1开始,那么从每一个字节开始是
"jmp 指令" 占用3 BYTES 一般是EB XX XX
"制造厂商的标识" 占用8 BYTES 如MSWIN4.1
接着就是bpb结构
我上面贴的是MSDN 中的,你可以搜索FAT32就会查到了
其中
A_BF_BPB_RootDirStrtClus
The cluster number of the first cluster in the FAT32 drive's root directory.
就是FAT32根目录的起始簇的低字
A_BF_BPB_RootDirStrtClusHi
The high word of the FAT32 starting cluster number.
是高字
dszsun 2002-08-26
  • 打赏
  • 举报
回复
哦,忘了说清楚,我对E盘FAT加密后没有重启。明天再看看。

如果对跟目录区的访问要用到FAT的话,那该怎样找出根目录文件占用的扇区呢?
谁有这方面的资料或example呀?
谢谢大家。
zara 2002-08-26
  • 打赏
  • 举报
回复
FAT32的根目录肯定是可以不连续的, 只是第一个簇的位置是固定的(02簇, 这和原来的一致), 如果你的根目录下的文件的目录项数从未超过128(是项数,不是文件和目录数,因为可能有长文件名), 那么自然不需要方位FAT区, 否则, 必须访问才能访问完整的根目录区.

下面是win2k的引导扇区的0x0c扇区中的遍历根目录中文件项以搜寻ntldr文件的部分代码, 你可仔细看看sub_0_80de子程:
loc_0_8000: ; CODE XREF: seg000:7CB5^j
movzx eax, byte ptr [bp+10h] ; number of FATs
mov ecx, [bp+24h] ; sectors per FAT
mul ecx
add eax, [bp+1Ch] ; hidden sectors
movzx edx, word ptr [bp+0Eh] ; reserved sectors
add eax, edx
mov [bp-4], eax ; the 1st data sector rel. to the disk physically
mov dword ptr [bp-0Ch], 0FFFFFFFFh
mov eax, [bp+2Ch] ; Root dir 1st cluster
cmp eax, 2
jb loc_0_7CD6 ; less than 2? It's error! go away
cmp eax, 0FFFFFF8h
jnb loc_0_7CD6 ; greater than 0fffffff8h? unreasonable, go away

loc_0_803A: ; CODE XREF: seg000:8079^j
push eax
sub eax, 2 ; data section starting with the cluster of 2
movzx ebx, byte ptr [bp+0Dh] ; sectors per cluster
mov si, bx
mul ebx
add eax, [bp-4] ; now, eax points to the sector of the cluster rel. to the phy. disk

loc_0_804E: ; CODE XREF: seg000:8072^j
mov bx, 8200h
mov di, bx
mov cx, 1
call loc_0_7CE0 ; read-in the sector

loc_0_8059: ; CODE XREF: seg000:806F^j
cmp [di], ch ; byte 00 of the dir. sector means ending of the dir. items
jz loc_0_807B
mov cl, 0Bh
push si
mov si, 7D70h ; db 'NTLDR '
rep cmpsb ; Is it the file of "NTLDR" ?
pop si
jz loc_0_8083 ; yes, found it, go ...
add di, cx
add di, 15h ; points to the next dir. item
cmp di, bx ; bx points to the next sector buffer while returning from sub_7ce0
jb loc_0_8059 ; there are more dir. items, goto check the next dir. item
dec si ; the next sector of the cluster
jnz loc_0_804E ; there are more sector in the cluster, go to check the next sector
pop eax
call sub_0_80DE ; get the next cluster number from FAT
jb loc_0_803A ; there is the next cluster, go to check it

loc_0_807B: ; CODE XREF: seg000:805B^j
add sp, 4
jmp loc_0_7CD6

sub_0_80DE proc near ; CODE XREF: seg000:8076^p seg000:80CD^p
shl eax, 2 ; cluster*4=position in FAT
call sub_0_80F6
mov eax, es:[bx+di] ; get the next cluster number
and eax, 0FFFFFFFh
cmp eax, 0FFFFFF8h ; Is the current the last one ?
retn
sub_0_80DE endp


;----------------------------------------------------------------------------

; S u b r o u t i n e

sub_0_80F6 proc near ; CODE XREF: sub_0_80DE+4^p
mov di, 7E00h
movzx ecx, word ptr [bp+0Bh] ; bytes per sector
xor edx, edx
div ecx ; cluster item: sector in EAX, offset in EDX
cmp eax, [bp-0Ch]
jz loc_0_8144
mov [bp-0Ch], eax
add eax, [bp+1Ch] ; hidden sectors
movzx ecx, word ptr [bp+0Eh] ; reserved sectors
add eax, ecx
movzx ebx, word ptr [bp+28h] ; flag (?)
and bx, 0Fh
jz loc_0_813A
cmp bl, [bp+10h] ; number of FATs
jnb loc_0_7CD6
push dx
mov ecx, eax
mov eax, [bp+24h] ; sectors per FAT
mul ebx
add eax, ecx
pop dx

loc_0_813A: ; CODE XREF: sub_0_80F6+2C^j
push dx
mov bx, di
mov cx, 1
call loc_0_7CE0 ; read-in one sector
pop dx

loc_0_8144: ; CODE XREF: sub_0_80F6+12^j
mov bx, dx
retn
sub_0_80F6 endp
紫郢剑侠 2002-08-26
  • 打赏
  • 举报
回复
FAT32不象FAT那样对根本目录项数有限制了。
dszsun 2002-08-26
  • 打赏
  • 举报
回复
回 giantzz(牛!是怎么死的。。。) :谢谢你的回复。
按你程序的意思,根目录文件的大小是固定的?并且我分析了你的程序,觉得你应该是根据DOS3.31以上的FAT12/16系统的bpb编的,对吗?
我现在要的是找出FAT32的根目录文件所占用的扇区,它的大小是不固定的,至于占用的扇区好象也是不连续的,因为操作系统把它也做为一个文件来处理。
不知道我说的对不对呢?
giantzz 2002-08-26
  • 打赏
  • 举报
回复
入口参数:BX=BPB表首地址
出口参数:AX=文件起始扇区号;DX=根目录起始扇区号
BEGIN_S proc near
push cx
mov al,[bx+5] ;取FAT表的个数
xor ah,ah
mul word ftr[bx+11] ;计算FAT表占用扇区数
add ax,[bx+17] ;加隐含扇区数
add ax,[bx+3] ;加保留扇区数
mov cx,ax ;CX为根目录区起始位置
mov ax,32
mul word ptr [bx+6] ;计算根目录区占用字节数
div word ptr [bx] ;根目录区占用扇区数
add ax,cx ;AX为文件区起始位置
mov dx,cx
pop cx
ret
BEGIN_S endp
dszsun 2002-08-26
  • 打赏
  • 举报
回复
谢谢楼上的回复。你能把你手头上的那方面的资料给我发一份吗?我手头上的是在
http://its.nbtvu.net.cn/frchen/cfr/cathedra/FATFS/ex_7.htm
里下载的,好象它并没有根目录首簇的字段。
谢谢
dszsun@sina.com
zara 2002-08-26
  • 打赏
  • 举报
回复
sorry, 我认为的根目录的首簇为2是错误的, 应该是在引导扇区的0x2c处的双字. WinHex中是这么说的, win2k的引导扇区中也是这么做的(上面贴出的代码开始处).
dszsun 2002-08-26
  • 打赏
  • 举报
回复
回楼上:我是说我找到的是那份资料,好想跟 windsi(困了)贴出来的不同。不知道为什么?
giantzz 2002-08-26
  • 打赏
  • 举报
回复
你说的资料就是这个?
我给你一个http://its.nbtvu.net.cn/frchen/cfr/cathedra/FATFS/ex_7.htm
dszsun 2002-08-26
  • 打赏
  • 举报
回复
谢谢楼上:
但把我弄糊涂了,我手头的一份FAT32bpb的资料,但好想跟你贴出来的不同!!!
困惑ing.........我是在这里下的资料:
http://its.nbtvu.net.cn/frchen/cfr/cathedra/FATFS/ex_7.htm
windsi 2002-08-26
  • 打赏
  • 举报
回复
FAT32的根目录大小是不固定的,而且它在FAT表中的首簇也不一定非是第二簇,你可以根据BPB表找到根目录的首簇,然后从首簇开始根据FAT表可以找出所有根目录所占用的簇,把簇的总和跟每簇扇区数相乘就得到根目录所占用的总扇区数。
FAT32对于根目录的管理与一般文件基本相似,只不过将它的首簇地址记录在BPB表中以定位。
在BPB结构之前是
read-only hex 3 "JMP instruction"
char[8] "OEM"
接着是FAT32的BPB
A_BF_BPB STRUC
A_BF_BPB_BytesPerSector DW ?
A_BF_BPB_SectorsPerCluster DB ?
A_BF_BPB_ReservedSectors DW ?
A_BF_BPB_NumberOfFATs DB ?
A_BF_BPB_RootEntries DW ?
A_BF_BPB_TotalSectors DW ?
A_BF_BPB_MediaDescriptor DB ?
A_BF_BPB_SectorsPerFAT DW ?
A_BF_BPB_SectorsPerTrack DW ?
A_BF_BPB_Heads DW ?
A_BF_BPB_HiddenSectors DW ?
A_BF_BPB_HiddenSectorsHigh DW ?
A_BF_BPB_BigTotalSectors DW ?
A_BF_BPB_BigTotalSectorsHigh DW ?
A_BF_BPB_BigSectorsPerFat DW ?
A_BF_BPB_BigSectorsPerFatHi DW ?
A_BF_BPB_ExtFlags DW ?
A_BF_BPB_FS_Version DW ?
A_BF_BPB_RootDirStrtClus DW ?
A_BF_BPB_RootDirStrtClusHi DW ?
A_BF_BPB_FSInfoSec DW ?
A_BF_BPB_BkUpBootSec DW ?
A_BF_BPB_Reserved DW 6 DUP (?)
A_BF_BPB ENDS


A_BF_BPB_RootDirStrtClus
The cluster number of the first cluster in the FAT32 drive's root directory.

A_BF_BPB_RootDirStrtClusHi
The high word of the FAT32 starting cluster number.


giantzz 2002-08-26
  • 打赏
  • 举报
回复
可以去看看FAT32的资料,你没有我可以
dszsun 2002-08-25
  • 打赏
  • 举报
回复
回giantzz(牛!是怎么死的。。。):我手头用bpb的资料,通过bpb表是不行的
dszsun 2002-08-25
  • 打赏
  • 举报
回复
回复:zara(Kyrie eleison)哦。也就是说根目录文件的访问要用到FAT?我知道它的大小是不固定的。但根据我的测试好想根目录文件的访问不要用到FAT吧,因为我做实验是曾把E盘的两份FAT全部加了密(没隐藏E盘),但我有可以看到E盘有多少个文件,文件名,目录,刚点开E盘是没什么两样哦。并且小于4k的文件可以正常访问(因为根目录文件我还没加密,它能访问文件的第一簇)。应该访问根目录文件没用到FAT吧,不知道我那实验是不是说明了这一点。盼望大家来讨论,看看在
vxd或vc中如何访问根目录文件所占用的扇区。
谢谢大家
giantzz 2002-08-25
  • 打赏
  • 举报
回复
BPB不可以吗?
加载更多回复(1)

21,453

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧