2010-01-23 16:24:03 +01:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;; ;;
|
|
|
|
|
;; Copyright (C) KolibriOS team 2004-2010. All rights reserved. ;;
|
|
|
|
|
;; 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$
|
|
|
|
|
|
|
|
|
|
EXT2_BAD_INO = 1
|
|
|
|
|
EXT2_ROOT_INO = 2
|
|
|
|
|
EXT2_ACL_IDX_INO = 3
|
|
|
|
|
EXT2_ACL_DATA_INO = 4
|
|
|
|
|
EXT2_BOOT_LOADER_INO= 5
|
|
|
|
|
EXT2_UNDEL_DIR_INO = 6
|
|
|
|
|
|
|
|
|
|
;type inode
|
2010-02-01 19:47:19 +01:00
|
|
|
|
EXT2_S_IFREG = 0x8000
|
|
|
|
|
EXT2_S_IFDIR = 0x4000
|
2010-01-23 16:24:03 +01:00
|
|
|
|
;user inode right's
|
|
|
|
|
EXT2_S_IRUSR = 0x0100
|
|
|
|
|
EXT2_S_IWUSR = 0x0080
|
|
|
|
|
EXT2_S_IXUSR = 0x0040
|
|
|
|
|
;group inode right's
|
|
|
|
|
EXT2_S_IRGRP = 0x0020
|
|
|
|
|
EXT2_S_IWGRP = 0x0010
|
|
|
|
|
EXT2_S_IXGRP = 0x0008
|
|
|
|
|
;other inode right's
|
|
|
|
|
EXT2_S_IROTH = 0x0004
|
2010-02-17 18:26:25 +01:00
|
|
|
|
EXT2_S_IWOTH = 0x0002
|
|
|
|
|
EXT2_S_IXOTH = 0x0001
|
|
|
|
|
EXT2_777_MODE = EXT2_S_IROTH or EXT2_S_IWOTH or EXT2_S_IXOTH or \
|
|
|
|
|
EXT2_S_IRGRP or EXT2_S_IWGRP or EXT2_S_IXGRP or \
|
|
|
|
|
EXT2_S_IRUSR or EXT2_S_IWUSR or EXT2_S_IXUSR
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
EXT2_FT_REG_FILE = 1 ;это файл, запись в родительском каталоге
|
|
|
|
|
EXT2_FT_DIR = 2 ;это папка
|
|
|
|
|
|
2010-02-09 15:17:26 +01:00
|
|
|
|
FS_FT_HIDDEN = 2
|
2010-01-23 16:24:03 +01:00
|
|
|
|
FS_FT_DIR = 0x10 ;это папка
|
|
|
|
|
FS_FT_ASCII = 0 ;имя в ascii
|
|
|
|
|
FS_FT_UNICODE = 1 ;имя в unicode
|
|
|
|
|
|
2010-02-13 14:34:41 +01:00
|
|
|
|
EXT2_FEATURE_INCOMPAT_FILETYPE = 0x0002
|
|
|
|
|
|
2010-02-08 20:51:43 +01:00
|
|
|
|
uglobal
|
|
|
|
|
EXT2_files_in_folder dd ? ;всего файлов в папке
|
|
|
|
|
EXT2_read_in_folder dd ? ;сколько файлов "считали"
|
|
|
|
|
EXT2_end_block dd ? ;конец очередного блока папки
|
|
|
|
|
EXT2_counter_blocks dd ?
|
|
|
|
|
EXT2_filename db 256 dup ?
|
2010-02-17 18:26:25 +01:00
|
|
|
|
EXT2_parent_name db 256 dup ?
|
|
|
|
|
EXT2_name_len dd ?
|
2010-02-08 20:51:43 +01:00
|
|
|
|
endg
|
|
|
|
|
|
2010-01-23 16:24:03 +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 dd 15 dup ?
|
|
|
|
|
.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
|
|
|
|
|
|
2010-02-17 18:26:25 +01:00
|
|
|
|
struct EXT2_BLOCK_GROUP_DESC
|
|
|
|
|
.block_bitmap dd ?
|
|
|
|
|
.inode_bitmap dd ?
|
|
|
|
|
.inode_table dd ?
|
|
|
|
|
.free_blocks_count dw ?
|
|
|
|
|
.free_inodes_count dw ?
|
|
|
|
|
.used_dirs_count dw ?
|
|
|
|
|
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 db 16 dup ? ;+104
|
|
|
|
|
.volume_name db 16 dup ? ;+120
|
|
|
|
|
.last_mounted db 64 dup ? ;+136
|
|
|
|
|
.algo_bitmap dd ? ;+200
|
|
|
|
|
.prealloc_blocks db ? ;+204
|
|
|
|
|
.preallock_dir_blocks db ? ;+205
|
|
|
|
|
dw ? ;+206 alignment
|
|
|
|
|
.journal_uuid db 16 dup ? ;+208
|
|
|
|
|
.journal_inum dd ? ;+224
|
|
|
|
|
.journal_dev dd ? ;+228
|
|
|
|
|
.last_orphan dd ? ;+232
|
|
|
|
|
.hash_seed dd 4 dup ? ;+236
|
|
|
|
|
.def_hash_version db ? ;+252
|
|
|
|
|
db 3 dup ? ;+253 reserved
|
|
|
|
|
.default_mount_options dd ? ;+256
|
|
|
|
|
.first_meta_bg dd ? ;+260
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
cmp dword [ebx+24], 3 ;s_block_size 0,1,2,3
|
|
|
|
|
ja .no
|
|
|
|
|
cmp word [ebx+56], 0xEF53 ;s_magic
|
|
|
|
|
jne .no
|
|
|
|
|
cmp word [ebx+58], 1 ;s_state (EXT_VALID_FS=1)
|
|
|
|
|
jne .no
|
2010-02-13 14:34:41 +01:00
|
|
|
|
mov eax, [ebx+96]
|
|
|
|
|
test eax, EXT2_FEATURE_INCOMPAT_FILETYPE
|
|
|
|
|
jz .no
|
|
|
|
|
test eax, not EXT2_FEATURE_INCOMPAT_FILETYPE
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
mov ecx, [ebx+24]
|
|
|
|
|
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
|
|
|
|
|
|
2010-02-01 19:47:19 +01:00
|
|
|
|
movzx ebp, word [ebx+88]
|
2010-01-23 16:24:03 +01:00
|
|
|
|
mov ecx, [ebx+32]
|
|
|
|
|
mov edx, [ebx+40]
|
|
|
|
|
|
|
|
|
|
mov [ext2_data.inode_size], ebp
|
|
|
|
|
mov [ext2_data.blocks_per_group], ecx
|
|
|
|
|
mov [ext2_data.inodes_per_group], edx
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2010-02-13 14:34:41 +01:00
|
|
|
|
jmp return_from_part_set
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
;==================================================================
|
|
|
|
|
;in: eax = i_block
|
|
|
|
|
; ebx = pointer to return memory
|
|
|
|
|
ext2_get_block:
|
|
|
|
|
push eax ebx ecx
|
|
|
|
|
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
|
|
|
|
|
inc eax
|
|
|
|
|
add ebx, 512
|
|
|
|
|
loop @B
|
|
|
|
|
pop ecx ebx eax
|
|
|
|
|
ret
|
|
|
|
|
;===================================================================
|
2010-02-03 19:01:16 +01:00
|
|
|
|
; in: ecx = номер блока в inode (0..)
|
2010-01-23 16:24:03 +01:00
|
|
|
|
; ebp = адрес inode
|
|
|
|
|
; out: ecx = адрес очередного блока
|
|
|
|
|
ext2_get_inode_block:
|
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
|
2010-02-03 19:01:16 +01:00
|
|
|
|
cmp ecx, [ext2_data.count_pointer_in_block] ; 12.. - indirect block
|
|
|
|
|
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]
|
2010-01-23 16:24:03 +01:00
|
|
|
|
;.get_triple_indirect_block:
|
|
|
|
|
push eax edx ebx
|
|
|
|
|
|
|
|
|
|
mov eax, [ebx + EXT2_INODE_STRUC.i_block + 14*4]
|
|
|
|
|
mov ebx, [ext2_data.ext2_temp_block]
|
|
|
|
|
call ext2_get_block
|
|
|
|
|
|
|
|
|
|
xor edx, edx
|
|
|
|
|
mov eax, ecx
|
|
|
|
|
div [ext2_data.count_pointer_in_block_square]
|
|
|
|
|
|
|
|
|
|
;eax - номер в полученном блоке edx - номер дальше
|
|
|
|
|
mov eax, [ebx + eax*4]
|
2010-02-03 19:01:16 +01:00
|
|
|
|
call ext2_get_block
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
mov eax, edx
|
|
|
|
|
jmp @F
|
|
|
|
|
|
|
|
|
|
.get_double_indirect_block:
|
|
|
|
|
push eax edx ebx
|
|
|
|
|
|
|
|
|
|
mov eax, [ebp + EXT2_INODE_STRUC.i_block + 13*4]
|
|
|
|
|
mov ebx, [ext2_data.ext2_temp_block]
|
|
|
|
|
call ext2_get_block
|
|
|
|
|
|
|
|
|
|
mov eax, ecx
|
|
|
|
|
@@:
|
|
|
|
|
xor edx, edx
|
|
|
|
|
div [ext2_data.count_pointer_in_block]
|
|
|
|
|
|
|
|
|
|
mov eax, [ebx + eax*4]
|
|
|
|
|
call ext2_get_block
|
|
|
|
|
mov ecx, [ebx + edx*4]
|
|
|
|
|
|
|
|
|
|
pop ebx edx eax
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
.get_indirect_block:
|
|
|
|
|
push eax ebx
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
mov ecx, [ebx + ecx*4]
|
|
|
|
|
pop ebx eax
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
.get_direct_block:
|
|
|
|
|
mov ecx, dword [ebp + EXT2_INODE_STRUC.i_block + ecx*4]
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;===================================================================
|
|
|
|
|
;get content inode by num
|
|
|
|
|
;in: eax = inode_num
|
|
|
|
|
; ebx = address of inode content
|
|
|
|
|
ext2_get_inode:
|
|
|
|
|
|
|
|
|
|
pushad
|
2010-02-17 18:26:25 +01:00
|
|
|
|
mov edi, ebx ;сохраним адрес inode
|
2010-01-23 16:24:03 +01:00
|
|
|
|
dec eax
|
|
|
|
|
xor edx, edx
|
|
|
|
|
div [ext2_data.inodes_per_group]
|
|
|
|
|
|
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]
|
|
|
|
|
mov ecx, [ext2_data.sb]
|
|
|
|
|
add eax, [ecx + EXT2_SB_STRUC.first_data_block]
|
|
|
|
|
inc eax
|
|
|
|
|
mov ebx, [ext2_data.ext2_temp_block]
|
|
|
|
|
call ext2_get_block
|
|
|
|
|
|
|
|
|
|
add ebx, edx ; локальный номер в блоке
|
|
|
|
|
mov eax, [ebx+8] ; номер блока - в терминах ext2
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
mov ecx, [ext2_data.log_block_size]
|
|
|
|
|
shl eax, cl
|
|
|
|
|
add eax, [PARTITION_START] ; а старт раздела - в терминах hdd (512)
|
|
|
|
|
|
|
|
|
|
;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
|
|
|
|
|
|
|
|
|
|
mov esi, edx ;добавим "остаток"
|
|
|
|
|
add esi, ebx ;к адресу
|
2010-02-13 14:34:41 +01:00
|
|
|
|
; mov ecx, [ext2_data.inode_size]
|
2010-01-23 16:24:03 +01:00
|
|
|
|
rep movsb ;копируем inode
|
|
|
|
|
popad
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
|
; in: esi -> children
|
|
|
|
|
; ebx -> pointer to dir block
|
|
|
|
|
; out: esi -> name without parent or not_changed
|
|
|
|
|
; ebx -> dir_rec of inode children or trash
|
|
|
|
|
ext2_test_block_by_name:
|
|
|
|
|
push eax ecx edx edi
|
|
|
|
|
|
|
|
|
|
mov edx, ebx
|
|
|
|
|
add edx, [ext2_data.block_size] ;запомним конец блока
|
|
|
|
|
|
|
|
|
|
.start_rec:
|
|
|
|
|
cmp [ebx + EXT2_DIR_STRUC.inode], 0
|
|
|
|
|
jz .next_rec
|
|
|
|
|
|
|
|
|
|
push esi
|
|
|
|
|
movzx ecx, [ebx + EXT2_DIR_STRUC.name_len]
|
2010-02-08 20:51:43 +01:00
|
|
|
|
mov edi, EXT2_filename
|
|
|
|
|
lea esi, [ebx + EXT2_DIR_STRUC.name]
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2010-02-08 20:51:43 +01:00
|
|
|
|
call utf8toansi_str
|
|
|
|
|
mov ecx, edi
|
|
|
|
|
sub ecx, EXT2_filename ;кол-во байт в получившейся строке
|
|
|
|
|
|
|
|
|
|
mov edi, EXT2_filename
|
|
|
|
|
mov esi, [esp]
|
2010-01-23 16:24:03 +01:00
|
|
|
|
@@:
|
|
|
|
|
jecxz .test_find
|
2010-02-08 20:51:43 +01:00
|
|
|
|
dec ecx
|
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
lodsb
|
2010-02-08 20:51:43 +01:00
|
|
|
|
call char_toupper
|
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
mov ah, [edi]
|
|
|
|
|
inc edi
|
|
|
|
|
xchg al, ah
|
2010-02-08 20:51:43 +01:00
|
|
|
|
call char_toupper
|
2010-01-23 16:24:03 +01:00
|
|
|
|
cmp al, ah
|
|
|
|
|
je @B
|
|
|
|
|
@@: ;не подошло
|
|
|
|
|
pop esi
|
|
|
|
|
.next_rec:
|
|
|
|
|
movzx eax, [ebx + EXT2_DIR_STRUC.rec_len]
|
|
|
|
|
add ebx, eax ;к след. записи
|
|
|
|
|
cmp ebx, edx ;проверим конец ли
|
2010-02-01 19:47:19 +01:00
|
|
|
|
jb .start_rec
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jmp .ret
|
|
|
|
|
|
|
|
|
|
.test_find:
|
|
|
|
|
cmp byte [esi], 0
|
|
|
|
|
je .find ;нашли конец
|
|
|
|
|
cmp byte [esi], '/'
|
|
|
|
|
jne @B
|
|
|
|
|
inc esi
|
|
|
|
|
.find:
|
|
|
|
|
pop eax ;удаляем из стека сохраненое значение
|
|
|
|
|
.ret:
|
|
|
|
|
pop edi edx ecx eax
|
|
|
|
|
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
|
2010-02-03 19:01:16 +01:00
|
|
|
|
jz .doit
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2010-02-03 19:01:16 +01:00
|
|
|
|
push ecx ebx
|
|
|
|
|
call ext2_find_lfn
|
|
|
|
|
jnc .doit2
|
|
|
|
|
pop ebx
|
2010-01-23 16:24:03 +01:00
|
|
|
|
.not_found:
|
2010-02-03 19:01:16 +01:00
|
|
|
|
pop ecx
|
2010-01-23 16:24:03 +01:00
|
|
|
|
or ebx, -1
|
|
|
|
|
mov eax, ERROR_FILE_NOT_FOUND
|
|
|
|
|
ret
|
|
|
|
|
|
2010-02-03 19:01:16 +01:00
|
|
|
|
.doit:
|
|
|
|
|
mov ebp, [ext2_data.root_inode]
|
|
|
|
|
push ecx
|
|
|
|
|
jmp @F
|
|
|
|
|
.doit2:
|
|
|
|
|
pop ebx
|
|
|
|
|
test [ebp + EXT2_INODE_STRUC.i_mode], EXT2_S_IFDIR
|
|
|
|
|
jz .not_found
|
|
|
|
|
@@:
|
|
|
|
|
xor eax, eax
|
|
|
|
|
mov edi, edx
|
|
|
|
|
mov ecx, 32/4
|
|
|
|
|
rep stosd ; fill header zero
|
|
|
|
|
pop edi ; edi = число блоков для чтения
|
|
|
|
|
push edx ebx
|
|
|
|
|
|
|
|
|
|
;--------------------------------------------- final step
|
2010-01-23 16:24:03 +01:00
|
|
|
|
and [EXT2_read_in_folder], 0
|
|
|
|
|
and [EXT2_files_in_folder], 0
|
|
|
|
|
|
2010-02-01 19:47:19 +01:00
|
|
|
|
mov eax, [ebp + EXT2_INODE_STRUC.i_blocks]
|
|
|
|
|
mov [EXT2_counter_blocks], eax
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2010-02-08 20:51:43 +01:00
|
|
|
|
add edx, 32 ; (header pointer in stack) edx = current mem for return
|
2010-02-03 19:01:16 +01:00
|
|
|
|
xor esi, esi ; esi = номер блока по порядку
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
.new_block_folder: ;reserved label
|
|
|
|
|
mov ecx, esi ; получим номер блока
|
|
|
|
|
call ext2_get_inode_block
|
|
|
|
|
|
|
|
|
|
mov eax, ecx
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_block]
|
|
|
|
|
call ext2_get_block ; и считываем блок с hdd
|
|
|
|
|
|
|
|
|
|
mov eax, ebx ; eax = current dir record
|
|
|
|
|
add ebx, [ext2_data.block_size]
|
|
|
|
|
mov [EXT2_end_block], ebx ; запомним конец очередного блока
|
|
|
|
|
|
|
|
|
|
pop ecx
|
|
|
|
|
mov ecx, [ecx] ; ecx = first wanted (flags ommited)
|
|
|
|
|
|
|
|
|
|
.find_wanted_start:
|
2010-02-08 21:43:55 +01:00
|
|
|
|
jecxz .find_wanted_end
|
2010-01-23 16:24:03 +01:00
|
|
|
|
.find_wanted_cycle:
|
|
|
|
|
cmp [eax + EXT2_DIR_STRUC.inode], 0 ; if (inode = 0) => not used
|
2010-02-08 20:51:43 +01:00
|
|
|
|
jz @F
|
2010-01-23 16:24:03 +01:00
|
|
|
|
inc [EXT2_files_in_folder]
|
2010-02-08 21:43:55 +01:00
|
|
|
|
dec ecx
|
2010-01-23 16:24:03 +01:00
|
|
|
|
@@:
|
|
|
|
|
movzx ebx, [eax+EXT2_DIR_STRUC.rec_len]
|
2010-02-17 18:26:25 +01:00
|
|
|
|
|
|
|
|
|
cmp ebx, 12 ; минимальная длина записи
|
|
|
|
|
jb .end_error
|
|
|
|
|
test ebx, 0x3 ; длина записи должна делиться на 4
|
|
|
|
|
jnz .end_error
|
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
add eax, ebx ; к следующей записи
|
|
|
|
|
cmp eax, [EXT2_end_block] ; проверяем "конец"
|
2010-02-08 21:43:55 +01:00
|
|
|
|
jb .find_wanted_start
|
|
|
|
|
|
2010-02-17 18:26:25 +01:00
|
|
|
|
push .find_wanted_start
|
2010-02-09 15:17:26 +01:00
|
|
|
|
.end_block: ;вылетили из цикла
|
2010-02-08 21:43:55 +01:00
|
|
|
|
mov ebx, [ext2_data.count_block_in_block]
|
|
|
|
|
sub [EXT2_counter_blocks], ebx
|
2010-02-09 15:17:26 +01:00
|
|
|
|
jbe .end_dir
|
2010-02-08 21:43:55 +01:00
|
|
|
|
|
2010-02-09 15:17:26 +01:00
|
|
|
|
inc esi ;получаем новый блок
|
2010-02-08 21:43:55 +01:00
|
|
|
|
push ecx
|
|
|
|
|
mov ecx, esi
|
|
|
|
|
call ext2_get_inode_block
|
|
|
|
|
mov eax, ecx
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_block]
|
|
|
|
|
call ext2_get_block
|
|
|
|
|
pop ecx
|
|
|
|
|
mov eax, ebx
|
|
|
|
|
add ebx, [ext2_data.block_size]
|
|
|
|
|
mov [EXT2_end_block], ebx
|
2010-02-09 15:17:26 +01:00
|
|
|
|
ret ; опять в цикл
|
|
|
|
|
|
|
|
|
|
.wanted_end:
|
|
|
|
|
loop .find_wanted_cycle ; ecx = -1
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2010-02-08 21:43:55 +01:00
|
|
|
|
.find_wanted_end:
|
2010-01-23 16:24:03 +01:00
|
|
|
|
mov ecx, edi
|
|
|
|
|
.wanted_start: ; ищем first_wanted+count
|
2010-02-09 15:17:26 +01:00
|
|
|
|
jecxz .wanted_end
|
2010-01-23 16:24:03 +01:00
|
|
|
|
cmp [eax + EXT2_DIR_STRUC.inode], 0 ; if (inode = 0) => not used
|
|
|
|
|
jz .empty_rec
|
|
|
|
|
inc [EXT2_files_in_folder]
|
|
|
|
|
inc [EXT2_read_in_folder]
|
|
|
|
|
|
2010-02-01 19:47:19 +01:00
|
|
|
|
mov edi, edx
|
|
|
|
|
push eax ecx
|
|
|
|
|
xor eax, eax
|
|
|
|
|
mov ecx, 40 / 4
|
|
|
|
|
rep stosd
|
|
|
|
|
pop ecx eax
|
|
|
|
|
|
2010-02-09 15:17:26 +01:00
|
|
|
|
push eax esi edx ;получим inode
|
2010-01-23 16:24:03 +01:00
|
|
|
|
mov eax, [eax + EXT2_DIR_STRUC.inode]
|
|
|
|
|
mov ebx, [ext2_data.ext2_temp_inode]
|
|
|
|
|
call ext2_get_inode
|
2010-02-09 15:17:26 +01:00
|
|
|
|
|
|
|
|
|
lea edi, [edx + 8]
|
|
|
|
|
|
|
|
|
|
mov eax, [ebx + EXT2_INODE_STRUC.i_ctime] ; переведем время в ntfs формат
|
|
|
|
|
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 ; пока достаем только буфер
|
|
|
|
|
test [ebx + EXT2_INODE_STRUC.i_mode], EXT2_S_IFDIR ; для папки размер
|
|
|
|
|
jnz @F ; не возвращаем
|
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
mov eax, [ebx + EXT2_INODE_STRUC.i_size] ;low size
|
2010-02-09 15:17:26 +01:00
|
|
|
|
stosd
|
|
|
|
|
mov eax, [ebx + EXT2_INODE_STRUC.i_dir_acl] ;high size
|
|
|
|
|
stosd
|
|
|
|
|
xor dword [edx], FS_FT_DIR
|
|
|
|
|
@@:
|
2010-01-23 16:24:03 +01:00
|
|
|
|
xor dword [edx], FS_FT_DIR
|
2010-02-09 15:17:26 +01:00
|
|
|
|
pop esi eax
|
|
|
|
|
|
2010-02-01 19:47:19 +01:00
|
|
|
|
or dword [edx+4], FS_FT_ASCII ; symbol type in name
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2010-02-09 15:17:26 +01:00
|
|
|
|
;теперь скопируем имя, сконвертировав из UTF-8 в CP866
|
2010-02-08 20:51:43 +01:00
|
|
|
|
push eax ecx esi
|
2010-01-23 16:24:03 +01:00
|
|
|
|
movzx ecx, [eax + EXT2_DIR_STRUC.name_len]
|
2010-02-08 20:51:43 +01:00
|
|
|
|
lea edi, [edx + 40]
|
2010-01-23 16:24:03 +01:00
|
|
|
|
lea esi, [eax + EXT2_DIR_STRUC.name]
|
2010-02-08 20:51:43 +01:00
|
|
|
|
call utf8toansi_str
|
|
|
|
|
pop esi ecx eax
|
2010-01-23 16:24:03 +01:00
|
|
|
|
and byte [edi], 0
|
|
|
|
|
|
2010-02-09 15:17:26 +01:00
|
|
|
|
cmp byte [edx + 40], '.'
|
|
|
|
|
jne @F
|
|
|
|
|
or dword [edx], FS_FT_HIDDEN
|
|
|
|
|
@@:
|
2010-02-08 20:51:43 +01:00
|
|
|
|
|
2010-02-09 15:17:26 +01:00
|
|
|
|
add edx, 40 + 264 ; go to next record
|
2010-02-08 20:51:43 +01:00
|
|
|
|
dec ecx ; если запись пустая ecx не надо уменьшать
|
2010-01-23 16:24:03 +01:00
|
|
|
|
.empty_rec:
|
|
|
|
|
movzx ebx, [eax + EXT2_DIR_STRUC.rec_len]
|
2010-02-17 18:26:25 +01:00
|
|
|
|
cmp ebx, 12 ; минимальная длина записи
|
|
|
|
|
jb .end_error
|
|
|
|
|
test ebx, 0x3 ; длина записи должна делиться на 4
|
|
|
|
|
jnz .end_error
|
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
add eax, ebx
|
|
|
|
|
cmp eax, [EXT2_end_block]
|
2010-02-08 20:51:43 +01:00
|
|
|
|
jb .wanted_start
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2010-02-09 15:17:26 +01:00
|
|
|
|
push .wanted_start ; дошли до конца очередного блока
|
|
|
|
|
jmp .end_block
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
.end_dir:
|
2010-02-09 15:17:26 +01:00
|
|
|
|
pop eax ; мусор (адрес возврата в цикл)
|
2010-02-17 18:26:25 +01:00
|
|
|
|
.end_error:
|
2010-01-23 16:24:03 +01:00
|
|
|
|
pop edx
|
|
|
|
|
mov ebx, [EXT2_read_in_folder]
|
|
|
|
|
mov ecx, [EXT2_files_in_folder]
|
|
|
|
|
mov dword [edx], 1 ;version
|
|
|
|
|
xor eax, eax
|
|
|
|
|
mov [edx+4], ebx
|
|
|
|
|
mov [edx+8], ecx
|
|
|
|
|
lea edi, [edx + 12]
|
|
|
|
|
mov ecx, 20 / 4
|
|
|
|
|
rep stosd
|
|
|
|
|
ret
|
|
|
|
|
;====================== end ext2_HdReadFolder
|
2010-02-08 20:51:43 +01:00
|
|
|
|
utf8toansi_str:
|
|
|
|
|
; convert UTF-8 string to ASCII-string (codepage 866)
|
|
|
|
|
; in: ecx=length source, esi->source, edi->buffer
|
|
|
|
|
; destroys: eax,esi,edi
|
|
|
|
|
jecxz .ret
|
|
|
|
|
.start:
|
|
|
|
|
lodsw
|
|
|
|
|
cmp al, 0x80
|
|
|
|
|
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
|
|
|
|
|
jb .unk
|
|
|
|
|
cmp ax, 0xd180
|
|
|
|
|
jb .rus1
|
|
|
|
|
cmp ax, 0xd190
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
|
;
|
|
|
|
|
; 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
|
|
|
|
|
;
|
|
|
|
|
;--------------------------------------------------------------
|
|
|
|
|
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
|
|
|
|
@@:
|
|
|
|
|
push ecx ebx
|
|
|
|
|
call ext2_find_lfn
|
|
|
|
|
pop ebx ecx
|
|
|
|
|
jnc .doit
|
|
|
|
|
;.not_found:
|
|
|
|
|
or ebx, -1
|
|
|
|
|
mov eax, ERROR_FILE_NOT_FOUND
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
.doit:
|
|
|
|
|
test [ebp + EXT2_INODE_STRUC.i_mode], EXT2_S_IFREG
|
|
|
|
|
jz .this_is_nofile
|
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
;-----------------------------------------------------------------------------final step
|
2010-02-08 20:51:43 +01:00
|
|
|
|
mov edi, edx ; edi = pointer to return mem
|
|
|
|
|
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 - стартовый номер байта
|
|
|
|
|
|
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
|
|
|
|
|
.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
|
|
|
|
|
jae .size_great_great ; а если равно, то не важно куда
|
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
.size_great_less:
|
|
|
|
|
or [EXT2_files_in_folder], 1 ;читаем по границе размера
|
2010-02-08 20:51:43 +01:00
|
|
|
|
mov ecx, [ebp + EXT2_INODE_STRUC.i_size]
|
|
|
|
|
sub ecx, [esi] ;(размер - старт)
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jmp @F
|
|
|
|
|
|
|
|
|
|
.size_great_great:
|
2010-02-08 20:51:43 +01:00
|
|
|
|
and [EXT2_files_in_folder], 0 ;читаем столько сколько запросили
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
@@:
|
2010-02-08 20:51:43 +01:00
|
|
|
|
push ecx ;save for return
|
|
|
|
|
test esi, esi
|
|
|
|
|
jz .zero_start
|
2010-01-23 16:24:03 +01: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]
|
|
|
|
|
|
|
|
|
|
mov [EXT2_counter_blocks], eax ;номер блока запоминаем
|
|
|
|
|
|
|
|
|
|
push ecx
|
|
|
|
|
mov ecx, eax
|
|
|
|
|
call ext2_get_inode_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
|
|
|
|
|
pop ecx
|
|
|
|
|
add ebx, edx
|
|
|
|
|
|
|
|
|
|
neg edx
|
2010-02-08 20:51:43 +01: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
|
|
|
|
|
rep movsb ;кусок 1-го блока
|
2010-02-04 17:44:28 +01:00
|
|
|
|
jmp @F
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
|
|
|
|
.zero_start:
|
2010-02-04 17:44:28 +01:00
|
|
|
|
mov eax, ecx
|
2010-01-23 16:24:03 +01:00
|
|
|
|
;теперь в eax кол-во оставшихся байт для чтения
|
2010-02-04 17:44:28 +01:00
|
|
|
|
@@:
|
2010-02-08 20:51:43 +01:00
|
|
|
|
mov ebx, edi ;чтение блока прям в ->ebx
|
2010-01-23 16:24:03 +01:00
|
|
|
|
xor edx, edx
|
2010-02-04 17:44:28 +01: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
|
|
|
|
@@:
|
2010-02-08 20:51:43 +01:00
|
|
|
|
test edi, edi
|
2010-01-23 16:24:03 +01:00
|
|
|
|
jz .finish_block
|
|
|
|
|
inc [EXT2_counter_blocks]
|
|
|
|
|
mov ecx, [EXT2_counter_blocks]
|
|
|
|
|
call ext2_get_inode_block
|
|
|
|
|
|
2010-02-08 20:51:43 +01:00
|
|
|
|
mov eax, ecx ;а ebx уже забит нужным значением
|
2010-01-23 16:24:03 +01:00
|
|
|
|
call ext2_get_block
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
mov ecx, [EXT2_counter_blocks]
|
|
|
|
|
inc ecx
|
|
|
|
|
call ext2_get_inode_block
|
|
|
|
|
|
|
|
|
|
mov edi, ebx
|
|
|
|
|
mov eax, ecx
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_block]
|
|
|
|
|
call ext2_get_block
|
|
|
|
|
|
|
|
|
|
mov ecx, edx
|
|
|
|
|
|
|
|
|
|
.only_one_block:
|
|
|
|
|
mov esi, ebx
|
2010-02-04 17:44:28 +01:00
|
|
|
|
rep movsb ;кусок last блока
|
|
|
|
|
.end_read:
|
2010-01-23 16:24:03 +01:00
|
|
|
|
pop ebx
|
|
|
|
|
cmp [EXT2_files_in_folder], 0
|
|
|
|
|
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
|
|
|
|
|
;========================
|
2010-02-09 15:17:26 +01:00
|
|
|
|
;in : esi -> name not save: eax ebx ecx
|
2010-02-01 19:47:19 +01:00
|
|
|
|
;out: ebp -> inode cf=0
|
|
|
|
|
; ebp -> trash cf=1
|
|
|
|
|
ext2_find_lfn:
|
|
|
|
|
mov ebp, [ext2_data.root_inode]
|
|
|
|
|
.next_folder:
|
|
|
|
|
or [EXT2_counter_blocks], -1 ;счетчик блоков папки cur block of inode
|
|
|
|
|
mov eax, [ebp + EXT2_INODE_STRUC.i_blocks] ;убывающий счетчик блоков
|
|
|
|
|
add eax, [ext2_data.count_block_in_block]
|
|
|
|
|
mov [EXT2_end_block], eax
|
|
|
|
|
.next_block_folder:
|
|
|
|
|
mov eax, [ext2_data.count_block_in_block]
|
|
|
|
|
sub [EXT2_end_block], eax
|
|
|
|
|
jz .not_found
|
|
|
|
|
inc [EXT2_counter_blocks]
|
|
|
|
|
mov ecx, [EXT2_counter_blocks]
|
|
|
|
|
call ext2_get_inode_block
|
|
|
|
|
|
|
|
|
|
mov eax, ecx
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_block] ;ebx = cur dir record
|
|
|
|
|
call ext2_get_block
|
|
|
|
|
|
|
|
|
|
mov eax, esi
|
|
|
|
|
call ext2_test_block_by_name
|
|
|
|
|
cmp eax, esi ;нашли имя?
|
|
|
|
|
jz .next_block_folder
|
|
|
|
|
|
|
|
|
|
cmp byte [esi],0
|
|
|
|
|
jz .get_inode_ret
|
|
|
|
|
|
|
|
|
|
cmp [ebx + EXT2_DIR_STRUC.file_type], EXT2_FT_DIR
|
|
|
|
|
jne .not_found ;нашли, но это не папка
|
|
|
|
|
mov eax, [ebx + EXT2_DIR_STRUC.inode]
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_inode] ;все же папка.
|
|
|
|
|
call ext2_get_inode
|
|
|
|
|
mov ebp, ebx
|
|
|
|
|
jmp .next_folder
|
|
|
|
|
|
|
|
|
|
.not_found:
|
|
|
|
|
stc
|
|
|
|
|
ret
|
|
|
|
|
.get_inode_ret:
|
2010-02-09 15:17:26 +01:00
|
|
|
|
mov [EXT2_end_block], ebx ; сохраняем указатеть на dir_rec
|
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
|
|
|
|
|
clc
|
|
|
|
|
ret
|
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
|
2010-02-01 19:47:19 +01:00
|
|
|
|
;========================
|
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
ext2_HdGetFileInfo:
|
2010-02-01 19:47:19 +01:00
|
|
|
|
cmp byte [esi], 0
|
|
|
|
|
jz .doit
|
|
|
|
|
|
|
|
|
|
call ext2_find_lfn
|
|
|
|
|
jnc .doit2
|
|
|
|
|
;.not_found:
|
|
|
|
|
mov eax, ERROR_FILE_NOT_FOUND
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
.doit:
|
|
|
|
|
mov ebp, [ext2_data.root_inode]
|
2010-02-09 15:17:26 +01:00
|
|
|
|
mov ebx, .doit ;неважно что лишь бы этому адресу не '.'
|
|
|
|
|
jmp @F
|
2010-02-01 19:47:19 +01:00
|
|
|
|
.doit2:
|
2010-02-09 15:17:26 +01:00
|
|
|
|
mov ebx, [EXT2_end_block]
|
|
|
|
|
add ebx, EXT2_DIR_STRUC.name
|
|
|
|
|
@@:
|
2010-02-01 19:47:19 +01:00
|
|
|
|
xor eax, eax
|
|
|
|
|
mov edi, edx
|
|
|
|
|
mov ecx, 40/4
|
2010-02-09 15:17:26 +01:00
|
|
|
|
rep stosd ; fill zero
|
2010-02-01 19:47:19 +01:00
|
|
|
|
|
2010-02-09 15:17:26 +01:00
|
|
|
|
cmp byte [ebx], '.'
|
|
|
|
|
jnz @F
|
|
|
|
|
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
|
|
|
|
|
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]
|
|
|
|
|
mov eax, [ebx + EXT2_INODE_STRUC.i_ctime]
|
|
|
|
|
xor edx, edx
|
|
|
|
|
add eax, 3054539008
|
|
|
|
|
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
|
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
|
2010-02-17 18:26:25 +01:00
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
|
;
|
|
|
|
|
; ext2_HdCreateFolder - create new folder
|
|
|
|
|
;
|
|
|
|
|
; esi points to filename
|
|
|
|
|
;
|
|
|
|
|
; ret eax = 0 ok read or other = errormsg
|
|
|
|
|
;
|
|
|
|
|
;--------------------------------------------------------------
|
|
|
|
|
cmp byte [esi], 0
|
|
|
|
|
jz .not_found
|
|
|
|
|
cmp byte [esi], '/'
|
|
|
|
|
jz .not_found
|
|
|
|
|
|
|
|
|
|
mov ebx, esi ; save source pointer
|
|
|
|
|
xor edi, edi ; slah pointer
|
|
|
|
|
@@:
|
|
|
|
|
lodsb
|
|
|
|
|
cmp al, 0
|
|
|
|
|
jz .zero
|
|
|
|
|
cmp al, '/'
|
|
|
|
|
jz .slash
|
|
|
|
|
jmp @B
|
|
|
|
|
|
|
|
|
|
.slash:
|
|
|
|
|
lodsb
|
|
|
|
|
cmp al, 0
|
|
|
|
|
jz .zero ; уберем слеш из имени
|
|
|
|
|
cmp al, '/'
|
|
|
|
|
jz .not_found
|
|
|
|
|
mov edi, esi ; edi -> next symbol after '/'
|
|
|
|
|
dec edi
|
|
|
|
|
jmp @B
|
|
|
|
|
|
|
|
|
|
.zero:
|
|
|
|
|
dec esi
|
|
|
|
|
test edi, edi
|
|
|
|
|
jz .doit
|
|
|
|
|
|
|
|
|
|
;слеш был
|
|
|
|
|
mov eax, esi
|
|
|
|
|
sub eax, edi
|
|
|
|
|
mov [EXT2_name_len], eax
|
|
|
|
|
|
|
|
|
|
mov ecx, edi
|
|
|
|
|
sub ecx, ebx
|
|
|
|
|
dec ecx ;выкинули '/' из имени ролителя
|
|
|
|
|
mov esi, ebx
|
|
|
|
|
mov edi, EXT2_parent_name
|
|
|
|
|
rep movsb
|
|
|
|
|
; esi - pointer to last slash
|
|
|
|
|
|
|
|
|
|
mov edx, esi
|
|
|
|
|
mov esi, EXT2_parent_name
|
|
|
|
|
call ext2_find_lfn
|
|
|
|
|
jnc .doit2
|
|
|
|
|
.not_found:
|
|
|
|
|
or ebx, -1
|
|
|
|
|
mov eax, ERROR_FILE_NOT_FOUND
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
.doit:
|
|
|
|
|
mov ebp, [ext2_data.root_inode]
|
|
|
|
|
mov edx, ebx ; имя создаваемой папки
|
|
|
|
|
sub esi, ebx
|
|
|
|
|
mov [EXT2_name_len], esi
|
|
|
|
|
.doit2:
|
|
|
|
|
;ebp -> parent_inode ebx->name_new_folder [EXT2_name_len]=length of name
|
|
|
|
|
; стратегия выбора группы для нового inode: (так делает линукс)
|
|
|
|
|
; 1) Ищем группу в которой меньше всего папок и в есть свободное место
|
|
|
|
|
; 2) Если такая группа не нашлась, то берем группу в которой больше свободного места
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
call ext2_balloc
|
|
|
|
|
jmp ext2_HdDelete
|
|
|
|
|
|
|
|
|
|
push ebx
|
|
|
|
|
push ebp
|
|
|
|
|
|
|
|
|
|
mov ecx, [ext2_data.sb]
|
|
|
|
|
cmp [ecx + EXT2_SB_STRUC.free_inodes_count],0 ; есть ли место для inode
|
|
|
|
|
jz .no_space
|
|
|
|
|
mov eax, [ecx + EXT2_SB_STRUC.free_block_count]
|
|
|
|
|
sub eax, [ecx + EXT2_SB_STRUC.r_block_count]
|
|
|
|
|
cmp eax, 2 ; и как минимум на 2 блока
|
|
|
|
|
jb .no_space
|
|
|
|
|
|
|
|
|
|
mov ecx, [ext2_data.groups_count]
|
|
|
|
|
mov esi, [ext2_data.global_desc_table]
|
|
|
|
|
mov edi, -1 ;указатель на лучшую группу
|
|
|
|
|
mov edx, 0
|
|
|
|
|
.find_group_dir:
|
|
|
|
|
jecxz .end_find_group_dir
|
|
|
|
|
movzx eax, [esi + EXT2_BLOCK_GROUP_DESC.free_inodes_count]
|
|
|
|
|
cmp eax, edx
|
|
|
|
|
jbe @F
|
|
|
|
|
cmp [esi + EXT2_BLOCK_GROUP_DESC.free_blocks_count], 0
|
|
|
|
|
jz @F
|
|
|
|
|
mov edi, esi
|
|
|
|
|
movzx edx, [esi + EXT2_BLOCK_GROUP_DESC.free_inodes_count]
|
|
|
|
|
@@:
|
|
|
|
|
dec ecx
|
|
|
|
|
add esi, 32 ;размер структуры
|
|
|
|
|
jmp .find_group_dir
|
|
|
|
|
.end_find_group_dir:
|
|
|
|
|
cmp edx, 0
|
|
|
|
|
jz .no_space
|
|
|
|
|
|
|
|
|
|
;нашли группу, получим битовую карту inode-ов (найдем locale number)
|
|
|
|
|
mov eax, [edi + EXT2_BLOCK_GROUP_DESC.inode_bitmap]
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_block]
|
|
|
|
|
call ext2_get_block
|
|
|
|
|
|
|
|
|
|
;теперь цикл по всем битам
|
|
|
|
|
mov esi, ebx
|
|
|
|
|
mov ecx, [ext2_data.inodes_per_group]
|
|
|
|
|
shr ecx, 5 ;делим на 32
|
|
|
|
|
mov ebp, ecx ; всего сохраним в ebp
|
|
|
|
|
or eax, -1 ; ищем первый свободный inode (!= -1)
|
|
|
|
|
repne scasd
|
|
|
|
|
jnz .test_last_dword ;нашли или нет
|
|
|
|
|
mov eax, [esi-4]
|
|
|
|
|
|
|
|
|
|
sub ebp, ecx
|
|
|
|
|
dec ebp
|
|
|
|
|
shl ebp, 5 ; глобальный номер локального номера
|
|
|
|
|
|
|
|
|
|
mov ecx, 32
|
|
|
|
|
@@:
|
|
|
|
|
test eax, 1
|
|
|
|
|
jz @F
|
|
|
|
|
shr eax, 1
|
|
|
|
|
loop @B
|
|
|
|
|
@@:
|
|
|
|
|
mov eax, 32
|
|
|
|
|
sub eax, ecx
|
|
|
|
|
|
|
|
|
|
add ebp, eax ; locale num of inode
|
|
|
|
|
|
|
|
|
|
mov eax, [esi-4]
|
|
|
|
|
;устанавливаем в eax крайний справа нулевой бит в 1
|
|
|
|
|
mov ecx, eax
|
|
|
|
|
inc ecx
|
|
|
|
|
or eax, ecx ; x | (x+1)
|
|
|
|
|
mov [esi-4], eax
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_block]
|
|
|
|
|
mov eax, [edi + EXT2_BLOCK_GROUP_DESC.inode_bitmap]
|
|
|
|
|
call ext2_set_block
|
|
|
|
|
;считаем таблицу inode
|
|
|
|
|
sub edi, [ext2_data.global_desc_table]
|
|
|
|
|
shr edi, 5
|
|
|
|
|
|
|
|
|
|
mov eax, edi
|
|
|
|
|
mul [ext2_data.inodes_per_group]
|
|
|
|
|
add eax, ebp
|
|
|
|
|
inc eax ; теперь в eax (ebp) номер inode-а
|
|
|
|
|
mov ebp, eax
|
|
|
|
|
;call ext2_get_inode_address
|
|
|
|
|
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_block]
|
|
|
|
|
call hd_read
|
|
|
|
|
add edx, ebx ; в edx адрес нужного inode
|
|
|
|
|
|
|
|
|
|
;забьем 0 для начала
|
|
|
|
|
mov edi, edx
|
|
|
|
|
mov ecx, [ext2_data.inode_size]
|
|
|
|
|
shr ecx, 2
|
|
|
|
|
xor eax, eax
|
|
|
|
|
rep stosd
|
|
|
|
|
|
|
|
|
|
mov edi, edx
|
|
|
|
|
mov eax, EXT2_S_IFDIR or EXT2_777_MODE
|
|
|
|
|
stosd ; i_mode
|
|
|
|
|
xor eax, eax
|
|
|
|
|
stosd ; i_uid
|
|
|
|
|
mov eax, [ext2_data.block_size]
|
|
|
|
|
stosd ; i_size
|
|
|
|
|
xor eax, eax
|
|
|
|
|
stosd ; i_atime
|
|
|
|
|
stosd ; i_ctime
|
|
|
|
|
stosd ; i_mtime
|
|
|
|
|
stosd ; i_dtime
|
|
|
|
|
stosd ; i_gid
|
|
|
|
|
inc eax
|
|
|
|
|
stosd ; i_links_count
|
|
|
|
|
mov eax, [ext2_data.count_block_in_block]
|
|
|
|
|
stosd ; i_blocks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.test_last_dword:
|
|
|
|
|
|
2010-01-23 16:24:03 +01:00
|
|
|
|
xor ebx, ebx
|
|
|
|
|
mov eax, ERROR_UNSUPPORTED_FS
|
|
|
|
|
ret
|
|
|
|
|
|
2010-02-17 18:26:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.no_space:
|
|
|
|
|
or ebx, -1
|
|
|
|
|
mov eax, ERROR_DISK_FULL
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;выделяет новый блок, если это можно
|
|
|
|
|
;иначе возвращает eax=0
|
|
|
|
|
ext2_balloc:
|
|
|
|
|
mov ecx, [ext2_data.sb]
|
|
|
|
|
mov eax, [ecx + EXT2_SB_STRUC.free_block_count]
|
|
|
|
|
sub eax, [ecx + EXT2_SB_STRUC.r_block_count]
|
|
|
|
|
jbe .no_space
|
|
|
|
|
|
|
|
|
|
mov ecx, [ext2_data.groups_count]
|
|
|
|
|
mov edi, [ext2_data.global_desc_table]
|
|
|
|
|
;mov esi, -1 ;указатель на лучшую группу
|
|
|
|
|
mov edx, 0
|
|
|
|
|
.find_group:
|
|
|
|
|
jecxz .end_find_group
|
|
|
|
|
movzx eax, [edi + EXT2_BLOCK_GROUP_DESC.free_blocks_count]
|
|
|
|
|
cmp eax, edx
|
|
|
|
|
jbe @F
|
|
|
|
|
mov esi, edi
|
|
|
|
|
mov edx, eax
|
|
|
|
|
@@:
|
|
|
|
|
dec ecx
|
|
|
|
|
add edi, 32 ;размер структуры
|
|
|
|
|
jmp .find_group
|
|
|
|
|
.end_find_group:
|
|
|
|
|
cmp edx, 0
|
|
|
|
|
jz .no_space
|
|
|
|
|
|
|
|
|
|
;нашли группу, получим битовую карту block-ов
|
|
|
|
|
mov eax, [esi + EXT2_BLOCK_GROUP_DESC.block_bitmap]
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_block]
|
|
|
|
|
call ext2_get_block
|
|
|
|
|
|
|
|
|
|
;теперь цикл по всем битам
|
|
|
|
|
mov edi, ebx
|
|
|
|
|
mov ecx, [ext2_data.blocks_per_group]
|
|
|
|
|
shr ecx, 5 ;делим на 32
|
|
|
|
|
mov ebp, ecx ;всего сохраним в ebp
|
|
|
|
|
or eax, -1 ;ищем первый свободный inode (!= -1)
|
|
|
|
|
repe scasd
|
|
|
|
|
jz .test_last_dword ;нашли или нет
|
|
|
|
|
|
|
|
|
|
mov eax, [edi-4]
|
|
|
|
|
sub ebp, ecx
|
|
|
|
|
dec ebp
|
|
|
|
|
shl ebp, 5 ; ebp = 32*(номер div 32). Теперь найдем (номер mod 32)
|
|
|
|
|
|
|
|
|
|
mov ecx, 32
|
|
|
|
|
@@:
|
|
|
|
|
test eax, 1
|
|
|
|
|
jz @F
|
|
|
|
|
shr eax, 1
|
|
|
|
|
loop @B
|
|
|
|
|
@@:
|
|
|
|
|
mov eax, 32
|
|
|
|
|
sub eax, ecx
|
|
|
|
|
|
|
|
|
|
add ebp, eax ; ebp = номер блока в группе
|
|
|
|
|
|
|
|
|
|
mov eax, [edi-4]
|
|
|
|
|
mov ecx, eax
|
|
|
|
|
inc ecx
|
|
|
|
|
or eax, ecx ; x | (x+1) - устанавливает в 1 крайний справа нулевой бит (block used)
|
|
|
|
|
mov [edi-4], eax
|
|
|
|
|
|
|
|
|
|
mov ebx, [ext2_data.ext2_save_block]
|
|
|
|
|
mov eax, [esi + EXT2_BLOCK_GROUP_DESC.inode_bitmap]
|
|
|
|
|
; call ext2_set_block ; и пишем на hdd новую битовую маску
|
|
|
|
|
|
|
|
|
|
;============== тут получаем номер блока
|
|
|
|
|
mov eax, [ext2_data.blocks_per_group]
|
|
|
|
|
sub esi, [ext2_data.global_desc_table]
|
|
|
|
|
shr esi, 5 ;esi - номер группы
|
|
|
|
|
mul esi
|
|
|
|
|
add ebp, eax ;(номер_группы) * (blocks_per_group) + локальный номер в группе
|
|
|
|
|
mov eax, [ext2_data.sb]
|
|
|
|
|
add ebp, [eax + EXT2_SB_STRUC.first_data_block]
|
|
|
|
|
|
|
|
|
|
;теперь поправим глобальную дескрипторную таблицу и суперблок
|
|
|
|
|
mov ebx, [ext2_data.sb]
|
|
|
|
|
dec [ebx + EXT2_SB_STRUC.free_block_count]
|
|
|
|
|
mov eax, 2
|
|
|
|
|
add eax, [PARTITION_START]
|
|
|
|
|
call hd_write
|
|
|
|
|
mov eax, [ebx + EXT2_SB_STRUC.first_data_block]
|
|
|
|
|
inc eax
|
|
|
|
|
dec [esi + EXT2_BLOCK_GROUP_DESC.free_blocks_count];edi все еще указывает на группу в которой мы выделил блок
|
|
|
|
|
call ext2_set_block
|
|
|
|
|
|
|
|
|
|
mov eax, ebx
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
.test_last_dword:
|
|
|
|
|
lodsd
|
|
|
|
|
mov ecx, [ext2_data.blocks_per_group]
|
|
|
|
|
and ecx, not (32-1) ;обнуляем все кроме последних 5 бит
|
|
|
|
|
mov edx, ecx
|
|
|
|
|
mov ebx, 1
|
|
|
|
|
@@:
|
|
|
|
|
jecxz .no_space
|
|
|
|
|
mov edx, ebx
|
|
|
|
|
or edx, eax ; тестируем очередной бит
|
|
|
|
|
shl ebx, 1
|
|
|
|
|
jmp @B
|
|
|
|
|
@@:
|
|
|
|
|
sub edx, ecx
|
|
|
|
|
dec edx ;номер в последнем блоке
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.no_space:
|
|
|
|
|
xor eax, eax
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;in: eax = i_block
|
|
|
|
|
; ebx = pointer to memory
|
|
|
|
|
ext2_set_block:
|
|
|
|
|
push eax ebx ecx
|
|
|
|
|
mov ecx, [ext2_data.log_block_size]
|
|
|
|
|
shl eax, cl
|
|
|
|
|
add eax, [PARTITION_START]
|
|
|
|
|
mov ecx, [ext2_data.count_block_in_block]
|
|
|
|
|
@@:
|
|
|
|
|
call hd_write
|
|
|
|
|
inc eax
|
|
|
|
|
add ebx, 512
|
|
|
|
|
loop @B
|
|
|
|
|
pop ecx ebx eax
|
|
|
|
|
ret
|
|
|
|
|
|