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
; ebx = destination
;-----------------------------------------------------------
and [hd_error], 0
push ecx esi edi ; scan cache
mov ecx,cache_max ; entries in cache

View File

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

View File

@ -464,7 +464,7 @@ fs_HdServices:
dd fs_HdSetFileEnd
dd fs_HdGetFileInfo
dd fs_HdSetFileInfo
dd fs_HdExecute
dd 0 ;fs_HdExecute
dd fs_HdDelete
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
iglobal
;******************************************************
; Please do not change this place - variables in text
; Mario79
@ -13,6 +15,11 @@ align 4
;******************************************************
PARTITION_START dd 0x3f
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
NUMBER_OF_FATS dd 0x2
SECTORS_PER_CLUSTER dd 0x8
@ -30,13 +37,34 @@ fatBAD dd 0x0FFFFFF7
fatEND dd 0x0FFFFFF8
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
; Mario79
;***************************************************************************
iglobal
partition_types: ; list of fat16/32 partitions
db 0x04 ; DOS: fat16 <32M
db 0x06 ; DOS: fat16 >32M
@ -55,6 +83,7 @@ iglobal
db 0xce ; DRDOS/secured: fat16, LBA-mapped
db 0xd4 ; Old Multiuser DOS secured: fat16 <32M
db 0xd6 ; Old Multiuser DOS secured: fat16 >32M
db 0x07 ; NTFS
partition_types_end:
@ -122,6 +151,14 @@ extended_already_set:
mov edx, eax ; start sector
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:
push eax
@ -134,8 +171,15 @@ next_primary_partition:
cmp ecx,[fat32part] ; is it wanted partition?
jnz next_primary_partition_1 ; no
mov edx,eax ; start sector
add edx,[ebx+0x1be+8+16] ; add relative start
mov edx, eax
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:
push eax
@ -148,8 +192,15 @@ next_primary_partition_1:
cmp ecx,[fat32part] ; is it wanted partition?
jnz next_primary_partition_2 ; no
mov edx,eax ; start sector
add edx,[ebx+0x1be+8+16+16] ; add relative start
mov edx, eax
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:
push eax
@ -162,8 +213,15 @@ next_primary_partition_2:
cmp ecx,[fat32part] ; is it wanted partition?
jnz next_partition ; no
mov edx,eax ; start sector
add edx,[ebx+0x1be+8+16+16+16] ; add relative start
mov edx, eax
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:
push eax
@ -241,7 +299,7 @@ problem_partition_or_fat:
popad
problem_hd:
mov [fat_type],0
mov [fs_type],0
mov [hd1_status],0 ; free
mov [problem_partition],1
ret
@ -249,14 +307,40 @@ problem_hd:
hd_and_partition_ok:
mov eax,edx
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
call hd_read ; read boot sector of partition
cmp [hd_error], 0
jne problem_fat_dec_count
mov [hd_setup],0
jz boot_read_ok
cmp [fs_type], 7
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?
jnz problem_fat_dec_count
@ -332,7 +416,7 @@ fat32_partition:
mov [fatBAD],0x0FFFFFF7
mov [fatEND],0x0FFFFFF8
mov [fatMASK],0x0FFFFFFF
mov [fat_type],32 ; Fat32
mov [fs_type],32 ; Fat32
mov [hd1_status],0 ; free
ret
@ -346,6 +430,6 @@ fat16_partition:
mov [fatBAD],0x0000FFF7
mov [fatEND],0x0000FFF8
mov [fatMASK],0x0000FFFF
mov [fat_type],16 ; Fat16
mov [fs_type],16 ; Fat16
mov [hd1_status],0 ; free
ret

View File

@ -378,11 +378,6 @@ B32:
@@:
mov [pg_data.kernel_tables], edx
;!!!!!!!!!!!!!!!!!!!!!!!!!!
include 'detect/disks.inc'
;!!!!!!!!!!!!!!!!!!!!!!!!!!
; CHECK EXTRA REGION
; ENABLE PAGING
call test_cpu
@ -462,6 +457,10 @@ include 'detect/disks.inc'
mov [graph_data_l+4],al
mov [graph_data_l+7],ah
;!!!!!!!!!!!!!!!!!!!!!!!!!!
include 'detect/disks.inc'
;!!!!!!!!!!!!!!!!!!!!!!!!!!
; 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/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 "blkdev/rd.inc" ; ramdisk read /write
include "fs/fs_lfn.inc" ; syscall, version 2