+ /*
+ * The caller should never ask for move_pos across packets,
+ * except to get exactly at the beginning of the next packet.
+ */
+ if (pos->prot == PROT_WRITE) {
+ /* The writer will add padding */
+ assert(pos->offset + offset == pos->packet_size);
+
+ /*
+ * Don't increment for initial stream move (only condition where
+ * pos->offset can be 0.
+ */
+ if (pos->offset)
+ pos->mmap_offset += WRITE_PACKET_LEN / CHAR_BIT;
+ pos->content_size = -1U; /* Unknown at this point */
+ pos->packet_size = WRITE_PACKET_LEN;
+ off = posix_fallocate(pos->fd, pos->mmap_offset, pos->packet_size / CHAR_BIT);
+ assert(off >= 0);
+ } else {
+ /* The reader will expect us to skip padding */
+ assert(pos->offset + offset == pos->content_size);
+
+ /*
+ * Don't increment for initial stream move (only condition where
+ * pos->offset can be 0).
+ */
+ if (pos->offset)
+ ++pos->cur_index;
+ index = &g_array_index(pos->packet_index, struct packet_index,
+ pos->cur_index);
+ pos->mmap_offset = index->offset;
+
+ /* Lookup context/packet size in index */
+ pos->content_size = index->content_size;
+ pos->packet_size = index->packet_size;
+ }