{"id":409814,"date":"2024-06-29T21:00:50","date_gmt":"2024-06-29T21:00:50","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=409814"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=409814","title":{"rendered":"<span>\u041f\u043e\u0441\u043e\u0431\u0438\u0435 \u043f\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u044f\u0434\u0440\u0430 Linux. \u0427.3<\/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-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/684382\/\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/-7\/yl\/hp\/-7ylhpzc6raohz-vopxottyejfu.png\" data-src=\"https:\/\/habrastorage.org\/webt\/-7\/yl\/hp\/-7ylhpzc6raohz-vopxottyejfu.png\"\/><\/div>\n<p><\/a><br \/>  <u>\u041e\u0442 \u0440\u0435\u0434\u0430\u043a\u0446\u0438\u0438<\/u>: \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u043b\u0441\u044f 31 \u0433\u043e\u0434 \u0441 \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0430\u043d\u043e\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f Linux. \u0418\u043c\u0435\u043d\u043d\u043e \u0432 \u044d\u0442\u043e\u0442 \u0434\u0435\u043d\u044c, 25 \u0430\u0432\u0433\u0443\u0441\u0442\u0430 1991 \u0433\u043e\u0434\u0430 \u041b\u0438\u043d\u0443\u0441 \u0422\u043e\u0440\u0432\u0430\u043b\u044c\u0434\u0441 \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u043b \u0432 \u043d\u043e\u0432\u043e\u0441\u0442\u044f\u0445 Usenet comp.os.minix \u0441\u043e\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0430:  <\/p>\n<blockquote><p><i>\u041f\u0440\u0438\u0432\u0435\u0442 \u0432\u0441\u0435\u043c \u0442\u0435\u043c, \u043a\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043c\u0438\u043d\u0438\u043a\u0441 \u2014 \u042f \u0434\u0435\u043b\u0430\u044e (\u0441\u0432\u043e\u0431\u043e\u0434\u043d\u0443\u044e) \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 (\u044d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0431\u0431\u0438, \u043d\u0435 \u0441\u0442\u043e\u043b\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0438 \u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435, \u043a\u0430\u043a GNU) \u0434\u043b\u044f 386(486)AT \u043a\u043b\u043e\u043d\u043e\u0432. \u042d\u0442\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043f\u0438\u0448\u0435\u0442\u0441\u044f \u0441 \u0430\u043f\u0440\u0435\u043b\u044f \u0438 \u0441\u043a\u043e\u0440\u043e \u0431\u0443\u0434\u0435\u0442 \u0433\u043e\u0442\u043e\u0432\u0430. \u042f \u0445\u043e\u0447\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u043e\u0442\u0437\u044b\u0432, \u043a\u0430\u0441\u0430\u044e\u0449\u0438\u0439\u0441\u044f \u0432\u0435\u0449\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0440\u0430\u0432\u044f\u0442\u0441\u044f\/\u043d\u0435 \u043d\u0440\u0430\u0432\u044f\u0442\u0441\u044f \u043b\u044e\u0434\u044f\u043c \u0432 \u043c\u0438\u043d\u0438\u043a\u0441, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u043e\u044f \u041e\u0421 \u043f\u043e\u0445\u043e\u0436\u0430 \u043d\u0430 \u043d\u0435\u0451 (\u0442\u0430\u043a\u043e\u0435 \u0436\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b (\u043f\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0441\u043e\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c), \u0441\u0440\u0435\u0434\u0438 \u043f\u0440\u043e\u0447\u0435\u0433\u043e).<\/p>\n<p>  \u0412 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u044f \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043b bash (1.08) \u0438 gcc (1.40), \u0438, \u043f\u043e\u0445\u043e\u0436\u0435, \u044d\u0442\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u044f \u043f\u043e\u043b\u0443\u0447\u0443 \u0447\u0442\u043e-\u0442\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u043d\u043e\u0435 \u0432 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0441\u044f\u0446\u0435\u0432, \u0438 \u044f \u0445\u043e\u0447\u0443 \u0443\u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0445\u043e\u0442\u044f\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043b\u044e\u0434\u0435\u0439. \u041b\u044e\u0431\u044b\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f, \u043d\u043e \u044f \u043d\u0435 \u043e\u0431\u0435\u0449\u0430\u044e, \u0447\u0442\u043e \u044f \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044e \u0438\u0445:-)<\/p>\n<p>  \u041b\u0438\u043d\u0443\u0441 (torvalds@kruuna.helsinki.fi)<\/p>\n<p>  PS. \u0414\u0430 \u2014 \u0432 \u043d\u0435\u0439 \u043d\u0435\u0442 \u043a\u043e\u0434\u0430 \u043c\u0438\u043d\u0438\u043a\u0441, \u0438 \u0431\u0443\u0434\u0435\u0442 \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u043e\u0442\u043e\u043a\u043e\u0432\u0430\u044f \u0424\u0421. \u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u041d\u0415\u041f\u0415\u0420\u0415\u041d\u041e\u0421\u0418\u041c\u0410 (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u044b Intel 386 \u0438 \u0442. \u0434.) \u0438, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0436\u0435\u0441\u0442\u043a\u0438\u0435 \u0434\u0438\u0441\u043a\u0438 AT, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u0441\u0451, \u0447\u0442\u043e \u0443 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c ?<\/i><\/p><\/blockquote>\n<p>\u041d\u0443 \u0430 \u043c\u044b \u2014 \u0432 \u044d\u0442\u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u0434\u0435\u043d\u044c, \u043c\u043e\u0436\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0436\u0435\u043b\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0442\u0440\u0443\u0434\u044b \u043f\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0443 \u044d\u0442\u043e\u0433\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u0431\u044b\u043b\u0438 \u0434\u043b\u044f \u0432\u0430\u0441 \u043f\u043e\u043b\u0435\u0437\u043d\u044b.<\/p>\n<p>  \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0441\u0435\u0440\u0438\u044e \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u044f\u0434\u0440\u0430. \u0412 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 <code>\/proc<\/code>, \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>sysfs<\/code>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432. <a name=\"habracut\"><\/a><\/p>\n<h2><font color=\"#3AC1EF\">\u258d \u0413\u043e\u0442\u043e\u0432\u044b\u0435 \u0447\u0430\u0441\u0442\u0438 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430:<\/font><\/h2>\n<p>  <\/p>\n<ul>\n<li> <a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/681880\/\">\u0427\u0430\u0441\u0442\u044c 1<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/683106\/\">\u0427\u0430\u0441\u0442\u044c 2<\/a><\/li>\n<li><b><font color=\"#3AC1EF\">\u0412\u044b \u0442\u0443\u0442 &#8212;> <\/font><\/b><a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/684382\/\">\u0427\u0430\u0441\u0442\u044c 3<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/685168\/\">\u0427\u0430\u0441\u0442\u044c 4<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/686596\/\">\u0427\u0430\u0441\u0442\u044c 5<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/688564\/\">\u0427\u0430\u0441\u0442\u044c 6<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/689346\/\">\u0427\u0430\u0441\u0442\u044c 7<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<h2><font color=\"#3AC1EF\">7. \u0424\u0430\u0439\u043b\u043e\u0432\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \/proc<\/font><\/h2>\n<p>  \u0412 Linux \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u044f\u0434\u0440\u0443 \u0438 \u043c\u043e\u0434\u0443\u043b\u044f\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c \u2013 \u0444\u0430\u0439\u043b\u043e\u0432\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 <code>\/proc<\/code>. \u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0443\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u0445 (\u043e\u0442\u0441\u044e\u0434\u0430 \u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435), \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c \u044f\u0434\u0440\u0430, \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0449\u0438\u043c \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>\/proc\/modules<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u043c\u043e\u0434\u0443\u043b\u0435\u0439, \u0430 <code>\/proc\/meminfo<\/code> \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>  \u0421\u043f\u043e\u0441\u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>procfs<\/code> \u043e\u0447\u0435\u043d\u044c \u0441\u0445\u043e\u0436 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u043e\u0432 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u2013 \u0441\u043f\u0435\u0440\u0432\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u043e \u0432\u0441\u0435\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0439 \u0434\u043b\u044f \u0444\u0430\u0439\u043b\u0430 <code>\/proc<\/code>, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u043b\u044e\u0431\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u0430\u043a\u0430\u044f \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u0430, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u0430\u044f \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 <code>\/proc<\/code>). \u0414\u0430\u043b\u0435\u0435 <code>init_module<\/code> \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u044d\u0442\u0443 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044f\u0434\u0440\u0430, \u0430 <code>cleanup_module<\/code> \u0435\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u0441\u043d\u0438\u043c\u0430\u0435\u0442. <\/p>\n<p>  \u041e\u0431\u044b\u0447\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0434\u0438\u0441\u043a\u0435, \u0430 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 (\u0433\u0434\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f <code>\/proc<\/code>), \u0438 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u043e\u043c\u0435\u0440\u043e\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u043d\u043e\u0433\u043e \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430 (inode) \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0434\u0438\u0441\u043a\u0430, \u0433\u0434\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f <code>inode<\/code> \u0444\u0430\u0439\u043b\u0430. \u042d\u0442\u043e\u0442 <code>inode<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0444\u0430\u0439\u043b\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0438\u043b\u0438 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0434\u0438\u0441\u043a\u0430, \u0433\u0434\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u044d\u0442\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430.<\/p>\n<p>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0438 \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0438 \u0444\u0430\u0439\u043b\u0430 \u0432\u044b\u0437\u043e\u0432 \u043c\u044b \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c, \u0432 \u044d\u0442\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435 \u043d\u0435\u0442 \u043c\u0435\u0441\u0442\u0430, \u043a\u0443\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0432\u043d\u0435\u0441\u0442\u0438 <code>try_module_get<\/code> \u0438 <code>module_put<\/code>, \u0438 \u0435\u0441\u043b\u0438 \u043f\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u0432\u0434\u0440\u0443\u0433 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c, \u0442\u043e \u044d\u0442\u043e \u0447\u0440\u0435\u0432\u0430\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f\u043c\u0438.<\/p>\n<p>  \u0412\u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 <code>\/proc<\/code>. \u042d\u0442\u043e Hello World \u0434\u043b\u044f \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b <code>\/proc<\/code>. \u0417\u0434\u0435\u0441\u044c \u0443 \u043d\u0430\u0441 \u0442\u0440\u0438 \u0447\u0430\u0441\u0442\u0438: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 <code>\/proc\/helloworld<\/code> \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>init_module<\/code>, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f (\u0438 \u0431\u0443\u0444\u0435\u0440\u0430) <code>\/proc\/helloworld<\/code> \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 <code>procfile_read<\/code> \u043f\u0440\u0438 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0438 \u0435\u0433\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>cleanup_module<\/code>.<\/p>\n<p>  \u0423\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u043c\u043e\u0434\u0443\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>proc_create<\/code>. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0437\u0434\u0435\u0441\u044c \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f <code>struct proc_dir_entry<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043e \u0434\u043b\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f <code>\/proc\/helloworld<\/code> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430 \u044d\u0442\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430). \u041d\u0443\u043b\u0435\u0432\u043e\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043f\u0440\u043e\u0432\u0430\u043b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f.<\/p>\n<p>  \u041f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u0438 <code>\/proc\/helloworld<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>procfile_read<\/code>. \u0423 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0432\u0430\u0436\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430: \u0431\u0443\u0444\u0435\u0440 (\u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440) \u0438 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 (\u0447\u0435\u0442\u0432\u0435\u0440\u0442\u044b\u0439). \u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0431\u0443\u0444\u0435\u0440\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0435\u0433\u043e \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043c\u0430\u043d\u0434\u0435 <code>cat<\/code>). \u0421\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u2013 \u044d\u0442\u043e \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0444\u0430\u0439\u043b\u0430. \u0415\u0441\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435 \u043d\u0443\u043b\u0435\u0432\u043e\u0435, \u0442\u043e\u0433\u0434\u0430 \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e. \u0422\u0430\u043a \u0447\u0442\u043e \u0431\u0443\u0434\u044c\u0442\u0435 \u0441 \u043d\u0435\u0439 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b \u2013 \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0432\u0435\u0440\u043d\u0435\u0442 \u043d\u0443\u043b\u044c, \u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">procfs1.c<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">$ cat \/proc\/helloworld HelloWorld! \/*   * procfs1.c   *\/    #include &lt;linux\/kernel.h>  #include &lt;linux\/module.h>  #include &lt;linux\/proc_fs.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_name \"helloworld\"    static struct proc_dir_entry *our_proc_file;    static ssize_t procfile_read(struct file *filePointer, char __user *buffer,                               size_t buffer_length, loff_t *offset)  {      char s[13] = \"HelloWorld!\\n\";      int len = sizeof(s);      ssize_t ret = len;        if (*offset >= len || copy_to_user(buffer, s, len)) {          pr_info(\"copy_to_user failed\\n\");          ret = 0;      } else {          pr_info(\"procfile read %s\\n\", filePointer->f_path.dentry->d_name.name);          *offset += len;      }        return ret;  }    #ifdef HAVE_PROC_OPS  static const struct proc_ops proc_file_fops = {      .proc_read = procfile_read,  };  #else  static const struct file_operations proc_file_fops = {      .read = procfile_read,  };  #endif    static int __init procfs1_init(void)  {      our_proc_file = proc_create(procfs_name, 0644, NULL, &amp;proc_file_fops);      if (NULL == our_proc_file) {          proc_remove(our_proc_file);          pr_alert(\"Error:Could not initialize \/proc\/%s\\n\", procfs_name);          return -ENOMEM;      }        pr_info(\"\/proc\/%s created\\n\", procfs_name);      return 0;  }    static void __exit procfs1_exit(void)  {      proc_remove(our_proc_file);      pr_info(\"\/proc\/%s removed\\n\", procfs_name);  }    module_init(procfs1_init);  module_exit(procfs1_exit);    MODULE_LICENSE(\"GPL\");<\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  <\/p>\n<h3><font color=\"#3AC1EF\">\u258d 7.1 \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 proc_ops<\/font><\/h3>\n<p>  \u0412 Linux v5.6+ \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <code>proc_ops<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u0432 <code>include\/linux\/proc_fs.h<\/code>. \u0412 \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0430\u0440\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u043e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430 <code>file_operations<\/code> \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 <code>\/proc<\/code> \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0445\u0443\u043a\u043e\u0432. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u043d\u0435\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0447\u043b\u0435\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 VFS \u043d\u0435 \u043d\u0443\u0436\u043d\u044b, \u0438 \u0432\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 VFS \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u043d\u0430\u0431\u043e\u0440 <code>file_operations<\/code>, \u043a\u043e\u0434 <code>\/proc<\/code> \u0440\u0430\u0437\u0434\u0443\u0432\u0430\u0435\u0442\u0441\u044f. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u043b\u043e\u0441\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e, \u043d\u043e \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u0447\u0442\u043e \u043f\u043e\u0432\u044b\u0448\u0430\u043b\u043e \u0435\u0435 \u0431\u044b\u0441\u0442\u0440\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0444\u0430\u0439\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0438\u0441\u0447\u0435\u0437\u0430\u0435\u0442 \u0432 <code>\/proc<\/code>, \u043c\u043e\u0436\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c <code>proc_flag<\/code> \u043a\u0430\u043a <code>PROC_ENTRY_PERMANENT<\/code>, \u044d\u043a\u043e\u043d\u043e\u043c\u044f \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f\/\u0447\u0442\u0435\u043d\u0438\u044f\/\u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f 2 \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438: 1 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 1 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u0435.<\/p>\n<h3><font color=\"#3AC1EF\">\u258d 7.2 \u0421\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0444\u0430\u0439\u043b\u0430 \/proc<\/font><\/h3>\n<p>  \u0412\u044b\u0448\u0435 \u0431\u044b\u043b \u043e\u043f\u0438\u0441\u0430\u043d \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>\/proc<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043b\u0438 \u0444\u0430\u0439\u043b <code>\/proc\/helloworld<\/code>. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432 <code>\/proc<\/code> \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c. \u041f\u0440\u0438\u043d\u0446\u0438\u043f \u0442\u043e\u0442 \u0436\u0435, \u0447\u0442\u043e \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043e \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u0435\u043c \u2013 \u043f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0444\u0430\u0439\u043b <code>\/proc<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f. \u041d\u043e \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u2013 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u2013 \u0437\u043d\u0430\u0447\u0438\u0442 \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u044f\u0434\u0440\u0430 (\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>copy_from_user<\/code> \u0438\u043b\u0438 <code>get_user<\/code>).<\/p>\n<p>  \u041f\u0440\u0438\u0447\u0438\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>copy_from_user<\/code> \u043b\u0438\u0431\u043e <code>get_user<\/code> \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0430\u043c\u044f\u0442\u044c Linux \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0430 (\u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430\u0445 \u0441 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043e\u0439 Intel \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435 \u0442\u0430\u043a). \u0422\u043e \u0435\u0441\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0441\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0435 \u043d\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u0443\u044e \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u0430 \u043d\u0430 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432 \u0435\u0435 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0435, \u0438 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0437\u0430 \u0441\u0435\u0433\u043c\u0435\u043d\u0442. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0434\u0438\u043d \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f \u044f\u0434\u0440\u0430 \u0438 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432.<\/p>\n<p>  \u041f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0445 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u043f\u0430\u043c\u044f\u0442\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u0442\u0441\u044f \u043e \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430\u0445 \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f. \u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0435 \u043c\u043e\u0434\u0443\u043b\u044c \u044f\u0434\u0440\u0430, \u0442\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0443 \u043f\u0430\u043c\u044f\u0442\u0438 \u044f\u0434\u0440\u0430, \u0438 \u044d\u0442\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438. \u041e\u0434\u043d\u0430\u043a\u043e, \u043a\u043e\u0433\u0434\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0431\u0443\u0444\u0435\u0440\u0430 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u043c\u0441\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c \u0438 \u044f\u0434\u0440\u043e\u043c, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u044f\u0434\u0440\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0431\u0443\u0444\u0435\u0440 \u043f\u0430\u043c\u044f\u0442\u0438, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0439\u0441\u044f \u0432 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430.<\/p>\n<p>  \u041a \u044d\u0442\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043c\u0430\u043a\u0440\u043e\u0441\u044b <code>put_user<\/code> \u0438 <code>get_user<\/code>, \u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442 \u044d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0441\u0438\u043c\u0432\u043e\u043b. \u0414\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c <code>copy_to_user<\/code> \u0438 <code>copy_from_user<\/code>. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0431\u0443\u0444\u0435\u0440 (\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0447\u0442\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u0438) \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u044f\u0434\u0440\u0430, \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0438 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u0438\u0437 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0447\u0442\u0435\u043d\u0438\u044f \u044d\u0442\u043e \u043d\u0435 \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0443\u0436\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u044f\u0434\u0440\u0430.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">procfs2.c<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">\/*   * procfs2.c - \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \"\u0444\u0430\u0439\u043b\u0430\" \u0432 \/proc   *\/    #include &lt;linux\/kernel.h> \/* \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u044f\u0434\u0440\u043e\u043c. *\/  #include &lt;linux\/module.h> \/* \u0414\u043b\u044f \u043c\u043e\u0434\u0443\u043b\u0435\u0439. *\/  #include &lt;linux\/proc_fs.h> \/* \u0414\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f procfs.*\/  #include &lt;linux\/uaccess.h> \/* \u0414\u043b\u044f copy_from_user. *\/  #include &lt;linux\/version.h>    #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0)  #define HAVE_PROC_OPS  #endif    #define PROCFS_MAX_SIZE 1024  #define PROCFS_NAME \"buffer1k\"    \/* \u042d\u0442\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0444\u0430\u0439\u043b\u0435 \/proc. *\/  static struct proc_dir_entry *our_proc_file;    \/* \u042d\u0442\u043e\u0442 \u0431\u0443\u0444\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0434 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u0430 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f. *\/  static char procfs_buffer[PROCFS_MAX_SIZE];    \/* \u0420\u0430\u0437\u043c\u0435\u0440 \u0431\u0443\u0444\u0435\u0440\u0430. *\/  static unsigned long procfs_buffer_size = 0;    \/* \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u0438 \u0444\u0430\u0439\u043b\u0430 \/proc. *\/  static ssize_t procfile_read(struct file *filePointer, char __user *buffer,                               size_t buffer_length, loff_t *offset)  {      char s[13] = \"HelloWorld!\\n\";      int len = sizeof(s);      ssize_t ret = len;        if (*offset >= len || copy_to_user(buffer, s, len)) {          pr_info(\"copy_to_user failed\\n\");          ret = 0;      } else {          pr_info(\"procfile read %s\\n\", filePointer->f_path.dentry->d_name.name);          *offset += len;      }        return ret;  }    \/* \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0444\u0430\u0439\u043b\u0430 \/proc. *\/  static ssize_t procfile_write(struct file *file, const char __user *buff,                                size_t len, loff_t *off)  {      procfs_buffer_size = len;      if (procfs_buffer_size > PROCFS_MAX_SIZE)          procfs_buffer_size = PROCFS_MAX_SIZE;        if (copy_from_user(procfs_buffer, buff, procfs_buffer_size))          return -EFAULT;        procfs_buffer[procfs_buffer_size &amp; (PROCFS_MAX_SIZE - 1)] = '\\0';      pr_info(\"procfile write %s\\n\", procfs_buffer);        return procfs_buffer_size;  }    #ifdef HAVE_PROC_OPS  static const struct proc_ops proc_file_fops = {      .proc_read = procfile_read,      .proc_write = procfile_write,  };  #else  static const struct file_operations proc_file_fops = {      .read = procfile_read,      .write = procfile_write,  };  #endif    static int __init procfs2_init(void)  {      our_proc_file = proc_create(PROCFS_NAME, 0644, NULL, &amp;proc_file_fops);      if (NULL == our_proc_file) {          proc_remove(our_proc_file);          pr_alert(\"Error:Could not initialize \/proc\/%s\\n\", PROCFS_NAME);          return -ENOMEM;      }        pr_info(\"\/proc\/%s created\\n\", PROCFS_NAME);      return 0;  }    static void __exit procfs2_exit(void)  {      proc_remove(our_proc_file);      pr_info(\"\/proc\/%s removed\\n\", PROCFS_NAME);  }    module_init(procfs2_init);  module_exit(procfs2_exit);    MODULE_LICENSE(\"GPL\");<\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  <\/p>\n<h3><font color=\"#3AC1EF\">\u258d 7.3 \u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u043c \/proc \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b<\/font><\/h3>\n<p>  \u041c\u044b \u0443\u0436\u0435 \u0432\u0438\u0434\u0435\u043b\u0438, \u043a\u0430\u043a \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0432 <code>procfs<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 <code>\/proc<\/code>. \u041d\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0442\u0430\u043a\u0438\u043c\u0438 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>inode<\/code>. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0441\u0443\u0442\u044c \u0437\u0434\u0435\u0441\u044c \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u0412 Linux \u0435\u0441\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0434\u043b\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441 <code>inode<\/code> \u0438 \u0444\u0430\u0439\u043b\u0430\u043c\u0438, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0441\u043e\u0431\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u043d\u0430 \u044d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, <code>struct inode_operations<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0442\u0430\u043a\u0436\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 <code>struct proc_ops<\/code>.<\/p>\n<p>  \u041e\u0442\u043b\u0438\u0447\u0430\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441 <code>inode<\/code> \u043e\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u0442\u043e, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441 \u0441\u0430\u043c\u0438\u043c\u0438 \u0444\u0430\u0439\u043b\u0430\u043c\u0438, \u0430 \u043f\u0435\u0440\u0432\u044b\u0435 \u0441\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0444\u0430\u0439\u043b\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u044f \u043d\u0430 \u043d\u0435\u0433\u043e \u0441\u0441\u044b\u043b\u043a\u0438.<\/p>\n<p>  \u0412 <code>\/proc<\/code> \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u043c\u044b \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435, \u043a\u0430\u043a\u0430\u044f <code>struct inode_operations<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043d\u0435\u043c\u0443. \u042d\u0442\u043e\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043c\u044b \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u2014 <code>struct inode_operations<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 <code>struct proc_ops<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u043d\u0430\u0448\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>procf_read<\/code> \u0438 <code>procfs_write<\/code>.<\/p>\n<p>  \u0415\u0449\u0435 \u043e\u0434\u0438\u043d \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u2013 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>module_permission<\/code>. \u041e\u043d\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0441 \u0444\u0430\u0439\u043b\u043e\u043c <code>\/proc<\/code>, \u0438 \u043c\u043e\u0436\u0435\u0442 \u0440\u0435\u0448\u0430\u0442\u044c, \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0435\u0433\u043e \u043a \u044d\u0442\u043e\u043c\u0443 \u0444\u0430\u0439\u043b\u0443 \u0438\u043b\u0438 \u043d\u0435\u0442. \u0421\u0435\u0439\u0447\u0430\u0441 \u043e\u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043b\u0438\u0448\u044c \u043d\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0438 uid \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (\u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u0438\u0437 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0435\u043c\u0441\u044f \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435), \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u043d\u0430 \u0447\u0435\u043c-\u0442\u043e \u0434\u0440\u0443\u0433\u043e\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 \u0442\u043e\u043c, \u043a\u0430\u043a\u0438\u0435 \u0435\u0449\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 \u0442\u0435\u043c \u0436\u0435 \u0444\u0430\u0439\u043b\u043e\u043c, \u043d\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043d\u044f \u0438\u043b\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u043c \u0432\u0432\u043e\u0434\u0435. <\/p>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u044f\u0441\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0440\u043e\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u044f\u0434\u0440\u0435 \u0440\u0435\u0432\u0435\u0440\u0441\u0438\u0440\u0443\u044e\u0442\u0441\u044f. \u041f\u0435\u0440\u0432\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430, \u0430 \u0432\u0442\u043e\u0440\u044b\u0435 \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430. \u041e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u0442\u0435\u043c, \u0447\u0442\u043e \u0447\u0442\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u2013 \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0447\u0442\u043e-\u0442\u043e \u0438\u0437 \u044f\u0434\u0440\u0430 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442, \u0442\u043e \u0434\u043b\u044f \u044f\u0434\u0440\u0430 \u044d\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u044b\u0432\u043e\u0434\u043e\u043c, \u0430 \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u044f\u0434\u0440\u043e, \u0442\u043e\u0433\u0434\u0430 \u0434\u043b\u044f \u044f\u0434\u0440\u0430 \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u0430\u043a \u0432\u0432\u043e\u0434.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">procfs3.c<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">\/*   * procfs3.c   *\/    #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>  <\/div>\n<\/p><\/div>\n<p>  \u0425\u043e\u0442\u0438\u0442\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0441 <code>procfs<\/code>? \u0427\u0442\u043e \u0436, \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438\u043c\u0435\u0439\u0442\u0435 \u0432\u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u043f\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 <code>procfs<\/code> \u0434\u043e\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u0432\u043e\u0438 \u0434\u043d\u0438, \u0438 \u043d\u0443\u0436\u043d\u043e \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>sysfs<\/code>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0435 \u0441 \u044f\u0434\u0440\u043e\u043c, \u0442\u043e \u043f\u043e\u0434\u0443\u043c\u0430\u0439\u0442\u0435 \u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430.<\/p>\n<h3><font color=\"#3AC1EF\">\u258d 7.4 \u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u043c \/proc \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e seq_file<\/font><\/h3>\n<p>  \u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0435\u043b\u0438, \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 \u0432 <code>\/proc<\/code> \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 API <code>seq_file<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b <code>\/proc<\/code> \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430. \u041e\u0441\u043d\u043e\u0432\u0430\u043d \u044d\u0442\u043e\u0442 API \u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438\u0437 3 \u0444\u0443\u043d\u043a\u0446\u0438\u0439: <code>start()<\/code>, <code>next()<\/code> \u0438 <code>stop()<\/code>. \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 <code>seq_file<\/code> \u044d\u0442\u0443 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0444\u0430\u0439\u043b <code>\/proc<\/code>.<\/p>\n<p>  \u041d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0435 \u0441 \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>start()<\/code> \u2013 \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0432\u0435\u0440\u043d\u0435\u0442 \u043d\u0435 <code>NULL<\/code>, \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>next()<\/code>. \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c, \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u044e\u0449\u0438\u043c \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u041f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 <code>next()<\/code> \u0442\u0430\u043a\u0436\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>show()<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0431\u0443\u0444\u0435\u0440, \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c. \u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>next()<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0432\u0435\u0440\u043d\u0435\u0442 <code>NULL<\/code>, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f, \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>stop()<\/code>.<\/p>\n<blockquote><p>\u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u041f\u043e\u0441\u043b\u0435 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>stop()<\/code> \u0441\u043d\u043e\u0432\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>start()<\/code>. \u0417\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u044d\u0442\u043e\u0442 \u0446\u0438\u043a\u043b, \u043a\u043e\u0433\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>start()<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>NULL<\/code>. \u041e\u0431\u0449\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0430 \u043d\u0430 \u0440\u0438\u0441. 1.<\/p><\/blockquote>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/iu\/3i\/8p\/iu3i8pqyc35g1mwatdoqfmvijxu.png\" data-src=\"https:\/\/habrastorage.org\/webt\/iu\/3i\/8p\/iu3i8pqyc35g1mwatdoqfmvijxu.png\"\/><br \/>  <i><font color=\"#999999\">\u0420\u0438\u0441. 1: \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b seq_file<\/font><\/i><\/p>\n<p>  \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>seq_file<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f <code>proc_ops<\/code>, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a <code>seq_read<\/code>, <code>seq_lseek<\/code> \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435, \u043d\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0444\u0430\u0439\u043b <code>\/proc<\/code>. \u0425\u043e\u0442\u044f \u0432\u044b \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">procfs4.c<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">\/*   * procfs4.c - \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \"\u0444\u0430\u0439\u043b\u0430\" \u0432 \/proc   * \u042d\u0442\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u043e\u043c \/proc \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 seq_file.   *\/    #include &lt;linux\/kernel.h> \/* \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u044f\u0434\u0440\u043e\u043c. *\/  #include &lt;linux\/module.h> \/* \u0414\u043b\u044f \u043c\u043e\u0434\u0443\u043b\u0435\u0439. *\/  #include &lt;linux\/proc_fs.h> \/* \u0414\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f procfs *\/  #include &lt;linux\/seq_file.h> \/* \u0414\u043b\u044f seq_file *\/  #include &lt;linux\/version.h>    #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0)  #define HAVE_PROC_OPS  #endif    #define PROC_NAME \"iter\"    \/* \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.   * \u0422\u043e \u0435\u0441\u0442\u044c, \u043a\u043e\u0433\u0434\u0430:   *   - \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0430\u0439\u043b \/proc   *   - \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (\u0432 \u043a\u043e\u043d\u0446\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438)   *\/  static void *my_seq_start(struct seq_file *s, loff_t *pos)  {      static unsigned long counter = 0;        \/* \u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c? *\/      if (*pos == 0) {          \/* \u0414\u0430 => \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u043d\u0443\u043b\u0435\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 *\/          return &amp;counter;      }        \/* \u041d\u0435\u0442 => \u044d\u0442\u043e \u043a\u043e\u043d\u0435\u0446 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f NULL \u0434\u043b\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u044f *\/      *pos = 0;      return NULL;  }    \/* \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.   * \u0415\u0435 \u0432\u044b\u0437\u043e\u0432 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442\u0441\u044f \u0434\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f NULL (\u0437\u0430\u0442\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f).   *\/  static void *my_seq_next(struct seq_file *s, void *v, loff_t *pos)  {      unsigned long *tmp_v = (unsigned long *)v;      (*tmp_v)++;      (*pos)++;      return NULL;  }    \/* \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0446\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. *\/  static void my_seq_stop(struct seq_file *s, void *v)  {      \/* \u0414\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0447\u0435\u0433\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432 start() \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. *\/  }    \/* \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u00ab\u0448\u0430\u0433\u0430\u00bb \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. *\/  static int my_seq_show(struct seq_file *s, void *v)  {      loff_t *spos = (loff_t *)v;        seq_printf(s, \"%Ld\\n\", *spos);      return 0;  }    \/* \u042d\u0442\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \"\u0444\u0443\u043d\u043a\u0446\u0438\u044e\" \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e. *\/  static struct seq_operations my_seq_ops = {      .start = my_seq_start,      .next = my_seq_next,      .stop = my_seq_stop,      .show = my_seq_show,  };    \/* \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0438 \u0444\u0430\u0439\u043b\u0430 \/proc. *\/  static int my_open(struct inode *inode, struct file *file)  {      return seq_open(file, &amp;my_seq_ops);  };    \/* \u042d\u0442\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u201c\u0444\u0443\u043d\u043a\u0446\u0438\u044e\u201d, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0443\u044e \u0444\u0430\u0439\u043b\u043e\u043c \/proc. *\/  #ifdef HAVE_PROC_OPS  static const struct proc_ops my_file_ops = {      .proc_open = my_open,      .proc_read = seq_read,      .proc_lseek = seq_lseek,      .proc_release = seq_release,  };  #else  static const struct file_operations my_file_ops = {      .open = my_open,      .read = seq_read,      .llseek = seq_lseek,      .release = seq_release,  };  #endif    static int __init procfs4_init(void)  {      struct proc_dir_entry *entry;        entry = proc_create(PROC_NAME, 0, NULL, &amp;my_file_ops);      if (entry == NULL) {          remove_proc_entry(PROC_NAME, NULL);          pr_debug(\"Error: Could not initialize \/proc\/%s\\n\", PROC_NAME);          return -ENOMEM;      }        return 0;  }    static void __exit procfs4_exit(void)  {      remove_proc_entry(PROC_NAME, NULL);      pr_debug(\"\/proc\/%s removed\\n\", PROC_NAME);  }    module_init(procfs4_init);  module_exit(procfs4_exit);    MODULE_LICENSE(\"GPL\");<\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u044d\u0442\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b:<\/p>\n<ul>\n<li><a href=\"https:\/\/lwn.net\/Articles\/22355\/\">lwn.net\/Articles\/22355<\/a><\/li>\n<li><a href=\"https:\/\/kernelnewbies.org\/Documents\/SeqFileHowTo\">kernelnewbies.org\/Documents\/SeqFileHowTo<\/a><\/li>\n<\/ul>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u043e\u0434 <code><a href=\"https:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/stable\/linux.git\/tree\/fs\/seq_file.c\">fs\/seq_file.c<\/a><\/code> \u0432 \u044f\u0434\u0440\u0435.<\/p>\n<h2><font color=\"#3AC1EF\">\u258d 8 sysfs: \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u043c\u043e\u0434\u0443\u043b\u0435\u043c<\/font><\/h2>\n<p>  <code>Sysfs<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u043c \u044f\u0434\u0440\u043e\u043c \u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430, \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0438\u043b\u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u043e\u0434\u0443\u043b\u0435\u0439. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u0446\u0435\u043b\u044f\u0445 \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u0438\u043b\u0438 \u0436\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0434\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043b\u0438\u0431\u043e \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432. \u041a\u0430\u0442\u0430\u043b\u043e\u0433\u0438 \u0438 \u0444\u0430\u0439\u043b\u044b <code>sysfs<\/code> \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442\u0441\u044f \u0432 <i>\/sys<\/i>.<\/p>\n<pre><code class=\"bash\">ls -l \/sys<\/code><\/pre>\n<p>  \u0410\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0434\u043b\u044f <code>kobjects<\/code> \u0432 \u044d\u0442\u043e\u0439 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043c\u043e\u0436\u043d\u043e \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0444\u043e\u0440\u043c\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432. <code>Sysfs<\/code> \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u044b, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044f \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u044f\u0434\u0440\u0430.<\/p>\n<p>  \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430:<\/p>\n<pre><code class=\"cpp\">struct attribute {      char *name;      struct module *owner;      umode_t mode;  };    int sysfs_create_file(struct kobject * kobj, const struct attribute * attr);  8void sysfs_remove_file(struct kobject * kobj, const struct attribute * attr);<\/code><\/pre>\n<p>  \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 struct device_attribute \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">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);  };    int device_create_file(struct device *, const struct device_attribute *);  void device_remove_file(struct device *, const struct device_attribute *);<\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442, \u043f\u0440\u0438 \u0435\u0433\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>show()<\/code> \u0438\u043b\u0438 <code>store()<\/code>. \u0414\u043b\u044f \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 <code><a href=\"https:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/stable\/linux.git\/tree\/include\/linux\/sysfs.h\">include\/linux\/sysfs.h<\/a><\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u043c\u0430\u043a\u0440\u043e\u0441\u044b (<code>__ATTR<\/code>, <code>__ATTR_RO<\/code>, <code>__ATTR_WO<\/code>, \u0438 \u0442.\u0434.), \u0443\u043f\u0440\u043e\u0449\u0430\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u0434 \u0431\u043e\u043b\u0435\u0435 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u043c \u0438 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u043c.<\/p>\n<p>  \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0434\u0443\u043b\u044f \u201cHello world\u201d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0439 \u0447\u0435\u0440\u0435\u0437 <code>sysfs<\/code>:<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">hello-sysfs.c<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">\/*   * hello-sysfs.c - \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f sysfs   *\/  #include &lt;linux\/fs.h>  #include &lt;linux\/init.h>  #include &lt;linux\/kobject.h>  #include &lt;linux\/module.h>  #include &lt;linux\/string.h>  #include &lt;linux\/sysfs.h>    static struct kobject *mymodule;    \/* \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c. *\/  static int myvariable = 0;    static ssize_t myvariable_show(struct kobject *kobj,                                 struct kobj_attribute *attr, char *buf)  {      return sprintf(buf, \"%d\\n\", myvariable);  }    static ssize_t myvariable_store(struct kobject *kobj,                                  struct kobj_attribute *attr, char *buf,                                  size_t count)  {      sscanf(buf, \"%du\", &amp;myvariable);      return count;  }    static struct kobj_attribute myvariable_attribute =      __ATTR(myvariable, 0660, myvariable_show, (void *)myvariable_store);    static int __init mymodule_init(void)  {      int error = 0;        pr_info(\"mymodule: initialised\\n\");        mymodule = kobject_create_and_add(\"mymodule\", kernel_kobj);      if (!mymodule)          return -ENOMEM;        error = sysfs_create_file(mymodule, &amp;myvariable_attribute.attr);      if (error) {          pr_info(\"failed to create the myvariable file \"                  \"in \/sys\/kernel\/mymodule\\n\");      }        return error;  }    static void __exit mymodule_exit(void)  {      pr_info(\"mymodule: Exit success\\n\");      kobject_put(mymodule);  }    module_init(mymodule_init);  module_exit(mymodule_exit);    MODULE_LICENSE(\"GPL\");<\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043c\u043e\u0434\u0443\u043b\u044f:<\/p>\n<pre><code class=\"bash\">make  sudo insmod hello-sysfs.ko<\/code><\/pre>\n<p>  \u0423\u0431\u0435\u0436\u0434\u0430\u0435\u043c\u0441\u044f \u0432 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0441\u0442\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"bash\">sudo lsmod | grep hello_sysfs<\/code><\/pre>\n<p>  \u041a\u0430\u043a\u043e\u0432\u043e \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>myvariable<\/code>?<\/p>\n<pre><code class=\"bash\">cat \/sys\/kernel\/mymodule\/myvariable<\/code><\/pre>\n<p>  \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>myvariable<\/code> \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430, \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c \u043b\u0438 \u043e\u043d\u043e:<\/p>\n<pre><code class=\"bash\">echo \"32\" > \/sys\/kernel\/mymodule\/myvariable  cat \/sys\/kernel\/mymodule\/myvariable<\/code><\/pre>\n<p>  \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f:<\/p>\n<pre><code class=\"bash\">sudo rmmod hello_sysfs<\/code><\/pre>\n<p>  \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u044b\u0448\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0432 <code>sysfs<\/code> \u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0435\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 <code>kobject<\/code>. \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 Linux v2.6.0, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <code>kobject<\/code> \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u043e\u0431\u0440\u0435\u0442\u0430\u043b\u0430 \u0441\u0432\u043e\u0439 \u043d\u044b\u043d\u0435\u0448\u043d\u0438\u0439 \u043e\u0431\u043b\u0438\u043a. \u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043e\u043d\u0430 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u043b\u0430\u0441\u044c \u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0443\u043d\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u044f\u0434\u0440\u0430, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0441 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u043e\u043c \u0441\u0441\u044b\u043b\u043e\u043a. \u041e\u0434\u043d\u0430\u043a\u043e \u0441\u043f\u0443\u0441\u0442\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0435\u0435 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u043b\u043e\u0441\u044c, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u043d\u0430 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 <code>sysfs<\/code>. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e <code>kobject<\/code> \u0438 <code>sysfs<\/code> \u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0432 <a href=\"https:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/stable\/linux.git\/tree\/Documentation\/driver-api\/driver-model\/driver.rst\">Documentation\/driver-api\/driver-model\/driver.rst<\/a> \u0438 <a href=\"https:\/\/lwn.net\/Articles\/51437\/\">lwn.net\/Articles\/51437<\/a>.<\/p>\n<h2><font color=\"#3AC1EF\">\u258d 9. \u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432<\/font><\/h2>\n<p>  \u0424\u0430\u0439\u043b\u044b \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0442\u0430\u043a\u0438\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0438 \u0432\u0432\u043e\u0434\u0430, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u043d\u0435\u043a\u0438\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b \u0438\u0445 \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u043c\u0441\u044f \u0432 \u044f\u0434\u0440\u0435 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u043e\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u0434\u043b\u044f \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0430\u043c\u0438\u043c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0444\u0430\u0439\u043b \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0438 \u0432 \u043d\u0435\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u044c, \u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0444\u0430\u0439\u043b. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0438\u0436\u0435 \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>device_write<\/code>.<\/p>\n<p>  \u041d\u043e \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u043e\u0440\u0442\u0443 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d \u043c\u043e\u0434\u0435\u043c (\u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043c\u043e\u0434\u0435\u043c \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439, \u044d\u0442\u0430 \u0441\u0445\u0435\u043c\u0430 \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043c\u043e\u0434\u0435\u043c, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0439 \u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u043e\u0440\u0442\u0443, \u0442\u0430\u043a \u0447\u0442\u043e \u0432\u043e\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043e\u0441\u043e\u0431\u043e \u043d\u0430\u043f\u0440\u044f\u0433\u0430\u0442\u044c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e). \u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0437\u0434\u0435\u0441\u044c \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u0430\u043a \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0430 \u043c\u043e\u0434\u0435\u043c (\u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u043a\u043e\u043c\u0430\u043d\u0434 \u0438\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438), \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0441 \u043d\u0435\u0433\u043e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u043d\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445). \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0436\u0435 \u0434\u0435\u043b\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0441\u0430\u043c\u0438\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u043e\u0440\u0442\u043e\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438\/\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u0412 Unix \u043e\u0442\u0432\u0435\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>ioctl<\/code> (\u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u043d\u043e \u043e\u0442 Input Output ConTroL). \u041a\u0430\u0436\u0434\u043e\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>ioctl<\/code>, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0435 \u0447\u0442\u0435\u043d\u0438\u0435 (\u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u044f\u0434\u0440\u0443), \u0437\u0430\u043f\u0438\u0441\u044c (\u0434\u043b\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443), \u0438 \u0442\u043e \u0438 \u0434\u0440\u0443\u0433\u043e\u0435, \u043b\u0438\u0431\u043e \u043d\u0438 \u043e\u0434\u043d\u043e \u0438\u0437 \u044d\u0442\u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439. \u0418\u043c\u0435\u0439\u0442\u0435 \u0432\u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u0432 <code>ioctl<\/code> \u0440\u043e\u043b\u0438 \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0441\u043d\u043e\u0432\u0430 \u0440\u0435\u0432\u0435\u0440\u0441\u0438\u0440\u0443\u044e\u0442\u0441\u044f, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u044f\u0434\u0440\u0443, \u0430 \u043f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0435\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043e\u0442 \u044f\u0434\u0440\u0430.<\/p>\n<p>  \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>ioctl<\/code> \u0441 \u0442\u0440\u0435\u043c\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438: \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u043e\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430, \u043d\u043e\u043c\u0435\u0440\u043e\u043c <code>ioctl<\/code> \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c, \u0438\u043c\u0435\u044e\u0449\u0438\u043c \u0442\u0438\u043f <code>long<\/code>, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0435\u0435 \u0441 \u0435\u0433\u043e \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435, \u0447\u0442\u043e \u0437\u0430\u0445\u043e\u0447\u0435\u0442\u0441\u044f. \u0422\u0430\u043a\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043d\u0435 \u0443\u0434\u0430\u0441\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043d\u0435\u0435. \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">ioctl.c<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">\/*   * ioctl.c   *\/  #include &lt;linux\/cdev.h>  #include &lt;linux\/fs.h>  #include &lt;linux\/init.h>  #include &lt;linux\/ioctl.h>  #include &lt;linux\/module.h>  #include &lt;linux\/slab.h>  #include &lt;linux\/uaccess.h>    struct ioctl_arg {      unsigned int val;  };    \/* Documentation\/ioctl\/ioctl-number.txt *\/  #define IOC_MAGIC '\\x66'    #define IOCTL_VALSET _IOW(IOC_MAGIC, 0, struct ioctl_arg)  #define IOCTL_VALGET _IOR(IOC_MAGIC, 1, struct ioctl_arg)  #define IOCTL_VALGET_NUM _IOR(IOC_MAGIC, 2, int)  #define IOCTL_VALSET_NUM _IOW(IOC_MAGIC, 3, int)    #define IOCTL_VAL_MAXNR 3  #define DRIVER_NAME \"ioctltest\"    static unsigned int test_ioctl_major = 0;  static unsigned int num_of_dev = 1;  static struct cdev test_ioctl_cdev;  static int ioctl_num = 0;    struct test_ioctl_data {      unsigned char val;      rwlock_t lock;  };    static long test_ioctl_ioctl(struct file *filp, unsigned int cmd,                               unsigned long arg)  {      struct test_ioctl_data *ioctl_data = filp->private_data;      int retval = 0;      unsigned char val;      struct ioctl_arg data;      memset(&amp;data, 0, sizeof(data));        switch (cmd) {      case IOCTL_VALSET:          if (copy_from_user(&amp;data, (int __user *)arg, sizeof(data))) {              retval = -EFAULT;              goto done;          }            pr_alert(\"IOCTL set val:%x .\\n\", data.val);          write_lock(&amp;ioctl_data->lock);          ioctl_data->val = data.val;          write_unlock(&amp;ioctl_data->lock);          break;        case IOCTL_VALGET:          read_lock(&amp;ioctl_data->lock);          val = ioctl_data->val;          read_unlock(&amp;ioctl_data->lock);          data.val = val;            if (copy_to_user((int __user *)arg, &amp;data, sizeof(data))) {              retval = -EFAULT;              goto done;          }            break;        case IOCTL_VALGET_NUM:          retval = __put_user(ioctl_num, (int __user *)arg);          break;        case IOCTL_VALSET_NUM:          ioctl_num = arg;          break;        default:          retval = -ENOTTY;      }    done:      return retval;  }    static ssize_t test_ioctl_read(struct file *filp, char __user *buf,                                 size_t count, loff_t *f_pos)  {      struct test_ioctl_data *ioctl_data = filp->private_data;      unsigned char val;      int retval;      int i = 0;        read_lock(&amp;ioctl_data->lock);      val = ioctl_data->val;      read_unlock(&amp;ioctl_data->lock);        for (; i &lt; count; i++) {          if (copy_to_user(&amp;buf[i], &amp;val, 1)) {              retval = -EFAULT;              goto out;          }      }        retval = count;  out:      return retval;  }    static int test_ioctl_close(struct inode *inode, struct file *filp)  {      pr_alert(\"%s call.\\n\", __func__);        if (filp->private_data) {          kfree(filp->private_data);          filp->private_data = NULL;      }        return 0;  }    static int test_ioctl_open(struct inode *inode, struct file *filp)  {      struct test_ioctl_data *ioctl_data;        pr_alert(\"%s call.\\n\", __func__);      ioctl_data = kmalloc(sizeof(struct test_ioctl_data), GFP_KERNEL);        if (ioctl_data == NULL)          return -ENOMEM;        rwlock_init(&amp;ioctl_data->lock);      ioctl_data->val = 0xFF;      filp->private_data = ioctl_data;        return 0;  }    static struct file_operations fops = {      .owner = THIS_MODULE,      .open = test_ioctl_open,      .release = test_ioctl_close,      .read = test_ioctl_read,      .unlocked_ioctl = test_ioctl_ioctl,  };    static int ioctl_init(void)  {      dev_t dev;      int alloc_ret = -1;      int cdev_ret = -1;      alloc_ret = alloc_chrdev_region(&amp;dev, 0, num_of_dev, DRIVER_NAME);        if (alloc_ret)          goto error;        test_ioctl_major = MAJOR(dev);      cdev_init(&amp;test_ioctl_cdev, &amp;fops);      cdev_ret = cdev_add(&amp;test_ioctl_cdev, dev, num_of_dev);        if (cdev_ret)          goto error;        pr_alert(\"%s driver(major: %d) installed.\\n\", DRIVER_NAME,               test_ioctl_major);      return 0;  error:      if (cdev_ret == 0)          cdev_del(&amp;test_ioctl_cdev);      if (alloc_ret == 0)          unregister_chrdev_region(dev, num_of_dev);      return -1;  }    static void ioctl_exit(void)  {      dev_t dev = MKDEV(test_ioctl_major, 0);        cdev_del(&amp;test_ioctl_cdev);      unregister_chrdev_region(dev, num_of_dev);      pr_alert(\"%s driver removed.\\n\", DRIVER_NAME);  }    module_init(ioctl_init);  module_exit(ioctl_exit);    MODULE_LICENSE(\"GPL\");  MODULE_DESCRIPTION(\"This is test_ioctl module\");<\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>test_ioctl_ioctl()<\/code> \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>cmd<\/code>. \u042d\u0442\u043e \u043d\u043e\u043c\u0435\u0440 <code>ioctl<\/code>. \u041e\u043d \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442 \u0441\u0442\u0430\u0440\u0448\u0438\u0439 (major) \u043d\u043e\u043c\u0435\u0440 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430, \u0442\u0438\u043f <code>ioctl<\/code>, \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0438 \u0442\u0438\u043f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430. \u041e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e\u0442 \u043d\u043e\u043c\u0435\u0440 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u043c\u0430\u043a\u0440\u043e\u0441\u0430 (<code>_IO<\/code>, <code>_IOR<\/code>, <code>_IOW<\/code> \u0438\u043b\u0438 <code>_IOWR<\/code> \u2014 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u0430) \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435. \u042d\u0442\u043e\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u043a\u043b\u044e\u0447\u0435\u043d \u0438 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>ioctl<\/code> (\u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u043c\u043e\u0433\u043b\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0435 <code>ioctl<\/code>), \u0438 \u0432 \u043c\u043e\u0434\u0443\u043b\u044c \u044f\u0434\u0440\u0430 (\u0447\u0442\u043e\u0431\u044b \u043e\u043d \u043c\u043e\u0433 \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c). \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0438\u0436\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u043c \u0444\u0430\u0439\u043b\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>chardev.h<\/code>, \u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0435\u0439 \u0435\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043e\u0439 <code>userspace_ioctl.c<\/code>.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>ioctl<\/code> \u0432 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u044f\u0445, \u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043b\u044f \u043d\u0435\u0435 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0435 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0422\u043e\u0433\u0434\u0430, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0447\u0443\u0436\u0430\u044f <code>ioctl<\/code>, \u0442\u043e \u0441\u0440\u0430\u0437\u0443 \u0441\u0442\u0430\u043d\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0447\u0442\u043e-\u0442\u043e \u043d\u0435 \u0442\u0430\u043a. \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432 \u0434\u0435\u0440\u0435\u0432\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u044f\u0434\u0440\u0430 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 <a href=\"https:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/stable\/linux.git\/tree\/Documentation\/userspace-api\/ioctl\/ioctl-number.rst\">Documentation\/userspace-api\/ioctl\/ioctl-number.rst<\/a><\/p>\n<p>  \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u043c\u0435\u0442\u044c \u0432\u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0435 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u0433\u043e\u043d\u043a\u0438. \u0420\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u0443\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0441 \u043e\u0431\u043c\u0435\u043d\u043e\u043c (CAS), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u0430\u0441\u044c \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 6.5, \u0447\u0442\u043e\u0431\u044b \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">chardev2.c<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">\/*   * chardev2.c \u2013 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u0432\u0432\u043e\u0434\u0430\/\u0432\u044b\u0432\u043e\u0434\u0430   *\/    #include &lt;linux\/cdev.h>  #include &lt;linux\/delay.h>  #include &lt;linux\/device.h>  #include &lt;linux\/fs.h>  #include &lt;linux\/init.h>  #include &lt;linux\/irq.h>  #include &lt;linux\/kernel.h>   #include &lt;linux\/module.h>   #include &lt;linux\/poll.h>    #include \"chardev.h\"  #define SUCCESS 0  #define DEVICE_NAME \"char_dev\"  #define BUF_LEN 80    enum {      CDEV_NOT_USED = 0,      CDEV_EXCLUSIVE_OPEN = 1,  };    \/* \u041e\u0442\u043a\u0440\u044b\u0442\u043e \u043b\u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e? \u0421\u043b\u0443\u0436\u0438\u0442 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f   * \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0443.  *\/  static atomic_t already_open = ATOMIC_INIT(CDEV_NOT_USED);    \/* \u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438. *\/  static char message[BUF_LEN];    static struct class *cls;    \/* \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0444\u0430\u0439\u043b \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430. *\/  static int device_open(struct inode *inode, struct file *file)  {      pr_info(\"device_open(%p)\\n\", file);        try_module_get(THIS_MODULE);      return SUCCESS;  }    static int device_release(struct inode *inode, struct file *file)  {      pr_info(\"device_release(%p,%p)\\n\", inode, file);        module_put(THIS_MODULE);      return SUCCESS;  }    \/* \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u0443\u0436\u0435 \u043e\u0442\u043a\u0440\u044b\u0432\u0448\u0438\u0439 \u0444\u0430\u0439\u043b,   * \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0438\u0437 \u043d\u0435\u0433\u043e.   *\/  static ssize_t device_read(struct file *file, \/* \u0441\u043c. include\/linux\/fs.h   *\/                             char __user *buffer, \/* \u0411\u0443\u0444\u0435\u0440 \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.  *\/                             size_t length, \/* \u0414\u043b\u0438\u043d\u0430 \u0431\u0443\u0444\u0435\u0440\u0430.     *\/                             loff_t *offset)  {      \/* \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0430\u0439\u0442\u043e\u0432, \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u044b\u0445 \u0432 \u0431\u0443\u0444\u0435\u0440. *\/      int bytes_read = 0;      \/* \u041a\u0430\u043a \u0434\u0430\u043b\u0435\u043a\u043e \u0437\u0430\u0448\u0435\u043b \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0439        * \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435? \u041f\u0440\u0438\u0433\u043e\u0436\u0434\u0430\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0431\u0443\u0444\u0435\u0440\u0430      * \u0432 device_read.      *\/      const char *message_ptr = message;        if (!*(message_ptr + *offset)) { \/* \u041c\u044b \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. *\/          *offset = 0; \/* \u0421\u0431\u0440\u043e\u0441 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f. *\/          return 0; \/* \u041e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0446\u0430 \u0444\u0430\u0439\u043b\u0430. *\/      }        message_ptr += *offset;        \/* \u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0431\u0443\u0444\u0435\u0440. *\/      while (length &amp;&amp; *message_ptr) {          \/* \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0431\u0443\u0444\u0435\u0440 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0445,           * \u0430 \u043d\u0435 \u0432 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0435 \u044f\u0434\u0440\u0430, \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u0435 \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e           * \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c put_user, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437           * \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430 \u044f\u0434\u0440\u0430 \u0432 \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.           *\/          put_user(*(message_ptr++), buffer++);          length--;          bytes_read++;      }        pr_info(\"Read %d bytes, %ld left\\n\", bytes_read, length);        *offset += bytes_read;        \/* \u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0447\u0442\u0435\u043d\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0430\u0439\u0442\u043e\u0432, \u0440\u0435\u0430\u043b\u044c\u043d\u043e       * \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0445 \u0432 \u0431\u0443\u0444\u0435\u0440.       *\/      return bytes_read;  }    \/* \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043a\u0442\u043e-\u0442\u043e \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0444\u0430\u0439\u043b \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430. *\/  static ssize_t device_write(struct file *file, const char __user *buffer,                              size_t length, loff_t *offset)  {      int i;        pr_info(\"device_write(%p,%p,%ld)\", file, buffer, length);        for (i = 0; i &lt; length &amp;&amp; i &lt; BUF_LEN; i++)          get_user(message[i], buffer + i);        \/* \u0422\u0430\u043a\u0436\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432\u043e \u0432\u0432\u043e\u0434\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. *\/      return i;  }    \/* \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c ioctl \u0434\u043b\u044f   * \u0444\u0430\u0439\u043b\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430. \u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0432\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430   * (\u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0434\u043b\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 inode \u0438 file, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0432\u0441\u0435    * \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432): \u043d\u043e\u043c\u0435\u0440 ioctl \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0439 \u0434\u043b\u044f \u044d\u0442\u043e\u0439 ioctl.   *   * \u0415\u0441\u043b\u0438 ioctl \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c\/\u0447\u0442\u0435\u043d\u0438\u0435 (\u0442\u043e \u0435\u0441\u0442\u044c \u0435\u0435 \u0432\u044b\u0432\u043e\u0434   * \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u043c\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443), \u0432\u044b\u0437\u043e\u0432 ioctl \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u044b\u0432\u043e\u0434   * \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.  *\/  static long  device_ioctl(struct file *file, \/* \u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435. *\/               unsigned int ioctl_num, \/* \u0427\u0438\u0441\u043b\u043e \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0434\u043b\u044f ioctl *\/               unsigned long ioctl_param)  {      int i;      long ret = SUCCESS;        \/* \u041c\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u043c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0434\u0432\u0443\u043c\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e *\/      if (atomic_cmpxchg(&amp;already_open, CDEV_NOT_USED, CDEV_EXCLUSIVE_OPEN))          return -EBUSY;        \/* \u041f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u043d\u043d\u043e\u0439 ioctl. *\/      switch (ioctl_num) {      case IOCTL_SET_MSG: {          \/* \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 (\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c            * \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435) \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0435\u0433\u043e \u043a\u0430\u043a \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430.           * \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0433\u043e ioctl \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c.           *\/          char __user *tmp = (char __user *)ioctl_param;          char ch;            \/* \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u0438\u043d\u044b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. *\/          get_user(ch, tmp);          for (i = 0; ch &amp;&amp; i &lt; BUF_LEN; i++, tmp++)              get_user(ch, tmp);            device_write(file, (char __user *)ioctl_param, i, NULL);          break;      }      case IOCTL_GET_MSG: {          loff_t offset = 0;            \/* \u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u043c\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u044b\u0439           * \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c.           *\/          i = device_read(file, (char __user *)ioctl_param, 99, &amp;offset);            \/* \u041f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0432 \u043a\u043e\u043d\u0435\u0446 \u0431\u0443\u0444\u0435\u0440\u0430 \u043d\u0443\u043b\u044c, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0441\u044f.           *\/          put_user('\\0', (char __user *)ioctl_param + i);          break;      }      case IOCTL_GET_NTH_BYTE:          \/* \u042d\u0442\u0430 ioctl \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438 \u0432\u0432\u043e\u0434\u043e\u043c (ioctl_param), \u0438 \u0432\u044b\u0432\u043e\u0434\u043e\u043c           * (\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438).           *\/          ret = (long)message[ioctl_param];          break;      }        \/* \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u044b\u0437\u043e\u0432. *\/      atomic_set(&amp;already_open, CDEV_NOT_USED);        return ret;  }    \/* \u041e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u0435\u0439. *\/    \/* \u042d\u0442\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438    * \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u043c \u043d\u0430\u043c\u0438 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e\u043c. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c    * \u043d\u0430 \u044d\u0442\u0443 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432, \u043e\u043d \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c   * \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0434\u043b\u044f init_module. NULL \u0434\u043b\u044f \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439.   *\/  static struct file_operations fops = {      .read = device_read,      .write = device_write,      .unlocked_ioctl = device_ioctl,      .open = device_open,      .release = device_release, \/* \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044e. *\/  };    \/* \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f \u2013 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430. *\/  static int __init chardev2_init(void)  {      \/* \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 (\u043f\u043e \u043c\u0435\u043d\u044c\u0448\u0435\u0439 \u043c\u0435\u0440\u0435 \u043f\u043e\u043f\u044b\u0442\u043a\u0430). *\/      int ret_val = register_chrdev(MAJOR_NUM, DEVICE_NAME, &amp;fops);        \/* \u041e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442 \u043e\u0448\u0438\u0431\u043a\u0443. *\/      if (ret_val &lt; 0) {          pr_alert(\"%s failed with %d\\n\",                   \"Sorry, registering the character device \", ret_val);          return ret_val;      }        cls = class_create(THIS_MODULE, DEVICE_FILE_NAME);      device_create(cls, NULL, MKDEV(MAJOR_NUM, 0), NULL, DEVICE_FILE_NAME);        pr_info(\"Device created on \/dev\/%s\\n\", DEVICE_FILE_NAME);        return 0;  }    \/* \u041e\u0447\u0438\u0441\u0442\u043a\u0430 \u2013 \u0441\u043d\u044f\u0442\u0438\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0438\u0437 \/proc. *\/  static void __exit chardev2_exit(void)  {      device_destroy(cls, MKDEV(MAJOR_NUM, 0));      class_destroy(cls);        \/* \u0421\u043d\u044f\u0442\u0438\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430. *\/      unregister_chrdev(MAJOR_NUM, DEVICE_NAME);  }    module_init(chardev2_init);  module_exit(chardev2_exit);    MODULE_LICENSE(\"GPL\");<\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">chardev.h<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">\/*   * chardev.h \u2013 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\u043c\u0438 ioctl.   *   * \u041e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u044b \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0438\u0445 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u043d\u0430\u0442\u044c   * \u043a\u0430\u043a \u043c\u043e\u0434\u0443\u043b\u044c \u044f\u0434\u0440\u0430 (\u0438\u0437 chardev2.c), \u0442\u0430\u043a \u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 ioctl()  * (\u0438\u0437 userspace_ioctl.c).   *\/    #ifndef CHARDEV_H  #define CHARDEV_H    #include &lt;linux\/ioctl.h>    \/* \u0421\u0442\u0430\u0440\u0448\u0438\u0439 \u043d\u043e\u043c\u0435\u0440 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430. \u041c\u044b \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043d\u0430    * \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 ioctl \u0434\u043e\u043b\u0436\u043d\u044b \u0435\u0433\u043e \u0437\u043d\u0430\u0442\u044c.   *\/  #define MAJOR_NUM 100    \/* \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430. *\/  #define IOCTL_SET_MSG _IOW(MAJOR_NUM, 0, char *)  \/* _IOW \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u043c\u0435\u0440 \u043a\u043e\u043c\u0430\u043d\u0434\u044b ioctl \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438   * \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043c\u043e\u0434\u0443\u043b\u044e \u044f\u0434\u0440\u0430.   *   * \u041f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442, MAJOR_NUM, \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0441\u0442\u0430\u0440\u0448\u0438\u0439 \u043d\u043e\u043c\u0435\u0440 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430   *   * \u0412\u0442\u043e\u0440\u043e\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u2013 \u044d\u0442\u043e \u043d\u043e\u043c\u0435\u0440 \u043a\u043e\u043c\u0430\u043d\u0434\u044b (\u0438\u0445 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441   * \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043c\u044b\u0441\u043b\u0430\u043c\u0438).   *   * \u0422\u0440\u0435\u0442\u0438\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u2013 \u044d\u0442\u043e \u0442\u0438\u043f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043e\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u044f\u0434\u0440\u0443   *\/    \/* \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430. *\/  #define IOCTL_GET_MSG _IOR(MAJOR_NUM, 1, char *)  \/* \u042d\u0442\u0430 IOCTL \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0441 \u0446\u0435\u043b\u044c\u044e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435    * \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430\u043c \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043d\u0443\u0436\u0435\u043d \u0431\u0443\u0444\u0435\u0440 \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f   * \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0432\u043e\u0434\u0430 \u043f\u0440\u0438 \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c.   *\/    \/* \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 n-\u043d\u043e\u0433\u043e \u0431\u0430\u0439\u0442\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. *\/  #define IOCTL_GET_NTH_BYTE _IOWR(MAJOR_NUM, 2, int)  \/* \u042d\u0442\u0430 IOCTL \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430. \u041e\u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442  * \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0447\u0438\u0441\u043b\u043e, n, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 message[n].   *\/    \/* \u0418\u043c\u044f \u0444\u0430\u0439\u043b\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430. *\/  #define DEVICE_FILE_NAME \"char_dev\"  #define DEVICE_PATH \"\/dev\/char_dev\"    #endif<\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">userspace_ioctl.c<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">\/*  userspace_ioctl.c \u2013 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c \u044f\u0434\u0440\u0430    *  \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e ioctl.  *   *  \u0414\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430 \u0438 \u0432\u044b\u0432\u043e\u0434\u0430 cat.  *  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c ioctl, \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439    *  \u043f\u0440\u043e\u0446\u0435\u0441\u0441.  *\/    \/* \u0414\u0435\u0442\u0430\u043b\u0438 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u043d\u043e\u043c\u0435\u0440\u0430 ioctl \u0438 \u0441\u0442\u0430\u0440\u0448\u0438\u0439 \u0444\u0430\u0439\u043b \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430.  *\/  #include \"..\/chardev.h\"    #include &lt;stdio.h> \/* \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u0432\u043e\u0434-\u0432\u044b\u0432\u043e\u0434. *\/  #include &lt;fcntl.h> \/* \u041e\u0442\u043a\u0440\u044b\u0442\u0438\u0435. *\/  #include &lt;unistd.h> \/* \u0417\u0430\u043a\u0440\u044b\u0442\u0438\u0435. *\/  #include &lt;stdlib.h> \/* \u0412\u044b\u0445\u043e\u0434. *\/  #include &lt;sys\/ioctl.h> \/* ioctl *\/    \/* \u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u043e\u0432 ioctl. *\/    int ioctl_set_msg(int file_desc, char *message)  {      int ret_val;        ret_val = ioctl(file_desc, IOCTL_SET_MSG, message);        if (ret_val &lt; 0) {          printf(\"ioctl_set_msg failed:%d\\n\", ret_val);      }        return ret_val;  }    int ioctl_get_msg(int file_desc)  {      int ret_val;      char message[100] = { 0 };      \/* \u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u042d\u0442\u043e \u043e\u043f\u0430\u0441\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043d\u0435 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u043c \u044f\u0434\u0440\u0443, \u0434\u043e \u043a\u0443\u0434\u0430      * \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c, \u0442\u043e \u0435\u0441\u0442\u044c \u0440\u0438\u0441\u043a\u0443\u0435\u043c \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435       * \u0431\u0443\u0444\u0435\u0440\u0430. \u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043c\u044b \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0434\u0432\u0435 ioctl - \u043e\u0434\u043d\u0443       * \u0434\u043b\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u044f\u0434\u0440\u0430 \u043e \u0434\u043b\u0438\u043d\u0435 \u0431\u0443\u0444\u0435\u0440\u0430 \u0438 \u0432\u0442\u043e\u0440\u0443\u044e \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f    * \u0435\u043c\u0443 \u0441\u0430\u043c\u043e\u0433\u043e \u0431\u0443\u0444\u0435\u0440\u0430 \u043f\u043e\u0434 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435.      *\/      ret_val = ioctl(file_desc, IOCTL_GET_MSG, message);        if (ret_val &lt; 0) {          printf(\"ioctl_get_msg failed:%d\\n\", ret_val);      }      printf(\"get_msg message:%s\", message);        return ret_val;  }    int ioctl_get_nth_byte(int file_desc)  {      int i, c;        printf(\"get_nth_byte message:\");        i = 0;      do {          c = ioctl(file_desc, IOCTL_GET_NTH_BYTE, i++);            if (c &lt; 0) {              printf(\"\\nioctl_get_nth_byte failed at the %d'th byte:\\n\", i);              return c;          }            putchar(c);      } while (c != 0);        return 0;  }    \/* Main \u2013 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 ioctl. *\/  int main(void)  {      int file_desc, ret_val;      char *msg = \"Message passed by ioctl\\n\";        file_desc = open(DEVICE_PATH, O_RDWR);      if (file_desc &lt; 0) {          printf(\"Can't open device file: %s, error:%d\\n\", DEVICE_PATH,                 file_desc);          exit(EXIT_FAILURE);      }        ret_val = ioctl_set_msg(file_desc, msg);      if (ret_val)          goto error;      ret_val = ioctl_get_nth_byte(file_desc);      if (ret_val)          goto error;      ret_val = ioctl_get_msg(file_desc);      if (ret_val)          goto error;        close(file_desc);      return 0;  error:      close(file_desc);      exit(EXIT_FAILURE);  }<\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  <\/p>\n<h2><font color=\"#3AC1EF\">\u258d \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435<\/font><\/h2>\n<p>  \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u0440\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0435\u0442 \u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u0430\u0445.<\/p>\n<h2><font color=\"#3AC1EF\">\u258d \u0413\u043e\u0442\u043e\u0432\u044b\u0435 \u0447\u0430\u0441\u0442\u0438 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430:<\/font><\/h2>\n<p>  <\/p>\n<ul>\n<li> <a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/681880\/\">\u0427\u0430\u0441\u0442\u044c 1<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/683106\/\">\u0427\u0430\u0441\u0442\u044c 2<\/a><\/li>\n<li><b><font color=\"#3AC1EF\">\u0412\u044b \u0442\u0443\u0442 &#8212;> <\/font><\/b><a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/684382\/\">\u0427\u0430\u0441\u0442\u044c 3<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/685168\/\">\u0427\u0430\u0441\u0442\u044c 4<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/686596\/\">\u0427\u0430\u0441\u0442\u044c 5<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/688564\/\">\u0427\u0430\u0441\u0442\u044c 6<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/689346\/\">\u0427\u0430\u0441\u0442\u044c 7<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<blockquote><p><b><font color=\"#3AC1EF\"><a href=\"https:\/\/bit.ly\/3uL5ZOg\">\u041c\u043e\u0449\u043d\u044b\u0435 VPS \u043d\u0430 SSD<\/a> \u0441\u043e \u0441\u043a\u0438\u0434\u043a\u0430\u043c\u0438 \u0434\u043e 53%. \u041f\u0430\u043d\u0435\u043b\u044c ISPmanager \u0432 \u043f\u043e\u0434\u0430\u0440\u043e\u043a*<\/font><\/b>. <\/p><\/blockquote>\n<p><a href=\"http:\/\/ruvds.com\/ru-rub?utm_source=habr&amp;utm_medium=article&amp;utm_campaign=Bright_Translate&amp;utm_content=posobie_po_programmirovaniyu_modulej_yadra_linux_chast_3\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/sz\/7j\/pf\/sz7jpfj8i1pa6ocj-eia09dev4q.png\" data-src=\"https:\/\/habrastorage.org\/webt\/sz\/7j\/pf\/sz7jpfj8i1pa6ocj-eia09dev4q.png\"\/><\/a><\/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\/684382\/\"> https:\/\/habr.com\/ru\/articles\/684382\/<\/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-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/684382\/\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/-7\/yl\/hp\/-7ylhpzc6raohz-vopxottyejfu.png\" data-src=\"https:\/\/habrastorage.org\/webt\/-7\/yl\/hp\/-7ylhpzc6raohz-vopxottyejfu.png\"\/><\/div>\n<p><\/a><br \/>  <u>\u041e\u0442 \u0440\u0435\u0434\u0430\u043a\u0446\u0438\u0438<\/u>: \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u043b\u0441\u044f 31 \u0433\u043e\u0434 \u0441 \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0430\u043d\u043e\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f Linux. \u0418\u043c\u0435\u043d\u043d\u043e \u0432 \u044d\u0442\u043e\u0442 \u0434\u0435\u043d\u044c, 25 \u0430\u0432\u0433\u0443\u0441\u0442\u0430 1991 \u0433\u043e\u0434\u0430 \u041b\u0438\u043d\u0443\u0441 \u0422\u043e\u0440\u0432\u0430\u043b\u044c\u0434\u0441 \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u043b \u0432 \u043d\u043e\u0432\u043e\u0441\u0442\u044f\u0445 Usenet comp.os.minix \u0441\u043e\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0430:  <\/p>\n<blockquote><p><i>\u041f\u0440\u0438\u0432\u0435\u0442 \u0432\u0441\u0435\u043c \u0442\u0435\u043c, \u043a\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043c\u0438\u043d\u0438\u043a\u0441 \u2014 \u042f \u0434\u0435\u043b\u0430\u044e (\u0441\u0432\u043e\u0431\u043e\u0434\u043d\u0443\u044e) \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 (\u044d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0431\u0431\u0438, \u043d\u0435 \u0441\u0442\u043e\u043b\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0438 \u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435, \u043a\u0430\u043a GNU) \u0434\u043b\u044f 386(486)AT \u043a\u043b\u043e\u043d\u043e\u0432. \u042d\u0442\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043f\u0438\u0448\u0435\u0442\u0441\u044f \u0441 \u0430\u043f\u0440\u0435\u043b\u044f \u0438 \u0441\u043a\u043e\u0440\u043e \u0431\u0443\u0434\u0435\u0442 \u0433\u043e\u0442\u043e\u0432\u0430. \u042f \u0445\u043e\u0447\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u043e\u0442\u0437\u044b\u0432, \u043a\u0430\u0441\u0430\u044e\u0449\u0438\u0439\u0441\u044f \u0432\u0435\u0449\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0440\u0430\u0432\u044f\u0442\u0441\u044f\/\u043d\u0435 \u043d\u0440\u0430\u0432\u044f\u0442\u0441\u044f \u043b\u044e\u0434\u044f\u043c \u0432 \u043c\u0438\u043d\u0438\u043a\u0441, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u043e\u044f \u041e\u0421 \u043f\u043e\u0445\u043e\u0436\u0430 \u043d\u0430 \u043d\u0435\u0451 (\u0442\u0430\u043a\u043e\u0435 \u0436\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b (\u043f\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0441\u043e\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c), \u0441\u0440\u0435\u0434\u0438 \u043f\u0440\u043e\u0447\u0435\u0433\u043e).<\/p>\n<p>  \u0412 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u044f \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043b bash (1.08) \u0438 gcc (1.40), \u0438, \u043f\u043e\u0445\u043e\u0436\u0435, \u044d\u0442\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u044f \u043f\u043e\u043b\u0443\u0447\u0443 \u0447\u0442\u043e-\u0442\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u043d\u043e\u0435 \u0432 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0441\u044f\u0446\u0435\u0432, \u0438 \u044f \u0445\u043e\u0447\u0443 \u0443\u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0445\u043e\u0442\u044f\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043b\u044e\u0434\u0435\u0439. \u041b\u044e\u0431\u044b\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f, \u043d\u043e \u044f \u043d\u0435 \u043e\u0431\u0435\u0449\u0430\u044e, \u0447\u0442\u043e \u044f \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044e \u0438\u0445:-)<\/p>\n<p>  \u041b\u0438\u043d\u0443\u0441 (torvalds@kruuna.helsinki.fi)<\/p>\n<p>  PS. \u0414\u0430 \u2014 \u0432 \u043d\u0435\u0439 \u043d\u0435\u0442 \u043a\u043e\u0434\u0430 \u043c\u0438\u043d\u0438\u043a\u0441, \u0438 \u0431\u0443\u0434\u0435\u0442 \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u043e\u0442\u043e\u043a\u043e\u0432\u0430\u044f \u0424\u0421. \u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u041d\u0415\u041f\u0415\u0420\u0415\u041d\u041e\u0421\u0418\u041c\u0410 (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u044b Intel 386 \u0438 \u0442. \u0434.) \u0438, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0436\u0435\u0441\u0442\u043a\u0438\u0435 \u0434\u0438\u0441\u043a\u0438 AT, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u0441\u0451, \u0447\u0442\u043e \u0443 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c ?<\/i><\/p><\/blockquote>\n<p>\u041d\u0443 \u0430 \u043c\u044b \u2014 \u0432 \u044d\u0442\u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u0434\u0435\u043d\u044c, \u043c\u043e\u0436\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0436\u0435\u043b\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0442\u0440\u0443\u0434\u044b \u043f\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0443 \u044d\u0442\u043e\u0433\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u0431\u044b\u043b\u0438 \u0434\u043b\u044f \u0432\u0430\u0441 \u043f\u043e\u043b\u0435\u0437\u043d\u044b.<\/p>\n<p>  \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0441\u0435\u0440\u0438\u044e \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u044f\u0434\u0440\u0430. \u0412 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 <code>\/proc<\/code>, \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>sysfs<\/code>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432. <\/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-409814","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/409814","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=409814"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/409814\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=409814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=409814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=409814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}