cbmimage
Loading...
Searching...
No Matches
BAM processing functions

Classes

struct  cbmimage_i_bam_selector_s
 BAM Selector . More...
 
struct  cbmimage_fileimage_functions_s
 BAM counter selector . More...
 

Typedefs

typedef enum cbmimage_BAM_state_e cbmimage_BAM_state
 state of the BAM
 
typedef struct cbmimage_i_bam_selector_s cbmimage_i_bam_selector
 BAM Selector .
 
typedef cbmimage_i_bam_selector cbmimage_i_bam_counter_selector
 BAM counter selector .
 
typedef struct cbmimage_fileimage_functions_s cbmimage_fileimage_functions
 BAM counter selector .
 

Enumerations

enum  cbmimage_BAM_state_e {
  BAM_UNKNOWN , BAM_REALLY_FREE , BAM_FREE , BAM_USED ,
  BAM_DOES_NOT_EXIST
}
 state of the BAM More...
 

Functions

static uint8_t reverse_bit_order (uint8_t input)
 
static int cbmimage_i_countbits (bam_mask_t value)
 
void cbmimage_i_init_bam_selector (cbmimage_image_settings *settings, cbmimage_i_bam_selector *selector, size_t selector_count)
 
static int cbmimage_i_get_right_selector (cbmimage_image_settings *settings, cbmimage_i_bam_selector *selector, size_t selector_count, uint8_t track)
 
static void cbmimage_i_bam_print (bam_mask_t mask)
 
static int cbmimage_i_check_max_bam_of_track (cbmimage_image_settings *settings, uint16_t track, bam_mask_t mask)
 
static int cbmimage_i_get_bam_of_track (cbmimage_image_settings *settings, uint8_t track, bam_mask_t *mask)
 
static uint16_t cbmimage_i_get_bam_counter_of_track (cbmimage_image_settings *settings, uint8_t track)
 
int cbmimage_i_bam_check_really_unused (cbmimage_image_settings *settings, cbmimage_blockaddress block)
 
cbmimage_BAM_state cbmimage_bam_get (cbmimage_fileimage *image, cbmimage_blockaddress block)
 get the unused/used state of a block in the BAM
 
int cbmimage_bam_check_consistency (cbmimage_fileimage *image)
 check the consistency of a BAM
 
int cbmimage_get_blocks_free (cbmimage_fileimage *image)
 get the count of blocks free
 
int cbmimage_bam_get_free_on_track (cbmimage_fileimage *image, uint8_t track)
 get the blocks free on a specific track
 

Detailed Description

Typedef Documentation

◆ cbmimage_fileimage_functions

BAM counter selector .

this type contains helper functions that perform image format specific operations on an image type

◆ cbmimage_i_bam_counter_selector

BAM counter selector .

A bam_counter selector is almost the same as a BAM selector. Instead of pointing to the bit map of the BAM, though, it points to the location where the number of free blocks on the track is located.

In most cases, these are located directly before the bitmap, so the BAM selector could be used. However, in the case of the 2nd side of a D71 image, this is not true; that's why this own type of selector is needed here.

Remarks

◆ cbmimage_i_bam_selector

BAM Selector .

This type describes where the BAM entries (that is, the bitmap part of the BAM) are located on disk. This way, the code that handles BAM entries is generic, and only the initialization of the BAM selector has to be image specific.

In case the BAM is stored in multiple blocks (or in the same block, but at different locations), an array of BAM selectors has to be used, with every selector describing one location of the BAM entries

Remarks

Enumeration Type Documentation

◆ cbmimage_BAM_state_e

state of the BAM

Enumerator
BAM_UNKNOWN 

BAM state of block is unknown.

BAM_REALLY_FREE 

BAM state of block is "free", and the block does not contain any data.

BAM_FREE 

BAM state of block is "free", but the block contains some data.

BAM_USED 

BAM state of block is "used".

BAM_DOES_NOT_EXIST 

the block does not exist

Function Documentation

◆ cbmimage_bam_check_consistency()

int cbmimage_bam_check_consistency ( cbmimage_fileimage * image)

check the consistency of a BAM

Parameters
[in]imagepointer to the image data
Returns
  • 0 if the BAM is consistent
  • != 0 if not
Remarks
A BAM is consistent if the following applies:
  • no track has free blocks for sectors that do not exist
  • the free block count of a track is the same as the number of free sectors
    (i.e., the number fits the bitmap)
Todo
How should details be given to the caller?

◆ cbmimage_bam_get()

cbmimage_BAM_state cbmimage_bam_get ( cbmimage_fileimage * image,
cbmimage_blockaddress block )

get the unused/used state of a block in the BAM

Parameters
[in]imagepointer to the image data
[in]blockthe address of the block to check
Returns
  • the BAM state (BAM_REALLY_FREE, BAM_USED, BAM_FREE).
Remarks
  • If the block does not exist, the result is unspecified. Thus, be careful that you provide a valid track.
Todo
: optimize. Getting the whole track just to extract one byte is a little bit of overhead. This can be optimized

◆ cbmimage_bam_get_free_on_track()

int cbmimage_bam_get_free_on_track ( cbmimage_fileimage * image,
uint8_t track )

get the blocks free on a specific track

Parameters
[in]imagepointer to the image data
[in]trackthe track number for which the number of tracks is requested
Returns
count of free blocks on this track

◆ cbmimage_get_blocks_free()

int cbmimage_get_blocks_free ( cbmimage_fileimage * image)

get the count of blocks free

Parameters
[in]imagepointer to the image data
Returns
count of free blocks on this image

◆ cbmimage_i_bam_check_really_unused()

int cbmimage_i_bam_check_really_unused ( cbmimage_image_settings * settings,
cbmimage_blockaddress block )

check if a block is really unused, that is, it's value is the same as after formatting

Parameters
[in]settingspointer to the image data internal settings
[in]blockthe address of the block to check
Returns
  • 0 if the block is used
  • != 0 otherwise
Remarks
  • If the block does not exist, the result is unspecified. Thus, be careful that you provide a valid track.
  • It is tested if the block is all "0" (0x00, 0x00, 0x00, ..., 0x00) OR if it is all but the first value "1" (0x??, 0x01, 0x01, ..., 0x01) The second scheme is used in the 1541 for no apparant reason. The 0x?? is often 0x4B (the result of the GCR conversion), but not on the first track!

◆ cbmimage_i_bam_print()

static void cbmimage_i_bam_print ( bam_mask_t mask)
static

output a BAM bitmap

Parameters
[in]maskthe BAM map to output

◆ cbmimage_i_check_max_bam_of_track()

static int cbmimage_i_check_max_bam_of_track ( cbmimage_image_settings * settings,
uint16_t track,
bam_mask_t mask )
static

check the BAM bitmap of a specific track

Parameters
[in]settingspointer to the image data internal settings
[in]trackthe track for which to find the BAM bitmap
[in]maskthe BAM map to check
Returns
  • 0 on success
  • -1 on error
Remarks
The BAM bitmap is invalid if
  • the track does not exist, or
  • sectors that do not exist are marked are available

◆ cbmimage_i_countbits()

static int cbmimage_i_countbits ( bam_mask_t value)
static

count the number of "1" bits

Parameters
[in]valuevalues of which to count the number of "1" bits
Returns
The number of "1" bits in value
Remarks
  • An extremly simple algorithm is used, just counting the bits in a loop.

◆ cbmimage_i_get_bam_counter_of_track()

static uint16_t cbmimage_i_get_bam_counter_of_track ( cbmimage_image_settings * settings,
uint8_t track )
static

get the BAM counter of a specific track

Parameters
[in]settingspointer to the image data internal settings
[in]trackthe track for which to find the BAM map
Returns
  • the number of free blocks on this track according to the BAM
Remarks
  • If an error occurs (track does not exist), the return value is 0. Note that this cannot be distinguished from an empty BAM map, so be careful that you provide a valid track.

◆ cbmimage_i_get_bam_of_track()

static int cbmimage_i_get_bam_of_track ( cbmimage_image_settings * settings,
uint8_t track,
bam_mask_t * mask )
static

get the BAM bitmap of a specific track

Parameters
[in]settingspointer to the image data internal settings
[in]trackthe track for which to find the BAM bitmap
[in,out]maskpointer to a bam_mask_t that will contain the BAM map on exit
Returns
  • 0 on success
  • -1 on error

◆ cbmimage_i_get_right_selector()

static int cbmimage_i_get_right_selector ( cbmimage_image_settings * settings,
cbmimage_i_bam_selector * selector,
size_t selector_count,
uint8_t track )
static

get the BAM selector that matches a specific track

Parameters
[in]settingspointer to the image data internal settings
[in]selectorarray of the selectors
[in]selector_countnumber of elements in the selector array
[in]trackthe track for which to find the BAM selector
Returns
  • The index of the selector to which the track belongs
  • If an error occurs (track does not exist), the return value is -1

◆ cbmimage_i_init_bam_selector()

void cbmimage_i_init_bam_selector ( cbmimage_image_settings * settings,
cbmimage_i_bam_selector * selector,
size_t selector_count )

init a BAM selector

Parameters
[in]settingspointer to the image data internal settings
[in,out]selectorarray of the selectors to initialize
[in]selector_countnumber of elements in the selector array
Remarks
  • The LBA part of the block address is initialized from the T/S values
  • The buffer pointer is set to the right location inside of the image

◆ reverse_bit_order()

static uint8_t reverse_bit_order ( uint8_t input)
static

reverse the bit order in the byte

Parameters
[in]inputbyte value of which the bit order should be reversed
Returns
the byte value with the reversed bits
Remarks
  • An extremly simple algorithm is used, just shifting out a bit from the input and shifting it in into the output in reverse order.
Todo
reversing can be optimized, for example by using a lookup table