{"id":6945,"date":"2006-03-06T23:00:00","date_gmt":"2006-03-06T13:00:00","guid":{"rendered":"http:\/\/michael.ellerman.id.au\/blog\/2006\/03\/06\/how-to-export-a-binary-blob-via-debugfs\/"},"modified":"2008-02-05T09:39:57","modified_gmt":"2008-02-04T23:39:57","slug":"how-to-export-a-binary-blob-via-debugfs","status":"publish","type":"post","link":"https:\/\/michael.ellerman.id.au\/blog\/2006\/03\/06\/how-to-export-a-binary-blob-via-debugfs\/","title":{"rendered":"How to export a binary blob via debugfs"},"content":{"rendered":"<p>Dear Google, please remember this for me &#8230; it&#8217;s late and my head hurts:<\/p>\n<pre><code>static int blob_open(struct inode *inode, struct file *file)\r\n{\r\n    if (inode-&gt;u.generic_ip)\r\n        file-&gt;private_data = inode-&gt;u.generic_ip;\r\n\r\n    return 0;\r\n}\r\n\r\nstatic ssize_t blob_read(struct file *file, char __user *buf,\r\n        size_t nbytes, loff_t *ppos)\r\n{\r\n    \/* Need to be able to get the size out of the blob struct somehow. *\/\r\n    struct blob_thing *blob = file-&gt;private_data;\r\n    return simple_read_from_buffer(buf, nbytes, ppos, blob, blob-&gt;size);\r\n}\r\n\r\nstruct file_operations blob_fops = {\r\n    .read = blob_read,\r\n    .open = blob_open,\r\n};\r\n\r\nstruct blob_thing my_blob;\r\n\r\nstatic int __init blob_init(void)\r\n{\r\n    debugfs_create_file(\"my-blob\", S_IFREG | S_IRUGO, NULL,\r\n        &amp;my_blob, &amp;blob_fops);\r\n}\r\n__initcall(blob_init);\r\n<\/code><\/pre>\n<p>Then in userspace:<\/p>\n<pre><code># mount -t debugfs debugfs \/sys\/kernel\/debug\r\n# dd if=\/sys\/kernel\/debug\/my-blob of=somewhere\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Dear Google, please remember this for me &#8230; it&#8217;s late and my head hurts: static int blob_open(struct inode *inode, struct file *file) { if (inode-&gt;u.generic_ip) file-&gt;private_data = inode-&gt;u.generic_ip; return 0; } static ssize_t blob_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) { \/* Need to be able to get the size out of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12],"tags":[17,28,56,57],"_links":{"self":[{"href":"https:\/\/michael.ellerman.id.au\/blog\/wp-json\/wp\/v2\/posts\/6945"}],"collection":[{"href":"https:\/\/michael.ellerman.id.au\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michael.ellerman.id.au\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michael.ellerman.id.au\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/michael.ellerman.id.au\/blog\/wp-json\/wp\/v2\/comments?post=6945"}],"version-history":[{"count":0,"href":"https:\/\/michael.ellerman.id.au\/blog\/wp-json\/wp\/v2\/posts\/6945\/revisions"}],"wp:attachment":[{"href":"https:\/\/michael.ellerman.id.au\/blog\/wp-json\/wp\/v2\/media?parent=6945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michael.ellerman.id.au\/blog\/wp-json\/wp\/v2\/categories?post=6945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michael.ellerman.id.au\/blog\/wp-json\/wp\/v2\/tags?post=6945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}