2012-03-08 09:33:38 +01:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;; ;;
|
2012-03-15 13:41:29 +01:00
|
|
|
|
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
|
2012-03-08 09:33:38 +01:00
|
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
|
;; 02.02.2010 turbanoff - support 70.5 ;;
|
|
|
|
|
;; 23.01.2010 turbanoff - support 70.0 70.1 ;;
|
2013-06-28 10:02:49 +02:00
|
|
|
|
;; 21.06.2013 yogev_ezra - Translate Russian comments ;;
|
2012-03-08 09:33:38 +01:00
|
|
|
|
;; ;;
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
$Revision$
|
|
|
|
|
|
2013-05-11 14:38:27 +02:00
|
|
|
|
EXT2_BAD_INO = 1
|
2012-03-08 09:33:38 +01:00
|
|
|
|
EXT2_ROOT_INO = 2
|
2013-05-11 14:38:27 +02:00
|
|
|
|
EXT2_ACL_IDX_INO = 3
|
2012-03-08 09:33:38 +01:00
|
|
|
|
EXT2_ACL_DATA_INO = 4
|
2012-10-12 20:24:48 +02:00
|
|
|
|
EXT2_BOOT_LOADER_INO = 5
|
2013-05-11 14:38:27 +02:00
|
|
|
|
EXT2_UNDEL_DIR_INO = 6
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
;RUS: флаги, указываемые в inode файла ;ENG: flags specified in file inode
|
2013-05-11 14:38:27 +02:00
|
|
|
|
EXT2_S_IFREG = 0x8000
|
|
|
|
|
EXT2_S_IFDIR = 0x4000
|
2013-06-28 10:02:49 +02:00
|
|
|
|
EXT2_S_IFMT = 0xF000 ;RUS: маска для типа файла ;ENG: mask for file type
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
;RUS: флаги, указываемые в linked list родительской папки
|
|
|
|
|
;ENG: flags specified in linked list of parent folder
|
|
|
|
|
EXT2_FT_REG_FILE = 1 ;RUS: это файл, запись в родительском каталоге
|
|
|
|
|
;ENG: this is a file, record in parent catalog
|
|
|
|
|
EXT2_FT_DIR = 2 ;RUS: это папка ;ENG: this is a folder
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
;RUS: флаги используемые KolibriOS ;ENG: flags used by KolibriOS
|
2013-05-11 14:38:27 +02:00
|
|
|
|
FS_FT_HIDDEN = 2
|
2013-06-28 10:02:49 +02:00
|
|
|
|
FS_FT_DIR = 0x10 ;RUS: это папка ;ENG: this is a folder
|
|
|
|
|
FS_FT_ASCII = 0 ;RUS: имя в ascii ;ENG: name in ASCII
|
|
|
|
|
FS_FT_UNICODE = 1 ;RUS: имя в unicode ;ENG: name in UNICODE
|
|
|
|
|
|
|
|
|
|
EXT2_FEATURE_INCOMPAT_FILETYPE = 0x0002 ;RUS: тип файла должен указываться в директории
|
|
|
|
|
;ENG: file type must be specified in the folder
|
|
|
|
|
EXT4_FEATURE_INCOMPAT_EXTENTS = 0x0040 ;RUS: экстенты ;ENG: extents
|
|
|
|
|
EXT4_FEATURE_INCOMPAT_FLEX_BG = 0x0200 ;RUS: гибкие группы блоков ;ENG: flexible block groups
|
|
|
|
|
|
|
|
|
|
;RUS: реализованные ext[234] features ;ENG: implemented ext[234] features
|
2012-10-12 20:24:48 +02:00
|
|
|
|
EXT4_FEATURE_INCOMPAT_SUPP = EXT2_FEATURE_INCOMPAT_FILETYPE \
|
|
|
|
|
or EXT4_FEATURE_INCOMPAT_EXTENTS \
|
|
|
|
|
or EXT4_FEATURE_INCOMPAT_FLEX_BG
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
;RUS: флаги, указываемые для inode в i_flags ;ENG: flags specified for inode in i_flags
|
2012-10-12 20:24:48 +02:00
|
|
|
|
EXT2_EXTENTS_FL = 0x00080000
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
struct EXT2_INODE_STRUC
|
|
|
|
|
i_mode dw ?
|
|
|
|
|
i_uid dw ?
|
|
|
|
|
i_size dd ?
|
|
|
|
|
i_atime dd ?
|
|
|
|
|
i_ctime dd ?
|
|
|
|
|
i_mtime dd ?
|
|
|
|
|
i_dtime dd ?
|
|
|
|
|
i_gid dw ?
|
|
|
|
|
i_links_count dw ?
|
|
|
|
|
i_blocks dd ?
|
|
|
|
|
i_flags dd ?
|
|
|
|
|
i_osd1 dd ?
|
|
|
|
|
i_block rd 15
|
|
|
|
|
i_generation dd ?
|
|
|
|
|
i_file_acl dd ?
|
|
|
|
|
i_dir_acl dd ?
|
|
|
|
|
i_faddr dd ?
|
|
|
|
|
i_osd2 dd ? ; 1..12
|
|
|
|
|
ends
|
|
|
|
|
|
|
|
|
|
struct EXT2_DIR_STRUC
|
|
|
|
|
inode dd ?
|
|
|
|
|
rec_len dw ?
|
|
|
|
|
name_len db ?
|
|
|
|
|
file_type db ?
|
|
|
|
|
name db ? ; 0..255
|
|
|
|
|
ends
|
|
|
|
|
|
|
|
|
|
struct EXT2_BLOCK_GROUP_DESC
|
2012-10-12 20:24:48 +02:00
|
|
|
|
block_bitmap dd ? ;+0
|
|
|
|
|
inode_bitmap dd ? ;+4
|
|
|
|
|
inode_table dd ? ;+8
|
|
|
|
|
free_blocks_count dw ? ;+12
|
|
|
|
|
free_inodes_count dw ? ;+14
|
|
|
|
|
used_dirs_count dw ? ;+16
|
|
|
|
|
pad dw ? ;+18
|
|
|
|
|
reserved rb 12;+20
|
2012-03-08 09:33:38 +01:00
|
|
|
|
ends
|
|
|
|
|
|
|
|
|
|
struct EXT2_SB_STRUC
|
|
|
|
|
inodes_count dd ? ;+0
|
|
|
|
|
blocks_count dd ? ;+4
|
|
|
|
|
r_block_count dd ? ;+8
|
|
|
|
|
free_block_count dd ? ;+12
|
|
|
|
|
free_inodes_count dd ? ;+16
|
|
|
|
|
first_data_block dd ? ;+20
|
|
|
|
|
log_block_size dd ? ;+24
|
|
|
|
|
log_frag_size dd ? ;+28
|
|
|
|
|
blocks_per_group dd ? ;+32
|
|
|
|
|
frags_per_group dd ? ;+36
|
|
|
|
|
inodes_per_group dd ? ;+40
|
|
|
|
|
mtime dd ? ;+44
|
|
|
|
|
wtime dd ? ;+48
|
|
|
|
|
mnt_count dw ? ;+52
|
|
|
|
|
max_mnt_count dw ? ;+54
|
|
|
|
|
magic dw ? ;+56
|
|
|
|
|
state dw ? ;+58
|
|
|
|
|
errors dw ? ;+60
|
|
|
|
|
minor_rev_level dw ? ;+62
|
|
|
|
|
lastcheck dd ? ;+64
|
|
|
|
|
check_intervals dd ? ;+68
|
|
|
|
|
creator_os dd ? ;+72
|
|
|
|
|
rev_level dd ? ;+76
|
|
|
|
|
def_resuid dw ? ;+80
|
|
|
|
|
def_resgid dw ? ;+82
|
|
|
|
|
first_ino dd ? ;+84
|
|
|
|
|
inode_size dw ? ;+88
|
|
|
|
|
block_group_nr dw ? ;+90
|
|
|
|
|
feature_compat dd ? ;+92
|
|
|
|
|
feature_incompat dd ? ;+96
|
|
|
|
|
feature_ro_compat dd ? ;+100
|
|
|
|
|
uuid rb 16 ;+104
|
|
|
|
|
volume_name rb 16 ;+120
|
|
|
|
|
last_mounted rb 64 ;+136
|
|
|
|
|
algo_bitmap dd ? ;+200
|
|
|
|
|
prealloc_blocks db ? ;+204
|
|
|
|
|
preallock_dir_blocks db ? ;+205
|
2012-10-12 20:24:48 +02:00
|
|
|
|
reserved_gdt_blocks dw ? ;+206
|
2012-03-08 09:33:38 +01:00
|
|
|
|
journal_uuid rb 16 ;+208
|
|
|
|
|
journal_inum dd ? ;+224
|
|
|
|
|
journal_dev dd ? ;+228
|
|
|
|
|
last_orphan dd ? ;+232
|
|
|
|
|
hash_seed rd 4 ;+236
|
|
|
|
|
def_hash_version db ? ;+252
|
|
|
|
|
rb 3 ;+253 reserved
|
|
|
|
|
default_mount_options dd ? ;+256
|
|
|
|
|
first_meta_bg dd ? ;+260
|
2012-10-12 20:24:48 +02:00
|
|
|
|
mkfs_time dd ? ;+264
|
|
|
|
|
jnl_blocks rd 17 ;+268
|
|
|
|
|
blocks_count_hi dd ? ;+336
|
|
|
|
|
r_blocks_count_hi dd ? ;+340
|
|
|
|
|
free_blocks_count_hi dd ? ;+344
|
|
|
|
|
min_extra_isize dw ? ;+348
|
|
|
|
|
want_extra_isize dw ? ;+350
|
|
|
|
|
flags dd ? ;+352
|
|
|
|
|
raid_stride dw ? ;+356
|
|
|
|
|
mmp_interval dw ? ;+358
|
|
|
|
|
mmp_block dq ? ;+360
|
|
|
|
|
raid_stripe_width dd ? ;+368
|
|
|
|
|
log_groups_per_flex db ? ;+372
|
|
|
|
|
ends
|
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
struct EXT4_EXTENT_HEADER ;RUS: заголовок блока экстентов/индексов
|
|
|
|
|
eh_magic dw ? ;RUS: в текущей реализации ext4 должно быть 0xF30A
|
|
|
|
|
eh_entries dw ? ;RUS: количество экстентов/индексов в блоке
|
|
|
|
|
eh_max dw ? ;RUS: max количество (используется при записи)
|
|
|
|
|
eh_depth dw ? ;RUS: глубина дерева (0, если это блок экстентов)
|
2012-10-12 20:24:48 +02:00
|
|
|
|
eh_generation dd ? ;???
|
|
|
|
|
ends
|
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
struct EXT4_EXTENT ;RUS: экстент ;ENG: extent
|
|
|
|
|
ee_block dd ? ;RUS: номер ext4 блока ;ENG: number of ext4 block
|
|
|
|
|
ee_len dw ? ;RUS: длина экстента ;ENG: extent length
|
|
|
|
|
ee_start_hi dw ? ;RUS: старшие 16 бит 48-битного адреса (пока не используются в KOS)
|
|
|
|
|
;ENG: upper 16 bits of the 48-bit address (not used in KolibriOS yet)
|
|
|
|
|
ee_start_lo dd ? ;RUS: младшие 32 бита 48-битного адреса
|
|
|
|
|
;ENG: lower 32 bits of the 48-bit address
|
2012-10-12 20:24:48 +02:00
|
|
|
|
ends
|
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
struct EXT4_EXTENT_IDX ;RUS: индекс - указатель на блок с экстентами/индексами
|
|
|
|
|
;ENG: index - pointer to block of extents/indexes
|
|
|
|
|
ei_block dd ? ;RUS: номер ext4 блока ;ENG: number of ext4 block
|
|
|
|
|
ei_leaf_lo dd ? ;RUS: младшие 32 бит 48-битного адреса
|
|
|
|
|
;ENG: lower 32 bits of the 48-bit address
|
|
|
|
|
ei_leaf_hi dw ? ;RUS: старшие 16 бит 48-битного адреса (пока не используются в KOS)
|
|
|
|
|
;ENG: upper 16 bits of the 48-bit address (not used in KolibriOS yet)
|
|
|
|
|
ei_unused dw ? ;RUS: зарезервировано ;ENG: reserved
|
2012-03-08 09:33:38 +01:00
|
|
|
|
ends
|
|
|
|
|
|
|
|
|
|
ext2_test_superblock:
|
|
|
|
|
cmp [fs_type], 0x83
|
|
|
|
|
jne .no
|
|
|
|
|
|
|
|
|
|
mov eax, [PARTITION_START]
|
|
|
|
|
add eax, 2 ;superblock start at 1024b
|
|
|
|
|
call hd_read
|
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
cmp [ebx + EXT2_SB_STRUC.log_block_size], 3 ;0,1,2,3
|
2012-03-08 09:33:38 +01:00
|
|
|
|
ja .no
|
2012-10-12 20:24:48 +02:00
|
|
|
|
cmp [ebx + EXT2_SB_STRUC.magic], 0xEF53
|
2012-03-08 09:33:38 +01:00
|
|
|
|
jne .no
|
2012-10-12 20:24:48 +02:00
|
|
|
|
cmp [ebx + EXT2_SB_STRUC.state], 1 ;EXT_VALID_FS=1
|
2012-03-08 09:33:38 +01:00
|
|
|
|
jne .no
|
2012-10-12 20:24:48 +02:00
|
|
|
|
cmp [ebx + EXT2_SB_STRUC.inodes_per_group], 0
|
|
|
|
|
je .no
|
|
|
|
|
|
|
|
|
|
mov eax, [ebx + EXT2_SB_STRUC.feature_incompat]
|
2012-03-08 09:33:38 +01:00
|
|
|
|
test eax, EXT2_FEATURE_INCOMPAT_FILETYPE
|
|
|
|
|
jz .no
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, not EXT4_FEATURE_INCOMPAT_SUPP
|
2012-03-08 09:33:38 +01:00
|
|
|
|
jnz .no
|
|
|
|
|
|
|
|
|
|
; OK, this is correct EXT2 superblock
|
|
|
|
|
clc
|
|
|
|
|
ret
|
|
|
|
|
.no:
|
|
|
|
|
; No, this superblock isn't EXT2
|
|
|
|
|
stc
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
ext2_setup:
|
|
|
|
|
mov [fs_type], 2
|
|
|
|
|
|
|
|
|
|
push 512
|
|
|
|
|
call kernel_alloc ; mem for superblock
|
|
|
|
|
mov esi, ebx
|
|
|
|
|
mov edi, eax
|
|
|
|
|
mov ecx, 512/4
|
|
|
|
|
rep movsd ; copy sb to reserved mem
|
|
|
|
|
mov ebx, eax
|
|
|
|
|
mov [ext2_data.sb], eax
|
|
|
|
|
|
|
|
|
|
mov eax, [ebx + EXT2_SB_STRUC.blocks_count]
|
|
|
|
|
sub eax, [ebx + EXT2_SB_STRUC.first_data_block]
|
|
|
|
|
dec eax
|
|
|
|
|
xor edx, edx
|
|
|
|
|
div [ebx + EXT2_SB_STRUC.blocks_per_group]
|
|
|
|
|
inc eax
|
|
|
|
|
mov [ext2_data.groups_count], eax
|
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
mov ecx, [ebx + EXT2_SB_STRUC.log_block_size]
|
2012-03-08 09:33:38 +01:00
|
|
|
|
inc ecx
|
|
|
|
|
mov [ext2_data.log_block_size], ecx ; 1, 2, 3, 4 equ 1kb, 2kb, 4kb, 8kb
|
|
|
|
|
|
|
|
|
|
mov eax, 1
|
|
|
|
|
shl eax, cl
|
|
|
|
|
mov [ext2_data.count_block_in_block], eax
|
|
|
|
|
|
|
|
|
|
shl eax, 7
|
|
|
|
|
mov [ext2_data.count_pointer_in_block], eax
|
2013-06-28 10:02:49 +02:00
|
|
|
|
mov edx, eax ;RUS: потом еще квадрат найдем ;ENG: we'll find a square later
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
shl eax, 2
|
|
|
|
|
mov [ext2_data.block_size], eax
|
|
|
|
|
|
|
|
|
|
push eax eax ; 2 kernel_alloc
|
|
|
|
|
|
|
|
|
|
mov eax, edx
|
|
|
|
|
mul edx
|
|
|
|
|
mov [ext2_data.count_pointer_in_block_square], eax
|
|
|
|
|
|
|
|
|
|
call kernel_alloc
|
|
|
|
|
mov [ext2_data.ext2_save_block], eax ; and for temp block
|
|
|
|
|
call kernel_alloc
|
|
|
|
|
mov [ext2_data.ext2_temp_block], eax ; and for get_inode proc
|
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
movzx ebp, word [ebx + EXT2_SB_STRUC.inode_size]
|
|
|
|
|
mov ecx, [ebx + EXT2_SB_STRUC.blocks_per_group]
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
mov [ext2_data.inode_size], ebp
|
|
|
|
|
mov [ext2_data.blocks_per_group], ecx
|
|
|
|
|
|
|
|
|
|
push ebp ebp ebp ;3 kernel_alloc
|
|
|
|
|
call kernel_alloc
|
|
|
|
|
mov [ext2_data.ext2_save_inode], eax
|
|
|
|
|
call kernel_alloc
|
|
|
|
|
mov [ext2_data.ext2_temp_inode], eax
|
|
|
|
|
call kernel_alloc
|
|
|
|
|
mov [ext2_data.root_inode], eax
|
|
|
|
|
|
|
|
|
|
mov ebx, eax
|
|
|
|
|
mov eax, EXT2_ROOT_INO
|
|
|
|
|
call ext2_get_inode ; read root inode
|
|
|
|
|
|
|
|
|
|
jmp return_from_part_set
|
|
|
|
|
|
|
|
|
|
;==================================================================
|
2012-10-12 20:24:48 +02:00
|
|
|
|
;read ext2 block form FS to memory
|
|
|
|
|
;in: eax = i_block (address of block in ext2 terms)
|
2013-05-11 14:38:27 +02:00
|
|
|
|
; ebx = pointer to return memory
|
2012-10-12 20:24:48 +02:00
|
|
|
|
;out: eax - error code (0 = no_error)
|
2012-03-08 09:33:38 +01:00
|
|
|
|
ext2_get_block:
|
2012-10-12 20:24:48 +02:00
|
|
|
|
push ebx ecx
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov ecx, [ext2_data.log_block_size]
|
|
|
|
|
shl eax, cl
|
|
|
|
|
add eax, [PARTITION_START]
|
|
|
|
|
mov ecx, [ext2_data.count_block_in_block]
|
|
|
|
|
@@:
|
|
|
|
|
call hd_read
|
2012-10-12 20:24:48 +02:00
|
|
|
|
cmp [hd_error], 0
|
|
|
|
|
jnz .fail
|
2012-03-08 09:33:38 +01:00
|
|
|
|
inc eax
|
|
|
|
|
add ebx, 512
|
|
|
|
|
loop @B
|
2012-10-12 20:24:48 +02:00
|
|
|
|
xor eax, eax
|
|
|
|
|
@@:
|
|
|
|
|
pop ecx ebx
|
|
|
|
|
ret
|
|
|
|
|
.fail:
|
|
|
|
|
mov eax, ERROR_DEVICE
|
|
|
|
|
jmp @B
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;===================================================================
|
2013-06-28 10:02:49 +02:00
|
|
|
|
;RUS: получает номер блока из extent inode ;ENG: receives block number from extent inode
|
|
|
|
|
;RUS: in: ecx = номер блока по порядку ;ENG: in: ecx = consecutive block number
|
|
|
|
|
;RUS: ebp = адрес extent header`а ;ENG: ebp = address of extent header
|
|
|
|
|
;RUS: out: ecx - адрес очередного блока в случае успеха ;ENG: out: ecx - address of next block, if successful
|
|
|
|
|
;RUS: eax - номер ошибки (если равно 0, то ошибки нет) ;ENG: eax - error number (0 - no error)
|
2012-10-12 20:24:48 +02:00
|
|
|
|
ext4_block_recursive_search:
|
|
|
|
|
cmp word [ebp + EXT4_EXTENT_HEADER.eh_magic], 0xF30A ;EXT4_EXT_MAGIC
|
|
|
|
|
jne .fail
|
|
|
|
|
|
|
|
|
|
movzx ebx, [ebp + EXT4_EXTENT_HEADER.eh_entries]
|
|
|
|
|
add ebp, sizeof.EXT4_EXTENT_HEADER
|
|
|
|
|
cmp word [ebp - sizeof.EXT4_EXTENT_HEADER + EXT4_EXTENT_HEADER.eh_depth], 0
|
|
|
|
|
je .leaf_block ;листовой ли это блок?
|
|
|
|
|
|
|
|
|
|
;не листовой блок, а индексный ; eax - ext4_extent_idx
|
|
|
|
|
test ebx, ebx
|
|
|
|
|
jz .fail ;пустой индексный блок -> ошибка
|
|
|
|
|
|
|
|
|
|
;цикл по индексам экстентов
|
|
|
|
|
@@:
|
|
|
|
|
cmp ebx, 1 ;у индексов не хранится длина,
|
|
|
|
|
je .end_search_index ;поэтому, если остался последний - то это нужный
|
|
|
|
|
|
|
|
|
|
cmp ecx, [ebp + EXT4_EXTENT_IDX.ei_block]
|
|
|
|
|
jb .fail
|
|
|
|
|
|
|
|
|
|
cmp ecx, [ebp + sizeof.EXT4_EXTENT_IDX + EXT4_EXTENT_IDX.ei_block] ;блок слeдующего индекса
|
|
|
|
|
jb .end_search_index ;следующий дальше - значит текущий, то что нам нужен
|
|
|
|
|
|
|
|
|
|
add ebp, sizeof.EXT4_EXTENT_IDX
|
|
|
|
|
dec ebx
|
|
|
|
|
jmp @B
|
|
|
|
|
|
|
|
|
|
.end_search_index:
|
|
|
|
|
;ebp указывает на нужный extent_idx, считываем следующий блок
|
|
|
|
|
mov ebx, [ext2_data.ext2_temp_block]
|
|
|
|
|
mov eax, [ebp + EXT4_EXTENT_IDX.ei_leaf_lo]
|
|
|
|
|
call ext2_get_block
|
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .fail
|
|
|
|
|
mov ebp, ebx
|
|
|
|
|
jmp ext4_block_recursive_search ;рекурсивно прыгаем в начало
|
|
|
|
|
|
|
|
|
|
.leaf_block: ;листовой блок ebp - ext4_extent
|
|
|
|
|
;цикл по экстентам
|
|
|
|
|
@@:
|
|
|
|
|
test ebx, ebx
|
|
|
|
|
jz .fail ;ни один узел не подошел - ошибка
|
|
|
|
|
|
|
|
|
|
mov edx, [ebp + EXT4_EXTENT.ee_block]
|
|
|
|
|
cmp ecx, edx
|
|
|
|
|
jb .fail ;если меньше, значит он был в предыдущих блоках -> ошибка
|
|
|
|
|
|
|
|
|
|
movzx edi, [ebp + EXT4_EXTENT.ee_len]
|
|
|
|
|
add edx, edi
|
|
|
|
|
cmp ecx, edx
|
|
|
|
|
jb .end_search_extent ;нашли нужный блок
|
|
|
|
|
|
|
|
|
|
add ebp, sizeof.EXT4_EXTENT
|
|
|
|
|
dec ebx
|
|
|
|
|
jmp @B
|
|
|
|
|
|
|
|
|
|
.end_search_extent:
|
|
|
|
|
mov edx, [ebp + EXT4_EXTENT.ee_start_lo]
|
|
|
|
|
sub ecx, [ebp + EXT4_EXTENT.ee_block] ;разница в ext4 блоках
|
|
|
|
|
add ecx, edx
|
|
|
|
|
xor eax, eax
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
.fail:
|
|
|
|
|
mov eax, ERROR_FS_FAIL
|
2012-03-08 09:33:38 +01:00
|
|
|
|
ret
|
2012-10-12 20:24:48 +02:00
|
|
|
|
|
2012-03-08 09:33:38 +01:00
|
|
|
|
;===================================================================
|
2012-10-12 20:24:48 +02:00
|
|
|
|
;получает адрес ext2 блока из inode с определнным номером
|
2013-06-28 10:02:49 +02:00
|
|
|
|
;RUS: in: ecx = номер блока в inode (0..) ;ENG: in: ecx = number of block in inode (0..)
|
|
|
|
|
;RUS: ebp = адрес inode ;ENG: ebp = inode address
|
|
|
|
|
;RUS: out: ecx = адрес очередного блока ;ENG: out: ecx = next block address
|
|
|
|
|
;RUS: eax - error code ;ENG: eax - error code
|
2012-03-08 09:33:38 +01:00
|
|
|
|
ext2_get_inode_block:
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test [ebp + EXT2_INODE_STRUC.i_flags], EXT2_EXTENTS_FL
|
|
|
|
|
jz @F
|
|
|
|
|
|
|
|
|
|
pushad
|
|
|
|
|
add ebp, EXT2_INODE_STRUC.i_block ;ebp - extent_header
|
|
|
|
|
call ext4_block_recursive_search
|
|
|
|
|
mov PUSHAD_ECX, ecx
|
|
|
|
|
mov PUSHAD_EAX, eax
|
|
|
|
|
popad
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
@@:
|
2012-03-08 09:33:38 +01:00
|
|
|
|
cmp ecx, 12 ; 0..11 - direct block address
|
|
|
|
|
jb .get_direct_block
|
|
|
|
|
|
|
|
|
|
sub ecx, 12
|
2012-10-12 20:24:48 +02:00
|
|
|
|
cmp ecx, [ext2_data.count_pointer_in_block] ; 12.. - indirect blocks
|
2012-03-08 09:33:38 +01:00
|
|
|
|
jb .get_indirect_block
|
|
|
|
|
|
|
|
|
|
sub ecx, [ext2_data.count_pointer_in_block]
|
|
|
|
|
cmp ecx, [ext2_data.count_pointer_in_block_square]
|
|
|
|
|
jb .get_double_indirect_block
|
|
|
|
|
|
|
|
|
|
sub ecx, [ext2_data.count_pointer_in_block_square]
|
2012-10-12 20:24:48 +02:00
|
|
|
|
;triple indirect block
|
|
|
|
|
push edx ebx
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
mov eax, [ebx + EXT2_INODE_STRUC.i_block + 14*4]
|
|
|
|
|
mov ebx, [ext2_data.ext2_temp_block]
|
|
|
|
|
call ext2_get_block
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .fail
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
xor edx, edx
|
|
|
|
|
mov eax, ecx
|
|
|
|
|
div [ext2_data.count_pointer_in_block_square]
|
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
;RUS: eax - номер в полученном блоке edx - номер дальше
|
|
|
|
|
;ENG: eax - current block number, edx - next block number
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov eax, [ebx + eax*4]
|
|
|
|
|
call ext2_get_block
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .fail
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
mov eax, edx
|
|
|
|
|
jmp @F
|
|
|
|
|
|
|
|
|
|
.get_double_indirect_block:
|
2012-10-12 20:24:48 +02:00
|
|
|
|
push edx ebx
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
mov eax, [ebp + EXT2_INODE_STRUC.i_block + 13*4]
|
|
|
|
|
mov ebx, [ext2_data.ext2_temp_block]
|
|
|
|
|
call ext2_get_block
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .fail
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
mov eax, ecx
|
2013-05-11 14:38:27 +02:00
|
|
|
|
@@:
|
2012-03-08 09:33:38 +01:00
|
|
|
|
xor edx, edx
|
|
|
|
|
div [ext2_data.count_pointer_in_block]
|
|
|
|
|
|
|
|
|
|
mov eax, [ebx + eax*4]
|
|
|
|
|
call ext2_get_block
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .fail
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
mov ecx, [ebx + edx*4]
|
|
|
|
|
.fail:
|
|
|
|
|
pop ebx edx
|
2012-03-08 09:33:38 +01:00
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
.get_indirect_block:
|
2012-10-12 20:24:48 +02:00
|
|
|
|
push ebx
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov eax, [ebp + EXT2_INODE_STRUC.i_block + 12*4]
|
|
|
|
|
mov ebx, [ext2_data.ext2_temp_block]
|
|
|
|
|
call ext2_get_block
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
2013-06-28 10:02:49 +02:00
|
|
|
|
jnz @F ;RUS: если не было ошибки ;ENG: if there was no error
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
mov ecx, [ebx + ecx*4] ;RUS: заносим результат ;ENG: ???
|
2012-10-12 20:24:48 +02:00
|
|
|
|
@@:
|
|
|
|
|
pop ebx
|
2012-03-08 09:33:38 +01:00
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
.get_direct_block:
|
2012-10-12 20:24:48 +02:00
|
|
|
|
mov ecx, [ebp + EXT2_INODE_STRUC.i_block + ecx*4]
|
|
|
|
|
xor eax, eax
|
2012-03-08 09:33:38 +01:00
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;===================================================================
|
|
|
|
|
;get content inode by num
|
2013-05-11 14:38:27 +02:00
|
|
|
|
;in: eax = inode_num
|
|
|
|
|
; ebx = address of inode content
|
2012-10-12 20:24:48 +02:00
|
|
|
|
;out: eax - error code
|
2012-03-08 09:33:38 +01:00
|
|
|
|
ext2_get_inode:
|
|
|
|
|
pushad
|
|
|
|
|
mov edi, ebx ;сохраним адрес inode
|
|
|
|
|
dec eax
|
|
|
|
|
xor edx, edx
|
2012-10-12 20:24:48 +02:00
|
|
|
|
|
|
|
|
|
mov ecx, [ext2_data.sb]
|
|
|
|
|
div [ecx + EXT2_SB_STRUC.inodes_per_group]
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
push edx ;locale num in group
|
|
|
|
|
|
|
|
|
|
mov edx, 32
|
|
|
|
|
mul edx ; address block_group in global_desc_table
|
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
;RUS: в eax - смещение группы с inode-ом относительно начала глобальной дескрипторной таблицы
|
|
|
|
|
;RUS: найдем блок в котором он находится
|
|
|
|
|
;ENG: in eax - inode group offset relative to global descriptor table start
|
|
|
|
|
;ENG: let's find the block this inode is in
|
2012-03-08 09:33:38 +01:00
|
|
|
|
div [ext2_data.block_size]
|
|
|
|
|
add eax, [ecx + EXT2_SB_STRUC.first_data_block]
|
|
|
|
|
inc eax
|
|
|
|
|
mov ebx, [ext2_data.ext2_temp_block]
|
|
|
|
|
call ext2_get_block
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .fail
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
add ebx, edx ;RUS: локальный номер в блоке ;ENG: local number inside block
|
|
|
|
|
mov eax, [ebx + EXT2_BLOCK_GROUP_DESC.inode_table] ;RUS: номер блока - в терминах ext2
|
|
|
|
|
;ENG: block number - in ext2 terms
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov ecx, [ext2_data.log_block_size]
|
|
|
|
|
shl eax, cl
|
2013-06-28 10:02:49 +02:00
|
|
|
|
add eax, [PARTITION_START] ;RUS: а старт раздела - в терминах hdd (512)
|
|
|
|
|
;ENG: partition start - in HDD terms (512)
|
|
|
|
|
;RUS: eax - указывает на таблицу inode-ов на hdd ;ENG: eax - points to inode table on HDD
|
|
|
|
|
mov esi, eax ;RUS: сохраним его пока в esi ;ENG: let's save it in esi for now
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
;RUS: прибавим локальный адрес inode-а ;ENG: add local address of inode
|
2012-03-08 09:33:38 +01:00
|
|
|
|
pop eax ; index
|
|
|
|
|
mov ecx, [ext2_data.inode_size]
|
|
|
|
|
mul ecx ; (index * inode_size)
|
|
|
|
|
mov ebp, 512
|
2013-06-28 10:02:49 +02:00
|
|
|
|
div ebp ;RUS: поделим на размер блока ;ENG: divide by block size
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
add eax, esi ;RUS: нашли адрес блока для чтения ;ENG: found block address to read
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov ebx, [ext2_data.ext2_temp_block]
|
|
|
|
|
call hd_read
|
2012-10-12 20:24:48 +02:00
|
|
|
|
cmp [hd_error], 0
|
|
|
|
|
jnz .fail
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
mov esi, edx ;RUS: добавим "остаток" ;ENG: add the "remainder"
|
|
|
|
|
add esi, ebx ;RUS: к адресу ;ENG: to the address
|
|
|
|
|
rep movsb ;RUS: копируем inode ;ENG: copy inode
|
2012-10-12 20:24:48 +02:00
|
|
|
|
xor eax, eax
|
|
|
|
|
.fail:
|
|
|
|
|
mov PUSHAD_EAX, eax
|
2012-03-08 09:33:38 +01:00
|
|
|
|
popad
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
|
;
|
|
|
|
|
; ext2_HdReadFolder - read disk folder
|
|
|
|
|
;
|
|
|
|
|
; esi points to filename
|
|
|
|
|
; ebx pointer to structure 32-bit number = first wanted block, 0+
|
|
|
|
|
; & flags (bitfields)
|
|
|
|
|
; flags: bit 0: 0=ANSI names, 1=UNICODE names
|
|
|
|
|
; ecx number of blocks to read, 0+
|
|
|
|
|
; edx mem location to return data
|
|
|
|
|
;
|
|
|
|
|
; ret ebx = blocks read or 0xffffffff folder not found
|
|
|
|
|
; eax = 0 ok read or other = errormsg
|
|
|
|
|
;
|
|
|
|
|
;--------------------------------------------------------------
|
|
|
|
|
ext2_HdReadFolder:
|
|
|
|
|
cmp byte [esi], 0
|
2012-10-12 20:24:48 +02:00
|
|
|
|
jz .root_folder
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
push ebx ecx edx
|
|
|
|
|
call ext2_find_lfn ;вернет в ebp адрес inode
|
|
|
|
|
pop edx ecx ebx
|
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_ret
|
|
|
|
|
test [ebp + EXT2_INODE_STRUC.i_mode], EXT2_S_IFDIR
|
|
|
|
|
jz .error_not_found
|
|
|
|
|
jmp @F
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
.root_folder:
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov ebp, [ext2_data.root_inode]
|
|
|
|
|
test [ebp + EXT2_INODE_STRUC.i_mode], EXT2_S_IFDIR
|
2012-10-12 20:24:48 +02:00
|
|
|
|
jz .error_root
|
|
|
|
|
;придется копировать inode
|
|
|
|
|
push ecx
|
|
|
|
|
mov esi, ebp
|
|
|
|
|
mov edi, [ext2_data.ext2_save_inode]
|
|
|
|
|
mov ecx, [ext2_data.inode_size]
|
|
|
|
|
shr ecx, 2
|
|
|
|
|
mov ebp, edi
|
|
|
|
|
rep movsd
|
|
|
|
|
pop ecx
|
2012-03-08 09:33:38 +01:00
|
|
|
|
@@:
|
2013-05-11 14:38:27 +02:00
|
|
|
|
cmp [ebp + EXT2_INODE_STRUC.i_size], 0 ;папка пуста
|
2012-10-12 20:24:48 +02:00
|
|
|
|
je .error_empty_dir
|
|
|
|
|
|
|
|
|
|
push edx ;адрес результата [edi + 28]
|
|
|
|
|
push 0 ;конец очередного блока папки [edi + 24]
|
|
|
|
|
push ecx ;сколько файлов нужно прочитать [edi + 20]
|
|
|
|
|
push dword [ebx] ;первый "нужный" файл [edi + 16]
|
|
|
|
|
push dword [ebx + 4];флаги [edi + 12]
|
|
|
|
|
push 0 ;[EXT2_read_in_folder] [edi + 8]
|
|
|
|
|
push 0 ;[EXT2_files_in_folder] [edi + 4]
|
|
|
|
|
push 0 ;номер блока по порядку [edi]
|
|
|
|
|
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov edi, edx
|
|
|
|
|
mov ecx, 32/4
|
|
|
|
|
rep stosd ; fill header zero
|
2013-05-11 14:38:27 +02:00
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
mov edi, esp ; edi - указатель на локальные переменные
|
|
|
|
|
add edx, 32 ; edx = current mem for return
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
xor ecx, ecx ; получим номер первого блока
|
2012-03-08 09:33:38 +01:00
|
|
|
|
call ext2_get_inode_block
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_get_block
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
mov eax, ecx
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_block]
|
|
|
|
|
call ext2_get_block ; и считываем блок с hdd
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_get_block
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
mov esi, ebx ; esi = current dir record
|
2012-03-08 09:33:38 +01:00
|
|
|
|
add ebx, [ext2_data.block_size]
|
2012-10-12 20:24:48 +02:00
|
|
|
|
mov [edi + 24], ebx ; запомним конец очередного блока
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
mov ecx, [edi + 16] ; ecx = first wanted (flags ommited)
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
.find_wanted_start:
|
|
|
|
|
jecxz .find_wanted_end
|
|
|
|
|
.find_wanted_cycle:
|
2012-10-12 20:24:48 +02:00
|
|
|
|
cmp [esi + EXT2_DIR_STRUC.inode], 0 ; if (inode = 0) => not used
|
2012-03-08 09:33:38 +01:00
|
|
|
|
jz @F
|
2012-10-12 20:24:48 +02:00
|
|
|
|
inc dword [edi + 4] ; EXT2_files_in_folder
|
2012-03-08 09:33:38 +01:00
|
|
|
|
dec ecx
|
2013-05-11 14:38:27 +02:00
|
|
|
|
@@:
|
2012-10-12 20:24:48 +02:00
|
|
|
|
movzx ebx, [esi + EXT2_DIR_STRUC.rec_len]
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
cmp ebx, 12 ; минимальная длина записи
|
2012-10-12 20:24:48 +02:00
|
|
|
|
jb .error_bad_len
|
2012-03-08 09:33:38 +01:00
|
|
|
|
test ebx, 0x3 ; длина записи должна делиться на 4
|
2012-10-12 20:24:48 +02:00
|
|
|
|
jnz .error_bad_len
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2013-05-11 14:38:27 +02:00
|
|
|
|
sub [ebp + EXT2_INODE_STRUC.i_size], ebx ;вычитаем напрямую из структуры inode
|
2012-10-12 20:24:48 +02:00
|
|
|
|
add esi, ebx ; к следующей записи
|
|
|
|
|
cmp esi, [edi + 24] ; сравниваем с концом блока
|
2012-03-08 09:33:38 +01:00
|
|
|
|
jb .find_wanted_start
|
|
|
|
|
|
|
|
|
|
push .find_wanted_start
|
2012-10-12 20:24:48 +02:00
|
|
|
|
.end_block: ;вылетели из цикла
|
2013-05-11 14:38:27 +02:00
|
|
|
|
cmp [ebp + EXT2_INODE_STRUC.i_size], 0
|
2012-10-12 20:24:48 +02:00
|
|
|
|
jle .end_dir
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
inc dword [edi] ;получаем новый блок
|
2012-03-08 09:33:38 +01:00
|
|
|
|
push ecx
|
2012-10-12 20:24:48 +02:00
|
|
|
|
mov ecx, [edi]
|
2012-03-08 09:33:38 +01:00
|
|
|
|
call ext2_get_inode_block
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_get_block
|
|
|
|
|
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov eax, ecx
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_block]
|
|
|
|
|
call ext2_get_block
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_get_block
|
|
|
|
|
|
2012-03-08 09:33:38 +01:00
|
|
|
|
pop ecx
|
2012-10-12 20:24:48 +02:00
|
|
|
|
mov esi, ebx
|
2012-03-08 09:33:38 +01:00
|
|
|
|
add ebx, [ext2_data.block_size]
|
2012-10-12 20:24:48 +02:00
|
|
|
|
mov [edi + 24], ebx ;запомним конец блока
|
2013-05-11 14:38:27 +02:00
|
|
|
|
ret ; опять в цикл
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
.wanted_end:
|
2012-10-12 20:24:48 +02:00
|
|
|
|
loop .find_wanted_cycle ; ecx 0 => -1 нужно посчитать сколько файлов
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
;дошли до первого "нужного" файла
|
2012-03-08 09:33:38 +01:00
|
|
|
|
.find_wanted_end:
|
2012-10-12 20:24:48 +02:00
|
|
|
|
mov ecx, [edi + 20]
|
2013-05-11 14:38:27 +02:00
|
|
|
|
.wanted_start: ; ищем first_wanted+count
|
2012-03-08 09:33:38 +01:00
|
|
|
|
jecxz .wanted_end
|
2012-10-12 20:24:48 +02:00
|
|
|
|
cmp [esi + EXT2_DIR_STRUC.inode], 0 ; if (inode = 0) => not used
|
2012-03-08 09:33:38 +01:00
|
|
|
|
jz .empty_rec
|
2012-10-12 20:24:48 +02:00
|
|
|
|
inc dword [edi + 8]
|
|
|
|
|
inc dword [edi + 4]
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
push edi ecx
|
|
|
|
|
mov edi, edx ;обнуляем место под очереное имя файла/папки
|
2012-03-08 09:33:38 +01:00
|
|
|
|
xor eax, eax
|
|
|
|
|
mov ecx, 40 / 4
|
|
|
|
|
rep stosd
|
2012-10-12 20:24:48 +02:00
|
|
|
|
pop ecx edi
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
push esi edi edx
|
|
|
|
|
mov eax, [esi + EXT2_DIR_STRUC.inode] ;получим дочерний inode
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov ebx, [ext2_data.ext2_temp_inode]
|
|
|
|
|
call ext2_get_inode
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_read_subinode
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
lea edi, [edx + 8]
|
|
|
|
|
|
2013-05-11 14:38:27 +02:00
|
|
|
|
mov eax, [ebx + EXT2_INODE_STRUC.i_ctime] ; переведем время в ntfs формат
|
2012-03-08 09:33:38 +01:00
|
|
|
|
xor edx, edx
|
|
|
|
|
add eax, 3054539008 ;(369 * 365 + 89) * 24 * 3600
|
|
|
|
|
adc edx, 2
|
|
|
|
|
call ntfs_datetime_to_bdfe.sec
|
|
|
|
|
|
|
|
|
|
mov eax, [ebx + EXT2_INODE_STRUC.i_atime]
|
|
|
|
|
xor edx, edx
|
|
|
|
|
add eax, 3054539008
|
|
|
|
|
adc edx, 2
|
|
|
|
|
call ntfs_datetime_to_bdfe.sec
|
|
|
|
|
|
|
|
|
|
mov eax, [ebx + EXT2_INODE_STRUC.i_mtime]
|
|
|
|
|
xor edx, edx
|
|
|
|
|
add eax, 3054539008
|
|
|
|
|
adc edx, 2
|
|
|
|
|
call ntfs_datetime_to_bdfe.sec
|
|
|
|
|
|
|
|
|
|
pop edx ; пока достаем только буфер
|
2013-05-11 14:38:27 +02:00
|
|
|
|
test [ebx + EXT2_INODE_STRUC.i_mode], EXT2_S_IFDIR ; для папки размер
|
2012-03-08 09:33:38 +01:00
|
|
|
|
jnz @F ; не возвращаем
|
|
|
|
|
|
2013-05-11 14:38:27 +02:00
|
|
|
|
mov eax, [ebx + EXT2_INODE_STRUC.i_size] ;low size
|
2012-03-08 09:33:38 +01:00
|
|
|
|
stosd
|
2013-05-11 14:38:27 +02:00
|
|
|
|
mov eax, [ebx + EXT2_INODE_STRUC.i_dir_acl] ;high size
|
2012-03-08 09:33:38 +01:00
|
|
|
|
stosd
|
2012-10-12 20:24:48 +02:00
|
|
|
|
xor dword [edx], FS_FT_DIR ;помечаем, что это файл(2 раза xor)
|
2013-05-11 14:38:27 +02:00
|
|
|
|
@@:
|
2012-10-12 20:24:48 +02:00
|
|
|
|
xor dword [edx], FS_FT_DIR ;помечаем, что это файл
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2013-05-11 14:38:27 +02:00
|
|
|
|
;теперь скопируем имя, сконвертировав из UTF-8 в CP866
|
2012-10-12 20:24:48 +02:00
|
|
|
|
push ecx ;edi и esi уже сохранены в стеке
|
|
|
|
|
movzx ecx, [esi + EXT2_DIR_STRUC.name_len]
|
2012-03-08 09:33:38 +01:00
|
|
|
|
lea edi, [edx + 40]
|
2012-10-12 20:24:48 +02:00
|
|
|
|
lea esi, [esi + EXT2_DIR_STRUC.name]
|
|
|
|
|
call utf8_to_cp866
|
2012-03-08 09:33:38 +01:00
|
|
|
|
and byte [edi], 0
|
2012-10-12 20:24:48 +02:00
|
|
|
|
pop ecx edi esi
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
cmp byte [edx + 40], '.' ; в linux файл, начинающийся с точки - скрытый
|
2012-03-08 09:33:38 +01:00
|
|
|
|
jne @F
|
|
|
|
|
or dword [edx], FS_FT_HIDDEN
|
2013-05-11 14:38:27 +02:00
|
|
|
|
@@:
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
add edx, 40 + 264 ; go to next record
|
|
|
|
|
dec ecx ; если запись пустая ecx не надо уменьшать
|
2013-05-11 14:38:27 +02:00
|
|
|
|
.empty_rec:
|
2012-10-12 20:24:48 +02:00
|
|
|
|
movzx ebx, [esi + EXT2_DIR_STRUC.rec_len]
|
2012-03-08 09:33:38 +01:00
|
|
|
|
cmp ebx, 12 ; минимальная длина записи
|
2012-10-12 20:24:48 +02:00
|
|
|
|
jb .error_bad_len
|
2012-03-08 09:33:38 +01:00
|
|
|
|
test ebx, 0x3 ; длина записи должна делиться на 4
|
2012-10-12 20:24:48 +02:00
|
|
|
|
jnz .error_bad_len
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2013-05-11 14:38:27 +02:00
|
|
|
|
sub [ebp + EXT2_INODE_STRUC.i_size], ebx ;вычитаем напрямую из структуры inode
|
2012-10-12 20:24:48 +02:00
|
|
|
|
add esi, ebx
|
|
|
|
|
cmp esi, [edi + 24] ;дошли ли до конца блока?
|
2012-03-08 09:33:38 +01:00
|
|
|
|
jb .wanted_start
|
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
push .wanted_start ; дошли
|
2012-03-08 09:33:38 +01:00
|
|
|
|
jmp .end_block
|
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
.end_dir: ;конец папки, когда еще не дошли до нужного файла
|
|
|
|
|
mov edx, [edi + 28] ;адрес структуры результата
|
|
|
|
|
mov ebx, [edi + 8] ;EXT2_read_in_folder
|
|
|
|
|
mov ecx, [edi + 4] ;EXT2_files_in_folder
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov dword [edx], 1 ;version
|
2012-10-12 20:24:48 +02:00
|
|
|
|
mov [edx + 4], ebx
|
|
|
|
|
mov [edx + 8], ecx
|
|
|
|
|
|
|
|
|
|
lea esp, [edi + 32]
|
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
xor eax, eax ;RUS: зарезервировано: нули в текущей реализации
|
|
|
|
|
;ENG: reserved: zeros in current implementation
|
2012-03-08 09:33:38 +01:00
|
|
|
|
lea edi, [edx + 12]
|
|
|
|
|
mov ecx, 20 / 4
|
|
|
|
|
rep stosd
|
|
|
|
|
ret
|
2012-10-12 20:24:48 +02:00
|
|
|
|
|
|
|
|
|
.error_bad_len:
|
|
|
|
|
mov eax, ERROR_FS_FAIL
|
|
|
|
|
.error_read_subinode:
|
|
|
|
|
.error_get_block:
|
|
|
|
|
lea esp, [edi + 32]
|
|
|
|
|
.error_ret:
|
|
|
|
|
or ebx, -1
|
|
|
|
|
ret
|
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
.error_empty_dir: ;RUS: inode папки без блоков ;ENG: inode of folder without blocks
|
|
|
|
|
.error_root: ;RUS: root - не папка ;ENG: root is not a folder
|
2012-10-12 20:24:48 +02:00
|
|
|
|
mov eax, ERROR_FS_FAIL
|
|
|
|
|
jmp .error_ret
|
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
.error_not_found: ;RUS: файл не найден ;ENG: file not found
|
2012-10-12 20:24:48 +02:00
|
|
|
|
mov eax, ERROR_FILE_NOT_FOUND
|
|
|
|
|
jmp .error_ret
|
|
|
|
|
|
|
|
|
|
;============================================
|
|
|
|
|
;convert UTF-8 string to ASCII-string (codepage 866)
|
|
|
|
|
;in: ecx = length source
|
|
|
|
|
; esi = source
|
|
|
|
|
; edi = buffer
|
2012-03-08 09:33:38 +01:00
|
|
|
|
; destroys: eax,esi,edi
|
2012-10-12 20:24:48 +02:00
|
|
|
|
utf8_to_cp866:
|
2012-03-08 09:33:38 +01:00
|
|
|
|
jecxz .ret
|
|
|
|
|
.start:
|
|
|
|
|
lodsw
|
2010-10-01 11:21:55 +02:00
|
|
|
|
cmp al, 0x80
|
2012-03-08 09:33:38 +01:00
|
|
|
|
jb .ascii
|
|
|
|
|
|
|
|
|
|
xchg al, ah ; big-endian
|
|
|
|
|
cmp ax, 0xd080
|
|
|
|
|
jz .yo1
|
|
|
|
|
cmp ax, 0xd191
|
|
|
|
|
jz .yo2
|
|
|
|
|
cmp ax, 0xd090
|
2010-10-01 11:21:55 +02:00
|
|
|
|
jb .unk
|
|
|
|
|
cmp ax, 0xd180
|
|
|
|
|
jb .rus1
|
|
|
|
|
cmp ax, 0xd190
|
2012-03-08 09:33:38 +01:00
|
|
|
|
jb .rus2
|
|
|
|
|
.unk:
|
|
|
|
|
mov al, '_'
|
|
|
|
|
jmp .doit
|
|
|
|
|
.yo1:
|
|
|
|
|
mov al, 0xf0 ; Ё capital
|
|
|
|
|
jmp .doit
|
|
|
|
|
.yo2:
|
|
|
|
|
mov al, 0xf1 ; ё small
|
|
|
|
|
jmp .doit
|
|
|
|
|
.rus1:
|
|
|
|
|
sub ax, 0xd090 - 0x80
|
|
|
|
|
jmp .doit
|
|
|
|
|
.rus2:
|
|
|
|
|
sub ax, 0xd18f - 0xEF
|
|
|
|
|
.doit:
|
|
|
|
|
stosb
|
|
|
|
|
sub ecx, 2
|
|
|
|
|
ja .start
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
.ascii:
|
|
|
|
|
stosb
|
|
|
|
|
dec esi
|
|
|
|
|
dec ecx
|
|
|
|
|
jnz .start
|
|
|
|
|
.ret:
|
|
|
|
|
ret
|
|
|
|
|
|
2010-10-01 11:21:55 +02:00
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
|
;
|
|
|
|
|
; ext2_HdRead - read hard disk
|
|
|
|
|
;
|
|
|
|
|
; esi points to filename
|
|
|
|
|
; ebx pointer to 64-bit number = first wanted byte, 0+
|
|
|
|
|
; may be ebx=0 - start from first byte
|
|
|
|
|
; ecx number of bytes to read, 0+
|
|
|
|
|
; edx mem location to return data
|
|
|
|
|
;
|
|
|
|
|
; ret ebx = bytes read or 0xffffffff file not found
|
|
|
|
|
; eax = 0 ok read or other = errormsg
|
2012-10-12 20:24:48 +02:00
|
|
|
|
|
2012-03-08 09:33:38 +01:00
|
|
|
|
;--------------------------------------------------------------
|
|
|
|
|
ext2_HdRead:
|
|
|
|
|
cmp byte [esi], 0
|
|
|
|
|
jnz @F
|
|
|
|
|
|
|
|
|
|
.this_is_nofile:
|
|
|
|
|
or ebx, -1
|
|
|
|
|
mov eax, ERROR_ACCESS_DENIED
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
@@:
|
2012-10-12 20:24:48 +02:00
|
|
|
|
push ecx ebx edx
|
2012-03-08 09:33:38 +01:00
|
|
|
|
call ext2_find_lfn
|
2012-10-12 20:24:48 +02:00
|
|
|
|
pop edx ebx ecx
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz @F
|
|
|
|
|
|
2012-03-08 09:33:38 +01:00
|
|
|
|
or ebx, -1
|
|
|
|
|
mov eax, ERROR_FILE_NOT_FOUND
|
|
|
|
|
ret
|
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
@@:
|
|
|
|
|
mov ax, [ebp + EXT2_INODE_STRUC.i_mode]
|
|
|
|
|
and ax, EXT2_S_IFMT ;оставляем только тип inode в ax
|
|
|
|
|
cmp ax, EXT2_S_IFREG
|
|
|
|
|
jne .this_is_nofile
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
mov edi, edx ; edi = pointer to return mem
|
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test ebx, ebx
|
|
|
|
|
jz @F
|
|
|
|
|
mov esi, ebx ; esi = pointer to first_wanted
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov ebx, [esi+4]
|
2013-06-28 10:02:49 +02:00
|
|
|
|
mov eax, [esi] ;RUS: ebx : eax - стартовый номер байта ;ENG: ebx : eax - start byte number
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
;RUS: ///// сравним хватит ли нам файла или нет ;ENG: ///// check if file is big enough for us
|
2012-03-08 09:33:38 +01:00
|
|
|
|
cmp [ebp + EXT2_INODE_STRUC.i_dir_acl], ebx
|
|
|
|
|
ja .size_great
|
|
|
|
|
jb .size_less
|
|
|
|
|
|
|
|
|
|
cmp [ebp + EXT2_INODE_STRUC.i_size], eax
|
|
|
|
|
ja .size_great
|
|
|
|
|
|
|
|
|
|
.size_less:
|
|
|
|
|
xor ebx, ebx
|
|
|
|
|
mov eax, ERROR_END_OF_FILE
|
|
|
|
|
ret
|
2012-10-12 20:24:48 +02:00
|
|
|
|
|
|
|
|
|
@@:
|
|
|
|
|
xor ebx, ebx
|
|
|
|
|
xor eax, eax
|
2012-03-08 09:33:38 +01:00
|
|
|
|
.size_great:
|
2013-06-28 10:02:49 +02:00
|
|
|
|
add eax, ecx ;RUS: add to first_wanted кол-во байт для чтения
|
|
|
|
|
;ENG: add to first_wanted number of bytes to read
|
2012-03-08 09:33:38 +01:00
|
|
|
|
adc ebx, 0
|
|
|
|
|
|
|
|
|
|
cmp [ebp + EXT2_INODE_STRUC.i_dir_acl], ebx
|
|
|
|
|
ja .size_great_great
|
|
|
|
|
jb .size_great_less
|
|
|
|
|
cmp [ebp + EXT2_INODE_STRUC.i_size], eax
|
2013-06-28 10:02:49 +02:00
|
|
|
|
jae .size_great_great ; and if it's equal, no matter where we jump
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
.size_great_less:
|
2013-06-28 10:02:49 +02:00
|
|
|
|
push 1 ;RUS: читаем по границе размера ;ENG: reading till the end of file
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov ecx, [ebp + EXT2_INODE_STRUC.i_size]
|
2013-06-28 10:02:49 +02:00
|
|
|
|
sub ecx, [esi] ;RUS: (размер - старт) = сколько читать ;ENG: to read = (size - start)
|
2012-03-08 09:33:38 +01:00
|
|
|
|
jmp @F
|
|
|
|
|
|
|
|
|
|
.size_great_great:
|
2013-06-28 10:02:49 +02:00
|
|
|
|
push 0 ;RUS: читаем столько, сколько запросили ;ENG: reading as much as requested
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
@@:
|
2012-10-12 20:24:48 +02:00
|
|
|
|
;здесь мы точно знаем сколько байт читать - ecx
|
|
|
|
|
;edi - return memory
|
|
|
|
|
;esi -> first wanted
|
|
|
|
|
|
|
|
|
|
push ecx ;количество считанных байт
|
2012-03-08 09:33:38 +01:00
|
|
|
|
test esi, esi
|
|
|
|
|
jz .zero_start
|
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
;получим кусок из первого блока
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov edx, [esi+4]
|
|
|
|
|
mov eax, [esi]
|
|
|
|
|
div [ext2_data.block_size]
|
|
|
|
|
|
2013-05-11 14:38:27 +02:00
|
|
|
|
push eax ;счетчик блоков ложим в стек
|
|
|
|
|
|
2012-03-08 09:33:38 +01:00
|
|
|
|
push ecx
|
|
|
|
|
mov ecx, eax
|
|
|
|
|
call ext2_get_inode_block
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_at_first_block
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov ebx, [ext2_data.ext2_save_block]
|
|
|
|
|
mov eax, ecx
|
|
|
|
|
call ext2_get_block
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_at_first_block
|
2012-03-08 09:33:38 +01:00
|
|
|
|
pop ecx
|
|
|
|
|
add ebx, edx
|
|
|
|
|
|
|
|
|
|
neg edx
|
2013-06-28 10:02:49 +02:00
|
|
|
|
add edx, [ext2_data.block_size] ;RUS: block_size - стартовый байт = сколько байт 1-го блока
|
|
|
|
|
;ENG: block_size - start byte = number of bytes in 1st block
|
2012-03-08 09:33:38 +01:00
|
|
|
|
cmp ecx, edx
|
|
|
|
|
jbe .only_one_block
|
|
|
|
|
|
|
|
|
|
mov eax, ecx
|
|
|
|
|
sub eax, edx
|
|
|
|
|
mov ecx, edx
|
|
|
|
|
|
|
|
|
|
mov esi, ebx
|
2013-06-28 10:02:49 +02:00
|
|
|
|
rep movsb ;RUS: кусок 1-го блока ;ENG: part of 1st block
|
2012-10-12 20:24:48 +02:00
|
|
|
|
jmp .calc_blocks_count
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
.zero_start:
|
|
|
|
|
mov eax, ecx
|
2013-05-11 14:38:27 +02:00
|
|
|
|
push 0 ;счетчик блоков ложим в стек
|
2012-03-08 09:33:38 +01:00
|
|
|
|
;теперь в eax кол-во оставшихся байт для чтения
|
2012-10-12 20:24:48 +02:00
|
|
|
|
.calc_blocks_count:
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov ebx, edi ;чтение блока прям в ->ebx
|
|
|
|
|
xor edx, edx
|
2013-05-11 14:38:27 +02:00
|
|
|
|
div [ext2_data.block_size] ;кол-во байт в последнем блоке (остаток) в edx
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov edi, eax ;кол-во целых блоков в edi
|
|
|
|
|
@@:
|
|
|
|
|
test edi, edi
|
|
|
|
|
jz .finish_block
|
2012-10-12 20:24:48 +02:00
|
|
|
|
inc dword [esp]
|
|
|
|
|
mov ecx, [esp]
|
2012-03-08 09:33:38 +01:00
|
|
|
|
call ext2_get_inode_block
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_at_read_cycle
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
mov eax, ecx ;а ebx уже забит нужным значением
|
|
|
|
|
call ext2_get_block
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_at_read_cycle
|
2012-03-08 09:33:38 +01:00
|
|
|
|
add ebx, [ext2_data.block_size]
|
|
|
|
|
|
|
|
|
|
dec edi
|
|
|
|
|
jmp @B
|
|
|
|
|
|
|
|
|
|
.finish_block: ;в edx - кол-во байт в последнем блоке
|
|
|
|
|
test edx, edx
|
|
|
|
|
jz .end_read
|
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
pop ecx ;счетчик блоков -> ecx
|
2012-03-08 09:33:38 +01:00
|
|
|
|
inc ecx
|
|
|
|
|
call ext2_get_inode_block
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
2013-05-11 14:38:27 +02:00
|
|
|
|
jnz .error_at_finish_block
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
mov edi, ebx
|
|
|
|
|
mov eax, ecx
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_block]
|
|
|
|
|
call ext2_get_block
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_at_finish_block
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2013-05-11 14:38:27 +02:00
|
|
|
|
mov ecx, edx
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov esi, ebx
|
|
|
|
|
rep movsb ;кусок last блока
|
2013-05-11 14:38:27 +02:00
|
|
|
|
jmp @F
|
|
|
|
|
|
2012-03-08 09:33:38 +01:00
|
|
|
|
.end_read:
|
2013-05-11 14:38:27 +02:00
|
|
|
|
pop ecx ;счетчик блоков, который хранился в стеке
|
|
|
|
|
@@:
|
|
|
|
|
pop ebx ;количество считанных байт
|
|
|
|
|
pop eax ; 1 или 0 - достигли ли конца файла
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
2012-03-08 09:33:38 +01:00
|
|
|
|
jz @F
|
|
|
|
|
|
|
|
|
|
mov eax, ERROR_END_OF_FILE
|
|
|
|
|
ret
|
|
|
|
|
@@:
|
|
|
|
|
xor eax, eax
|
|
|
|
|
ret
|
2012-10-12 20:24:48 +02:00
|
|
|
|
|
|
|
|
|
.only_one_block:
|
|
|
|
|
mov esi, ebx
|
|
|
|
|
rep movsb ;кусок last блока
|
|
|
|
|
jmp .end_read
|
|
|
|
|
|
|
|
|
|
.error_at_first_block:
|
|
|
|
|
pop edx
|
|
|
|
|
.error_at_read_cycle:
|
|
|
|
|
pop ebx
|
|
|
|
|
.error_at_finish_block:
|
|
|
|
|
pop ecx edx
|
|
|
|
|
or ebx, -1
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
|
; in: esi = file path
|
|
|
|
|
; ebx = pointer to dir block
|
|
|
|
|
; out: esi - name without parent or not_changed
|
|
|
|
|
; ebx - dir_rec of inode children
|
|
|
|
|
ext2_test_block_by_name:
|
|
|
|
|
sub esp, 256 ;EXT2_filename
|
|
|
|
|
mov edx, ebx
|
2013-06-28 10:02:49 +02:00
|
|
|
|
add edx, [ext2_data.block_size] ;RUS: запомним конец блока ;ENG: save block end
|
2012-10-12 20:24:48 +02:00
|
|
|
|
|
|
|
|
|
.start_rec:
|
|
|
|
|
cmp [ebx + EXT2_DIR_STRUC.inode], 0
|
|
|
|
|
jz .next_rec
|
|
|
|
|
|
|
|
|
|
mov edi, esp
|
|
|
|
|
push esi
|
|
|
|
|
movzx ecx, [ebx + EXT2_DIR_STRUC.name_len]
|
|
|
|
|
lea esi, [ebx + EXT2_DIR_STRUC.name]
|
|
|
|
|
call utf8_to_cp866
|
|
|
|
|
|
|
|
|
|
mov ecx, edi
|
|
|
|
|
lea edi, [esp + 4]
|
2013-06-28 10:02:49 +02:00
|
|
|
|
sub ecx, edi ;RUS: кол-во байт в получившейся строке ;ENG: number of bytes in resulting string
|
2012-10-12 20:24:48 +02:00
|
|
|
|
|
|
|
|
|
mov esi, [esp]
|
|
|
|
|
@@:
|
|
|
|
|
jecxz .test_find
|
|
|
|
|
dec ecx
|
|
|
|
|
|
|
|
|
|
lodsb
|
|
|
|
|
call char_toupper
|
|
|
|
|
|
|
|
|
|
mov ah, [edi]
|
|
|
|
|
inc edi
|
|
|
|
|
xchg al, ah
|
|
|
|
|
call char_toupper
|
|
|
|
|
cmp al, ah
|
|
|
|
|
je @B
|
2013-06-28 10:02:49 +02:00
|
|
|
|
@@: ;RUS: не подошло ;ENG: didn't fit
|
2012-10-12 20:24:48 +02:00
|
|
|
|
pop esi
|
|
|
|
|
.next_rec:
|
|
|
|
|
movzx eax, [ebx + EXT2_DIR_STRUC.rec_len]
|
2013-06-28 10:02:49 +02:00
|
|
|
|
add ebx, eax ;RUS: к след. записи ;ENG: go to next record
|
|
|
|
|
cmp ebx, edx ;RUS: проверим конец ли ;ENG: check if this is the end
|
2012-10-12 20:24:48 +02:00
|
|
|
|
jb .start_rec
|
|
|
|
|
add esp, 256
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
.test_find:
|
|
|
|
|
cmp byte [esi], 0
|
2013-06-28 10:02:49 +02:00
|
|
|
|
je .ret ;RUS: нашли конец ;ENG: the end reached
|
2012-10-12 20:24:48 +02:00
|
|
|
|
cmp byte [esi], '/'
|
|
|
|
|
jne @B
|
|
|
|
|
inc esi
|
|
|
|
|
.ret:
|
|
|
|
|
add esp, 256 + 4
|
|
|
|
|
ret
|
|
|
|
|
|
2012-03-08 09:33:38 +01:00
|
|
|
|
;========================
|
2012-10-12 20:24:48 +02:00
|
|
|
|
;Ищет inode по строке пути
|
|
|
|
|
;in: esi = name
|
|
|
|
|
;out: eax - error code
|
|
|
|
|
; ebp = inode
|
|
|
|
|
; dl - первый байт из имени файла/папки
|
2012-03-08 09:33:38 +01:00
|
|
|
|
ext2_find_lfn:
|
|
|
|
|
mov ebp, [ext2_data.root_inode]
|
2012-10-12 20:24:48 +02:00
|
|
|
|
cmp [ebp + EXT2_INODE_STRUC.i_blocks], 0
|
|
|
|
|
je .error_empty_root
|
|
|
|
|
|
|
|
|
|
.next_path_part:
|
|
|
|
|
push [ebp + EXT2_INODE_STRUC.i_blocks]
|
|
|
|
|
xor ecx, ecx
|
|
|
|
|
.folder_block_cycle:
|
2013-05-11 14:38:27 +02:00
|
|
|
|
push ecx
|
2012-03-08 09:33:38 +01:00
|
|
|
|
call ext2_get_inode_block
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_get_inode_block
|
2013-05-11 14:38:27 +02:00
|
|
|
|
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov eax, ecx
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_block] ;ebx = cur dir record
|
|
|
|
|
call ext2_get_block
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_get_block
|
2013-05-11 14:38:27 +02:00
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
push esi
|
2012-03-08 09:33:38 +01:00
|
|
|
|
call ext2_test_block_by_name
|
2013-05-11 14:38:27 +02:00
|
|
|
|
pop edi ecx
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
cmp edi, esi ;RUS: нашли имя? ;ENG: did we find a name?
|
|
|
|
|
je .next_folder_block ;RUS: не нашли -> к след. блоку ;ENG: we didn't -> moving to next block
|
2013-05-11 14:38:27 +02:00
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
cmp byte [esi], 0 ;RUS: дошли до "конца" пути -> возваращаемся
|
|
|
|
|
;ENG: reached the "end" of path -> returning
|
2012-03-08 09:33:38 +01:00
|
|
|
|
jz .get_inode_ret
|
|
|
|
|
|
2013-06-28 10:02:49 +02:00
|
|
|
|
cmp [ebx + EXT2_DIR_STRUC.file_type], EXT2_FT_DIR ;RUS: нашли, но это не папка
|
|
|
|
|
jne .not_found ;ENG: found, but it's not a folder
|
2012-10-12 20:24:48 +02:00
|
|
|
|
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov eax, [ebx + EXT2_DIR_STRUC.inode]
|
2013-06-28 10:02:49 +02:00
|
|
|
|
mov ebx, [ext2_data.ext2_save_inode] ;RUS: все же папка. ;ENG: it's a folder afterall
|
2012-03-08 09:33:38 +01:00
|
|
|
|
call ext2_get_inode
|
2012-10-12 20:24:48 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_get_inode
|
2013-06-28 10:02:49 +02:00
|
|
|
|
pop ecx ;RUS: в стеке лежит кол-во блоков ;ENG: stack top contains number of blocks
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov ebp, ebx
|
2012-10-12 20:24:48 +02:00
|
|
|
|
jmp .next_path_part
|
|
|
|
|
|
|
|
|
|
.next_folder_block:
|
|
|
|
|
;к следующему блоку в текущей папке
|
2013-06-28 10:02:49 +02:00
|
|
|
|
pop eax ;RUS: счетчик блоков ;ENG: blocks counter
|
2012-10-12 20:24:48 +02:00
|
|
|
|
sub eax, [ext2_data.count_block_in_block]
|
|
|
|
|
jle .not_found
|
|
|
|
|
|
2013-05-11 14:38:27 +02:00
|
|
|
|
push eax
|
2012-10-12 20:24:48 +02:00
|
|
|
|
inc ecx
|
|
|
|
|
jmp .folder_block_cycle
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
|
|
|
|
.not_found:
|
2012-10-12 20:24:48 +02:00
|
|
|
|
mov eax, ERROR_FILE_NOT_FOUND
|
2012-03-08 09:33:38 +01:00
|
|
|
|
ret
|
2012-10-12 20:24:48 +02:00
|
|
|
|
|
2012-03-08 09:33:38 +01:00
|
|
|
|
.get_inode_ret:
|
2013-06-28 10:02:49 +02:00
|
|
|
|
pop ecx ;RUS: в стеке лежит кол-во блоков ;ENG: stack top contains number of blocks
|
|
|
|
|
mov dl, [ebx + EXT2_DIR_STRUC.name] ;RUS: в dl - первый символ () ;ENG: ???
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov eax, [ebx + EXT2_DIR_STRUC.inode]
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_inode]
|
|
|
|
|
call ext2_get_inode
|
|
|
|
|
mov ebp, ebx
|
2012-10-12 20:24:48 +02:00
|
|
|
|
xor eax, eax
|
2012-03-08 09:33:38 +01:00
|
|
|
|
ret
|
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
.error_get_inode_block:
|
|
|
|
|
.error_get_block:
|
2013-05-11 14:38:27 +02:00
|
|
|
|
pop ecx
|
2012-10-12 20:24:48 +02:00
|
|
|
|
.error_get_inode:
|
|
|
|
|
pop ebx
|
|
|
|
|
.error_empty_root:
|
|
|
|
|
mov eax, ERROR_FS_FAIL
|
|
|
|
|
ret
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
|
;ext2_HdGetFileInfo - read file info from block device
|
|
|
|
|
;
|
|
|
|
|
;in: esi points to filename
|
|
|
|
|
; edx mem location to return data
|
|
|
|
|
;--------------------------------------------------------------
|
2012-03-08 09:33:38 +01:00
|
|
|
|
ext2_HdGetFileInfo:
|
2012-10-12 20:24:48 +02:00
|
|
|
|
xchg bx, bx
|
2012-03-08 09:33:38 +01:00
|
|
|
|
cmp byte [esi], 0
|
2012-10-12 20:24:48 +02:00
|
|
|
|
jz .is_root
|
2012-03-08 09:33:38 +01:00
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
push edx
|
2012-03-08 09:33:38 +01:00
|
|
|
|
call ext2_find_lfn
|
2012-10-12 20:24:48 +02:00
|
|
|
|
mov ebx, edx
|
|
|
|
|
pop edx
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz @F
|
2012-03-08 09:33:38 +01:00
|
|
|
|
ret
|
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
.is_root:
|
2013-06-28 10:02:49 +02:00
|
|
|
|
xor ebx, ebx ;RUS: root не может быть скрытым ;ENG: root cannot be hidden
|
2012-03-08 09:33:38 +01:00
|
|
|
|
mov ebp, [ext2_data.root_inode]
|
|
|
|
|
@@:
|
|
|
|
|
xor eax, eax
|
|
|
|
|
mov edi, edx
|
|
|
|
|
mov ecx, 40/4
|
|
|
|
|
rep stosd ; fill zero
|
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
cmp bl, '.'
|
|
|
|
|
jne @F
|
2012-03-08 09:33:38 +01:00
|
|
|
|
or dword [edx], FS_FT_HIDDEN
|
|
|
|
|
@@:
|
|
|
|
|
|
|
|
|
|
test [ebp + EXT2_INODE_STRUC.i_mode], EXT2_S_IFDIR
|
|
|
|
|
jnz @F
|
|
|
|
|
mov eax, [ebp + EXT2_INODE_STRUC.i_size] ;low size
|
|
|
|
|
mov ebx, [ebp + EXT2_INODE_STRUC.i_dir_acl] ;high size
|
|
|
|
|
mov dword [edx+32], eax
|
|
|
|
|
mov dword [edx+36], ebx
|
|
|
|
|
xor dword [edx], FS_FT_DIR
|
|
|
|
|
@@:
|
|
|
|
|
xor dword [edx], FS_FT_DIR
|
|
|
|
|
|
|
|
|
|
lea edi, [edx + 8]
|
2012-10-12 20:24:48 +02:00
|
|
|
|
mov eax, [ebp + EXT2_INODE_STRUC.i_ctime]
|
2012-03-08 09:33:38 +01:00
|
|
|
|
xor edx, edx
|
|
|
|
|
add eax, 3054539008
|
|
|
|
|
adc edx, 2
|
|
|
|
|
call ntfs_datetime_to_bdfe.sec
|
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
mov eax, [ebp + EXT2_INODE_STRUC.i_atime]
|
2012-03-08 09:33:38 +01:00
|
|
|
|
xor edx, edx
|
|
|
|
|
add eax, 3054539008
|
|
|
|
|
adc edx, 2
|
|
|
|
|
call ntfs_datetime_to_bdfe.sec
|
|
|
|
|
|
2012-10-12 20:24:48 +02:00
|
|
|
|
mov eax, [ebp + EXT2_INODE_STRUC.i_mtime]
|
2012-03-08 09:33:38 +01:00
|
|
|
|
xor edx, edx
|
|
|
|
|
add eax, 3054539008
|
|
|
|
|
adc edx, 2
|
|
|
|
|
call ntfs_datetime_to_bdfe.sec
|
|
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
ext2_HdRewrite:
|
|
|
|
|
ext2_HdWrite:
|
|
|
|
|
ext2_HdSetFileEnd:
|
|
|
|
|
ext2_HdSetFileInfo:
|
|
|
|
|
ext2_HdDelete:
|
|
|
|
|
ext2_HdCreateFolder:
|
|
|
|
|
xor ebx, ebx
|
|
|
|
|
mov eax, ERROR_UNSUPPORTED_FS
|
|
|
|
|
ret
|