1.fatal error:asm/system.h:No such file or directory
1 #include <linux/version.h> 2 #if LINUX_VERSION_CODE > KERNEL_VERSION(3, 3, 0) 3 #include <asm/switch_to.h> 4 #else 5 #include <asm/system.h> 6 #endif
2.error:type defaults to ‘int‘ in declaration specifiers
static memory_major = MEMORY_MAJOR;
static int memory_major = MEMORY_MAJOR;
3.error: unknown field ‘ioctl’ specified in initializer
1 static const struct file_operations globalmem_fops = 2 { 3 .owner = THIS_MODULE, 4 .llseek = globalmem_llseek, 5 .read = globalmem_read, 6 .write = globalmem_write, 7 //.ioctl 改为 .compat_ioctl 8 .compat_ioctl = globalmem_ioctl, 9 .open = globalmem_open, 10 .release = globalmem_release, 11 };
4.error: implicit declaration of function ‘kmalloc’
error: implicit declaration of function ‘kfree’
1 #include <linux/slab.h>
5.error: function declaration isn‘t a prototype
int memory init()
1 int memory init(void)
6.insmod: error inserting ‘memory.ko‘: -1 Device or resource busy
cat /proc/devices
主设备号冲突
1 //#define MEMORY_MAJOR 254 /*预设的globalmem的主设备号*/ 2 #define MEMORY_MAJOR 255 /*预设的globalmem的主设备号*/
7.cat: /dev/memory: No such device or address
把globalmem_read函数中的if (p >= GLOBALMEM_SIZE)改为if (p >GLOBALMEM_SIZE)就好了。具体原因是一次调用cat会读两次,每次读取4096个字节,此时文件读指针ppos就是4096了,在第二次读的时候,到if (p >=GLOBALMEM_SIZE)这里条件为真,globalmem_read就返回ENXIO错误了,所以才会出现No such device orbaddress"错误。
返回错误值才是正确的,因为读的位置已经越界,所以要返回错误。该返回错误的时候返回正确,那就是错误。改成if (p >GLOBALMEM_SIZE)是错误的。