https://github.com/opcoder0/fanotify
Fanotify API for Go
https://github.com/opcoder0/fanotify
fanotify filesystem-events filesystem-monitoring filesystemwatcher golang linux
Last synced: about 1 year ago
JSON representation
Fanotify API for Go
- Host: GitHub
- URL: https://github.com/opcoder0/fanotify
- Owner: opcoder0
- License: mit
- Created: 2022-11-29T01:34:15.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-03T01:56:12.000Z (almost 3 years ago)
- Last Synced: 2025-03-25T02:48:57.143Z (over 1 year ago)
- Topics: fanotify, filesystem-events, filesystem-monitoring, filesystemwatcher, golang, linux
- Language: Go
- Homepage:
- Size: 92.8 KB
- Stars: 11
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fanotify Library

Fanotify library provides a simple API to monitor filesystem for events.
The listener is initialized with flags automatically based on the kernel version. The mark flag features that specify the
the events to monitor a file/directory are validated and checked for valid combinations and validated against the kernel
version.
fanotify has features spanning different kernel versions -
- For Linux kernel version 5.0 and earlier no additional information about the underlying filesystem object is available.
- For Linux kernel versions 5.1 - 5.8 additional information about the underlying filesystem object is correlated to an event.
- For Linux kernel version 5.9 or later the modified file name is made available in the event.
## Examples
Example code for different use-cases can be found here https://github.com/opcoder0/fanotify-examples
## Known Issues
Certain flag combinations / event types cause issues with event reporting.
- `fanotify.FileCreated` cannot be or-ed / combined with `fanotify.FileClosed`. The `fanotify` event notification group does not generate any event for this combination.
- Using `fanotify.FileOpened` with any of the event types containing `OrDirectory` causes numerous duplicate events for the path.
- `fanotifyFileOrDirectoryOpened` with any of the other event types causes numerous duplicate events for the path.
## Tests
Running tests require `CAP_SYS_ADM` privilege. To run the tests make sure to add `go` to the `sudo` PATH.
The command runs all the tests except the ones that test the flag bugs mentioned in the "Known Issues" section above -
```
sudo go test -v
```
To run the tests with flag issues -
```
sudo go test -v -bug
```