天天看點

attribute/device_attribute/driver_attrivute ...

在include/linux/device.h中定義了

struct attribute {
    const char      *name;
    mode_t          mode;
};      
struct device_attribute {
    struct attribute    attr;
    ssize_t (*show)(struct device *dev, struct device_attribute *attr, char *buf);
    ssize_t (*store)(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
};      
struct driver_attribute {
    struct attribute attr;
    ssize_t (*show)(struct device_driver *driver, char *buf);
    ssize_t (*store)(struct device_driver *driver, const char *buf,
             size_t count);
};      
struct class_attribute {
    struct attribute attr;
    ssize_t (*show)(struct class *class, struct class_attribute *attr, char *buf);
    ssize_t (*store)(struct class *class, struct class_attribute *attr, const char *buf, size_t count);
};      

在/include/linux/sysfs.h中定義了

struct bin_attribute {
    struct attribute    attr;
    size_t          size;
    void            *private;
    ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *, char *, loff_t, size_t);
    ssize_t (*write)(struct file *,struct kobject *, struct bin_attribute *, char *, loff_t, size_t);
    int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr, struct vm_area_struct *vma);
};      
struct class {
    const char      *name;
    struct module       *owner;
    struct class_attribute      *class_attrs;
    struct device_attribute     *dev_attrs;
    struct bin_attribute        *dev_bin_attrs;
…
};      
struct attribute_group {
    const char      *name;
    mode_t          (*is_visible)(struct kobject *, struct attribute *, int);
    struct attribute    **attrs;
};      

繼續閱讀