Как вы получаете размер файла в ядре Linux?
Я нашел эту ссылку (http://www.spinics.net/lists/newbies/msg41016.html) и пытался сделать именно это. Поэтому я написал код в модуле ядра:
#include <linux/path.h>
#include <linux/namei.h>
#include <linux/fs.h>
struct path p;
struct kstat ks;
kern_path(filepath, 0, &p);
vfs_getattr(&p, &ks);
printk(KERN_INFO "size: %lld\n", ks.size);
Который не будет компилироваться, потому что:
/root/kernelmodule/hello.c:15: warning: passing argument 1 of ‘vfs_getattr’ from incompatible pointer type
include/linux/fs.h:2563: note: expected ‘struct vfsmount *’ but argument is of type ‘struct path *’
/root/kernelmodule/hello.c:15: warning: passing argument 2 of ‘vfs_getattr’ from incompatible pointer type
include/linux/fs.h:2563: note: expected ‘struct dentry *’ but argument is of type ‘struct kstat *’
/root/kernelmodule/hello.c:15: error: too few arguments to function ‘vfs_getattr’
Так что я действительно запутался, так как я смотрел на эту документацию:http://lxr.free-electrons.com/source/fs/stat.c#L40
И теперь я вижу внутри /linux/fs.h, что прототип для vfs_getattr:
extern int vfs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
Может ли кто-нибудь помочь мне с моей реализацией? Я читаю на vfsmount и dentry, но все еще потерялся.