202609142132_《Unix(唯一) sample code》

// 内核中的 file 结构体(简化版)
struct file {
    struct file_operations *f_op;  // 函数指针表
    void *private_data;            // 具体设备数据
    int f_flags;
    loff_t f_pos;
};

// 每种设备实现这些操作
struct file_operations {
    ssize_t (*read)(struct file *, char *, size_t, loff_t *);
    ssize_t (*write)(struct file *, const char *, size_t, loff_t *);
    int (*open)(struct inode *, struct file *);
    int (*release)(struct inode *, struct file *);
};

 

posted @ 2026-09-14 21:34  Coca-code  阅读(3)  评论(0)    收藏  举报