Quantcast
Channel: Active questions tagged kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 6334

How do you get the size of a file in the linux kernel?

$
0
0

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 typeinclude/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 typeinclude/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.


Viewing all articles
Browse latest Browse all 6334

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>