{"id":81970,"date":"2026-07-25T05:27:39","date_gmt":"2026-07-24T21:27:39","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/81970.html"},"modified":"2026-07-25T05:27:39","modified_gmt":"2026-07-24T21:27:39","slug":"linux%e5%ad%97%e7%ac%a6%e8%ae%be%e5%a4%87%e9%a9%b1%e5%8a%a8%e7%9a%84%e5%ae%8c%e6%95%b4%e7%94%9f%e5%91%bd%e5%91%a8%e6%9c%9f%ef%bc%9a%e4%bb%8einsmod%e5%88%b0rmmod%e7%9a%84%e7%8a%b6%e6%80%81%e7%ae%a1","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/81970.html","title":{"rendered":"Linux\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f\uff1a\u4eceinsmod\u5230rmmod\u7684\u72b6\u6001\u7ba1\u7406\u4e0esysfs\u63a5\u53e3\u8bbe\u8ba1"},"content":{"rendered":"<h2>Linux\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f&#xff1a;\u4eceinsmod\u5230rmmod\u7684\u72b6\u6001\u7ba1\u7406\u4e0esysfs\u63a5\u53e3\u8bbe\u8ba1<\/h2>\n<h3>\u4e00\u3001\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u4e0d\u662f\u7b80\u5355\u7684\u8bfb\u5199\u51fd\u6570<\/h3>\n<p>\u521d\u5b66\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u65f6\u5bb9\u6613\u8bef\u89e3&#xff1a;\u5199\u597dopen\/read\/write\/release\u56db\u4e2a\u56de\u8c03&#xff0c;\u6ce8\u518c\u4e00\u4e2a\u8bbe\u5907\u53f7&#xff0c;\u5c31\u5b8c\u6210\u4e86\u3002\u4f46\u751f\u4ea7\u7ea7\u9a71\u52a8\u5fc5\u987b\u5904\u7406\u5b8c\u6574\u7684\u751f\u547d\u5468\u671f\u2014\u2014\u6a21\u5757\u52a0\u8f7d\u65f6\u7684\u8d44\u6e90\u521d\u59cb\u5316\u3001\u8bbe\u5907\u521b\u5efa\u4e0esysfs\u63a5\u53e3\u3001\u5f15\u7528\u8ba1\u6570\u9632\u6b62\u70ed\u62d4\u62d4\u65f6\u6a21\u5757\u88ab\u63d0\u524d\u5378\u8f7d\u3001\u6a21\u5757\u5378\u8f7d\u65f6\u7684\u8d44\u6e90\u91ca\u653e\u987a\u5e8f\u3002\u5ffd\u7565\u4efb\u4f55\u4e00\u4e2a\u73af\u8282\u90fd\u4f1a\u5bfc\u81f4\u5185\u6838\u5d29\u6e83\u6216\u8d44\u6e90\u6cc4\u6f0f\u3002<\/p>\n<h3>\u4e8c\u3001\u751f\u547d\u5468\u671f\u72b6\u6001\u673a\u4e0e\u5173\u952e\u8282\u70b9<\/h3>\n<p>\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7684\u751f\u547d\u5468\u671f\u7531\u4e94\u4e2a\u72b6\u6001\u7ec4\u6210&#xff1a;<\/p>\n<table>\n<tr>\u72b6\u6001\u89e6\u53d1\u6761\u4ef6\u5173\u952e\u52a8\u4f5c<\/tr>\n<tbody>\n<tr>\n<td>UNINIT<\/td>\n<td>\u6a21\u5757\u672a\u52a0\u8f7d<\/td>\n<td>\u65e0<\/td>\n<\/tr>\n<tr>\n<td>INIT<\/td>\n<td>insmod\u6267\u884c<\/td>\n<td>\u6ce8\u518c\u8bbe\u5907\u53f7\u3001\u521b\u5efacdev\u3001\u521d\u59cb\u5316\u786c\u4ef6<\/td>\n<\/tr>\n<tr>\n<td>ACTIVE<\/td>\n<td>\u8bbe\u5907\u8282\u70b9\u88ab\u6253\u5f00<\/td>\n<td>\u5f15\u7528\u8ba1\u6570&#043;1<\/td>\n<\/tr>\n<tr>\n<td>BUSY<\/td>\n<td>\u6709\u8fdb\u7a0b\u6301\u6709fd<\/td>\n<td>\u5f15\u7528\u8ba1\u6570&gt;0&#xff0c;\u7981\u6b62rmmod<\/td>\n<\/tr>\n<tr>\n<td>CLEANUP<\/td>\n<td>rmmod\u6267\u884c\u4e14\u5f15\u7528\u8ba1\u6570&#061;0<\/td>\n<td>\u91ca\u653ecdev\u3001\u6ce8\u9500\u8bbe\u5907\u53f7\u3001\u91ca\u653e\u786c\u4ef6\u8d44\u6e90<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u751f\u547d\u5468\u671f\u72b6\u6001\u673a<\/h4>\n<p>stateDiagram-v2<br \/>\n    [*] &#8211;&gt; UNINIT: \u6a21\u5757\u6e90\u7801\u7f16\u8bd1<br \/>\n    UNINIT &#8211;&gt; INIT: insmod\u6267\u884c<br \/>\n    INIT &#8211;&gt; ACTIVE: cdev_add\u6210\u529f \u8bbe\u5907\u53ef\u7528<\/p>\n<p>    ACTIVE &#8211;&gt; BUSY: open() \u5f15\u7528\u8ba1\u6570&#043;1<br \/>\n    BUSY &#8211;&gt; BUSY: \u591a\u6b21open() \u8ba1\u6570\u9012\u589e<br \/>\n    BUSY &#8211;&gt; ACTIVE: release() \u8ba1\u6570-1\u52300<\/p>\n<p>    ACTIVE &#8211;&gt; CLEANUP: rmmod\u4e14\u8ba1\u6570&#061;0<br \/>\n    BUSY &#8211;&gt; WAITING: rmmod\u4f46\u8ba1\u6570&gt;0 \u7b49\u5f85\u91ca\u653e<br \/>\n    WAITING &#8211;&gt; ACTIVE: \u6240\u6709fd\u5173\u95ed \u8ba1\u6570\u5f52\u96f6 \u81ea\u52a8\u5378\u8f7d<\/p>\n<p>    CLEANUP &#8211;&gt; UNINIT: \u91ca\u653e\u5b8c\u6210<\/p>\n<p>    note right of BUSY: try_module_get \u589e\u52a0\u6a21\u5757\u5f15\u7528\u8ba1\u6570<br \/>\n    note right of ACTIVE: module_put \u51cf\u5c11\u6a21\u5757\u5f15\u7528\u8ba1\u6570<\/p>\n<p>\u6838\u5fc3\u7ea6\u675f&#xff1a;try_module_get\u5728open\u65f6\u589e\u52a0\u6a21\u5757\u5f15\u7528\u8ba1\u6570&#xff0c;module_put\u5728release\u65f6\u51cf\u5c11\u3002\u5f15\u7528\u8ba1\u6570&gt;0\u65f6rmmod\u4f1a\u88ab\u62d2\u7edd&#xff0c;\u4fdd\u8bc1\u6b63\u5728\u4f7f\u7528\u7684\u6a21\u5757\u4e0d\u4f1a\u88ab\u5378\u8f7d\u3002<\/p>\n<h3>\u4e09\u3001\u5f15\u7528\u8ba1\u6570\u4e0e\u70ed\u63d2\u62d4\u7684\u5b9e\u73b0\u673a\u5236<\/h3>\n<h4>\u6a21\u5757\u5f15\u7528\u8ba1\u6570<\/h4>\n<p>\u5185\u6838\u901a\u8fc7struct module\u7684refcnt\u5b57\u6bb5\u8ffd\u8e2a\u6a21\u5757\u5f15\u7528\u3002\u9a71\u52a8\u5fc5\u987b\u624b\u52a8\u7ef4\u62a4&#xff1a;<\/p>\n<p>\/* open\u56de\u8c03\u4e2d\u589e\u52a0\u5f15\u7528\u8ba1\u6570 *\/<br \/>\nstatic int dev_open(struct inode *inode, struct file *filp)<br \/>\n{<br \/>\n    if (!try_module_get(THIS_MODULE))<br \/>\n        return -ENODEV;  \/* \u6a21\u5757\u6b63\u5728\u5378\u8f7d&#xff0c;\u62d2\u7edd\u6253\u5f00 *\/<br \/>\n    filp-&gt;private_data &#061; &amp;dev_data;<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>\/* release\u56de\u8c03\u4e2d\u51cf\u5c11\u5f15\u7528\u8ba1\u6570 *\/<br \/>\nstatic int dev_release(struct inode *inode, struct file *filp)<br \/>\n{<br \/>\n    module_put(THIS_MODULE);<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>try_module_get\u800c\u975emodule_get&#xff1a;\u5982\u679c\u6a21\u5757\u6b63\u5728\u5378\u8f7d\u8fc7\u7a0b\u4e2d&#xff0c;try_module_get\u8fd4\u56de0&#xff08;\u5b89\u5168\u5931\u8d25&#xff09;&#xff0c;\u800cmodule_get\u4f1a\u76f4\u63a5\u589e\u52a0\u8ba1\u6570\u5bfc\u81f4\u5378\u8f7d\u5931\u8d25&#xff08;\u4e0d\u5b89\u5168&#xff09;\u3002<\/p>\n<h4>\u70ed\u62d4\u62d4\u5904\u7406<\/h4>\n<p>\u70ed\u62d4\u62d4\u573a\u666f&#xff1a;\u8bbe\u5907\u7269\u7406\u79fb\u9664\u65f6&#xff0c;\u9a71\u52a8\u9700\u8981\u901a\u77e5\u6240\u6709\u6301\u6709fd\u7684\u8fdb\u7a0b&#xff0c;\u5e76\u7b49\u5f85\u5b83\u4eec\u5173\u95edfd\u540e\u518d\u5378\u8f7d\u6a21\u5757\u3002<\/p>\n<p>static void handle_hot_unplug(void)<br \/>\n{<br \/>\n    \/* \u901a\u77e5\u7528\u6237\u7a7a\u95f4\u8bbe\u5907\u5df2\u79fb\u9664 *\/<br \/>\n    sysfs_notify(&amp;dev_data.dev.kobj, NULL, &#034;status&#034;);<\/p>\n<p>    \/* \u6807\u8bb0\u8bbe\u5907\u4e0d\u53ef\u7528&#xff0c;\u540e\u7eedopen\u62d2\u7edd *\/<br \/>\n    dev_data.removed &#061; true;<\/p>\n<p>    \/* \u7b49\u5f85\u6240\u6709\u6301\u6709\u8005\u91ca\u653e *\/<br \/>\n    while (dev_data.open_count &gt; 0) {<br \/>\n        msleep(100);<br \/>\n    }<br \/>\n    \/* \u6240\u6709fd\u5df2\u5173\u95ed&#xff0c;\u53ef\u4ee5\u5b89\u5168\u5378\u8f7d *\/<br \/>\n}<\/p>\n<h3>\u56db\u3001sysfs\u63a5\u53e3\u8bbe\u8ba1\u4e0e\u5b8c\u6574\u9a71\u52a8\u4ee3\u7801<\/h3>\n<p>sysfs\u63a5\u53e3\u662f\u9a71\u52a8\u4e0e\u7528\u6237\u7a7a\u95f4\u7684\u914d\u7f6e\u901a\u9053\u3002\u6bcf\u4e2a\u5c5e\u6027\u6587\u4ef6\u5bf9\u5e94\u4e00\u4e2ashow\/store\u56de\u8c03\u3002\u8bbe\u8ba1\u539f\u5219&#xff1a;<\/p>\n<li>\u53ea\u66b4\u9732\u914d\u7f6e\u53c2\u6570\u548c\u72b6\u6001\u4fe1\u606f&#xff0c;\u4e0d\u66b4\u9732\u5185\u90e8\u5b9e\u73b0\u7ec6\u8282<\/li>\n<li>store\u56de\u8c03\u5fc5\u987b\u9a8c\u8bc1\u8f93\u5165\u503c\u7684\u5408\u6cd5\u6027<\/li>\n<li>\u5c5e\u6027\u6587\u4ef6\u6743\u9650\u4e25\u683c\u533a\u5206&#xff1a;\u914d\u7f6e\u6587\u4ef6\u53ea\u5141\u8bb8root\u5199\u5165&#xff0c;\u72b6\u6001\u6587\u4ef6\u5bf9\u6240\u6709\u4eba\u53ea\u8bfb<\/li>\n<h4>\u5b8c\u6574\u9a71\u52a8\u4ee3\u7801<\/h4>\n<p>#include &lt;linux\/module.h&gt;<br \/>\n#include &lt;linux\/kernel.h&gt;<br \/>\n#include &lt;linux\/fs.h&gt;<br \/>\n#include &lt;linux\/cdev.h&gt;<br \/>\n#include &lt;linux\/device.h&gt;<br \/>\n#include &lt;linux\/slab.h&gt;<br \/>\n#include &lt;linux\/uaccess.h&gt;<br \/>\n#include &lt;linux\/kobject.h&gt;<\/p>\n<p>#define DEVICE_NAME &#034;mydev&#034;<br \/>\n#define CLASS_NAME  &#034;mydev_class&#034;<br \/>\n#define BUF_SIZE    4096<\/p>\n<p>static dev_t dev_num;<br \/>\nstatic struct cdev my_cdev;<br \/>\nstatic struct class *my_class;<br \/>\nstatic struct device *my_device;<\/p>\n<p>struct dev_private {<br \/>\n    char buffer[BUF_SIZE];<br \/>\n    size_t data_len;<br \/>\n    bool removed;<br \/>\n    int open_count;<br \/>\n    int max_buffer_size;     \/* \u53ef\u914d\u7f6e\u53c2\u6570 *\/<br \/>\n};<\/p>\n<p>static struct dev_private dev_data &#061; {<br \/>\n    .max_buffer_size &#061; BUF_SIZE,<br \/>\n};<\/p>\n<p>\/* &#8212;- sysfs\u5c5e\u6027 &#8212;- *\/<\/p>\n<p>static ssize_t status_show(<br \/>\n    struct device *dev, struct device_attribute *attr, char *buf)<br \/>\n{<br \/>\n    return sprintf(buf,<br \/>\n        &#034;open_count: %d\\\\n&#034;<br \/>\n        &#034;data_len: %zu\\\\n&#034;<br \/>\n        &#034;removed: %d\\\\n&#034;<br \/>\n        &#034;max_buffer_size: %d\\\\n&#034;,<br \/>\n        dev_data.open_count,<br \/>\n        dev_data.data_len,<br \/>\n        dev_data.removed,<br \/>\n        dev_data.max_buffer_size);<br \/>\n}<\/p>\n<p>static ssize_t max_buffer_size_store(<br \/>\n    struct device *dev, struct device_attribute *attr,<br \/>\n    const char *buf, size_t count)<br \/>\n{<br \/>\n    int new_size;<br \/>\n    if (kstrtoint(buf, 10, &amp;new_size))<br \/>\n        return -EINVAL;<br \/>\n    if (new_size &lt; 1 || new_size &gt; BUF_SIZE)<br \/>\n        return -EINVAL;<br \/>\n    dev_data.max_buffer_size &#061; new_size;<br \/>\n    return count;<br \/>\n}<\/p>\n<p>static DEVICE_ATTR(status, 0444, status_show, NULL);<br \/>\nstatic DEVICE_ATTR(max_buffer_size, 0644, NULL, max_buffer_size_store);<\/p>\n<p>\/* &#8212;- \u6587\u4ef6\u64cd\u4f5c &#8212;- *\/<\/p>\n<p>static int dev_open(struct inode *inode, struct file *filp)<br \/>\n{<br \/>\n    if (dev_data.removed)<br \/>\n        return -ENODEV;<br \/>\n    if (!try_module_get(THIS_MODULE))<br \/>\n        return -ENODEV;<br \/>\n    dev_data.open_count&#043;&#043;;<br \/>\n    filp-&gt;private_data &#061; &amp;dev_data;<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>static int dev_release(struct inode *inode, struct file *filp)<br \/>\n{<br \/>\n    dev_data.open_count&#8211;;<br \/>\n    module_put(THIS_MODULE);<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>static ssize_t dev_read(<br \/>\n    struct file *filp, char __user *buf, size_t len, loff_t *off)<br \/>\n{<br \/>\n    struct dev_private *priv &#061; filp-&gt;private_data;<br \/>\n    if (*off &gt;&#061; priv-&gt;data_len)<br \/>\n        return 0;<br \/>\n    size_t to_copy &#061; min(len, priv-&gt;data_len &#8211; *off);<br \/>\n    if (copy_to_user(buf, priv-&gt;buffer &#043; *off, to_copy))<br \/>\n        return -EFAULT;<br \/>\n    *off &#043;&#061; to_copy;<br \/>\n    return to_copy;<br \/>\n}<\/p>\n<p>static ssize_t dev_write(<br \/>\n    struct file *filp, const char __user *buf, size_t len, loff_t *off)<br \/>\n{<br \/>\n    struct dev_private *priv &#061; filp-&gt;private_data;<br \/>\n    size_t to_copy &#061; min(len,<br \/>\n        (size_t)priv-&gt;max_buffer_size &#8211; *off);<br \/>\n    if (to_copy &#061;&#061; 0)<br \/>\n        return -ENOSPC;<br \/>\n    if (copy_from_user(priv-&gt;buffer &#043; *off, buf, to_copy))<br \/>\n        return -EFAULT;<br \/>\n    *off &#043;&#061; to_copy;<br \/>\n    priv-&gt;data_len &#061; *off;<br \/>\n    return to_copy;<br \/>\n}<\/p>\n<p>static struct file_operations fops &#061; {<br \/>\n    .owner   &#061; THIS_MODULE,<br \/>\n    .open    &#061; dev_open,<br \/>\n    .release &#061; dev_release,<br \/>\n    .read    &#061; dev_read,<br \/>\n    .write   &#061; dev_write,<br \/>\n};<\/p>\n<p>\/* &#8212;- \u6a21\u5757\u521d\u59cb\u5316\u4e0e\u5378\u8f7d &#8212;- *\/<\/p>\n<p>static int __init mydev_init(void)<br \/>\n{<br \/>\n    \/* \u52a8\u6001\u5206\u914d\u8bbe\u5907\u53f7 *\/<br \/>\n    if (alloc_chrdev_region(&amp;dev_num, 0, 1, DEVICE_NAME) &lt; 0)<br \/>\n        return -ENOMEM;<\/p>\n<p>    \/* \u521d\u59cb\u5316\u5e76\u6dfb\u52a0cdev *\/<br \/>\n    cdev_init(&amp;my_cdev, &amp;fops);<br \/>\n    my_cdev.owner &#061; THIS_MODULE;<br \/>\n    if (cdev_add(&amp;my_cdev, dev_num, 1) &lt; 0)<br \/>\n        goto fail_cdev;<\/p>\n<p>    \/* \u521b\u5efa\u8bbe\u5907\u7c7b\u548c\u8bbe\u5907\u8282\u70b9 *\/<br \/>\n    my_class &#061; class_create(CLASS_NAME);<br \/>\n    if (IS_ERR(my_class))<br \/>\n        goto fail_class;<\/p>\n<p>    my_device &#061; device_create(my_class, NULL, dev_num, NULL, DEVICE_NAME);<br \/>\n    if (IS_ERR(my_device))<br \/>\n        goto fail_device;<\/p>\n<p>    \/* \u521b\u5efasysfs\u5c5e\u6027\u6587\u4ef6 *\/<br \/>\n    device_create_file(my_device, &amp;dev_attr_status);<br \/>\n    device_create_file(my_device, &amp;dev_attr_max_buffer_size);<\/p>\n<p>    pr_info(&#034;mydev: \u521d\u59cb\u5316\u5b8c\u6210 major&#061;%d minor&#061;%d\\\\n&#034;,<br \/>\n            MAJOR(dev_num), MINOR(dev_num));<br \/>\n    return 0;<\/p>\n<p>fail_device:<br \/>\n    class_destroy(my_class);<br \/>\nfail_class:<br \/>\n    cdev_del(&amp;my_cdev);<br \/>\nfail_cdev:<br \/>\n    unregister_chrdev_region(dev_num, 1);<br \/>\n    return -1;<br \/>\n}<\/p>\n<p>static void __exit mydev_exit(void)<br \/>\n{<br \/>\n    \/* \u7b49\u5f85\u6240\u6709\u6301\u6709\u8005\u91ca\u653e *\/<br \/>\n    while (dev_data.open_count &gt; 0) {<br \/>\n        pr_warn(&#034;mydev: \u7b49\u5f85open_count\u5f52\u96f6 (%d)\\\\n&#034;,<br \/>\n                dev_data.open_count);<br \/>\n        msleep(100);<br \/>\n    }<\/p>\n<p>    \/* \u6309\u6ce8\u518c\u9006\u5e8f\u91ca\u653e\u8d44\u6e90 *\/<br \/>\n    device_remove_file(my_device, &amp;dev_attr_status);<br \/>\n    device_remove_file(my_device, &amp;dev_attr_max_buffer_size);<br \/>\n    device_destroy(my_class, dev_num);<br \/>\n    class_destroy(my_class);<br \/>\n    cdev_del(&amp;my_cdev);<br \/>\n    unregister_chrdev_region(dev_num, 1);<\/p>\n<p>    pr_info(&#034;mydev: \u5378\u8f7d\u5b8c\u6210\\\\n&#034;);<br \/>\n}<\/p>\n<p>module_init(mydev_init);<br \/>\nmodule_exit(mydev_exit);<\/p>\n<p>MODULE_LICENSE(&#034;GPL&#034;);<br \/>\nMODULE_AUTHOR(&#034;zhongyiren&#034;);<br \/>\nMODULE_DESCRIPTION(&#034;\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u5b8c\u6574\u751f\u547d\u5468\u671f\u793a\u4f8b&#034;);<\/p>\n<p>\u8d44\u6e90\u91ca\u653e\u7684\u9006\u5e8f\u539f\u5219&#xff1a;sysfs\u5c5e\u6027\u2192\u8bbe\u5907\u8282\u70b9\u2192\u8bbe\u5907\u7c7b\u2192cdev\u2192\u8bbe\u5907\u53f7\u3002\u6bcf\u4e2a\u8d44\u6e90\u7684\u91ca\u653e\u987a\u5e8f\u5fc5\u987b\u4e0e\u6ce8\u518c\u987a\u5e8f\u4e25\u683c\u76f8\u53cd&#xff0c;\u5426\u5219\u4f1a\u4ea7\u751f dangling reference\u3002<\/p>\n<h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<li>\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7684\u751f\u547d\u5468\u671f\u7531\u4e94\u4e2a\u72b6\u6001\u6784\u6210&#xff1a;UNINIT\u2192INIT\u2192ACTIVE\u2192BUSY\u2192CLEANUP&#xff0c;\u6bcf\u4e2a\u72b6\u6001\u8f6c\u6362\u6709\u660e\u786e\u7684\u89e6\u53d1\u6761\u4ef6\u548c\u5173\u952e\u52a8\u4f5c<\/li>\n<li>\u5f15\u7528\u8ba1\u6570\u901a\u8fc7try_module_get\/module_put\u7ef4\u62a4&#xff0c;open\u65f6\u589e\u52a0\u3001release\u65f6\u51cf\u5c11&#xff0c;\u8ba1\u6570&gt;0\u65f6rmmod\u88ab\u62d2\u7edd\u4fdd\u8bc1\u5b89\u5168<\/li>\n<li>\u70ed\u62d4\u62d4\u5904\u7406\u9700\u8981\u6807\u8bb0\u8bbe\u5907\u4e0d\u53ef\u7528\u3001\u901a\u77e5\u7528\u6237\u7a7a\u95f4\u3001\u7b49\u5f85\u6240\u6709fd\u5173\u95ed\u540e\u624d\u6267\u884c\u5378\u8f7d&#xff0c;\u4e0d\u80fd\u5f3a\u5236\u5378\u8f7d\u6b63\u5728\u4f7f\u7528\u7684\u6a21\u5757<\/li>\n<li>sysfs\u63a5\u53e3\u8bbe\u8ba1\u539f\u5219&#xff1a;\u53ea\u66b4\u9732\u914d\u7f6e\u548c\u72b6\u6001\u3001store\u56de\u8c03\u5fc5\u987b\u9a8c\u8bc1\u8f93\u5165\u3001\u6743\u9650\u4e25\u683c\u533a\u5206root\u5199\u5165\u4e0e\u53ea\u8bfb<\/li>\n<li>\u8d44\u6e90\u91ca\u653e\u5fc5\u987b\u6309\u6ce8\u518c\u9006\u5e8f\u6267\u884c&#xff1a;sysfs\u2192device\u2192class\u2192cdev\u2192chrdev_region&#xff0c;\u9006\u5e8f\u91ca\u653e\u907f\u514ddangling reference\u5bfc\u81f4\u7684\u5185\u6838\u5d29\u6e83<\/li>\n","protected":false},"excerpt":{"rendered":"<p>Linux\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f&#xff1a;\u4eceinsmod\u5230rmmod\u7684\u72b6\u6001\u7ba1\u7406\u4e0esysfs\u63a5\u53e3\u8bbe\u8ba1<br \/>\n\u4e00\u3001\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u4e0d\u662f\u7b80\u5355\u7684\u8bfb\u5199\u51fd\u6570<br \/>\n\u521d\u5b66\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u65f6\u5bb9\u6613\u8bef\u89e3&#xff1a;\u5199\u597dopen\/read\/write\/release\u56db\u4e2a\u56de\u8c03&#xff0c;\u6ce8\u518c\u4e00\u4e2a\u8bbe\u5907\u53f7&#xff0c;\u5c31\u5b8c\u6210\u4e86\u3002\u4f46\u751f\u4ea7\u7ea7\u9a71\u52a8\u5fc5\u987b\u5904\u7406\u5b8c\u6574\u7684\u751f\u547d\u5468\u671f\u2014\u2014\u6a21\u5757\u52a0\u8f7d\u65f6\u7684\u8d44\u6e90\u521d\u59cb\u5316\u3001\u8bbe\u5907\u521b\u5efa\u4e0esysfs\u63a5\u53e3\u3001\u5f15\u7528\u8ba1\u6570\u9632\u6b62\u70ed\u62d4\u62d4\u65f6\u6a21\u5757\u88ab\u63d0\u524d\u5378\u8f7d\u3001\u6a21\u5757\u5378\u8f7d\u65f6\u7684\u8d44\u6e90\u91ca\u653e\u987a\u5e8f\u3002\u5ffd\u7565\u4efb\u4f55\u4e00\u4e2a\u73af\u8282\u90fd\u4f1a\u5bfc\u81f4\u5185\u6838<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9152,58,219],"topic":[],"class_list":["post-81970","post","type-post","status-publish","format-standard","hentry","category-server","tag-9152","tag-linux","tag-219"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Linux\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f\uff1a\u4eceinsmod\u5230rmmod\u7684\u72b6\u6001\u7ba1\u7406\u4e0esysfs\u63a5\u53e3\u8bbe\u8ba1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/81970.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linux\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f\uff1a\u4eceinsmod\u5230rmmod\u7684\u72b6\u6001\u7ba1\u7406\u4e0esysfs\u63a5\u53e3\u8bbe\u8ba1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"Linux\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f&#xff1a;\u4eceinsmod\u5230rmmod\u7684\u72b6\u6001\u7ba1\u7406\u4e0esysfs\u63a5\u53e3\u8bbe\u8ba1 \u4e00\u3001\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u4e0d\u662f\u7b80\u5355\u7684\u8bfb\u5199\u51fd\u6570 \u521d\u5b66\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u65f6\u5bb9\u6613\u8bef\u89e3&#xff1a;\u5199\u597dopen\/read\/write\/release\u56db\u4e2a\u56de\u8c03&#xff0c;\u6ce8\u518c\u4e00\u4e2a\u8bbe\u5907\u53f7&#xff0c;\u5c31\u5b8c\u6210\u4e86\u3002\u4f46\u751f\u4ea7\u7ea7\u9a71\u52a8\u5fc5\u987b\u5904\u7406\u5b8c\u6574\u7684\u751f\u547d\u5468\u671f\u2014\u2014\u6a21\u5757\u52a0\u8f7d\u65f6\u7684\u8d44\u6e90\u521d\u59cb\u5316\u3001\u8bbe\u5907\u521b\u5efa\u4e0esysfs\u63a5\u53e3\u3001\u5f15\u7528\u8ba1\u6570\u9632\u6b62\u70ed\u62d4\u62d4\u65f6\u6a21\u5757\u88ab\u63d0\u524d\u5378\u8f7d\u3001\u6a21\u5757\u5378\u8f7d\u65f6\u7684\u8d44\u6e90\u91ca\u653e\u987a\u5e8f\u3002\u5ffd\u7565\u4efb\u4f55\u4e00\u4e2a\u73af\u8282\u90fd\u4f1a\u5bfc\u81f4\u5185\u6838\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/81970.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-24T21:27:39+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/81970.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/81970.html\",\"name\":\"Linux\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f\uff1a\u4eceinsmod\u5230rmmod\u7684\u72b6\u6001\u7ba1\u7406\u4e0esysfs\u63a5\u53e3\u8bbe\u8ba1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-07-24T21:27:39+00:00\",\"dateModified\":\"2026-07-24T21:27:39+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/81970.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/81970.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/81970.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f\uff1a\u4eceinsmod\u5230rmmod\u7684\u72b6\u6001\u7ba1\u7406\u4e0esysfs\u63a5\u53e3\u8bbe\u8ba1\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Linux\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f\uff1a\u4eceinsmod\u5230rmmod\u7684\u72b6\u6001\u7ba1\u7406\u4e0esysfs\u63a5\u53e3\u8bbe\u8ba1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/81970.html","og_locale":"zh_CN","og_type":"article","og_title":"Linux\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f\uff1a\u4eceinsmod\u5230rmmod\u7684\u72b6\u6001\u7ba1\u7406\u4e0esysfs\u63a5\u53e3\u8bbe\u8ba1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"Linux\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f&#xff1a;\u4eceinsmod\u5230rmmod\u7684\u72b6\u6001\u7ba1\u7406\u4e0esysfs\u63a5\u53e3\u8bbe\u8ba1 \u4e00\u3001\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u4e0d\u662f\u7b80\u5355\u7684\u8bfb\u5199\u51fd\u6570 \u521d\u5b66\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u65f6\u5bb9\u6613\u8bef\u89e3&#xff1a;\u5199\u597dopen\/read\/write\/release\u56db\u4e2a\u56de\u8c03&#xff0c;\u6ce8\u518c\u4e00\u4e2a\u8bbe\u5907\u53f7&#xff0c;\u5c31\u5b8c\u6210\u4e86\u3002\u4f46\u751f\u4ea7\u7ea7\u9a71\u52a8\u5fc5\u987b\u5904\u7406\u5b8c\u6574\u7684\u751f\u547d\u5468\u671f\u2014\u2014\u6a21\u5757\u52a0\u8f7d\u65f6\u7684\u8d44\u6e90\u521d\u59cb\u5316\u3001\u8bbe\u5907\u521b\u5efa\u4e0esysfs\u63a5\u53e3\u3001\u5f15\u7528\u8ba1\u6570\u9632\u6b62\u70ed\u62d4\u62d4\u65f6\u6a21\u5757\u88ab\u63d0\u524d\u5378\u8f7d\u3001\u6a21\u5757\u5378\u8f7d\u65f6\u7684\u8d44\u6e90\u91ca\u653e\u987a\u5e8f\u3002\u5ffd\u7565\u4efb\u4f55\u4e00\u4e2a\u73af\u8282\u90fd\u4f1a\u5bfc\u81f4\u5185\u6838","og_url":"https:\/\/www.wsisp.com\/helps\/81970.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-07-24T21:27:39+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/81970.html","url":"https:\/\/www.wsisp.com\/helps\/81970.html","name":"Linux\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f\uff1a\u4eceinsmod\u5230rmmod\u7684\u72b6\u6001\u7ba1\u7406\u4e0esysfs\u63a5\u53e3\u8bbe\u8ba1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-07-24T21:27:39+00:00","dateModified":"2026-07-24T21:27:39+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/81970.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/81970.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/81970.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Linux\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f\uff1a\u4eceinsmod\u5230rmmod\u7684\u72b6\u6001\u7ba1\u7406\u4e0esysfs\u63a5\u53e3\u8bbe\u8ba1"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/81970","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=81970"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/81970\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=81970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=81970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=81970"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=81970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}