Ensure that the file end is updated in the original file extent if it has been overwritten through a micro log operation.
This commit is contained in:
parent
3140f36356
commit
aef0e9eae6
|
@ -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 a new issue