File system: added function 70.8 - delete file/folder

git-svn-id: svn://kolibrios.org@171 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Evgeny Grechnikov (Diamond) 2006-10-09 12:34:00 +00:00
parent 9395f92693
commit 8609e45095
5 changed files with 434 additions and 78 deletions

View File

@ -918,6 +918,12 @@ ramdisk_root_extend_dir:
stc stc
ret ret
uglobal
; this is for delete support
rd_prev_sector dd ?
rd_prev_prev_sector dd ?
endg
ramdisk_notroot_next: ramdisk_notroot_next:
add edi, 0x20 add edi, 0x20
test edi, 0x1FF test edi, 0x1FF
@ -926,6 +932,9 @@ ramdisk_notroot_next:
ramdisk_notroot_next_sector: ramdisk_notroot_next_sector:
push ecx push ecx
mov ecx, [eax] mov ecx, [eax]
push [rd_prev_sector]
pop [rd_prev_prev_sector]
mov [rd_prev_sector], ecx
mov ecx, [ecx*2+0x280000] mov ecx, [ecx*2+0x280000]
and ecx, 0xFFF and ecx, 0xFFF
cmp ecx, 2849 cmp ecx, 2849
@ -2289,4 +2298,107 @@ fs_RamdiskExecute:
mov eax, 6 mov eax, 6
ret ret
;----------------------------------------------------------------
;
; fs_RamdiskDelete - delete file or empty folder from ramdisk
;
; esi points to filename
;
; ret eax = 0 ok or other = errormsg
;
;--------------------------------------------------------------
fs_RamdiskDelete:
cmp byte [esi], 0
jnz @f
; cannot delete root!
.access_denied:
push ERROR_ACCESS_DENIED
.pop_ret:
pop eax
ret
@@:
and [rd_prev_sector], 0
and [rd_prev_prev_sector], 0
push edi
call rd_find_lfn
jnc .found
pop edi
push ERROR_FILE_NOT_FOUND
jmp .pop_ret
.found:
cmp dword [edi], '. '
jz .access_denied2
cmp dword [edi], '.. '
jz .access_denied2
test byte [edi+11], 10h
jz .dodel
; we can delete only empty folders!
movzx eax, word [edi+26]
push ebx
mov ebx, eax
shl ebx, 9
add ebx, RAMDISK + 31*0x200 + 2*0x20
.checkempty:
cmp byte [ebx], 0
jz .empty
cmp byte [ebx], 0xE5
jnz .notempty
add ebx, 0x20
test ebx, 0x1FF
jnz .checkempty
movzx eax, word [RAMDISK_FAT + eax*2]
test eax, eax
jz .empty
mov ebx, eax
shl ebx, 9
add ebx, RAMDISK + 31*0x200
jmp .checkempty
.notempty:
pop ebx
.access_denied2:
pop edi
jmp .access_denied
.empty:
pop ebx
.dodel:
movzx eax, word [edi+26]
; delete folder entry
mov byte [edi], 0xE5
; delete LFN (if present)
.lfndel:
test edi, 0x1FF
jnz @f
cmp [rd_prev_sector], 0
jz @f
cmp [rd_prev_sector], -1
jz .lfndone
mov edi, [rd_prev_sector]
push [rd_prev_prev_sector]
pop [rd_prev_sector]
or [rd_prev_prev_sector], -1
shl edi, 9
add edi, RAMDISK + 31*0x200 + 0x200
@@:
sub edi, 0x20
cmp byte [edi], 0xE5
jz .lfndone
cmp byte [edi+11], 0xF
jnz .lfndone
mov byte [edi], 0xE5
jmp .lfndel
.lfndone:
; delete FAT chain
test eax, eax
jz .done
lea eax, [RAMDISK_FAT + eax*2]
push dword [eax]
and word [eax], 0
pop eax
and eax, 0xFFF
jmp .lfndone
.done:
pop edi
xor eax, eax
ret
; \end{diamond} ; \end{diamond}

View File

@ -1114,6 +1114,12 @@ fat_find_lfn:
popa popa
ret ret
uglobal
; this is for delete support
fd_prev_sector dd ?
fd_prev_prev_sector dd ?
endg
flp_root_next: flp_root_next:
cmp edi, 0xD200-0x20 cmp edi, 0xD200-0x20
jae @f jae @f
@ -1124,6 +1130,13 @@ flp_root_next:
inc dword [eax] inc dword [eax]
cmp dword [eax], 14 cmp dword [eax], 14
jae flp_root_first.readerr jae flp_root_first.readerr
push [fd_prev_sector]
pop [fd_prev_prev_sector]
push eax
mov eax, [eax]
add eax, 19-1
mov [fd_prev_sector], eax
pop eax
flp_root_first: flp_root_first:
mov eax, [eax] mov eax, [eax]
pusha pusha
@ -1162,7 +1175,11 @@ flp_notroot_next:
flp_notroot_next_sector: flp_notroot_next_sector:
push ecx push ecx
mov ecx, [eax] mov ecx, [eax]
mov ecx, [ecx*2+0x282000] push [fd_prev_sector]
pop [fd_prev_prev_sector]
add ecx, 31
mov [fd_prev_sector], ecx
mov ecx, [(ecx-31)*2+0x282000]
and ecx, 0xFFF and ecx, 0xFFF
cmp ecx, 2849 cmp ecx, 2849
jae flp_notroot_first.err2 jae flp_notroot_first.err2
@ -2573,4 +2590,133 @@ fs_FloppyExecute:
mov eax, 11 mov eax, 11
ret ret
;----------------------------------------------------------------
;
; fs_FloppyDelete - delete file or empty folder from floppy
;
; esi points to filename
;
; ret eax = 0 ok or other = errormsg
;
;--------------------------------------------------------------
fs_FloppyDelete:
call read_flp_fat
cmp [FDC_Status], 0
jz @f
push 11
jmp .pop_ret
@@:
cmp byte [esi], 0
jnz @f
; cannot delete root!
.access_denied:
push ERROR_ACCESS_DENIED
.pop_ret:
pop eax
ret
@@:
and [fd_prev_sector], 0
and [fd_prev_prev_sector], 0
push edi
call fd_find_lfn
jnc .found
pop edi
push ERROR_FILE_NOT_FOUND
jmp .pop_ret
.found:
cmp dword [edi], '. '
jz .access_denied2
cmp dword [edi], '.. '
jz .access_denied2
test byte [edi+11], 10h
jz .dodel
; we can delete only empty folders!
push eax
movzx eax, word [edi+26]
push ebx
pusha
add eax, 31
call read_chs_sector
popa
mov ebx, FDD_DATA + 2*0x20
.checkempty:
cmp byte [ebx], 0
jz .empty
cmp byte [ebx], 0xE5
jnz .notempty
add ebx, 0x20
cmp ebx, FDD_DATA + 0x200
jb .checkempty
movzx eax, word [FLOPPY_FAT + eax*2]
pusha
add eax, 31
call read_chs_sector
popa
mov ebx, FDD_DATA
jmp .checkempty
.notempty:
pop ebx
pop eax
.access_denied2:
pop edi
jmp .access_denied
.empty:
pop ebx
pop eax
pusha
call read_chs_sector
popa
.dodel:
push eax
movzx eax, word [edi+26]
xchg eax, [esp]
; delete folder entry
mov byte [edi], 0xE5
; delete LFN (if present)
.lfndel:
cmp edi, FDD_DATA
ja @f
cmp [fd_prev_sector], 0
jz .lfndone
push [fd_prev_sector]
push [fd_prev_prev_sector]
pop [fd_prev_sector]
and [fd_prev_prev_sector], 0
pusha
call save_chs_sector
popa
pop eax
pusha
call read_chs_sector
popa
mov edi, FDD_DATA+0x200
@@:
sub edi, 0x20
cmp byte [edi], 0xE5
jz .lfndone
cmp byte [edi+11], 0xF
jnz .lfndone
mov byte [edi], 0xE5
jmp .lfndel
.lfndone:
pusha
call save_chs_sector
popa
; delete FAT chain
pop eax
test eax, eax
jz .done
@@:
lea eax, [FLOPPY_FAT + eax*2]
push dword [eax]
and word [eax], 0
pop eax
and eax, 0xFFF
jnz @b
.done:
call save_flp_fat
pop edi
xor eax, eax
ret
; \end{diamond} ; \end{diamond}

View File

@ -7,6 +7,7 @@
;; Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it ;; ;; Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it ;;
;; ;; ;; ;;
;; See file COPYING for details ;; ;; See file COPYING for details ;;
;; 08.10.2006 LFN delete file/folder - diamond ;;
;; 20.08.2006 LFN set file size (truncate/extend) - diamond ;; ;; 20.08.2006 LFN set file size (truncate/extend) - diamond ;;
;; 17.08.2006 LFN write/append to file - diamond ;; ;; 17.08.2006 LFN write/append to file - diamond ;;
;; 23.06.2006 LFN start application - diamond ;; ;; 23.06.2006 LFN start application - diamond ;;
@ -61,6 +62,8 @@ PUSHAD_EBP equ [esp+8]
PUSHAD_ESI equ [esp+4] PUSHAD_ESI equ [esp+4]
PUSHAD_EDI equ [esp+0] PUSHAD_EDI equ [esp+0]
uglobal
align 4
cluster dd 0 ; used by file_write,makedir,append cluster dd 0 ; used by file_write,makedir,append
partition_count dd 0 ; partitions found by set_FAT32_variables partition_count dd 0 ; partitions found by set_FAT32_variables
longname_sec1 dd 0 ; used by analyze_directory to save 2 previous longname_sec1 dd 0 ; used by analyze_directory to save 2 previous
@ -83,11 +86,15 @@ new_filepos dd 0 ; used by append
bytes2write dd 0 ; used by append bytes2write dd 0 ; used by append
cache_search_start dd 0 ; used by find_empty_slot cache_search_start dd 0 ; used by find_empty_slot
endg
iglobal
fat_in_cache dd -1 fat_in_cache dd -1
fat_cache: times 512 db 0 endg
uglobal uglobal
align 4
fat_cache: times 512 db 0
Sector512: ; label for dev_hdcd.inc Sector512: ; label for dev_hdcd.inc
buffer: times 512 db 0 buffer: times 512 db 0
deltree_buffer: times 512 db 0 deltree_buffer: times 512 db 0
@ -980,38 +987,6 @@ makedir:
xor eax,eax xor eax,eax
ret ret
removedir:
;-----------------------------------------------------
; input : eax = file/directory name
; edx = path
; output : eax = 0 - ok
; 3 - unknown FS
; 5 - file not found
; 10 - access denied
;-----------------------------------------------------
cmp [fat_type],0
jnz remove_dir_fat_ok
mov eax,ERROR_UNKNOWN_FS
ret
remove_dir_fat_ok:
; call reserve_hd1
push edi
mov edi,1 ; allow directory remove
call file_delete
cmp [hd_error],0
jne @f
pop edi
call update_disk ; write all of cache and fat to hd
@@:
mov [hd1_status],0
ret
add_disk_free_space: add_disk_free_space:
;----------------------------------------------------- ;-----------------------------------------------------
; input : ecx = cluster count ; input : ecx = cluster count
@ -2340,8 +2315,14 @@ fat16_root_next:
ret ; CF=0 ret ; CF=0
fat16_root_next_sector: fat16_root_next_sector:
; read next sector ; read next sector
push [longname_sec2]
pop [longname_sec1]
push ecx push ecx
mov ecx, [eax+4] mov ecx, [eax+4]
push ecx
add ecx, [ROOT_START]
mov [longname_sec2], ecx
pop ecx
inc ecx inc ecx
mov [eax+4], ecx mov [eax+4], ecx
cmp ecx, [ROOT_SECTORS] cmp ecx, [ROOT_SECTORS]
@ -2391,6 +2372,12 @@ fat_notroot_next:
add edi, 0x20 add edi, 0x20
ret ; CF=0 ret ; CF=0
fat_notroot_next_sector: fat_notroot_next_sector:
push [longname_sec2]
pop [longname_sec1]
push eax
call fat_get_sector
mov [longname_sec2], eax
pop eax
push ecx push ecx
mov ecx, [eax+4] mov ecx, [eax+4]
inc ecx inc ecx
@ -3639,7 +3626,7 @@ fs_HdExecute:
.flags: .flags:
cmp [fat_type], 0 cmp [fat_type], 0
jnz @f jnz @f
mov eax, ERROR_UNKNOWN_FS mov eax, -ERROR_UNKNOWN_FS
ret ret
@@: @@:
cmp byte [esi], 0 cmp byte [esi], 0
@ -3722,4 +3709,154 @@ fs_HdExecute:
mov eax, 11 mov eax, 11
ret ret
;----------------------------------------------------------------
;
; fs_HdDelete - delete file or empty folder from hard disk
;
; esi points to filename
;
; ret eax = 0 ok or other = errormsg
;
;--------------------------------------------------------------
fs_HdDelete:
cmp [fat_type], 0
jnz @f
push ERROR_UNKNOWN_FS
.pop_ret:
pop eax
ret
@@:
cmp byte [esi], 0
jnz @f
; cannot delete root!
.access_denied:
push ERROR_ACCESS_DENIED
jmp .pop_ret
@@:
and [longname_sec1], 0
and [longname_sec2], 0
push edi
call hd_find_lfn
jnc .found
pop edi
push ERROR_FILE_NOT_FOUND
jmp .pop_ret
.found:
cmp dword [edi], '. '
jz .access_denied2
cmp dword [edi], '.. '
jz .access_denied2
test byte [edi+11], 10h
jz .dodel
; we can delete only empty folders!
pushad
mov ebp, [edi+20-2]
mov bp, [edi+26]
xor ecx, ecx
lea eax, [ebp-2]
imul eax, [SECTORS_PER_CLUSTER]
add eax, [DATA_START]
mov ebx, buffer
call hd_read
cmp [hd_error], 0
jnz .err1
add ebx, 2*0x20
.checkempty:
cmp byte [ebx], 0
jz .empty
cmp byte [ebx], 0xE5
jnz .notempty
add ebx, 0x20
cmp ebx, buffer+0x200
jb .checkempty
inc ecx
cmp ecx, [SECTORS_PER_CLUSTER]
jb @f
mov eax, ebp
call get_FAT
cmp [hd_error], 0
jnz .err1
mov ebp, eax
xor ecx, ecx
@@:
lea eax, [ebp-2]
imul eax, [SECTORS_PER_CLUSTER]
add eax, [DATA_START]
add eax, ecx
mov ebx, buffer
call hd_read
cmp [hd_error], 0
jz .checkempty
.err1:
popad
.err2:
pop edi
push 11
pop eax
ret
.notempty:
popad
.access_denied2:
pop edi
push ERROR_ACCESS_DENIED
pop eax
ret
.empty:
popad
push ebx
mov ebx, buffer
call hd_read
pop ebx
cmp [hd_error], 0
jnz .err2
.dodel:
push eax
mov eax, [edi+20-2]
mov ax, [edi+26]
xchg eax, [esp]
; delete folder entry
mov byte [edi], 0xE5
; delete LFN (if present)
.lfndel:
cmp edi, buffer
ja @f
cmp [longname_sec2], 0
jz .lfndone
push [longname_sec2]
push [longname_sec1]
pop [longname_sec2]
and [longname_sec1], 0
push ebx
mov ebx, buffer
call hd_write
mov eax, [esp+4]
call hd_read
pop ebx
pop eax
mov edi, buffer+0x200
@@:
sub edi, 0x20
cmp byte [edi], 0xE5
jz .lfndone
cmp byte [edi+11], 0xF
jnz .lfndone
mov byte [edi], 0xE5
jmp .lfndel
.lfndone:
push ebx
mov ebx, buffer
call hd_write
pop ebx
; delete FAT chain
pop eax
call clear_cluster_chain
call update_disk
pop edi
xor eax, eax
cmp [hd_error], 0
jz @f
mov al, 11
@@:
ret
; \end{diamond} ; \end{diamond}

View File

@ -37,7 +37,6 @@ file_system:
; ;
; eax = 0 ; read file /RamDisk/First 6 ; eax = 0 ; read file /RamDisk/First 6
; eax = 1 ; write file /RamDisk/First 33 /HardDisk/First 56 ; eax = 1 ; write file /RamDisk/First 33 /HardDisk/First 56
; eax = 2 ; delete file /RamDisk/First 32
; eax = 4 ; makedir ; eax = 4 ; makedir
; eax = 5 ; rename file/directory ; eax = 5 ; rename file/directory
; eax = 8 ; lba read ; eax = 8 ; lba read
@ -92,8 +91,6 @@ file_system:
je fs_read je fs_read
cmp dword [eax+0],4 ; MAKEDIR - dont care about read&write blocks cmp dword [eax+0],4 ; MAKEDIR - dont care about read&write blocks
je fs_read je fs_read
cmp dword [eax+0],2 ; DELETE - dont care about read&write blocks
je fs_read
cmp dword [0x3000],1 ; no memory checks for kernel requests cmp dword [0x3000],1 ; no memory checks for kernel requests
jz no_checks_for_kernel jz no_checks_for_kernel
@ -283,15 +280,6 @@ endg
jmp file_system_return jmp file_system_return
fs_noramdisk_write: fs_noramdisk_write:
cmp dword [esp+20],2 ;DELETE
jne fs_noramdisk_delete
mov eax,[esp+4] ; fname
add eax,2*12+1
call filedelete
jmp file_system_return
fs_noramdisk_delete:
fs_noramdisk: fs_noramdisk:
;******************************************************************** ;********************************************************************
@ -359,17 +347,6 @@ endg
fs_noflpdisk_write: fs_noflpdisk_write:
cmp dword [esp+20],2 ; DELETE
jne fs_noflpdisk_delete
mov eax,[esp+4] ; fname
add eax,2*12+1
call floppy_filedelete
mov [flp_status],0
jmp file_system_return
fs_noflpdisk_delete:
fs_noflpdisk: fs_noflpdisk:
;***************************************************************** ;*****************************************************************
@ -521,24 +498,6 @@ hd_err_return:
fs_noharddisk_write: fs_noharddisk_write:
cmp dword [esp+20],2 ; DELETE
jne fs_noharddisk_delete
mov eax,[esp+0] ; /dirname or /filename
mov byte [eax],0 ; path to asciiz
inc eax ; filename start
mov edx,[esp+4]
add edx,12*2 ; path start
call removedir
mov edi,[esp+0]
mov byte [edi],'/'
jmp file_system_return
fs_noharddisk_delete:
cmp dword [esp+20],4 ; MAKEDIR cmp dword [esp+20],4 ; MAKEDIR
jne fs_noharddisk_makedir jne fs_noharddisk_makedir

View File

@ -82,9 +82,8 @@ file_system_lfn:
; 5 : get file/directory attributes structure ; 5 : get file/directory attributes structure
; 6 : set file/directory attributes structure ; 6 : set file/directory attributes structure
; 7 : start application ; 7 : start application
; 8 : delete file - not implemented yet ; 8 : delete file
; 9 : create directory - not implemented yet ; 9 : create directory - not implemented yet
; 10: rename file/directory - not implemented yet
add eax, std_application_base_address add eax, std_application_base_address
; parse file name ; parse file name
@ -352,6 +351,7 @@ fs_RamdiskServices:
dd fs_RamdiskGetFileInfo dd fs_RamdiskGetFileInfo
dd fs_RamdiskSetFileInfo dd fs_RamdiskSetFileInfo
dd fs_RamdiskExecute dd fs_RamdiskExecute
dd fs_RamdiskDelete
fs_NumRamdiskServices = ($ - fs_RamdiskServices)/4 fs_NumRamdiskServices = ($ - fs_RamdiskServices)/4
fs_OnFloppy: fs_OnFloppy:
@ -381,6 +381,7 @@ fs_FloppyServices:
dd fs_FloppyGetFileInfo dd fs_FloppyGetFileInfo
dd fs_FloppySetFileInfo dd fs_FloppySetFileInfo
dd fs_FloppyExecute dd fs_FloppyExecute
dd fs_FloppyDelete
fs_NumFloppyServices = ($ - fs_FloppyServices)/4 fs_NumFloppyServices = ($ - fs_FloppyServices)/4
fs_OnHd0: fs_OnHd0:
@ -452,6 +453,7 @@ fs_HdServices:
dd fs_HdGetFileInfo dd fs_HdGetFileInfo
dd fs_HdSetFileInfo dd fs_HdSetFileInfo
dd fs_HdExecute dd fs_HdExecute
dd fs_HdDelete
fs_NumHdServices = ($ - fs_HdServices)/4 fs_NumHdServices = ($ - fs_HdServices)/4
;******************************************************* ;*******************************************************