posts - 403, comments - 310, trackbacks - 0, articles - 7
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          讀核筆記(2) - 內核模塊

          Posted on 2008-02-10 18:53 ZelluX 閱讀(921) 評論(0)  編輯  收藏 所屬分類: LinuxSystem
          /proc文件系統不是直接從內核的存儲區中讀寫數據,二是通過回調函數實現文件讀寫的。struct proc_dir_entry有一對讀寫操作函數指針read_proc_t, write_proc_t。
          一個編寫內核模塊操作proc文件系統的例子,書上的源程序是在2.4.18下跑起來的,改了三個地方在2.6.23下成功運行。當然Makefile也按照2.6中make modules的方式寫了。

          1. 去掉MODULE_VERSION宏的定義,和頭文件沖突。
          2. 去掉MOD_INC_USE_COUNT和MOD_DEC_USE_COUNT,2.6中的改變

          Preventing premature unloading

          In 2.4 modules, the MOD_INC_USE_COUNT macro is used to prevent unloading of the module while there is an open file. The 2.6 kernel, however, knows not to unload a module that owns a character device that's currently open.

          However, this requires that the module be explicit in specifying ownership of character devices, using the THIS_MODULE macro. You also have to take out all calls to MOD_INC_USE_COUNT and MOD_DEC_USE_COUNT.

          The 2.6 kernel considers modules that use the deprecated facility to be unsafe, and does not permit their unloading, even with rmmod -f.

          3. 去掉proc_mknod增加一個tty設備文件那部分代碼,2.6中去掉了這個函數,貌似要用udev代替,以后再看了。

          修改后代碼:

          主站蜘蛛池模板: 抚远县| 左权县| 沈阳市| 白水县| 广汉市| 和田县| 汶川县| 内丘县| 舒兰市| 温州市| 盐源县| 三都| 读书| 蛟河市| 西峡县| 咸宁市| 象山县| 大兴区| 平乐县| 洞口县| 龙州县| 桐乡市| 亚东县| 安陆市| 大丰市| 江孜县| 逊克县| 昭苏县| 南城县| 台东市| 淅川县| 措美县| 望奎县| 翁源县| 泾阳县| 达尔| 乌鲁木齐市| 麻江县| 色达县| 合阳县| 岳普湖县|