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

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

          Posted on 2008-02-10 18:53 ZelluX 閱讀(914) 評論(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代替,以后再看了。

          修改后代碼:

          主站蜘蛛池模板: 甘孜| 广宁县| 新沂市| 松滋市| 木兰县| 紫阳县| 盖州市| 衡南县| 嘉黎县| 尖扎县| 尼木县| 广安市| 阜阳市| 广灵县| 新津县| 上饶市| 观塘区| 永昌县| 克山县| 施甸县| 喀喇沁旗| 武鸣县| 岚皋县| 永嘉县| 伊川县| 富源县| 出国| 白山市| 宝应县| 濉溪县| 明水县| 鄱阳县| 邵武市| 泗洪县| 突泉县| 华蓥市| 平阴县| 敦化市| 西城区| 宣威市| 张北县|