mirror of
https://github.com/oliverschmidt/contiki.git
synced 2025-01-03 11:30:53 +00:00
Merge pull request #582 from nvt/coffee-file-end-fix
Make sure that Coffee updates the file end after a micro log write.
This commit is contained in:
commit
9ce285f8c0
@ -1155,6 +1155,7 @@ cfs_write(int fd, const void *buf, unsigned size)
|
|||||||
int i;
|
int i;
|
||||||
struct log_param lp;
|
struct log_param lp;
|
||||||
cfs_offset_t bytes_left;
|
cfs_offset_t bytes_left;
|
||||||
|
int8_t need_dummy_write;
|
||||||
const char dummy[1] = { 0xff };
|
const char dummy[1] = { 0xff };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1188,6 +1189,7 @@ cfs_write(int fd, const void *buf, unsigned size)
|
|||||||
#else
|
#else
|
||||||
if(FILE_MODIFIED(file) || fdp->offset < file->end) {
|
if(FILE_MODIFIED(file) || fdp->offset < file->end) {
|
||||||
#endif
|
#endif
|
||||||
|
need_dummy_write = 0;
|
||||||
for(bytes_left = size; bytes_left > 0;) {
|
for(bytes_left = size; bytes_left > 0;) {
|
||||||
lp.offset = fdp->offset;
|
lp.offset = fdp->offset;
|
||||||
lp.buf = buf;
|
lp.buf = buf;
|
||||||
@ -1212,13 +1214,19 @@ cfs_write(int fd, const void *buf, unsigned size)
|
|||||||
occur while writing log records. */
|
occur while writing log records. */
|
||||||
if(fdp->offset > file->end) {
|
if(fdp->offset > file->end) {
|
||||||
file->end = fdp->offset;
|
file->end = fdp->offset;
|
||||||
|
need_dummy_write = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fdp->offset > file->end) {
|
if(need_dummy_write) {
|
||||||
/* Update the original file's end with a dummy write. */
|
/*
|
||||||
COFFEE_WRITE(dummy, 1, absolute_offset(file->page, fdp->offset));
|
* A log record has been written at an offset beyond the original
|
||||||
|
* extent's end. Consequently, we need to write a dummy value at the
|
||||||
|
* corresponding end offset in the original extent to ensure that
|
||||||
|
* the correct file size is calculated when opening the file again.
|
||||||
|
*/
|
||||||
|
COFFEE_WRITE(dummy, 1, absolute_offset(file->page, fdp->offset - 1));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#endif /* COFFEE_MICRO_LOGS */
|
#endif /* COFFEE_MICRO_LOGS */
|
||||||
|
Loading…
Reference in New Issue
Block a user