이 링크 (http://www.spinics.net/lists/newbies/msg41016.html)를 발견 했으니 까. 나는이 문서에서보고 된 이후 난 정말 혼란 스러워요 그래서리눅스 커널에서 파일의 크기를 어떻게 얻습니까?
/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’
:
#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);
때문에 컴파일되지 않습니다 : 그래서 커널 모듈에 코드를 작성 지금 http://lxr.free-electrons.com/source/fs/stat.c#L40
및 I /linux/fs.h에서 vfs_getattr의 프로토 타입은 다음과 같습니다.
extern int vfs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
아무도 내 구현 도와 드릴까요? 나는 vfsmount와 dentry를 읽고 있지만 여전히 길을 잃고 있습니다.
"리눅스 커널에서"- 커널 랜드 코드를 작성하려고한다는 뜻입니까? 그렇지 않다면, 단지'stat()'또는'ftell()'. –
예 이것은 커널 모듈 내부에 있습니다. – wright8191