[以解決] 請問Linux 3.0.4 register_sysctl_table的用法

看板LinuxDev作者 (evilkiss)時間9年前 (2015/02/05 15:34), 9年前編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
原本是使用linux kernel 2.6.28 改成 linux kernel 3.0.4後 卻發現cat /proc/sys/dev/file 讀到的資料變成亂碼 且是持續產生 Linux 2.6.28 :(如預期) sysctl /proc/sys/dev/file .proc.sys.dev.file = 0 0 0 0 0 0 0 0 cat /proc/sys/dev/file 0 0 0 0 0 0 0 0 Linux 3.0.4 : (不如預期的結果) sysctl /proc/sys/dev/file kernel.sched_child_runs_first = 0 kernel.sched_rt_period_us = 1000000 kernel.sched_rt_runtime_us = 950000 .....一大堆資訊 但就是沒有需要的 還出現別的file的值 cat /proc/sys/dev/file 一堆不斷出現的亂碼 (但貼到PTT上卻變成 rnel.sched_child_runs_first = 0 kernel.sched_rt_period_us = 10 .... 等 跟sysctl指令結果一樣的資訊) 不知道有沒有人有類似的經驗 或是知道3.0.4的用法?? code 如下 : ctl_table dev_table[] = { { //.ctl_name = DEV_FILE, Linux 3.0.4 此變數被移除了 .procname = "file", .maxlen = 8*sizeof(int), .mode = 0644, .data = file_table, .proc_handler = &file_proc_handler, //如果改成proc_dointvec_minmax 就正常....但想要接別的功能 //.strategy = &sysctl_intvec, Linux 3.0.4 此變數被移除了 .extra1 = &file_min, .extra2 = &file_max, }, {0} }; static int file_proc_handler(ctl_table *ctl, int write, struct file *filp, void *buffer, size_t *lenp, loff_t *offp) { int ret; ret = proc_dointvec_minmax(ctl, write, buffer, lenp, offp); if(write && !strcmp(ctl->procname,"file")){ file_handler(); //show on the led } return ret; } 自己找到正確方法了 自己試出答案 複製 fs/drop_caches.c drop_caches_sysctl_handler()的作法 { int ret; /*add min and max value check*/ ret = proc_dointvec_minmax(ctl, write, buffer, lenp, offp); if(ret) return ret; if (write){ led_handler(); //show on the led } return 0; } ctl_table root_table[] = { {"dev", NULL, 0, 0555, dev_table}, } 最後在driver_init() 註冊 register_sysctl_table(root_table); -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.124.125.144 ※ 文章網址: https://www.ptt.cc/bbs/LinuxDev/M.1423121698.A.F17.html ※ 編輯: evilkiss (59.124.125.144), 02/05/2015 15:52:30 ※ 編輯: evilkiss (59.124.125.144), 02/05/2015 18:10:15

02/07 02:05, , 1F
下載kernel source 自己看結構如何@@?
02/07 02:05, 1F
※ 編輯: evilkiss (59.124.125.144), 02/12/2015 18:39:18
文章代碼(AID): #1KqnqYyN (LinuxDev)