X-Git-Url: https://git.wirehaze.ovh/BOS.git/blobdiff_plain/c3be929643a2fbce4210ef509cd1b8815c21c000..5e144deaab35e84b572c5374dcda25490dd5c737:/kernel/fat12/fat12.asm?ds=inline diff --git a/kernel/fat12/fat12.asm b/kernel/fat12/fat12.asm index a961782..832df8f 100644 --- a/kernel/fat12/fat12.asm +++ b/kernel/fat12/fat12.asm @@ -7,23 +7,56 @@ ;----------------------------------------------------------; ;---------------------------------------------; - ; main FAT12 info structure ; + ; FAT12 calltable and structure pointer ; ;---------------------------------------------; - struc fat12 + FAT12: + .data_pointer dd 0 ; internal driver data + .FSname db 'FAT12' ; 5 char filesystem name + .init dd init_fat12 ; pointer to init + .deinit dd 0 ; remove driver + .format dd 0 ; format drive + .mount dd 0 ; mount drive + .unmount dd 0 ; unmount drive + .find dd 0 ; find file + .findnext dd 0 ; get next match + .open dd 0 ; open file, get handle + .close dd 0 ; close file from handle + .attrib dd 0 ; get/set attrib. and time + .read dd 0 ; read file from handle + .write dd 0 ; write file from handle + .seek dd 0 ; seek from handle + .rename dd 0 ; rename file + .remove dd 0 ; remove file/dir + .create dd 0 ; create file/dir + .ioctl dd 0 ; extra calls if exists + + ;---------------------------------------------; + ; FAT12 main info structure ; + ;---------------------------------------------; + struc fat12_data { - .disk_number db 0 ; which VFS disk number - .root_dir dw 0 ; position of rootdir - .fat_1 dd 0 ; position of fat1 - .fat_2 dd 0 ; position of fat2 - .data_area dw 0 ; position of dataarea - .disk_size dd 0 ; total storage size - .free_space dd 0 ; free space available - .boot bootsector + .disk_number db 0 ; which VFS disk number + .root_dir dw 0 ; position of rootdir + .disk_size dd 0 ; total storage size + .free_space dd 0 ; free space available + .fat_1 dd 0 ; position of fat1 + .fat_2 dd 0 ; position of fat2 + .data_area dw 0 ; position of dataarea + .boot: times sizeof.bootsector db 0 ; copy of FAT12 bootsector .dir_entries: - times 16 * sizeof.dir_entry db 0 ; 512b dir entry buffer - .fat_buffer: times 512 db 0 ; 512b FAT cluster info buffer + times 16 * sizeof.dir_entry db 0 ; 512b dir entry buffer + .fat_buffer: times 512 db 0 ; 512b FAT cluster info buffer + .foundfile: + times 1 * sizeof.search db 0 ; "DTA" like structure + .filehandles: ; "System File Table" + times 32 * sizeof.filehandle db 0 ; for now, max opened files is 32 } + virtual at 0 ; could use "at esi" instead + fat12_data fat12_data + sizeof.fat12_data = $-$$ + end virtual + ;---------------------------------------------; ; FAT12 bootsector structure ; ;---------------------------------------------; @@ -53,10 +86,15 @@ .boot_signature db 0,0 ; 0x55,0xAA } + virtual at 0 + bootsector bootsector + sizeof.bootsector = $-$$ + end virtual + ;---------------------------------------------; ; FAT12 directory entry structure ; ;---------------------------------------------; - struct dir_entry + struc dir_entry { .filename db 0,0,0,0,0,0,0,0 .extension db 0,0,0 @@ -68,10 +106,15 @@ .filesize dd 0 } + virtual at 0 + dir_entry dir_entry + sizeof.dir_entry = $-$$ + end virtual + ;---------------------------------------------; ; FAT12 directory entry for LFN ; ;---------------------------------------------; - struct lnf_entry + struc lfn_entry { .order db 0 ; LFN entry in sequence, never 0x00 or 0xE5. .namefirst dw 0,0,0,0,0 ; 5 first unicode (2byte) chars @@ -85,22 +128,55 @@ virtual at 0 lfn_entry lfn_entry - sizeof.lfn_entry = $ + sizeof.lfn_entry = $-$$ end virtual - virtual at 0 - dir_entry dir_entry - sizeof.dir_entry = $ - end virtual + ;---------------------------------------------; + ; FAT12 file search/DTA structure ; + ;---------------------------------------------; + struc search + { + .searchname: + times 255 db 0 ; file search pattern. + .attribute db 0 ; search attribute. + .direntry dw 0 ; directory entry number, 0 based + .dircluster dw 0 ; starting cluster of dir, 0 root + .foundattrib db 0 ; attribute of matching file + .foundtime dw 0 ; file time + .founddate dw 0 ; file date + .foundsize dw 0 ; file size + } virtual at 0 - bootsector bootsector - sizeof.bootsector = $ + search search + sizeof.search = $-$$ end virtual + ;---------------------------------------------; + ; FAT12 file-handle structure ; + ;---------------------------------------------; + struc filehandle + { + .handles db 0 ; reference count or or zero for unused + .mode db 0 ; open mode. 0=read, 1=write, 2=r/w. + .lfn_entry dw 0 ; file LFN directory entry position + .direntry dw 0 ; file directory entry position + .cluster dw 0 ; file first cluster + .attribute db 0 ; file attributes + .filetime dw 0 ; last modified time + .filedate dw 0 ; last modified date + .filesize dd 0 ; filesize + .position dd 0 ; R/W position in file + .clusterpos dw 0 ; cluster number of last cluster read + .shortname: + times 11 db 0 ; short name + .fullname: + times 255 db 0 ; the full LFN + } + virtual at 0 - disk disk - sizeof.disk = $ + filehandle filehandle + sizeof.filehandle = $-$$ end virtual ;------------------------------------------; @@ -135,16 +211,6 @@ attribute_lfn = 0x0F ; attrb. byte value for LFN dir entry - - - -fd0: fat12 ; define fd0 data.. tmp example. - -; TODO, alloc memory for struct and keep pointer only. -; --------------- -;drive dd 0 -;mov edi, drive+fat12into.boot - ;--------------------------------------------------------------; ; init_fat12 - detect if drive fs is fat12 and init ; ;--------------------------------------------------------------; @@ -191,7 +257,10 @@ calc_lfn_chksum: mov cx, 11 xor ax, ax ; return value start with null .l1: - add ax, byte [esi] ; add next char to sum + push cx + movzx cx, byte [esi] ; add next char to sum + add ax, cx + pop cx shr ax, 1 ; shift sum right by 1 inc esi ; prepare for next character loop .l1