Index: kernel/trunk/docs/sysfuncs.txt =================================================================== --- kernel/trunk/docs/sysfuncs.txt (revision 4049) +++ kernel/trunk/docs/sysfuncs.txt (working copy) @@ -1566,28 +1566,28 @@ Remarks: * The function is supported only for ATAPI devices (CD and DVD). * An example of usage of the function is the application CD_tray. - -====================================================================== -======= Function 25 - put image area on the background layer. ======== -====================================================================== -Paramters: - * eax = 25 - function number - * ebx = pointer to the previously allocated memory area, - where placed the source images in a format BBGGRRTTBBGGRRTT... - * ecx = [size on axis x]*65536 + [size on axis y] - * edx = [coordinate on axis x]*65536 + [coordinate on axis y] -Returned value: - * function does not return value -Remarks: - * Coordinates of the image are coordinates of the upper left corner - of the image relative to the screen. - * Size of the image in bytes is 4*xsize*ysize - * TT - byte pointer of transparency, at current version: - 1 to FF - opaque, 0 - transparent. - * The function places the image directly to LFB. It is not for - background image f.15. Options f.15 to f.25 does not make sense. ====================================================================== +======= Function 25 - put image area on the background layer. ======== +====================================================================== +Paramters: + * eax = 25 - function number + * ebx = pointer to the previously allocated memory area, + where placed the source images in a format BBGGRRTTBBGGRRTT... + * ecx = [size on axis x]*65536 + [size on axis y] + * edx = [coordinate on axis x]*65536 + [coordinate on axis y] +Returned value: + * function does not return value +Remarks: + * Coordinates of the image are coordinates of the upper left corner + of the image relative to the screen. + * Size of the image in bytes is 4*xsize*ysize + * TT - byte pointer of transparency, at current version: + 1 to FF - opaque, 0 - transparent. + * The function places the image directly to LFB. It is not for + background image f.15. Options f.15 to f.25 does not make sense. + +====================================================================== ======== Function 26, subfunction 1 - get MPU MIDI base port. ======== ====================================================================== Parameters: @@ -3953,7 +3953,7 @@ * +0: dword: 2 = subfunction number * +4: dword: 0 (reserved) * +8: dword: 0 (reserved) - * +12 = +0xC: dword: number of bytes to read + * +12 = +0xC: dword: number of bytes to write * +16 = +0x10: dword: pointer to data * +20 = +0x14: ASCIIZ-name of file, the rules of names forming are given in the general description Index: kernel/trunk/fs/ext2/ext2.asm =================================================================== --- kernel/trunk/fs/ext2/ext2.asm (revision 4049) +++ kernel/trunk/fs/ext2/ext2.asm (working copy) @@ -8,9 +8,9 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; include 'ext2.inc' -include 'blocks.asm' -include 'inode.asm' -include 'resource.asm' +include 'blocks.inc' +include 'inode.inc' +include 'resource.inc' iglobal align 4 @@ -197,6 +197,11 @@ test eax, eax jnz .error + ;call ext2_sb_update + ; Sync the disk. + ;mov esi, [ebp + PARTITION.Disk] + ;call disk_sync ; eax contains error code, if any. + mov eax, ebp ; Return pointer to EXTFS. pop edi esi ebp ebx ret @@ -811,6 +816,13 @@ ; Output: eax = error code. ;--------------------------------------------------------------------- ext2_SetFileInfo: + test [ebp + EXTFS.partition_flags], EXT2_RO + jz @F + + mov eax, ERROR_UNSUPPORTED_FS + ret + + @@: push edx esi edi ebx call ext2_lock mov edx, [ebx + 16] @@ -888,6 +900,13 @@ ; Output: eax = error code. ;--------------------------------------------------------------------- ext2_Delete: + test [ebp + EXTFS.partition_flags], EXT2_RO + jz @F + + mov eax, ERROR_UNSUPPORTED_FS + ret + + @@: push ebx ecx edx esi edi call ext2_lock @@ -1071,12 +1090,19 @@ ; Output: eax = error code. ;--------------------------------------------------------------------- ext2_CreateFolder: + test [ebp + EXTFS.partition_flags], EXT2_RO + jz @F + + mov eax, ERROR_UNSUPPORTED_FS + ret + + @@: push ebx ecx edx esi edi call ext2_lock add esi, [esp + 20 + 4] - ; Can't create root, but for CreateFile already existing directory is success. + ; Can't create root, but for CreateFolder already existing directory is success. cmp byte [esi], 0 jz .success @@ -1210,12 +1236,462 @@ mov eax, ERROR_DISK_FULL jmp .return -self_link: db ".", 0 -parent_link: db "..", 0 +self_link db ".", 0 +parent_link db "..", 0 +;--------------------------------------------------------------------- +; Rewrite a file. +; Input: esi + [esp + 4] = file name. +; ebx = pointer to paramteres from sysfunc 70. +; ebp = pointer to EXTFS structure. +; Output: eax = error code. +; ebx = bytes written. +;--------------------------------------------------------------------- ext2_Rewrite: + test [ebp + EXTFS.partition_flags], EXT2_RO + jz @F + + mov eax, ERROR_UNSUPPORTED_FS + ret + + @@: + push ecx edx esi edi + pushad + + call ext2_lock + + add esi, [esp + 16 + 32 + 4] + ; Can't create root. + cmp byte [esi], 0 + jz .error_access_denied + + push esi + stdcall ext2_inode_find, 0 + pop esi + + ; If the file is there, delete it. + test eax, eax + jnz @F + + pushad + + push eax + call ext2_unlock + pop eax + + push dword 0x00000000 + call ext2_Delete + add esp, 4 + + push eax + call ext2_lock + pop eax + + test eax, eax + jnz .error_access_denied_delete + + popad + + @@: + ; Find parent. + call ext2_inode_find_parent + test eax, eax + jnz .error_access_denied + + ; Inode ID for preference. + mov eax, esi + call ext2_inode_alloc + test eax, eax + jnz .error_full + + ; Save allocated inode in EDX; filename is in EDI; parent ID in ESI. + mov edx, ebx + + push edi + + xor al, al + mov edi, [ebp + EXTFS.ext2_temp_inode] + mov ecx, [ebp + EXTFS.inode_size] + rep stosb + + mov edi, [ebp + EXTFS.ext2_temp_inode] + add edi, EXT2_INODE_STRUC.i_atime + call current_unix_time + + add edi, 8 + call current_unix_time + + pop edi + + mov ebx, [ebp + EXTFS.ext2_temp_inode] + mov [ebx + EXT2_INODE_STRUC.i_mode], EXT2_S_IFREG + mov eax, edx + call ext2_inode_write + test eax, eax + jnz .error + + ; Link parent to child. + mov eax, esi + mov ebx, edx + mov esi, edi + mov dl, EXT2_FT_REG_FILE + call ext2_inode_link + test eax, eax + jnz .error + + popad + push eax + call ext2_unlock + pop eax + + push dword 0x00000000 + call ext2_Write + add esp, 4 + + push eax + call ext2_lock + pop eax + + .success: + push eax + call ext2_sb_update + + ; Sync the disk. + mov esi, [ebp + PARTITION.Disk] + call disk_sync ; eax contains error code, if any. + pop eax + + .return: + push eax + call ext2_unlock + pop eax + + pop edi esi edx ecx + ret + + .error: + mov eax, ERROR_ACCESS_DENIED + jmp .success + + .error_access_denied_delete: + popad + + .error_access_denied: + popad + xor ebx, ebx + + mov eax, ERROR_ACCESS_DENIED + jmp .return + + .error_full: + popad + xor ebx, ebx + + mov eax, ERROR_DISK_FULL + jmp .return + +;--------------------------------------------------------------------- +; Write to a file. +; Input: esi + [esp + 4] = file name. +; ebx = pointer to paramteres from sysfunc 70. +; ebp = pointer to EXTFS structure. +; Output: eax = error code. +; ebx = number of bytes written. +;--------------------------------------------------------------------- ext2_Write: + test [ebp + EXTFS.partition_flags], EXT2_RO + jz @F + + mov eax, ERROR_UNSUPPORTED_FS + ret + + @@: + push ecx edx esi edi + call ext2_lock + + add esi, [esp + 16 + 4] + + ; Can't write to root. + cmp byte [esi], 0 + jz .error + + push ebx ecx edx + stdcall ext2_inode_find, 0 + pop edx ecx ebx + ; If file not there, error. + xor ecx, ecx + test eax, eax + jnz .error_file_not_found + + ; Save the inode. + push esi + + ; Check if it's a file. + mov edx, [ebp + EXTFS.ext2_save_inode] + cmp [edx + EXT2_INODE_STRUC.i_mode], EXT2_S_IFREG + jne .error + + mov eax, esi + mov ecx, [ebx + 4] + + call ext2_inode_extend + xor ecx, ecx + test eax, eax + jnz .error_device + + ; ECX contains the size to write, and ESI points to it. + mov ecx, [ebx + 0x0C] + mov esi, [ebx + 0x10] + + ; Save the size of the inode. + mov eax, [edx + EXT2_INODE_STRUC.i_size] + push eax + + xor edx, edx + div [ebp + EXTFS.block_size] + + test edx, edx + jz .start_aligned + + ; Start isn't aligned, so deal with the non-aligned bytes. + mov ebx, [ebp + EXTFS.block_size] + sub ebx, edx + + cmp ebx, ecx + jbe @F + + ; If the size to copy fits in current block, limit to that, instead of the entire block. + mov ebx, ecx + + @@: + DEBUGF 1, "STARTING\n" + ; Copy EBX bytes, in EAX indexed block. + push eax + call ext2_inode_read_entry + test eax, eax + pop eax + jnz .error_inode_size + + push ecx + + mov ecx, ebx + mov edi, ebx + add edi, edx + rep movsb + + pop ecx + + ; Write the block. + call ext2_inode_write_entry + test eax, eax + jnz .error_inode_size + + add [esp], ebx + sub ecx, ebx + jz .write_inode + + .start_aligned: + cmp ecx, [ebp + EXTFS.block_size] + jb @F + + mov eax, [esp] + xor edx, edx + div [ebp + EXTFS.block_size] + + push eax + mov edx, [esp + 8] + call ext2_inode_blank_entry + test eax, eax + pop eax + jnz .error_inode_size + + push ecx + + mov ecx, [ebp + EXTFS.block_size] + mov edi, [ebp + EXTFS.ext2_save_block] + rep movsb + + pop ecx + + call ext2_inode_write_entry + test eax, eax + jnz .error_inode_size + + mov eax, [ebp + EXTFS.block_size] + sub ecx, eax + add [esp], eax + jmp .start_aligned + + ; Handle the remaining bytes. + @@: + DEBUGF 1, "REMAINING\n" + test ecx, ecx + jz .write_inode + + mov eax, [esp] + xor edx, edx + div [ebp + EXTFS.block_size] + + push eax + call ext2_inode_read_entry + test eax, eax + pop eax + jz @F + + push eax + mov edx, [esp + 8] + + call ext2_inode_blank_entry + test eax, eax + pop eax + jnz .error_inode_size + + @@: + push ecx + mov edi, [ebp + EXTFS.ext2_save_block] + rep movsb + pop ecx + + call ext2_inode_write_entry + test eax, eax + jnz .error_inode_size + + add [esp], ecx + xor ecx, ecx + + .write_inode: + mov ebx, [ebp + EXTFS.ext2_temp_inode] + pop eax + mov [ebx + EXT2_INODE_STRUC.i_size], eax + mov eax, [esp] + + call ext2_inode_write + + test eax, eax + jnz .error_device + + .success: + call ext2_sb_update + + ; Sync the disk. + mov esi, [ebp + PARTITION.Disk] + call disk_sync ; eax contains error code, if any. + + .return: + push eax + call ext2_unlock + pop eax + + add esp, 4 + + mov ebx, [esp + 12] + sub ebx, ecx + pop edi esi edx ecx + ret + + .error: + mov eax, ERROR_ACCESS_DENIED + jmp .return + + .error_file_not_found: + mov eax, ERROR_FILE_NOT_FOUND + jmp .return + + .error_inode_size: + mov ebx, [ebp + EXTFS.ext2_temp_inode] + pop eax + mov [ebx + EXT2_INODE_STRUC.i_size], eax + mov eax, [esp] + + call ext2_inode_write + + .error_device: + call ext2_sb_update + + ; Sync the disk. + mov esi, [ebp + PARTITION.Disk] + call disk_sync ; eax contains error code, if any. + + mov eax, ERROR_DEVICE + jmp .return + +;--------------------------------------------------------------------- +; Set the end of a file. +; Input: esi + [esp + 4] = file name. +; ebx = pointer to paramteres from sysfunc 70. +; ebp = pointer to EXTFS structure. +; Output: eax = error code. +;--------------------------------------------------------------------- ext2_SetFileEnd: - xor ebx, ebx + test [ebp + EXTFS.partition_flags], EXT2_RO + jz @F + mov eax, ERROR_UNSUPPORTED_FS ret + + @@: + push ebx ecx edx esi edi + call ext2_lock + + add esi, [esp + 20 + 4] + + ; Can't write to root. + cmp byte [esi], 0 + jz .error + + stdcall ext2_inode_find, 0 + ; If file not there, error. + test eax, eax + jnz .error_file_not_found + + ; Check if it's a file. + mov edx, [ebp + EXTFS.ext2_save_inode] + cmp [edx + EXT2_INODE_STRUC.i_mode], EXT2_S_IFREG + jne .error + + mov eax, esi + mov ecx, [ebx + 4] + call ext2_inode_extend + test eax, eax + jnz .error_disk_full + + mov eax, esi + call ext2_inode_truncate + test eax, eax + jnz .error_disk_full + + mov eax, esi + mov ebx, [ebp + EXTFS.ext2_temp_inode] + call ext2_inode_write + + call ext2_sb_update + + ; Sync the disk. + mov esi, [ebp + PARTITION.Disk] + call disk_sync ; eax contains error code, if any. + + .return: + push eax + call ext2_unlock + pop eax + + pop edi esi edx ecx ebx + ret + + .error: + mov eax, ERROR_ACCESS_DENIED + jmp .return + + .error_file_not_found: + mov eax, ERROR_FILE_NOT_FOUND + jmp .return + + .error_disk_full: + call ext2_sb_update + + ; Sync the disk. + mov esi, [ebp + PARTITION.Disk] + call disk_sync ; eax contains error code, if any. + + mov eax, ERROR_DISK_FULL + jmp .return Index: kernel/trunk/fs/ext2/ext2.inc =================================================================== --- kernel/trunk/fs/ext2/ext2.inc (revision 4049) +++ kernel/trunk/fs/ext2/ext2.inc (working copy) @@ -7,6 +7,13 @@ ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Future jobs for driver, in order of preference: +; * clean up existing extents support. +; * add b-tree directories support. +; * add long file support. +; * add journal support. +; * add minor features that come with ext3/4. + ; Recommended move to some kernel-wide bitmap handling code (with a bit of abstraction, of course). ;---------------------------------------------------------------------