I found this link (http://www.spinics.net/lists/newbies/msg41016.html) and have been looking into doing just that. So I wrote code in a kernel module:
#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);
Which will not compile because:
/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’
So I am really confused since I was looking at this documentation: http://lxr.free-electrons.com/source/fs/stat.c#L40
And now I see inside /linux/fs.h that the prototype for vfs_getattr is:
extern int vfs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
Can anyone help me with my implementation? I am reading into vfsmount and dentry but am still lost.