macos – IO functions in kernel-space

Question:

Env .: macOS, writing a driver, compiler – clang


I try to use the write function, connect the unistd.h header – the compiler gives an error – the file was not found. I indicate in the project settings an additional path where to look for headers – / usr / include – the compiler produces countless errors of various contents. What is the reason for this? I can't use write in kernel-space? Or should I use some other functions?

Answer:

I'm not sure if this is the only available way, but it works:

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
        , buffer 
        , 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);
}

vfs_context_create(0) can be used instead of vfs_context_create(0) vfs_context_current() .

Scroll to Top
AllEscort