cbmimage
Loading...
Searching...
No Matches
cbmimage.h File Reference

cbmimage API and their definitions More...

#include <stddef.h>
#include <stdint.h>
Include dependency graph for cbmimage.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  cbmimage_track_sector_s
 Address on floppy: Track/Sector variant. More...
 
struct  cbmimage_blockaddress_s
 Address on drive. More...
 
struct  cbmimage_dir_header_name_s
 The name of a directory header or directory entry. More...
 
struct  cbmimage_dir_header_s
 A directory header. More...
 
struct  cbmimage_dir_entry_s
 A directory entry. More...
 
struct  cbmimage_fileimage_s
 Type that describes a CBM disk image on which to operate. More...
 
struct  cbmimage_loop_s
 cbmimage loop detector struct More...
 
struct  cbmimage_blockaccessor_s
 cbmimage block accessor data structure More...
 
struct  cbmimage_fat_entry_s
 cbmimage One entry of the FAT structure More...
 
struct  cbmimage_fat_s
 cbmimage FAT structure More...
 
struct  cbmimage_chain_s
 type to describe a chain that is followed More...
 
struct  cbmimage_file_s
 file handling data More...
 

Macros

#define CBMIMAGE_TS_INIT(_track, _sector)
 initializer for a cbmimage_track_sector
 
#define CBMIMAGE_TS_SET(_ts, _track, _sector)
 set a cbmimage_track_sector
 
#define CBMIMAGE_TS_CLEAR(_ts)
 clear a cbmimage_track_sector
 
#define CBMIMAGE_BLOCK_INIT(_track, _sector, _lba)
 initializer for a cbmimage_blockaddress
 
#define CBMIMAGE_BLOCK_INIT_FROM_TS(_track, _sector)
 initializer for a cbmimage_blockaddress
 
#define CBMIMAGE_BLOCK_INIT_FROM_LBA(_lba)
 initializer for a cbmimage_blockaddress
 
#define CBMIMAGE_BLOCK_SET_FROM_TS(_image, _block, _track, _sector)
 initializer for a cbmimage_blockaddress
 
#define CBMIMAGE_BLOCK_SET_FROM_LBA(_image, _block, _lba)
 initializer for a cbmimage_blockaddress
 

Typedefs

typedef enum cbmimage_BAM_state_e cbmimage_BAM_state
 state of the BAM
 
typedef struct cbmimage_track_sector_s cbmimage_track_sector
 Address on floppy: Track/Sector variant.
 
typedef uint16_t cbmimage_lba
 Address on floppy: LBA variant.
 
typedef struct cbmimage_blockaddress_s cbmimage_blockaddress
 Address on drive.
 
typedef enum cbmimage_dir_type_e cbmimage_dir_type
 The type of a directory entry cbmimage_dir_entry_s.
 
typedef enum cbmimage_geos_filetype_e cbmimage_geos_filetype
 The GEOS type of a directory entry cbmimage_dir_entry_s.
 
typedef struct cbmimage_dir_header_name_s cbmimage_dir_header_name
 The name of a directory header or directory entry.
 
typedef struct cbmimage_dir_header_s cbmimage_dir_header
 A directory header.
 
typedef struct cbmimage_dir_entry_s cbmimage_dir_entry
 A directory entry.
 
typedef enum cbmimage_imagetype_e cbmimage_imagetype
 The type of the libcbmimage image.
 
typedef struct cbmimage_fileimage_s cbmimage_fileimage
 Type that describes a CBM disk image on which to operate.
 
typedef struct cbmimage_loop_s cbmimage_loop
 cbmimage loop detector struct
 
typedef struct cbmimage_blockaccessor_s cbmimage_blockaccessor
 cbmimage block accessor data structure
 
typedef struct cbmimage_fat_entry_s cbmimage_fat_entry
 cbmimage One entry of the FAT structure
 
typedef struct cbmimage_fat_s cbmimage_fat
 cbmimage FAT structure
 
typedef struct cbmimage_chain_s cbmimage_chain
 type to describe a chain that is followed
 
typedef struct cbmimage_file_s cbmimage_file
 file handling data
 
typedef void cbmimage_print_function_type(const char *text)
 Type for a print() style callback.
 

Enumerations

enum  cbmimage_BAM_state_e {
  BAM_UNKNOWN , BAM_REALLY_FREE , BAM_FREE , BAM_USED ,
  BAM_DOES_NOT_EXIST
}
 state of the BAM More...
 
enum  cbmimage_dir_type_e {
  DIR_TYPE_DEL = 0 , DIR_TYPE_SEQ = 1 , DIR_TYPE_PRG = 2 , DIR_TYPE_USR = 3 ,
  DIR_TYPE_REL = 4 , DIR_TYPE_PART1581 = 5 , DIR_TYPE_CMD_NATIVE = 6 , DIR_TYPE_PART_OFFSET = 0x100 ,
  DIR_TYPE_PART_NO = DIR_TYPE_PART_OFFSET , DIR_TYPE_PART_CMD_NATIVE = DIR_TYPE_PART_OFFSET + 0x01 , DIR_TYPE_PART_D64 = DIR_TYPE_PART_OFFSET + 0x02 , DIR_TYPE_PART_D71 = DIR_TYPE_PART_OFFSET + 0x03 ,
  DIR_TYPE_PART_D81 = DIR_TYPE_PART_OFFSET + 0x04 , DIR_TYPE_PART_SYSTEM = DIR_TYPE_PART_OFFSET + 0xFF
}
 The type of a directory entry cbmimage_dir_entry_s. More...
 
enum  cbmimage_geos_filetype_e {
  GEOS_FILETYPE_NON_GEOS = 0x00 , GEOS_FILETYPE_BASIC = 0x01 , GEOS_FILETYPE_ASSEMBLER = 0x02 , GEOS_FILETYPE_DATA_FILE = 0x03 ,
  GEOS_FILETYPE_SYSTEM_FILE = 0x04 , GEOS_FILETYPE_DESK_ACCESSORY = 0x05 , GEOS_FILETYPE_APPLICATION = 0x06 , GEOS_FILETYPE_APPLICATION_DATA = 0x07 ,
  GEOS_FILETYPE_FONT_FILE = 0x08 , GEOS_FILETYPE_PRINTER_DRIVER = 0x09 , GEOS_FILETYPE_INPUT_DRIVER = 0x0A , GEOS_FILETYPE_DISK_DRIVER = 0x0B ,
  GEOS_FILETYPE_SYSTEM_BOOT_FILE = 0x0C , GEOS_FILETYPE_TEMPORARY = 0x0D , GEOS_FILETYPE_AUTO_EXECUTE_FILE = 0x0E
}
 The GEOS type of a directory entry cbmimage_dir_entry_s. More...
 
enum  cbmimage_imagetype_e {
  TYPE_UNKNOWN , TYPE_D40 , TYPE_D64 , TYPE_D64_40TRACK ,
  TYPE_D64_40TRACK_SPEEDDOS , TYPE_D64_40TRACK_DOLPHIN , TYPE_D64_40TRACK_PROLOGIC , TYPE_D64_42TRACK ,
  TYPE_D71 , TYPE_D81 , TYPE_D80 , TYPE_D82 ,
  TYPE_CMD_D1M , TYPE_CMD_D2M , TYPE_CMD_D4M , TYPE_CMD_NATIVE ,
  TYPE_LAST
}
 The type of the libcbmimage image. More...
 

Functions

cbmimage_imagetype cbmimage_image_guesstype (const uint8_t *buffer, size_t size, int *extra_errormap)
 
cbmimage_imagetype cbmimage_image_file_guesstype (const char *filename)
 
cbmimage_fileimagecbmimage_image_open (const uint8_t *buffer, size_t size, cbmimage_imagetype)
 open an in-memory CBM image
 
cbmimage_fileimagecbmimage_image_openfile (const char *filename, cbmimage_imagetype)
 open a CBM image from a file
 
void cbmimage_image_readfile (cbmimage_fileimage *, const char *filename)
 read a file and store it in a given CBM image
 
void cbmimage_image_writefile (cbmimage_fileimage *, const char *filename)
 write the CBM image to a file
 
const void * cbmimage_image_get_raw (cbmimage_fileimage *)
 get a pointer to the raw image contents
 
size_t cbmimage_image_get_raw_size (cbmimage_fileimage *)
 get the size of the raw image contents
 
void cbmimage_image_close (cbmimage_fileimage *)
 close a CBM image
 
void cbmimage_image_fat_dump (cbmimage_fileimage *, int linear)
 dump a FAT structure of the image
 
const char * cbmimage_get_imagetype_name (cbmimage_fileimage *)
 get the image type as string
 
const char * cbmimage_get_filename (cbmimage_fileimage *)
 get the file name of the image
 
uint16_t cbmimage_get_max_track (cbmimage_fileimage *)
 get the maximum tracks of the image
 
uint16_t cbmimage_get_max_sectors (cbmimage_fileimage *)
 get the maximum sectors on a track of the image
 
uint16_t cbmimage_get_max_lba (cbmimage_fileimage *)
 get the maximum LBA of the image
 
uint16_t cbmimage_get_bytes_in_block (cbmimage_fileimage *)
 get the number of blocks in a block of the image
 
uint16_t cbmimage_get_sectors_in_track (cbmimage_fileimage *, uint16_t track)
 get the number of sectors on a specific track of the image
 
int cbmimage_blockaddress_ts_exists (cbmimage_fileimage *, uint8_t track, uint8_t sector)
 check if T/S is valid
 
int cbmimage_blockaddress_lba_exists (cbmimage_fileimage *, uint16_t lba)
 check if LBA is valid
 
int cbmimage_blockaddress_init_from_ts (cbmimage_fileimage *, cbmimage_blockaddress *block)
 initialize a block address from its T/S specification
 
int cbmimage_blockaddress_init_from_lba (cbmimage_fileimage *, cbmimage_blockaddress *block)
 initialize a block address from its T/S specification
 
int cbmimage_blockaddress_init_from_ts_value (cbmimage_fileimage *, cbmimage_blockaddress *block, uint8_t track, uint8_t sector)
 initialize a block address when T/S are given
 
int cbmimage_blockaddress_init_from_lba_value (cbmimage_fileimage *, cbmimage_blockaddress *block, uint16_t lba)
 initialize a block address when LBA is given
 
int cbmimage_blockaddress_advance (cbmimage_fileimage *, cbmimage_blockaddress *block)
 advance a block address, going to the next block
 
int cbmimage_blockaddress_advance_in_track (cbmimage_fileimage *, cbmimage_blockaddress *block)
 advance a block address, going to the next block in the same track
 
int cbmimage_blockaddress_add (cbmimage_fileimage *, cbmimage_blockaddress *blockresult, cbmimage_blockaddress block_adder)
 add two block address together
 
int cbmimage_read_block (cbmimage_fileimage *, cbmimage_blockaddress block, void *buffer, size_t buffersize)
 read a block from the image and copy it into the provided buffer
 
int cbmimage_write_block (cbmimage_fileimage *, cbmimage_blockaddress block, void *buffer, size_t buffersize)
 write a block to the image by copying it from the provided buffer
 
int cbmimage_read_next_block (cbmimage_fileimage *, cbmimage_blockaddress *block, void *buffer, size_t buffersize)
 read the next block from the image and copy it into the provided buffer
 
cbmimage_blockaccessorcbmimage_blockaccessor_create (cbmimage_fileimage *image, cbmimage_blockaddress block)
 create a block accessor for a specific block
 
cbmimage_blockaccessorcbmimage_blockaccessor_create_from_ts (cbmimage_fileimage *image, uint8_t track, uint8_t sector)
 create a block accessor for a specific T/S
 
cbmimage_blockaccessorcbmimage_blockaccessor_create_from_lba (cbmimage_fileimage *image, uint16_t lba)
 create a block accessor for a specific LBA
 
void cbmimage_blockaccessor_close (cbmimage_blockaccessor *accessor)
 close a block accessor, freeing its resources
 
int cbmimage_blockaccessor_set_to (cbmimage_blockaccessor *accessor, cbmimage_blockaddress block)
 set a block accessor for a specific block
 
int cbmimage_blockaccessor_set_to_ts (cbmimage_blockaccessor *accessor, uint8_t track, uint8_t sector)
 set a block accessor for a specific T/S
 
int cbmimage_blockaccessor_set_to_lba (cbmimage_blockaccessor *accessor, uint16_t lba)
 set a block accessor for a specific LBA
 
int cbmimage_blockaccessor_advance (cbmimage_blockaccessor *accessor)
 advance a block accessor to the next block
 
int cbmimage_blockaccessor_follow (cbmimage_blockaccessor *accessor)
 follow the block chain of a block accessor to the next block
 
int cbmimage_blockaccessor_get_next_block (cbmimage_blockaccessor *accessor, cbmimage_blockaddress *block_next)
 get the next block of this accessor if we follow the chain
 
int cbmimage_bam_check_consistency (cbmimage_fileimage *)
 check the consistency of a BAM
 
int cbmimage_get_blocks_free (cbmimage_fileimage *)
 get the count of blocks free
 
cbmimage_BAM_state cbmimage_bam_get (cbmimage_fileimage *, cbmimage_blockaddress block)
 get the unused/used state of a block in the BAM
 
int cbmimage_bam_get_free_on_track (cbmimage_fileimage *image, uint8_t track)
 get the blocks free on a specific track
 
cbmimage_dir_headercbmimage_dir_get_header (cbmimage_fileimage *)
 get the header entry
 
void cbmimage_dir_get_header_close (cbmimage_dir_header *)
 free the resources from a cbmimage_dir_get_header()
 
cbmimage_dir_entrycbmimage_dir_get_first (cbmimage_fileimage *)
 get the first (non-empty) directory entry
 
int cbmimage_dir_get_next (cbmimage_dir_entry *)
 get the next (non-empty) directory entry
 
int cbmimage_dir_get_is_valid (cbmimage_dir_entry *)
 get the next (non-empty) directory entry
 
char * cbmimage_dir_extract_name (cbmimage_dir_header_name *, char *name, size_t len)
 extract the name of a directory entry as a C string
 
int cbmimage_dir_is_deleted (cbmimage_dir_entry *)
 check if the directory entry points to a deleted file
 
int cbmimage_dir_chdir (cbmimage_dir_entry *)
 perform a chdir to a partition marked by a directory entry
 
int cbmimage_dir_chdir_close (cbmimage_fileimage *)
 "close a chdir"; that is, go back to the parent directory
 
void cbmimage_dir_get_close (cbmimage_dir_entry *)
 free the resources from a cbmimage_dir_get_first()
 
cbmimage_loopcbmimage_loop_create (cbmimage_fileimage *)
 create a loop detector data structure
 
void cbmimage_loop_close (cbmimage_loop *)
 free a loop detector data structure
 
int cbmimage_loop_mark (cbmimage_loop *, cbmimage_blockaddress block)
 mark a block as used/visited
 
int cbmimage_loop_check (cbmimage_loop *, cbmimage_blockaddress block)
 check if a block is marked as used/visited
 
int cbmimage_validate (cbmimage_fileimage *)
 validate the disk (and the bam)
 
cbmimage_filecbmimage_file_open_by_name (const char *filename)
 open a file on the cbmimage where the name is known
 
cbmimage_filecbmimage_file_open_by_dir_entry (cbmimage_dir_entry *dir_entry)
 open a file on the cbmimage that has already een enumerated
 
void cbmimage_file_close (cbmimage_file *file)
 close a file
 
int cbmimage_file_read_next_block (cbmimage_file *file, uint8_t *buffer, size_t buffer_size)
 read a block from the file
 
int cbmimage_print_set_function (cbmimage_print_function_type print_function)
 set the callback for output from the library
 
cbmimage_fatcbmimage_fat_create (cbmimage_fileimage *image)
 create a FAT structure
 
int cbmimage_fat_set (cbmimage_fat *, cbmimage_blockaddress block, cbmimage_blockaddress target)
 set a block in the FAT to a target in the FAT
 
int cbmimage_fat_clear (cbmimage_fat *, cbmimage_blockaddress block)
 set a block in the FAT to unused
 
cbmimage_blockaddress cbmimage_fat_get (cbmimage_fat *, cbmimage_blockaddress block)
 get the target of a block in the FAT
 
int cbmimage_fat_is_used (cbmimage_fat *, cbmimage_blockaddress block)
 check if a block in the FAT is marked as used
 
void cbmimage_fat_dump (cbmimage_fat *, int linear)
 dump a FAT structure
 
void cbmimage_fat_close (cbmimage_fat *)
 close a FAT structure
 
cbmimage_chaincbmimage_chain_start (cbmimage_fileimage *, cbmimage_blockaddress)
 start the chain processing for a file chain
 
void cbmimage_chain_close (cbmimage_chain *chain)
 close the chain structure
 
int cbmimage_chain_advance (cbmimage_chain *chain)
 advance to the next block of this chain
 
int cbmimage_chain_last_result (cbmimage_chain *chain)
 check if this chain has been processed competely
 
int cbmimage_chain_is_done (cbmimage_chain *chain)
 check if this chain has been processed competely
 
int cbmimage_chain_is_loop (cbmimage_chain *chain)
 check if this chain has fallen into a loop
 
cbmimage_blockaddress cbmimage_chain_get_current (cbmimage_chain *chain)
 get the address of the current block in this chain
 
cbmimage_blockaddress cbmimage_chain_get_next (cbmimage_chain *chain)
 get the address of the next block in this chain
 
uint8_t * cbmimage_chain_get_data (cbmimage_chain *chain)
 get a pointer to the data of the current block in this chain
 

Variables

const cbmimage_blockaddress cbmimage_block_unused
 Definition of an empty cbmimage_blockaddress.
 

Detailed Description

cbmimage API and their definitions


Author
Spiro Trikaliotis

Macro Definition Documentation

◆ CBMIMAGE_BLOCK_INIT

#define CBMIMAGE_BLOCK_INIT ( _track,
_sector,
_lba )
Value:
{ .lba = (_lba), .ts = CBMIMAGE_TS_INIT((_track), (_sector)) }
#define CBMIMAGE_TS_INIT(_track, _sector)
initializer for a cbmimage_track_sector
Definition cbmimage.h:52

initializer for a cbmimage_blockaddress

This macro can be used like
cbmimage_blockaddress var = CBMIMAGE_BLOCK_INIT(track, sector, lba)
in order to initialize the var.

Parameters
[in]_trackthe track to use as initializer
[in]_sectorthe sector to use as initializer
[in]_lbathe LBA to use as initializer

◆ CBMIMAGE_BLOCK_INIT_FROM_LBA

#define CBMIMAGE_BLOCK_INIT_FROM_LBA ( _lba)
Value:
CBMIMAGE_INIT_BLOCK(0, 0, (_lba))

initializer for a cbmimage_blockaddress

This macro can be used like
cbmimage_blockaddress var = CBMIMAGE_BLOCK_INIT_FROM_LBA(lba)
in order to initialize the var.

Parameters
[in]_lbathe LBA to use as initializer
Remarks
The track and sector part is set to 0, marking that it is still not initialized.

◆ CBMIMAGE_BLOCK_INIT_FROM_TS

#define CBMIMAGE_BLOCK_INIT_FROM_TS ( _track,
_sector )
Value:
CBMIMAGE_BLOCK_INIT((_track), (_sector), 0)
#define CBMIMAGE_BLOCK_INIT(_track, _sector, _lba)
initializer for a cbmimage_blockaddress
Definition cbmimage.h:127

initializer for a cbmimage_blockaddress

This macro can be used like
cbmimage_blockaddress var = CBMIMAGE_BLOCK_INIT_FROM_TS(track, sector)
in order to initialize the var.

Parameters
[in]_trackthe track to use as initializer
[in]_sectorthe sector to use as initializer
Remarks
The LBA part is set to 0, marking that it is still not initialized.

◆ CBMIMAGE_BLOCK_SET_FROM_LBA

#define CBMIMAGE_BLOCK_SET_FROM_LBA ( _image,
_block,
_lba )
Value:
do { \
(_block).lba = (_lba); \
cbmimage_blockaddress_init_from_lba((_image), &(_block)); \
} while (0)

initializer for a cbmimage_blockaddress

This macro can be used like
CBMIMAGE_BLOCK_SET_FROM_LBA(image, block, lba)
in order to initialize the var.

Parameters
[in]_imagepointer to the image data
[in,out]_blockthe cbmimage_blockaddress to be modified
[in]_lbathe LBA to use as initializer
Remarks
The track and sector values are calculated from the _lba value

◆ CBMIMAGE_BLOCK_SET_FROM_TS

#define CBMIMAGE_BLOCK_SET_FROM_TS ( _image,
_block,
_track,
_sector )
Value:
do { \
CBMIMAGE_TS_SET((_block).ts, (_track), (_sector)); \
cbmimage_blockaddress_init_from_ts((_image), &(_block)); \
} while (0)

initializer for a cbmimage_blockaddress

This macro can be used like
CBMIMAGE_BLOCK_SET_FROM_TS(image, block, track, sector)
in order to initialize the var.

Parameters
[in]_imagepointer to the image data
[in,out]_blockthe cbmimage_blockaddress to be modified
[in]_trackthe track to use as initializer
[in]_sectorthe sector to use as initializer
Remarks
The LBA part is calculated from the _track and _sector values

◆ CBMIMAGE_TS_CLEAR

#define CBMIMAGE_TS_CLEAR ( _ts)
Value:
CBMIMAGE_TS_SET((_ts), 0, 0)
#define CBMIMAGE_TS_SET(_ts, _track, _sector)
set a cbmimage_track_sector
Definition cbmimage.h:71

clear a cbmimage_track_sector

Clearing a track/sectors means to put it into an "invalid" state

This macro can be used like
CBMIMAGE_TS_CLEAR(var)
in order to initialize the var with track and sector

Parameters
[in,out]_tsThe variable which is modified

◆ CBMIMAGE_TS_INIT

#define CBMIMAGE_TS_INIT ( _track,
_sector )
Value:
{ .track = (_track), .sector = (_sector) }

initializer for a cbmimage_track_sector

This macro can be used like
cbmimage_track_sector var = CBMIMAGE_TS_INIT(track, sector)
in order to initialize the var.

Parameters
[in]_trackthe track to use as initializer
[in]_sectorthe sector to use as initializer

◆ CBMIMAGE_TS_SET

#define CBMIMAGE_TS_SET ( _ts,
_track,
_sector )
Value:
do { (_ts).track = (_track); (_ts).sector = (_sector); } while (0)

set a cbmimage_track_sector

This macro can be used like
CBMIMAGE_TS_INIT(var, track, sector)
in order to initialize the var with track and sector

Parameters
[in,out]_tsThe variable which is modified
[in]_trackthe track to use as initializer
[in]_sectorthe sector to use as initializer

Typedef Documentation

◆ cbmimage_file

file handling data

The structure is used for processing a file from a file image.

Todo
Add VLIR and REL file processing and needed structures

◆ cbmimage_print_function_type

typedef void cbmimage_print_function_type(const char *text)

Type for a print() style callback.

Used with cbmimage_print_set_function()

Function Documentation

◆ cbmimage_blockaddress_lba_exists()

int cbmimage_blockaddress_lba_exists ( cbmimage_fileimage * image,
uint16_t lba )

check if LBA is valid

Parameters
[in]imagepointer to the image data
[in]lbathe LBA of the block to be tested for existance
Returns
  • 0 if the block T/S is not valid
  • != 0 if the block T/S is valid
Remarks

◆ cbmimage_blockaddress_ts_exists()

int cbmimage_blockaddress_ts_exists ( cbmimage_fileimage * image,
uint8_t track,
uint8_t sector )

check if T/S is valid

Parameters
[in]imagepointer to the image data
[in]trackthe track of the block to be tested for existance
[in]sectorthe sector of the block to be tested for existance
Returns
  • 0 if the block T/S is not valid
  • != 0 if the block T/S is valid
Remarks

Variable Documentation

◆ cbmimage_block_unused

const cbmimage_blockaddress cbmimage_block_unused
extern

Definition of an empty cbmimage_blockaddress.

Whenever you need to use an empty or unused block address, you can use this one instead of defining it on your own.