Commit 7e3873de authored by Mikhail Karpenko's avatar Mikhail Karpenko

Reset write pointer to start when disk end is reached

parent 84ebd545
...@@ -106,6 +106,7 @@ static inline size_t align_bytes_num(size_t data_len, size_t align_len) ...@@ -106,6 +106,7 @@ static inline size_t align_bytes_num(size_t data_len, size_t align_len)
return align_len - rem; return align_len - rem;
} }
/** Remap vectors pointing to various buffers with frame data to vectors used during frame alignment */
static void remap_vectors(camogm_state *state, struct iovec *chunks) static void remap_vectors(camogm_state *state, struct iovec *chunks)
{ {
int chunk_index = 1; int chunk_index = 1;
...@@ -177,6 +178,7 @@ static size_t get_blocks_num(struct iovec *sgl, size_t n_elem) ...@@ -177,6 +178,7 @@ static size_t get_blocks_num(struct iovec *sgl, size_t n_elem)
return total / PHY_BLOCK_SIZE; return total / PHY_BLOCK_SIZE;
} }
/** Allocate and initialize buffers for frame alignment */
int init_align_buffers(camogm_state *state) int init_align_buffers(camogm_state *state)
{ {
state->writer_params.data_chunks = (struct iovec *)malloc(MAX_DATA_CHUNKS * sizeof(struct iovec)); state->writer_params.data_chunks = (struct iovec *)malloc(MAX_DATA_CHUNKS * sizeof(struct iovec));
...@@ -211,6 +213,7 @@ int init_align_buffers(camogm_state *state) ...@@ -211,6 +213,7 @@ int init_align_buffers(camogm_state *state)
return 0; return 0;
} }
/** Delete buffers for frame alignment */
void deinit_align_buffers(camogm_state *state) void deinit_align_buffers(camogm_state *state)
{ {
struct writer_params *params = &state->writer_params; struct writer_params *params = &state->writer_params;
...@@ -408,7 +411,6 @@ void align_frame(camogm_state *state) ...@@ -408,7 +411,6 @@ void align_frame(camogm_state *state)
} else { } else {
/* the frame is aligned to sector boundary but some buffers may be not */ /* the frame is aligned to sector boundary but some buffers may be not */
chunks[CHUNK_ALIGN].iov_base = vectrpos(cbuff, 0); chunks[CHUNK_ALIGN].iov_base = vectrpos(cbuff, 0);
// chunks[CHUNK_ALIGN].iov_dma = cbuff->iov_dma + cbuff->iov_len;
chunks[CHUNK_ALIGN].iov_len = 0; chunks[CHUNK_ALIGN].iov_len = 0;
if (chunks[CHUNK_DATA_1].iov_len == 0) { if (chunks[CHUNK_DATA_1].iov_len == 0) {
data_len = chunks[CHUNK_DATA_0].iov_len % ALIGNMENT_SIZE; data_len = chunks[CHUNK_DATA_0].iov_len % ALIGNMENT_SIZE;
...@@ -510,6 +512,7 @@ int prep_last_block(camogm_state *state) ...@@ -510,6 +512,7 @@ int prep_last_block(camogm_state *state)
return ret; return ret;
} }
/** Convert LBA to byte offset used for lseek */
off64_t lba_to_offset(uint64_t lba) off64_t lba_to_offset(uint64_t lba)
{ {
return lba * PHY_BLOCK_SIZE; return lba * PHY_BLOCK_SIZE;
......
...@@ -329,6 +329,7 @@ int camogm_frame_jpeg(camogm_state *state) ...@@ -329,6 +329,7 @@ int camogm_frame_jpeg(camogm_state *state)
align_frame(state); align_frame(state);
if (update_lba(state) == 1) { if (update_lba(state) == 1) {
D0(fprintf(debug_file, "The end of block device reached, continue recording from start\n")); D0(fprintf(debug_file, "The end of block device reached, continue recording from start\n"));
lseek(state->writer_params.blockdev_fd, 0, SEEK_SET);
} }
D6(fprintf(debug_file, "Block device positions: start = %llu, current = %llu, end = %llu\n", D6(fprintf(debug_file, "Block device positions: start = %llu, current = %llu, end = %llu\n",
state->writer_params.lba_start, state->writer_params.lba_current, state->writer_params.lba_end)); state->writer_params.lba_start, state->writer_params.lba_current, state->writer_params.lba_end));
...@@ -342,10 +343,6 @@ int camogm_frame_jpeg(camogm_state *state) ...@@ -342,10 +343,6 @@ int camogm_frame_jpeg(camogm_state *state)
if (state->writer_params.last_ret_val != 0) { if (state->writer_params.last_ret_val != 0) {
return state->writer_params.last_ret_val; return state->writer_params.last_ret_val;
} }
// update statistics
// state->rawdev.last_jpeg_size = camogm_get_jpeg_size(state);
// state->rawdev.total_rec_len += state->rawdev.last_jpeg_size;
} }
return 0; return 0;
...@@ -424,12 +421,6 @@ void *jpeg_writer(void *thread_args) ...@@ -424,12 +421,6 @@ void *jpeg_writer(void *thread_args)
if (params->data_ready) { if (params->data_ready) {
l = 0; l = 0;
state->writer_params.last_ret_val = 0; state->writer_params.last_ret_val = 0;
// for (int i = 0; i < (state->chunk_index) - 1; i++) {
// chunks_iovec[i].iov_base = state->packetchunks[i + 1].chunk;
// chunks_iovec[i].iov_len = state->packetchunks[i + 1].bytes;
// l += chunks_iovec[i].iov_len;
// }
// chunk_index = state->chunk_index;
chunk_index = get_data_buffers(state, &chunks_iovec, FILE_CHUNKS_NUM); chunk_index = get_data_buffers(state, &chunks_iovec, FILE_CHUNKS_NUM);
if (chunk_index > 0) { if (chunk_index > 0) {
for (int i = 0; i < chunk_index; i++) for (int i = 0; i < chunk_index; i++)
......
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