Interfaces in Proc and SYS used in Linux debugging

Source: Internet
Author: User

During the debugging process, we usually need to constantly modify the value of the Register to debug the effect. Now we find that there are two ways to use proc and SYS respectively.
Proc -- |
| ----- Read_proc
| ----- Write_proc

Sys --- |
| ----- Show
| ----- Store

The proc method does not depend on kobject. In sys, show and store depend on kobject.
The basic usage is as follows:
----------------------------------------------------------------------
-------------------------- Start proc ----------------------------
----------------------------------------------------------------------

struct proc_dir_entry *prEntry;    prEntry = create_proc_entry("driver/proc_func", 0, NULL);     if (prEntry) {        prEntry->read_proc = read_proc_func;         prEntry->write_proc = write_proc_func;     }    else {        printk("add /proc/driver/camsensor entry fail \n");      }

For the definitions of read_proc and write_proc, refer to the definition in proc_fs.h to implement

/* * This is not completely implemented yet. The idea is to * create an in-memory tree (like the actual /proc filesystem * tree) of these proc_dir_entries, so that we can dynamically * add new files to /proc. * * The "next" pointer creates a linked list of one /proc directory, * while parent/subdir create the directory structure (every * /proc file has a parent, but "subdir" is NULL for all * non-directory entries). */typedefint (read_proc_t)(char *page, char **start, off_t off,  int count, int *eof, void *data);typedefint (write_proc_t)(struct file *file, const char __user *buffer,   unsigned long count, void *data);

----------------------------------------------------------------------
-------------------------- End proc ---------------------------
----------------------------------------------------------------------

Using sys to implement interface debugging is as follows, provided that a device is available.
---------------------------------------------------------------------
-------------------------- Start sys --------------------------
---------------------------------------------------------------------

static struct device_attribute test1_attr = {.attr = {.name = "test1",.mode = 0644,.owner = THIS_MODULE},.show = test1_show_func,.store = test1_store_func,};static struct device_attribute *test_attributes[] = {&test1_attr,&test2_attr,&test3_attr,};for (i = 0; i < ARRAY_SIZE(*test_attributes); i++) {ret = device_create_file(&dev,*test_attributes[i]);if (ret) {printk("failed: sysfs file %s\n",*test_attributes[i]->attr.name);goto failed_unregister_dev_file;}}

The functions of show and store are defined as follows:

/* interface for exporting device attributes */struct device_attribute {struct attributeattr;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);};

---------------------------------------------------------------------
-------------------------- End sys --------------------------
----------------------------------------------------------------------

These two methods can be used to debug LCM or camera without re-compilation, which is very helpful for debugging.

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.