Use of kobject in Linux Device Model

Source: Internet
Author: User

To create a directory under the/sys/directory, You need to register a kobject structure with the kernel. This structure is a carrier of the directory. The attribute of this structure is saved by struct kobj_type. The method for registering kojbect is:/* initialize the kobject structure */void kobject_init (struct kobject * kobj ); /* register the kobject object to the Linux system */INT kobject_add (struct kobject * kobj); or combine the preceding two steps into one step: int kobject_init_and_add (struct kobject * kobj, struct kobj_type * ktypestruct kobject * parent, const char * FMT ,...); the file files and operations in the directory are defined in struct kobj_type: struct kobj_type {void (* release) (struct kobject * kobj); struct sysfs_ops * sysfs_ops; /* file operation */struct attribute ** default_attrs;/* file definition */}; File Operations: Struct sysfs_ops {ssize_t (* Show) (struct kobject * kobj, struct attribute * ATTR, char * buffer); ssize_t (* store) (struct kobject * kobj, struct attribute * ATTR, const char * buffer, size_t size) ;}; show: This function is called when the user reads the attribute file. This function saves the attribute value to the buffer and returns it to the user State. Store: when a user writes an attribute file, this function is called to store the attribute values passed by the user. File definition: The files in the directory are defined by the struct attribute ** default_attrs; array. The structure is as follows: struct attribute {char * Name;/* attribute file name */struct module * owner; mode_t mode; /* attribute protection space */};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.