Files
AnyPS5/docs/dev/debt/changes/docs-libkernel-vnode-attrib-console-1160.md

5.1 KiB

libkernel

change [EVFILT_VNODE, sceKernelAddFileEvent and sceKernelDeleteFileEvent]

  • EVFILT_VNODE, sceKernelAddFileEvent and sceKernelDeleteFileEvent (libkernel) watch the host file or directory behind the descriptor and turn host changes into FreeBSD 11 vnode hints, which filt_vfsvnode adds whole when they share a bit with the requested fflags: a write that grows a file is NOTE_WRITE | NOTE_EXTEND, another write NOTE_WRITE, a shrinking truncate or an attribute change NOTE_ATTRIB, a higher link count NOTE_LINK, a lower one or a pending delete NOTE_DELETE, a new path NOTE_RENAME; in a directory, an entry created, removed or renamed is NOTE_WRITE, with NOTE_LINK for a subdirectory, and on Linux an entry moved from or to another directory adds NOTE_EXTEND; inotify queues the two halves of a rename one after the other, so a watcher woken by the first can read it alone, and a half read without the other is classified only after a getdents64 on the watched directory, which takes the directory lock that rename holds until both halves are queued (do_renameat2 around vfs_rename and its fsnotify_move, iterate_dir), an ordering taken from the kernel source, not from inotify(7), which promises none; a directory registered with NOTE_EXTEND on Windows is accepted, as vfs_kqfilter does not check it, but never receives it, because the directory handle cannot tell a move between directories from a removal plus an addition. FreeBSD's hints depend on the filesystem. On a PS5 payload process (firmware 11.60) every ftruncate (growing, shrinking or to the size the file has), fchmod to the mode the file has and utimes reported NOTE_ATTRIB alone, a pwrite that grew the file NOTE_WRITE | NOTE_EXTEND and one that did not NOTE_WRITE, and a second EV_ADD replaced the fflags of the first; titles are not measured. Here a growing ftruncate reports NOTE_WRITE | NOTE_EXTEND where the console reports NOTE_ATTRIB, and on Windows utimes on a file reports NOTE_WRITE. The three Windows notifications are told apart in the error, which names the parent, entries or subdirectories watch, the path it was given and GetLastError, but a FindFirstChangeNotification that fails still throws rather than returning an error to the guest: the EVFILT_VNODE attach path is vfs_kqfilter, which returns EINVAL, ENOMEM or 0 after fget has turned a descriptor that is not open into EBADF, and consults no directory permission, so no FreeBSD errno stands for a host that refuses to notify, and what the console does on such a host is not measured. Only the parent watch can fail this way in practice: entries and subdirectories need the FILE_LIST_DIRECTORY that opening the watched directory already took. The parent handle produces no hint of its own, as RunHostWatch only calls FindNextChangeNotification on it, so a later change may leave the watch on its 50 ms poll instead of throwing; that is not done here. Windows uses FindFirstChangeNotification on the parent directory (and on a watched directory itself) and compares GetFileInformationByHandleEx snapshots at least every 50 ms, because a write through an open handle is reported only when the handle is flushed or closed, so file hints can arrive 50 ms late, and a file deleted while watched, which the POSIX delete of Windows 10 1903 moves into $Extend\$Deleted until its last handle closes, reports NOTE_DELETE without NOTE_RENAME and keeps its handle without a parent directory watch, as that directory cannot be watched; a shrinking truncate of a watched file can also report NOTE_WRITE on Windows, because NTFS can show the truncate's new LastWriteTime before its new size (2 to 12 times per million back-to-back shrinking SetEndOfFile calls on a loaded machine, also through a single NtQueryInformationFile(FileAllInformation)), and a snapshot taken in between sees a write at the old size; Linux uses inotify on the file and is not run. NOTE_REVOKE, NOTE_OPEN, NOTE_CLOSE, NOTE_CLOSE_WRITE, NOTE_READ, unknown bits and descriptors other than files, directories, pipes and sockets throw. sceKernelAddFileEvent(eq, fd, watch, udata) and sceKernelDeleteFileEvent(eq, fd) take the OpenOrbis and SharpProspero signatures; watch is taken as the fflags and the event is added with EV_CLEAR, neither confirmed on a title (feat(libkernel): implement kevent EV_DISABLE, EV_DISPATCH and EV_FORCEONESHOT) (fix(libkernel): follow kqueue_register for EV_FORCEONESHOT and modify flags)