{"id":49713,"date":"2023-05-24T13:32:38","date_gmt":"2023-05-24T05:32:38","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=49713"},"modified":"2023-05-24T13:32:38","modified_gmt":"2023-05-24T05:32:38","slug":"linux-device-driver","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-device-driver.html","title":{"rendered":"linux\u8bbe\u5907\u9a71\u52a8\u4e4b\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nLinux\u5b57\u7b26\u8bbe\u5907\u63d0\u4f9b\u8fde\u7eed\u7684\u6570\u636e\u6d41\uff0c\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u987a\u5e8f\u8bfb\u53d6\uff0c\u901a\u5e38\u4e0d\u652f\u6301\u968f\u673a\u5b58\u53d6\u3002\u76f8\u53cd\uff0c\u6b64\u7c7b\u8bbe\u5907\u652f\u6301\u6309\u5b57\u8282\/\u5b57\u7b26\u6765\u8bfb\u5199\u8bbe\u5907\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u952e\u76d8\uff0c\u4e32\u53e3\uff0c\u8c03\u5236\u89e3\u8c03\u5668\u90fd\u662f\u5178\u578b\u7684\u5b57\u7b26\u8bbe\u5907\u3002<\/b><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u4f17\u6240\u5468\u77e5\uff0c\u5b57\u7b26\u8bbe\u5907\u662fLinux\u4e0b\u6700\u57fa\u672c\uff0c\u4e5f\u662f\u6700\u5e38\u7528\u5230\u7684\u8bbe\u5907\uff0c\u5b83\u662f\u5b66\u4e60linux\u9a71\u52a8\u5165\u95e8\u6700\u597d\u7684\u9009\u62e9\u3002\u8ba1\u7b97\u673a\u7684\u5f88\u591a\u4e1c\u897f\u90fd\u662f\u76f8\u901a\u7684\uff0c\u638c\u63e1\u4e86\u5176\u4e2d\u4e00\u5757\uff0c\u5176\u5b83\u7684\u5c31\u89e6\u7c7b\u65c1\u901a\u4e86\u3002\u5728\u5199\u9a71\u52a8\u4e4b\u524d\uff0c\u5fc5\u987b\u5148\u641e\u6e05\u695a\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7684\u6846\u67b6\u5927\u6982\u662f\u600e\u6837\u7684\uff0c\u4e00\u5b9a\u8981\u5f04\u6e05\u695a\u6d41\u7a0b\uff0c\u624d\u5f00\u59cb\u52a8\u624b\uff0c\u4e0d\u8981\u4e00\u5f00\u59cb\u5c31\u52a8\u624b\u5199\u4ee3\u7801\u3002<\/p>\n

linux\u7cfb\u7edf\u8bbe\u5907\u5206\u7c7b<\/b><\/div>\n

linux\u7cfb\u7edf\u5c06\u8bbe\u5907\u5206\u4e3a3\u7c7b\uff1a\u5b57\u7b26\u8bbe\u5907\u3001\u5757\u8bbe\u5907\u3001\u7f51\u7edc\u8bbe\u5907\u3002<\/p>\n

<\/p>\n

    \n
  • \u5b57\u7b26\u8bbe\u5907\uff1a\u662f\u6307\u53ea\u80fd\u4e00\u4e2a\u5b57\u8282\u4e00\u4e2a\u5b57\u8282\u8bfb\u5199\u7684\u8bbe\u5907\uff0c\u4e0d\u80fd\u968f\u673a\u8bfb\u53d6\u8bbe\u5907\u5185\u5b58\u4e2d\u7684\u67d0\u4e00\u6570\u636e\uff0c\u8bfb\u53d6\u6570\u636e\u9700\u8981\u6309\u7167\u5148\u540e\u6570\u636e\u3002\u5b57\u7b26\u8bbe\u5907\u662f\u9762\u5411\u6d41\u7684\u8bbe\u5907\uff0c\u5e38\u89c1\u7684\u5b57\u7b26\u8bbe\u5907\u6709\u9f20\u6807\u3001\u952e\u76d8\u3001\u4e32\u53e3\u3001\u63a7\u5236\u53f0\u548cLED\u8bbe\u5907\u7b49\u3002<\/li>\n
  • \u5757\u8bbe\u5907\uff1a\u662f\u6307\u53ef\u4ee5\u4ece\u8bbe\u5907\u7684\u4efb\u610f\u4f4d\u7f6e\u8bfb\u53d6\u4e00\u5b9a\u957f\u5ea6\u6570\u636e\u7684\u8bbe\u5907\u3002\u5757\u8bbe\u5907\u5305\u62ec\u786c\u76d8\u3001\u78c1\u76d8\u3001U\u76d8\u548cSD\u5361\u7b49\u3002<\/li>\n<\/ul>\n

    \u6bcf\u4e00\u4e2a\u5b57\u7b26\u8bbe\u5907\u6216\u5757\u8bbe\u5907\u90fd\u5728\/dev\u76ee\u5f55\u4e0b\u5bf9\u5e94\u4e00\u4e2a\u8bbe\u5907\u6587\u4ef6\u3002linux\u7528\u6237\u7a0b\u5e8f\u901a\u8fc7\u8bbe\u5907\u6587\u4ef6\uff08\u6216\u79f0\u8bbe\u5907\u8282\u70b9\uff09\u6765\u4f7f\u7528\u9a71\u52a8\u7a0b\u5e8f\u64cd\u4f5c\u5b57\u7b26\u8bbe\u5907\u548c\u5757\u8bbe\u5907\u3002<\/p>\n

    \u5b57\u7b26\u8bbe\u5907\u3001\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u4e0e\u7528\u6237\u7a7a\u95f4\u8bbf\u95ee\u8be5\u8bbe\u5907\u7684\u7a0b\u5e8f\u4e09\u8005\u4e4b\u95f4\u7684\u5173\u7cfb<\/strong><\/div>\n

    <\/p>\n

    \u5982\u56fe\uff0c\u5728Linux\u5185\u6838\u4e2d\u4f7f\u7528cdev\u7ed3\u6784\u4f53\u6765\u63cf\u8ff0\u5b57\u7b26\u8bbe\u5907\uff0c\u901a\u8fc7\u5176\u6210\u5458dev_t\u6765\u5b9a\u4e49\u8bbe\u5907\u53f7\uff08\u5206\u4e3a\u4e3b\u3001\u6b21\u8bbe\u5907\u53f7\uff09\u4ee5\u786e\u5b9a\u5b57\u7b26\u8bbe\u5907\u7684\u552f\u4e00\u6027\u3002\u901a\u8fc7\u5176\u6210\u5458file_operations\u6765\u5b9a\u4e49\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u63d0\u4f9b\u7ed9VFS\u7684\u63a5\u53e3\u51fd\u6570\uff0c\u5982\u5e38\u89c1\u7684open()\u3001read()\u3001write()\u7b49\u3002<\/p>\n

    \u5728Linux\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u4e2d\uff0c\u6a21\u5757\u52a0\u8f7d\u51fd\u6570\u901a\u8fc7register_chrdev_region( ) \u6216alloc_chrdev_region( )\u6765\u9759\u6001\u6216\u8005\u52a8\u6001\u83b7\u53d6\u8bbe\u5907\u53f7\uff0c\u901a\u8fc7cdev_init( )\u5efa\u7acbcdev\u4e0efile_operations\u4e4b\u95f4\u7684\u8fde\u63a5\uff0c\u901a\u8fc7cdev_add( )\u5411\u7cfb\u7edf\u6dfb\u52a0\u4e00\u4e2acdev\u4ee5\u5b8c\u6210\u6ce8\u518c\u3002\u6a21\u5757\u5378\u8f7d\u51fd\u6570\u901a\u8fc7cdev_del( )\u6765\u6ce8\u9500cdev\uff0c\u901a\u8fc7unregister_chrdev_region( )\u6765\u91ca\u653e\u8bbe\u5907\u53f7\u3002<\/p>\n

    \u7528\u6237\u7a7a\u95f4\u8bbf\u95ee\u8be5\u8bbe\u5907\u7684\u7a0b\u5e8f\u901a\u8fc7Linux\u7cfb\u7edf\u8c03\u7528\uff0c\u5982open( )\u3001read( )\u3001write( )\uff0c\u6765\u201c\u8c03\u7528\u201dfile_operations\u6765\u5b9a\u4e49\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u63d0\u4f9b\u7ed9VFS\u7684\u63a5\u53e3\u51fd\u6570\u3002<\/p>\n

    \u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u6a21\u578b<\/strong><\/div>\n

    <\/p>\n

    1.\u9a71\u52a8\u521d\u59cb\u5316<\/strong><\/span><\/div>\n

    1.1. \u5206\u914dcdev<\/em><\/strong><\/p>\n

    \u57282.6\u7684\u5185\u6838\u4e2d\u4f7f\u7528cdev\u7ed3\u6784\u4f53\u6765\u63cf\u8ff0\u5b57\u7b26\u8bbe\u5907\uff0c\u5728\u9a71\u52a8\u4e2d\u5206\u914dcdev,\u4e3b\u8981\u662f\u5206\u914d\u4e00\u4e2acdev\u7ed3\u6784\u4f53\u4e0e\u7533\u8bf7\u8bbe\u5907\u53f7\uff0c\u4ee5\u6309\u952e\u9a71\u52a8\u4e3a\u4f8b\uff1a<\/p>\n

    \/*\u5206\u914dcdev*\/\r\nstruct cdev btn_cdev;\r\n\/*1.1 \u7533\u8bf7\u8bbe\u5907\u53f7*\/\r\nif(major){\r\n    \/\/\u9759\u6001\r\n    dev_id = MKDEV(major, 0);\r\n    register_chrdev_region(dev_id, 1, \"button\");\r\n    } \r\nelse {\r\n    \/\/\u52a8\u6001\r\n    alloc_chardev_region(&dev_id, 0, 1, \"button\");\r\n    major = MAJOR(dev_id);\r\n    }<\/pre>\n

    \u4ece\u4e0a\u9762\u7684\u4ee3\u7801\u53ef\u4ee5\u770b\u51fa\uff0c\u7533\u8bf7\u8bbe\u5907\u53f7\u6709\u52a8\u9759\u4e4b\u5206\uff0c\u5176\u5b9e\u8bbe\u5907\u53f7\u8fd8\u6709\u4e3b\u6b21\u4e4b\u5206\u3002\u5728Linux\u4e2d\u4ee5\u4e3b\u8bbe\u5907\u53f7\u7528\u6765\u6807\u8bc6\u4e0e\u8bbe\u5907\u6587\u4ef6\u76f8\u8fde\u7684\u9a71\u52a8\u7a0b\u5e8f\u3002\u6b21\u7f16\u53f7\u88ab\u9a71\u52a8\u7a0b\u5e8f\u7528\u6765\u8fa8\u522b\u64cd\u4f5c\u7684\u662f\u54ea\u4e2a\u8bbe\u5907\u3002cdev \u7ed3\u6784\u4f53\u7684 dev_t \u6210\u5458\u5b9a\u4e49\u4e86\u8bbe\u5907\u53f7\uff0c\u4e3a 32 \u4f4d\uff0c\u5176\u4e2d\u9ad8 12 \u4f4d\u4e3a\u4e3b\u8bbe\u5907\u53f7\uff0c\u4f4e20 \u4f4d\u4e3a\u6b21\u8bbe\u5907\u53f7\u3002<\/p>\n

    \u8bbe\u5907\u53f7\u7684\u83b7\u5f97\u4e0e\u751f\u6210\uff1a<\/p>\n

    \u83b7\u5f97\uff1a<\/p>\n

    \u4e3b\u8bbe\u5907\u53f7\uff1aMAJOR(dev_t dev);\r\n\u6b21\u8bbe\u5907\u53f7\uff1aMINOR(dev_t dev);<\/pre>\n

    \u751f\u6210\uff1aMKDEV(int major,int minor);<\/p>\n

    \u8bbe\u5907\u53f7\u7533\u8bf7\u7684\u52a8\u9759\u4e4b\u5206\uff1a<\/p>\n

    \u9759\u6001\uff1a<\/p>\n

    int register_chrdev_region(dev_t from, unsigned count, const char *name)\uff1b\r\n\/*\u529f\u80fd\uff1a\u7533\u8bf7\u4f7f\u7528\u4ecefrom\u5f00\u59cb\u7684count \u4e2a\u8bbe\u5907\u53f7(\u4e3b\u8bbe\u5907\u53f7\u4e0d\u53d8\uff0c\u6b21\u8bbe\u5907\u53f7\u589e\u52a0\uff09*\/<\/pre>\n

    \u9759\u6001\u7533\u8bf7\u76f8\u5bf9\u8f83\u7b80\u5355\uff0c\u4f46\u662f\u4e00\u65e6\u9a71\u52a8\u88ab\u5e7f\u6cdb\u4f7f\u7528,\u8fd9\u4e2a\u968f\u673a\u9009\u5b9a\u7684\u4e3b\u8bbe\u5907\u53f7\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8bbe\u5907\u53f7\u51b2\u7a81\uff0c\u800c\u4f7f\u9a71\u52a8\u7a0b\u5e8f\u65e0\u6cd5\u6ce8\u518c\u3002<\/p>\n

    \u52a8\u6001\uff1a<\/p>\n

    int alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count,const char *name)\uff1b\r\n\/*\u529f\u80fd\uff1a\u8bf7\u6c42\u5185\u6838\u52a8\u6001\u5206\u914dcount\u4e2a\u8bbe\u5907\u53f7\uff0c\u4e14\u6b21\u8bbe\u5907\u53f7\u4ecebaseminor\u5f00\u59cb\u3002*\/<\/pre>\n

    \u52a8\u6001\u7533\u8bf7\u7b80\u5355\uff0c\u6613\u4e8e\u9a71\u52a8\u63a8\u5e7f\uff0c\u4f46\u662f\u65e0\u6cd5\u5728\u5b89\u88c5\u9a71\u52a8\u524d\u521b\u5efa\u8bbe\u5907\u6587\u4ef6(\u56e0\u4e3a\u5b89\u88c5\u524d\u8fd8\u6ca1\u6709\u5206\u914d\u5230\u4e3b\u8bbe\u5907\u53f7)\u3002<\/p>\n

    1.2\u521d\u59cb\u5316cdev<\/em><\/strong><\/p>\n

    void cdev_init(struct cdev *, struct file_operations *);\r\ncdev_init()\u51fd\u6570\u7528\u4e8e\u521d\u59cb\u5316 cdev \u7684\u6210\u5458\uff0c\u5e76\u5efa\u7acb cdev \u548c file_operations \u4e4b\u95f4\u7684\u8fde\u63a5\u3002<\/pre>\n

    1.3\u6ce8\u518ccdev<\/strong><\/em><\/p>\n

    int cdev_add(struct cdev *, dev_t, unsigned);\r\ncdev_add()\u51fd\u6570\u5411\u7cfb\u7edf\u6dfb\u52a0\u4e00\u4e2a cdev\uff0c\u5b8c\u6210\u5b57\u7b26\u8bbe\u5907\u7684\u6ce8\u518c\u3002<\/pre>\n

    1.4\u786c\u4ef6\u521d\u59cb\u5316<\/strong><\/em><\/p>\n

    \u786c\u4ef6\u521d\u59cb\u5316\u4e3b\u8981\u662f\u786c\u4ef6\u8d44\u6e90\u7684\u7533\u8bf7\u4e0e\u914d\u7f6e\uff0c\u4ee5TQ210\u7684\u6309\u952e\u9a71\u52a8\u4e3a\u4f8b\uff1a<\/p>\n

    \/* 1.4 \u786c\u4ef6\u521d\u59cb\u5316*\/\r\n\/\/\u7533\u8bf7GPIO\u8d44\u6e90\r\ngpio_request(S5PV210_GPH0(0), \"GPH0_0\");\r\n\/\/\u914d\u7f6e\u8f93\u5165\r\ngpio_direction_input(S5PV210_GPH0(0));<\/pre>\n

    \u00a0<\/strong>2.\u5b9e\u73b0\u8bbe\u5907\u64cd\u4f5c<\/strong><\/span><\/p>\n

    \u7528\u6237\u7a7a\u95f4\u7684\u7a0b\u5e8f\u4ee5\u8bbf\u95ee\u6587\u4ef6\u7684\u5f62\u5f0f\u8bbf\u95ee\u5b57\u7b26\u8bbe\u5907\uff0c\u901a\u5e38\u8fdb\u884copen\u3001read\u3001write\u3001close\u7b49\u7cfb\u7edf\u8c03\u7528\u3002\u800c\u8fd9\u4e9b\u7cfb\u7edf\u8c03\u7528\u7684\u6700\u7ec8\u843d\u5b9e\u5219\u662ffile_operations\u7ed3\u6784\u4f53\u4e2d\u6210\u5458\u51fd\u6570\uff0c\u5b83\u4eec\u662f\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u4e0e\u5185\u6838\u7684\u63a5\u53e3\u3002\u4ee5TQ210\u7684\u6309\u952e\u9a71\u52a8\u4e3a\u4f8b\uff1a<\/p>\n

    \/*\u8bbe\u5907\u64cd\u4f5c\u96c6\u5408*\/\r\nstatic struct file_operations btn_fops = {\r\n    .owner = THIS_MODULE,\r\n    .open = button_open,\r\n    .release = button_close,\r\n    .read = button_read\r\n};<\/pre>\n

    \u4e0a\u9762\u4ee3\u7801\u4e2d\u7684button_open\u3001button_close\u3001button_read\u662f\u8981\u5728\u9a71\u52a8\u4e2d\u81ea\u5df1\u5b9e\u73b0\u7684\u3002file_operations\u7ed3\u6784\u4f53\u6210\u5458\u51fd\u6570\u6709\u5f88\u591a\u4e2a\uff0c\u4e0b\u9762\u5c31\u9009\u51e0\u4e2a\u5e38\u89c1\u7684\u6765\u5c55\u793a\uff1a<\/p>\n

    2.1 open()\u51fd\u6570<\/strong><\/em><\/p>\n

    \u539f\u578b\uff1a<\/p>\n

    int(*open)(struct inode *, struct file*);\r\n\/*\u6253\u5f00*\/<\/pre>\n

    2.2 read()\u51fd\u6570<\/strong><\/em><\/p>\n

    \u539f\u578b\uff1a<\/p>\n

    ssize_t(*read)(struct file *, char __user*, size_t, loff_t*);\r\n\/*\u7528\u6765\u4ece\u8bbe\u5907\u4e2d\u8bfb\u53d6\u6570\u636e\uff0c\u6210\u529f\u65f6\u51fd\u6570\u8fd4\u56de\u8bfb\u53d6\u7684\u5b57\u8282\u6570\uff0c\u51fa\u9519\u65f6\u8fd4\u56de\u4e00\u4e2a\u8d1f\u503c*\/<\/pre>\n

    2.3 write()\u51fd\u6570<\/strong><\/em><\/p>\n

    \u539f\u578b\uff1a<\/p>\n

    ssize_t(*write)(struct file *, const char__user *, size_t, loff_t*);\r\n\/*\u5411\u8bbe\u5907\u53d1\u9001\u6570\u636e\uff0c\u6210\u529f\u65f6\u8be5\u51fd\u6570\u8fd4\u56de\u5199\u5165\u7684\u5b57\u8282\u6570\u3002\u5982\u679c\u6b64\u51fd\u6570\u672a\u88ab\u5b9e\u73b0\uff0c\r\n\u5f53\u7528\u6237\u8fdb\u884cwrite()\u7cfb\u7edf\u8c03\u7528\u65f6\uff0c\u5c06\u5f97\u5230-EINVAL\u8fd4\u56de\u503c*\/<\/pre>\n

    2.4 close()\u51fd\u6570<\/strong><\/em><\/p>\n

    \u539f\u578b\uff1a<\/p>\n

    int(*release)(struct inode *, struct file*);\r\n\/*\u5173\u95ed*\/<\/pre>\n

    2.5\u8865\u5145\u8bf4\u660e<\/strong><\/em><\/p>\n

    1. \u5728Linux\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f\u8bbe\u8ba1\u4e2d\uff0c\u67093\u79cd\u975e\u5e38\u91cd\u8981\u7684\u6570\u636e\u7ed3\u6784\uff1astruct file\u3001struct inode\u3001struct file_operations\u3002struct file \u4ee3\u8868\u4e00\u4e2a\u6253\u5f00\u7684\u6587\u4ef6\u3002\u7cfb\u7edf\u4e2d\u6bcf\u4e2a\u6253\u5f00\u7684\u6587\u4ef6\u5728\u5185\u6838\u7a7a\u95f4\u90fd\u6709\u4e00\u4e2a\u5173\u8054\u7684struct file\u3002\u5b83\u7531\u5185\u6838\u5728\u6253\u5f00\u6587\u4ef6\u65f6\u521b\u5efa, \u5728\u6587\u4ef6\u5173\u95ed\u540e\u91ca\u653e\u3002\u5176\u6210\u5458loff_t f_pos \u8868\u793a\u6587\u4ef6\u8bfb\u5199\u4f4d\u7f6e\u3002struct inode \u7528\u6765\u8bb0\u5f55\u6587\u4ef6\u7684\u7269\u7406\u4e0a\u7684\u4fe1\u606f\u3002\u56e0\u6b64,\u5b83\u548c\u4ee3\u8868\u6253\u5f00\u6587\u4ef6\u7684file\u7ed3\u6784\u662f\u4e0d\u540c\u7684\u3002\u4e00\u4e2a\u6587\u4ef6\u53ef\u4ee5\u5bf9\u5e94\u591a\u4e2afile\u7ed3\u6784,\u4f46\u53ea\u6709\u4e00\u4e2ainode\u7ed3\u6784\u3002\u5176\u6210\u5458dev_t i_rdev\u8868\u793a\u8bbe\u5907\u53f7\u3002struct file_operations \u4e00\u4e2a\u51fd\u6570\u6307\u9488\u7684\u96c6\u5408\uff0c\u5b9a\u4e49\u80fd\u5728\u8bbe\u5907\u4e0a\u8fdb\u884c\u7684\u64cd\u4f5c\u3002\u7ed3\u6784\u4e2d\u7684\u6210\u5458\u6307\u5411\u9a71\u52a8\u4e2d\u7684\u51fd\u6570,\u8fd9\u4e9b\u51fd\u6570\u5b9e\u73b0\u4e00\u4e2a\u7279\u522b\u7684\u64cd\u4f5c, \u5bf9\u4e8e\u4e0d\u652f\u6301\u7684\u64cd\u4f5c\u4fdd\u7559\u4e3aNULL\u3002<\/p>\n

    2. \u5728read( )\u548cwrite( )\u4e2d\u7684buff \u53c2\u6570\u662f\u7528\u6237\u7a7a\u95f4\u6307\u9488\u3002\u56e0\u6b64,\u5b83\u4e0d\u80fd\u88ab\u5185\u6838\u4ee3\u7801\u76f4\u63a5\u5f15\u7528\uff0c\u56e0\u4e3a\u7528\u6237\u7a7a\u95f4\u6307\u9488\u5728\u5185\u6838\u7a7a\u95f4\u65f6\u53ef\u80fd\u6839\u672c\u662f\u65e0\u6548\u7684\u2014\u2014\u6ca1\u6709\u90a3\u4e2a\u5730\u5740\u7684\u6620\u5c04\u3002\u56e0\u6b64\uff0c\u5185\u6838\u63d0\u4f9b\u4e86\u4e13\u95e8\u7684\u51fd\u6570\u7528\u4e8e\u8bbf\u95ee\u7528\u6237\u7a7a\u95f4\u7684\u6307\u9488\uff1a<\/p>\n

    unsigned long copy_from_user(void *to, const void __user *from, unsigned long count);\r\nunsigned long copy_to_user(void __user *to, const void *from, unsigned long count);<\/pre>\n
    3.\u9a71\u52a8\u6ce8\u9500<\/strong><\/span><\/div>\n

    3.1 \u5220\u9664cdev<\/strong><\/em><\/p>\n

    \u5728\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u6a21\u5757\u5378\u8f7d\u51fd\u6570\u4e2d\u901a\u8fc7cdev_del()\u51fd\u6570\u5411\u7cfb\u7edf\u5220\u9664\u4e00\u4e2acdev\uff0c\u5b8c\u6210\u5b57\u7b26\u8bbe\u5907\u7684\u6ce8\u9500\u3002<\/p>\n

    \/*\u539f\u578b\uff1a*\/\r\nvoid cdev_del(struct cdev *);\r\n\/*\u4f8b\uff1a*\/\r\ncdev_del(&btn_cdev);<\/pre>\n

    3.2 \u91ca\u653e\u8bbe\u5907\u53f7
    \n\u5728\u8c03\u7528cdev_del()\u51fd\u6570\u4ece\u7cfb\u7edf\u6ce8\u9500\u5b57\u7b26\u8bbe\u5907\u4e4b\u540e\uff0cunregister_chrdev_region()\u5e94\u8be5\u88ab\u8c03\u7528\u4ee5\u91ca\u653e\u539f\u5148\u7533\u8bf7\u7684\u8bbe\u5907\u53f7\u3002<\/p>\n

    \/*\u539f\u578b\uff1a*\/\r\nvoid unregister_chrdev_region(dev_t from, unsigned count);\r\n\/*\u4f8b\uff1a*\/\r\nunregister_chrdev_region(MKDEV(major, 0), 1);<\/pre>\n

    4.\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f\u57fa\u7840<\/strong><\/span><\/p>\n

    4.1 \u7ed3\u6784\u4f53<\/strong><\/em><\/p>\n

    \u5728Linux2.6 \u5185\u6838\u4e2d\uff0c\u4f7f\u7528cdev\u7ed3\u6784\u4f53\u6765\u63cf\u8ff0\u4e00\u4e2a\u5b57\u7b26\u8bbe\u5907\uff0ccdev\u7ed3\u6784\u4f53\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n

    struct cdev {\r\n    struct kobject kobj;\r\n    struct module *owner; \/*\u901a\u5e38\u4e3aTHIS_MODULE*\/\r\n    struct file_operations *ops; \/*\u5728cdev_init()\u8fd9\u4e2a\u51fd\u6570\u91cc\u9762\u4e0ecdev\u7ed3\u6784\u8054\u7cfb\u8d77\u6765*\/\r\n    struct list_head list;\r\n    dev_t dev; \/*\u8bbe\u5907\u53f7*\/\r\n    unsigned int count;\r\n}\uff1b<\/pre>\n

    MAJOR(dev_t dev)cdev \u7ed3\u6784\u4f53\u7684dev_t \u6210\u5458\u5b9a\u4e49\u4e86\u8bbe\u5907\u53f7\uff0c\u4e3a32\u4f4d\uff0c\u5176\u4e2d12\u4f4d\u662f\u4e3b\u8bbe\u5907\u53f7\uff0c20\u4f4d\u662f\u6b21\u8bbe\u5907\u53f7\uff0c\u6211\u4eec\u53ea\u9700\u4f7f\u7528\u4e8c\u4e2a\u7b80\u5355\u7684\u5b8f\u5c31\u53ef\u4ee5\u4ecedev_t \u4e2d\u83b7\u53d6\u4e3b\u8bbe\u5907\u53f7\u548c\u6b21\u8bbe\u5907\u53f7\uff1a<\/p>\n

    MINOR(dev_t dev)<\/pre>\n

    \u76f8\u53cd\u5730\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e3b\u6b21\u8bbe\u5907\u53f7\u6765\u751f\u6210dev_t\uff1a<\/p>\n

    MKDEV(int major,int minor)<\/pre>\n

    4.2 Linux2.6\u5185\u6838\u63d0\u4f9b\u4e00\u7ec4\u51fd\u6570\u7528\u4e8e\u64cd\u4f5ccdev\u7ed3\u6784\u4f53<\/strong><\/em><\/p>\n

    (1)void cdev_init(struct cdev*,struct file_operations *);\r\n(2)struct cdev *cdev_alloc(void);\r\n(3)int cdev_add(struct cdev *,dev_t,unsigned);\r\n(4)void cdev_del(struct cdev *);<\/pre>\n

    \u5176\u4e2d\uff081\uff09\u7528\u4e8e\u521d\u59cb\u5316cdev\u7ed3\u6784\u4f53\uff0c\u5e76\u5efa\u7acbcdev\u4e0efile_operations \u4e4b\u95f4\u7684\u8fde\u63a5\u3002\uff082\uff09\u7528\u4e8e\u52a8\u6001\u5206\u914d\u4e00\u4e2acdev\u7ed3\u6784\uff0c\uff083\uff09\u5411\u5185\u6838\u6ce8\u518c\u4e00\u4e2acdev\u7ed3\u6784\uff0c\uff084\uff09\u5411\u5185\u6838\u6ce8\u9500\u4e00\u4e2acdev\u7ed3\u6784\u3002<\/p>\n

    4.3 Linux2.6\u5185\u6838\u5206\u914d\u548c\u91ca\u653e\u8bbe\u5907\u53f7<\/strong><\/em><\/p>\n

    \u5728\u8c03\u7528cdev_add()\u51fd\u6570\u5411\u7cfb\u7edf\u6ce8\u518c\u5b57\u7b26\u8bbe\u5907\u4e4b\u524d\uff0c\u9996\u5148\u5e94\u5411\u7cfb\u7edf\u7533\u8bf7\u8bbe\u5907\u53f7\uff0c\u6709\u4e8c\u79cd\u65b9\u6cd5\u7533\u8bf7\u8bbe\u5907\u53f7\uff0c\u4e00\u79cd\u662f\u9759\u6001\u7533\u8bf7\u8bbe\u5907\u53f7\uff1a<\/p>\n

    int register_chrdev_region(dev_t from,unsigned count,const char *name)<\/pre>\n

    \u53e6\u4e00\u79cd\u662f\u52a8\u6001\u7533\u8bf7\u8bbe\u5907\u53f7\uff1a<\/p>\n

    int alloc_chrdev_region(dev_t *dev,unsigned baseminor,unsigned count,const char *name);<\/pre>\n

    \u5176\u4e2d\uff0c\u9759\u6001\u7533\u8bf7\u662f\u5df2\u77e5\u8d77\u59cb\u8bbe\u5907\u53f7\u7684\u60c5\u51b5\uff0c\u5982\u5148\u4f7f\u7528cat \/proc\/devices \u547d\u4ee4\u67e5\u5f97\u54ea\u4e2a\u8bbe\u5907\u53f7\u672a\u4e8b\u5148\u4f7f\u7528\uff08\u4e0d\u63a8\u8350\u4f7f\u7528\u9759\u6001\u7533\u8bf7\uff09\uff1b\u52a8\u6001\u7533\u8bf7\u662f\u7531\u7cfb\u7edf\u81ea\u52a8\u5206\u914d\uff0c\u53ea\u9700\u8bbe\u7f6emajor = 0\u5373\u53ef\u3002<\/p>\n

    \u76f8\u53cd\u5730\uff0c\u5728\u8c03\u7528cdev_del()\u51fd\u6570\u4ece\u7cfb\u7edf\u4e2d\u6ce8\u9500\u5b57\u7b26\u8bbe\u5907\u4e4b\u540e\uff0c\u5e94\u8be5\u5411\u7cfb\u7edf\u7533\u8bf7\u91ca\u653e\u539f\u5148\u7533\u8bf7\u7684\u8bbe\u5907\u53f7\uff0c\u4f7f\u7528\uff1a<\/p>\n

    void unregister_chrdev_region(dev_t from,unsigned count);<\/pre>\n

    4.4 cdev\u7ed3\u6784\u7684file_operations\u7ed3\u6784\u4f53<\/strong><\/em><\/p>\n

    \u8fd9\u4e2a\u7ed3\u6784\u4f53\u662f\u5b57\u7b26\u8bbe\u5907\u5f53\u4e2d\u6700\u91cd\u8981\u7684\u7ed3\u6784\u4f53\u4e4b\u4e00\uff0cfile_operations \u7ed3\u6784\u4f53\u4e2d\u7684\u6210\u5458\u51fd\u6570\u6307\u9488\u662f\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f\u8bbe\u8ba1\u7684\u4e3b\u4f53\u5185\u5bb9\uff0c\u8fd9\u4e9b\u51fd\u6570\u5b9e\u9645\u4e0a\u5728\u5e94\u7528\u7a0b\u5e8f\u8fdb\u884cLinux \u7684 open()\u3001read()\u3001write()\u3001close()\u3001seek()\u3001ioctl()\u7b49\u7cfb\u7edf\u8c03\u7528\u65f6\u6700\u7ec8\u88ab\u8c03\u7528\u3002<\/p>\n

    struct file_operations {\r\n    \/*\u62e5\u6709\u8be5\u7ed3\u6784\u7684\u6a21\u5757\u8ba1\u6570\uff0c\u4e00\u822c\u4e3aTHIS_MODULE*\/\r\n    struct module *owner;\r\n    \/*\u7528\u4e8e\u4fee\u6539\u6587\u4ef6\u5f53\u524d\u7684\u8bfb\u5199\u4f4d\u7f6e*\/\r\n    loff_t (*llseek) (struct file *, loff_t, int);\r\n    \/*\u4ece\u8bbe\u5907\u4e2d\u540c\u6b65\u8bfb\u53d6\u6570\u636e*\/\r\n    ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);\r\n\r\n    \/*\u5411\u8bbe\u5907\u4e2d\u5199\u6570\u636e*\/\r\n    ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);\r\n\r\n    ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);\r\n    ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);\r\n    int (*readdir) (struct file *, void *, filldir_t);\r\n   \r\n    \/*\u8f6e\u8be2\u51fd\u6570\uff0c\u5224\u65ad\u76ee\u524d\u662f\u5426\u53ef\u4ee5\u8fdb\u884c\u975e\u963b\u585e\u7684\u8bfb\u53d6\u6216\u5199\u5165*\/\r\n    unsigned int (*poll) (struct file *, struct poll_table_struct *);\r\n\r\n    \/*\u6267\u884c\u8bbe\u5907\u7684I\/O\u547d\u4ee4*\/\r\n    int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);\r\n\r\n    long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);\r\n    long (*compat_ioctl) (struct file *, unsigned int, unsigned long);\r\n\r\n    \/*\u7528\u4e8e\u8bf7\u6c42\u5c06\u8bbe\u5907\u5185\u5b58\u6620\u5c04\u5230\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4*\/\r\n    int (*mmap) (struct file *, struct vm_area_struct *);\r\n \r\n    \/*\u6253\u5f00\u8bbe\u5907\u6587\u4ef6*\/\r\n    int (*open) (struct inode *, struct file *);\r\n    int (*flush) (struct file *, fl_owner_t id);\r\n  \r\n    \/*\u5173\u95ed\u8bbe\u5907\u6587\u4ef6*\/\r\n    int (*release) (struct inode *, struct file *);\r\n\r\n    int (*fsync) (struct file *, struct dentry *, int datasync);\r\n    int (*aio_fsync) (struct kiocb *, int datasync);\r\n    int (*fasync) (int, struct file *, int);\r\n    int (*lock) (struct file *, int, struct file_lock *);\r\n    ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);\r\n    unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);\r\n    int (*check_flags)(int);\r\n    int (*flock) (struct file *, int, struct file_lock *);\r\n    ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);\r\n    ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);\r\n    int (*setlease)(struct file *, long, struct file_lock **);<\/pre>\n

    4.5 file\u7ed3\u6784<\/strong><\/em><\/p>\n

    file \u7ed3\u6784\u4ee3\u8868\u4e00\u4e2a\u6253\u5f00\u7684\u6587\u4ef6\uff0c\u5b83\u7684\u7279\u70b9\u662f\u4e00\u4e2a\u6587\u4ef6\u53ef\u4ee5\u5bf9\u5e94\u591a\u4e2afile\u7ed3\u6784\u3002\u5b83\u7531\u5185\u6838\u518dopen\u65f6\u521b\u5efa\uff0c\u5e76\u4f20\u9012\u7ed9\u5728\u8be5\u6587\u4ef6\u4e0a\u64cd\u4f5c\u7684\u6240\u6709\u51fd\u6570\uff0c\u76f4\u5230\u6700\u540eclose\u51fd\u6570\uff0c\u5728\u6587\u4ef6\u7684\u6240\u6709\u5b9e\u4f8b\u90fd\u88ab\u5173\u95ed\u4e4b\u540e\uff0c\u5185\u6838\u624d\u91ca\u653e\u8fd9\u4e2a\u6570\u636e\u7ed3\u6784\u3002<\/p>\n

    \u5728\u5185\u6838\u6e90\u4ee3\u7801\u4e2d\uff0c\u6307\u5411 struct file \u7684\u6307\u9488\u901a\u5e38\u6bd4\u79f0\u4e3afilp\uff0cfile\u7ed3\u6784\u6709\u4ee5\u4e0b\u51e0\u4e2a\u91cd\u8981\u7684\u6210\u5458\uff1a
    \n\u5185\u6838\u7528inode \u7ed3\u6784\u5728\u5185\u90e8\u8868\u793a\u6587\u4ef6\uff0c\u5b83\u662f\u5b9e\u5b9e\u5728\u5728\u7684\u8868\u793a\u7269\u7406\u786c\u4ef6\u4e0a\u7684\u67d0\u4e00\u4e2a\u6587\u4ef6\uff0c\u4e14\u4e00\u4e2a\u6587\u4ef6\u4ec5\u6709\u4e00\u4e2ainode\u4e0e\u4e4b\u5bf9\u5e94\uff0c\u540c\u6837\u5b83\u6709\u4e8c\u4e2a\u6bd4\u8f83\u91cd\u8981\u7684\u6210\u5458\uff1a<\/p>\n

    struct file{\r\n    mode_t fmode; \/*\u6587\u4ef6\u6a21\u5f0f\uff0c\u5982FMODE_READ\uff0cFMODE_WRITE*\/\r\n    ...\r\n    loff_t f_pos; \/*loff_t \u662f\u4e00\u4e2a64\u4f4d\u7684\u6570\uff0c\u9700\u8981\u65f6\uff0c\u987b\u5f3a\u5236\u8f6c\u6362\u4e3a32\u4f4d*\/\r\n    unsigned int f_flags; \/*\u6587\u4ef6\u6807\u5fd7\uff0c\u5982\uff1aO_NONBLOCK*\/\r\n    struct file_operations *f_op;\r\n    void *private_data; \/*\u975e\u5e38\u91cd\u8981\uff0c\u7528\u4e8e\u5b58\u653e\u8f6c\u6362\u540e\u7684\u8bbe\u5907\u63cf\u8ff0\u7ed3\u6784\u6307\u9488*\/\r\n    ...\r\n};<\/pre>\n

    4.6 inode\u7ed3\u6784<\/strong><\/em><\/p>\n

    struct inode{\r\n    dev_t i_rdev; \/*\u8bbe\u5907\u7f16\u53f7*\/\r\n    struct cdev *i_cdev; \/*cdev \u662f\u8868\u793a\u5b57\u7b26\u8bbe\u5907\u7684\u5185\u6838\u7684\u5185\u90e8\u7ed3\u6784*\/\r\n};<\/pre>\n

    \u53ef\u4ee5\u4eceinode\u4e2d\u83b7\u53d6\u4e3b\u6b21\u8bbe\u5907\u53f7\uff0c\u4f7f\u7528\u4e0b\u9762\u4e8c\u4e2a\u5b8f\uff1a<\/p>\n

    \/*\u9a71\u52a8\u5de5\u7a0b\u5e08\u4e00\u822c\u4e0d\u5173\u5fc3\u8fd9\u4e8c\u4e2a\u5b8f*\/\r\nunsigned int imajor(struct inode *inode);\r\nunsigned int iminor(struct inode *inode);<\/pre>\n

    4.7 \u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u6a21\u5757\u52a0\u8f7d\u4e0e\u5378\u8f7d\u51fd\u6570<\/strong><\/em><\/p>\n

    \u5728\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u6a21\u5757\u52a0\u8f7d\u51fd\u6570\u4e2d\u5e94\u8be5\u5b9e\u73b0\u8bbe\u5907\u53f7\u7684\u7533\u8bf7\u548ccdev \u7ed3\u6784\u7684\u6ce8\u518c\uff0c\u800c\u5728\u5378\u8f7d\u51fd\u6570\u4e2d\u5e94\u8be5\u5b9e\u73b0\u8bbe\u5907\u53f7\u7684\u91ca\u653e\u4e0ecdev\u7ed3\u6784\u7684\u6ce8\u9500\u3002<\/p>\n

    \u6211\u4eec\u4e00\u822c\u4e60\u60ef\u5c06cdev\u5185\u5d4c\u5230\u53e6\u5916\u4e00\u4e2a\u8bbe\u5907\u76f8\u5173\u7684\u7ed3\u6784\u4f53\u91cc\u9762\uff0c\u8be5\u8bbe\u5907\u5305\u542b\u6240\u6d89\u53ca\u7684cdev\u3001\u79c1\u6709\u6570\u636e\u53ca\u4fe1\u53f7\u91cf\u7b49\u7b49\u4fe1\u606f\u3002\u5e38\u89c1\u7684\u8bbe\u5907\u7ed3\u6784\u4f53\u3001\u6a21\u5757\u52a0\u8f7d\u51fd\u6570\u3001\u6a21\u5757\u5378\u8f7d\u51fd\u6570\u5f62\u5f0f\u5982\u4e0b\uff1a<\/p>\n

    \/*\u8bbe\u5907\u7ed3\u6784\u4f53*\/\r\nstruct xxx_dev{\r\n    struct cdev cdev;\r\n    char *data;\r\n    struct semaphore sem;\r\n    ...\r\n};<\/pre>\n
    \/*\u6a21\u5757\u52a0\u8f7d\u51fd\u6570*\/\r\nstatic int __init xxx_init(void)\r\n{\r\n    ...\r\n    \/\/\u521d\u59cb\u5316cdev\u7ed3\u6784;\r\n    \/\/\u7533\u8bf7\u8bbe\u5907\u53f7\uff1b\r\n    \/\/\u6ce8\u518c\u8bbe\u5907\u53f7\uff1b\r\n    \/\/\u7533\u8bf7\u5206\u914d\u8bbe\u5907\u7ed3\u6784\u4f53\u7684\u5185\u5b58\uff1b\r\n}<\/pre>\n
    \/*\u6a21\u5757\u5378\u8f7d\u51fd\u6570*\/\r\nstatic void __exit xxx_exit(void)\r\n{\r\n    ...\r\n    \/\/\u91ca\u653e\u539f\u5148\u7533\u8bf7\u7684\u8bbe\u5907\u53f7\uff1b\r\n    \/\/\u91ca\u653e\u539f\u5148\u7533\u8bf7\u7684\u5185\u5b58\uff1b\r\n    \/\/\u6ce8\u9500cdev\u8bbe\u5907\uff1b\r\n}<\/pre>\n

    4.8 \u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7684file_operations\u7ed3\u6784\u4f53\u6210\u5458\u51fd\u6570<\/strong><\/em><\/p>\n

    \/*\u8bfb\u8bbe\u5907*\/\r\nssize_t xxx_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)\r\n{\r\n    \/*\u4f7f\u7528filp->private_data\u83b7\u53d6\u8bbe\u5907\u7ed3\u6784\u4f53\u6307\u9488\uff1b*\/\r\n    \/*\u5206\u6790\u548c\u83b7\u53d6\u6709\u6548\u7684\u957f\u5ea6\uff1b*\/\r\n    \/*\u5185\u6838\u7a7a\u95f4\u5230\u7528\u6237\u7a7a\u95f4\u7684\u6570\u636e\u4f20\u9012*\/\r\n    copy_to_user(void __user *to, const void *from, unsigned long count);\r\n}<\/pre>\n
    \/*\u5199\u8bbe\u5907*\/\r\nssize_t xxx_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos)\r\n{\r\n    \/*\u4f7f\u7528filp->private_data\u83b7\u53d6\u8bbe\u5907\u7ed3\u6784\u4f53\u6307\u9488\uff1b*\/\r\n    \/*\u5206\u6790\u548c\u83b7\u53d6\u6709\u6548\u7684\u957f\u5ea6\uff1b*\/ \r\n    \/*\u7528\u6237\u7a7a\u95f4\u5230\u5185\u6838\u7a7a\u95f4\u7684\u6570\u636e\u4f20\u9012*\/\r\n    copy_from_user(void *to, const void __user *from, unsigned long count);\r\n}<\/pre>\n
    \/*ioctl\u51fd\u6570*\/\r\nstatic int xxx_ioctl(struct inode *inode,struct file *filp,unsigned int cmd,unsigned long arg) \r\n{\r\n   switch(cmd){\r\n      case xxx_CMD1:\r\n         break;\r\n      case xxx_CMD2:\r\n         break;\r\n      default:\r\n         return -ENOTTY; \/*\u4e0d\u80fd\u652f\u6301\u7684\u547d\u4ee4*\/\r\n   }\r\n   return 0;\r\n}<\/pre>\n

    4.9 \u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u6587\u4ef6\u64cd\u4f5c\u7ed3\u6784\u4f53\u6a21\u677f<\/strong><\/em><\/p>\n

    struct file_operations xxx_fops = {\r\n    .owner = THIS_MODULE,\r\n    .open = xxx_open,\r\n    .read = xxx_read,\r\n    .write = xxx_write,\r\n    .close = xxx_release,\r\n    .ioctl = xxx_ioctl,\r\n    .lseek = xxx_llseek,\r\n};<\/pre>\n
    \n

    \u539f\u6587\u6765\u81ea\uff1ahttp:\/\/blog.jobbole.com\/86531\/<\/a><\/p>\n

    \u672c\u6587\u5730\u5740\uff1ahttp:\/\/lrxjmw.cn\/linux-device-driver.html<\/a>\u7f16\u8f91\uff1a\u738b\u663e\u707f\uff0c\u5ba1\u6838\u5458\uff1a\u51af\u742a<\/span><\/p>\n<\/blockquote>\n

     <\/p>\n","protected":false},"excerpt":{"rendered":"

    \u5bfc\u8bfb Linux\u5b57\u7b26\u8bbe\u5907\u63d0\u4f9b\u8fde\u7eed\u7684\u6570\u636e\u6d41\uff0c\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u987a\u5e8f\u8bfb\u53d6\uff0c\u901a\u5e38\u4e0d\u652f\u6301\u968f\u673a\u5b58\u53d6\u3002\u76f8\u53cd\uff0c\u6b64\u7c7b\u8bbe\u5907\u652f\u6301\u6309\u5b57\u8282\/ […]<\/p>\n","protected":false},"author":402,"featured_media":51722,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-49713","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/49713","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/402"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=49713"}],"version-history":[{"count":24,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/49713\/revisions"}],"predecessor-version":[{"id":273138,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/49713\/revisions\/273138"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/51722"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=49713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=49713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=49713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}