iT邦幫忙

DAY 17
0

Linux kernel模組的開發系列 第 17

file_operations 資料結構

file_operations 資料結構是 Linux character device 的核心,程式呼叫到 kernel moduel 的動作時,實際上都是引用透過這個資料結構所定義的內容。像我們在介紹 /proc 檔案系統中所介紹的 "hello_proc” 程式,裡頭的 file_operations 資料結構是這樣的:

static const struct file_operations hello_proc_fops = {
  .owner = THIS_MODULE,
  .open = hello_proc_open,
  .read = seq_read,
  .llseek = seq_lseek,
  .release = single_release,
};

在這裡 hello_proc_fops 定義了 5 個動作: owner, open, read, llseek, release。owner 指向擁有該結構的 module 業就是這裡的 hello_proc。open 定義當開啟 module 時要進行的動作,也就是執行 hello_proc_open 函數,在這裡他最終會印出 Hello proc! 而 read 跟 llseek 都是作為讀取 module 時的動作,release 則是在 unload module 要做的動作。


上一篇
/proc 檔案系統
下一篇
寫入與讀取 /proc 檔案
系列文
Linux kernel模組的開發30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言