Commit 92d762d1 authored by g3gg0's avatar g3gg0
Browse files

mlv_lite: embed VERS blocks into MLV file so there is no uncertainity about...

mlv_lite: embed VERS blocks into MLV file so there is no uncertainity about the modules used for a given recording

--HG--
branch : unified
parent 6a6b2af6d172
......@@ -1612,6 +1612,73 @@ static void init_mlv_chunk_headers(struct raw_info * raw_info)
mlv_fill_wbal(&wbal_hdr, mlv_start_timestamp);
}
static int write_mlv_vers_blocks(FILE *f)
{
int mod = -1;
int error = 0;
do
{
/* get next loaded module id */
mod = module_get_next_loaded(mod);
/* make sure thats a valid one */
if(mod >= 0)
{
/* fetch information from module loader */
const char *mod_name = module_get_name(mod);
const char *mod_build_date = module_get_string(mod, "Build date");
const char *mod_last_update = module_get_string(mod, "Last update");
if(mod_name != NULL)
{
/* just in case that ever happens */
if(mod_build_date == NULL)
{
mod_build_date = "(no build date)";
}
if(mod_last_update == NULL)
{
mod_last_update = "(no version)";
}
/* separating the format string allows us to measure its length for malloc */
const char *fmt_string = "%s built %s; commit %s";
int buf_length = strlen(fmt_string) + strlen(mod_name) + strlen(mod_build_date) + strlen(mod_last_update) + 1;
char *version_string = malloc(buf_length);
/* now build the string */
snprintf(version_string, buf_length, fmt_string, mod_name, mod_build_date, mod_last_update);
/* and finally remove any newlines, they are annoying */
for(unsigned int pos = 0; pos < strlen(version_string); pos++)
{
if(version_string[pos] == '\n')
{
version_string[pos] = ' ';
}
}
/* let the mlv helpers build the block for us */
mlv_vers_hdr_t *hdr = NULL;
mlv_build_vers(&hdr, mlv_start_timestamp, version_string);
/* try to write to output file */
if(FIO_WriteFile(f, hdr, hdr->blockSize) != (int)hdr->blockSize)
{
error = 1;
}
/* free both temporary string and allocated mlv block */
free(version_string);
free(hdr);
}
}
} while(mod >= 0 && !error);
return error;
}
static int write_mlv_chunk_headers(FILE* f)
{
if (FIO_WriteFile(f, &file_hdr, file_hdr.blockSize) != (int)file_hdr.blockSize) return 0;
......@@ -1621,6 +1688,7 @@ static int write_mlv_chunk_headers(FILE* f)
if (FIO_WriteFile(f, &lens_hdr, lens_hdr.blockSize) != (int)lens_hdr.blockSize) return 0;
if (FIO_WriteFile(f, &rtci_hdr, rtci_hdr.blockSize) != (int)rtci_hdr.blockSize) return 0;
if (FIO_WriteFile(f, &wbal_hdr, wbal_hdr.blockSize) != (int)wbal_hdr.blockSize) return 0;
if (write_mlv_vers_blocks(f)) return 0;
int hdr_size = FIO_SeekSkipFile(f, 0, SEEK_CUR);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment