Truncate
dhalsimax opened this issue · 2 comments
Hi,
Nice work, I never user FUSE before, anyway the truncate function in vmram.cpp does:
file->size(size);
And it it's just nice for this function to delegate the class, anyway the file function size() in file class:
void file_t::size(size_t new_size) {
if (new_size < _size) {
free_blocks(new_size);
}
_size = new_size;
mtime(util::time());
}
Suppose you are using the standard shell command truncate on a new file or to increase the size of any existing one, as you only check the new size is less the _size member field you will finally get the new or bigger "truncated" file without the correct blocks allocated. So then, when using the file again, you will get a segfault. Try by yourself.
Is it solution writing a while loop to allocate all the blocks needed with alloc_block function?
Regards Massimo.
That's weird, I'd expect the block allocation logic in file_t::write
to be triggered in that case. Is that not what happens?
Yes yuo are right, I have reviewed the code again and that would be the expectation: the write member should fill the gaps. Buy After all the exact steps to riproduce the segfault are:
-Make any file with truncate command of the desidered size (make sure your size will fit in the available space to prevent any other issue).
-Format the file with commad mkfs.ext4
- you Will get a segfault in vramfs process prior mkfs.ext4 will finish
If you create the file with a "dd" command instead everything should work.
Regards.