如何在内核模块中使用vfs_read读取整个文件?

问题描述:

我必须读取正在写入的内核模块内的缓冲区中的整个文件。我开始以下写作here如何在内核模块中使用vfs_read读取整个文件?

但我不清楚如何检索文件大小,为阵列缓冲区分配内存。我无法找到有关VFS功能的良好文档。 (我在3.2内核上工作)。

这怎么能实现呢?由于

通过使用vfs_stat()vfs_fstatHow do you get the size of a file in the linux kernel?

+0

谢谢回答,我用vfs_stat()。现在我从struct kstat中获得“大小”。似乎它是loff_t(long long)类型。 因此,例如,用%lld打印值,我看到“/ bin/ls”:-131941060952272。 这是不可能的。我究竟做错了什么? – user3376554

+0

检查你的参数是否正确,并且没有'vfs_stat()设置的错误' – Vishal

+0

在https://*.com/questions/19195560/whats-wrong-with-vfs-stat-call上已经存在一个例子,你应在http://www.linuxjournal.com/node/8110/print – Vishal