{"id":349124,"date":"2023-06-21T09:01:10","date_gmt":"2023-06-21T09:01:10","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=349124"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=349124","title":{"rendered":"<span>\u0417\u0430\u043c\u0435\u0442\u043a\u0430 \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u00abprocfs3.c\u00bb 7 \u0433\u043b\u0430\u0432\u044b \u043a\u043d\u0438\u0433\u0438 \u00abThe Linux Kernel Module Programming Guide\u00bb<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ad0\/ffc\/758\/ad0ffc758d03954e5d34d69def875f9c.png\" width=\"649\" height=\"837\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ad0\/ffc\/758\/ad0ffc758d03954e5d34d69def875f9c.png\"\/><\/figure>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u043c\u0435\u0442\u043a\u0435 \u0445\u043e\u0447\u0443 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0430\u0440\u0443 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \/proc \u0438\u0437 \u0432\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0430\u043d\u0443\u0430\u043b\u0430. \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0437\u043d\u0430\u043d\u0438\u044f \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u0441\u043e\u0441\u0442\u044b\u043a\u043e\u0432\u043a\u0438 \u0438 \u0432\u0435\u0449\u0438 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u043d\u044b\u0435 \u0434\u043e \u043a\u043e\u043d\u0446\u0430, \u0442\u0430\u043a \u0447\u0442\u043e \u0442\u0443\u0442 \u043f\u043e\u043f\u044b\u0442\u0430\u044e\u0441\u044c \u0432\u043d\u0435\u0441\u0442\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u044f\u0441\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u043d\u0430\u0447\u043d\u0435\u0442 \u0442\u043e\u043f\u0430\u0442\u044c \u044d\u0442\u0438\u043c \u043f\u0443\u0442\u0435\u043c.<\/p>\n<h2>\u0410 \u043f\u043e\u0447\u0435\u043c\u0443?<\/h2>\n<p>\u0418\u0437\u0443\u0447\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u044f\u0434\u0440\u0430 Linux, \u043f\u043e\u0437\u043d\u0430\u0432\u0430\u044f (\u0418\u041c\u0425\u041e, \u0445\u043e\u0440\u043e\u0448\u0438\u0439) \u0442\u0440\u0443\u0434 &#171;The Linux Kernel Module Programming Guide&#187; \u0437\u0430\u043c\u0435\u0442\u0438\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0441\u043e\u0441\u0442\u044b\u043a\u043e\u0432\u043e\u043a \u043f\u0440\u0438 \u0432\u043f\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 7 &#171;\u0424\u0430\u0439\u043b\u043e\u0432\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \/proc&#187;. <\/p>\n<p>\u0421\u0440\u0430\u0437\u0443 \u043f\u043e\u044f\u0441\u043d\u044e: \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0430\u043f\u0440\u044f\u0442\u0430\u0442\u044c\u0441\u044f \u0431\u044b\u043b\u043e \u043b\u0435\u043d\u044c \u0447\u0438\u0442\u0430\u043b \u043a\u043d\u0438\u0436\u043a\u0443 \u0432 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0435 \u043e\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u044b RUVDS (\u0437\u0430 \u0447\u0442\u043e \u0438\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e), \u043d\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434, \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0441\u0442\u0430\u0440, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0432\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0441\u044f \u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b, \u0434\u0430\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0439 &#171;May 2, 2023&#187; &#8212; \u0432\u0440\u043e\u0434\u0435 \u0431\u044b \u043a\u0430\u043a \u0441\u0432\u0435\u0436\u0430\u043a). \u0423\u0441\u043b\u043e\u0432\u0438\u043c\u0441\u044f, \u0447\u0442\u043e \u0434\u0430\u043b\u0435\u0435 \u043f\u043e \u0442\u0435\u043a\u0441\u0442\u0443 &#171;RU&#187; \u0431\u0443\u0434\u0435\u0442 \u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043d\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e, &#171;EN&#187; &#8212; \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b.<\/p>\n<h2>\u0417\u0430 \u0447\u0442\u043e \u0437\u0430\u0446\u0435\u043f\u0438\u043b\u0441\u044f?<\/h2>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u043e\u0436\u0443 \u043a\u043e\u0434 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c &#171;procfs3.c&#187;, \u043a\u0430\u043a \u043e\u043d \u0435\u0441\u0442\u044c \u0432 RU.<\/p>\n<pre><code class=\"cpp\">#include &lt;linux\/kernel.h> #include &lt;linux\/module.h> #include &lt;linux\/proc_fs.h> #include &lt;linux\/sched.h> #include &lt;linux\/uaccess.h> #include &lt;linux\/version.h>  #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0) #define HAVE_PROC_OPS #endif   #define PROCFS_MAX_SIZE 2048 #define PROCFS_ENTRY_FILENAME \"buffer2k\"  static struct proc_dir_entry *our_proc_file; static char procfs_buffer[PROCFS_MAX_SIZE]; static unsigned long procfs_buffer_size = 0;  static ssize_t procfs_read(struct file *filp, char __user *buffer,                            size_t length, loff_t *offset) {   static int finished = 0;   if (finished) {       pr_debug(\"procfs_read: END\\n\");       finished = 0;       return 0;     }    finished = 1;    if (copy_to_user(buffer, procfs_buffer, procfs_buffer_size))     return -EFAULT;    pr_debug(\"procfs_read: read %lu bytes\\n\", procfs_buffer_size);   return procfs_buffer_size; }  static ssize_t procfs_write(struct file *file, const char __user *buffer,                             size_t len, loff_t *off) {   if (len > PROCFS_MAX_SIZE)     procfs_buffer_size = PROCFS_MAX_SIZE;   else     procfs_buffer_size = len;    if (copy_from_user(procfs_buffer, buffer, procfs_buffer_size))     return -EFAULT;    pr_debug(\"procfs_write: write %lu bytes\\n\", procfs_buffer_size);   return procfs_buffer_size; }  static int procfs_open(struct inode *inode, struct file *file) {   try_module_get(THIS_MODULE);   return 0; }  static int procfs_close(struct inode *inode, struct file *file) {   module_put(THIS_MODULE);   return 0; }  #ifdef HAVE_PROC_OPS static struct proc_ops file_ops_4_our_proc_file = {   .proc_read = procfs_read,   .proc_write = procfs_write,   .proc_open = procfs_open,   .proc_release = procfs_close, };   #else static const struct file_operations file_ops_4_our_proc_file = {   .read = procfs_read,   .write = procfs_write,   .open = procfs_open,   .release = procfs_close, }; #endif  static int __init procfs3_init(void) {   our_proc_file = proc_create(PROCFS_ENTRY_FILENAME, 0644, NULL,                               &amp;file_ops_4_our_proc_file);    if (our_proc_file == NULL) {     remove_proc_entry(PROCFS_ENTRY_FILENAME, NULL);     pr_debug(\"Error: Could not initialize \/proc\/%s\\n\",              PROCFS_ENTRY_FILENAME);      return -ENOMEM;   }    proc_set_size(our_proc_file, 80);   proc_set_user(our_proc_file, GLOBAL_ROOT_UID, GLOBAL_ROOT_GID);    pr_debug(\"\/proc\/%s created\\n\", PROCFS_ENTRY_FILENAME);   return 0;   }  static void __exit procfs3_exit(void) {   remove_proc_entry(PROCFS_ENTRY_FILENAME, NULL);   pr_debug(\"\/proc\/%s removed\\n\", PROCFS_ENTRY_FILENAME);   }  module_init(procfs3_init); module_exit(procfs3_exit);  MODULE_LICENSE(\"GPL\");  <\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u0432\u0432\u0435\u043b\u043e \u0441\u043c\u0443\u0442\u0443 &#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044f &#171;procfs_read&#187;. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, cat-\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u044d\u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 cat \u0432\u044b\u0437\u0432\u0430\u0442\u044c 2 \u0440\u0430\u0437\u0430 \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 (\u043d\u0430\u043f\u043e\u043c\u043d\u044e, 0 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0447\u0442\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d\u043e, \u0430 \u0442\u0443\u0442 0 \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u043d\u0430 2-\u0439 \u0432\u044b\u0437\u043e\u0432). <\/p>\n<p>\u0427\u0435\u0441\u0442\u043d\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 &#171;procfs_write&#187; \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043f\u043e\u0447\u0435\u043c\u0443 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044f\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f &#171;procfs_buffer_size&#187;, \u0430 \u043d\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 &#171;len&#187;. <\/p>\n<p>\u0418 \u0443\u0431\u0438\u043b\u043e \u043c\u0435\u043d\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 &#171;remove_proc_entry&#187;. \u0423\u0431\u0438\u043b\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e\u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u0440\u043e\u0434\u0435 \u0431\u044b \u043a\u0430\u043a \u0434\u043b\u044f \u0442\u0435\u0445 \u0436\u0435 \u0432\u0435\u0449\u0435\u0439 \u0431\u044b\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043e &#171;proc_remove&#187;. <\/p>\n<p>\u0420\u0435\u0448\u0438\u043b \u0437\u0430\u0433\u043b\u044f\u0434\u0443\u0442\u044c \u0432 EN. <\/p>\n<h2>\u0410 \u0447\u0442\u043e \u0442\u0430\u043c \u0432 EN?<\/h2>\n<p>\u0417\u0430\u0433\u043b\u044f\u043d\u0443\u0432 \u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u044f \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e \u043e\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0441\u0432\u0435\u0436\u0435\u0435 \u0438 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u0435\u0435:<\/p>\n<pre><code class=\"cpp\">#include &lt;linux\/kernel.h> #include &lt;linux\/module.h> #include &lt;linux\/proc_fs.h> #include &lt;linux\/sched.h> #include &lt;linux\/uaccess.h> #include &lt;linux\/version.h> #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0) #include &lt;linux\/minmax.h> #endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0) #define HAVE_PROC_OPS #endif #define PROCFS_MAX_SIZE 2048UL #define PROCFS_ENTRY_FILENAME \"buffer2k\" static struct proc_dir_entry *our_proc_file; static char procfs_buffer[PROCFS_MAX_SIZE]; static unsigned long procfs_buffer_size = 0; static ssize_t procfs_read(struct file *filp, char __user *buffer, size_t length, loff_t *offset) {   if (*offset || procfs_buffer_size == 0) {     pr_debug(\"procfs_read: END\\n\");     *offset = 0;     return 0;   }   procfs_buffer_size = min(procfs_buffer_size, length);      if (copy_to_user(buffer, procfs_buffer, procfs_buffer_size))     return -EFAULT;      *offset += procfs_buffer_size;   pr_debug(\"procfs_read: read %lu bytes\\n\", procfs_buffer_size);   return procfs_buffer_size; }  static ssize_t procfs_write(struct file *file, const char __user *buffer,                             size_t len, loff_t *off) {   procfs_buffer_size = min(PROCFS_MAX_SIZE, len);   if (copy_from_user(procfs_buffer, buffer, procfs_buffer_size))     return -EFAULT;   *off += procfs_buffer_size;    pr_debug(\"procfs_write: write %lu bytes\\n\", procfs_buffer_size);   return procfs_buffer_size; }  static int procfs_open(struct inode *inode, struct file *file) {   try_module_get(THIS_MODULE);   return 0; }  static int procfs_close(struct inode *inode, struct file *file) {   module_put(THIS_MODULE);   return 0; }  #ifdef HAVE_PROC_OPS static struct proc_ops file_ops_4_our_proc_file = {   .proc_read = procfs_read,   .proc_write = procfs_write,   .proc_open = procfs_open,   .proc_release = procfs_close, }; #else static const struct file_operations file_ops_4_our_proc_file = {   .read = procfs_read,   .write = procfs_write,   .open = procfs_open,   .release = procfs_close, }; #endif  static int __init procfs3_init(void) {   our_proc_file = proc_create(PROCFS_ENTRY_FILENAME, 0644, NULL,                               &amp;file_ops_4_our_proc_file);    if (our_proc_file == NULL) {     remove_proc_entry(PROCFS_ENTRY_FILENAME, NULL);      pr_debug(\"Error: Could not initialize \/proc\/%s\\n\",              PROCFS_ENTRY_FILENAME);        return -ENOMEM;   }    proc_set_size(our_proc_file, 80);   proc_set_user(our_proc_file, GLOBAL_ROOT_UID, GLOBAL_ROOT_GID);    pr_debug(\"\/proc\/%s created\\n\", PROCFS_ENTRY_FILENAME);   return 0; }  static void __exit procfs3_exit(void) {   remove_proc_entry(PROCFS_ENTRY_FILENAME, NULL);   pr_debug(\"\/proc\/%s removed\\n\", PROCFS_ENTRY_FILENAME); }  module_init(procfs3_init); module_exit(procfs3_exit);  MODULE_LICENSE(\"GPL\"); <\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e &#171;procfs_read&#187; \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0435, \u0434\u0430 \u0438 \u0432 \u0446\u0435\u043b\u043e\u043c \u043a\u043e\u0434 \u0446\u0438\u0432\u0438\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u0435\u0435 &#8212; \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f, \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432\u0441\u044f\u043a\u0438\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b.<\/p>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b &#8212; \u0431\u0438\u043d\u0433\u043e! \u041d\u0430 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f! \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441\u0442\u0430\u0440\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438! \u041d\u043e \u0442\u0435\u0440\u0437\u0430\u0432\u0448\u0438\u0439 \u043c\u0435\u043d\u044f &#171;remove_proc_entry&#187; \u0432\u0441\u0435 \u0435\u0449\u0435 \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e \u0441\u0438\u044f\u0435\u0442 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u0438\u0445 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0439 \u043e\u0442 \u0430\u0432\u0442\u043e\u0440\u043e\u0432.<\/p>\n<h2>proc_remove vs remove_proc_entry<\/h2>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043d\u044f\u043b, \u043f\u043e\u043b\u0435\u0437 \u043d\u0430 \u0432\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u044e&#8230; \u0418 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043d\u0435\u043c\u044b\u0441\u043b\u0438\u043c\u044b\u043c \u0444\u0443\u0442\u0443\u0440\u0438\u0441\u0442\u0438\u0447\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043d\u0430\u0448\u0435\u043b <a href=\"https:\/\/docs.kernel.org\/filesystems\/seq_file.html?highlight=create_proc_entry\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443<\/a>, \u0433\u0434\u0435 \u0435\u0441\u0442\u044c \u0444\u0440\u0430\u0437\u0430:<\/p>\n<blockquote>\n<p>Deprecated create_proc_entry. <\/p>\n<p>Note that the above article uses create_proc_entry which was removed in kernel 3.10. Current versions require the following update:<\/p>\n<\/blockquote>\n<pre><code class=\"cpp\">-   entry = create_proc_entry(\"sequence\", 0, NULL); -   if (entry) -           entry->proc_fops = &amp;ct_file_ops; +   entry = proc_create(\"sequence\", 0, NULL, &amp;ct_file_ops);<\/code><\/pre>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043d\u0435 \u0443\u0432\u0438\u0434\u0435\u043b (\u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435 \u043c\u0430\u043b\u043e \u0438\u0441\u043a\u0430\u043b, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u043a\u0442\u043e-\u0442\u043e \u0443\u043c\u043d\u044b\u0439 \u043f\u043e\u0434\u0441\u043a\u0430\u0436\u0435\u0442 \u0447\u0442\u043e-\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435). <\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u044f \u0433\u043b\u0443\u043f \u0438 \u043d\u0435\u043e\u043f\u044b\u0442\u0435\u043d, \u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043b &#171;create_proc_entry&#187; &amp; &#171;remove_proc_entry&#187;, \u043a\u0430\u043a 1\u0439, &#171;depricated&#187; \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f\/\u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u0447\u043a\u0438 \u0432\u0445\u043e\u0434\u0430 \u0432 \/proc, \u0430 &#171;proc_create&#187; &amp; &#171;proc_remove&#187;, \u043a\u0430\u043a 2-\u0439, \u0431\u043e\u043b\u0435\u0435 \u0441\u0432\u0435\u0436\u0438\u0439.<\/p>\n<h2>\u0418\u0442\u043e\u0433<\/h2>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0432\u0441\u0435\u0445 \u043f\u043e\u0438\u0441\u043a\u043e\u0432 \u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432, \u043d\u0430\u043f\u0438\u0441\u0430\u043b <a href=\"https:\/\/github.com\/JozeAlexandro\/linux_kernle_simple_procfs_note\" rel=\"noopener noreferrer nofollow\">\u043c\u043e\u0434\u0443\u043b\u044c<\/a> \u043f\u043e \u043e\u0431\u0440\u0430\u0437\u0443 \u0438 \u043f\u043e\u0434\u043e\u0431\u0438\u044e \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445, \u043d\u043e \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u0445\u0432\u0430\u0442\u0430\u043b\u043e \u043c\u043d\u0435. \u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u043e\u0433\u0434\u0430-\u0442\u043e \u043a\u043e\u043c\u0443-\u0442\u043e \u044d\u0442\u043e \u0447\u0435\u043c-\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442, \u0441\u043f\u0430\u0441\u0438\u0431\u043e.<\/p>\n<h2>P.S.<\/h2>\n<p>\u0424\u0443\u043d\u0438\u043a\u0446\u0438\u044f &#171;proc_set_size&#187; \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440 \u0444\u0430\u0439\u043b\u0430 \u0432 \/proc. \u041c\u0431 \u043a\u0442\u043e-\u0442\u043e \u0441\u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043e\u043d \u0442\u0430\u043c?)<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/743002\/\"> https:\/\/habr.com\/ru\/articles\/743002\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><\/figure>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u043c\u0435\u0442\u043a\u0435 \u0445\u043e\u0447\u0443 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0430\u0440\u0443 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \/proc \u0438\u0437 \u0432\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0430\u043d\u0443\u0430\u043b\u0430. \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0437\u043d\u0430\u043d\u0438\u044f \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u0441\u043e\u0441\u0442\u044b\u043a\u043e\u0432\u043a\u0438 \u0438 \u0432\u0435\u0449\u0438 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u043d\u044b\u0435 \u0434\u043e \u043a\u043e\u043d\u0446\u0430, \u0442\u0430\u043a \u0447\u0442\u043e \u0442\u0443\u0442 \u043f\u043e\u043f\u044b\u0442\u0430\u044e\u0441\u044c \u0432\u043d\u0435\u0441\u0442\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u044f\u0441\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u043d\u0430\u0447\u043d\u0435\u0442 \u0442\u043e\u043f\u0430\u0442\u044c \u044d\u0442\u0438\u043c \u043f\u0443\u0442\u0435\u043c.<\/p>\n<h2>\u0410 \u043f\u043e\u0447\u0435\u043c\u0443?<\/h2>\n<p>\u0418\u0437\u0443\u0447\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u044f\u0434\u0440\u0430 Linux, \u043f\u043e\u0437\u043d\u0430\u0432\u0430\u044f (\u0418\u041c\u0425\u041e, \u0445\u043e\u0440\u043e\u0448\u0438\u0439) \u0442\u0440\u0443\u0434 &#171;The Linux Kernel Module Programming Guide&#187; \u0437\u0430\u043c\u0435\u0442\u0438\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0441\u043e\u0441\u0442\u044b\u043a\u043e\u0432\u043e\u043a \u043f\u0440\u0438 \u0432\u043f\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 7 &#171;\u0424\u0430\u0439\u043b\u043e\u0432\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \/proc&#187;. <\/p>\n<p>\u0421\u0440\u0430\u0437\u0443 \u043f\u043e\u044f\u0441\u043d\u044e: \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0430\u043f\u0440\u044f\u0442\u0430\u0442\u044c\u0441\u044f \u0431\u044b\u043b\u043e \u043b\u0435\u043d\u044c \u0447\u0438\u0442\u0430\u043b \u043a\u043d\u0438\u0436\u043a\u0443 \u0432 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0435 \u043e\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u044b RUVDS (\u0437\u0430 \u0447\u0442\u043e \u0438\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e), \u043d\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434, \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0441\u0442\u0430\u0440, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0432\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0441\u044f \u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b, \u0434\u0430\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0439 &#171;May 2, 2023&#187; &#8212; \u0432\u0440\u043e\u0434\u0435 \u0431\u044b \u043a\u0430\u043a \u0441\u0432\u0435\u0436\u0430\u043a). \u0423\u0441\u043b\u043e\u0432\u0438\u043c\u0441\u044f, \u0447\u0442\u043e \u0434\u0430\u043b\u0435\u0435 \u043f\u043e \u0442\u0435\u043a\u0441\u0442\u0443 &#171;RU&#187; \u0431\u0443\u0434\u0435\u0442 \u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043d\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e, &#171;EN&#187; &#8212; \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b.<\/p>\n<h2>\u0417\u0430 \u0447\u0442\u043e \u0437\u0430\u0446\u0435\u043f\u0438\u043b\u0441\u044f?<\/h2>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u043e\u0436\u0443 \u043a\u043e\u0434 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c &#171;procfs3.c&#187;, \u043a\u0430\u043a \u043e\u043d \u0435\u0441\u0442\u044c \u0432 RU.<\/p>\n<pre><code class=\"cpp\">#include &lt;linux\/kernel.h> #include &lt;linux\/module.h> #include &lt;linux\/proc_fs.h> #include &lt;linux\/sched.h> #include &lt;linux\/uaccess.h> #include &lt;linux\/version.h>  #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0) #define HAVE_PROC_OPS #endif   #define PROCFS_MAX_SIZE 2048 #define PROCFS_ENTRY_FILENAME \"buffer2k\"  static struct proc_dir_entry *our_proc_file; static char procfs_buffer[PROCFS_MAX_SIZE]; static unsigned long procfs_buffer_size = 0;  static ssize_t procfs_read(struct file *filp, char __user *buffer,                            size_t length, loff_t *offset) {   static int finished = 0;   if (finished) {       pr_debug(\"procfs_read: END\\n\");       finished = 0;       return 0;     }    finished = 1;    if (copy_to_user(buffer, procfs_buffer, procfs_buffer_size))     return -EFAULT;    pr_debug(\"procfs_read: read %lu bytes\\n\", procfs_buffer_size);   return procfs_buffer_size; }  static ssize_t procfs_write(struct file *file, const char __user *buffer,                             size_t len, loff_t *off) {   if (len > PROCFS_MAX_SIZE)     procfs_buffer_size = PROCFS_MAX_SIZE;   else     procfs_buffer_size = len;    if (copy_from_user(procfs_buffer, buffer, procfs_buffer_size))     return -EFAULT;    pr_debug(\"procfs_write: write %lu bytes\\n\", procfs_buffer_size);   return procfs_buffer_size; }  static int procfs_open(struct inode *inode, struct file *file) {   try_module_get(THIS_MODULE);   return 0; }  static int procfs_close(struct inode *inode, struct file *file) {   module_put(THIS_MODULE);   return 0; }  #ifdef HAVE_PROC_OPS static struct proc_ops file_ops_4_our_proc_file = {   .proc_read = procfs_read,   .proc_write = procfs_write,   .proc_open = procfs_open,   .proc_release = procfs_close, };   #else static const struct file_operations file_ops_4_our_proc_file = {   .read = procfs_read,   .write = procfs_write,   .open = procfs_open,   .release = procfs_close, }; #endif  static int __init procfs3_init(void) {   our_proc_file = proc_create(PROCFS_ENTRY_FILENAME, 0644, NULL,                               &amp;file_ops_4_our_proc_file);    if (our_proc_file == NULL) {     remove_proc_entry(PROCFS_ENTRY_FILENAME, NULL);     pr_debug(\"Error: Could not initialize \/proc\/%s\\n\",              PROCFS_ENTRY_FILENAME);      return -ENOMEM;   }    proc_set_size(our_proc_file, 80);   proc_set_user(our_proc_file, GLOBAL_ROOT_UID, GLOBAL_ROOT_GID);    pr_debug(\"\/proc\/%s created\\n\", PROCFS_ENTRY_FILENAME);   return 0;   }  static void __exit procfs3_exit(void) {   remove_proc_entry(PROCFS_ENTRY_FILENAME, NULL);   pr_debug(\"\/proc\/%s removed\\n\", PROCFS_ENTRY_FILENAME);   }  module_init(procfs3_init); module_exit(procfs3_exit);  MODULE_LICENSE(\"GPL\");  <\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u0432\u0432\u0435\u043b\u043e \u0441\u043c\u0443\u0442\u0443 &#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044f &#171;procfs_read&#187;. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, cat-\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u044d\u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 cat \u0432\u044b\u0437\u0432\u0430\u0442\u044c 2 \u0440\u0430\u0437\u0430 \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 (\u043d\u0430\u043f\u043e\u043c\u043d\u044e, 0 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0447\u0442\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d\u043e, \u0430 \u0442\u0443\u0442 0 \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u043d\u0430 2-\u0439 \u0432\u044b\u0437\u043e\u0432). <\/p>\n<p>\u0427\u0435\u0441\u0442\u043d\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 &#171;procfs_write&#187; \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043f\u043e\u0447\u0435\u043c\u0443 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044f\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f &#171;procfs_buffer_size&#187;, \u0430 \u043d\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 &#171;len&#187;. <\/p>\n<p>\u0418 \u0443\u0431\u0438\u043b\u043e \u043c\u0435\u043d\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 &#171;remove_proc_entry&#187;. \u0423\u0431\u0438\u043b\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e\u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u0440\u043e\u0434\u0435 \u0431\u044b \u043a\u0430\u043a \u0434\u043b\u044f \u0442\u0435\u0445 \u0436\u0435 \u0432\u0435\u0449\u0435\u0439 \u0431\u044b\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043e &#171;proc_remove&#187;. <\/p>\n<p>\u0420\u0435\u0448\u0438\u043b \u0437\u0430\u0433\u043b\u044f\u0434\u0443\u0442\u044c \u0432 EN. <\/p>\n<h2>\u0410 \u0447\u0442\u043e \u0442\u0430\u043c \u0432 EN?<\/h2>\n<p>\u0417\u0430\u0433\u043b\u044f\u043d\u0443\u0432 \u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u044f \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e \u043e\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0441\u0432\u0435\u0436\u0435\u0435 \u0438 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u0435\u0435:<\/p>\n<pre><code class=\"cpp\">#include &lt;linux\/kernel.h> #include &lt;linux\/module.h> #include &lt;linux\/proc_fs.h> #include &lt;linux\/sched.h> #include &lt;linux\/uaccess.h> #include &lt;linux\/version.h> #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0) #include &lt;linux\/minmax.h> #endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0) #define HAVE_PROC_OPS #endif #define PROCFS_MAX_SIZE 2048UL #define PROCFS_ENTRY_FILENAME \"buffer2k\" static struct proc_dir_entry *our_proc_file; static char procfs_buffer[PROCFS_MAX_SIZE]; static unsigned long procfs_buffer_size = 0; static ssize_t procfs_read(struct file *filp, char __user *buffer, size_t length, loff_t *offset) {   if (*offset || procfs_buffer_size == 0) {     pr_debug(\"procfs_read: END\\n\");     *offset = 0;     return 0;   }   procfs_buffer_size = min(procfs_buffer_size, length);      if (copy_to_user(buffer, procfs_buffer, procfs_buffer_size))     return -EFAULT;      *offset += procfs_buffer_size;   pr_debug(\"procfs_read: read %lu bytes\\n\", procfs_buffer_size);   return procfs_buffer_size; }  static ssize_t procfs_write(struct file *file, const char __user *buffer,                             size_t len, loff_t *off) {   procfs_buffer_size = min(PROCFS_MAX_SIZE, len);   if (copy_from_user(procfs_buffer, buffer, procfs_buffer_size))     return -EFAULT;   *off += procfs_buffer_size;    pr_debug(\"procfs_write: write %lu bytes\\n\", procfs_buffer_size);   return procfs_buffer_size; }  static int procfs_open(struct inode *inode, struct file *file) {   try_module_get(THIS_MODULE);   return 0; }  static int procfs_close(struct inode *inode, struct file *file) {   module_put(THIS_MODULE);   return 0; }  #ifdef HAVE_PROC_OPS static struct proc_ops file_ops_4_our_proc_file = {   .proc_read = procfs_read,   .proc_write = procfs_write,   .proc_open = procfs_open,   .proc_release = procfs_close, }; #else static const struct file_operations file_ops_4_our_proc_file = {   .read = procfs_read,   .write = procfs_write,   .open = procfs_open,   .release = procfs_close, }; #endif  static int __init procfs3_init(void) {   our_proc_file = proc_create(PROCFS_ENTRY_FILENAME, 0644, NULL,                               &amp;file_ops_4_our_proc_file);    if (our_proc_file == NULL) {     remove_proc_entry(PROCFS_ENTRY_FILENAME, NULL);      pr_debug(\"Error: Could not initialize \/proc\/%s\\n\",              PROCFS_ENTRY_FILENAME);        return -ENOMEM;   }    proc_set_size(our_proc_file, 80);   proc_set_user(our_proc_file, GLOBAL_ROOT_UID, GLOBAL_ROOT_GID);    pr_debug(\"\/proc\/%s created\\n\", PROCFS_ENTRY_FILENAME);   return 0; }  static void __exit procfs3_exit(void) {   remove_proc_entry(PROCFS_ENTRY_FILENAME, NULL);   pr_debug(\"\/proc\/%s removed\\n\", PROCFS_ENTRY_FILENAME); }  module_init(procfs3_init); module_exit(procfs3_exit);  MODULE_LICENSE(\"GPL\"); <\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e &#171;procfs_read&#187; \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0435, \u0434\u0430 \u0438 \u0432 \u0446\u0435\u043b\u043e\u043c \u043a\u043e\u0434 \u0446\u0438\u0432\u0438\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u0435\u0435 &#8212; \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f, \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432\u0441\u044f\u043a\u0438\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b.<\/p>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b &#8212; \u0431\u0438\u043d\u0433\u043e! \u041d\u0430 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f! \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441\u0442\u0430\u0440\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438! \u041d\u043e \u0442\u0435\u0440\u0437\u0430\u0432\u0448\u0438\u0439 \u043c\u0435\u043d\u044f &#171;remove_proc_entry&#187; \u0432\u0441\u0435 \u0435\u0449\u0435 \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e \u0441\u0438\u044f\u0435\u0442 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u0438\u0445 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0439 \u043e\u0442 \u0430\u0432\u0442\u043e\u0440\u043e\u0432.<\/p>\n<h2>proc_remove vs remove_proc_entry<\/h2>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043d\u044f\u043b, \u043f\u043e\u043b\u0435\u0437 \u043d\u0430 \u0432\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u044e&#8230; \u0418 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043d\u0435\u043c\u044b\u0441\u043b\u0438\u043c\u044b\u043c \u0444\u0443\u0442\u0443\u0440\u0438\u0441\u0442\u0438\u0447\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043d\u0430\u0448\u0435\u043b <a href=\"https:\/\/docs.kernel.org\/filesystems\/seq_file.html?highlight=create_proc_entry\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443<\/a>, \u0433\u0434\u0435 \u0435\u0441\u0442\u044c \u0444\u0440\u0430\u0437\u0430:<\/p>\n<blockquote>\n<p>Deprecated create_proc_entry. <\/p>\n<p>Note that the above article uses create_proc_entry which was removed in kernel 3.10. Current versions require the following update:<\/p>\n<\/blockquote>\n<pre><code class=\"cpp\">-   entry = create_proc_entry(\"sequence\", 0, NULL); -   if (entry) -           entry->proc_fops = &amp;ct_file_ops; +   entry = proc_create(\"sequence\", 0, NULL, &amp;ct_file_ops);<\/code><\/pre>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043d\u0435 \u0443\u0432\u0438\u0434\u0435\u043b (\u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435 \u043c\u0430\u043b\u043e \u0438\u0441\u043a\u0430\u043b, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u043a\u0442\u043e-\u0442\u043e \u0443\u043c\u043d\u044b\u0439 \u043f\u043e\u0434\u0441\u043a\u0430\u0436\u0435\u0442 \u0447\u0442\u043e-\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435). <\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u044f \u0433\u043b\u0443\u043f \u0438 \u043d\u0435\u043e\u043f\u044b\u0442\u0435\u043d, \u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043b &#171;create_proc_entry&#187; &amp; &#171;remove_proc_entry&#187;, \u043a\u0430\u043a 1\u0439, &#171;depricated&#187; \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f\/\u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u0447\u043a\u0438 \u0432\u0445\u043e\u0434\u0430 \u0432 \/proc, \u0430 &#171;proc_create&#187; &amp; &#171;proc_remove&#187;, \u043a\u0430\u043a 2-\u0439, \u0431\u043e\u043b\u0435\u0435 \u0441\u0432\u0435\u0436\u0438\u0439.<\/p>\n<h2>\u0418\u0442\u043e\u0433<\/h2>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0432\u0441\u0435\u0445 \u043f\u043e\u0438\u0441\u043a\u043e\u0432 \u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432, \u043d\u0430\u043f\u0438\u0441\u0430\u043b <a href=\"https:\/\/github.com\/JozeAlexandro\/linux_kernle_simple_procfs_note\" rel=\"noopener noreferrer nofollow\">\u043c\u043e\u0434\u0443\u043b\u044c<\/a> \u043f\u043e \u043e\u0431\u0440\u0430\u0437\u0443 \u0438 \u043f\u043e\u0434\u043e\u0431\u0438\u044e \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445, \u043d\u043e \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u0445\u0432\u0430\u0442\u0430\u043b\u043e \u043c\u043d\u0435. \u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u043e\u0433\u0434\u0430-\u0442\u043e \u043a\u043e\u043c\u0443-\u0442\u043e \u044d\u0442\u043e \u0447\u0435\u043c-\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442, \u0441\u043f\u0430\u0441\u0438\u0431\u043e.<\/p>\n<h2>P.S.<\/h2>\n<p>\u0424\u0443\u043d\u0438\u043a\u0446\u0438\u044f &#171;proc_set_size&#187; \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440 \u0444\u0430\u0439\u043b\u0430 \u0432 \/proc. \u041c\u0431 \u043a\u0442\u043e-\u0442\u043e \u0441\u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043e\u043d \u0442\u0430\u043c?)<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/743002\/\"> https:\/\/habr.com\/ru\/articles\/743002\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-349124","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/349124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=349124"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/349124\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=349124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=349124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=349124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}