2010-01-23 16:24:03 +01:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;; ;;
|
2012-03-13 17:51:57 +01:00
|
|
|
|
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
|
2010-01-23 16:24:03 +01:00
|
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
2010-02-01 19:47:19 +01:00
|
|
|
|
;; 02.02.2010 turbanoff - support 70.5 ;;
|
|
|
|
|
;; 23.01.2010 turbanoff - support 70.0 70.1 ;;
|
2010-01-23 16:24:03 +01:00
|
|
|
|
;; ;;
|
|
|
|
|
;; ;;
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
$Revision$
|
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
EXT2_BAD_INO = 1
|
2010-01-23 16:24:03 +01:00
|
|
|
|
EXT2_ROOT_INO = 2
|
2012-07-25 18:26:11 +02:00
|
|
|
|
EXT2_ACL_IDX_INO = 3
|
2010-01-23 16:24:03 +01:00
|
|
|
|
EXT2_ACL_DATA_INO = 4
|
2012-07-25 18:26:11 +02:00
|
|
|
|
EXT2_BOOT_LOADER_INO = 5
|
|
|
|
|
EXT2_UNDEL_DIR_INO = 6
|
|
|
|
|
|
|
|
|
|
;флаги, указываемый в inode файла
|
|
|
|
|
EXT2_S_IFREG = 0x8000
|
|
|
|
|
EXT2_S_IFDIR = 0x4000
|
2012-09-11 19:39:26 +02:00
|
|
|
|
EXT2_S_IFMT = 0xF000 ;маска для типа файла
|
2012-07-25 18:26:11 +02:00
|
|
|
|
|
|
|
|
|
;флаги, указываемые в linked list родительской папки
|
|
|
|
|
EXT2_FT_REG_FILE = 1 ;это файл, запись в родительском каталоге
|
|
|
|
|
EXT2_FT_DIR = 2 ;это папка
|
|
|
|
|
|
|
|
|
|
;флаги используемые KolibriOS
|
|
|
|
|
FS_FT_HIDDEN = 2
|
|
|
|
|
FS_FT_DIR = 0x10 ;это папка
|
|
|
|
|
FS_FT_ASCII = 0 ;имя в ascii
|
|
|
|
|
FS_FT_UNICODE = 1 ;имя в unicode
|
|
|
|
|
|
|
|
|
|
EXT2_FEATURE_INCOMPAT_FILETYPE = 0x0002 ;тип файла должен указываться в директории
|
|
|
|
|
EXT4_FEATURE_INCOMPAT_EXTENTS = 0x0040 ;экстенты
|
|
|
|
|
EXT4_FEATURE_INCOMPAT_FLEX_BG = 0x0200 ;гибкие группы блоков
|
|
|
|
|
;реализованные ext[234] features
|
|
|
|
|
EXT4_FEATURE_INCOMPAT_SUPP = EXT2_FEATURE_INCOMPAT_FILETYPE \
|
|
|
|
|
or EXT4_FEATURE_INCOMPAT_EXTENTS \
|
|
|
|
|
or EXT4_FEATURE_INCOMPAT_FLEX_BG
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;флаги, указываемые для inode в i_flags
|
|
|
|
|
EXT2_EXTENTS_FL = 0x00080000
|
2010-02-08 20:51:43 +01:00
|
|
|
|
|
2012-02-22 16:46:09 +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
|
2010-01-23 16:24:03 +01:00
|
|
|
|
ends
|
|
|
|
|
|
2012-02-22 16:46:09 +01:00
|
|
|
|
struct EXT2_DIR_STRUC
|
|
|
|
|
inode dd ?
|
|
|
|
|
rec_len dw ?
|
|
|
|
|
name_len db ?
|
|
|
|
|
file_type db ?
|
|
|
|
|
name db ? ; 0..255
|
2010-01-23 16:24:03 +01:00
|
|
|
|
ends
|
|
|
|
|
|
2012-02-22 16:46:09 +01:00
|
|
|
|
struct EXT2_BLOCK_GROUP_DESC
|
2012-07-25 18:26:11 +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
|
2010-02-17 18:26:25 +01:00
|
|
|
|
ends
|
|
|
|
|
|
2012-02-22 16:46:09 +01:00
|
|
|
|
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-07-25 18:26:11 +02:00
|
|
|
|
reserved_gdt_blocks dw ? ;+206
|
2012-02-22 16:46:09 +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-07-25 18:26:11 +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
|
|
|
|
|
|
|
|
|
|
struct EXT4_EXTENT_HEADER ;заголовок блока экстентов/индексов
|
|
|
|
|
eh_magic dw ? ;в текущей реализации ext4 должно быть 0xF30A
|
|
|
|
|
eh_entries dw ? ;количество экстентов/индексов в блоке
|
|
|
|
|
eh_max dw ? ;max количество (используется при записи)
|
|
|
|
|
eh_depth dw ? ;глубина дерева (0, если это блок экстентов)
|
|
|
|
|
eh_generation dd ? ;???
|
|
|
|
|
ends
|
|
|
|
|
|
|
|
|
|
struct EXT4_EXTENT ;экстент
|
|
|
|
|
ee_block dd ? ;номер ext4 блока
|
|
|
|
|
ee_len dw ? ;длина экстента
|
|
|
|
|
ee_start_hi dw ? ;старшие 16 бит 48-битного адреса (пока не используются в KOS)
|
|
|
|
|
ee_start_lo dd ? ;младшие 32 бита 48-битного адреса
|
|
|
|
|
ends
|
|
|
|
|
|
|
|
|
|
struct EXT4_EXTENT_IDX ;индес - указатель на блок с экстентами/индексами
|
|
|
|
|
ei_block dd ? ;номер ext4 блока
|
|
|
|
|
ei_leaf_lo dd ? ;младшие 32 бит 48-битного адреса
|
|
|
|
|
ei_leaf_hi dw ? ;старшие 16 бит 48-битного адреса (пока не используются в KOS)
|
|
|
|
|
ei_unused dw ? ;зарезервировано
|
2010-02-17 18:26:25 +01:00
|
|
|
|
ends
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
ext2_test_superblock:
|
2010-02-13 14:34:41 +01:00
|
|
|
|
cmp [fs_type], 0x83
|
|
|
|
|
jne .no
|
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
mov eax, [PARTITION_START]
|
|
|
|
|
add eax, 2 ;superblock start at 1024b
|
|
|
|
|
call hd_read
|
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
cmp [ebx + EXT2_SB_STRUC.log_block_size], 3 ;0,1,2,3
|
2010-01-23 16:24:03 +01:00
|
|
|
|
ja .no
|
2012-07-25 18:26:11 +02:00
|
|
|
|
cmp [ebx + EXT2_SB_STRUC.magic], 0xEF53
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jne .no
|
2012-07-25 18:26:11 +02:00
|
|
|
|
cmp [ebx + EXT2_SB_STRUC.state], 1 ;EXT_VALID_FS=1
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jne .no
|
2012-07-25 18:26:11 +02:00
|
|
|
|
cmp [ebx + EXT2_SB_STRUC.inodes_per_group], 0
|
|
|
|
|
je .no
|
|
|
|
|
|
|
|
|
|
mov eax, [ebx + EXT2_SB_STRUC.feature_incompat]
|
2010-02-13 14:34:41 +01:00
|
|
|
|
test eax, EXT2_FEATURE_INCOMPAT_FILETYPE
|
|
|
|
|
jz .no
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, not EXT4_FEATURE_INCOMPAT_SUPP
|
2010-02-13 14:34:41 +01:00
|
|
|
|
jnz .no
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
; OK, this is correct EXT2 superblock
|
|
|
|
|
clc
|
|
|
|
|
ret
|
|
|
|
|
.no:
|
|
|
|
|
; No, this superblock isn't EXT2
|
|
|
|
|
stc
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
ext2_setup:
|
|
|
|
|
mov [fs_type], 2
|
2010-02-17 18:26:25 +01:00
|
|
|
|
|
|
|
|
|
push 512
|
|
|
|
|
call kernel_alloc ; mem for superblock
|
|
|
|
|
mov esi, ebx
|
|
|
|
|
mov edi, eax
|
|
|
|
|
mov ecx, 512/4
|
2011-10-14 23:38:50 +02:00
|
|
|
|
rep movsd ; copy sb to reserved mem
|
2010-02-17 18:26:25 +01:00
|
|
|
|
mov ebx, eax
|
2011-10-14 23:38:50 +02:00
|
|
|
|
mov [ext2_data.sb], eax
|
2010-02-17 18:26:25 +01:00
|
|
|
|
|
|
|
|
|
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-07-25 18:26:11 +02:00
|
|
|
|
mov ecx, [ebx + EXT2_SB_STRUC.log_block_size]
|
2010-01-23 16:24:03 +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
|
|
|
|
|
mov edx, eax ; потом еще квадрат найдем
|
|
|
|
|
|
|
|
|
|
shl eax, 2
|
|
|
|
|
mov [ext2_data.block_size], eax
|
|
|
|
|
|
2010-02-17 18:26:25 +01:00
|
|
|
|
push eax eax ; 2 kernel_alloc
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
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-07-25 18:26:11 +02:00
|
|
|
|
movzx ebp, word [ebx + EXT2_SB_STRUC.inode_size]
|
|
|
|
|
mov ecx, [ebx + EXT2_SB_STRUC.blocks_per_group]
|
2010-01-23 16:24:03 +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
|
2010-02-17 18:26:25 +01:00
|
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
|
jmp return_from_part_set
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
;==================================================================
|
2012-07-25 18:26:11 +02:00
|
|
|
|
;read ext2 block form FS to memory
|
|
|
|
|
;in: eax = i_block (address of block in ext2 terms)
|
|
|
|
|
; ebx = pointer to return memory
|
|
|
|
|
;out: eax - error code (0 = no_error)
|
2010-01-23 16:24:03 +01:00
|
|
|
|
ext2_get_block:
|
2012-07-25 18:26:11 +02:00
|
|
|
|
push ebx ecx
|
2010-01-23 16:24:03 +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-07-25 18:26:11 +02:00
|
|
|
|
cmp [hd_error], 0
|
|
|
|
|
jnz .fail
|
2010-01-23 16:24:03 +01:00
|
|
|
|
inc eax
|
|
|
|
|
add ebx, 512
|
|
|
|
|
loop @B
|
2012-07-25 18:26:11 +02:00
|
|
|
|
xor eax, eax
|
|
|
|
|
@@:
|
|
|
|
|
pop ecx ebx
|
|
|
|
|
ret
|
|
|
|
|
.fail:
|
|
|
|
|
mov eax, ERROR_DEVICE
|
|
|
|
|
jmp @B
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;===================================================================
|
|
|
|
|
;получает номер блока из extent inode
|
|
|
|
|
;in: ecx = номер блока по порядку
|
|
|
|
|
; ebp = адрес extent header`а
|
|
|
|
|
;out: ecx - адрес очередного блока в случае успеха
|
|
|
|
|
; eax - номер ошибки (если равно 0, то ошибки нет)
|
|
|
|
|
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
|
2010-01-23 16:24:03 +01:00
|
|
|
|
ret
|
2012-07-25 18:26:11 +02:00
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
;===================================================================
|
2012-07-25 18:26:11 +02:00
|
|
|
|
;получает адрес ext2 блока из inode с определнным номером
|
|
|
|
|
;in: ecx = номер блока в inode (0..)
|
|
|
|
|
; ebp = адрес inode
|
|
|
|
|
;out: ecx = адрес очередного блока
|
|
|
|
|
; eax - error code
|
2010-01-23 16:24:03 +01:00
|
|
|
|
ext2_get_inode_block:
|
2012-07-25 18:26:11 +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
|
|
|
|
|
|
|
|
|
|
@@:
|
2010-02-03 19:01:16 +01:00
|
|
|
|
cmp ecx, 12 ; 0..11 - direct block address
|
|
|
|
|
jb .get_direct_block
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
sub ecx, 12
|
2012-07-25 18:26:11 +02:00
|
|
|
|
cmp ecx, [ext2_data.count_pointer_in_block] ; 12.. - indirect blocks
|
2010-02-03 19:01:16 +01:00
|
|
|
|
jb .get_indirect_block
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
sub ecx, [ext2_data.count_pointer_in_block]
|
|
|
|
|
cmp ecx, [ext2_data.count_pointer_in_block_square]
|
2010-02-03 19:01:16 +01:00
|
|
|
|
jb .get_double_indirect_block
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2010-02-03 19:01:16 +01:00
|
|
|
|
sub ecx, [ext2_data.count_pointer_in_block_square]
|
2012-07-25 18:26:11 +02:00
|
|
|
|
;triple indirect block
|
|
|
|
|
push edx ebx
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
|
mov eax, [ebx + EXT2_INODE_STRUC.i_block + 14*4]
|
|
|
|
|
mov ebx, [ext2_data.ext2_temp_block]
|
2010-01-23 16:24:03 +01:00
|
|
|
|
call ext2_get_block
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .fail
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
xor edx, edx
|
|
|
|
|
mov eax, ecx
|
|
|
|
|
div [ext2_data.count_pointer_in_block_square]
|
|
|
|
|
|
|
|
|
|
;eax - номер в полученном блоке edx - номер дальше
|
2011-10-14 23:38:50 +02:00
|
|
|
|
mov eax, [ebx + eax*4]
|
|
|
|
|
call ext2_get_block
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .fail
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
|
mov eax, edx
|
|
|
|
|
jmp @F
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
.get_double_indirect_block:
|
2012-07-25 18:26:11 +02:00
|
|
|
|
push edx ebx
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
mov eax, [ebp + EXT2_INODE_STRUC.i_block + 13*4]
|
|
|
|
|
mov ebx, [ext2_data.ext2_temp_block]
|
|
|
|
|
call ext2_get_block
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .fail
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
mov eax, ecx
|
2012-07-25 18:26:11 +02:00
|
|
|
|
@@:
|
2010-01-23 16:24:03 +01:00
|
|
|
|
xor edx, edx
|
|
|
|
|
div [ext2_data.count_pointer_in_block]
|
|
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
|
mov eax, [ebx + eax*4]
|
2010-01-23 16:24:03 +01:00
|
|
|
|
call ext2_get_block
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .fail
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov ecx, [ebx + edx*4]
|
|
|
|
|
.fail:
|
|
|
|
|
pop ebx edx
|
2010-01-23 16:24:03 +01:00
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
.get_indirect_block:
|
2012-07-25 18:26:11 +02:00
|
|
|
|
push ebx
|
2010-01-23 16:24:03 +01:00
|
|
|
|
mov eax, [ebp + EXT2_INODE_STRUC.i_block + 12*4]
|
2010-02-03 19:01:16 +01:00
|
|
|
|
mov ebx, [ext2_data.ext2_temp_block]
|
2010-01-23 16:24:03 +01:00
|
|
|
|
call ext2_get_block
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
2013-03-03 19:42:16 +01:00
|
|
|
|
jnz @F ;если не было ошибки
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov ecx, [ebx + ecx*4] ;заносим результат
|
|
|
|
|
@@:
|
|
|
|
|
pop ebx
|
2010-01-23 16:24:03 +01:00
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
.get_direct_block:
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov ecx, [ebp + EXT2_INODE_STRUC.i_block + ecx*4]
|
|
|
|
|
xor eax, eax
|
2010-01-23 16:24:03 +01:00
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;===================================================================
|
|
|
|
|
;get content inode by num
|
2012-07-25 18:26:11 +02:00
|
|
|
|
;in: eax = inode_num
|
|
|
|
|
; ebx = address of inode content
|
|
|
|
|
;out: eax - error code
|
2010-01-23 16:24:03 +01:00
|
|
|
|
ext2_get_inode:
|
2011-10-14 23:38:50 +02:00
|
|
|
|
pushad
|
|
|
|
|
mov edi, ebx ;сохраним адрес inode
|
|
|
|
|
dec eax
|
|
|
|
|
xor edx, edx
|
2012-07-25 18:26:11 +02:00
|
|
|
|
|
|
|
|
|
mov ecx, [ext2_data.sb]
|
|
|
|
|
div [ecx + EXT2_SB_STRUC.inodes_per_group]
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2010-02-17 18:26:25 +01:00
|
|
|
|
push edx ;locale num in group
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
mov edx, 32
|
|
|
|
|
mul edx ; address block_group in global_desc_table
|
|
|
|
|
|
2010-02-17 18:26:25 +01:00
|
|
|
|
; в eax - смещение группы с inode-ом относительно начала глобальной дескрипторной таблицы
|
|
|
|
|
; найдем блок в котором он находится
|
|
|
|
|
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-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .fail
|
2010-02-17 18:26:25 +01:00
|
|
|
|
|
|
|
|
|
add ebx, edx ; локальный номер в блоке
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov eax, [ebx + EXT2_BLOCK_GROUP_DESC.inode_table]; номер блока - в терминах ext2
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
mov ecx, [ext2_data.log_block_size]
|
|
|
|
|
shl eax, cl
|
2012-07-25 18:26:11 +02:00
|
|
|
|
add eax, [PARTITION_START] ; а старт раздела - в терминах hdd (512)
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
;eax - указывает на таблицу inode-ов на hdd
|
2010-02-13 14:34:41 +01:00
|
|
|
|
mov esi, eax ;сохраним его пока в esi
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
; прибавим локальный адрес inode-а
|
|
|
|
|
pop eax ; index
|
2010-02-13 14:34:41 +01:00
|
|
|
|
mov ecx, [ext2_data.inode_size]
|
|
|
|
|
mul ecx ; (index * inode_size)
|
2010-01-23 16:24:03 +01:00
|
|
|
|
mov ebp, 512
|
|
|
|
|
div ebp ;поделим на размер блока
|
|
|
|
|
|
2010-02-13 14:34:41 +01:00
|
|
|
|
add eax, esi ;нашли адрес блока для чтения
|
2010-01-23 16:24:03 +01:00
|
|
|
|
mov ebx, [ext2_data.ext2_temp_block]
|
|
|
|
|
call hd_read
|
2012-07-25 18:26:11 +02:00
|
|
|
|
cmp [hd_error], 0
|
|
|
|
|
jnz .fail
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
mov esi, edx ;добавим "остаток"
|
|
|
|
|
add esi, ebx ;к адресу
|
2011-10-14 23:38:50 +02:00
|
|
|
|
rep movsb ;копируем inode
|
2012-07-25 18:26:11 +02:00
|
|
|
|
xor eax, eax
|
|
|
|
|
.fail:
|
|
|
|
|
mov PUSHAD_EAX, eax
|
2010-01-23 16:24:03 +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-07-25 18:26:11 +02:00
|
|
|
|
jz .root_folder
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +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
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
.root_folder:
|
2010-02-03 19:01:16 +01:00
|
|
|
|
mov ebp, [ext2_data.root_inode]
|
|
|
|
|
test [ebp + EXT2_INODE_STRUC.i_mode], EXT2_S_IFDIR
|
2012-07-25 18:26:11 +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
|
2010-02-03 19:01:16 +01:00
|
|
|
|
@@:
|
2012-07-25 18:26:11 +02:00
|
|
|
|
cmp [ebp + EXT2_INODE_STRUC.i_blocks], 0 ;папка пуста
|
|
|
|
|
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]
|
|
|
|
|
|
2010-02-03 19:01:16 +01:00
|
|
|
|
mov edi, edx
|
|
|
|
|
mov ecx, 32/4
|
2011-10-14 23:38:50 +02:00
|
|
|
|
rep stosd ; fill header zero
|
2012-07-25 18:26:11 +02:00
|
|
|
|
|
|
|
|
|
mov edi, esp ; edi - указатель на локальные переменные
|
|
|
|
|
add edx, 32 ; edx = current mem for return
|
2010-02-03 19:01:16 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
xor ecx, ecx ; получим номер первого блока
|
2010-01-23 16:24:03 +01:00
|
|
|
|
call ext2_get_inode_block
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_get_block
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
mov eax, ecx
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_block]
|
|
|
|
|
call ext2_get_block ; и считываем блок с hdd
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_get_block
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov esi, ebx ; esi = current dir record
|
2010-01-23 16:24:03 +01:00
|
|
|
|
add ebx, [ext2_data.block_size]
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov [edi + 24], ebx ; запомним конец очередного блока
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov ecx, [edi + 16] ; ecx = first wanted (flags ommited)
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
.find_wanted_start:
|
2011-10-14 23:38:50 +02:00
|
|
|
|
jecxz .find_wanted_end
|
2010-01-23 16:24:03 +01:00
|
|
|
|
.find_wanted_cycle:
|
2012-07-25 18:26:11 +02:00
|
|
|
|
cmp [esi + EXT2_DIR_STRUC.inode], 0 ; if (inode = 0) => not used
|
2011-10-14 23:38:50 +02:00
|
|
|
|
jz @F
|
2012-07-25 18:26:11 +02:00
|
|
|
|
inc dword [edi + 4] ; EXT2_files_in_folder
|
2011-10-14 23:38:50 +02:00
|
|
|
|
dec ecx
|
2012-07-25 18:26:11 +02:00
|
|
|
|
@@:
|
|
|
|
|
movzx ebx, [esi + EXT2_DIR_STRUC.rec_len]
|
2010-02-17 18:26:25 +01:00
|
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
|
cmp ebx, 12 ; минимальная длина записи
|
2012-07-25 18:26:11 +02:00
|
|
|
|
jb .error_bad_len
|
2011-10-14 23:38:50 +02:00
|
|
|
|
test ebx, 0x3 ; длина записи должна делиться на 4
|
2012-07-25 18:26:11 +02:00
|
|
|
|
jnz .error_bad_len
|
2010-02-17 18:26:25 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
add esi, ebx ; к следующей записи
|
|
|
|
|
cmp esi, [edi + 24] ; сравниваем с концом блока
|
2011-10-14 23:38:50 +02:00
|
|
|
|
jb .find_wanted_start
|
2010-02-08 21:43:55 +01:00
|
|
|
|
|
2010-02-17 18:26:25 +01:00
|
|
|
|
push .find_wanted_start
|
2012-07-25 18:26:11 +02:00
|
|
|
|
.end_block: ;вылетели из цикла
|
2010-02-08 21:43:55 +01:00
|
|
|
|
mov ebx, [ext2_data.count_block_in_block]
|
2012-07-25 18:26:11 +02:00
|
|
|
|
sub [ebp + EXT2_INODE_STRUC.i_blocks], ebx ;вычитаем напрямую из структуры inode
|
|
|
|
|
jle .end_dir
|
2010-02-08 21:43:55 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
inc dword [edi] ;получаем новый блок
|
2010-02-08 21:43:55 +01:00
|
|
|
|
push ecx
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov ecx, [edi]
|
2010-02-08 21:43:55 +01:00
|
|
|
|
call ext2_get_inode_block
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_get_block
|
|
|
|
|
|
2010-02-08 21:43:55 +01:00
|
|
|
|
mov eax, ecx
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_block]
|
|
|
|
|
call ext2_get_block
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_get_block
|
|
|
|
|
|
2010-02-08 21:43:55 +01:00
|
|
|
|
pop ecx
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov esi, ebx
|
2010-02-08 21:43:55 +01:00
|
|
|
|
add ebx, [ext2_data.block_size]
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov [edi + 24], ebx ;запомним конец блока
|
|
|
|
|
ret ; опять в цикл
|
2010-02-09 15:17:26 +01:00
|
|
|
|
|
|
|
|
|
.wanted_end:
|
2012-07-25 18:26:11 +02:00
|
|
|
|
loop .find_wanted_cycle ; ecx 0 => -1 нужно посчитать сколько файлов
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
;дошли до первого "нужного" файла
|
2010-02-08 21:43:55 +01:00
|
|
|
|
.find_wanted_end:
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov ecx, [edi + 20]
|
|
|
|
|
.wanted_start: ; ищем first_wanted+count
|
2011-10-14 23:38:50 +02:00
|
|
|
|
jecxz .wanted_end
|
2012-07-25 18:26:11 +02:00
|
|
|
|
cmp [esi + EXT2_DIR_STRUC.inode], 0 ; if (inode = 0) => not used
|
2011-10-14 23:38:50 +02:00
|
|
|
|
jz .empty_rec
|
2012-07-25 18:26:11 +02:00
|
|
|
|
inc dword [edi + 8]
|
|
|
|
|
inc dword [edi + 4]
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
push edi ecx
|
|
|
|
|
mov edi, edx ;обнуляем место под очереное имя файла/папки
|
2011-10-14 23:38:50 +02:00
|
|
|
|
xor eax, eax
|
|
|
|
|
mov ecx, 40 / 4
|
|
|
|
|
rep stosd
|
2012-07-25 18:26:11 +02:00
|
|
|
|
pop ecx edi
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
push esi edi edx
|
|
|
|
|
mov eax, [esi + EXT2_DIR_STRUC.inode] ;получим дочерний inode
|
2011-10-14 23:38:50 +02:00
|
|
|
|
mov ebx, [ext2_data.ext2_temp_inode]
|
|
|
|
|
call ext2_get_inode
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_read_subinode
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
|
|
lea edi, [edx + 8]
|
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov eax, [ebx + EXT2_INODE_STRUC.i_ctime] ; переведем время в ntfs формат
|
2011-10-14 23:38:50 +02: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 ; пока достаем только буфер
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test [ebx + EXT2_INODE_STRUC.i_mode], EXT2_S_IFDIR ; для папки размер
|
2011-10-14 23:38:50 +02:00
|
|
|
|
jnz @F ; не возвращаем
|
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov eax, [ebx + EXT2_INODE_STRUC.i_size] ;low size
|
2011-10-14 23:38:50 +02:00
|
|
|
|
stosd
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov eax, [ebx + EXT2_INODE_STRUC.i_dir_acl] ;high size
|
2011-10-14 23:38:50 +02:00
|
|
|
|
stosd
|
2012-07-25 18:26:11 +02:00
|
|
|
|
xor dword [edx], FS_FT_DIR ;помечаем, что это файл(2 раза xor)
|
|
|
|
|
@@:
|
|
|
|
|
xor dword [edx], FS_FT_DIR ;помечаем, что это файл
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
;теперь скопируем имя, сконвертировав из UTF-8 в CP866
|
|
|
|
|
push ecx ;edi и esi уже сохранены в стеке
|
|
|
|
|
movzx ecx, [esi + EXT2_DIR_STRUC.name_len]
|
2011-10-14 23:38:50 +02:00
|
|
|
|
lea edi, [edx + 40]
|
2012-07-25 18:26:11 +02:00
|
|
|
|
lea esi, [esi + EXT2_DIR_STRUC.name]
|
|
|
|
|
call utf8_to_cp866
|
2011-10-14 23:38:50 +02:00
|
|
|
|
and byte [edi], 0
|
2012-07-25 18:26:11 +02:00
|
|
|
|
pop ecx edi esi
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
cmp byte [edx + 40], '.' ; в linux файл, начинающийся с точки - скрытый
|
2011-10-14 23:38:50 +02:00
|
|
|
|
jne @F
|
|
|
|
|
or dword [edx], FS_FT_HIDDEN
|
2012-07-25 18:26:11 +02:00
|
|
|
|
@@:
|
2010-02-08 20:51:43 +01:00
|
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
|
add edx, 40 + 264 ; go to next record
|
|
|
|
|
dec ecx ; если запись пустая ecx не надо уменьшать
|
2012-07-25 18:26:11 +02:00
|
|
|
|
.empty_rec:
|
|
|
|
|
movzx ebx, [esi + EXT2_DIR_STRUC.rec_len]
|
2011-10-14 23:38:50 +02:00
|
|
|
|
cmp ebx, 12 ; минимальная длина записи
|
2012-07-25 18:26:11 +02:00
|
|
|
|
jb .error_bad_len
|
2011-10-14 23:38:50 +02:00
|
|
|
|
test ebx, 0x3 ; длина записи должна делиться на 4
|
2012-07-25 18:26:11 +02:00
|
|
|
|
jnz .error_bad_len
|
2010-02-17 18:26:25 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
add esi, ebx
|
|
|
|
|
cmp esi, [edi + 24] ;дошли ли до конца блока?
|
2011-10-14 23:38:50 +02:00
|
|
|
|
jb .wanted_start
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
push .wanted_start ; дошли
|
2010-02-09 15:17:26 +01:00
|
|
|
|
jmp .end_block
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
.end_dir: ;конец папки, когда еще не дошли до нужного файла
|
|
|
|
|
mov edx, [edi + 28] ;адрес структуры результата
|
|
|
|
|
mov ebx, [edi + 8] ;EXT2_read_in_folder
|
|
|
|
|
mov ecx, [edi + 4] ;EXT2_files_in_folder
|
2010-01-23 16:24:03 +01:00
|
|
|
|
mov dword [edx], 1 ;version
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov [edx + 4], ebx
|
|
|
|
|
mov [edx + 8], ecx
|
|
|
|
|
|
|
|
|
|
lea esp, [edi + 32]
|
|
|
|
|
|
|
|
|
|
xor eax, eax ;зарезервировано: нули в текущей реализации
|
2010-01-23 16:24:03 +01:00
|
|
|
|
lea edi, [edx + 12]
|
|
|
|
|
mov ecx, 20 / 4
|
2011-10-14 23:38:50 +02:00
|
|
|
|
rep stosd
|
2010-01-23 16:24:03 +01:00
|
|
|
|
ret
|
2012-07-25 18:26:11 +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
|
|
|
|
|
|
|
|
|
|
.error_empty_dir: ;inode папки без блоков
|
|
|
|
|
.error_root: ;root - не папка
|
|
|
|
|
mov eax, ERROR_FS_FAIL
|
|
|
|
|
jmp .error_ret
|
|
|
|
|
|
|
|
|
|
.error_not_found: ;файл не найден
|
|
|
|
|
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
|
2010-02-08 20:51:43 +01:00
|
|
|
|
; destroys: eax,esi,edi
|
2012-07-25 18:26:11 +02:00
|
|
|
|
utf8_to_cp866:
|
2010-02-08 20:51:43 +01:00
|
|
|
|
jecxz .ret
|
|
|
|
|
.start:
|
|
|
|
|
lodsw
|
2011-10-14 23:38:50 +02:00
|
|
|
|
cmp al, 0x80
|
2010-02-08 20:51:43 +01:00
|
|
|
|
jb .ascii
|
|
|
|
|
|
2010-02-09 15:17:26 +01:00
|
|
|
|
xchg al, ah ; big-endian
|
2010-02-08 20:51:43 +01:00
|
|
|
|
cmp ax, 0xd080
|
|
|
|
|
jz .yo1
|
|
|
|
|
cmp ax, 0xd191
|
|
|
|
|
jz .yo2
|
|
|
|
|
cmp ax, 0xd090
|
2011-10-14 23:38:50 +02:00
|
|
|
|
jb .unk
|
|
|
|
|
cmp ax, 0xd180
|
|
|
|
|
jb .rus1
|
|
|
|
|
cmp ax, 0xd190
|
2010-02-08 20:51:43 +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-01-23 16:24:03 +01:00
|
|
|
|
|
2011-10-14 23:38:50 +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-07-25 18:26:11 +02:00
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
;--------------------------------------------------------------
|
|
|
|
|
ext2_HdRead:
|
|
|
|
|
cmp byte [esi], 0
|
2010-02-08 20:51:43 +01:00
|
|
|
|
jnz @F
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2010-02-01 19:47:19 +01:00
|
|
|
|
.this_is_nofile:
|
2010-01-23 16:24:03 +01:00
|
|
|
|
or ebx, -1
|
|
|
|
|
mov eax, ERROR_ACCESS_DENIED
|
|
|
|
|
ret
|
|
|
|
|
|
2010-02-08 20:51:43 +01:00
|
|
|
|
@@:
|
2012-07-25 18:26:11 +02:00
|
|
|
|
push ecx ebx edx
|
2010-02-08 20:51:43 +01:00
|
|
|
|
call ext2_find_lfn
|
2012-07-25 18:26:11 +02:00
|
|
|
|
pop edx ebx ecx
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz @F
|
|
|
|
|
|
2010-02-08 20:51:43 +01:00
|
|
|
|
or ebx, -1
|
|
|
|
|
mov eax, ERROR_FILE_NOT_FOUND
|
|
|
|
|
ret
|
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
@@:
|
2012-09-11 19:39:26 +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
|
2010-02-08 20:51:43 +01:00
|
|
|
|
|
|
|
|
|
mov edi, edx ; edi = pointer to return mem
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test ebx, ebx
|
|
|
|
|
jz @F
|
|
|
|
|
mov esi, ebx ; esi = pointer to first_wanted
|
2010-01-23 16:24:03 +01:00
|
|
|
|
mov ebx, [esi+4]
|
|
|
|
|
mov eax, [esi] ; ebx : eax - стартовый номер байта
|
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
;///// сравним хватит ли нам файла или нет
|
2010-02-08 20:51:43 +01:00
|
|
|
|
cmp [ebp + EXT2_INODE_STRUC.i_dir_acl], ebx
|
2010-01-23 16:24:03 +01:00
|
|
|
|
ja .size_great
|
|
|
|
|
jb .size_less
|
|
|
|
|
|
2010-02-08 20:51:43 +01:00
|
|
|
|
cmp [ebp + EXT2_INODE_STRUC.i_size], eax
|
2010-01-23 16:24:03 +01:00
|
|
|
|
ja .size_great
|
|
|
|
|
|
|
|
|
|
.size_less:
|
2010-02-08 20:51:43 +01:00
|
|
|
|
xor ebx, ebx
|
2010-02-17 18:26:25 +01:00
|
|
|
|
mov eax, ERROR_END_OF_FILE
|
2010-01-23 16:24:03 +01:00
|
|
|
|
ret
|
2012-07-25 18:26:11 +02:00
|
|
|
|
|
|
|
|
|
@@:
|
|
|
|
|
xor ebx, ebx
|
|
|
|
|
xor eax, eax
|
2010-01-23 16:24:03 +01:00
|
|
|
|
.size_great:
|
2010-02-08 20:51:43 +01:00
|
|
|
|
add eax, ecx ;add to first_wanted кол-во байт для чтения
|
|
|
|
|
adc ebx, 0
|
|
|
|
|
|
|
|
|
|
cmp [ebp + EXT2_INODE_STRUC.i_dir_acl], ebx
|
2010-01-23 16:24:03 +01:00
|
|
|
|
ja .size_great_great
|
|
|
|
|
jb .size_great_less
|
2010-02-08 20:51:43 +01:00
|
|
|
|
cmp [ebp + EXT2_INODE_STRUC.i_size], eax
|
2012-07-25 18:26:11 +02:00
|
|
|
|
jae .size_great_great
|
2010-02-08 20:51:43 +01:00
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
.size_great_less:
|
2013-03-03 14:53:24 +01:00
|
|
|
|
push 1 ;читаем по границе размера
|
2010-02-08 20:51:43 +01:00
|
|
|
|
mov ecx, [ebp + EXT2_INODE_STRUC.i_size]
|
2012-07-25 18:26:11 +02:00
|
|
|
|
sub ecx, [esi] ;(размер - старт) = сколько читать
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jmp @F
|
|
|
|
|
|
|
|
|
|
.size_great_great:
|
2013-03-03 14:53:24 +01:00
|
|
|
|
push 0 ;читаем столько сколько запросили
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
@@:
|
2012-07-25 18:26:11 +02:00
|
|
|
|
;здесь мы точно знаем сколько байт читать - ecx
|
|
|
|
|
;edi - return memory
|
|
|
|
|
;esi -> first wanted
|
|
|
|
|
|
|
|
|
|
push ecx ;количество считанных байт
|
2010-02-08 20:51:43 +01:00
|
|
|
|
test esi, esi
|
|
|
|
|
jz .zero_start
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
;получим кусок из первого блока
|
2010-02-08 20:51:43 +01:00
|
|
|
|
mov edx, [esi+4]
|
|
|
|
|
mov eax, [esi]
|
2010-01-23 16:24:03 +01:00
|
|
|
|
div [ext2_data.block_size]
|
|
|
|
|
|
2013-03-03 14:53:24 +01:00
|
|
|
|
push eax ;счетчик блоков ложим в стек
|
2012-07-25 18:26:11 +02:00
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
push ecx
|
|
|
|
|
mov ecx, eax
|
|
|
|
|
call ext2_get_inode_block
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_at_first_block
|
2010-02-08 20:51:43 +01:00
|
|
|
|
mov ebx, [ext2_data.ext2_save_block]
|
2010-01-23 16:24:03 +01:00
|
|
|
|
mov eax, ecx
|
|
|
|
|
call ext2_get_block
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_at_first_block
|
2010-01-23 16:24:03 +01:00
|
|
|
|
pop ecx
|
|
|
|
|
add ebx, edx
|
|
|
|
|
|
|
|
|
|
neg edx
|
2011-10-14 23:38:50 +02:00
|
|
|
|
add edx, [ext2_data.block_size] ;block_size - стартовый байт = сколько байт 1-го блока
|
2010-01-23 16:24:03 +01:00
|
|
|
|
cmp ecx, edx
|
|
|
|
|
jbe .only_one_block
|
|
|
|
|
|
|
|
|
|
mov eax, ecx
|
|
|
|
|
sub eax, edx
|
|
|
|
|
mov ecx, edx
|
|
|
|
|
|
|
|
|
|
mov esi, ebx
|
2011-10-14 23:38:50 +02:00
|
|
|
|
rep movsb ;кусок 1-го блока
|
2012-07-25 18:26:11 +02:00
|
|
|
|
jmp .calc_blocks_count
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
.zero_start:
|
2010-02-04 17:44:28 +01:00
|
|
|
|
mov eax, ecx
|
2013-03-03 14:53:24 +01:00
|
|
|
|
push 0 ;счетчик блоков ложим в стек
|
2010-01-23 16:24:03 +01:00
|
|
|
|
;теперь в eax кол-во оставшихся байт для чтения
|
2012-07-25 18:26:11 +02:00
|
|
|
|
.calc_blocks_count:
|
2010-02-08 20:51:43 +01:00
|
|
|
|
mov ebx, edi ;чтение блока прям в ->ebx
|
2010-01-23 16:24:03 +01:00
|
|
|
|
xor edx, edx
|
2012-07-25 18:26:11 +02:00
|
|
|
|
div [ext2_data.block_size] ;кол-во байт в последнем блоке (остаток) в edx
|
2010-02-08 20:51:43 +01:00
|
|
|
|
mov edi, eax ;кол-во целых блоков в edi
|
2010-01-23 16:24:03 +01:00
|
|
|
|
@@:
|
2011-10-14 23:38:50 +02:00
|
|
|
|
test edi, edi
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jz .finish_block
|
2012-07-25 18:26:11 +02:00
|
|
|
|
inc dword [esp]
|
|
|
|
|
mov ecx, [esp]
|
2010-01-23 16:24:03 +01:00
|
|
|
|
call ext2_get_inode_block
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_at_read_cycle
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2010-02-08 20:51:43 +01:00
|
|
|
|
mov eax, ecx ;а ebx уже забит нужным значением
|
2010-01-23 16:24:03 +01:00
|
|
|
|
call ext2_get_block
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_at_read_cycle
|
2010-01-23 16:24:03 +01:00
|
|
|
|
add ebx, [ext2_data.block_size]
|
|
|
|
|
|
2010-02-08 20:51:43 +01:00
|
|
|
|
dec edi
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jmp @B
|
|
|
|
|
|
|
|
|
|
.finish_block: ;в edx - кол-во байт в последнем блоке
|
2010-02-08 20:51:43 +01:00
|
|
|
|
test edx, edx
|
|
|
|
|
jz .end_read
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
pop ecx ;счетчик блоков -> ecx
|
2010-01-23 16:24:03 +01:00
|
|
|
|
inc ecx
|
|
|
|
|
call ext2_get_inode_block
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
2013-03-03 19:42:16 +01:00
|
|
|
|
jnz .error_at_finish_block
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
mov edi, ebx
|
|
|
|
|
mov eax, ecx
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_block]
|
|
|
|
|
call ext2_get_block
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_at_finish_block
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov ecx, edx
|
2010-01-23 16:24:03 +01:00
|
|
|
|
mov esi, ebx
|
2011-10-14 23:38:50 +02:00
|
|
|
|
rep movsb ;кусок last блока
|
2013-03-03 14:53:24 +01:00
|
|
|
|
jmp @F
|
|
|
|
|
|
2010-02-04 17:44:28 +01:00
|
|
|
|
.end_read:
|
2013-03-03 14:53:24 +01:00
|
|
|
|
pop ecx ;счетчик блоков, который хранился в стеке
|
|
|
|
|
@@:
|
|
|
|
|
pop ebx ;количество считанных байт
|
|
|
|
|
pop eax ; 1 или 0 - достигли ли конца файла
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jz @F
|
|
|
|
|
|
2010-02-17 18:26:25 +01:00
|
|
|
|
mov eax, ERROR_END_OF_FILE
|
2010-01-23 16:24:03 +01:00
|
|
|
|
ret
|
|
|
|
|
@@:
|
|
|
|
|
xor eax, eax
|
|
|
|
|
ret
|
2012-07-25 18:26:11 +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
|
|
|
|
|
add edx, [ext2_data.block_size] ;запомним конец блока
|
|
|
|
|
|
|
|
|
|
.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]
|
|
|
|
|
sub ecx, edi ;кол-во байт в получившейся строке
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
@@: ;не подошло
|
|
|
|
|
pop esi
|
|
|
|
|
.next_rec:
|
|
|
|
|
movzx eax, [ebx + EXT2_DIR_STRUC.rec_len]
|
|
|
|
|
add ebx, eax ;к след. записи
|
|
|
|
|
cmp ebx, edx ;проверим конец ли
|
|
|
|
|
jb .start_rec
|
|
|
|
|
add esp, 256
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
.test_find:
|
|
|
|
|
cmp byte [esi], 0
|
|
|
|
|
je .ret ;нашли конец
|
|
|
|
|
cmp byte [esi], '/'
|
|
|
|
|
jne @B
|
|
|
|
|
inc esi
|
|
|
|
|
.ret:
|
|
|
|
|
add esp, 256 + 4
|
|
|
|
|
ret
|
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
;========================
|
2012-07-25 18:26:11 +02:00
|
|
|
|
;Ищет inode по строке пути
|
|
|
|
|
;in: esi = name
|
|
|
|
|
;out: eax - error code
|
|
|
|
|
; ebp = inode
|
|
|
|
|
; dl - первый байт из имени файла/папки
|
2010-02-01 19:47:19 +01:00
|
|
|
|
ext2_find_lfn:
|
|
|
|
|
mov ebp, [ext2_data.root_inode]
|
2012-07-25 18:26:11 +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:
|
2010-02-01 19:47:19 +01:00
|
|
|
|
call ext2_get_inode_block
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_get_inode_block
|
|
|
|
|
|
2010-02-01 19:47:19 +01:00
|
|
|
|
mov eax, ecx
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_block] ;ebx = cur dir record
|
|
|
|
|
call ext2_get_block
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_get_block
|
|
|
|
|
|
|
|
|
|
push esi
|
2010-02-01 19:47:19 +01:00
|
|
|
|
call ext2_test_block_by_name
|
2012-07-25 18:26:11 +02:00
|
|
|
|
pop edi
|
2010-02-01 19:47:19 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
cmp edi, esi ;нашли имя?
|
|
|
|
|
je .next_folder_block ;не нашли -> к след. блоку
|
|
|
|
|
|
|
|
|
|
cmp byte [esi], 0 ;дошли до "конца" пути -> возваращаемся
|
2010-02-01 19:47:19 +01:00
|
|
|
|
jz .get_inode_ret
|
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
cmp [ebx + EXT2_DIR_STRUC.file_type], EXT2_FT_DIR ;нашли, но это не папка
|
|
|
|
|
jne .not_found
|
|
|
|
|
|
2010-02-01 19:47:19 +01:00
|
|
|
|
mov eax, [ebx + EXT2_DIR_STRUC.inode]
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_inode] ;все же папка.
|
|
|
|
|
call ext2_get_inode
|
2012-07-25 18:26:11 +02:00
|
|
|
|
test eax, eax
|
|
|
|
|
jnz .error_get_inode
|
|
|
|
|
pop ecx ;в стеке лежит кол-во блоков
|
2010-02-01 19:47:19 +01:00
|
|
|
|
mov ebp, ebx
|
2012-07-25 18:26:11 +02:00
|
|
|
|
jmp .next_path_part
|
|
|
|
|
|
|
|
|
|
.next_folder_block:
|
|
|
|
|
;к следующему блоку в текущей папке
|
|
|
|
|
pop eax ;счетчик блоков
|
|
|
|
|
sub eax, [ext2_data.count_block_in_block]
|
|
|
|
|
jle .not_found
|
|
|
|
|
|
2013-03-03 17:32:44 +01:00
|
|
|
|
push eax
|
2012-07-25 18:26:11 +02:00
|
|
|
|
inc ecx
|
|
|
|
|
jmp .folder_block_cycle
|
2010-02-01 19:47:19 +01:00
|
|
|
|
|
|
|
|
|
.not_found:
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov eax, ERROR_FILE_NOT_FOUND
|
2010-02-01 19:47:19 +01:00
|
|
|
|
ret
|
2012-07-25 18:26:11 +02:00
|
|
|
|
|
2010-02-01 19:47:19 +01:00
|
|
|
|
.get_inode_ret:
|
2012-07-25 18:26:11 +02:00
|
|
|
|
pop ecx ;в стеке лежит кол-во блоков
|
|
|
|
|
mov dl, [ebx + EXT2_DIR_STRUC.name] ;в dl - первый символ ()
|
2010-02-01 19:47:19 +01:00
|
|
|
|
mov eax, [ebx + EXT2_DIR_STRUC.inode]
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_inode]
|
|
|
|
|
call ext2_get_inode
|
|
|
|
|
mov ebp, ebx
|
2012-07-25 18:26:11 +02:00
|
|
|
|
xor eax, eax
|
2010-02-01 19:47:19 +01:00
|
|
|
|
ret
|
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
.error_get_inode_block:
|
|
|
|
|
.error_get_block:
|
|
|
|
|
.error_get_inode:
|
|
|
|
|
pop ebx
|
|
|
|
|
.error_empty_root:
|
|
|
|
|
mov eax, ERROR_FS_FAIL
|
|
|
|
|
ret
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
|
;ext2_HdGetFileInfo - read file info from block device
|
|
|
|
|
;
|
|
|
|
|
;in: esi points to filename
|
|
|
|
|
; edx mem location to return data
|
|
|
|
|
;--------------------------------------------------------------
|
2010-01-23 16:24:03 +01:00
|
|
|
|
ext2_HdGetFileInfo:
|
2012-07-25 18:26:11 +02:00
|
|
|
|
xchg bx, bx
|
2010-02-01 19:47:19 +01:00
|
|
|
|
cmp byte [esi], 0
|
2012-07-25 18:26:11 +02:00
|
|
|
|
jz .is_root
|
2010-02-01 19:47:19 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
push edx
|
2010-02-01 19:47:19 +01:00
|
|
|
|
call ext2_find_lfn
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov ebx, edx
|
|
|
|
|
pop edx
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz @F
|
2010-02-01 19:47:19 +01:00
|
|
|
|
ret
|
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
.is_root:
|
|
|
|
|
xor ebx, ebx ;root не может быть скрытым
|
2010-02-01 19:47:19 +01:00
|
|
|
|
mov ebp, [ext2_data.root_inode]
|
2010-02-09 15:17:26 +01:00
|
|
|
|
@@:
|
2010-02-01 19:47:19 +01:00
|
|
|
|
xor eax, eax
|
|
|
|
|
mov edi, edx
|
|
|
|
|
mov ecx, 40/4
|
2011-10-14 23:38:50 +02:00
|
|
|
|
rep stosd ; fill zero
|
2010-02-01 19:47:19 +01:00
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
cmp bl, '.'
|
|
|
|
|
jne @F
|
2010-02-09 15:17:26 +01:00
|
|
|
|
or dword [edx], FS_FT_HIDDEN
|
2010-02-01 19:47:19 +01:00
|
|
|
|
@@:
|
2010-02-09 15:17:26 +01:00
|
|
|
|
|
|
|
|
|
test [ebp + EXT2_INODE_STRUC.i_mode], EXT2_S_IFDIR
|
2011-10-14 23:38:50 +02:00
|
|
|
|
jnz @F
|
2010-02-01 19:47:19 +01:00
|
|
|
|
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
|
2010-02-09 15:17:26 +01:00
|
|
|
|
xor dword [edx], FS_FT_DIR
|
|
|
|
|
@@:
|
|
|
|
|
xor dword [edx], FS_FT_DIR
|
|
|
|
|
|
|
|
|
|
lea edi, [edx + 8]
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov eax, [ebp + EXT2_INODE_STRUC.i_ctime]
|
2010-02-09 15:17:26 +01:00
|
|
|
|
xor edx, edx
|
|
|
|
|
add eax, 3054539008
|
|
|
|
|
adc edx, 2
|
|
|
|
|
call ntfs_datetime_to_bdfe.sec
|
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov eax, [ebp + EXT2_INODE_STRUC.i_atime]
|
2010-02-09 15:17:26 +01:00
|
|
|
|
xor edx, edx
|
|
|
|
|
add eax, 3054539008
|
|
|
|
|
adc edx, 2
|
|
|
|
|
call ntfs_datetime_to_bdfe.sec
|
|
|
|
|
|
2012-07-25 18:26:11 +02:00
|
|
|
|
mov eax, [ebp + EXT2_INODE_STRUC.i_mtime]
|
2010-02-09 15:17:26 +01:00
|
|
|
|
xor edx, edx
|
|
|
|
|
add eax, 3054539008
|
|
|
|
|
adc edx, 2
|
|
|
|
|
call ntfs_datetime_to_bdfe.sec
|
2010-02-01 19:47:19 +01:00
|
|
|
|
|
|
|
|
|
xor eax, eax
|
2010-01-23 16:24:03 +01:00
|
|
|
|
ret
|
2010-02-01 19:47:19 +01:00
|
|
|
|
|
2010-02-17 18:26:25 +01:00
|
|
|
|
ext2_HdRewrite:
|
|
|
|
|
ext2_HdWrite:
|
|
|
|
|
ext2_HdSetFileEnd:
|
2010-01-23 16:24:03 +01:00
|
|
|
|
ext2_HdSetFileInfo:
|
2010-02-17 18:26:25 +01:00
|
|
|
|
ext2_HdDelete:
|
|
|
|
|
ext2_HdCreateFolder:
|
2010-01-23 16:24:03 +01:00
|
|
|
|
xor ebx, ebx
|
|
|
|
|
mov eax, ERROR_UNSUPPORTED_FS
|
|
|
|
|
ret
|