2016-07-13 03:01:16 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2024-05-22 17:15:14 +02:00
|
|
|
;; Copyright (C) KolibriOS team 2013-2024. All rights reserved. ;;
|
2016-07-13 03:01:16 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License. ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
|
|
; EXT external functions
|
|
|
|
; in:
|
|
|
|
; ebx -> parameter structure of sysfunc 70
|
|
|
|
; ebp -> EXTFS structure
|
2016-08-15 18:55:03 +02:00
|
|
|
; esi -> path string in UTF-8
|
2016-07-13 03:01:16 +02:00
|
|
|
; out:
|
|
|
|
; eax, ebx = return values for sysfunc 70
|
|
|
|
iglobal
|
|
|
|
align 4
|
|
|
|
ext_user_functions:
|
|
|
|
dd ext_free
|
2024-05-09 16:22:13 +02:00
|
|
|
dd (ext_user_functions_end - ext_user_functions - 8) / 4
|
2016-07-13 03:01:16 +02:00
|
|
|
dd ext_ReadFile
|
|
|
|
dd ext_ReadFolder
|
|
|
|
dd ext_CreateFile
|
|
|
|
dd ext_WriteFile
|
|
|
|
dd ext_SetFileEnd
|
|
|
|
dd ext_GetFileInfo
|
|
|
|
dd ext_SetFileInfo
|
|
|
|
dd 0
|
|
|
|
dd ext_Delete
|
|
|
|
dd ext_CreateFolder
|
2017-07-09 10:28:00 +02:00
|
|
|
dd ext_Rename
|
2016-07-13 03:01:16 +02:00
|
|
|
ext_user_functions_end:
|
|
|
|
endg
|
|
|
|
|
|
|
|
struct DIRENTRY
|
|
|
|
inodeNumber dd ?
|
|
|
|
entryLength dw ?
|
|
|
|
nameLength db ?
|
|
|
|
fileType db ?
|
|
|
|
name db ? ; rb [nameLength]
|
|
|
|
ends
|
|
|
|
|
|
|
|
struct INODE
|
|
|
|
accessMode dw ?
|
|
|
|
UID dw ?
|
|
|
|
fileSize dd ?
|
|
|
|
accessedTime dd ?
|
|
|
|
inodeModified dd ?
|
|
|
|
dataModified dd ?
|
|
|
|
deletedTime dd ?
|
|
|
|
GID dw ?
|
|
|
|
linksCount dw ?
|
|
|
|
sectorsUsed dd ?
|
|
|
|
featureFlags dd ?
|
|
|
|
reserved dd ?
|
|
|
|
blockNumbers rd 12
|
|
|
|
addressBlock dd ?
|
|
|
|
doubleAddress dd ?
|
|
|
|
tripleAddress dd ?
|
|
|
|
generation dd ?
|
|
|
|
ACL dd ?
|
|
|
|
fileSizeHigh dd ?
|
|
|
|
ends
|
|
|
|
|
|
|
|
struct BGDESCR ; block group descriptor
|
|
|
|
blockBitmap dd ?
|
|
|
|
inodeBitmap dd ?
|
|
|
|
inodeTable dd ?
|
|
|
|
blocksFree dw ?
|
|
|
|
inodesFree dw ?
|
|
|
|
directoriesCount dw ?
|
|
|
|
reserved rb 14
|
|
|
|
ends
|
|
|
|
|
|
|
|
struct SUPERBLOCK
|
|
|
|
inodesTotal dd ?
|
|
|
|
blocksTotal dd ?
|
|
|
|
blocksReserved dd ?
|
|
|
|
blocksFree dd ?
|
|
|
|
inodesFree dd ?
|
|
|
|
firstGroupBlock dd ?
|
|
|
|
sectorsPerBlockLog dd ? ; shift for 1024
|
|
|
|
fragmentSizeLog dd ?
|
|
|
|
blocksPerGroup dd ?
|
|
|
|
fragmentsPerGroup dd ?
|
|
|
|
inodesPerGroup dd ?
|
|
|
|
lastMountTime dd ?
|
|
|
|
lastWriteTime dd ?
|
|
|
|
mountCount dw ?
|
|
|
|
mountMax dw ?
|
|
|
|
magic dw ?
|
|
|
|
state dw ?
|
|
|
|
errorHandling dw ?
|
|
|
|
additionalVersion dw ?
|
|
|
|
lastCheck dd ?
|
|
|
|
checkInterval dd ?
|
|
|
|
creatorOS dd ?
|
|
|
|
dynamicVersionFlag dd ?
|
|
|
|
reservedUID dw ?
|
|
|
|
reservedGID dw ?
|
|
|
|
firstInode dd ?
|
|
|
|
inodeSize dw ?
|
|
|
|
thisBlockGroup dw ?
|
|
|
|
compatibleFlags dd ?
|
|
|
|
incompatibleFlags dd ?
|
|
|
|
RO_compatibleFlags dd ?
|
2017-03-01 17:45:33 +01:00
|
|
|
UUID rb 16
|
|
|
|
volumeLabel rb 16
|
2016-07-13 03:01:16 +02:00
|
|
|
ends
|
|
|
|
|
|
|
|
; ext4 extent tree
|
|
|
|
struct NODEHEADER ; tree node header
|
|
|
|
magic dw ? ; 0xF30A
|
|
|
|
entriesFolow dw ?
|
|
|
|
entriesMax dw ?
|
|
|
|
currentDepth dw ?
|
|
|
|
generation dd ?
|
|
|
|
ends
|
|
|
|
|
|
|
|
struct INDEX ; root/branch
|
|
|
|
fileBlock dd ?
|
|
|
|
nodeBlock dd ?
|
|
|
|
nodeBlockHigh dw ?
|
|
|
|
reserved dw ?
|
|
|
|
ends
|
|
|
|
|
|
|
|
struct EXTENT ; leaf
|
|
|
|
fileBlock dd ?
|
|
|
|
blocksCount dw ?
|
|
|
|
fsBlockHigh dw ?
|
|
|
|
fsBlock dd ?
|
|
|
|
ends
|
|
|
|
|
|
|
|
ROOT_INODE = 2
|
|
|
|
EXTENTS_USED = 80000h
|
|
|
|
TYPE_MASK = 0F000h
|
|
|
|
FLAG_FILE = 8000h
|
|
|
|
DIRECTORY = 4000h
|
|
|
|
DIR_FLAG_FILE = 1
|
|
|
|
DIR_DIRECTORY = 2
|
|
|
|
KOS_HIDDEN = 2
|
|
|
|
KOS_DIRECTORY = 10h
|
|
|
|
READ_ONLY = 1
|
|
|
|
|
|
|
|
; Implemented "incompatible" features:
|
|
|
|
; 2 = have file type in directory entry
|
|
|
|
; 40h = extents
|
|
|
|
; 200h = flexible block groups
|
|
|
|
INCOMPATIBLE_SUPPORT = 242h
|
|
|
|
; Read only support for "incompatible" features:
|
|
|
|
INCOMPATIBLE_READ_SUPPORT = 240h
|
|
|
|
|
|
|
|
; Implemented "read-only" features:
|
|
|
|
; 1 = sparse superblock
|
|
|
|
; 2 = 64-bit file size
|
|
|
|
READ_ONLY_SUPPORT = 3
|
|
|
|
|
|
|
|
struct EXTFS PARTITION
|
|
|
|
Lock MUTEX
|
|
|
|
mountType dd ?
|
|
|
|
bytesPerBlock dd ?
|
|
|
|
sectorsPerBlock dd ?
|
|
|
|
dwordsPerBlock dd ?
|
|
|
|
dwordsPerBranch dd ? ; dwordsPerBlock ^ 2
|
|
|
|
mainBlockBuffer dd ?
|
|
|
|
tempBlockBuffer dd ?
|
2017-01-28 03:39:27 +01:00
|
|
|
descriptorTable dd ?
|
|
|
|
descriptorTableEnd dd ?
|
2016-10-01 22:34:06 +02:00
|
|
|
align0 rb 200h-EXTFS.align0
|
2016-07-13 03:01:16 +02:00
|
|
|
superblock SUPERBLOCK
|
2016-10-01 22:34:06 +02:00
|
|
|
align1 rb 400h-EXTFS.align1
|
2016-07-13 03:01:16 +02:00
|
|
|
rootInodeBuffer INODE
|
2016-10-01 22:34:06 +02:00
|
|
|
align2 rb 600h-EXTFS.align2
|
|
|
|
inodeBuffer INODE
|
|
|
|
align3 rb 800h-EXTFS.align3
|
2016-07-13 03:01:16 +02:00
|
|
|
ends
|
|
|
|
|
|
|
|
; mount if it's a valid EXT partition
|
|
|
|
ext2_create_partition:
|
|
|
|
; in:
|
|
|
|
; ebp -> PARTITION structure
|
|
|
|
; ebx -> boot sector
|
|
|
|
; ebx+512 -> buffer
|
|
|
|
; out:
|
|
|
|
; eax -> EXTFS structure, 0 = not EXT
|
|
|
|
push ebx
|
|
|
|
cmp dword [esi+DISK.MediaInfo.SectorSize], 512
|
|
|
|
jnz .fail
|
|
|
|
mov eax, 2
|
|
|
|
add ebx, 512
|
|
|
|
call fs_read32_sys
|
|
|
|
test eax, eax
|
|
|
|
jnz .fail
|
|
|
|
cmp [ebx+SUPERBLOCK.magic], 0xEF53
|
|
|
|
jne .fail
|
|
|
|
cmp [ebx+SUPERBLOCK.state], 1
|
2016-08-15 18:55:03 +02:00
|
|
|
ja .fail
|
2016-07-13 03:01:16 +02:00
|
|
|
test [ebx+SUPERBLOCK.incompatibleFlags], not INCOMPATIBLE_SUPPORT
|
|
|
|
jnz .fail
|
|
|
|
cmp [ebx+SUPERBLOCK.sectorsPerBlockLog], 6 ; 64KB
|
|
|
|
ja .fail
|
2017-02-02 06:47:15 +01:00
|
|
|
cmp [ebx+SUPERBLOCK.inodeSize], 512
|
2016-07-13 03:01:16 +02:00
|
|
|
ja .fail
|
|
|
|
cmp [ebx+SUPERBLOCK.blocksPerGroup], 0
|
|
|
|
je .fail
|
|
|
|
cmp [ebx+SUPERBLOCK.inodesPerGroup], 0
|
|
|
|
je .fail
|
2016-10-01 22:34:06 +02:00
|
|
|
movi eax, sizeof.EXTFS
|
|
|
|
call malloc
|
2016-07-13 03:01:16 +02:00
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
|
|
|
mov ecx, dword [ebp+PARTITION.FirstSector]
|
|
|
|
mov dword [eax+EXTFS.FirstSector], ecx
|
|
|
|
mov ecx, dword [ebp+PARTITION.FirstSector+4]
|
|
|
|
mov dword [eax+EXTFS.FirstSector+4], ecx
|
|
|
|
mov ecx, dword [ebp+PARTITION.Length]
|
|
|
|
mov dword [eax+EXTFS.Length], ecx
|
|
|
|
mov ecx, dword [ebp+PARTITION.Length+4]
|
|
|
|
mov dword [eax+EXTFS.Length+4], ecx
|
|
|
|
mov ecx, [ebp+PARTITION.Disk]
|
|
|
|
mov [eax+EXTFS.Disk], ecx
|
|
|
|
mov [eax+EXTFS.FSUserFunctions], ext_user_functions
|
|
|
|
|
|
|
|
push ebp esi edi
|
|
|
|
mov ebp, eax
|
|
|
|
lea ecx, [eax+EXTFS.Lock]
|
|
|
|
call mutex_init
|
|
|
|
mov esi, ebx
|
|
|
|
lea edi, [ebp+EXTFS.superblock]
|
|
|
|
mov ecx, 512/4
|
|
|
|
rep movsd ; copy superblock
|
|
|
|
mov ecx, [ebx+SUPERBLOCK.sectorsPerBlockLog]
|
|
|
|
inc ecx
|
|
|
|
mov eax, 1
|
|
|
|
shl eax, cl
|
|
|
|
mov [ebp+EXTFS.sectorsPerBlock], eax
|
|
|
|
shl eax, 9
|
|
|
|
mov [ebp+EXTFS.bytesPerBlock], eax
|
|
|
|
shl eax, 1
|
|
|
|
push eax
|
|
|
|
shr eax, 3
|
|
|
|
mov [ebp+EXTFS.dwordsPerBlock], eax
|
|
|
|
mul eax
|
|
|
|
mov [ebp+EXTFS.dwordsPerBranch], eax
|
|
|
|
call kernel_alloc
|
|
|
|
test eax, eax
|
|
|
|
jz .error
|
|
|
|
mov [ebp+EXTFS.mainBlockBuffer], eax
|
|
|
|
add eax, [ebp+EXTFS.bytesPerBlock]
|
|
|
|
mov [ebp+EXTFS.tempBlockBuffer], eax
|
|
|
|
mov [ebp+EXTFS.mountType], 0
|
|
|
|
test [ebx+SUPERBLOCK.RO_compatibleFlags], not READ_ONLY_SUPPORT
|
|
|
|
jnz .read_only
|
|
|
|
test [ebx+SUPERBLOCK.incompatibleFlags], INCOMPATIBLE_READ_SUPPORT
|
|
|
|
jz @f
|
|
|
|
.read_only:
|
|
|
|
or [ebp+EXTFS.mountType], READ_ONLY
|
2017-01-28 03:39:27 +01:00
|
|
|
@@:
|
|
|
|
mov eax, [ebx+SUPERBLOCK.inodesTotal]
|
|
|
|
dec eax
|
|
|
|
xor edx, edx
|
|
|
|
div [ebx+SUPERBLOCK.inodesPerGroup]
|
|
|
|
inc eax
|
|
|
|
shl eax, 5
|
|
|
|
push eax eax
|
|
|
|
call kernel_alloc
|
|
|
|
pop ecx
|
|
|
|
test eax, eax
|
|
|
|
jz .error2
|
|
|
|
mov [ebp+EXTFS.descriptorTable], eax
|
|
|
|
mov ebx, eax
|
|
|
|
add eax, ecx
|
|
|
|
mov [ebp+EXTFS.descriptorTableEnd], eax
|
|
|
|
mov eax, [ebp+EXTFS.superblock.firstGroupBlock]
|
|
|
|
inc eax
|
|
|
|
mul [ebp+EXTFS.sectorsPerBlock]
|
|
|
|
dec ecx
|
|
|
|
shr ecx, 9
|
|
|
|
inc ecx
|
|
|
|
call fs_read64_sys
|
|
|
|
test eax, eax
|
|
|
|
jnz @f
|
|
|
|
mov al, ROOT_INODE
|
2016-07-13 03:01:16 +02:00
|
|
|
lea ebx, [ebp+EXTFS.rootInodeBuffer]
|
|
|
|
call readInode
|
|
|
|
test eax, eax
|
|
|
|
jnz @f
|
|
|
|
mov eax, ebp
|
|
|
|
pop edi esi ebp ebx
|
|
|
|
ret
|
|
|
|
|
|
|
|
@@:
|
2017-01-28 03:39:27 +01:00
|
|
|
stdcall kernel_free, [ebp+EXTFS.descriptorTable]
|
|
|
|
.error2:
|
2016-07-13 03:01:16 +02:00
|
|
|
stdcall kernel_free, [ebp+EXTFS.mainBlockBuffer]
|
|
|
|
.error:
|
2016-10-01 22:34:06 +02:00
|
|
|
mov eax, ebp
|
|
|
|
call free
|
2016-07-13 03:01:16 +02:00
|
|
|
pop edi esi ebp
|
|
|
|
.fail:
|
|
|
|
pop ebx
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
; unmount EXT partition
|
|
|
|
ext_free:
|
|
|
|
; in: eax -> EXTFS structure
|
2017-01-28 03:39:27 +01:00
|
|
|
push eax [eax+EXTFS.mainBlockBuffer]
|
|
|
|
stdcall kernel_free, [eax+EXTFS.descriptorTable]
|
|
|
|
call kernel_free
|
2016-10-01 22:34:06 +02:00
|
|
|
pop eax
|
|
|
|
jmp free
|
2016-07-13 03:01:16 +02:00
|
|
|
|
|
|
|
extfsWriteBlock:
|
|
|
|
push fs_write64_sys
|
|
|
|
jmp @f
|
2016-10-07 14:10:45 +02:00
|
|
|
; in: eax = block number, ebx -> buffer
|
2016-07-13 03:01:16 +02:00
|
|
|
extfsReadBlock:
|
|
|
|
push fs_read64_sys
|
|
|
|
@@:
|
|
|
|
push ecx edx
|
|
|
|
mov ecx, [ebp+EXTFS.sectorsPerBlock]
|
|
|
|
mul ecx
|
|
|
|
call dword[esp+8]
|
|
|
|
pop edx ecx
|
|
|
|
add esp, 4
|
|
|
|
test eax, eax
|
|
|
|
jz @f
|
|
|
|
movi eax, ERROR_DEVICE
|
|
|
|
stc
|
|
|
|
@@:
|
|
|
|
ret
|
|
|
|
|
|
|
|
extfsWriteDescriptor:
|
2017-01-28 03:39:27 +01:00
|
|
|
; in: ebx = block group descriptor
|
|
|
|
mov eax, [ebp+EXTFS.superblock.firstGroupBlock]
|
|
|
|
inc eax
|
|
|
|
mul [ebp+EXTFS.sectorsPerBlock]
|
|
|
|
sub ebx, [ebp+EXTFS.descriptorTable]
|
|
|
|
shr ebx, 9
|
|
|
|
add eax, ebx
|
|
|
|
shl ebx, 9
|
|
|
|
add ebx, [ebp+EXTFS.descriptorTable]
|
2016-11-24 18:29:52 +01:00
|
|
|
call fs_write32_sys
|
2016-07-13 03:01:16 +02:00
|
|
|
ret
|
|
|
|
|
2016-11-24 18:29:52 +01:00
|
|
|
extfsExtentFree:
|
|
|
|
; in: eax = first block number, ecx = extent size
|
|
|
|
push ebx edx edi
|
2016-07-13 03:01:16 +02:00
|
|
|
sub eax, [ebp+EXTFS.superblock.firstGroupBlock]
|
|
|
|
xor edx, edx
|
2016-11-24 18:29:52 +01:00
|
|
|
mov ebx, [ebp+EXTFS.superblock.blocksPerGroup]
|
|
|
|
div ebx
|
|
|
|
sub ebx, edx
|
|
|
|
sub ebx, ecx
|
|
|
|
jc .ret
|
2017-01-28 03:39:27 +01:00
|
|
|
push edx
|
|
|
|
mov ebx, [ebp+EXTFS.descriptorTable]
|
|
|
|
shl eax, 5
|
|
|
|
add ebx, eax
|
|
|
|
mov eax, ecx
|
|
|
|
mul [ebp+EXTFS.sectorsPerBlock]
|
2016-11-24 18:29:52 +01:00
|
|
|
add [ebx+BGDESCR.blocksFree], cx
|
2017-01-28 03:39:27 +01:00
|
|
|
add [ebp+EXTFS.superblock.blocksFree], ecx
|
|
|
|
sub [ebp+EXTFS.inodeBuffer.sectorsUsed], eax
|
|
|
|
push [ebx+BGDESCR.blockBitmap]
|
2016-10-07 14:10:45 +02:00
|
|
|
call extfsWriteDescriptor
|
2017-01-28 03:39:27 +01:00
|
|
|
pop eax
|
2016-10-07 14:10:45 +02:00
|
|
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
2017-01-28 03:39:27 +01:00
|
|
|
mov edx, eax
|
2016-07-13 03:01:16 +02:00
|
|
|
call extfsReadBlock
|
|
|
|
pop eax
|
2017-01-28 03:39:27 +01:00
|
|
|
jc .ret
|
|
|
|
push ebx edx
|
2016-11-24 18:29:52 +01:00
|
|
|
mov edi, eax
|
|
|
|
shr edi, 5
|
|
|
|
shl edi, 2
|
|
|
|
add edi, ebx
|
|
|
|
mov edx, ecx
|
2016-11-30 18:27:25 +01:00
|
|
|
and eax, 31
|
|
|
|
jz .aligned
|
2016-11-24 18:29:52 +01:00
|
|
|
mov ecx, 32
|
|
|
|
sub ecx, eax
|
|
|
|
sub edx, ecx
|
|
|
|
jnc @f
|
|
|
|
add ecx, edx
|
|
|
|
xor edx, edx
|
|
|
|
@@:
|
|
|
|
or ebx, -1
|
|
|
|
shl ebx, cl
|
|
|
|
not ebx
|
|
|
|
mov ecx, eax
|
|
|
|
shl ebx, cl
|
|
|
|
not ebx
|
|
|
|
and [edi], ebx
|
|
|
|
add edi, 4
|
|
|
|
xor eax, eax
|
2016-11-30 18:27:25 +01:00
|
|
|
.aligned:
|
|
|
|
mov ecx, edx
|
|
|
|
shr ecx, 5
|
2016-11-24 18:29:52 +01:00
|
|
|
rep stosd
|
2016-07-13 03:01:16 +02:00
|
|
|
and edx, 31
|
2016-11-30 18:27:25 +01:00
|
|
|
jz @f
|
2016-11-24 18:29:52 +01:00
|
|
|
mov ecx, edx
|
|
|
|
not eax
|
|
|
|
shl eax, cl
|
|
|
|
and [edi], eax
|
2016-10-07 14:10:45 +02:00
|
|
|
@@:
|
2016-11-24 18:29:52 +01:00
|
|
|
pop eax ebx
|
|
|
|
call extfsWriteBlock
|
|
|
|
.ret:
|
|
|
|
pop edi edx ebx
|
2016-11-01 06:21:53 +01:00
|
|
|
xor eax, eax
|
2016-07-13 03:01:16 +02:00
|
|
|
ret
|
|
|
|
|
2016-11-01 06:21:53 +01:00
|
|
|
extfsInodeAlloc:
|
|
|
|
; in: eax = parent inode number
|
|
|
|
; out: ebx = allocated inode number
|
2017-01-28 03:39:27 +01:00
|
|
|
push ecx edx edi
|
2016-07-13 03:01:16 +02:00
|
|
|
dec eax
|
|
|
|
xor edx, edx
|
|
|
|
div [ebp+EXTFS.superblock.inodesPerGroup]
|
2017-01-28 03:39:27 +01:00
|
|
|
mov ebx, [ebp+EXTFS.descriptorTable]
|
|
|
|
shl eax, 5
|
|
|
|
add ebx, eax
|
|
|
|
push ebx
|
2016-07-13 03:01:16 +02:00
|
|
|
.test_block_group:
|
2017-01-28 03:39:27 +01:00
|
|
|
push ebx
|
2016-11-30 18:27:25 +01:00
|
|
|
cmp [ebx+BGDESCR.blocksFree], 0
|
|
|
|
jz .next
|
2017-01-28 03:39:27 +01:00
|
|
|
cmp [ebx+BGDESCR.inodesFree], 0
|
|
|
|
jz .next
|
2016-11-24 18:29:52 +01:00
|
|
|
dec [ebx+BGDESCR.inodesFree]
|
2017-01-28 03:39:27 +01:00
|
|
|
dec [ebp+EXTFS.superblock.inodesFree]
|
|
|
|
push [ebx+BGDESCR.inodeBitmap]
|
2016-10-07 14:10:45 +02:00
|
|
|
call extfsWriteDescriptor
|
2017-01-28 03:39:27 +01:00
|
|
|
pop eax
|
2016-10-07 14:10:45 +02:00
|
|
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
2017-01-28 03:39:27 +01:00
|
|
|
mov edx, eax
|
2016-07-13 03:01:16 +02:00
|
|
|
mov edi, ebx
|
|
|
|
call extfsReadBlock
|
|
|
|
jc .fail
|
2016-11-01 06:21:53 +01:00
|
|
|
mov ecx, [ebp+EXTFS.superblock.inodesPerGroup]
|
2016-07-13 03:01:16 +02:00
|
|
|
or eax, -1
|
|
|
|
shr ecx, 5
|
|
|
|
repz scasd
|
|
|
|
jz .next
|
|
|
|
sub edi, 4
|
|
|
|
mov eax, [edi]
|
|
|
|
not eax
|
|
|
|
bsf eax, eax
|
|
|
|
bts [edi], eax
|
2016-10-07 14:10:45 +02:00
|
|
|
sub edi, [ebp+EXTFS.tempBlockBuffer]
|
2016-07-13 03:01:16 +02:00
|
|
|
shl edi, 3
|
|
|
|
add eax, edi
|
|
|
|
mov ecx, eax
|
|
|
|
mov eax, edx
|
|
|
|
call extfsWriteBlock
|
2016-10-07 14:10:45 +02:00
|
|
|
pop eax
|
2017-01-28 03:39:27 +01:00
|
|
|
sub eax, [ebp+EXTFS.descriptorTable]
|
|
|
|
shr eax, 5
|
2016-11-01 06:21:53 +01:00
|
|
|
mul [ebp+EXTFS.superblock.inodesPerGroup]
|
2016-11-24 18:29:52 +01:00
|
|
|
lea ebx, [eax+ecx+1]
|
2016-10-07 14:10:45 +02:00
|
|
|
xor eax, eax
|
2016-11-24 18:29:52 +01:00
|
|
|
.ret:
|
2017-01-28 03:39:27 +01:00
|
|
|
pop edi edi edx ecx
|
2016-07-13 03:01:16 +02:00
|
|
|
ret
|
|
|
|
|
2017-01-28 03:39:27 +01:00
|
|
|
.next: ; search forward, then backward
|
|
|
|
pop ebx
|
|
|
|
cmp ebx, [esp]
|
|
|
|
jc .backward
|
|
|
|
add ebx, 32
|
|
|
|
cmp ebx, [ebp+EXTFS.descriptorTableEnd]
|
|
|
|
jc .test_block_group
|
|
|
|
mov ebx, [esp]
|
2016-07-13 03:01:16 +02:00
|
|
|
.backward:
|
2017-01-28 03:39:27 +01:00
|
|
|
sub ebx, 32
|
|
|
|
cmp ebx, [ebp+EXTFS.descriptorTable]
|
2016-11-24 18:29:52 +01:00
|
|
|
jnc .test_block_group
|
|
|
|
movi eax, ERROR_DISK_FULL
|
2017-01-28 03:39:27 +01:00
|
|
|
push eax
|
2016-11-24 18:29:52 +01:00
|
|
|
.fail:
|
|
|
|
pop edi
|
|
|
|
jmp .ret
|
2016-07-13 03:01:16 +02:00
|
|
|
|
2016-11-01 06:21:53 +01:00
|
|
|
extfsExtentAlloc:
|
2016-11-24 18:29:52 +01:00
|
|
|
; in: eax = parent inode number, ecx = blocks max
|
|
|
|
; out: ebx = first block number, ecx = blocks allocated
|
2016-11-01 06:21:53 +01:00
|
|
|
push edx esi edi ecx
|
|
|
|
dec eax
|
|
|
|
xor edx, edx
|
|
|
|
div [ebp+EXTFS.superblock.inodesPerGroup]
|
2017-01-28 03:39:27 +01:00
|
|
|
mov ebx, [ebp+EXTFS.descriptorTable]
|
|
|
|
shl eax, 5
|
|
|
|
add ebx, eax
|
|
|
|
push ebx
|
2016-11-01 06:21:53 +01:00
|
|
|
.test_block_group:
|
2017-01-28 03:39:27 +01:00
|
|
|
push ebx
|
|
|
|
cmp [ebx+BGDESCR.blocksFree], 0
|
|
|
|
jz .next
|
2016-11-24 18:29:52 +01:00
|
|
|
mov eax, [ebx+BGDESCR.blockBitmap]
|
2016-11-01 06:21:53 +01:00
|
|
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
|
|
|
mov edx, eax
|
|
|
|
mov edi, ebx
|
|
|
|
call extfsReadBlock
|
|
|
|
jc .fail
|
|
|
|
mov ecx, [ebp+EXTFS.superblock.blocksPerGroup]
|
|
|
|
shr ecx, 5
|
|
|
|
or eax, -1
|
|
|
|
repz scasd
|
|
|
|
jz .next
|
|
|
|
mov esi, edi
|
|
|
|
sub esi, 4
|
|
|
|
push edx ecx
|
|
|
|
mov eax, [esi]
|
|
|
|
not eax
|
|
|
|
bsf ecx, eax
|
|
|
|
not eax
|
|
|
|
shr eax, cl
|
|
|
|
shl eax, cl
|
2016-11-24 18:29:52 +01:00
|
|
|
mov ebx, 32
|
2016-11-30 18:27:25 +01:00
|
|
|
bsf ebx, eax
|
2016-11-01 06:21:53 +01:00
|
|
|
sub ebx, ecx
|
|
|
|
mov eax, [esp+16]
|
|
|
|
cmp ebx, eax
|
|
|
|
jc @f
|
|
|
|
mov ebx, eax
|
|
|
|
@@:
|
|
|
|
or eax, -1
|
2016-11-30 18:27:25 +01:00
|
|
|
cmp ebx, 32
|
|
|
|
jz @f
|
|
|
|
xchg ebx, ecx
|
2016-11-01 06:21:53 +01:00
|
|
|
shl eax, cl
|
|
|
|
not eax
|
|
|
|
xchg ebx, ecx
|
|
|
|
shl eax, cl
|
2016-11-30 18:27:25 +01:00
|
|
|
@@:
|
2016-11-01 06:21:53 +01:00
|
|
|
or [esi], eax
|
|
|
|
sub esi, [ebp+EXTFS.tempBlockBuffer]
|
|
|
|
shl esi, 3
|
|
|
|
add esi, ecx
|
|
|
|
mov eax, [esp+16]
|
|
|
|
sub eax, ebx
|
|
|
|
mov [esp+16], ebx
|
|
|
|
add ebx, ecx
|
|
|
|
pop ecx
|
|
|
|
test eax, eax
|
|
|
|
jz .done
|
|
|
|
cmp ebx, 32
|
|
|
|
jnz .done
|
|
|
|
jecxz .done
|
|
|
|
mov ebx, eax
|
|
|
|
shr eax, 5
|
|
|
|
inc eax
|
|
|
|
and ebx, 31
|
|
|
|
cmp ecx, eax
|
|
|
|
jnc @f
|
|
|
|
mov eax, ecx
|
|
|
|
mov bl, 32
|
|
|
|
@@:
|
|
|
|
mov ecx, eax
|
|
|
|
shl eax, 5
|
|
|
|
add [esp+12], eax
|
|
|
|
xor eax, eax
|
|
|
|
push edi
|
|
|
|
repz scasd
|
|
|
|
jz @f
|
|
|
|
mov eax, [edi-4]
|
|
|
|
bsf eax, eax
|
|
|
|
xchg eax, ebx
|
|
|
|
test ecx, ecx
|
|
|
|
jnz @f
|
|
|
|
cmp ebx, eax
|
|
|
|
jc @f
|
|
|
|
mov ebx, eax
|
|
|
|
@@:
|
|
|
|
inc ecx
|
|
|
|
shl ecx, 5
|
|
|
|
sub ecx, ebx
|
|
|
|
sub [esp+16], ecx
|
|
|
|
mov ecx, edi
|
|
|
|
pop edi
|
|
|
|
sub ecx, edi
|
|
|
|
shr ecx, 2
|
|
|
|
dec ecx
|
|
|
|
or eax, -1
|
|
|
|
rep stosd
|
|
|
|
mov ecx, ebx
|
2017-02-08 18:14:28 +01:00
|
|
|
jecxz .done
|
2016-11-30 18:27:25 +01:00
|
|
|
neg ecx
|
|
|
|
add ecx, 32
|
|
|
|
shr eax, cl
|
2016-11-01 06:21:53 +01:00
|
|
|
or [edi], eax
|
|
|
|
.done:
|
|
|
|
pop eax
|
|
|
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
|
|
|
call extfsWriteBlock
|
2017-01-28 03:39:27 +01:00
|
|
|
mov ebx, [esp]
|
2016-11-01 06:21:53 +01:00
|
|
|
mov ecx, [esp+8]
|
2016-11-24 18:29:52 +01:00
|
|
|
sub [ebx+BGDESCR.blocksFree], cx
|
2017-01-28 03:39:27 +01:00
|
|
|
jnc @f
|
|
|
|
mov [ebx+BGDESCR.blocksFree], 0
|
|
|
|
@@:
|
2016-11-01 06:21:53 +01:00
|
|
|
sub [ebp+EXTFS.superblock.blocksFree], ecx
|
|
|
|
call extfsWriteDescriptor
|
|
|
|
pop eax ebx
|
2017-01-28 03:39:27 +01:00
|
|
|
sub eax, [ebp+EXTFS.descriptorTable]
|
|
|
|
shr eax, 5
|
2016-11-01 06:21:53 +01:00
|
|
|
mul [ebp+EXTFS.superblock.blocksPerGroup]
|
|
|
|
mov ebx, eax
|
|
|
|
add ebx, esi
|
2016-11-24 18:29:52 +01:00
|
|
|
add ebx, [ebp+EXTFS.superblock.firstGroupBlock]
|
2016-11-01 06:21:53 +01:00
|
|
|
pop ecx
|
2016-11-24 18:29:52 +01:00
|
|
|
mov eax, ecx
|
|
|
|
mul [ebp+EXTFS.sectorsPerBlock]
|
|
|
|
add [ebp+EXTFS.inodeBuffer.sectorsUsed], eax
|
|
|
|
xor eax, eax
|
2016-11-01 06:21:53 +01:00
|
|
|
.ret:
|
|
|
|
pop edi esi edx
|
|
|
|
ret
|
|
|
|
|
|
|
|
.next: ; search forward, then backward
|
2017-01-28 03:39:27 +01:00
|
|
|
pop ebx
|
|
|
|
cmp ebx, [esp]
|
2016-11-01 06:21:53 +01:00
|
|
|
jc .backward
|
2017-01-28 03:39:27 +01:00
|
|
|
add ebx, 32
|
|
|
|
cmp ebx, [ebp+EXTFS.descriptorTableEnd]
|
|
|
|
jc .test_block_group
|
|
|
|
mov ebx, [esp]
|
2016-11-01 06:21:53 +01:00
|
|
|
.backward:
|
2017-01-28 03:39:27 +01:00
|
|
|
sub ebx, 32
|
|
|
|
cmp ebx, [ebp+EXTFS.descriptorTable]
|
|
|
|
jnc .test_block_group
|
2016-11-01 06:21:53 +01:00
|
|
|
movi eax, ERROR_DISK_FULL
|
2017-01-28 03:39:27 +01:00
|
|
|
push eax
|
2016-11-24 18:29:52 +01:00
|
|
|
.fail:
|
|
|
|
add esp, 12
|
2016-11-01 06:21:53 +01:00
|
|
|
xor ecx, ecx
|
2016-11-24 18:29:52 +01:00
|
|
|
stc
|
2016-11-01 06:21:53 +01:00
|
|
|
jmp .ret
|
|
|
|
|
2016-11-18 15:43:26 +01:00
|
|
|
extfsGetExtent:
|
|
|
|
; in: ecx = starting file block
|
|
|
|
; out: eax = first block number, ecx = extent size
|
|
|
|
push ebx edx esi
|
|
|
|
lea esi, [ebp+EXTFS.inodeBuffer]
|
2016-07-13 03:01:16 +02:00
|
|
|
test [esi+INODE.featureFlags], EXTENTS_USED
|
|
|
|
jz .listTreeSearch
|
|
|
|
add esi, INODE.blockNumbers
|
|
|
|
.extentTreeSearch:
|
|
|
|
cmp word [esi+NODEHEADER.magic], 0xF30A
|
|
|
|
jne .fail
|
|
|
|
movzx ebx, [esi+NODEHEADER.entriesFolow]
|
|
|
|
add esi, sizeof.NODEHEADER
|
2016-11-18 15:43:26 +01:00
|
|
|
test ebx, ebx
|
|
|
|
jz .noBlock
|
2016-07-13 03:01:16 +02:00
|
|
|
cmp word [esi-sizeof.NODEHEADER+NODEHEADER.currentDepth], 0
|
|
|
|
je .leaf_block
|
2016-11-18 15:43:26 +01:00
|
|
|
dec ebx
|
|
|
|
jz .end_search_index
|
2016-07-13 03:01:16 +02:00
|
|
|
@@:
|
|
|
|
cmp ecx, [esi+sizeof.INDEX+INDEX.fileBlock]
|
|
|
|
jb .end_search_index
|
|
|
|
add esi, sizeof.INDEX
|
|
|
|
dec ebx
|
2016-11-18 15:43:26 +01:00
|
|
|
jnz @b
|
2016-07-13 03:01:16 +02:00
|
|
|
.end_search_index:
|
|
|
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
|
|
|
mov eax, [esi+INDEX.nodeBlock]
|
|
|
|
call extfsReadBlock
|
2016-11-18 15:43:26 +01:00
|
|
|
jc .fail2
|
2016-07-13 03:01:16 +02:00
|
|
|
mov esi, ebx
|
|
|
|
jmp .extentTreeSearch
|
|
|
|
|
2016-11-18 15:43:26 +01:00
|
|
|
.fail:
|
|
|
|
movi eax, ERROR_FS_FAIL
|
|
|
|
jmp .fail2
|
|
|
|
|
2016-07-13 03:01:16 +02:00
|
|
|
.leaf_block:
|
2016-11-18 15:43:26 +01:00
|
|
|
movzx edx, [esi+EXTENT.blocksCount]
|
|
|
|
add edx, [esi+EXTENT.fileBlock]
|
|
|
|
sub edx, ecx
|
|
|
|
ja .end_search_extent
|
2016-07-13 03:01:16 +02:00
|
|
|
add esi, sizeof.EXTENT
|
|
|
|
dec ebx
|
2016-11-18 15:43:26 +01:00
|
|
|
jnz .leaf_block
|
|
|
|
.noBlock:
|
|
|
|
movi eax, ERROR_END_OF_FILE
|
|
|
|
.fail2:
|
|
|
|
pop esi edx ebx
|
|
|
|
stc
|
|
|
|
ret
|
2016-07-13 03:01:16 +02:00
|
|
|
|
|
|
|
.end_search_extent:
|
|
|
|
sub ecx, [esi+EXTENT.fileBlock]
|
2016-11-18 15:43:26 +01:00
|
|
|
jc .fail
|
2016-07-13 03:01:16 +02:00
|
|
|
add ecx, [esi+EXTENT.fsBlock]
|
2016-11-18 15:43:26 +01:00
|
|
|
mov eax, ecx
|
|
|
|
mov ecx, edx
|
|
|
|
pop esi edx ebx
|
2016-07-13 03:01:16 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
.listTreeSearch:
|
|
|
|
cmp ecx, 12
|
|
|
|
jb .get_direct_block
|
|
|
|
sub ecx, 12
|
|
|
|
cmp ecx, [ebp+EXTFS.dwordsPerBlock]
|
|
|
|
jb .get_indirect_block
|
|
|
|
sub ecx, [ebp+EXTFS.dwordsPerBlock]
|
|
|
|
cmp ecx, [ebp+EXTFS.dwordsPerBranch]
|
|
|
|
jb .get_double_indirect_block
|
|
|
|
; triply-indirect blocks
|
|
|
|
sub ecx, [ebp+EXTFS.dwordsPerBranch]
|
|
|
|
mov eax, [esi+INODE.tripleAddress]
|
2016-10-01 22:34:06 +02:00
|
|
|
test eax, eax
|
|
|
|
jz .noBlock
|
2016-07-13 03:01:16 +02:00
|
|
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
|
|
|
call extfsReadBlock
|
|
|
|
jc .fail2
|
|
|
|
xor edx, edx
|
|
|
|
mov eax, ecx
|
|
|
|
div [ebp+EXTFS.dwordsPerBranch]
|
|
|
|
; eax = number in triply-indirect block, edx = number in branch
|
|
|
|
mov eax, [ebx+eax*4]
|
|
|
|
test eax, eax
|
2016-10-01 22:34:06 +02:00
|
|
|
jz .noBlock
|
2016-07-13 03:01:16 +02:00
|
|
|
call extfsReadBlock
|
|
|
|
jc .fail2
|
|
|
|
mov eax, edx
|
|
|
|
jmp @f
|
|
|
|
|
2016-11-18 15:43:26 +01:00
|
|
|
.get_direct_block:
|
|
|
|
mov edx, ecx
|
|
|
|
mov cl, 12
|
|
|
|
lea ebx, [esi+INODE.blockNumbers]
|
|
|
|
jmp .calculateExtent
|
|
|
|
|
|
|
|
.get_indirect_block:
|
|
|
|
mov eax, [esi+INODE.addressBlock]
|
|
|
|
test eax, eax
|
|
|
|
jz .noBlock
|
|
|
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
|
|
|
call extfsReadBlock
|
|
|
|
jc .fail2
|
|
|
|
mov edx, ecx
|
|
|
|
mov ecx, [ebp+EXTFS.dwordsPerBlock]
|
|
|
|
jmp .calculateExtent
|
2016-07-13 03:01:16 +02:00
|
|
|
|
|
|
|
.get_double_indirect_block:
|
|
|
|
mov eax, [esi+INODE.doubleAddress]
|
|
|
|
test eax, eax
|
2016-10-01 22:34:06 +02:00
|
|
|
jz .noBlock
|
2016-07-13 03:01:16 +02:00
|
|
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
|
|
|
call extfsReadBlock
|
|
|
|
jc .fail2
|
|
|
|
mov eax, ecx
|
|
|
|
@@:
|
|
|
|
xor edx, edx
|
2016-11-18 15:43:26 +01:00
|
|
|
mov ecx, [ebp+EXTFS.dwordsPerBlock]
|
|
|
|
div ecx
|
2016-07-13 03:01:16 +02:00
|
|
|
; eax = number in doubly-indirect block, edx = number in indirect block
|
|
|
|
mov eax, [ebx+eax*4]
|
|
|
|
test eax, eax
|
2016-10-01 22:34:06 +02:00
|
|
|
jz .noBlock
|
2016-07-13 03:01:16 +02:00
|
|
|
call extfsReadBlock
|
|
|
|
jc .fail2
|
2016-11-18 15:43:26 +01:00
|
|
|
.calculateExtent:
|
|
|
|
lea esi, [ebx+edx*4]
|
|
|
|
lodsd
|
2016-11-24 18:29:52 +01:00
|
|
|
test eax, eax
|
|
|
|
jz .noBlock
|
2016-11-18 15:43:26 +01:00
|
|
|
mov ebx, eax
|
|
|
|
sub ecx, edx
|
|
|
|
xor edx, edx
|
2016-07-13 03:01:16 +02:00
|
|
|
@@:
|
2016-11-18 15:43:26 +01:00
|
|
|
inc edx
|
|
|
|
dec ecx
|
|
|
|
jz @f
|
|
|
|
lodsd
|
|
|
|
sub eax, ebx
|
|
|
|
sub eax, edx
|
2016-07-13 03:01:16 +02:00
|
|
|
jz @b
|
|
|
|
@@:
|
2016-11-18 15:43:26 +01:00
|
|
|
mov eax, ebx
|
|
|
|
mov ecx, edx
|
|
|
|
pop esi edx ebx
|
|
|
|
clc
|
2016-07-13 03:01:16 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
getInodeLocation:
|
|
|
|
; in: eax = inode number
|
2016-11-24 18:29:52 +01:00
|
|
|
; out: eax = inode sector, edx = offset in sector
|
2016-07-13 03:01:16 +02:00
|
|
|
dec eax
|
|
|
|
xor edx, edx
|
|
|
|
div [ebp+EXTFS.superblock.inodesPerGroup]
|
2017-01-28 03:39:27 +01:00
|
|
|
shl eax, 5
|
|
|
|
add eax, [ebp+EXTFS.descriptorTable]
|
|
|
|
mov ebx, [eax+BGDESCR.inodeTable]
|
|
|
|
imul ebx, [ebp+EXTFS.sectorsPerBlock]
|
2016-12-23 12:10:24 +01:00
|
|
|
movzx eax, [ebp+EXTFS.superblock.inodeSize]
|
|
|
|
mul edx
|
2016-07-13 03:01:16 +02:00
|
|
|
mov edx, eax
|
|
|
|
shr eax, 9
|
|
|
|
and edx, 511
|
2016-11-24 18:29:52 +01:00
|
|
|
add eax, ebx
|
2016-07-13 03:01:16 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
writeInode:
|
2016-10-07 14:10:45 +02:00
|
|
|
; in: eax = inode number, ebx -> inode data
|
2016-07-13 03:01:16 +02:00
|
|
|
push edx edi esi ecx ebx eax
|
|
|
|
mov edi, ebx
|
|
|
|
call fsGetTime
|
|
|
|
add eax, 978307200
|
|
|
|
mov [edi+INODE.inodeModified], eax
|
|
|
|
pop eax
|
2016-11-30 18:27:25 +01:00
|
|
|
cmp eax, ROOT_INODE
|
|
|
|
jnz @f
|
|
|
|
movzx ecx, [ebp+EXTFS.superblock.inodeSize]
|
|
|
|
mov esi, edi
|
2017-02-02 06:47:15 +01:00
|
|
|
lea edi, [ebp+EXTFS.rootInodeBuffer]
|
2016-11-30 18:27:25 +01:00
|
|
|
rep movsb
|
|
|
|
@@:
|
2016-07-13 03:01:16 +02:00
|
|
|
call getInodeLocation
|
|
|
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
|
|
|
mov ecx, eax
|
|
|
|
call fs_read32_sys
|
|
|
|
test eax, eax
|
|
|
|
jnz @f
|
|
|
|
mov eax, ecx
|
|
|
|
movzx ecx, [ebp+EXTFS.superblock.inodeSize]
|
|
|
|
mov edi, edx
|
|
|
|
add edi, ebx
|
2016-11-30 18:27:25 +01:00
|
|
|
mov esi, [esp]
|
2016-07-13 03:01:16 +02:00
|
|
|
rep movsb
|
|
|
|
call fs_write32_sys
|
|
|
|
.ret:
|
|
|
|
pop ebx ecx esi edi edx
|
|
|
|
ret
|
|
|
|
|
|
|
|
@@:
|
2016-11-01 06:21:53 +01:00
|
|
|
movi eax, ERROR_DEVICE
|
|
|
|
stc
|
|
|
|
jmp .ret
|
|
|
|
|
|
|
|
readInode:
|
|
|
|
; in: eax = inode number, ebx -> inode buffer
|
|
|
|
push edx edi esi ecx ebx
|
|
|
|
mov edi, ebx
|
|
|
|
call getInodeLocation
|
|
|
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
|
|
|
call fs_read32_sys
|
|
|
|
test eax, eax
|
|
|
|
jnz @b
|
|
|
|
movzx ecx, [ebp+EXTFS.superblock.inodeSize]
|
|
|
|
mov esi, edx
|
|
|
|
add esi, ebx
|
|
|
|
rep movsb
|
|
|
|
xor eax, eax
|
|
|
|
pop ebx ecx esi edi edx
|
|
|
|
ret
|
|
|
|
|
|
|
|
indirectBlockAlloc:
|
|
|
|
; in:
|
|
|
|
; edi -> indirect block number
|
|
|
|
; ebx = starting extent block
|
|
|
|
; ecx = extent size
|
|
|
|
; edx = starting file block
|
|
|
|
mov eax, [edi]
|
|
|
|
test eax, eax
|
|
|
|
jz .newBlock
|
|
|
|
push edi ebx ecx
|
|
|
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
|
|
|
call extfsReadBlock
|
|
|
|
jc .err2
|
|
|
|
lea edi, [ebx+edx*4]
|
|
|
|
test edx, edx
|
|
|
|
jz @f
|
|
|
|
cmp dword[edi-4], 0
|
|
|
|
jnz @f
|
|
|
|
pop ecx ebx edi
|
|
|
|
.err:
|
|
|
|
mov al, ERROR_FS_FAIL
|
|
|
|
stc
|
|
|
|
ret
|
|
|
|
|
|
|
|
.err2:
|
|
|
|
pop ecx ebx edi
|
|
|
|
ret
|
|
|
|
|
|
|
|
.newBlock:
|
|
|
|
test edx, edx
|
|
|
|
jnz .err
|
|
|
|
mov [edi], ebx
|
|
|
|
inc ebx
|
|
|
|
dec ecx
|
|
|
|
push edi ebx ecx
|
|
|
|
mov ecx, [ebp+EXTFS.dwordsPerBlock]
|
|
|
|
mov edi, [ebp+EXTFS.tempBlockBuffer]
|
|
|
|
push edi
|
|
|
|
rep stosd
|
|
|
|
pop edi
|
|
|
|
@@:
|
|
|
|
mov ecx, [ebp+EXTFS.dwordsPerBlock]
|
|
|
|
sub ecx, edx
|
|
|
|
pop ebx eax
|
|
|
|
sub ebx, ecx
|
|
|
|
jnc @f
|
|
|
|
add ecx, ebx
|
|
|
|
xor ebx, ebx
|
|
|
|
@@:
|
|
|
|
jecxz .done
|
|
|
|
add edx, ecx
|
|
|
|
@@:
|
|
|
|
stosd
|
|
|
|
inc eax
|
|
|
|
loop @b
|
|
|
|
.done:
|
|
|
|
pop edi
|
|
|
|
push eax ebx
|
|
|
|
mov eax, [edi]
|
|
|
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
|
|
|
call extfsWriteBlock
|
|
|
|
pop ecx ebx
|
|
|
|
ret
|
|
|
|
|
|
|
|
doublyIndirectBlockAlloc:
|
|
|
|
; in:
|
|
|
|
; edi -> indirect block number
|
|
|
|
; edx = starting file block
|
|
|
|
; ebx = starting extent block
|
|
|
|
; ecx = extent size
|
|
|
|
; [esp+4] = rest of size
|
|
|
|
; [esp+8] = parent inode number
|
|
|
|
mov eax, [edi]
|
|
|
|
test eax, eax
|
|
|
|
jz .newBlock
|
|
|
|
push edi ecx ebx
|
|
|
|
mov ebx, [ebp+EXTFS.mainBlockBuffer]
|
|
|
|
call extfsReadBlock
|
|
|
|
jc .err2
|
|
|
|
mov eax, edx
|
|
|
|
xor edx, edx
|
|
|
|
mov ecx, [ebp+EXTFS.dwordsPerBlock]
|
|
|
|
div ecx
|
|
|
|
lea edi, [ebx+eax*4]
|
|
|
|
pop ebx
|
|
|
|
test eax, eax
|
|
|
|
jz @f
|
|
|
|
cmp dword[edi-4], 0
|
|
|
|
jnz @f
|
|
|
|
pop ecx edi
|
|
|
|
.err:
|
|
|
|
mov al, ERROR_FS_FAIL
|
|
|
|
stc
|
|
|
|
ret
|
|
|
|
|
|
|
|
.err2:
|
|
|
|
pop ebx ecx edi
|
|
|
|
ret
|
|
|
|
|
|
|
|
.newBlock:
|
|
|
|
test edx, edx
|
|
|
|
jnz .err
|
|
|
|
mov [edi], ebx
|
|
|
|
inc ebx
|
|
|
|
dec ecx
|
|
|
|
inc dword[esp+4]
|
|
|
|
push edi ecx
|
|
|
|
mov ecx, [ebp+EXTFS.dwordsPerBlock]
|
|
|
|
mov edi, [ebp+EXTFS.mainBlockBuffer]
|
|
|
|
push ecx edi
|
|
|
|
rep stosd
|
|
|
|
pop edi ecx
|
|
|
|
@@:
|
|
|
|
sub ecx, eax
|
|
|
|
xchg [esp], ecx
|
|
|
|
.loop:
|
|
|
|
cmp dword[edi], 0
|
|
|
|
jnz @f
|
|
|
|
inc dword[esp+12]
|
|
|
|
@@:
|
|
|
|
jecxz .extentAlloc
|
|
|
|
call indirectBlockAlloc
|
|
|
|
jc .end
|
|
|
|
cmp edx, [ebp+EXTFS.dwordsPerBlock]
|
|
|
|
jnz @b
|
|
|
|
add edi, 4
|
|
|
|
xor edx, edx
|
|
|
|
dec dword[esp]
|
|
|
|
jnz .loop
|
|
|
|
.end:
|
|
|
|
pop edi edi
|
|
|
|
push ebx eax
|
|
|
|
mov eax, [edi]
|
|
|
|
mov ebx, [ebp+EXTFS.mainBlockBuffer]
|
|
|
|
call extfsWriteBlock
|
|
|
|
pop ebx
|
|
|
|
add eax, ebx
|
|
|
|
xor ebx, ebx
|
|
|
|
cmp ebx, eax
|
|
|
|
pop ebx
|
|
|
|
ret
|
|
|
|
|
|
|
|
.extentAlloc:
|
|
|
|
mov ecx, [esp+12]
|
|
|
|
xor eax, eax
|
|
|
|
jecxz .end
|
|
|
|
mov eax, [esp+16]
|
|
|
|
call extfsExtentAlloc
|
|
|
|
jc .end
|
|
|
|
sub [esp+12], ecx
|
|
|
|
jmp @b
|
|
|
|
|
|
|
|
extfsExtendFile:
|
|
|
|
; in:
|
|
|
|
; [ebp+EXTFS.inodeBuffer] = inode
|
2017-01-30 02:03:59 +01:00
|
|
|
; ecx = inode number
|
|
|
|
; edx:eax = new size
|
|
|
|
push ebx esi edi ecx
|
2016-11-01 06:21:53 +01:00
|
|
|
lea esi, [ebp+EXTFS.inodeBuffer]
|
2017-01-30 02:03:59 +01:00
|
|
|
mov ebx, [esi+INODE.fileSize]
|
|
|
|
mov ecx, [esi+INODE.fileSizeHigh]
|
|
|
|
cmp ebx, eax
|
|
|
|
sbb ecx, edx
|
2016-11-01 06:21:53 +01:00
|
|
|
jnc .ret
|
2017-01-30 02:03:59 +01:00
|
|
|
mov ecx, [esi+INODE.fileSizeHigh]
|
2016-11-01 06:21:53 +01:00
|
|
|
mov [esi+INODE.fileSize], eax
|
2017-01-30 02:03:59 +01:00
|
|
|
mov [esi+INODE.fileSizeHigh], edx
|
|
|
|
sub eax, 1
|
|
|
|
sbb edx, 0
|
|
|
|
div [ebp+EXTFS.bytesPerBlock]
|
2016-11-01 06:21:53 +01:00
|
|
|
inc eax
|
2017-01-30 02:03:59 +01:00
|
|
|
xchg eax, ebx
|
|
|
|
mov edx, ecx
|
|
|
|
sub eax, 1
|
|
|
|
sbb edx, 0
|
2016-11-01 06:21:53 +01:00
|
|
|
jc @f
|
2017-01-30 02:03:59 +01:00
|
|
|
div [ebp+EXTFS.bytesPerBlock]
|
2016-11-01 06:21:53 +01:00
|
|
|
@@:
|
2017-01-30 02:03:59 +01:00
|
|
|
inc eax
|
|
|
|
sub ebx, eax
|
2016-11-01 06:21:53 +01:00
|
|
|
jz .ret
|
2017-01-30 02:03:59 +01:00
|
|
|
push ebx
|
|
|
|
mov edx, eax
|
2016-11-01 06:21:53 +01:00
|
|
|
@@:
|
|
|
|
mov ecx, [esp]
|
|
|
|
mov eax, [esp+4]
|
|
|
|
test ecx, ecx
|
|
|
|
jz .done
|
|
|
|
call extfsExtentAlloc
|
|
|
|
jc .errDone
|
|
|
|
sub [esp], ecx
|
|
|
|
cmp edx, 12
|
|
|
|
jc .directBlocks
|
|
|
|
sub edx, 12
|
|
|
|
cmp edx, [ebp+EXTFS.dwordsPerBlock]
|
|
|
|
jc .indirectBlocks
|
|
|
|
sub edx, [ebp+EXTFS.dwordsPerBlock]
|
|
|
|
cmp edx, [ebp+EXTFS.dwordsPerBranch]
|
|
|
|
jc .doublyIndirectBlock
|
|
|
|
sub edx, [ebp+EXTFS.dwordsPerBranch]
|
|
|
|
jmp .triplyIndirectBlock
|
|
|
|
|
|
|
|
.newExtent:
|
|
|
|
jmp @b
|
|
|
|
|
|
|
|
.directBlocks:
|
|
|
|
lea edi, [esi+INODE.blockNumbers+edx*4]
|
|
|
|
test edx, edx
|
|
|
|
jz @f
|
|
|
|
cmp dword[edi-4], 0
|
|
|
|
jz .errDone
|
|
|
|
@@:
|
|
|
|
mov eax, ebx
|
|
|
|
mov ebx, ecx
|
|
|
|
mov ecx, 12
|
|
|
|
sub ecx, edx
|
|
|
|
sub ebx, ecx
|
|
|
|
jnc @f
|
|
|
|
add ecx, ebx
|
|
|
|
xor ebx, ebx
|
|
|
|
@@:
|
|
|
|
add edx, ecx
|
|
|
|
@@:
|
|
|
|
stosd
|
|
|
|
inc eax
|
|
|
|
loop @b
|
|
|
|
mov ecx, ebx
|
|
|
|
mov ebx, eax
|
|
|
|
jecxz .newExtent
|
|
|
|
xor edx, edx
|
|
|
|
.indirectBlocks:
|
|
|
|
lea edi, [esi+INODE.addressBlock]
|
|
|
|
cmp dword[edi], 0
|
|
|
|
jnz @f
|
|
|
|
inc dword[esp]
|
|
|
|
@@:
|
|
|
|
call indirectBlockAlloc
|
|
|
|
jc .errDone
|
|
|
|
add edx, 12
|
|
|
|
jecxz .newExtent
|
|
|
|
xor edx, edx
|
|
|
|
.doublyIndirectBlock:
|
|
|
|
lea edi, [esi+INODE.doubleAddress]
|
|
|
|
call doublyIndirectBlockAlloc
|
|
|
|
jc .errDone
|
|
|
|
mov edx, [ebp+EXTFS.dwordsPerBranch]
|
|
|
|
add edx, [ebp+EXTFS.dwordsPerBlock]
|
|
|
|
add edx, 12
|
|
|
|
jecxz .newExtent
|
|
|
|
xor edx, edx
|
|
|
|
.triplyIndirectBlock:
|
|
|
|
push ecx ebx edx
|
|
|
|
stdcall kernel_alloc, [ebp+EXTFS.bytesPerBlock]
|
|
|
|
pop edx
|
|
|
|
mov esi, eax
|
|
|
|
mov eax, [ebp+EXTFS.inodeBuffer.tripleAddress]
|
|
|
|
test eax, eax
|
|
|
|
jz .newBlock
|
|
|
|
mov ebx, esi
|
|
|
|
call extfsReadBlock
|
|
|
|
pop ebx ecx
|
|
|
|
jc .errFree
|
|
|
|
mov eax, edx
|
|
|
|
xor edx, edx
|
|
|
|
div [ebp+EXTFS.dwordsPerBranch]
|
|
|
|
lea edi, [esi+eax*4]
|
|
|
|
test eax, eax
|
|
|
|
jz @f
|
|
|
|
cmp dword[edi-4], 0
|
|
|
|
jnz @f
|
|
|
|
mov al, ERROR_FS_FAIL
|
|
|
|
.errFree:
|
|
|
|
push ecx eax
|
|
|
|
stdcall kernel_free, esi
|
|
|
|
pop eax ecx
|
|
|
|
.errDone:
|
|
|
|
imul ecx, [ebp+EXTFS.sectorsPerBlock]
|
|
|
|
sub [ebp+EXTFS.inodeBuffer.sectorsUsed], ecx
|
|
|
|
pop ebx
|
|
|
|
imul ebx, [ebp+EXTFS.sectorsPerBlock]
|
|
|
|
add ebx, ecx
|
|
|
|
shl ebx, 9
|
|
|
|
sub [ebp+EXTFS.inodeBuffer.fileSize], ebx
|
|
|
|
stc
|
|
|
|
jmp .ret
|
|
|
|
|
|
|
|
.newBlock:
|
|
|
|
pop ebx ecx
|
|
|
|
mov al, ERROR_FS_FAIL
|
|
|
|
test edx, edx
|
|
|
|
jnz .errFree
|
|
|
|
mov [ebp+EXTFS.inodeBuffer.tripleAddress], ebx
|
|
|
|
inc ebx
|
|
|
|
dec ecx
|
|
|
|
inc dword[esp]
|
|
|
|
push ecx
|
|
|
|
mov ecx, [ebp+EXTFS.dwordsPerBlock]
|
|
|
|
mov edi, esi
|
|
|
|
xor eax, eax
|
|
|
|
rep stosd
|
|
|
|
mov edi, esi
|
|
|
|
pop ecx
|
|
|
|
@@:
|
|
|
|
jecxz .extentAlloc
|
|
|
|
call doublyIndirectBlockAlloc
|
|
|
|
jc .errSave
|
|
|
|
add edi, 4
|
|
|
|
jmp @b
|
|
|
|
|
|
|
|
.extentAlloc:
|
|
|
|
mov ecx, [esp]
|
|
|
|
mov eax, [esp+4]
|
|
|
|
jecxz @f
|
|
|
|
call extfsExtentAlloc
|
|
|
|
jc .errSave
|
|
|
|
sub [esp], ecx
|
|
|
|
jmp @b
|
|
|
|
|
|
|
|
@@:
|
|
|
|
mov eax, [ebp+EXTFS.inodeBuffer.tripleAddress]
|
|
|
|
mov ebx, esi
|
|
|
|
call extfsWriteBlock
|
|
|
|
stdcall kernel_free, esi
|
|
|
|
.done:
|
|
|
|
xor eax, eax
|
|
|
|
pop edi
|
|
|
|
.ret:
|
2017-01-30 02:03:59 +01:00
|
|
|
pop edi edi esi ebx
|
2016-11-01 06:21:53 +01:00
|
|
|
ret
|
|
|
|
|
|
|
|
.errSave:
|
|
|
|
push eax
|
|
|
|
mov eax, [ebp+EXTFS.inodeBuffer.tripleAddress]
|
|
|
|
mov ebx, esi
|
|
|
|
call extfsWriteBlock
|
|
|
|
pop eax
|
|
|
|
jmp .errFree
|
|
|
|
|
2017-02-06 10:55:55 +01:00
|
|
|
freeBlockList:
|
|
|
|
; in: edi -> list of blocks, edx = amount of blocks
|
|
|
|
; out: ebx=0 -> end of list
|
2016-11-24 18:29:52 +01:00
|
|
|
mov ebx, [edi]
|
|
|
|
test ebx, ebx
|
2017-02-06 10:55:55 +01:00
|
|
|
jz .ret
|
2016-11-24 18:29:52 +01:00
|
|
|
xor eax, eax
|
2016-11-01 06:21:53 +01:00
|
|
|
xor ecx, ecx
|
|
|
|
@@:
|
|
|
|
stosd
|
2016-11-24 18:29:52 +01:00
|
|
|
inc ecx
|
2016-11-01 06:21:53 +01:00
|
|
|
dec edx
|
2016-11-24 18:29:52 +01:00
|
|
|
jz @f
|
|
|
|
mov eax, [edi]
|
|
|
|
sub eax, ebx
|
|
|
|
sub eax, ecx
|
|
|
|
jz @b
|
|
|
|
@@:
|
|
|
|
mov eax, ebx
|
|
|
|
call extfsExtentFree
|
|
|
|
test edx, edx
|
2017-02-06 10:55:55 +01:00
|
|
|
jnz freeBlockList
|
|
|
|
.ret:
|
|
|
|
ret
|
|
|
|
|
|
|
|
freeIndirectBlock:
|
|
|
|
; in: edi -> indirect block number, edx = starting block
|
|
|
|
; out: edi = edi+4, eax=0 -> end
|
|
|
|
pushd ecx 0 edi edx
|
|
|
|
mov eax, [edi]
|
|
|
|
test eax, eax
|
|
|
|
jz .ret
|
|
|
|
mov ebx, [ebp+EXTFS.mainBlockBuffer]
|
|
|
|
call extfsReadBlock
|
|
|
|
jc .ret
|
|
|
|
lea edi, [ebx+edx*4]
|
|
|
|
neg edx
|
|
|
|
add edx, [ebp+EXTFS.dwordsPerBlock]
|
|
|
|
call freeBlockList
|
|
|
|
test ebx, ebx
|
|
|
|
jz @f
|
|
|
|
inc dword[esp+8]
|
|
|
|
@@:
|
2016-11-01 06:21:53 +01:00
|
|
|
pop edx edi
|
|
|
|
mov eax, [edi]
|
|
|
|
test edx, edx
|
|
|
|
jnz @f
|
2016-11-24 18:29:52 +01:00
|
|
|
xor ecx, ecx
|
|
|
|
inc ecx
|
|
|
|
call extfsExtentFree
|
2016-11-01 06:21:53 +01:00
|
|
|
stosd
|
|
|
|
jmp .done
|
|
|
|
|
2016-07-13 03:01:16 +02:00
|
|
|
@@:
|
2016-11-24 18:29:52 +01:00
|
|
|
mov ebx, [ebp+EXTFS.mainBlockBuffer]
|
2016-11-01 06:21:53 +01:00
|
|
|
call extfsWriteBlock
|
|
|
|
add edi, 4
|
|
|
|
.done:
|
|
|
|
pop eax ecx
|
|
|
|
xor edx, edx
|
2016-07-13 03:01:16 +02:00
|
|
|
ret
|
|
|
|
|
2016-11-01 06:21:53 +01:00
|
|
|
.ret:
|
|
|
|
pop edi edi edx ecx
|
|
|
|
ret
|
|
|
|
|
|
|
|
freeDoublyIndirectBlock:
|
|
|
|
; in: edi -> doubly-indirect block number, edx = starting block
|
|
|
|
; out: edi = edi+4, eax=-1 -> done, eax=0 -> end
|
|
|
|
mov eax, [edi]
|
|
|
|
test eax, eax
|
|
|
|
jz .ret
|
|
|
|
push ecx eax edx
|
|
|
|
stdcall kernel_alloc, [ebp+EXTFS.bytesPerBlock]
|
2016-10-07 14:10:45 +02:00
|
|
|
mov ebx, eax
|
2016-11-01 06:21:53 +01:00
|
|
|
pop edx eax
|
|
|
|
pushd 0 ebx edx
|
|
|
|
call extfsReadBlock
|
|
|
|
jc .err
|
|
|
|
mov eax, edx
|
2016-07-13 03:01:16 +02:00
|
|
|
xor edx, edx
|
2016-11-01 06:21:53 +01:00
|
|
|
mov ecx, [ebp+EXTFS.dwordsPerBlock]
|
|
|
|
div ecx
|
|
|
|
sub ecx, eax
|
|
|
|
push edi
|
|
|
|
lea edi, [ebx+eax*4]
|
|
|
|
@@:
|
|
|
|
call freeIndirectBlock
|
|
|
|
test eax, eax
|
|
|
|
jz .end
|
|
|
|
dec ecx
|
|
|
|
jnz @b
|
|
|
|
dec dword[esp+12]
|
|
|
|
.end:
|
|
|
|
pop edi edx
|
|
|
|
mov eax, [edi]
|
2016-07-13 03:01:16 +02:00
|
|
|
test edx, edx
|
2016-11-01 06:21:53 +01:00
|
|
|
jnz @f
|
|
|
|
xor ecx, ecx
|
2016-11-24 18:29:52 +01:00
|
|
|
inc ecx
|
|
|
|
call extfsExtentFree
|
2016-11-01 06:21:53 +01:00
|
|
|
stosd
|
|
|
|
jmp .done
|
|
|
|
|
2016-10-07 14:10:45 +02:00
|
|
|
@@:
|
2016-11-01 06:21:53 +01:00
|
|
|
mov ebx, [esp]
|
|
|
|
call extfsWriteBlock
|
|
|
|
add edi, 4
|
|
|
|
jmp .done
|
|
|
|
|
|
|
|
.err:
|
|
|
|
mov [esp+8], eax
|
|
|
|
pop eax
|
2016-10-01 22:34:06 +02:00
|
|
|
.done:
|
2016-11-01 06:21:53 +01:00
|
|
|
call kernel_free
|
|
|
|
pop eax ecx
|
2016-07-13 03:01:16 +02:00
|
|
|
.ret:
|
2016-11-01 06:21:53 +01:00
|
|
|
xor edx, edx
|
2016-07-13 03:01:16 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
extfsTruncateFile:
|
2017-01-30 02:03:59 +01:00
|
|
|
; in: edx:eax = new size, [ebp+EXTFS.inodeBuffer] = inode
|
2016-10-07 14:10:45 +02:00
|
|
|
lea esi, [ebp+EXTFS.inodeBuffer]
|
2017-01-30 02:03:59 +01:00
|
|
|
mov ecx, edx
|
|
|
|
cmp eax, [esi+INODE.fileSize]
|
|
|
|
sbb ecx, [esi+INODE.fileSizeHigh]
|
2016-10-07 14:10:45 +02:00
|
|
|
jnc .ret
|
2017-01-30 02:03:59 +01:00
|
|
|
mov [esi+INODE.fileSize], eax
|
|
|
|
mov [esi+INODE.fileSizeHigh], edx
|
|
|
|
sub eax, 1
|
|
|
|
sbb edx, 0
|
|
|
|
jc @f
|
|
|
|
div [ebp+EXTFS.bytesPerBlock]
|
|
|
|
@@:
|
|
|
|
inc eax
|
|
|
|
mov edx, eax
|
2016-11-01 06:21:53 +01:00
|
|
|
cmp edx, 12
|
|
|
|
jc .directBlocks
|
|
|
|
sub edx, 12
|
|
|
|
cmp edx, [ebp+EXTFS.dwordsPerBlock]
|
|
|
|
jc .indirectBlocks
|
|
|
|
sub edx, [ebp+EXTFS.dwordsPerBlock]
|
|
|
|
cmp edx, [ebp+EXTFS.dwordsPerBranch]
|
|
|
|
jc .doublyIndirectBlock
|
|
|
|
sub edx, [ebp+EXTFS.dwordsPerBranch]
|
|
|
|
jmp .triplyIndirectBlock
|
|
|
|
|
|
|
|
.directBlocks:
|
|
|
|
lea edi, [esi+INODE.blockNumbers+edx*4]
|
|
|
|
neg edx
|
|
|
|
add edx, 12
|
2017-02-06 10:55:55 +01:00
|
|
|
call freeBlockList
|
|
|
|
test ebx, ebx
|
2016-11-01 06:21:53 +01:00
|
|
|
jz .ret
|
|
|
|
.indirectBlocks:
|
|
|
|
lea edi, [esi+INODE.addressBlock]
|
|
|
|
call freeIndirectBlock
|
|
|
|
test eax, eax
|
|
|
|
jz .ret
|
|
|
|
.doublyIndirectBlock:
|
|
|
|
lea edi, [esi+INODE.doubleAddress]
|
|
|
|
call freeDoublyIndirectBlock
|
|
|
|
test eax, eax
|
|
|
|
jz .ret
|
|
|
|
.triplyIndirectBlock:
|
|
|
|
mov eax, [esi+INODE.tripleAddress]
|
|
|
|
test eax, eax
|
|
|
|
jz .ret
|
|
|
|
push eax edx
|
|
|
|
stdcall kernel_alloc, [ebp+EXTFS.bytesPerBlock]
|
2016-10-07 14:10:45 +02:00
|
|
|
mov ebx, eax
|
2016-11-01 06:21:53 +01:00
|
|
|
pop edx eax
|
|
|
|
push ebx eax edx
|
|
|
|
call extfsReadBlock
|
|
|
|
jc .err
|
|
|
|
mov eax, edx
|
2016-07-13 03:01:16 +02:00
|
|
|
xor edx, edx
|
2016-11-01 06:21:53 +01:00
|
|
|
div [ebp+EXTFS.dwordsPerBranch]
|
|
|
|
mov ecx, [ebp+EXTFS.dwordsPerBlock]
|
|
|
|
sub ecx, eax
|
|
|
|
lea edi, [ebx+eax*4]
|
|
|
|
@@:
|
|
|
|
call freeDoublyIndirectBlock
|
|
|
|
test eax, eax
|
|
|
|
jz .end
|
|
|
|
dec ecx
|
|
|
|
jnz @b
|
|
|
|
.end:
|
|
|
|
pop edx eax
|
2016-07-13 03:01:16 +02:00
|
|
|
test edx, edx
|
2016-10-07 14:10:45 +02:00
|
|
|
jnz @f
|
|
|
|
xor ecx, ecx
|
2016-11-24 18:29:52 +01:00
|
|
|
inc ecx
|
|
|
|
call extfsExtentFree
|
2016-11-01 06:21:53 +01:00
|
|
|
mov [esi+INODE.tripleAddress], eax
|
|
|
|
jmp .done
|
|
|
|
|
2016-10-07 14:10:45 +02:00
|
|
|
@@:
|
2016-11-01 06:21:53 +01:00
|
|
|
mov ebx, [esp]
|
|
|
|
call extfsWriteBlock
|
|
|
|
jmp .done
|
2016-10-07 14:10:45 +02:00
|
|
|
|
2016-11-01 06:21:53 +01:00
|
|
|
.err:
|
|
|
|
pop eax eax
|
2016-10-01 22:34:06 +02:00
|
|
|
.done:
|
2016-11-01 06:21:53 +01:00
|
|
|
call kernel_free
|
2016-07-13 03:01:16 +02:00
|
|
|
.ret:
|
|
|
|
ret
|
|
|
|
|
|
|
|
linkInode:
|
|
|
|
; in:
|
|
|
|
; eax = inode on which to link
|
|
|
|
; ebx = inode to link
|
2016-08-15 18:55:03 +02:00
|
|
|
; esi -> name in UTF-8
|
2016-07-13 03:01:16 +02:00
|
|
|
; dl = file type
|
|
|
|
push esi edi ebx ecx eax edx
|
|
|
|
call strlen
|
|
|
|
push esi ebx ecx
|
2016-10-01 22:34:06 +02:00
|
|
|
lea esi, [ebp+EXTFS.inodeBuffer]
|
2016-07-13 03:01:16 +02:00
|
|
|
mov ebx, esi
|
|
|
|
call readInode
|
|
|
|
jc .error_inode_read
|
2016-11-01 06:21:53 +01:00
|
|
|
mov eax, [esi+INODE.fileSize]
|
2017-02-02 06:47:15 +01:00
|
|
|
xor edx, edx
|
|
|
|
div [ebp+EXTFS.bytesPerBlock]
|
2016-07-13 03:01:16 +02:00
|
|
|
xor ecx, ecx
|
|
|
|
.searchBlock:
|
2016-10-01 22:34:06 +02:00
|
|
|
push eax ; blocks total
|
|
|
|
push ecx ; current file block number
|
|
|
|
cmp eax, ecx
|
|
|
|
jz .alloc_block
|
2016-11-18 15:43:26 +01:00
|
|
|
call extfsGetExtent
|
2016-07-13 03:01:16 +02:00
|
|
|
jc .error_get_inode_block
|
2016-11-18 15:43:26 +01:00
|
|
|
push eax
|
2016-07-13 03:01:16 +02:00
|
|
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
|
|
|
call extfsReadBlock
|
|
|
|
jc .error_block_read
|
2016-10-01 22:34:06 +02:00
|
|
|
mov ecx, [esp+12]
|
2017-02-06 10:55:55 +01:00
|
|
|
add ecx, 8 ; directory entry size
|
2016-07-13 03:01:16 +02:00
|
|
|
mov edi, [ebp+EXTFS.tempBlockBuffer]
|
|
|
|
mov edx, edi
|
|
|
|
add edx, [ebp+EXTFS.bytesPerBlock]
|
|
|
|
.searchSpace:
|
|
|
|
movzx eax, [edi+DIRENTRY.entryLength]
|
|
|
|
test eax, eax
|
|
|
|
jz .zeroLength
|
|
|
|
cmp [edi+DIRENTRY.inodeNumber], 0
|
|
|
|
je .unusedEntry
|
|
|
|
movzx ebx, [edi+DIRENTRY.nameLength]
|
|
|
|
add ebx, 8+3
|
|
|
|
and ebx, -4
|
|
|
|
sub eax, ebx
|
|
|
|
add edi, ebx
|
|
|
|
cmp eax, ecx
|
|
|
|
jb .nextEntry
|
|
|
|
sub edi, ebx
|
|
|
|
mov [edi+DIRENTRY.entryLength], bx
|
|
|
|
add edi, ebx
|
|
|
|
mov [edi+DIRENTRY.entryLength], ax
|
|
|
|
jmp .found
|
|
|
|
|
|
|
|
.unusedEntry:
|
|
|
|
cmp eax, ecx
|
|
|
|
jge .found
|
|
|
|
.nextEntry:
|
|
|
|
add edi, eax
|
|
|
|
cmp edi, edx
|
|
|
|
jb .searchSpace
|
2017-02-06 10:55:55 +01:00
|
|
|
pop ecx
|
|
|
|
@@:
|
|
|
|
pop ecx eax
|
2016-10-01 22:34:06 +02:00
|
|
|
inc ecx
|
|
|
|
jmp .searchBlock
|
2016-07-13 03:01:16 +02:00
|
|
|
|
|
|
|
.zeroLength:
|
|
|
|
mov eax, edx
|
|
|
|
sub eax, edi
|
2017-02-06 10:55:55 +01:00
|
|
|
mov [edi+DIRENTRY.entryLength], ax
|
2016-07-13 03:01:16 +02:00
|
|
|
cmp eax, ecx
|
|
|
|
jge .found
|
|
|
|
mov [edi+DIRENTRY.inodeNumber], 0
|
|
|
|
pop eax
|
|
|
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
|
|
|
call extfsWriteBlock
|
2017-02-06 10:55:55 +01:00
|
|
|
jmp @b
|
|
|
|
|
2016-11-18 15:43:26 +01:00
|
|
|
.alloc_block:
|
2017-01-30 02:03:59 +01:00
|
|
|
mov eax, [esi+INODE.fileSize]
|
|
|
|
add eax, [ebp+EXTFS.bytesPerBlock]
|
|
|
|
xor edx, edx
|
|
|
|
mov ecx, [esp+24]
|
2016-11-18 15:43:26 +01:00
|
|
|
call extfsExtendFile
|
|
|
|
jc .error_get_inode_block
|
|
|
|
mov eax, [esp+24]
|
|
|
|
mov ebx, esi
|
|
|
|
call writeInode
|
|
|
|
jc .error_get_inode_block
|
2016-07-13 03:01:16 +02:00
|
|
|
mov ecx, [esp]
|
2016-11-18 15:43:26 +01:00
|
|
|
call extfsGetExtent
|
2016-07-13 03:01:16 +02:00
|
|
|
jc .error_get_inode_block
|
2016-11-18 15:43:26 +01:00
|
|
|
push eax
|
2016-10-07 14:10:45 +02:00
|
|
|
mov edi, [ebp+EXTFS.tempBlockBuffer]
|
2016-07-13 03:01:16 +02:00
|
|
|
mov eax, [ebp+EXTFS.bytesPerBlock]
|
|
|
|
mov [edi+DIRENTRY.entryLength], ax
|
|
|
|
.found:
|
|
|
|
pop edx ecx ecx ecx ebx esi
|
2016-10-07 14:10:45 +02:00
|
|
|
mov [edi+DIRENTRY.inodeNumber], ebx
|
|
|
|
mov word [edi+DIRENTRY.nameLength], cx
|
2017-02-06 10:55:55 +01:00
|
|
|
sub eax, 8
|
|
|
|
cmp ecx, eax
|
|
|
|
adc ecx, 0
|
|
|
|
test [ebp+EXTFS.superblock.incompatibleFlags], 2
|
|
|
|
jz @f
|
|
|
|
mov eax, [esp]
|
2016-07-13 03:01:16 +02:00
|
|
|
mov [edi+DIRENTRY.fileType], al
|
2017-02-06 10:55:55 +01:00
|
|
|
@@:
|
2016-07-13 03:01:16 +02:00
|
|
|
add edi, 8
|
|
|
|
rep movsb
|
|
|
|
mov eax, edx
|
|
|
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
|
|
|
call extfsWriteBlock
|
|
|
|
@@:
|
|
|
|
pop edx ecx ecx ebx edi esi
|
|
|
|
ret
|
|
|
|
|
|
|
|
.error_block_read:
|
|
|
|
pop ebx
|
|
|
|
.error_get_inode_block:
|
|
|
|
pop ebx ebx
|
|
|
|
.error_inode_read:
|
2017-07-09 10:28:00 +02:00
|
|
|
pop ebx ebx ebx
|
2016-07-13 03:01:16 +02:00
|
|
|
jmp @b
|
|
|
|
|
|
|
|
unlinkInode:
|
2017-02-04 14:17:52 +01:00
|
|
|
; in: eax = directory inode number, esi = inode to unlink
|
|
|
|
push edi
|
2016-10-01 22:34:06 +02:00
|
|
|
lea ebx, [ebp+EXTFS.inodeBuffer]
|
2016-07-13 03:01:16 +02:00
|
|
|
call readInode
|
2017-02-04 14:17:52 +01:00
|
|
|
jc .ret
|
|
|
|
xor ecx, ecx
|
2016-07-13 03:01:16 +02:00
|
|
|
.loop:
|
2017-02-04 14:17:52 +01:00
|
|
|
push ecx
|
2016-11-18 15:43:26 +01:00
|
|
|
call extfsGetExtent
|
2016-07-13 03:01:16 +02:00
|
|
|
jc .fail_loop
|
2016-11-18 15:43:26 +01:00
|
|
|
mov edi, eax
|
2016-07-13 03:01:16 +02:00
|
|
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
|
|
|
call extfsReadBlock
|
|
|
|
jc .fail_loop
|
|
|
|
.first_dir_entry: ; edi -> block
|
2017-02-04 14:17:52 +01:00
|
|
|
cmp [ebx+DIRENTRY.inodeNumber], esi
|
2016-07-13 03:01:16 +02:00
|
|
|
jne @f
|
|
|
|
mov [ebx+DIRENTRY.inodeNumber], 0
|
|
|
|
mov word [ebx+DIRENTRY.nameLength], 0 ; fileType = 0
|
|
|
|
jmp .write_block
|
|
|
|
|
2017-02-04 14:17:52 +01:00
|
|
|
.fail:
|
|
|
|
pop edi
|
|
|
|
movi eax, ERROR_FS_FAIL
|
|
|
|
stc
|
|
|
|
.fail_loop:
|
|
|
|
pop edi
|
|
|
|
jmp .ret
|
|
|
|
|
|
|
|
.next:
|
|
|
|
pop ecx ecx
|
|
|
|
inc ecx
|
|
|
|
jmp .loop
|
|
|
|
|
2016-07-13 03:01:16 +02:00
|
|
|
@@:
|
|
|
|
mov edx, ebx
|
|
|
|
add edx, [ebp+EXTFS.bytesPerBlock]
|
|
|
|
push edx
|
|
|
|
@@:
|
|
|
|
movzx ecx, [ebx+DIRENTRY.entryLength]
|
2017-02-04 14:17:52 +01:00
|
|
|
jecxz .fail
|
|
|
|
mov edx, ebx
|
2016-07-13 03:01:16 +02:00
|
|
|
add ebx, ecx
|
|
|
|
cmp ebx, [esp]
|
2017-02-04 14:17:52 +01:00
|
|
|
jnc .next
|
|
|
|
cmp [ebx+DIRENTRY.inodeNumber], esi
|
|
|
|
jnz @b
|
|
|
|
mov cx, [ebx+DIRENTRY.entryLength]
|
|
|
|
add [edx+DIRENTRY.entryLength], cx
|
2016-07-13 03:01:16 +02:00
|
|
|
pop eax
|
|
|
|
.write_block:
|
|
|
|
pop eax
|
|
|
|
mov eax, edi
|
|
|
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
|
|
|
call extfsWriteBlock
|
2017-02-04 14:17:52 +01:00
|
|
|
.ret:
|
|
|
|
pop edi
|
2016-07-13 03:01:16 +02:00
|
|
|
ret
|
|
|
|
|
2016-09-14 14:33:51 +02:00
|
|
|
findInode:
|
2016-08-15 18:55:03 +02:00
|
|
|
; in: esi -> path string in UTF-8
|
2016-07-13 03:01:16 +02:00
|
|
|
; out:
|
2016-08-15 18:55:03 +02:00
|
|
|
; edi -> file name in UTF-8
|
2016-09-14 14:33:51 +02:00
|
|
|
; esi = last inode number
|
2016-10-01 22:34:06 +02:00
|
|
|
; [ebp+EXTFS.inodeBuffer] = last inode
|
2016-09-14 14:33:51 +02:00
|
|
|
; ecx = parent inode number
|
|
|
|
; CF=1 -> file not found, edi=0 -> error
|
2016-07-13 03:01:16 +02:00
|
|
|
push esi
|
|
|
|
lea esi, [ebp+EXTFS.rootInodeBuffer]
|
2016-10-01 22:34:06 +02:00
|
|
|
lea edi, [ebp+EXTFS.inodeBuffer]
|
2016-07-13 03:01:16 +02:00
|
|
|
movzx ecx, [ebp+EXTFS.superblock.inodeSize]
|
2016-09-14 14:33:51 +02:00
|
|
|
mov edx, esi
|
2016-07-13 03:01:16 +02:00
|
|
|
rep movsb
|
2016-09-14 14:33:51 +02:00
|
|
|
pop esi
|
2017-01-30 02:03:59 +01:00
|
|
|
pushd ebx 0 ROOT_INODE
|
2016-10-01 22:34:06 +02:00
|
|
|
mov edi, esi
|
2016-11-24 18:29:52 +01:00
|
|
|
cmp [edx+INODE.fileSize], 0
|
2016-09-14 14:33:51 +02:00
|
|
|
jz .not_found
|
|
|
|
cmp byte [esi], 0
|
|
|
|
jnz .next_path_part
|
2016-07-13 03:01:16 +02:00
|
|
|
xor eax, eax
|
2017-01-30 02:03:59 +01:00
|
|
|
pop esi ecx ebx
|
2016-09-14 14:33:51 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
@@:
|
|
|
|
pop esi esi
|
|
|
|
.error:
|
2017-01-30 02:03:59 +01:00
|
|
|
pop esi ecx ebx
|
2016-09-14 14:33:51 +02:00
|
|
|
xor edi, edi
|
|
|
|
stc
|
2016-08-02 22:28:34 +02:00
|
|
|
ret
|
2016-07-13 03:01:16 +02:00
|
|
|
|
|
|
|
.next_path_part:
|
2016-11-24 18:29:52 +01:00
|
|
|
push [edx+INODE.fileSize]
|
2016-07-13 03:01:16 +02:00
|
|
|
xor ecx, ecx
|
|
|
|
.folder_block_cycle:
|
|
|
|
push ecx
|
2016-11-18 15:43:26 +01:00
|
|
|
call extfsGetExtent
|
2016-09-14 14:33:51 +02:00
|
|
|
jc @b
|
2016-07-13 03:01:16 +02:00
|
|
|
mov ebx, [ebp+EXTFS.mainBlockBuffer]
|
|
|
|
call extfsReadBlock
|
2016-09-14 14:33:51 +02:00
|
|
|
jc @b
|
2016-07-13 03:01:16 +02:00
|
|
|
push esi edx
|
|
|
|
mov edx, ebx
|
|
|
|
add edx, [ebp+EXTFS.bytesPerBlock]
|
|
|
|
.start_rec:
|
|
|
|
cmp [ebx+DIRENTRY.inodeNumber], 0
|
|
|
|
jz .next_rec
|
|
|
|
push esi
|
|
|
|
movzx ecx, [ebx+DIRENTRY.nameLength]
|
2016-08-15 18:55:03 +02:00
|
|
|
lea edi, [ebx+DIRENTRY.name]
|
|
|
|
repz cmpsb
|
|
|
|
jz .test_find
|
2016-07-13 03:01:16 +02:00
|
|
|
@@: ; doesn't match
|
|
|
|
pop esi
|
|
|
|
.next_rec:
|
2017-02-06 10:55:55 +01:00
|
|
|
movzx ecx, [ebx+DIRENTRY.entryLength]
|
|
|
|
jecxz .stop
|
|
|
|
add ebx, ecx
|
2016-07-13 03:01:16 +02:00
|
|
|
cmp ebx, edx
|
|
|
|
jb .start_rec
|
2017-02-06 10:55:55 +01:00
|
|
|
jmp .stop
|
2016-07-13 03:01:16 +02:00
|
|
|
|
|
|
|
.test_find:
|
|
|
|
cmp byte [esi], 0
|
|
|
|
je @f
|
|
|
|
cmp byte [esi], '/'
|
|
|
|
jne @b
|
|
|
|
inc esi
|
|
|
|
@@:
|
2017-02-06 10:55:55 +01:00
|
|
|
pop edx
|
|
|
|
.stop:
|
|
|
|
pop edx edi ecx eax
|
2016-07-13 03:01:16 +02:00
|
|
|
; ebx -> matched directory entry, esi -> name without parent, or not changed
|
|
|
|
cmp edi, esi
|
2016-09-14 14:33:51 +02:00
|
|
|
jnz @f
|
2016-11-24 18:29:52 +01:00
|
|
|
sub eax, [ebp+EXTFS.bytesPerBlock]
|
2016-07-13 03:01:16 +02:00
|
|
|
jle .not_found
|
|
|
|
push eax
|
|
|
|
inc ecx
|
|
|
|
jmp .folder_block_cycle
|
|
|
|
|
2016-09-14 14:33:51 +02:00
|
|
|
@@:
|
2016-07-13 03:01:16 +02:00
|
|
|
pop eax
|
2016-09-14 14:33:51 +02:00
|
|
|
mov [esp], eax
|
2016-07-13 03:01:16 +02:00
|
|
|
mov eax, [ebx+DIRENTRY.inodeNumber]
|
2016-10-01 22:34:06 +02:00
|
|
|
lea ebx, [ebp+EXTFS.inodeBuffer]
|
2016-09-14 14:33:51 +02:00
|
|
|
push eax
|
2016-07-13 03:01:16 +02:00
|
|
|
call readInode
|
2016-09-14 14:33:51 +02:00
|
|
|
jc .error
|
|
|
|
cmp byte [esi], 0
|
|
|
|
je .ret
|
|
|
|
mov edx, ebx
|
|
|
|
movzx eax, [ebx+INODE.accessMode]
|
|
|
|
and eax, TYPE_MASK
|
|
|
|
cmp eax, DIRECTORY
|
|
|
|
jz .next_path_part
|
2016-10-01 22:34:06 +02:00
|
|
|
xor edi, edi ; path folder is a file
|
|
|
|
jmp @f
|
|
|
|
|
2016-07-13 03:01:16 +02:00
|
|
|
.not_found:
|
2016-10-01 22:34:06 +02:00
|
|
|
mov esi, edi
|
|
|
|
call strlen
|
|
|
|
mov al, '/'
|
|
|
|
repnz scasb
|
|
|
|
mov edi, esi
|
|
|
|
jnz @f
|
|
|
|
xor edi, edi ; path folder not found
|
|
|
|
@@:
|
2016-07-13 03:01:16 +02:00
|
|
|
movi eax, ERROR_FILE_NOT_FOUND
|
|
|
|
stc
|
2016-09-14 14:33:51 +02:00
|
|
|
.ret:
|
2017-01-30 02:03:59 +01:00
|
|
|
pop esi ecx ebx
|
2016-08-02 22:28:34 +02:00
|
|
|
ret
|
2016-07-13 03:01:16 +02:00
|
|
|
|
|
|
|
writeSuperblock:
|
|
|
|
push ebx
|
|
|
|
mov eax, 2
|
|
|
|
lea ebx, [ebp+EXTFS.superblock]
|
|
|
|
call fs_write32_sys
|
|
|
|
pop ebx
|
|
|
|
ret
|
|
|
|
|
|
|
|
extfsWritingInit:
|
|
|
|
movi eax, ERROR_UNSUPPORTED_FS
|
|
|
|
test [ebp+EXTFS.mountType], READ_ONLY
|
|
|
|
jnz @f
|
|
|
|
ext_lock:
|
|
|
|
lea ecx, [ebp+EXTFS.Lock]
|
|
|
|
jmp mutex_lock
|
|
|
|
|
|
|
|
@@:
|
|
|
|
pop ebx
|
|
|
|
xor ebx, ebx
|
|
|
|
ret
|
|
|
|
|
|
|
|
ext_unlock:
|
|
|
|
lea ecx, [ebp+EXTFS.Lock]
|
|
|
|
jmp mutex_unlock
|
|
|
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
ext_ReadFolder:
|
|
|
|
call ext_lock
|
|
|
|
cmp byte [esi], 0
|
|
|
|
jz .root_folder
|
2016-08-02 22:28:34 +02:00
|
|
|
call findInode
|
2016-07-13 03:01:16 +02:00
|
|
|
jc .error_ret
|
2016-10-01 22:34:06 +02:00
|
|
|
lea esi, [ebp+EXTFS.inodeBuffer]
|
2016-09-14 14:33:51 +02:00
|
|
|
test [esi+INODE.accessMode], FLAG_FILE
|
|
|
|
jnz .error_not_found
|
2016-07-13 03:01:16 +02:00
|
|
|
jmp @f
|
|
|
|
|
|
|
|
.root_folder:
|
|
|
|
lea esi, [ebp+EXTFS.rootInodeBuffer]
|
2016-10-01 22:34:06 +02:00
|
|
|
lea edi, [ebp+EXTFS.inodeBuffer]
|
2016-07-13 03:01:16 +02:00
|
|
|
movzx ecx, [ebp+EXTFS.superblock.inodeSize]
|
|
|
|
shr ecx, 2
|
|
|
|
push edi
|
|
|
|
rep movsd
|
|
|
|
pop esi
|
|
|
|
@@:
|
|
|
|
cmp [esi+INODE.fileSize], 0
|
|
|
|
je .error_empty_dir
|
|
|
|
mov edx, [ebx+16]
|
|
|
|
push edx ; [edi+28] result buffer
|
|
|
|
push 0 ; [edi+24] end of the current block in folder
|
|
|
|
pushd [ebx+12] ; [edi+20] files to read
|
|
|
|
pushd [ebx+4] ; [edi+16] first wanted file
|
|
|
|
pushd [ebx+8] ; [edi+12] flags
|
|
|
|
push 0 ; [edi+8] read files
|
|
|
|
push 0 ; [edi+4] files in folder
|
|
|
|
push 0 ; [edi] current block index
|
|
|
|
mov edi, esp ; edi -> local variables
|
|
|
|
add edx, 32
|
|
|
|
xor ecx, ecx
|
2016-11-18 15:43:26 +01:00
|
|
|
call extfsGetExtent
|
2016-07-13 03:01:16 +02:00
|
|
|
jc .error_get_block
|
|
|
|
mov ebx, [ebp+EXTFS.mainBlockBuffer]
|
|
|
|
call extfsReadBlock
|
|
|
|
jc .error_get_block
|
|
|
|
mov eax, ebx
|
|
|
|
add eax, [ebp+EXTFS.bytesPerBlock]
|
|
|
|
mov [edi+24], eax
|
|
|
|
mov ecx, [edi+16]
|
|
|
|
.find_wanted_start:
|
|
|
|
jecxz .find_wanted_end
|
|
|
|
.find_wanted_cycle:
|
|
|
|
cmp [ebx+DIRENTRY.inodeNumber], 0
|
|
|
|
jz @f
|
|
|
|
inc dword [edi+4]
|
|
|
|
dec ecx
|
|
|
|
@@:
|
|
|
|
movzx eax, [ebx+DIRENTRY.entryLength]
|
|
|
|
cmp eax, 12 ; minimum entry length
|
|
|
|
jb .error_bad_len
|
|
|
|
test eax, 3 ; length must be aligned
|
|
|
|
jnz .error_bad_len
|
|
|
|
sub [esi+INODE.fileSize], eax
|
|
|
|
add ebx, eax
|
|
|
|
cmp ebx, [edi+24]
|
|
|
|
jb .find_wanted_start
|
|
|
|
push .find_wanted_start
|
|
|
|
.end_block: ; read next block
|
|
|
|
cmp [esi+INODE.fileSize], 0
|
|
|
|
jle .end_dir
|
|
|
|
inc dword [edi]
|
|
|
|
push ecx
|
|
|
|
mov ecx, [edi]
|
2016-11-18 15:43:26 +01:00
|
|
|
call extfsGetExtent
|
2016-07-13 03:01:16 +02:00
|
|
|
jc .error_get_block
|
|
|
|
mov ebx, [ebp+EXTFS.mainBlockBuffer]
|
|
|
|
call extfsReadBlock
|
|
|
|
jc .error_get_block
|
|
|
|
pop ecx
|
|
|
|
mov eax, ebx
|
|
|
|
add eax, [ebp+EXTFS.bytesPerBlock]
|
|
|
|
mov [edi+24], eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
.wanted_end:
|
|
|
|
loop .find_wanted_cycle
|
|
|
|
.find_wanted_end:
|
|
|
|
mov ecx, [edi+20]
|
|
|
|
.wanted_start:
|
|
|
|
jecxz .wanted_end
|
|
|
|
cmp [ebx+DIRENTRY.inodeNumber], 0
|
|
|
|
jz .empty_rec
|
|
|
|
inc dword [edi+8]
|
|
|
|
inc dword [edi+4]
|
2016-10-01 22:34:06 +02:00
|
|
|
push ebx edi ecx esi edx edi
|
2016-08-15 18:55:03 +02:00
|
|
|
pushd [edi+12]
|
2016-07-13 03:01:16 +02:00
|
|
|
mov edi, edx
|
|
|
|
xor eax, eax
|
|
|
|
mov ecx, 40 / 4
|
|
|
|
rep stosd
|
2016-10-01 22:34:06 +02:00
|
|
|
popd [edx+4] edi
|
2016-07-13 03:01:16 +02:00
|
|
|
mov eax, [ebx+DIRENTRY.inodeNumber]
|
2016-10-01 22:34:06 +02:00
|
|
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
2016-07-13 03:01:16 +02:00
|
|
|
call readInode
|
|
|
|
jc .error_read_subinode
|
|
|
|
mov esi, ebx
|
|
|
|
lea edi, [edx+8]
|
|
|
|
mov eax, [ebx+INODE.inodeModified]
|
|
|
|
sub eax, 978307200 ; 01.01.1970-01.01.2001 = (365*31+8)*24*60*60
|
|
|
|
call fsTime2bdfe
|
|
|
|
|
|
|
|
mov eax, [esi+INODE.accessedTime]
|
|
|
|
sub eax, 978307200
|
|
|
|
call fsTime2bdfe
|
|
|
|
|
|
|
|
mov eax, [esi+INODE.dataModified]
|
|
|
|
sub eax, 978307200
|
|
|
|
call fsTime2bdfe
|
|
|
|
pop edx
|
|
|
|
or dword [edx], KOS_DIRECTORY
|
2016-09-14 14:33:51 +02:00
|
|
|
test [esi+INODE.accessMode], FLAG_FILE
|
|
|
|
jz @f
|
2016-07-13 03:01:16 +02:00
|
|
|
xor dword [edx], KOS_DIRECTORY ; mark as file
|
|
|
|
mov eax, [esi+INODE.fileSize]
|
|
|
|
stosd
|
|
|
|
mov eax, [esi+INODE.fileSizeHigh]
|
|
|
|
stosd
|
|
|
|
@@:
|
|
|
|
mov esi, [esp+12]
|
|
|
|
movzx ecx, [esi+DIRENTRY.nameLength]
|
|
|
|
lea esi, [esi+DIRENTRY.name]
|
2016-08-15 18:55:03 +02:00
|
|
|
cmp byte [esi], '.'
|
|
|
|
jnz @f
|
|
|
|
or byte [edx], KOS_HIDDEN
|
|
|
|
@@:
|
|
|
|
lea edi, [edx+40]
|
2016-12-15 18:38:17 +01:00
|
|
|
cmp byte [edx+4], 3
|
|
|
|
jz .utf8
|
|
|
|
add ecx, esi
|
|
|
|
cmp byte [edx+4], 2
|
2016-08-15 18:55:03 +02:00
|
|
|
jz .utf16
|
|
|
|
@@:
|
|
|
|
call utf8to16
|
|
|
|
call uni2ansi_char
|
|
|
|
stosb
|
|
|
|
cmp esi, ecx
|
|
|
|
jc @b
|
2016-07-13 03:01:16 +02:00
|
|
|
and byte [edi], 0
|
2016-08-15 18:55:03 +02:00
|
|
|
add edx, 40+264
|
2016-07-13 03:01:16 +02:00
|
|
|
@@:
|
2016-08-15 18:55:03 +02:00
|
|
|
pop esi ecx edi ebx
|
2016-07-13 03:01:16 +02:00
|
|
|
dec ecx
|
|
|
|
.empty_rec:
|
|
|
|
movzx eax, [ebx+DIRENTRY.entryLength]
|
|
|
|
cmp eax, 12
|
|
|
|
jb .error_bad_len
|
|
|
|
test eax, 3
|
|
|
|
jnz .error_bad_len
|
|
|
|
sub [esi+INODE.fileSize], eax
|
|
|
|
add ebx, eax
|
|
|
|
cmp ebx, [edi+24]
|
|
|
|
jb .wanted_start
|
|
|
|
push .wanted_start
|
|
|
|
jmp .end_block
|
|
|
|
|
2016-12-15 18:38:17 +01:00
|
|
|
.utf8:
|
|
|
|
rep movsb
|
|
|
|
mov byte [edi], 0
|
|
|
|
add edx, 40+520
|
|
|
|
jmp @b
|
|
|
|
|
2016-08-15 18:55:03 +02:00
|
|
|
.utf16:
|
|
|
|
call utf8to16
|
|
|
|
stosw
|
|
|
|
cmp esi, ecx
|
|
|
|
jc .utf16
|
|
|
|
and word [edi], 0
|
|
|
|
add edx, 40+520
|
|
|
|
jmp @b
|
|
|
|
|
2016-07-13 03:01:16 +02:00
|
|
|
.end_dir:
|
|
|
|
call ext_unlock
|
|
|
|
mov edx, [edi+28]
|
|
|
|
mov ebx, [edi+8]
|
|
|
|
mov ecx, [edi+4]
|
|
|
|
mov dword [edx], 1 ; version
|
|
|
|
mov [edx+4], ebx
|
|
|
|
mov [edx+8], ecx
|
|
|
|
lea esp, [edi+32]
|
|
|
|
mov ecx, 20/4
|
|
|
|
lea edi, [edx+12]
|
|
|
|
xor eax, eax
|
|
|
|
rep stosd
|
|
|
|
ret
|
|
|
|
|
|
|
|
.error_bad_len:
|
|
|
|
movi eax, ERROR_FS_FAIL
|
|
|
|
.error_read_subinode:
|
|
|
|
.error_get_block:
|
|
|
|
lea esp, [edi+32]
|
|
|
|
.error_ret:
|
2017-03-28 16:30:08 +02:00
|
|
|
xor ebx, ebx
|
2016-07-13 03:01:16 +02:00
|
|
|
push eax
|
|
|
|
call ext_unlock
|
|
|
|
pop eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
.error_empty_dir:
|
|
|
|
movi eax, ERROR_FS_FAIL
|
|
|
|
jmp .error_ret
|
|
|
|
|
|
|
|
.error_not_found:
|
|
|
|
movi eax, ERROR_FILE_NOT_FOUND
|
|
|
|
jmp .error_ret
|
|
|
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
ext_ReadFile:
|
|
|
|
call ext_lock
|
2016-08-02 22:28:34 +02:00
|
|
|
call findInode
|
2017-01-30 02:03:59 +01:00
|
|
|
pushd 0 eax
|
2016-11-18 15:43:26 +01:00
|
|
|
jc .ret
|
2016-10-01 22:34:06 +02:00
|
|
|
lea esi, [ebp+EXTFS.inodeBuffer]
|
2016-11-18 15:43:26 +01:00
|
|
|
mov byte [esp], ERROR_ACCESS_DENIED
|
|
|
|
test [esi+INODE.accessMode], FLAG_FILE
|
|
|
|
jz .ret ; not a file
|
|
|
|
mov byte [esp], ERROR_END_OF_FILE
|
|
|
|
mov eax, [esi+INODE.fileSize]
|
|
|
|
mov edx, [esi+INODE.fileSizeHigh]
|
|
|
|
sub eax, [ebx+4]
|
|
|
|
sbb edx, [ebx+8]
|
|
|
|
jc .ret
|
2016-07-13 03:01:16 +02:00
|
|
|
mov ecx, [ebx+12]
|
2016-11-18 15:43:26 +01:00
|
|
|
sub eax, ecx
|
|
|
|
sbb edx, 0
|
|
|
|
jc @f
|
|
|
|
xor eax, eax
|
|
|
|
mov [esp], eax
|
2016-07-13 03:01:16 +02:00
|
|
|
@@:
|
2016-11-18 15:43:26 +01:00
|
|
|
add ecx, eax
|
2016-07-13 03:01:16 +02:00
|
|
|
mov eax, [ebx+4]
|
2016-11-18 15:43:26 +01:00
|
|
|
mov edx, [ebx+8]
|
|
|
|
mov edi, [ebx+16]
|
2016-07-13 03:01:16 +02:00
|
|
|
div [ebp+EXTFS.bytesPerBlock]
|
2016-11-18 15:43:26 +01:00
|
|
|
test edx, edx
|
|
|
|
jz .aligned
|
|
|
|
.piece:
|
|
|
|
push eax ecx
|
|
|
|
mov esi, edx
|
2016-07-13 03:01:16 +02:00
|
|
|
mov ecx, eax
|
2016-11-18 15:43:26 +01:00
|
|
|
call extfsGetExtent
|
|
|
|
jc .errorGet
|
|
|
|
mov ecx, [ebp+EXTFS.sectorsPerBlock]
|
|
|
|
mul ecx
|
2016-07-13 03:01:16 +02:00
|
|
|
mov ebx, [ebp+EXTFS.mainBlockBuffer]
|
2016-11-18 15:43:26 +01:00
|
|
|
call fs_read64_sys
|
|
|
|
test eax, eax
|
|
|
|
jnz .errorRead
|
|
|
|
pop eax
|
|
|
|
mov ecx, [ebp+EXTFS.bytesPerBlock]
|
|
|
|
sub ecx, esi
|
|
|
|
sub eax, ecx
|
|
|
|
jnc @f
|
|
|
|
add ecx, eax
|
|
|
|
xor eax, eax
|
|
|
|
@@:
|
|
|
|
add esi, ebx
|
|
|
|
add [esp+8], ecx
|
2016-07-13 03:01:16 +02:00
|
|
|
rep movsb
|
2016-11-18 15:43:26 +01:00
|
|
|
mov ecx, eax
|
|
|
|
pop eax
|
|
|
|
inc eax
|
2016-07-13 03:01:16 +02:00
|
|
|
xor edx, edx
|
2016-11-18 15:43:26 +01:00
|
|
|
jecxz .ret
|
|
|
|
.aligned:
|
|
|
|
xchg eax, ecx
|
2016-07-13 03:01:16 +02:00
|
|
|
div [ebp+EXTFS.bytesPerBlock]
|
2016-11-18 15:43:26 +01:00
|
|
|
push edx
|
|
|
|
mov edx, eax
|
|
|
|
.writeExtent:
|
|
|
|
test edx, edx
|
|
|
|
jz .end
|
|
|
|
push ecx
|
|
|
|
call extfsGetExtent
|
|
|
|
jc .errorGet
|
|
|
|
sub edx, ecx
|
|
|
|
jnc @f
|
|
|
|
add ecx, edx
|
|
|
|
xor edx, edx
|
2016-07-13 03:01:16 +02:00
|
|
|
@@:
|
2016-11-18 15:43:26 +01:00
|
|
|
add [esp], ecx
|
|
|
|
imul ecx, [ebp+EXTFS.sectorsPerBlock]
|
|
|
|
mov ebx, edi
|
|
|
|
push edx ecx
|
|
|
|
mul [ebp+EXTFS.sectorsPerBlock]
|
|
|
|
call fs_read64_sys
|
|
|
|
pop ecx edx
|
|
|
|
test eax, eax
|
|
|
|
jnz .errorRead
|
|
|
|
shl ecx, 9
|
|
|
|
add edi, ecx
|
|
|
|
add [esp+12], ecx
|
|
|
|
pop ecx
|
|
|
|
jmp .writeExtent
|
2016-07-13 03:01:16 +02:00
|
|
|
|
2016-11-18 15:43:26 +01:00
|
|
|
.end:
|
2016-07-13 03:01:16 +02:00
|
|
|
mov eax, ecx
|
2016-11-18 15:43:26 +01:00
|
|
|
pop ecx
|
|
|
|
jecxz .ret
|
|
|
|
jmp .piece
|
2016-07-13 03:01:16 +02:00
|
|
|
|
2016-11-18 15:43:26 +01:00
|
|
|
.errorRead:
|
|
|
|
movi eax, ERROR_DEVICE
|
|
|
|
.errorGet:
|
2016-07-13 03:01:16 +02:00
|
|
|
pop ebx ebx
|
2016-11-18 15:43:26 +01:00
|
|
|
mov [esp], eax
|
|
|
|
.ret:
|
2016-07-13 03:01:16 +02:00
|
|
|
call ext_unlock
|
2016-11-18 15:43:26 +01:00
|
|
|
pop eax ebx
|
2016-07-13 03:01:16 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
ext_GetFileInfo:
|
|
|
|
cmp byte [esi], 0
|
2017-03-01 17:45:33 +01:00
|
|
|
jz .volume
|
|
|
|
call ext_lock
|
2016-08-02 22:28:34 +02:00
|
|
|
call findInode
|
2017-03-01 17:45:33 +01:00
|
|
|
jc .ret
|
2016-10-01 22:34:06 +02:00
|
|
|
lea esi, [ebp+EXTFS.inodeBuffer]
|
2017-01-30 02:03:59 +01:00
|
|
|
mov edx, [ebx+16]
|
2016-09-14 14:33:51 +02:00
|
|
|
mov bl, [edi]
|
2016-07-13 03:01:16 +02:00
|
|
|
xor eax, eax
|
|
|
|
mov edi, edx
|
|
|
|
mov ecx, 40/4
|
|
|
|
rep stosd
|
|
|
|
cmp bl, '.'
|
|
|
|
jne @f
|
|
|
|
or dword [edx], KOS_HIDDEN
|
|
|
|
@@:
|
|
|
|
or dword [edx], KOS_DIRECTORY
|
2016-09-14 14:33:51 +02:00
|
|
|
test [esi+INODE.accessMode], FLAG_FILE
|
|
|
|
jz @f
|
2016-07-13 03:01:16 +02:00
|
|
|
xor dword [edx], KOS_DIRECTORY ; mark as file
|
|
|
|
mov eax, [esi+INODE.fileSize]
|
|
|
|
mov ebx, [esi+INODE.fileSizeHigh]
|
|
|
|
mov dword [edx+32], eax
|
|
|
|
mov dword [edx+36], ebx
|
|
|
|
@@:
|
|
|
|
lea edi, [edx+8]
|
|
|
|
mov eax, [esi+INODE.inodeModified]
|
|
|
|
sub eax, 978307200 ; 01.01.1970-01.01.2001 = (365*31+8)*24*60*60
|
|
|
|
call fsTime2bdfe
|
|
|
|
|
|
|
|
mov eax, [esi+INODE.accessedTime]
|
|
|
|
sub eax, 978307200
|
|
|
|
call fsTime2bdfe
|
|
|
|
|
|
|
|
mov eax, [esi+INODE.dataModified]
|
|
|
|
sub eax, 978307200
|
|
|
|
call fsTime2bdfe
|
2017-03-01 17:45:33 +01:00
|
|
|
xor eax, eax
|
|
|
|
.ret:
|
|
|
|
push eax
|
2016-07-13 03:01:16 +02:00
|
|
|
call ext_unlock
|
2017-03-01 17:45:33 +01:00
|
|
|
pop eax
|
2017-03-07 17:28:02 +01:00
|
|
|
@@:
|
2017-03-01 17:45:33 +01:00
|
|
|
ret
|
|
|
|
|
|
|
|
.volume:
|
|
|
|
mov eax, dword[ebp+EXTFS.Length]
|
|
|
|
mov edx, dword[ebp+EXTFS.Length+4]
|
|
|
|
mov edi, [ebx+16]
|
|
|
|
shld edx, eax, 9
|
|
|
|
shl eax, 9
|
|
|
|
mov [edi+36], edx
|
|
|
|
mov [edi+32], eax
|
|
|
|
mov eax, [ebx+8]
|
|
|
|
mov byte [edi], 8
|
|
|
|
mov [edi+4], eax
|
2017-03-07 17:28:02 +01:00
|
|
|
test eax, eax
|
|
|
|
jz @b
|
2017-03-01 17:45:33 +01:00
|
|
|
lea esi, [ebp+EXTFS.superblock.volumeLabel]
|
|
|
|
mov ecx, 16
|
|
|
|
add edi, 40
|
|
|
|
cmp eax, 3
|
|
|
|
jz .utf8
|
|
|
|
add ecx, esi
|
|
|
|
cmp eax, 2
|
|
|
|
jz .utf16
|
|
|
|
@@:
|
|
|
|
call utf8to16
|
|
|
|
call uni2ansi_char
|
|
|
|
stosb
|
|
|
|
cmp esi, ecx
|
|
|
|
jc @b
|
|
|
|
jmp @f
|
|
|
|
|
|
|
|
.utf8:
|
|
|
|
rep movsb
|
|
|
|
jmp @f
|
|
|
|
|
|
|
|
.utf16:
|
|
|
|
call utf8to16
|
|
|
|
stosw
|
|
|
|
cmp esi, ecx
|
|
|
|
jc .utf16
|
|
|
|
@@:
|
2016-07-13 03:01:16 +02:00
|
|
|
xor eax, eax
|
2017-03-01 17:45:33 +01:00
|
|
|
mov [edi], ax
|
2016-07-13 03:01:16 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
ext_SetFileInfo:
|
|
|
|
call extfsWritingInit
|
2016-08-02 22:28:34 +02:00
|
|
|
call findInode
|
2016-07-13 03:01:16 +02:00
|
|
|
jc @f
|
2017-01-30 02:03:59 +01:00
|
|
|
push esi
|
|
|
|
mov esi, [ebx+16]
|
|
|
|
add esi, 16
|
2016-10-01 22:34:06 +02:00
|
|
|
lea edi, [ebp+EXTFS.inodeBuffer]
|
2016-07-13 03:01:16 +02:00
|
|
|
call fsCalculateTime
|
|
|
|
add eax, 978307200 ; 01.01.1970-01.01.2001 = (365*31+8)*24*60*60
|
|
|
|
mov [edi+INODE.accessedTime], eax
|
|
|
|
|
|
|
|
add esi, 8
|
|
|
|
call fsCalculateTime
|
|
|
|
add eax, 978307200
|
|
|
|
mov [edi+INODE.dataModified], eax
|
|
|
|
mov ebx, edi
|
|
|
|
pop eax
|
|
|
|
call writeInode
|
|
|
|
@@:
|
|
|
|
push eax
|
|
|
|
jc @f
|
|
|
|
call writeSuperblock
|
|
|
|
mov esi, [ebp+PARTITION.Disk]
|
|
|
|
call disk_sync
|
|
|
|
@@:
|
|
|
|
call ext_unlock
|
|
|
|
pop eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
ext_Delete:
|
|
|
|
call extfsWritingInit
|
2016-08-02 22:28:34 +02:00
|
|
|
call findInode
|
2017-02-04 14:17:52 +01:00
|
|
|
jc .error
|
|
|
|
push ecx
|
|
|
|
movzx edi, [ebp+EXTFS.inodeBuffer.accessMode]
|
|
|
|
and edi, TYPE_MASK
|
|
|
|
cmp edi, DIRECTORY
|
2016-07-13 03:01:16 +02:00
|
|
|
jne .file
|
2016-11-18 15:43:26 +01:00
|
|
|
xor ecx, ecx
|
2016-07-13 03:01:16 +02:00
|
|
|
.checkDirectory:
|
2016-11-18 15:43:26 +01:00
|
|
|
push ecx
|
|
|
|
call extfsGetExtent
|
|
|
|
jc .empty
|
2016-07-13 03:01:16 +02:00
|
|
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
|
|
|
call extfsReadBlock
|
2017-02-04 14:17:52 +01:00
|
|
|
jc .error8
|
2016-07-13 03:01:16 +02:00
|
|
|
mov edx, ebx
|
|
|
|
add edx, [ebp+EXTFS.bytesPerBlock]
|
|
|
|
.dir_entry:
|
2017-02-04 14:17:52 +01:00
|
|
|
movzx ecx, [ebx+DIRENTRY.nameLength]
|
|
|
|
mov ax, word [ebx+DIRENTRY.name]
|
|
|
|
jecxz @f
|
|
|
|
cmp al, '.'
|
|
|
|
jnz .not_empty
|
|
|
|
dec ecx
|
|
|
|
jz @f
|
|
|
|
cmp al, ah
|
|
|
|
jnz .not_empty
|
|
|
|
dec ecx
|
|
|
|
jnz .not_empty
|
2016-07-13 03:01:16 +02:00
|
|
|
@@:
|
2017-02-04 14:17:52 +01:00
|
|
|
mov cx, [ebx+DIRENTRY.entryLength]
|
|
|
|
jecxz @f
|
2016-07-13 03:01:16 +02:00
|
|
|
add ebx, ecx
|
|
|
|
cmp ebx, edx
|
|
|
|
jb .dir_entry
|
2017-02-04 14:17:52 +01:00
|
|
|
@@:
|
2016-11-18 15:43:26 +01:00
|
|
|
pop ecx
|
|
|
|
inc ecx
|
2016-07-13 03:01:16 +02:00
|
|
|
jmp .checkDirectory
|
|
|
|
|
2016-11-24 18:29:52 +01:00
|
|
|
.not_empty:
|
|
|
|
pop eax eax
|
|
|
|
push ERROR_ACCESS_DENIED
|
|
|
|
jmp .ret
|
|
|
|
|
2017-02-04 14:17:52 +01:00
|
|
|
.error8:
|
|
|
|
pop ebx
|
|
|
|
.error4:
|
|
|
|
pop ebx
|
|
|
|
.error:
|
|
|
|
push eax
|
|
|
|
jmp .ret
|
|
|
|
|
2016-07-13 03:01:16 +02:00
|
|
|
.empty:
|
2017-02-04 14:17:52 +01:00
|
|
|
pop ecx ecx
|
2016-11-18 15:43:26 +01:00
|
|
|
cmp eax, ERROR_END_OF_FILE
|
2017-02-04 14:17:52 +01:00
|
|
|
jnz .error
|
|
|
|
push ecx
|
2016-07-13 03:01:16 +02:00
|
|
|
.file:
|
2016-09-14 14:33:51 +02:00
|
|
|
mov eax, ecx
|
|
|
|
call unlinkInode
|
2017-02-04 14:17:52 +01:00
|
|
|
jc .error4
|
|
|
|
pop eax
|
2016-10-01 22:34:06 +02:00
|
|
|
lea ebx, [ebp+EXTFS.inodeBuffer]
|
2017-02-04 14:17:52 +01:00
|
|
|
cmp edi, DIRECTORY
|
|
|
|
jnz @f
|
|
|
|
dec [ebx+INODE.linksCount]
|
|
|
|
call writeInode
|
|
|
|
@@:
|
|
|
|
mov eax, esi
|
2016-07-13 03:01:16 +02:00
|
|
|
call readInode
|
2017-02-04 14:17:52 +01:00
|
|
|
jc .error
|
|
|
|
dec [ebx+INODE.linksCount]
|
|
|
|
jz @f
|
|
|
|
cmp edi, DIRECTORY
|
|
|
|
jnz .hardlinks
|
|
|
|
@@:
|
|
|
|
push esi edi
|
2017-01-30 02:03:59 +01:00
|
|
|
xor eax, eax
|
|
|
|
xor edx, edx
|
2016-11-01 06:21:53 +01:00
|
|
|
call extfsTruncateFile ; free file's data
|
2016-07-13 03:01:16 +02:00
|
|
|
movzx ecx, [ebp+EXTFS.superblock.inodeSize]
|
2016-10-01 22:34:06 +02:00
|
|
|
lea edi, [ebp+EXTFS.inodeBuffer]
|
2016-12-02 15:34:11 +01:00
|
|
|
xor eax, eax
|
2017-01-30 02:03:59 +01:00
|
|
|
push edi
|
2016-12-02 15:34:11 +01:00
|
|
|
rep stosb
|
2016-07-13 03:01:16 +02:00
|
|
|
call fsGetTime
|
2017-02-04 14:17:52 +01:00
|
|
|
pop ebx edi esi
|
2016-07-13 03:01:16 +02:00
|
|
|
add eax, 978307200
|
2016-12-02 15:34:11 +01:00
|
|
|
mov [ebx+INODE.deletedTime], eax
|
2017-02-04 14:17:52 +01:00
|
|
|
mov eax, esi
|
2016-07-13 03:01:16 +02:00
|
|
|
dec eax
|
|
|
|
xor edx, edx
|
|
|
|
div [ebp+EXTFS.superblock.inodesPerGroup]
|
2017-01-28 03:39:27 +01:00
|
|
|
push edx
|
|
|
|
mov ebx, [ebp+EXTFS.descriptorTable]
|
|
|
|
shl eax, 5
|
|
|
|
add ebx, eax
|
2017-02-04 14:17:52 +01:00
|
|
|
cmp edi, DIRECTORY
|
2016-11-24 18:29:52 +01:00
|
|
|
jnz @f
|
|
|
|
dec [ebx+BGDESCR.directoriesCount]
|
|
|
|
@@:
|
|
|
|
inc [ebx+BGDESCR.inodesFree]
|
2017-01-28 03:39:27 +01:00
|
|
|
push [ebx+BGDESCR.inodeBitmap]
|
2016-07-13 03:01:16 +02:00
|
|
|
call extfsWriteDescriptor
|
2017-01-28 03:39:27 +01:00
|
|
|
pop eax
|
2016-11-24 18:29:52 +01:00
|
|
|
mov ebx, [ebp+EXTFS.tempBlockBuffer]
|
2017-01-28 03:39:27 +01:00
|
|
|
mov ecx, eax
|
2016-11-24 18:29:52 +01:00
|
|
|
call extfsReadBlock
|
2017-02-04 14:17:52 +01:00
|
|
|
pop edx
|
|
|
|
jc .error
|
|
|
|
mov eax, edx
|
2016-11-24 18:29:52 +01:00
|
|
|
and edx, 31
|
|
|
|
shr eax, 5
|
|
|
|
shl eax, 2
|
|
|
|
add eax, ebx
|
|
|
|
btr [eax], edx
|
|
|
|
mov eax, ecx
|
|
|
|
call extfsWriteBlock
|
|
|
|
inc [ebp+EXTFS.superblock.inodesFree]
|
2017-02-04 14:17:52 +01:00
|
|
|
.hardlinks:
|
|
|
|
mov eax, esi
|
|
|
|
lea ebx, [ebp+EXTFS.inodeBuffer]
|
|
|
|
call writeInode
|
2016-07-13 03:01:16 +02:00
|
|
|
push eax
|
|
|
|
call writeSuperblock
|
|
|
|
mov esi, [ebp+PARTITION.Disk]
|
|
|
|
call disk_sync
|
|
|
|
.ret:
|
|
|
|
call ext_unlock
|
|
|
|
xor ebx, ebx
|
|
|
|
pop eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
ext_CreateFolder:
|
|
|
|
call extfsWritingInit
|
2016-08-02 22:28:34 +02:00
|
|
|
call findInode
|
2016-07-13 03:01:16 +02:00
|
|
|
jnc .success ; exist
|
2016-09-14 14:33:51 +02:00
|
|
|
test edi, edi
|
|
|
|
jz .error
|
2016-07-13 03:01:16 +02:00
|
|
|
mov eax, esi
|
2016-11-01 06:21:53 +01:00
|
|
|
call extfsInodeAlloc
|
2016-07-13 03:01:16 +02:00
|
|
|
jc .error
|
|
|
|
push ebx esi edi
|
2016-10-01 22:34:06 +02:00
|
|
|
lea edi, [ebp+EXTFS.inodeBuffer]
|
2016-07-13 03:01:16 +02:00
|
|
|
movzx ecx, [ebp+EXTFS.superblock.inodeSize]
|
2017-02-02 06:47:15 +01:00
|
|
|
xor eax, eax
|
2016-07-13 03:01:16 +02:00
|
|
|
rep stosb
|
|
|
|
call fsGetTime
|
|
|
|
add eax, 978307200
|
2017-02-02 06:47:15 +01:00
|
|
|
lea ebx, [ebp+EXTFS.inodeBuffer]
|
|
|
|
mov [ebx+INODE.accessedTime], eax
|
|
|
|
mov [ebx+INODE.dataModified], eax
|
2016-07-13 03:01:16 +02:00
|
|
|
pop edi esi edx
|
|
|
|
; edx = allocated inode number, edi -> filename, esi = parent inode number
|
2017-02-10 10:17:54 +01:00
|
|
|
mov [ebx+INODE.accessMode], DIRECTORY or 511
|
2017-07-09 10:28:00 +02:00
|
|
|
mov byte [ebx+INODE.linksCount], 2
|
2016-07-13 03:01:16 +02:00
|
|
|
mov eax, edx
|
|
|
|
call writeInode
|
|
|
|
jc .error
|
|
|
|
; link to self
|
|
|
|
push edx esi
|
|
|
|
mov eax, edx
|
|
|
|
mov ebx, eax
|
|
|
|
mov dl, DIR_DIRECTORY
|
|
|
|
mov esi, self_link
|
|
|
|
call linkInode
|
|
|
|
pop esi edx
|
|
|
|
jc .error
|
|
|
|
; link to parent
|
|
|
|
push edx esi
|
|
|
|
mov eax, ebx
|
|
|
|
mov ebx, esi
|
|
|
|
mov dl, DIR_DIRECTORY
|
|
|
|
mov esi, parent_link
|
|
|
|
call linkInode
|
|
|
|
pop esi edx
|
|
|
|
jc .error
|
|
|
|
; link parent to child
|
2017-07-09 10:28:00 +02:00
|
|
|
push esi
|
2016-07-13 03:01:16 +02:00
|
|
|
mov eax, esi
|
|
|
|
mov ebx, edx
|
|
|
|
mov esi, edi
|
|
|
|
mov dl, DIR_DIRECTORY
|
|
|
|
call linkInode
|
2017-07-09 10:28:00 +02:00
|
|
|
pop edx
|
|
|
|
jc .error
|
|
|
|
push ebx
|
|
|
|
lea ebx, [ebp+EXTFS.inodeBuffer]
|
|
|
|
inc [ebx+INODE.linksCount]
|
|
|
|
mov eax, edx
|
|
|
|
call writeInode
|
|
|
|
pop ebx
|
2016-07-13 03:01:16 +02:00
|
|
|
jc .error
|
|
|
|
mov eax, ebx
|
|
|
|
dec eax
|
|
|
|
xor edx, edx
|
|
|
|
div [ebp+EXTFS.superblock.inodesPerGroup]
|
2017-01-28 03:39:27 +01:00
|
|
|
mov ebx, [ebp+EXTFS.descriptorTable]
|
|
|
|
shl eax, 5
|
|
|
|
add ebx, eax
|
2016-11-24 18:29:52 +01:00
|
|
|
inc [ebx+BGDESCR.directoriesCount]
|
2016-07-13 03:01:16 +02:00
|
|
|
call extfsWriteDescriptor
|
|
|
|
.success:
|
|
|
|
.error:
|
|
|
|
push eax
|
|
|
|
call writeSuperblock
|
|
|
|
mov esi, [ebp+PARTITION.Disk]
|
|
|
|
call disk_sync
|
|
|
|
call ext_unlock
|
|
|
|
pop eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
self_link db ".", 0
|
|
|
|
parent_link db "..", 0
|
|
|
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
ext_CreateFile:
|
|
|
|
call extfsWritingInit
|
2016-11-18 15:43:26 +01:00
|
|
|
pushd 0 0 ebx
|
2016-08-02 22:28:34 +02:00
|
|
|
call findInode
|
2016-09-14 14:33:51 +02:00
|
|
|
jnc .exist
|
|
|
|
test edi, edi
|
|
|
|
jz .error
|
2016-07-13 03:01:16 +02:00
|
|
|
mov eax, esi
|
2016-11-01 06:21:53 +01:00
|
|
|
call extfsInodeAlloc
|
2016-07-13 03:01:16 +02:00
|
|
|
jc .error
|
2016-09-14 14:33:51 +02:00
|
|
|
push ebx ebx esi edi
|
2016-10-01 22:34:06 +02:00
|
|
|
lea edi, [ebp+EXTFS.inodeBuffer]
|
2016-07-13 03:01:16 +02:00
|
|
|
movzx ecx, [ebp+EXTFS.superblock.inodeSize]
|
2017-02-02 06:47:15 +01:00
|
|
|
xor eax, eax
|
2016-07-13 03:01:16 +02:00
|
|
|
rep stosb
|
|
|
|
call fsGetTime
|
|
|
|
add eax, 978307200
|
2017-02-02 06:47:15 +01:00
|
|
|
lea ebx, [ebp+EXTFS.inodeBuffer]
|
|
|
|
mov [ebx+INODE.accessedTime], eax
|
|
|
|
mov [ebx+INODE.dataModified], eax
|
2016-07-13 03:01:16 +02:00
|
|
|
pop edi esi edx
|
|
|
|
; edx = allocated inode number, edi -> filename, esi = parent inode number
|
2017-02-10 10:17:54 +01:00
|
|
|
mov [ebx+INODE.accessMode], FLAG_FILE or 110110110b
|
2017-07-09 10:28:00 +02:00
|
|
|
mov byte [ebx+INODE.linksCount], 1
|
2016-07-13 03:01:16 +02:00
|
|
|
mov eax, edx
|
|
|
|
call writeInode
|
2016-09-14 14:33:51 +02:00
|
|
|
jc .error2
|
2016-07-13 03:01:16 +02:00
|
|
|
; link parent to child
|
|
|
|
mov eax, esi
|
|
|
|
mov ebx, edx
|
|
|
|
mov esi, edi
|
|
|
|
mov dl, DIR_FLAG_FILE
|
|
|
|
call linkInode
|
2016-09-14 14:33:51 +02:00
|
|
|
jc .error2
|
2017-07-09 10:28:00 +02:00
|
|
|
mov eax, ebx
|
|
|
|
lea ebx, [ebp+EXTFS.inodeBuffer]
|
|
|
|
call readInode
|
|
|
|
jc .error2
|
2016-07-13 03:01:16 +02:00
|
|
|
pop esi ebx
|
2017-01-30 02:03:59 +01:00
|
|
|
mov eax, [ebx+12]
|
|
|
|
xor edx, edx
|
2016-09-14 14:33:51 +02:00
|
|
|
jmp ext_WriteFile.start
|
2016-07-13 03:01:16 +02:00
|
|
|
|
2016-09-14 14:33:51 +02:00
|
|
|
.exist:
|
|
|
|
movi eax, ERROR_ACCESS_DENIED
|
2016-11-18 15:43:26 +01:00
|
|
|
test [ebp+EXTFS.inodeBuffer.accessMode], FLAG_FILE
|
2016-09-14 14:33:51 +02:00
|
|
|
jz .error ; not a file
|
|
|
|
pop ebx
|
2017-01-30 02:03:59 +01:00
|
|
|
mov eax, [ebx+12]
|
|
|
|
xor edx, edx
|
|
|
|
push eax edx ebx esi
|
2016-09-14 14:33:51 +02:00
|
|
|
call extfsTruncateFile
|
2017-01-30 02:03:59 +01:00
|
|
|
pop esi ebx edx eax
|
2016-11-01 06:21:53 +01:00
|
|
|
jmp ext_WriteFile.start
|
|
|
|
|
2016-09-14 14:33:51 +02:00
|
|
|
.error2:
|
|
|
|
pop ebx
|
2016-07-13 03:01:16 +02:00
|
|
|
.error:
|
|
|
|
push eax
|
|
|
|
call ext_unlock
|
2016-11-18 15:43:26 +01:00
|
|
|
pop eax ebx ebx ebx
|
2016-07-13 03:01:16 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
ext_WriteFile:
|
|
|
|
call extfsWritingInit
|
2016-08-02 22:28:34 +02:00
|
|
|
call findInode
|
2016-11-18 15:43:26 +01:00
|
|
|
pushd 0 eax
|
|
|
|
jc .ret
|
|
|
|
mov byte [esp], ERROR_ACCESS_DENIED
|
|
|
|
test [ebp+EXTFS.inodeBuffer.accessMode], FLAG_FILE
|
|
|
|
jz .ret ; not a file
|
2017-01-30 02:03:59 +01:00
|
|
|
mov byte [esp], 0
|
|
|
|
mov eax, [ebx+4]
|
|
|
|
mov edx, [ebx+8]
|
|
|
|
add eax, [ebx+12]
|
|
|
|
adc edx, 0
|
2016-09-14 14:33:51 +02:00
|
|
|
.start:
|
2016-11-18 15:43:26 +01:00
|
|
|
push esi
|
2017-01-30 02:03:59 +01:00
|
|
|
mov ecx, esi
|
2016-07-13 03:01:16 +02:00
|
|
|
call extfsExtendFile
|
2016-11-18 15:43:26 +01:00
|
|
|
jc .errorExtend
|
2016-11-01 06:21:53 +01:00
|
|
|
mov eax, [ebx+4]
|
2017-01-30 02:03:59 +01:00
|
|
|
mov edx, [ebx+8]
|
2016-11-18 15:43:26 +01:00
|
|
|
mov ecx, [ebx+12]
|
|
|
|
mov esi, [ebx+16]
|
|
|
|
.write:
|
2017-02-10 10:17:54 +01:00
|
|
|
jecxz .zero
|
2016-07-13 03:01:16 +02:00
|
|
|
div [ebp+EXTFS.bytesPerBlock]
|
|
|
|
test edx, edx
|
2016-11-18 15:43:26 +01:00
|
|
|
jz .aligned
|
|
|
|
.piece:
|
|
|
|
mov ebx, ecx
|
|
|
|
mov edi, edx
|
|
|
|
mov ecx, eax
|
|
|
|
push eax
|
|
|
|
call extfsGetExtent
|
|
|
|
jc .errorGet
|
|
|
|
mov ecx, [ebp+EXTFS.sectorsPerBlock]
|
|
|
|
mul ecx
|
|
|
|
push ecx eax ebx
|
|
|
|
mov ebx, [ebp+EXTFS.mainBlockBuffer]
|
|
|
|
call fs_read64_sys
|
|
|
|
test eax, eax
|
|
|
|
jnz .errorDevice
|
|
|
|
pop eax
|
|
|
|
mov ecx, [ebp+EXTFS.bytesPerBlock]
|
|
|
|
sub ecx, edi
|
|
|
|
sub eax, ecx
|
|
|
|
jnc @f
|
|
|
|
add ecx, eax
|
|
|
|
xor eax, eax
|
2016-07-13 03:01:16 +02:00
|
|
|
@@:
|
2016-11-18 15:43:26 +01:00
|
|
|
add edi, ebx
|
|
|
|
add [esp+20], ecx
|
2016-07-13 03:01:16 +02:00
|
|
|
rep movsb
|
2016-11-18 15:43:26 +01:00
|
|
|
mov edi, eax
|
|
|
|
pop eax ecx
|
2016-07-13 03:01:16 +02:00
|
|
|
xor edx, edx
|
2016-11-18 15:43:26 +01:00
|
|
|
call fs_write64_sys
|
|
|
|
mov ecx, edi
|
|
|
|
pop eax
|
|
|
|
inc eax
|
2016-07-13 03:01:16 +02:00
|
|
|
xor edx, edx
|
2017-02-10 10:17:54 +01:00
|
|
|
.zero:
|
2016-11-18 15:43:26 +01:00
|
|
|
jecxz .done
|
|
|
|
.aligned:
|
|
|
|
xchg eax, ecx
|
2016-07-13 03:01:16 +02:00
|
|
|
div [ebp+EXTFS.bytesPerBlock]
|
2016-11-18 15:43:26 +01:00
|
|
|
push edx
|
|
|
|
mov edx, eax
|
|
|
|
.writeExtent:
|
|
|
|
test edx, edx
|
|
|
|
jz .end
|
2016-07-13 03:01:16 +02:00
|
|
|
push ecx
|
2016-11-18 15:43:26 +01:00
|
|
|
call extfsGetExtent
|
|
|
|
jc .errorGet2
|
|
|
|
sub edx, ecx
|
|
|
|
jnc @f
|
|
|
|
add ecx, edx
|
|
|
|
xor edx, edx
|
|
|
|
@@:
|
|
|
|
add [esp], ecx
|
|
|
|
imul ecx, [ebp+EXTFS.sectorsPerBlock]
|
|
|
|
mov ebx, esi
|
|
|
|
push edx ecx
|
|
|
|
mul [ebp+EXTFS.sectorsPerBlock]
|
|
|
|
call fs_write64_sys
|
|
|
|
test eax, eax
|
|
|
|
jnz .errorDevice
|
|
|
|
pop ebx edx ecx
|
|
|
|
shl ebx, 9
|
|
|
|
add esi, ebx
|
|
|
|
add [esp+12], ebx
|
|
|
|
jmp .writeExtent
|
|
|
|
|
|
|
|
.end:
|
|
|
|
mov eax, ecx
|
2016-07-13 03:01:16 +02:00
|
|
|
pop ecx
|
2016-11-18 15:43:26 +01:00
|
|
|
jecxz .done
|
|
|
|
jmp .piece
|
|
|
|
|
|
|
|
.errorDevice:
|
2016-09-14 14:33:51 +02:00
|
|
|
pop eax eax
|
2016-11-18 15:43:26 +01:00
|
|
|
movi eax, ERROR_DEVICE
|
|
|
|
.errorGet2:
|
2016-07-13 03:01:16 +02:00
|
|
|
pop ebx
|
2016-11-18 15:43:26 +01:00
|
|
|
.errorGet:
|
|
|
|
pop ebx
|
|
|
|
.errorExtend:
|
|
|
|
mov [esp+4], eax
|
|
|
|
.done:
|
|
|
|
lea ebx, [ebp+EXTFS.inodeBuffer]
|
|
|
|
pop eax
|
|
|
|
call writeInode
|
|
|
|
add [esp], eax
|
2016-07-13 03:01:16 +02:00
|
|
|
call writeSuperblock
|
|
|
|
mov esi, [ebp+PARTITION.Disk]
|
|
|
|
call disk_sync
|
2016-11-18 15:43:26 +01:00
|
|
|
.ret:
|
2016-07-13 03:01:16 +02:00
|
|
|
call ext_unlock
|
2016-11-18 15:43:26 +01:00
|
|
|
pop eax ebx
|
2016-07-13 03:01:16 +02:00
|
|
|
ret
|
|
|
|
|
2016-11-18 15:43:26 +01:00
|
|
|
.erase:
|
2017-01-30 02:03:59 +01:00
|
|
|
push eax eax edi
|
2016-11-18 15:43:26 +01:00
|
|
|
mov eax, ebx
|
|
|
|
jmp .write
|
2016-07-13 03:01:16 +02:00
|
|
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
ext_SetFileEnd:
|
|
|
|
call extfsWritingInit
|
2016-08-02 22:28:34 +02:00
|
|
|
call findInode
|
2016-11-01 06:21:53 +01:00
|
|
|
jc .error2
|
2016-10-07 14:10:45 +02:00
|
|
|
lea edi, [ebp+EXTFS.inodeBuffer]
|
2016-07-13 03:01:16 +02:00
|
|
|
movi eax, ERROR_ACCESS_DENIED
|
2016-11-18 15:43:26 +01:00
|
|
|
test [edi+INODE.accessMode], FLAG_FILE
|
|
|
|
jz .error2 ; not a file
|
2017-01-30 02:03:59 +01:00
|
|
|
mov eax, [ebx+4]
|
|
|
|
mov edx, [ebx+8]
|
2016-10-07 14:10:45 +02:00
|
|
|
mov ebx, [edi+INODE.fileSize]
|
2017-01-30 02:03:59 +01:00
|
|
|
mov ecx, [edi+INODE.fileSizeHigh]
|
|
|
|
push esi ecx
|
|
|
|
cmp ebx, eax
|
|
|
|
sbb ecx, edx
|
|
|
|
mov ecx, esi
|
2016-11-18 15:43:26 +01:00
|
|
|
jnc @f
|
2016-10-07 14:10:45 +02:00
|
|
|
call extfsExtendFile
|
2017-01-30 02:03:59 +01:00
|
|
|
pop esi
|
2016-10-07 14:10:45 +02:00
|
|
|
jc .error
|
2017-01-30 02:03:59 +01:00
|
|
|
mov eax, [edi+INODE.fileSize]
|
|
|
|
mov edx, [edi+INODE.fileSizeHigh]
|
|
|
|
sub eax, ebx
|
|
|
|
sbb edx, esi
|
|
|
|
jnz .done
|
|
|
|
cmp eax, 1000001h
|
2016-11-18 15:43:26 +01:00
|
|
|
jnc .done
|
2017-01-30 02:03:59 +01:00
|
|
|
push eax
|
|
|
|
stdcall kernel_alloc, eax
|
2016-11-18 15:43:26 +01:00
|
|
|
pop ecx
|
|
|
|
test eax, eax
|
|
|
|
jz .error
|
|
|
|
push ecx
|
|
|
|
add ecx, 3
|
|
|
|
shr ecx, 2
|
2017-01-30 02:03:59 +01:00
|
|
|
mov edx, esi
|
2016-11-18 15:43:26 +01:00
|
|
|
mov esi, eax
|
2016-10-07 14:10:45 +02:00
|
|
|
mov edi, eax
|
|
|
|
xor eax, eax
|
2016-11-18 15:43:26 +01:00
|
|
|
rep stosd
|
2017-01-30 02:03:59 +01:00
|
|
|
pop ecx edi
|
2016-11-18 15:43:26 +01:00
|
|
|
push esi
|
|
|
|
call ext_WriteFile.erase
|
|
|
|
call kernel_free
|
2016-10-07 14:10:45 +02:00
|
|
|
xor eax, eax
|
2016-11-18 15:43:26 +01:00
|
|
|
ret
|
|
|
|
|
2016-10-07 14:10:45 +02:00
|
|
|
@@:
|
2016-11-18 15:43:26 +01:00
|
|
|
call extfsTruncateFile
|
2017-01-30 02:03:59 +01:00
|
|
|
pop eax
|
2016-10-07 14:10:45 +02:00
|
|
|
.done:
|
2016-11-01 06:21:53 +01:00
|
|
|
xor eax, eax
|
|
|
|
.error:
|
|
|
|
xchg eax, [esp]
|
2016-10-01 22:34:06 +02:00
|
|
|
lea ebx, [ebp+EXTFS.inodeBuffer]
|
2016-07-13 03:01:16 +02:00
|
|
|
call writeInode
|
2016-11-18 15:43:26 +01:00
|
|
|
add [esp], eax
|
2016-07-13 03:01:16 +02:00
|
|
|
call writeSuperblock
|
|
|
|
mov esi, [ebp+PARTITION.Disk]
|
|
|
|
call disk_sync
|
2016-11-18 15:43:26 +01:00
|
|
|
pop eax
|
2016-11-01 06:21:53 +01:00
|
|
|
.error2:
|
2016-11-18 15:43:26 +01:00
|
|
|
push eax
|
2016-07-13 03:01:16 +02:00
|
|
|
call ext_unlock
|
|
|
|
pop eax
|
|
|
|
ret
|
2017-07-09 10:28:00 +02:00
|
|
|
|
|
|
|
;----------------------------------------------------------------
|
|
|
|
ext_Rename:
|
|
|
|
call extfsWritingInit
|
|
|
|
push esi
|
|
|
|
mov esi, edi
|
|
|
|
call findInode
|
|
|
|
jnc .error
|
|
|
|
test edi, edi
|
|
|
|
jz .error
|
|
|
|
xchg [esp], esi
|
|
|
|
push edi
|
|
|
|
call findInode
|
|
|
|
pop edi
|
|
|
|
jc .error
|
|
|
|
xor edx, edx
|
|
|
|
inc edx
|
|
|
|
test [ebp+EXTFS.inodeBuffer.accessMode], DIRECTORY
|
|
|
|
jz @f
|
|
|
|
inc edx
|
|
|
|
@@:
|
|
|
|
mov eax, ecx
|
|
|
|
push ecx edx
|
|
|
|
call unlinkInode
|
|
|
|
pop edx ecx
|
|
|
|
jc .error
|
|
|
|
cmp edx, 1
|
|
|
|
jz @f
|
|
|
|
lea ebx, [ebp+EXTFS.inodeBuffer]
|
|
|
|
dec [ebx+INODE.linksCount]
|
|
|
|
mov eax, ecx
|
|
|
|
call writeInode
|
|
|
|
jc .error
|
|
|
|
@@:
|
|
|
|
mov ebx, esi
|
|
|
|
mov esi, edi
|
|
|
|
pop eax
|
|
|
|
push eax edx
|
|
|
|
call linkInode
|
|
|
|
pop edx
|
|
|
|
jc .error
|
|
|
|
pop eax
|
|
|
|
cmp edx, 1
|
|
|
|
jz @f
|
|
|
|
lea ebx, [ebp+EXTFS.inodeBuffer]
|
|
|
|
inc [ebx+INODE.linksCount]
|
|
|
|
call writeInode
|
|
|
|
@@:
|
|
|
|
call writeSuperblock
|
|
|
|
mov esi, [ebp+PARTITION.Disk]
|
|
|
|
call disk_sync
|
|
|
|
call ext_unlock
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
.error:
|
|
|
|
push eax
|
|
|
|
call ext_unlock
|
|
|
|
pop eax ebx
|
|
|
|
ret
|