Remove duplicate journal writing code (and fix it at the same time)
This commit is contained in:
+35
-2
@@ -119,6 +119,39 @@ struct journal_t
|
||||
uint8_t *sector_buf;
|
||||
journal_sector_info_t *sector_info;
|
||||
uint64_t sector_count;
|
||||
uint64_t cur_sector = 0;
|
||||
uint64_t in_sector_pos = 0;
|
||||
int cur_sector = 0;
|
||||
int in_sector_pos = 0;
|
||||
};
|
||||
|
||||
struct blockstore_journal_check_t
|
||||
{
|
||||
blockstore *bs;
|
||||
uint64_t next_pos, next_sector, next_in_pos;
|
||||
int sectors_required;
|
||||
|
||||
blockstore_journal_check_t(blockstore *bs);
|
||||
int check_available(blockstore_operation *op, int required, int size, int data_after);
|
||||
};
|
||||
|
||||
inline journal_entry* prefill_single_journal_entry(journal_t & journal, uint16_t type, uint32_t size)
|
||||
{
|
||||
if (512 - journal.in_sector_pos < size)
|
||||
{
|
||||
// Move to the next journal sector
|
||||
// Also select next sector buffer in memory
|
||||
journal.cur_sector = ((journal.cur_sector + 1) % journal.sector_count);
|
||||
journal.sector_info[journal.cur_sector].offset = journal.next_free;
|
||||
journal.in_sector_pos = 0;
|
||||
journal.next_free = (journal.next_free+512) < journal.len ? journal.next_free + 512 : 512;
|
||||
memset(journal.sector_buf + 512*journal.cur_sector, 0, 512);
|
||||
}
|
||||
journal_entry *je = (struct journal_entry*)(
|
||||
journal.sector_buf + 512*journal.cur_sector + journal.in_sector_pos
|
||||
);
|
||||
journal.in_sector_pos += size;
|
||||
je->magic = JOURNAL_MAGIC;
|
||||
je->type = type;
|
||||
je->size = size;
|
||||
je->crc32_prev = journal.crc32_last;
|
||||
return je;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user