![]() |
![]() |
![]() |
libMirage Reference Manual | ![]() |
---|---|---|---|---|
Top | Description |
#include <mirage.h> enum MIRAGE_SubChannel; #define MIRAGE_CAST_DATA (buf, off, type) #define MIRAGE_CAST_PTR (buf, off, type) #define MIRAGE_CHECK_ARG (arg) #define G_LIST_FOR_EACH (cursor, list) gchar * mirage_helper_find_data_file (const gchar *filename
,const gchar *path
); gchar * mirage_helper_get_suffix (gchar *filename
); gboolean mirage_helper_has_suffix (gchar *filename
,gchar *suffix
); gboolean mirage_helper_match_suffixes (gchar *filename
,gchar **suffixes
); gint mirage_helper_strcasecmp (const gchar *str1
,const gchar *str2
); gint mirage_helper_strncasecmp (const gchar *str1
,const gchar *str2
,gint len
); MIRAGE_ParserInfo * mirage_helper_create_parser_info (gchar *id
,gchar *name
,gchar *version
,gchar *author
,gboolean multi_file
,gchar *description
,gint num_suffixes
,...
); void mirage_helper_destroy_parser_info (MIRAGE_ParserInfo *info
); MIRAGE_FragmentInfo * mirage_helper_create_fragment_info (gchar *id
,gchar *name
,gchar *version
,gchar *author
,gchar *interface
,gint num_suffixes
,...
); void mirage_helper_destroy_fragment_info (MIRAGE_FragmentInfo *info
); void mirage_helper_lba2msf (gint lba
,gboolean diff
,guint8 *m
,guint8 *s
,guint8 *f
); gchar * mirage_helper_lba2msf_str (gint lba
,gboolean diff
); gint mirage_helper_msf2lba (guint8 m
,guint8 s
,guint8 f
,gboolean diff
); gint mirage_helper_msf2lba_str (gchar *msf
,gboolean diff
); gint mirage_helper_hex2bcd (gint hex
); gint mirage_helper_bcd2hex (gint bcd
); guint8 mirage_helper_ascii2isrc (gchar c
); gchar mirage_helper_isrc2ascii (guint8 c
); guint16 mirage_helper_subchannel_q_calculate_crc (guint8 *data
); void mirage_helper_subchannel_q_encode_mcn (guint8 *buf
,gchar *mcn
); void mirage_helper_subchannel_q_decode_mcn (guint8 *buf
,gchar *mcn
); void mirage_helper_subchannel_q_encode_isrc (guint8 *buf
,gchar *isrc
); void mirage_helper_subchannel_q_decode_isrc (guint8 *buf
,gchar *isrc
); void mirage_helper_subchannel_interleave (gint subchan
,guint8 *channel12
,guint8 *channel96
); void mirage_helper_subchannel_deinterleave (gint subchan
,guint8 *channel96
,guint8 *channel12
); void mirage_helper_sector_edc_ecc_compute_edc_block (const guint8 *src
,guint16 size
,guint8 *dest
); void mirage_helper_sector_edc_ecc_compute_ecc_block (guint8 *src
,guint32 major_count
,guint32 minor_count
,guint32 major_mult
,guint32 minor_inc
,guint8 *dest
);
These functions are exported because, while primarily designed to be used within libMirage, they could also prove useful to other applications. They cover the following functionality:
mirage_helper_get_suffix()
,
mirage_helper_has_suffix()
,
mirage_helper_match_suffixes()
.
mirage_helper_strcasecmp()
,
mirage_helper_strncasecmp()
.
mirage_helper_create_parser_info()
,
mirage_helper_destroy_parser_info()
,
mirage_helper_create_fragment_info()
,
mirage_helper_destroy_fragment_info()
.
mirage_helper_lba2msf()
,
mirage_helper_lba2msf_str()
,
mirage_helper_msf2lba()
,
mirage_helper_msf2lba_str()
.
mirage_helper_hex2bcd()
,
mirage_helper_bcd2hex()
.
mirage_helper_ascii2isrc()
,
mirage_helper_isrc2ascii()
.
mirage_helper_subchannel_q_calculate_crc()
,
mirage_helper_subchannel_q_encode_mcn()
,
mirage_helper_subchannel_q_decode_mcn()
,
mirage_helper_subchannel_q_encode_isrc()
,
mirage_helper_subchannel_q_decode_isrc()
.
mirage_helper_subchannel_interleave()
,
mirage_helper_subchannel_deinterleave()
.
mirage_helper_sector_edc_ecc_compute_edc_block()
,
mirage_helper_sector_edc_ecc_compute_ecc_block()
.
typedef enum { SUBCHANNEL_W = 0, SUBCHANNEL_V = 1, SUBCHANNEL_U = 2, SUBCHANNEL_T = 3, SUBCHANNEL_S = 4, SUBCHANNEL_R = 5, SUBCHANNEL_Q = 6, SUBCHANNEL_P = 7, } MIRAGE_SubChannel;
Subchannel type for interleaving/deinterleaving.
#define MIRAGE_CAST_DATA(buf,off,type) (*((type *)(buf+off)))
A macro for easy retrieval of data from (unsigned integer) buffer. Mostly to be used in binary image parsers, for example, to retrieve guint32 or guint16 value from buffer.
|
buffer to get data from |
|
offset in buffer at which to get data |
|
data type (i.e. 'guint64') |
#define MIRAGE_CAST_PTR(buf,off,type) ((type)(buf+off))
A macro for easy placing of pointers within (unsigned integer) buffer. Mostly to be used in binary image parsers, for example, to retrieve a string or a structure from buffer.
|
buffer to place pointer in |
|
offset in buffer at which to place pointer |
|
pointer type (i.e. 'gchar *') |
#define MIRAGE_CHECK_ARG(arg)
A macro to be used within libMirage objects. It checks whether arg
is valid
pointer argument (non-NULL). If it is not, it returns false and error is set
to MIRAGE_E_INVALIDARG
. The existance of local variable error
of type
GError** is assumed.
|
argument to be checked |
#define G_LIST_FOR_EACH(cursor,list)
A macro providing for loop on GList. cursor
is a cursor of type GList*, and
is used to store current element in the list. list
is a GLib's double linked
list that for loop should be performed on.
|
cursor |
|
list |
gchar * mirage_helper_find_data_file (const gchar *filename
,const gchar *path
);
Attempts to find a file with filename filename
and path path
. filename
can
be file's basename or an absolute path. path
can be either directory path (in
this case, it must end with '/') or a filename (i.e. of file descriptor).
If filename
is an absolute path, its existence is first checked. If it
doesn't exist, path
's dirname is combined with filename
's basename, and the
combination's existence is checked. If that fails as well, then directory,
specified by path
's dirname is opened and its content is case-insensitively
compared to filename
's basename. This way, all possible case variations are
taken into account (i.e. file.iso, FILE.ISO, FiLe.IsO, etc.). If at any of
above steps the result is positive, the resulting filename is returned as a
newly allocated string.
The returned string should be freed when no longer needed.
gchar * mirage_helper_get_suffix (gchar *filename
);
Retrieves suffix from filename
.
|
filename |
Returns : |
pointer to character in filename at which the suffix starts. |
gboolean mirage_helper_has_suffix (gchar *filename
,gchar *suffix
);
Checks whether file name filename
ends with suffix suffix
.
gboolean mirage_helper_match_suffixes (gchar *filename
,gchar **suffixes
);
Checks whether filename
ends with a suffix from suffixes
.
gint mirage_helper_strcasecmp (const gchar *str1
,const gchar *str2
);
Replacement function for g_strcasecmp/strcasecmp, which can properly handle UTF-8. Glib docs state this is only an approximation, albeit it should be a fairly good one.
It compares the two strings str1
and str2
, ignoring the case of the characters.
It returns an integer less than, equal to, or greater than zero if str1
is found,
respectively, to be less than, to match, or be greater than str2
.
|
first string |
|
second string |
Returns : |
an integer less than, equal to, or greater than zero if str1
is found, respectively, to be less than, to match, or be greater than str2 . |
gint mirage_helper_strncasecmp (const gchar *str1
,const gchar *str2
,gint len
);
Replacement function for g_strncasecmp/strncasecmp, which can properly handle UTF-8. Glib docs state this is only an approximation, albeit it should be a fairly good one.
It compares first len
characters of string str1
and str2
, ignoring the case of
the characters. It returns an integer less than, equal to, or greater than zero if
first len
characters of str1
is found, respectively, to be less than, to match,
or be greater than first len
characters of str2
.
|
first string |
|
second string |
|
length of string to compare |
Returns : |
an integer less than, equal to, or greater than zero if first len
characters of str1 is found, respectively, to be less than, to match, or
be greater than first len characters of str2 . |
MIRAGE_ParserInfo * mirage_helper_create_parser_info (gchar *id
,gchar *name
,gchar *version
,gchar *author
,gboolean multi_file
,gchar *description
,gint num_suffixes
,...
);
A convenience function that allocates and fills a MIRAGE_ParserInfo structure.
num_suffixes
is number of provided suffixes (including terminating NULL),
while Varargs
is a NULL-terminated list of suffixes.
|
parser ID |
|
parser name |
|
parser version |
|
author name |
|
multi-file image support |
|
image file description |
|
number of image file suffixes |
|
image file suffixes |
Returns : |
a new MIRAGE_ParserInfo containing the provided information. It should
be destroyed with mirage_helper_destroy_parser_info() when no longer needed. |
void mirage_helper_destroy_parser_info (MIRAGE_ParserInfo *info
);
A convenience function that properly destroys a MIRAGE_ParserInfo structure, freeing all its fields and the structure itself.
|
a MIRAGE_ParserInfo to be destroyed |
MIRAGE_FragmentInfo * mirage_helper_create_fragment_info (gchar *id
,gchar *name
,gchar *version
,gchar *author
,gchar *interface
,gint num_suffixes
,...
);
A convenience function that allocates and fills a MIRAGE_FragmentInfo structure.
num_suffixes
is number of provided suffixes (including terminating NULL),
while Varargs
is a NULL-terminated list of suffixes.
|
fragment ID |
|
fragment name |
|
fragment version |
|
author name |
|
interface fragment implements |
|
number of filename suffixes |
|
filename suffixes |
Returns : |
a new MIRAGE_FragmentInfo containing the provided information. It should
be destroyed with mirage_helper_destroy_fragment_info() when no longer needed. |
void mirage_helper_destroy_fragment_info (MIRAGE_FragmentInfo *info
);
A convenience function that properly destroys a MIRAGE_FragmentInfo structure, freeing all its fields and the structure itself.
|
a MIRAGE_FragmentInfo to be destroyed |
void mirage_helper_lba2msf (gint lba
,gboolean diff
,guint8 *m
,guint8 *s
,guint8 *f
);
Converts LBA sector address stored in lba
into MSF address, storing each field
into m
, s
and f
, respectively.
If diff
is TRUE
, 150 frames difference is accounted for; this should be
used when converting absolute addresses. When converting relative addresses
(or lengths), diff
should be set to FALSE
.
gchar * mirage_helper_lba2msf_str (gint lba
,gboolean diff
);
Converts LBA sector address stored in lba
into MSF address.
If diff
is TRUE
, 150 frames difference is accounted for; this should be
used when converting absolute addresses. When converting relative addresses
(or lengths), diff
should be set to FALSE
.
|
LBA address |
|
account for the difference |
Returns : |
a newly-allocated string containing MSF address; it should be freed
with g_free() when no longer needed. |
gint mirage_helper_msf2lba (guint8 m
,guint8 s
,guint8 f
,gboolean diff
);
Converts MSF sector address stored in m
, s
and f
into LBA address.
If diff
is TRUE
, 150 frames difference is accounted for; this should be
used when converting absolute addresses. When converting relative addresses
(or lengths), diff
should be set to FALSE
.
|
minutes |
|
seconds |
|
frames |
|
difference |
Returns : |
integer representing LBA address |
gint mirage_helper_msf2lba_str (gchar *msf
,gboolean diff
);
Converts MSF sector address stored in msf
string into LBA address.
If diff
is TRUE
, 150 frames difference is accounted for; this should be
used when converting absolute addresses. When converting relative addresses
(or lengths), diff
should be set to FALSE
.
|
MSF string |
|
difference |
Returns : |
integer representing LBA address |
gint mirage_helper_hex2bcd (gint hex
);
Converts hex-encoded integer into bcd-encoded integer.
|
hex-encoded integer |
Returns : |
bcd-encoded integer |
gint mirage_helper_bcd2hex (gint bcd
);
Converts bcd-encoded integer into hex-encoded integer.
|
bcd-encoded integer |
Returns : |
hex-encoded integer |
guint8 mirage_helper_ascii2isrc (gchar c
);
Converts ASCII character c
into ISRC character.
|
ASCII character |
Returns : |
ISRC character |
gchar mirage_helper_isrc2ascii (guint8 c
);
Converts ISRC character c
into ASCII character.
|
ISRC character |
Returns : |
ACSII character |
guint16 mirage_helper_subchannel_q_calculate_crc
(guint8 *data
);
Calculates the CRC-16 checksum of the Q subchannel data stored in data
.
|
buffer containing Q subchannel data |
Returns : |
CRC-16 checksum of Q subchannel data |
void mirage_helper_subchannel_q_encode_mcn (guint8 *buf
,gchar *mcn
);
Encodes MCN string mcn
into buffer buf
.
|
buffer to encode MCN into |
|
MCN string |
void mirage_helper_subchannel_q_decode_mcn (guint8 *buf
,gchar *mcn
);
Decodes MCN stored in buf
into string mcn
.
|
buffer containing encoded MCN |
|
string to decode MCN into |
void mirage_helper_subchannel_q_encode_isrc (guint8 *buf
,gchar *isrc
);
Encodes ISRC string isrc
into buffer buf
.
|
buffer to encode ISRC into |
|
ISRC string |
void mirage_helper_subchannel_q_decode_isrc (guint8 *buf
,gchar *isrc
);
Decodes ISRC stored in buf
into string isrc
.
|
buffer containing encoded ISRC |
|
string to decode ISRC into |
void mirage_helper_subchannel_interleave (gint subchan
,guint8 *channel12
,guint8 *channel96
);
Interleaves subchannel data of type subchan
stored in channel12
into
subchannel data stored in subchannel96
.
|
subchannel type |
|
buffer containing subchannel data to interleave |
|
buffer to interleave subchannel data into |
void mirage_helper_subchannel_deinterleave (gint subchan
,guint8 *channel96
,guint8 *channel12
);
Deinterleaves subchannel data of type subchan
from subchannel data stored in
channel96
and writes the resulting subhcannel data into subchannel12
.
|
subchannel type |
|
buffer containing subchannel data to deinterleave |
|
buffer to deinterleave subchannel data into |
void mirage_helper_sector_edc_ecc_compute_edc_block (const guint8 *src
,guint16 size
,guint8 *dest
);
Calculates EDC (error detection code) for data in src
of length size
and
writes the result into dest
.
To calculate EDC for different types of sectors and store it into sector data, use:
mirage_helper_sector_edc_ecc_compute_edc_block(sector_buffer+0x00, 0x810, sector_buffer+0x810);
mirage_helper_sector_edc_ecc_compute_edc_block(sector_buffer+0x10, 0x808, sector_buffer+0x818);
mirage_helper_sector_edc_ecc_compute_edc_block(sector_buffer+0x10, 0x91C, sector_buffer+0x92C);
(This is assuming all other sector data is already stored in sector_buffer and that sector_buffer is 2532 bytes long)
|
data to calculate EDC data for |
|
size of data in src
|
|
buffer to write calculated EDC data into |
void mirage_helper_sector_edc_ecc_compute_ecc_block (guint8 *src
,guint32 major_count
,guint32 minor_count
,guint32 major_mult
,guint32 minor_inc
,guint8 *dest
);
Calculates ECC (error correction code) for data in src
and writes the result
into dest
. The code assumes 2352 byte sectors. It can calculate both P and Q
layer of ECC data, depending on major_count
, minor_count
, major_mult
and
minor_inc.
To calculate ECC (first P, then Q layer) for different types of sectors and store it into sector data, use:
mirage_helper_sector_edc_ecc_compute_ecc_block(sector_buffer+0xC, 86, 24, 2, 86, sector_buffer+0x81C);
mirage_helper_sector_edc_ecc_compute_ecc_block(sector_buffer+0xC, 52, 43, 86, 88, sector_buffer+0x8C8);
mirage_helper_sector_edc_ecc_compute_ecc_block(sector_buffer+0xC, 86, 24, 2, 86, sector_buffer+0x81C);
mirage_helper_sector_edc_ecc_compute_ecc_block(sector_buffer+0xC, 52, 43, 86, 88, sector_buffer+0x8C8);
(This is assuming all other sector data, including EDC, is already stored in sector_buffer and that sector_buffer is 2532 bytes long)
|
data to calculate ECC data for |
|
major count |
|
minor count |
|
major multiplicator |
|
minor increment |
|
buffer to write calculated ECC data into |