mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-12-05 00:50:52 +00:00
5.1 KiB
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_vfsvnodeadds whole when they share a bit with the requestedfflags: a write that grows a file isNOTE_WRITE | NOTE_EXTEND, another writeNOTE_WRITE, a shrinking truncate or an attribute changeNOTE_ATTRIB, a higher link countNOTE_LINK, a lower one or a pending deleteNOTE_DELETE, a new pathNOTE_RENAME; in a directory, an entry created, removed or renamed isNOTE_WRITE, withNOTE_LINKfor a subdirectory, and on Linux an entry moved from or to another directory addsNOTE_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 agetdents64on the watched directory, which takes the directory lock thatrenameholds until both halves are queued (do_renameat2aroundvfs_renameand itsfsnotify_move,iterate_dir), an ordering taken from the kernel source, not from inotify(7), which promises none; a directory registered withNOTE_EXTENDon Windows is accepted, asvfs_kqfilterdoes 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) everyftruncate(growing, shrinking or to the size the file has),fchmodto the mode the file has andutimesreportedNOTE_ATTRIBalone, apwritethat grew the fileNOTE_WRITE | NOTE_EXTENDand one that did notNOTE_WRITE, and a secondEV_ADDreplaced thefflagsof the first; titles are not measured. Here a growingftruncatereportsNOTE_WRITE | NOTE_EXTENDwhere the console reportsNOTE_ATTRIB, and on Windowsutimeson a file reportsNOTE_WRITE. The three Windows notifications are told apart in the error, which names theparent,entriesorsubdirectorieswatch, the path it was given andGetLastError, but aFindFirstChangeNotificationthat fails still throws rather than returning an error to the guest: the EVFILT_VNODE attach path isvfs_kqfilter, which returnsEINVAL,ENOMEMor 0 afterfgethas turned a descriptor that is not open intoEBADF, 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 theparentwatch can fail this way in practice:entriesandsubdirectoriesneed theFILE_LIST_DIRECTORYthat opening the watched directory already took. The parent handle produces no hint of its own, asRunHostWatchonly callsFindNextChangeNotificationon it, so a later change may leave the watch on its 50 ms poll instead of throwing; that is not done here. Windows usesFindFirstChangeNotificationon the parent directory (and on a watched directory itself) and comparesGetFileInformationByHandleExsnapshots 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\$Deleteduntil its last handle closes, reportsNOTE_DELETEwithoutNOTE_RENAMEand keeps its handle without a parent directory watch, as that directory cannot be watched; a shrinking truncate of a watched file can also reportNOTE_WRITEon Windows, because NTFS can show the truncate's newLastWriteTimebefore its new size (2 to 12 times per million back-to-back shrinkingSetEndOfFilecalls on a loaded machine, also through a singleNtQueryInformationFile(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)andsceKernelDeleteFileEvent(eq, fd)take the OpenOrbis and SharpProspero signatures;watchis taken as thefflagsand the event is added withEV_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)