lib_log: fix length correction in the headers, cleanup

This commit is contained in:
Thomas Schoebel-Theuer 2013-07-04 08:19:24 +02:00
parent 82e7f1b823
commit 9a104deb19
2 changed files with 10 additions and 8 deletions

View File

@ -255,9 +255,10 @@ void *log_reserve(struct log_status *logst, struct log_header *lh)
DATA_PUT(data, offset, lh->l_pos);
logst->reallen_offset = offset;
DATA_PUT(data, offset, lh->l_len);
DATA_PUT(data, offset, lh->l_extra_len);
DATA_PUT(data, offset, (short)0); // spare
DATA_PUT(data, offset, (int)0); // spare
DATA_PUT(data, offset, lh->l_code);
DATA_PUT(data, offset, lh->l_extra);
DATA_PUT(data, offset, (short)0); // spare
// remember the last timestamp
memcpy(&logst->tmp_pos_stamp, &lh->l_stamp, sizeof(logst->tmp_pos_stamp));
@ -324,7 +325,7 @@ bool log_finalize(struct log_status *logst, int len, void (*endio)(void *private
/* Correct the length in the header.
*/
offset = logst->reallen_offset;
DATA_PUT(data, offset, len);
DATA_PUT(data, offset, (short)len);
/* Write the trailer.
*/

View File

@ -10,9 +10,11 @@
#ifndef LIB_LOG_H
#define LIB_LOG_H
#ifdef __KERNEL__
#include "mars.h"
extern atomic_t global_mref_flying;
#endif
/* The following structure is memory-only.
* Transfers to disk are indirectly via the
@ -27,10 +29,8 @@ struct log_header_v1 {
struct timespec l_stamp;
struct timespec l_written;
loff_t l_pos;
int l_len;
int l_extra_len;
short l_len;
short l_code;
short l_extra;
unsigned int l_seq_nr;
int l_crc;
};
@ -149,9 +149,10 @@ int log_scan(void *buf, int len, loff_t file_pos, int file_offset, bool sloppy,
DATA_GET(buf, offset, lh->l_stamp.tv_nsec);
DATA_GET(buf, offset, lh->l_pos);
DATA_GET(buf, offset, lh->l_len);
DATA_GET(buf, offset, lh->l_extra_len);
offset += 2; // skip spare
offset += 4; // skip spare
DATA_GET(buf, offset, lh->l_code);
DATA_GET(buf, offset, lh->l_extra);
offset += 2; // skip spare
found_offset = offset;
offset += lh->l_len;