问题
I'm developing a file system based on fuse. but experiencing difficulties during development.
My question is 'how to get entire file size when fuse_write'.
in fuse_write,
static int test_fuse_write(const char *path, const char *buf, size_t size,
off_t offset, struct fuse_file_info *fi)
these arguments are not related to source file. only related to destination file. I want a total file size.
for example, when copying file 'A' in ext4 file system to file 'B' in fuse file system. if size of file 'A' is 12MB, when the fuse_write function first called, is there a way to know the file size(12MB)?
I'm sorry I do not have enough English.
回答1:
The answer is no.
Regardless of fuse file system, write is a file system operation while "copy" is a user utility (ex. cp in Unix). The copy utility executes read operations on the source file and write operations on the destination file. The reads and writes are "unaware" of each other. You can dig in the source code of cp
More ever, any read and write operations done by a user utility are divided by the kernel into consequent chunks of usually same size (ex. 64K). So a write operation of data in length of a few megabytes will be seen in your implementation of the fuse write function as a series of (let's say) 64K length consequent calls.
You should be encouraged that this is exactly the type of enlightenment you reach when writing a fuse file system...
来源:https://stackoverflow.com/questions/52069606/how-to-get-entire-file-size-when-fuse-write