Skip to content

Fix owner restoration and discard across nvstore init #7721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions features/nvstore/source/nvstore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ int NVStore::copy_record(uint8_t from_area, uint32_t from_offset, uint32_t to_of

int NVStore::garbage_collection(uint16_t key, uint16_t flags, uint8_t owner, uint16_t buf_size, const void *buf)
{
uint32_t curr_offset, new_area_offset, next_offset;
uint32_t curr_offset, new_area_offset, next_offset, curr_owner;
int ret;
uint8_t curr_area;

Expand All @@ -534,7 +534,8 @@ int NVStore::garbage_collection(uint16_t key, uint16_t flags, uint8_t owner, uin
return ret;
}
_offset_by_key[key] = new_area_offset | (1 - _active_area) << offs_by_key_area_bit_pos |
(((flags & set_once_flag) != 0) << offs_by_key_set_once_bit_pos);
(((flags & set_once_flag) != 0) << offs_by_key_set_once_bit_pos) |
(owner << offs_by_key_owner_bit_pos);
new_area_offset = next_offset;
}

Expand All @@ -544,15 +545,16 @@ int NVStore::garbage_collection(uint16_t key, uint16_t flags, uint8_t owner, uin
curr_offset = _offset_by_key[key];
uint16_t save_flags = curr_offset & offs_by_key_flag_mask & ~offs_by_key_area_mask;
curr_area = (uint8_t)(curr_offset >> offs_by_key_area_bit_pos) & 1;
curr_offset &= ~offs_by_key_flag_mask;
curr_owner = _offset_by_key[key] & offs_by_key_owner_mask;
curr_offset &= offs_by_key_offset_mask;
if ((!curr_offset) || (curr_area != _active_area)) {
continue;
}
ret = copy_record(curr_area, curr_offset, new_area_offset, next_offset);
if (ret != NVSTORE_SUCCESS) {
return ret;
}
_offset_by_key[key] = new_area_offset | (1 - curr_area) << offs_by_key_area_bit_pos | save_flags;
_offset_by_key[key] = new_area_offset | (1 - curr_area) << offs_by_key_area_bit_pos | save_flags | curr_owner;
new_area_offset = next_offset;
}

Expand Down