flat assembler
Message board for the users of flat assembler.

Index > OS Construction > fatLX - low level FAT file system driver

Author
Thread Post new topic Reply to topic
Mike Gonta



Joined: 26 Dec 2010
Posts: 243
Mike Gonta 18 Mar 2012, 19:48
fatLX - low level FAT file system driver
LX is the Roman numeral (which as a number system is pretty much only used for Super Bowl) for 60
and fat32 + fat16 + fat12 adds up to 60.
For simplicity, the code assumes an unpartitioned USB flash drive with the Volume Boot Record in the first
physical sector and sector size 512 bytes. The code is PM32 and uses the HLL fasmx macros.
The DRIVE_INFO struct currently 3k in size, contains variables and data used in the process.
The high level file sytem routines such as read, write, delete, rename, etc. will first setup drive_info and call
get_drive_info which will load the boot sector and setup some variables. The other routines will access the
DRIVE_INFO struct.
Code:
proc get_drive_info, drive_info
; load boot sector and setup some variables
proc get_first_directory_entry, drive_info, cluster_number
; load 1st sector of directory in 512 byte buffer in drive_info,
; if cluster_number is 0 use root directory of fat12 or fat16
; return pointer to first directory entry
proc get_next_directory_entry, drive_info
; return pointer to next directory entry, buffering directory as necessary
proc mark_directory, drive_info
; mark directory buffer modified when directory entry changed
proc flush_directory, drive_info
; write directory sector to drive

proc get_fat_entry, drive_info, fat
; load calculated fat sector (3 if fat12) to fat buffer in drive_info
; return cluster number of fat entry
proc put_fat_entry, drive_info, fat, cluster_number
; update fat entry with cluster number
; mark fat buffer as modified
proc flush_fat, drive_info
; write fat sector to drive    
I've started work on the code. Comments, suggestions and participation are welcome.
The code will be released as Public Domain.

_________________
Mike Gonta
look and see - many look but few see

https://mikegonta.com
Post 18 Mar 2012, 19:48
View user's profile Send private message Visit poster's website Reply with quote
Mike Gonta



Joined: 26 Dec 2010
Posts: 243
Mike Gonta 18 Mar 2012, 20:22
Code:
use32
struct DRIVE_INFO
  vbr db 11 dup ?
    vbr.bytes_per_sector dw ?
    vbr.sectors_per_cluster db ?
    vbr.reserved_sector_count dw ?
    vbr.number_of_fats db ?
    vbr.root_directory_entries dw ?
    vbr.sector_count dw ?
      db ?
    vbr.sectors_per_fat dw ?
      dd ?
    hidden_sectors dd ?
    sector_count dd ?
    sectors_per_fat dd ?
      dd ?
    root_directory_cluster_number dd ?
    information_sector_number dw ?
      db 17 dup ?
    volume_id dd ?
    volume_label db 11 dup ?
    file_system db 8 dup ?
      db 2 dup ?
    drive_number dd ?
    start_of_fat dd ?
    start_of_root_directory dd ?
    start_of_data dd ?
      dd ?
      dd 100 dup ?
  information_sector dd 122 dup ?
    free_clusters dd ?
    last_cluster dd ?
      dd 4 dup ?
  fat_buffer dd 512*3/4 dup ?
  directory_buffer dd 512/4 dup ?
ends

proc file_routine, args
locals
  drive_info DRIVE_INFO
endl
  mov [drive_info.drive_number], [drive_number]
  call get_drive_info, addr drive_info
  ret
endp
    

_________________
Mike Gonta
look and see - many look but few see

https://mikegonta.com
Post 18 Mar 2012, 20:22
View user's profile Send private message Visit poster's website Reply with quote
GhostXoPCorp



Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp 20 Mar 2012, 02:18
Really like it, to be honest the system you have here is similar to the one i have. Either a good idea or everyone does this as well. Better idea to put it into macro form. Keep up the good work Smile

_________________
Oh that divide overflow. Just jumps out of the bushes every time to scare the day lights out of me.
Post 20 Mar 2012, 02:18
View user's profile Send private message Reply with quote
Mike Gonta



Joined: 26 Dec 2010
Posts: 243
Mike Gonta 20 Mar 2012, 09:17
GhostXoPCorp wrote:
Better idea to put it into macro form.

fasmx (operating system independent HLL macros) is the macro form.

_________________
Mike Gonta
look and see - many look but few see

https://mikegonta.com
Post 20 Mar 2012, 09:17
View user's profile Send private message Visit poster's website Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 20 Mar 2012, 20:25
Cool, i have had the the same idea, but with something like 'macro basic'
Post 20 Mar 2012, 20:25
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.