salloc.c (sector allocator)
Posted: Mon Feb 29, 2016 1:26 pm
salloc.c (sector allocator) is a static sector buffer allocator cache for small systems.
salloc expects two parameters - a DWORD LBA sector number and a DWORD flag called clear.
salloc returns a void* to a 512 byte buffer which contains the contents of the file system LBA
sector. This buffer is assigned to the LBA requested.
If the clear flag is set, a buffer of zero's is returned. This buffer is assigned to the LBA
requested and marked dirty. This feature is used FAT32 when a directory needs to be extended
with an additional cluster cleared to zero's.
The header of the headerless buffers (the header is not attached to the buffer as in malloc)
contains pointers for 2 double linked lists, the LBA, the buffer address, a dirty flag and a locked flag.
All buffers are statically linked to a Least Recently Used list and are double linked to a LBA array
of pointers.
To find an LBA the modulus (sizeof (the array)) is used to index the array. Buffer headers are double
linked to this list as the buffers are allocated. Each allocated buffer is moved to the MRU end of the
list and also to the beginning of it's LBA array list. Unlike the usual buffer cache systems only a
pointer to the buffer is returned (there is no back and forth copying).
scommit expects a single parameter - a void* which was returned by salloc and marks the buffer
header as dirty.
sreserve expects a single parameter - a void* which was returned by salloc and marks the buffer
header as locked. Locked buffers are skipped in the selection of LRU to maintain important buffers
in memory.
srelease expects a single parameter - a void* which was returned by salloc and marks the buffer
header as unlocked.
sflush expects a single parameter - a void* which was returned by salloc and writes the buffer if
marked dirty to the drive. If the parameter is 0, all buffers marked dirty will be written.
Invalid buffer pointers are merely ignored when committing, reserving, releasing and flushing.
sverify expects a single parameter - a void* which was returned by salloc. This is an internal routine
with verifies the buffer address with range checking. It calculates the associated buffer header
pointer, so there is no lookup required as with the usual buffer cache systems.
A read_write_sectors (and memset) must be provided.
salloc expects two parameters - a DWORD LBA sector number and a DWORD flag called clear.
salloc returns a void* to a 512 byte buffer which contains the contents of the file system LBA
sector. This buffer is assigned to the LBA requested.
If the clear flag is set, a buffer of zero's is returned. This buffer is assigned to the LBA
requested and marked dirty. This feature is used FAT32 when a directory needs to be extended
with an additional cluster cleared to zero's.
The header of the headerless buffers (the header is not attached to the buffer as in malloc)
contains pointers for 2 double linked lists, the LBA, the buffer address, a dirty flag and a locked flag.
All buffers are statically linked to a Least Recently Used list and are double linked to a LBA array
of pointers.
To find an LBA the modulus (sizeof (the array)) is used to index the array. Buffer headers are double
linked to this list as the buffers are allocated. Each allocated buffer is moved to the MRU end of the
list and also to the beginning of it's LBA array list. Unlike the usual buffer cache systems only a
pointer to the buffer is returned (there is no back and forth copying).
scommit expects a single parameter - a void* which was returned by salloc and marks the buffer
header as dirty.
sreserve expects a single parameter - a void* which was returned by salloc and marks the buffer
header as locked. Locked buffers are skipped in the selection of LRU to maintain important buffers
in memory.
srelease expects a single parameter - a void* which was returned by salloc and marks the buffer
header as unlocked.
sflush expects a single parameter - a void* which was returned by salloc and writes the buffer if
marked dirty to the drive. If the parameter is 0, all buffers marked dirty will be written.
Invalid buffer pointers are merely ignored when committing, reserving, releasing and flushing.
sverify expects a single parameter - a void* which was returned by salloc. This is an internal routine
with verifies the buffer address with range checking. It calculates the associated buffer header
pointer, so there is no lookup required as with the usual buffer cache systems.
A read_write_sectors (and memset) must be provided.