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代替,以后再看了。

          修改后代碼:

          主站蜘蛛池模板: 长顺县| 云阳县| 若尔盖县| 辽阳县| 荆州市| 龙里县| 曲沃县| 成安县| 临海市| 津南区| 安图县| 深泽县| 涟水县| 都昌县| 通榆县| 新蔡县| 南丹县| 宝鸡市| 冕宁县| 阳信县| 醴陵市| 宁乡县| 曲阜市| 商城县| 房产| 寻乌县| 泰顺县| 屏东市| 永城市| 青铜峡市| 吴堡县| 泰兴市| 巩义市| 兴仁县| 德清县| 齐齐哈尔市| 澜沧| 云林县| 伊金霍洛旗| 景德镇市| 板桥市|