#include <sys/file.h>
sys/file.h
functionfile_socket
int file_socket(int, socket_t *)
▾
claude-fable-5, 2026-08-23 · not from Apple sources · verified against xnu bsd/kern/kern_descrip.c
Looks up fd in the calling process's open file table and returns its socket in *sp. On success an I/O reference (fp_iocount) is taken on the underlying fileproc, which must be released with file_drop(); no reference is taken on the socket itself, so the pointer can become invalid once that reference is dropped and the file is closed. Returns ENOTSOCK if fd does not refer to a socket, EBADF for a bad descriptor. Use of this function is discouraged.
functionfile_vnode
int file_vnode(int, vnode_t *)
▾
claude-fable-5, 2026-08-23 · not from Apple sources · verified against xnu bsd/kern/kern_descrip.c
Looks up fd in the calling process's open file table and returns its vnode in *vpp; equivalent to file_vnode_withvid with a NULL vid pointer. On success an I/O reference (fp_iocount) is taken on the underlying fileproc, which must be released with file_drop(); no vnode reference is taken, so the pointer can become invalid once that reference is dropped and the file is closed. Returns EINVAL if fd does not refer to a vnode, EBADF for a bad descriptor. Use of this function is discouraged.
functionfile_vnode_withvid
int file_vnode_withvid(int, vnode_t *, uint32_t *)
▾
claude-fable-5, 2026-08-23 · not from Apple sources · verified against xnu bsd/kern/kern_descrip.c
As file_vnode(), but additionally returns the vnode's identity generation (vid) in *vidp when that pointer is non-NULL, allowing the caller to revalidate the vnode later with vnode_getwithvid(). Takes an fp_iocount reference that must be released with file_drop(). Returns EINVAL if fd does not refer to a vnode, EBADF for a bad descriptor. Use of this function is discouraged.
functionfile_flags
int file_flags(int, int *)
▾
claude-fable-5, 2026-08-23 · not from Apple sources · verified against xnu bsd/kern/kern_descrip.c
Returns in *flags the open-file flags (the fileproc's f_flag: FREAD, FWRITE, nonblocking and append state, ...) of the file underlying fd in the calling process. Returns EBADF if fd is invalid. Unlike file_vnode() and file_socket(), no I/O reference is held on return.
functionfile_drop
int file_drop(int)
▾
claude-fable-5, 2026-08-23 · not from Apple sources · verified against xnu bsd/kern/kern_descrip.c
Drops the I/O reference (fp_iocount) on fd's fileproc obtained by file_vnode(), file_vnode_withvid(), or file_socket(), and wakes any thread waiting to drain the file during a close. Always returns 0. Panics if the caller could not have held an I/O reference. Use of this function is discouraged, like the functions it balances.