How to get entire file size when fuse write

被刻印的时光 ゝ 提交于 2021-02-05 07:44:32

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!