Skip to contentSkip to conversation

fanotify: Document FAN_REPORT_FD_ERROR

PATCH In review Amir Goldstein 2 participants 7 messages Mar 31, 2025 – Apr 3, 2025 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 fanotify: Document FAN_REPORT_FD_ERROR

This flag from v6.13 allows reporting detailed errors on failure to open a file descriptor for an event.

This API was backported to LTS kernels v6.12.4 and v6.6.66.

---

Changes from v1:
- Added RVB
- typo and format fixes

 man/man2/fanotify_init.2 | 28 ++++++++++++++++++++++++++++
 man/man7/fanotify.7      | 14 ++++++++++++++
 2 files changed, 42 insertions(+)
man/man2/fanotify_init.2 +28 -0
index fa4ae9125..bf573c6fa 100644
@@ -364,6 +364,34 @@ so this restriction may eventually be lifted.
 For more details on information records,
 see
 .BR fanotify (7).
+.TP
+.BR FAN_REPORT_FD_ERROR " (since Linux 6.13 and 6.12.4 and 6.6.66)"
+.\" commit 522249f05c5551aec9ec0ba9b6438f1ec19c138d
+Events for fanotify groups initialized with this flag may contain
+an error code that explains the reason for failure to open a file descriptor.
+The
+.I .fd
+member of the
+.I fanotify_event_metadata
+structure normally contains
+an open file descriptor associated with the object of the event
+or FAN_NOFD in case a file descriptor could not be opened.
+For a group initialized with this flag, instead of FAN_NOFD,
+the
+.I .fd
+member of the
+.I fanotify_event_metadata
+structure will contain a negative error value.
+When the group is also initialized with flag
+.BR FAN_REPORT_PIDFD ,
+in case a process file descriptor could not be opened,
+the
+.I .pidfd
+member of the
+.I fanotify_event_info_pidfd
+structure will also contain a negative error value.
+For more details, see
+.BR fanotify (7).
 .P
 The
 .I event_f_flags
man/man7/fanotify.7 +14 -0
index a532a963a..fd16bf294 100644
@@ -335,6 +335,13 @@ file status flag is set on the open file description.
 This flag suppresses fanotify event generation.
 Hence, when the receiver of the fanotify event accesses the notified file or
 directory using this file descriptor, no additional events will be created.
+.IP
+When an fanotify group is initialized using
+.BR FAN_REPORT_FD_ERROR ,
+this field will contain a negative error value in case a file descriptor
+could not be opened and
+in case of a queue overflow, the value will be
+.BR \-EBADF .
 .TP
 .I pid
 If flag
@@ -679,6 +686,13 @@ Once the event listener has dealt with an event
 and the pidfd is no longer required,
 the pidfd should be closed via
 .BR close (2).
+.IP
+When an fanotify group is initialized using
+.BR FAN_REPORT_FD_ERROR ,
+this field will contain a negative error value
+in case a pidfd creation failure and
+in case of a terminated process, the value will be
+.BR \-ESRCH .
 .P
 The fields of the
 .I fanotify_event_info_error
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 2/3 fanotify: Fixes for documentation of FAN_FS_ERROR

FAN_EVENT_INFO_TYPE_ERROR was missing from the list of info types.

The order of FAN_FS_ERROR entry in the event section was rather arbitrary inside the group of fid info events.

FAN_FS_ERROR is a special event with error info, so place its entry after the entries for fid info events and before the entries for permission events.

Reduce unneeded newlines in the FAN_FS_ERROR entry.

---

Alejandro,

This unrelated cleanup was plit out of the FAN_PRE_ACCESS patch and I have also added some extra cleanup in preparation for adding mount events.

If you were going to re-organize the section describing the different extra event info types, maybe better doing this after merging the new types from v6.14: FAN_EVENT_INFO_TYPE_RANGE and FAN_EVENT_INFO_TYPE_MNT.

Thanks,
Amir.

 man/man2/fanotify_mark.2 | 44 +++++++++++++++++++---------------------
 man/man7/fanotify.7      |  7 ++++---
 2 files changed, 25 insertions(+), 26 deletions(-)
man/man2/fanotify_mark.2 +21 -23
index 47cafb21c..1d132fa1a 100644
@@ -362,29 +362,6 @@ Create an event when a marked file or directory itself is deleted.
 An fanotify group that identifies filesystem objects by file handles
 is required.
 .TP
-.BR FAN_FS_ERROR " (since Linux 5.16, 5.15.154, and 5.10.220)"
-.\" commit 9709bd548f11a092d124698118013f66e1740f9b
-Create an event when a filesystem error
-leading to inconsistent filesystem metadata is detected.
-An additional information record of type
-.B FAN_EVENT_INFO_TYPE_ERROR
-is returned for each event in the read buffer.
-An fanotify group that identifies filesystem objects by file handles
-is required.
-.IP
-Events of such type are dependent on support
-from the underlying filesystem.
-At the time of writing,
-only the
-.B ext4
-filesystem reports
-.B FAN_FS_ERROR
-events.
-.IP
-See
-.BR fanotify (7)
-for additional details.
-.TP
 .BR FAN_MOVED_FROM " (since Linux 5.1)"
 .\" commit 235328d1fa4251c6dcb32351219bb553a58838d2
 Create an event when a file or directory has been moved from a marked
@@ -418,6 +395,27 @@ Create an event when a marked file or directory itself has been moved.
 An fanotify group that identifies filesystem objects by file handles
 is required.
 .TP
+.BR FAN_FS_ERROR " (since Linux 5.16, 5.15.154, and 5.10.220)"
+.\" commit 9709bd548f11a092d124698118013f66e1740f9b
+Create an event when a filesystem error
+leading to inconsistent filesystem metadata is detected.
+An additional information record of type
+.B FAN_EVENT_INFO_TYPE_ERROR
+is returned for each event in the read buffer.
+An fanotify group that identifies filesystem objects by file handles
+is required.
+Events of such type are dependent on support
+from the underlying filesystem.
+At the time of writing,
+only the
+.B ext4
+filesystem reports
+.B FAN_FS_ERROR
+events.
+See
+.BR fanotify (7)
+for additional details.
+.TP
 .B FAN_OPEN_PERM
 Create an event when a permission to open a file or directory is requested.
 An fanotify file descriptor created with
man/man7/fanotify.7 +4 -3
index fd16bf294..614410cd9 100644
@@ -395,9 +395,6 @@ A child file or directory was deleted in a watched parent.
 .B FAN_DELETE_SELF
 A watched file or directory was deleted.
 .TP
-.B FAN_FS_ERROR
-A filesystem error was detected.
-.TP
 .B FAN_RENAME
 A file or directory has been moved to or from a watched parent directory.
 .TP
@@ -425,6 +422,9 @@ A file or directory that was opened read-only
 .RB ( O_RDONLY )
 was closed.
 .TP
+.B FAN_FS_ERROR
+A filesystem error was detected.
+.TP
 .B FAN_Q_OVERFLOW
 The event queue exceeded the limit on number of events.
 This limit can be overridden by specifying the
@@ -510,6 +510,7 @@ The value of this field can be set to one of the following:
 .BR FAN_EVENT_INFO_TYPE_FID ,
 .BR FAN_EVENT_INFO_TYPE_DFID ,
 .BR FAN_EVENT_INFO_TYPE_DFID_NAME ,
+.BR FAN_EVENT_INFO_TYPE_ERROR ,
 or
 .BR FAN_EVENT_INFO_TYPE_PIDFD .
 The value set for this field
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v2 2/3] fanotify: Fixes for documentation of FAN_FS_ERROR

Hi Amir,

Quoted 40 lines · Amir Goldstein

FAN_EVENT_INFO_TYPE_ERROR was missing from the list of info types.

The order of FAN_FS_ERROR entry in the event section was rather arbitrary inside the group of fid info events.

FAN_FS_ERROR is a special event with error info, so place its entry after the entries for fid info events and before the entries for permission events.

Reduce unneeded newlines in the FAN_FS_ERROR entry.

---

Alejandro,

This unrelated cleanup was plit out of the FAN_PRE_ACCESS patch and I have also added some extra cleanup in preparation for adding mount events.

If you were going to re-organize the section describing the different extra event info types, maybe better doing this after merging the new types from v6.14: FAN_EVENT_INFO_TYPE_RANGE and FAN_EVENT_INFO_TYPE_MNT.

Thanks,
Amir.

 man/man2/fanotify_mark.2 | 44 +++++++++++++++++++---------------------
 man/man7/fanotify.7      |  7 ++++---
 2 files changed, 25 insertions(+), 26 deletions(-)
man/man2/fanotify_mark.2 +0 -0
index 47cafb21c..1d132fa1a 100644
@@ -362,29 +362,6 @@ Create an event when a marked file or directory itself is deleted.
 An fanotify group that identifies filesystem objects by file handles
 is required.
 .TP

man/man2/fanotify_mark.2 Create an event when a marked file or directory itself is deleted. · line 374

Quoted 10 lines
man/man2/fanotify_mark.2 +0 -10
-.BR FAN_FS_ERROR " (since Linux 5.16, 5.15.154, and 5.10.220)"
-.\" commit 9709bd548f11a092d124698118013f66e1740f9b
-Create an event when a filesystem error
-leading to inconsistent filesystem metadata is detected.
-An additional information record of type
-.B FAN_EVENT_INFO_TYPE_ERROR
-is returned for each event in the read buffer.
-An fanotify group that identifies filesystem objects by file handles
-is required.
-.IP

You forgot the .IP in the moved text.

Cheers,
Alex

Quoted 79 lines
man/man2/fanotify_mark.2 +21 -13
-Events of such type are dependent on support
-from the underlying filesystem.
-At the time of writing,
-only the
-.B ext4
-filesystem reports
-.B FAN_FS_ERROR
-events.
-.IP
-See
-.BR fanotify (7)
-for additional details.
-.TP
 .BR FAN_MOVED_FROM " (since Linux 5.1)"
 .\" commit 235328d1fa4251c6dcb32351219bb553a58838d2
 Create an event when a file or directory has been moved from a marked
@@ -418,6 +395,27 @@ Create an event when a marked file or directory itself has been moved.
 An fanotify group that identifies filesystem objects by file handles
 is required.
 .TP
+.BR FAN_FS_ERROR " (since Linux 5.16, 5.15.154, and 5.10.220)"
+.\" commit 9709bd548f11a092d124698118013f66e1740f9b
+Create an event when a filesystem error
+leading to inconsistent filesystem metadata is detected.
+An additional information record of type
+.B FAN_EVENT_INFO_TYPE_ERROR
+is returned for each event in the read buffer.
+An fanotify group that identifies filesystem objects by file handles
+is required.
+Events of such type are dependent on support
+from the underlying filesystem.
+At the time of writing,
+only the
+.B ext4
+filesystem reports
+.B FAN_FS_ERROR
+events.
+See
+.BR fanotify (7)
+for additional details.
+.TP
 .B FAN_OPEN_PERM
 Create an event when a permission to open a file or directory is requested.
 An fanotify file descriptor created with
man/man7/fanotify.7 +4 -3
index fd16bf294..614410cd9 100644
@@ -395,9 +395,6 @@ A child file or directory was deleted in a watched parent.
 .B FAN_DELETE_SELF
 A watched file or directory was deleted.
 .TP
-.B FAN_FS_ERROR
-A filesystem error was detected.
-.TP
 .B FAN_RENAME
 A file or directory has been moved to or from a watched parent directory.
 .TP
@@ -425,6 +422,9 @@ A file or directory that was opened read-only
 .RB ( O_RDONLY )
 was closed.
 .TP
+.B FAN_FS_ERROR
+A filesystem error was detected.
+.TP
 .B FAN_Q_OVERFLOW
 The event queue exceeded the limit on number of events.
 This limit can be overridden by specifying the
@@ -510,6 +510,7 @@ The value of this field can be set to one of the following:
 .BR FAN_EVENT_INFO_TYPE_FID ,
 .BR FAN_EVENT_INFO_TYPE_DFID ,
 .BR FAN_EVENT_INFO_TYPE_DFID_NAME ,
+.BR FAN_EVENT_INFO_TYPE_ERROR ,
 or
 .BR FAN_EVENT_INFO_TYPE_PIDFD .
 The value set for this field
Signature · 1 line
2.34.1
Signature · 3 lines
<https://www.alejandro-colomar.es/>
<https://www.alejandro-colomar.es:8443/>
<http://www.alejandro-colomar.es:8080/>
#3 lore raw

Re: [PATCH v2 2/3] fanotify: Fixes for documentation of FAN_FS_ERROR

Quoted 48 lines · Alejandro Colomar

Hi Amir,

Quoted 44 lines · Amir Goldstein

FAN_EVENT_INFO_TYPE_ERROR was missing from the list of info types.

The order of FAN_FS_ERROR entry in the event section was rather arbitrary inside the group of fid info events.

FAN_FS_ERROR is a special event with error info, so place its entry after the entries for fid info events and before the entries for permission events.

Reduce unneeded newlines in the FAN_FS_ERROR entry.

---

Alejandro,

This unrelated cleanup was plit out of the FAN_PRE_ACCESS patch and I have also added some extra cleanup in preparation for adding mount events.

If you were going to re-organize the section describing the different extra event info types, maybe better doing this after merging the new types from v6.14: FAN_EVENT_INFO_TYPE_RANGE and FAN_EVENT_INFO_TYPE_MNT.

Thanks,
Amir.

 man/man2/fanotify_mark.2 | 44 +++++++++++++++++++---------------------
 man/man7/fanotify.7      |  7 ++++---
 2 files changed, 25 insertions(+), 26 deletions(-)
man/man2/fanotify_mark.2 +0 -4
index 47cafb21c..1d132fa1a 100644
@@ -362,29 +362,6 @@ Create an event when a marked file or directory itself is deleted.
 An fanotify group that identifies filesystem objects by file handles
 is required.
 .TP
-.BR FAN_FS_ERROR " (since Linux 5.16, 5.15.154, and 5.10.220)"
-.\" commit 9709bd548f11a092d124698118013f66e1740f9b
-Create an event when a filesystem error
-leading to inconsistent filesystem metadata is detected.
Quoted 9 lines

man/man2/fanotify_mark.2 Create an event when a marked file or directory itself is deleted. · line 374

Quoted 6 lines
man/man2/fanotify_mark.2 +0 -6
-An additional information record of type
-.B FAN_EVENT_INFO_TYPE_ERROR
-is returned for each event in the read buffer.
-An fanotify group that identifies filesystem objects by file handles
-is required.
-.IP

You forgot the .IP in the moved text.

I wrote "Reduce unneeded newlines in the FAN_FS_ERROR entry." The newlines seem unneeded IMO and inconsistent with other entries.

But it's not a big deal.

Thanks,
Amir.

#4 lore raw

Re: [PATCH v2 2/3] fanotify: Fixes for documentation of FAN_FS_ERROR

Hi Amir,

Quoted 6 lines · Amir Goldstein
Quoted 2 lines

You forgot the .IP in the moved text.

I wrote "Reduce unneeded newlines in the FAN_FS_ERROR entry." The newlines seem unneeded IMO and inconsistent with other entries.

Ah, okay, I missed that. I thought it was a mistake. :) Then I'm fine with it, I think.

Have a lovely day!
Alex

Quoted 2 lines

But it's not a big deal.

Signature · 3 lines
<https://www.alejandro-colomar.es/>
<https://www.alejandro-colomar.es:8443/>
<http://www.alejandro-colomar.es:8080/>
#5 lore raw

PATCH v2 3/3 fanotify: Document FAN_PRE_ACCESS event

In reply to Amir Goldstein

The new FAN_PRE_ACCESS events are created before access to a file range, to provides an opportunity for the event listener to modify the content of the object before the user can accesss it.

Those events are available for group in class FAN_CLASS_PRE_CONTENT They are reported with FAN_EVENT_INFO_TYPE_RANGE info record.

---

Changed from v1:
- Added RVB
- Added FAN_PRE_ACCESS to fanotify.7
- Split out missing FAN_EVENT_INFO_TYPE_ERROR to pre patch
- Minor format fixes

 man/man2/fanotify_init.2 |  4 ++--
 man/man2/fanotify_mark.2 | 14 ++++++++++++
 man/man7/fanotify.7      | 49 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+), 2 deletions(-)
man/man2/fanotify_init.2 +2 -2
index bf573c6fa..699b6f054 100644
@@ -57,8 +57,8 @@ Only one of the following notification classes may be specified in
 .B FAN_CLASS_PRE_CONTENT
 This value allows the receipt of events notifying that a file has been
 accessed and events for permission decisions if a file may be accessed.
-It is intended for event listeners that need to access files before they
-contain their final data.
+It is intended for event listeners that may need to write data to files
+before their final data can be accessed.
 This notification class might be used by hierarchical storage managers,
 for example.
 Use of this flag requires the
man/man2/fanotify_mark.2 +14 -0
index 1d132fa1a..da569279b 100644
@@ -443,6 +443,20 @@ or
 .B FAN_CLASS_CONTENT
 is required.
 .TP
+.BR FAN_PRE_ACCESS " (since Linux 6.14)"
+.\" commit 4f8afa33817a6420398d1c177c6e220a05081f51
+Create an event before read or write access to a file range,
+that provides an opportunity for the event listener
+to modify the content of the file
+before access to the content
+in the specified range.
+An additional information record of type
+.B FAN_EVENT_INFO_TYPE_RANGE
+is returned for each event in the read buffer.
+An fanotify file descriptor created with
+.B FAN_CLASS_PRE_CONTENT
+is required.
+.TP
 .B FAN_ONDIR
 Create events for directories\[em]for example, when
 .BR opendir (3),
man/man7/fanotify.7 +49 -0

73 lines not on this page · raw message

Signature · 1 line
2.34.1
#6 lore raw
In reply to Amir Goldstein

Hi Amir,

Quoted 8 lines · Amir Goldstein

This flag from v6.13 allows reporting detailed errors on failure to open a file descriptor for an event.

This API was backported to LTS kernels v6.12.4 and v6.6.66.

Thanks! I've applied the patch.

Have a lovely night!
Alex

Quoted 84 lines

---

Changes from v1:
- Added RVB
- typo and format fixes

 man/man2/fanotify_init.2 | 28 ++++++++++++++++++++++++++++
 man/man7/fanotify.7      | 14 ++++++++++++++
 2 files changed, 42 insertions(+)
man/man2/fanotify_init.2 +28 -0
index fa4ae9125..bf573c6fa 100644
@@ -364,6 +364,34 @@ so this restriction may eventually be lifted.
 For more details on information records,
 see
 .BR fanotify (7).
+.TP
+.BR FAN_REPORT_FD_ERROR " (since Linux 6.13 and 6.12.4 and 6.6.66)"
+.\" commit 522249f05c5551aec9ec0ba9b6438f1ec19c138d
+Events for fanotify groups initialized with this flag may contain
+an error code that explains the reason for failure to open a file descriptor.
+The
+.I .fd
+member of the
+.I fanotify_event_metadata
+structure normally contains
+an open file descriptor associated with the object of the event
+or FAN_NOFD in case a file descriptor could not be opened.
+For a group initialized with this flag, instead of FAN_NOFD,
+the
+.I .fd
+member of the
+.I fanotify_event_metadata
+structure will contain a negative error value.
+When the group is also initialized with flag
+.BR FAN_REPORT_PIDFD ,
+in case a process file descriptor could not be opened,
+the
+.I .pidfd
+member of the
+.I fanotify_event_info_pidfd
+structure will also contain a negative error value.
+For more details, see
+.BR fanotify (7).
 .P
 The
 .I event_f_flags
man/man7/fanotify.7 +14 -0
index a532a963a..fd16bf294 100644
@@ -335,6 +335,13 @@ file status flag is set on the open file description.
 This flag suppresses fanotify event generation.
 Hence, when the receiver of the fanotify event accesses the notified file or
 directory using this file descriptor, no additional events will be created.
+.IP
+When an fanotify group is initialized using
+.BR FAN_REPORT_FD_ERROR ,
+this field will contain a negative error value in case a file descriptor
+could not be opened and
+in case of a queue overflow, the value will be
+.BR \-EBADF .
 .TP
 .I pid
 If flag
@@ -679,6 +686,13 @@ Once the event listener has dealt with an event
 and the pidfd is no longer required,
 the pidfd should be closed via
 .BR close (2).
+.IP
+When an fanotify group is initialized using
+.BR FAN_REPORT_FD_ERROR ,
+this field will contain a negative error value
+in case a pidfd creation failure and
+in case of a terminated process, the value will be
+.BR \-ESRCH .
 .P
 The fields of the
 .I fanotify_event_info_error
Signature · 1 line
2.34.1
Signature · 3 lines
<https://www.alejandro-colomar.es/>
<https://www.alejandro-colomar.es:8443/>
<http://www.alejandro-colomar.es:8080/>