New -report_system_area form "gpt_crc_of:"

This commit is contained in:
2014-04-12 13:02:23 +00:00
parent 825df24b70
commit 551823d96f
5 changed files with 86 additions and 35 deletions

View File

@ -1391,6 +1391,38 @@ hint_revoke:;
}
int Xorriso_gpt_crc(struct XorrisO *xorriso, char *path, int flag)
{
int ret;
char *buf = NULL;
FILE *fp = NULL;
uint32_t crc;
Xorriso_alloc_meM(buf, char, 32 * 1024);
ret= Xorriso_afile_fopen(xorriso, path, "rb", &fp, 0);
if(ret <= 0)
goto ex;
ret= fread(buf, 1, 32 * 1024, fp);
if(ret == 0) {
strcpy(xorriso->info_text,
"No bytes readable for GPT CRC from ");
Text_shellsafe(path, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
ret= 0; goto ex;
}
crc= iso_crc32_gpt((unsigned char *) buf, ret, 0);
sprintf(xorriso->result_line, "0x%8.8x\n", (unsigned int) crc);
Xorriso_result(xorriso, 0);
ret= 1;
ex:;
if(fp != NULL && fp != stdin)
fclose(fp);
Xorriso_free_meM(buf);
return(ret);
}
int Xorriso_report_system_area(struct XorrisO *xorriso, char *form, int flag)
{
int ret;
@ -1404,6 +1436,9 @@ int Xorriso_report_system_area(struct XorrisO *xorriso, char *form, int flag)
if(ret <= 0)
goto ex;
ret= iso_image_report_system_area(image, &text, 0);
} else if(strncmp(form, "gpt_crc_of:", 11) == 0) {
ret = Xorriso_gpt_crc(xorriso, form + 11, 0);
goto ex;
} else {
strcpy(xorriso->info_text,
"-report_system_area form parameter not recognized: ");
@ -1440,3 +1475,4 @@ ex:;
free(text);
return(ret);
}