调试Linux内核,在vfs_write()中获取当前文件写所属的硬盘盘符,添加以下主要代码。但编译时,报错“error: dereferencing pointer to incomplete type”。仔细检查了代码,也没发现错误。
最后感觉是struct gendisk的定义没找到,在read_write.c文件头添加包含linux/blkdev.h后,编译通过。
#include <linux/blkdev.h>
struct gendisk *disk;
if(file->f_path.dentry->d_inode && file->f_path.dentry->d_inode->i_bdev)
disk = file->f_path.dentry->d_inode->i_bdev->bd_disk;
[root@root /zlib/linux-3.10.0-327.x86_64]
#make -j64
make[1]: Nothing to be done for `all’.
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
CC scripts/mod/devicetable-offsets.s
GEN scripts/mod/devicetable-offsets.h
HOSTCC scripts/mod/file2alias.o
HOSTLD scripts/mod/modpost
make[1]: Nothing to be done for `relocs’.
make[1]: `arch/x86/purgatory/kexec-purgatory.c’ is up to date.
CALL scripts/checksyscalls.sh
CHK include/generated/compile.h
make[3]: `arch/x86/realmode/rm/realmode.bin’ is up to date.
CC fs/read_write.o
fs/read_write.c: In function ‘vfs_write’:
fs/read_write.c:527:24: error: dereferencing pointer to incomplete type
if(disk && strstr(disk->disk_name, “rb”))
^
fs/read_write.c:531:87: error: dereferencing pointer to incomplete type
tsc-prev_tsc, total_tsc/count, w_count, file->f_path.dentry->d_iname, *pos, disk->disk_name);
^
make[1]: *** [fs/read_write.o] Error 1
make[1]: *** Waiting for unfinished jobs….
make: *** [fs] Error 2
make: *** Waiting for unfinished jobs….
make: *** wait: No child processes. Stop.
[root@root /zlib/linux-3.10.0-327.x86_64]
Leave a Reply