NTFS reader, part 1: read root directory

git-svn-id: svn://kolibrios.org@256 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Evgeny Grechnikov (Diamond) 2006-12-29 15:42:36 +00:00
parent af99f0b88d
commit b308bbdde7
7 changed files with 1492 additions and 74 deletions

View File

@ -21,6 +21,7 @@ hd_read:
; input : eax = block to read ; input : eax = block to read
; ebx = destination ; ebx = destination
;----------------------------------------------------------- ;-----------------------------------------------------------
and [hd_error], 0
push ecx esi edi ; scan cache push ecx esi edi ; scan cache
mov ecx,cache_max ; entries in cache mov ecx,cache_max ; entries in cache

View File

@ -189,7 +189,7 @@ set_FAT:
jb sfc_error jb sfc_error
cmp eax,[LAST_CLUSTER] cmp eax,[LAST_CLUSTER]
ja sfc_error ja sfc_error
cmp [fat_type],16 cmp [fs_type],16
je sfc_1 je sfc_1
add eax,eax add eax,eax
sfc_1: sfc_1:
@ -217,7 +217,7 @@ set_FAT:
sfc_in_cache: sfc_in_cache:
cmp [fat_type],16 cmp [fs_type],16
jne sfc_test32 jne sfc_test32
sfc_set16: sfc_set16:
@ -253,7 +253,7 @@ get_FAT:
;-------------------------------- ;--------------------------------
push ebx esi push ebx esi
cmp [fat_type],16 cmp [fs_type],16
je gfc_1 je gfc_1
add eax,eax add eax,eax
gfc_1: gfc_1:
@ -381,7 +381,7 @@ analyze_directory:
jnb adr_data_cluster jnb adr_data_cluster
mov eax,[ROOT_CLUSTER] ; if cluster < 2 then read rootdir mov eax,[ROOT_CLUSTER] ; if cluster < 2 then read rootdir
cmp [fat_type],16 cmp [fs_type],16
jne adr_data_cluster jne adr_data_cluster
mov eax,[ROOT_START] mov eax,[ROOT_START]
mov edx,[ROOT_SECTORS] mov edx,[ROOT_SECTORS]
@ -476,7 +476,7 @@ analyze_directory_to_write:
jnb adw_data_cluster jnb adw_data_cluster
mov eax,[ROOT_CLUSTER] ; if cluster < 2 then read rootdir mov eax,[ROOT_CLUSTER] ; if cluster < 2 then read rootdir
cmp [fat_type],16 cmp [fs_type],16
jne adw_data_cluster jne adw_data_cluster
mov eax,[ROOT_START] mov eax,[ROOT_START]
mov edx,[ROOT_SECTORS] mov edx,[ROOT_SECTORS]
@ -599,7 +599,7 @@ get_data_cluster:
jnb gdc_cluster jnb gdc_cluster
mov eax,[ROOT_CLUSTER] ; if cluster < 2 then read rootdir mov eax,[ROOT_CLUSTER] ; if cluster < 2 then read rootdir
cmp [fat_type],16 cmp [fs_type],16
jne gdc_cluster jne gdc_cluster
mov eax,[ROOT_START] mov eax,[ROOT_START]
mov ecx,[ROOT_SECTORS] ; Note: not cluster size mov ecx,[ROOT_SECTORS] ; Note: not cluster size
@ -817,9 +817,12 @@ makedir:
; 10 - access denied ; 10 - access denied
; Note : can only make one directory at time ; Note : can only make one directory at time
;----------------------------------------------------- ;-----------------------------------------------------
cmp [fat_type],0 cmp [fs_type], 16
jnz make_dir_fat_ok jz make_dir_fat_ok
mov eax,ERROR_UNKNOWN_FS cmp [fs_type], 32
jz make_dir_fat_ok
push ERROR_UNKNOWN_FS
pop eax
ret ret
make_dir_fat_ok: make_dir_fat_ok:
@ -995,7 +998,7 @@ add_disk_free_space:
;----------------------------------------------------- ;-----------------------------------------------------
test ecx,ecx ; no change test ecx,ecx ; no change
je add_dfs_no je add_dfs_no
cmp [fat_type],32 ; free disk space only used by fat32 cmp [fs_type],32 ; free disk space only used by fat32
jne add_dfs_no jne add_dfs_no
push eax ebx push eax ebx
@ -1036,9 +1039,12 @@ file_write:
; 8 - disk full ; 8 - disk full
; 10 - access denied ; 10 - access denied
;-------------------------------------------------------------------------- ;--------------------------------------------------------------------------
cmp [fat_type],0 cmp [fs_type], 16
jnz fat_ok_for_writing jz fat_ok_for_writing
mov eax,ERROR_UNKNOWN_FS cmp [fs_type], 32
jz fat_ok_for_writing
push ERROR_UNKNOWN_FS
pop eax
ret ret
fat_ok_for_writing: fat_ok_for_writing:
@ -1222,8 +1228,10 @@ file_read:
; 10 - access denied ; 10 - access denied
; ebx = size of file/directory ; ebx = size of file/directory
;-------------------------------------------------------------------------- ;--------------------------------------------------------------------------
cmp [fat_type],0 cmp [fs_type], 16
jnz fat_ok_for_reading jz fat_ok_for_reading
cmp [fs_type], 32
jz fat_ok_for_reading
xor ebx,ebx xor ebx,ebx
mov eax,ERROR_UNKNOWN_FS mov eax,ERROR_UNKNOWN_FS
mov [hd1_status], ebx mov [hd1_status], ebx
@ -1344,7 +1352,7 @@ get_dir_size:
mov eax,[ROOT_SECTORS] mov eax,[ROOT_SECTORS]
shl eax,9 ; fat16 rootdir size in bytes shl eax,9 ; fat16 rootdir size in bytes
cmp [fat_type],16 cmp [fs_type],16
je dir_size_ret je dir_size_ret
mov eax,[ROOT_CLUSTER] mov eax,[ROOT_CLUSTER]
@ -1379,9 +1387,12 @@ file_delete:
; 5 - file not found ; 5 - file not found
; 10 - access denied ; 10 - access denied
;----------------------------------------------------- ;-----------------------------------------------------
cmp [fat_type],0 cmp [fs_type], 16
jnz file_del_fat_ok jz file_del_fat_ok
mov eax,ERROR_UNKNOWN_FS cmp [fs_type], 32
jz file_del_fat_ok
push ERROR_UNKNOWN_FS
pop eax
ret ret
file_del_fat_ok: file_del_fat_ok:
@ -1665,9 +1676,12 @@ rename:
; 8 - disk full ; 8 - disk full
; 10 - access denied ; 10 - access denied
;----------------------------------------------------------- ;-----------------------------------------------------------
cmp [fat_type],0 cmp [fs_type], 16
jnz fat_ok_for_rename jz fat_ok_for_rename
mov eax,ERROR_UNKNOWN_FS cmp [fs_type], 32
jz fat_ok_for_rename
push ERROR_UNKNOWN_FS
pop eax
ret ret
fat_ok_for_rename: fat_ok_for_rename:
@ -1825,8 +1839,10 @@ get_hd_info:
; ebx = total clusters on disk ; ebx = total clusters on disk
; ecx = free clusters on disk ; ecx = free clusters on disk
;----------------------------------------------------------- ;-----------------------------------------------------------
cmp [fat_type],0 cmp [fs_type], 16
jnz info_fat_ok jz info_fat_ok
cmp [fs_type], 32
jz info_fat_ok
xor edx,edx xor edx,edx
xor ebx,ebx xor ebx,ebx
xor ecx,ecx xor ecx,ecx
@ -1949,7 +1965,7 @@ hd_find_lfn:
push fat16_root_first push fat16_root_first
push fat16_root_next push fat16_root_next
mov eax, [ROOT_CLUSTER] mov eax, [ROOT_CLUSTER]
cmp [fat_type], 32 cmp [fs_type], 32
jz .fat32 jz .fat32
.loop: .loop:
call fat_find_lfn call fat_find_lfn
@ -2000,8 +2016,12 @@ hd_find_lfn:
; ;
;-------------------------------------------------------------- ;--------------------------------------------------------------
fs_HdRead: fs_HdRead:
cmp [fat_type], 0 cmp [fs_type], 16
jnz @f jz @f
cmp [fs_type], 32
jz @f
cmp [fs_type], 1
jz ntfs_HdRead
or ebx, -1 or ebx, -1
mov eax, ERROR_UNKNOWN_FS mov eax, ERROR_UNKNOWN_FS
ret ret
@ -2155,6 +2175,17 @@ fs_HdRead:
; ;
;-------------------------------------------------------------- ;--------------------------------------------------------------
fs_HdReadFolder: fs_HdReadFolder:
cmp [fs_type], 1
jz ntfs_HdReadFolder
cmp [fs_type], 16
jz @f
cmp [fs_type], 32
jz @f
push ERROR_UNSUPPORTED_FS
pop eax
or ebx, -1
ret
@@:
mov eax, [ROOT_CLUSTER] mov eax, [ROOT_CLUSTER]
push edi push edi
cmp byte [esi], 0 cmp byte [esi], 0
@ -2195,7 +2226,7 @@ fs_HdReadFolder:
mov [cluster_tmp], eax mov [cluster_tmp], eax
test eax, eax test eax, eax
jnz @f jnz @f
cmp [fat_type], 32 cmp [fs_type], 32
jz .notfound jz .notfound
mov eax, [ROOT_START] mov eax, [ROOT_START]
push [ROOT_SECTORS] push [ROOT_SECTORS]
@ -2525,8 +2556,13 @@ fshrfs:
ret ret
fs_HdRewrite: fs_HdRewrite:
cmp [fat_type], 0 cmp [fs_type], 1
jz fshrfs jz ntfs_HdRewrite
cmp [fs_type], 16
jz @f
cmp [fs_type], 32
jnz fshrfs
@@:
cmp byte [esi], 0 cmp byte [esi], 0
jz fshrad jz fshrad
pushad pushad
@ -2545,7 +2581,7 @@ fs_HdRewrite:
test ebp, ebp test ebp, ebp
jnz .noroot jnz .noroot
mov ebp, [ROOT_CLUSTER] mov ebp, [ROOT_CLUSTER]
cmp [fat_type], 32 cmp [fs_type], 32
jz .pushnotroot jz .pushnotroot
push fat16_root_extend_dir push fat16_root_extend_dir
push fat16_root_end_write push fat16_root_end_write
@ -2944,7 +2980,7 @@ fs_HdRewrite:
;---------------------------------------------------------------- ;----------------------------------------------------------------
; ;
; fs_HdWrite - LFN variant for writing to floppy ; fs_HdWrite - LFN variant for writing to hard disk
; ;
; esi points to filename ; esi points to filename
; ebx pointer to 64-bit number = first wanted byte, 0+ ; ebx pointer to 64-bit number = first wanted byte, 0+
@ -2968,8 +3004,12 @@ fs_HdWrite.ret11:
jmp fs_HdWrite.ret0 jmp fs_HdWrite.ret0
fs_HdWrite: fs_HdWrite:
cmp [fat_type], 0 cmp [fs_type], 1
jnz @f jz ntfs_HdWrite
cmp [fs_type], 16
jz @f
cmp [fs_type], 32
jz @f
push ERROR_UNKNOWN_FS push ERROR_UNKNOWN_FS
jmp .ret0 jmp .ret0
@@: @@:
@ -3301,8 +3341,12 @@ hd_extend_file:
; ;
;-------------------------------------------------------------- ;--------------------------------------------------------------
fs_HdSetFileEnd: fs_HdSetFileEnd:
cmp [fat_type], 0 cmp [fs_type], 1
jnz @f jz ntfs_HdSetFileEnd
cmp [fs_type], 16
jz @f
cmp [fs_type], 32
jz @f
push ERROR_UNKNOWN_FS push ERROR_UNKNOWN_FS
.ret: .ret:
pop eax pop eax
@ -3529,8 +3573,12 @@ fs_HdSetFileEnd:
ret ret
fs_HdGetFileInfo: fs_HdGetFileInfo:
cmp [fat_type], 0 cmp [fs_type], 1
jnz @f jz ntfs_HdGetFileInfo
cmp [fs_type], 16
jz @f
cmp [fs_type], 32
jz @f
mov eax, ERROR_UNKNOWN_FS mov eax, ERROR_UNKNOWN_FS
ret ret
@@: @@:
@ -3553,8 +3601,12 @@ fs_HdGetFileInfo:
jmp fs_GetFileInfo_finish jmp fs_GetFileInfo_finish
fs_HdSetFileInfo: fs_HdSetFileInfo:
cmp [fat_type], 0 cmp [fs_type], 1
jnz @f jz ntfs_HdSetFileInfo
cmp [fs_type], 16
jz @f
cmp [fs_type], 32
jz @f
mov eax, ERROR_UNKNOWN_FS mov eax, ERROR_UNKNOWN_FS
ret ret
@@: @@:
@ -3589,6 +3641,8 @@ fs_HdSetFileInfo:
xor eax, eax xor eax, eax
ret ret
if 0 ; starting from revision 237 execute is implemented in taskman.inc
; through fs_XxxGetFileInfo and fs_XxxRead
;---------------------------------------------------------------- ;----------------------------------------------------------------
; ;
; fs_HdExecute - LFN variant for executing from harddisk ; fs_HdExecute - LFN variant for executing from harddisk
@ -3708,6 +3762,7 @@ fs_HdExecute:
popad popad
mov eax, 11 mov eax, 11
ret ret
end if
;---------------------------------------------------------------- ;----------------------------------------------------------------
; ;
@ -3719,8 +3774,12 @@ fs_HdExecute:
; ;
;-------------------------------------------------------------- ;--------------------------------------------------------------
fs_HdDelete: fs_HdDelete:
cmp [fat_type], 0 cmp [fs_type], 1
jnz @f jz ntfs_HdDelete
cmp [fs_type], 16
jz @f
cmp [fs_type], 32
jz @f
push ERROR_UNKNOWN_FS push ERROR_UNKNOWN_FS
.pop_ret: .pop_ret:
pop eax pop eax

View File

@ -464,7 +464,7 @@ fs_HdServices:
dd fs_HdSetFileEnd dd fs_HdSetFileEnd
dd fs_HdGetFileInfo dd fs_HdGetFileInfo
dd fs_HdSetFileInfo dd fs_HdSetFileInfo
dd fs_HdExecute dd 0 ;fs_HdExecute
dd fs_HdDelete dd fs_HdDelete
fs_NumHdServices = ($ - fs_HdServices)/4 fs_NumHdServices = ($ - fs_HdServices)/4

1274
kernel/trunk/fs/ntfs.inc Executable file

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,8 @@
;************************************************************* ;*************************************************************
align 4 align 4
iglobal
;****************************************************** ;******************************************************
; Please do not change this place - variables in text ; Please do not change this place - variables in text
; Mario79 ; Mario79
@ -13,6 +15,11 @@ align 4
;****************************************************** ;******************************************************
PARTITION_START dd 0x3f PARTITION_START dd 0x3f
PARTITION_END dd 0 PARTITION_END dd 0
fs_type db 0 ; 0=none, 1=NTFS, 16=FAT16, 32=FAT32
fs_dependent_data_start:
; FATxx data
SECTORS_PER_FAT dd 0x1f3a SECTORS_PER_FAT dd 0x1f3a
NUMBER_OF_FATS dd 0x2 NUMBER_OF_FATS dd 0x2
SECTORS_PER_CLUSTER dd 0x8 SECTORS_PER_CLUSTER dd 0x8
@ -30,13 +37,34 @@ fatBAD dd 0x0FFFFFF7
fatEND dd 0x0FFFFFF8 fatEND dd 0x0FFFFFF8
fatMASK dd 0x0FFFFFFF fatMASK dd 0x0FFFFFFF
fat_type db 0 ; 0=none, 16=fat16, 32=fat32 fs_dependent_data_end:
virtual at fs_dependent_data_start
; NTFS data
ntfs_data:
.sectors_per_cluster dd ?
.mft_cluster dd ?
.mftmirr_cluster dd ?
.frs_size dd ? ; FRS size in bytes
.iab_size dd ? ; IndexAllocationBuffer size in bytes
.frs_buffer dd ?
.iab_buffer dd ?
.mft_retrieval dd ?
.mft_retrieval_size dd ?
.mft_retrieval_alloc dd ?
.mft_retrieval_end dd ?
.cur_index_size dd ?
.cur_index_buf dd ?
if $ > fs_dependent_data_end
ERROR: increase sizeof(fs_dependent_data)!
end if
end virtual
;*************************************************************************** ;***************************************************************************
; End place ; End place
; Mario79 ; Mario79
;*************************************************************************** ;***************************************************************************
iglobal
partition_types: ; list of fat16/32 partitions partition_types: ; list of fat16/32 partitions
db 0x04 ; DOS: fat16 <32M db 0x04 ; DOS: fat16 <32M
db 0x06 ; DOS: fat16 >32M db 0x06 ; DOS: fat16 >32M
@ -55,6 +83,7 @@ iglobal
db 0xce ; DRDOS/secured: fat16, LBA-mapped db 0xce ; DRDOS/secured: fat16, LBA-mapped
db 0xd4 ; Old Multiuser DOS secured: fat16 <32M db 0xd4 ; Old Multiuser DOS secured: fat16 <32M
db 0xd6 ; Old Multiuser DOS secured: fat16 >32M db 0xd6 ; Old Multiuser DOS secured: fat16 >32M
db 0x07 ; NTFS
partition_types_end: partition_types_end:
@ -122,6 +151,14 @@ extended_already_set:
mov edx, eax ; start sector mov edx, eax ; start sector
add edx, [ebx+0x1be+8] ; add relative start add edx, [ebx+0x1be+8] ; add relative start
push edx
add edx, [ebx+0x1be+12] ; add length
dec edx ; PARTITION_END is inclusive
mov [PARTITION_END], edx ; note that this can be changed
; when file system data will be available
mov dl, [ebx+0x1be+4]
mov [fs_type], dl ; save for FS recognizer (separate FAT vs NTFS)
pop edx
next_primary_partition: next_primary_partition:
push eax push eax
@ -134,8 +171,15 @@ next_primary_partition:
cmp ecx,[fat32part] ; is it wanted partition? cmp ecx,[fat32part] ; is it wanted partition?
jnz next_primary_partition_1 ; no jnz next_primary_partition_1 ; no
mov edx,eax ; start sector mov edx, eax
add edx,[ebx+0x1be+8+16] ; add relative start add edx, [ebx+0x1be+8+16]
push edx
add edx, [ebx+0x1be+12+16]
dec edx
mov [PARTITION_END], edx
mov dl, [ebx+0x1be+4+16]
mov [fs_type], dl
pop edx
next_primary_partition_1: next_primary_partition_1:
push eax push eax
@ -148,8 +192,15 @@ next_primary_partition_1:
cmp ecx,[fat32part] ; is it wanted partition? cmp ecx,[fat32part] ; is it wanted partition?
jnz next_primary_partition_2 ; no jnz next_primary_partition_2 ; no
mov edx,eax ; start sector mov edx, eax
add edx,[ebx+0x1be+8+16+16] ; add relative start add edx, [ebx+0x1be+8+16+16]
push edx
add edx, [ebx+0x1be+12+16+16]
dec edx
mov [PARTITION_END], edx
mov dl, [ebx+0x1be+4+16+16]
mov [fs_type], dl
pop edx
next_primary_partition_2: next_primary_partition_2:
push eax push eax
@ -162,8 +213,15 @@ next_primary_partition_2:
cmp ecx,[fat32part] ; is it wanted partition? cmp ecx,[fat32part] ; is it wanted partition?
jnz next_partition ; no jnz next_partition ; no
mov edx,eax ; start sector mov edx, eax
add edx,[ebx+0x1be+8+16+16+16] ; add relative start add edx, [ebx+0x1be+8+16+16+16]
push edx
add edx, [ebx+0x1be+12+16+16+16]
dec edx
mov [PARTITION_END], edx
mov dl, [ebx+0x1be+4+16+16+16]
mov [fs_type], dl
pop edx
next_partition: next_partition:
push eax push eax
@ -241,7 +299,7 @@ problem_partition_or_fat:
popad popad
problem_hd: problem_hd:
mov [fat_type],0 mov [fs_type],0
mov [hd1_status],0 ; free mov [hd1_status],0 ; free
mov [problem_partition],1 mov [problem_partition],1
ret ret
@ -249,14 +307,40 @@ problem_hd:
hd_and_partition_ok: hd_and_partition_ok:
mov eax,edx mov eax,edx
mov [PARTITION_START],eax mov [PARTITION_START],eax
mov edx, [PARTITION_END]
sub edx, eax
inc edx ; edx = length of partition
mov [hd_setup],1 ; mov [hd_setup],1
mov ebx,buffer mov ebx,buffer
call hd_read ; read boot sector of partition call hd_read ; read boot sector of partition
cmp [hd_error], 0 cmp [hd_error], 0
jne problem_fat_dec_count jz boot_read_ok
cmp [fs_type], 7
mov [hd_setup],0 jnz problem_fat_dec_count
; NTFS duplicates bootsector:
; NT4/2k/XP+ saves bootsector copy in the end of disk
; NT 3.51 saves bootsector copy in the middle of disk
and [hd_error], 0
mov eax, [PARTITION_END]
call hd_read
cmp [hd_error], 0
jnz @f
call ntfs_test_bootsec
jnc boot_read_ok
@@:
and [hd_error], 0
mov eax, edx
shr eax, 1
add eax, [PARTITION_START]
call hd_read
cmp [hd_error], 0
jnz problem_fat_dec_count ; ­¥ áã¤ì¡ ...
boot_read_ok:
; mov [hd_setup], 0
; if we are running on NTFS, check bootsector
cmp [fs_type], 7
jz ntfs_setup
cmp word [ebx+0x1fe],0xaa55 ; is it valid boot sector? cmp word [ebx+0x1fe],0xaa55 ; is it valid boot sector?
jnz problem_fat_dec_count jnz problem_fat_dec_count
@ -332,7 +416,7 @@ fat32_partition:
mov [fatBAD],0x0FFFFFF7 mov [fatBAD],0x0FFFFFF7
mov [fatEND],0x0FFFFFF8 mov [fatEND],0x0FFFFFF8
mov [fatMASK],0x0FFFFFFF mov [fatMASK],0x0FFFFFFF
mov [fat_type],32 ; Fat32 mov [fs_type],32 ; Fat32
mov [hd1_status],0 ; free mov [hd1_status],0 ; free
ret ret
@ -346,6 +430,6 @@ fat16_partition:
mov [fatBAD],0x0000FFF7 mov [fatBAD],0x0000FFF7
mov [fatEND],0x0000FFF8 mov [fatEND],0x0000FFF8
mov [fatMASK],0x0000FFFF mov [fatMASK],0x0000FFFF
mov [fat_type],16 ; Fat16 mov [fs_type],16 ; Fat16
mov [hd1_status],0 ; free mov [hd1_status],0 ; free
ret ret

View File

@ -378,11 +378,6 @@ B32:
@@: @@:
mov [pg_data.kernel_tables], edx mov [pg_data.kernel_tables], edx
;!!!!!!!!!!!!!!!!!!!!!!!!!!
include 'detect/disks.inc'
;!!!!!!!!!!!!!!!!!!!!!!!!!!
; CHECK EXTRA REGION
; ENABLE PAGING ; ENABLE PAGING
call test_cpu call test_cpu
@ -462,6 +457,10 @@ include 'detect/disks.inc'
mov [graph_data_l+4],al mov [graph_data_l+4],al
mov [graph_data_l+7],ah mov [graph_data_l+7],ah
;!!!!!!!!!!!!!!!!!!!!!!!!!!
include 'detect/disks.inc'
;!!!!!!!!!!!!!!!!!!!!!!!!!!
; READ RAMDISK IMAGE FROM HD ; READ RAMDISK IMAGE FROM HD
;!!!!!!!!!!!!!!!!!!!!!!! ;!!!!!!!!!!!!!!!!!!!!!!!

View File

@ -241,6 +241,7 @@ include "boot/shutdown.inc" ; shutdown or restart
include "fs/fs.inc" ; syscall include "fs/fs.inc" ; syscall
include "fs/fat32.inc" ; read / write for fat32 filesystem include "fs/fat32.inc" ; read / write for fat32 filesystem
include "fs/ntfs.inc" ; read / write for ntfs filesystem
include "fs/fat12.inc" ; read / write for fat12 filesystem include "fs/fat12.inc" ; read / write for fat12 filesystem
include "blkdev/rd.inc" ; ramdisk read /write include "blkdev/rd.inc" ; ramdisk read /write
include "fs/fs_lfn.inc" ; syscall, version 2 include "fs/fs_lfn.inc" ; syscall, version 2