Created
August 7, 2018 06:30
-
-
Save isnullxbh/2c2fb731331a37d90e8bea1d4ac23757 to your computer and use it in GitHub Desktop.
Write into file from kernel-space
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <sys/time.h> | |
| #include <sys/vnode.h> | |
| #include <sys/fcntl.h> | |
| ... | |
| static int idx = 0; | |
| char file_name_buf[100]; | |
| file_name_buf[0] = 0; | |
| snprintf(file_name_buf, 100, "/tmp/vbi_%d.cap", ++idx); | |
| if (m_vbi_flow) { | |
| BUF_INFO2_T buf_inf = { .type = FE_BUF_TYPE_VBI }; | |
| if (STATUS_SUCCESS == m_vbi_flow->setDQBuf(&buf_inf)) { | |
| // bcopy(, dest_ptr, buf_inf.bytesused); | |
| vnode_t vnode = NULLVP; | |
| vfs_context_t ctxt = vfs_context_create(0); | |
| errno_t errno; | |
| errno = vnode_open(file_name_buf, (O_TRUNC | O_CREAT | O_RDWR), S_IRUSR | S_IWUSR, VNODE_LOOKUP_NOFOLLOW, &vnode, ctxt); | |
| if (!errno) { | |
| vn_rdwr(UIO_WRITE, vnode, (char*)m_pBufs[buf_inf.index]->getBufferAddr(), buf_inf.bytesused, 0, UIO_SYSSPACE, IO_NOCACHE|IO_NODELOCKED|IO_UNIT, vfs_context_ucred(ctxt), (int *) 0, vfs_context_proc(ctxt)); | |
| vnode_close(vnode, FWASWRITTEN, ctxt); | |
| } | |
| setQBuf(m_feHandle, &buf_inf); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment