[Bug 299239] inotify_add_watch(2) fails with EBADF on fusefs subdirectories

From: <bugzilla-noreply_at_freebsd.org>
Date: Fri, 09 Oct 2026 01:57:15 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=299239

            Bug ID: 299239
           Summary: inotify_add_watch(2) fails with EBADF on fusefs
                    subdirectories
           Product: Base System
           Version: 15.1-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: sam@sheridan.co.uk
 Attachment #275510 text/plain
         mime type:

Created attachment 275510
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=275510&action=edit
inotify test: watches a directory and prints events

On 15.1-RELEASE-p4 amd64, inotify_add_watch() on a directory inside a fusefs
mount fails with EBADF unless some process has that directory open. File
managers (Thunar, via GLib) never see changes on exFAT/NTFS drives.

vn_inotify_add_watch() scans the directory with vn_dir_next_dirent() without
a VOP_OPEN, and fuse_vnop_readdir() returns EBADF when there is no open
directory handle (it only opens one implicitly for MNT_EXPORTED mounts).
Same code in main. The mount's root works because fuse_vnop_close() keeps
directory handles until VOP_INACTIVE, which the root never reaches.

To reproduce with the attached inw.c and fusefs-exfat:
  mount.exfat-fuse /dev/da1s1 /mnt; mkdir /mnt/sub
  ./inw /mnt/sub                                # Bad file descriptor
  sh -c 'exec 3</mnt/sub; sleep 30' & ./inw /mnt/sub   # works

Same pattern as bug 278135 (a fusefs operation on a vnode with no open handle).

-- 
You are receiving this mail because:
You are the assignee for the bug.