【文章內(nèi)容簡介】
rld模塊程序編寫一個(gè)簡單的 Makefile,如下所示: objm := ? 并使用如下命令編譯 HelloWorld模塊,如下所示: $ make C /usr/src/? 如果當(dāng)前處于模塊所在的目錄,以下命令與上述命令同等: $ make –C /usr/src/ M=$(pwd) modules 設(shè)備驅(qū)動(dòng)編程基礎(chǔ) 17 ? Linux內(nèi)核模塊編程 ? Linux內(nèi)核模塊編程 ? 模塊與 GPL ? 對(duì)于自己編寫的驅(qū)動(dòng)等內(nèi)核代碼,如果不編譯為模塊則無法繞開 GPL,編譯為模塊后企業(yè)在產(chǎn)品中使用模塊。 設(shè)備驅(qū)動(dòng)編程基礎(chǔ) 18 ? Linux內(nèi)核模塊編程 ? Linux內(nèi)核模塊編程 ? 內(nèi)核模塊示例 設(shè)備驅(qū)動(dòng)編程基礎(chǔ) 19 ? 字符設(shè)備驅(qū)動(dòng)編程 用 戶 調(diào) 用模 塊 i n i t _ m o d u l e ( ) c l e a n u p _ m o d u l e ( )內(nèi) 核注 冊(cè) 設(shè) 備卸 載 設(shè) 備設(shè) 備 功 能 i n s m o d r m m o d20 ? 重要數(shù)據(jù)結(jié)構(gòu) ? file_operations struct file_operations { loff_t (*llseek) (struct file *, loff_t, int)。 ssize_t (*read) (struct file *filp, char *buff, size_t count, loff_t *offp)。 ssize_t (*write) (struct file *filp, const char *buff, size_t count, loff_t *offp)。 int (*readdir) (struct file *, void *, filldir_t)。 unsigned int (*poll) (struct file *, struct poll_table_struct *)。 int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long)。 int (*mmap) (struct file *, struct vm_area_struct *)。 int (*open) (struct inode *, struct file *)。 int (*flush) (struct file *)。 int (*release) (struct inode *, struct file *)。 int (*fsync) (struct file *, struct dentry *)。 int (*fasync) (int, struct file *, int)。 int (*check_media_change) (kdev_t dev)。 int (*revalidate) (kdev_t dev)。 int (*lock) (struct file *, int, struct file_lock *)。 }。 字符設(shè)備驅(qū)動(dòng)編程 21 ? 重要數(shù)據(jù)結(jié)構(gòu) ? struct