Delete meta file if becomes zero.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2023-01-14 00:39:06 +01:00
parent 7293683906
commit f59b7d92ef
No known key found for this signature in database
GPG key ID: C0095B7870A4CCD3

View file

@ -353,17 +353,21 @@ int meta_delete(uint16_t fid) {
uint16_t cfid = (tag_data[0] << 8 | tag_data[1]);
if (cfid == fid) {
size_t new_len = data_len-1-tag_len-format_tlv_len(tag_len, NULL);
fdata = (uint8_t *)calloc(1, new_len);
if (tpos > data) {
memcpy(fdata, data, tpos-data);
if (new_len == 0)
flash_clear_file(ef);
else {
fdata = (uint8_t *)calloc(1, new_len);
if (tpos > data) {
memcpy(fdata, data, tpos-data);
}
if (data+data_len > p) {
memcpy(fdata+(tpos-data), p, data+data_len-p);
}
int r = flash_write_data_to_file(ef, fdata, new_len);
free(fdata);
if (r != CCID_OK)
return CCID_EXEC_ERROR;
}
if (data+data_len > p) {
memcpy(fdata+(tpos-data), p, data+data_len-p);
}
int r = flash_write_data_to_file(ef, fdata, new_len);
free(fdata);
if (r != CCID_OK)
return CCID_EXEC_ERROR;
low_flash_available();
break;
}