1616 // ErrCapSysAdmin indicates caller is missing CAP_SYS_ADMIN permissions
1717 ErrCapSysAdmin = errors .New ("require CAP_SYS_ADMIN capability" )
1818 // ErrInvalidFlagCombination indicates the bit/combination of flags are invalid
19- ErrInvalidFlagCombination = errors .New ("invalid flag bits " )
19+ ErrInvalidFlagCombination = errors .New ("invalid flag bitmask " )
2020 // ErrNilListener indicates the listener is nil
2121 ErrNilListener = errors .New ("nil listener" )
2222 // ErrUnsupportedOnKernelVersion indicates the feature/flag is unavailable for the current kernel version
@@ -36,8 +36,8 @@ type Event struct {
3636 // Path holds the name of the parent directory
3737 Path string
3838 // FileName holds the name of the file under the watched parent. The value is only available
39- // when NewListener is created by passing `true` with `withName` argument. The feature is available
40- // only with kernels 5.9 or higher .
39+ // on kernels 5.1 or greater (that support the receipt of events which contain additional information
40+ // about the underlying filesystem object correlated to an event) .
4141 FileName string
4242 // EventTypes holds bit mask representing the operations
4343 EventTypes EventType
@@ -46,7 +46,7 @@ type Event struct {
4646}
4747
4848// Listener represents a fanotify notification group that holds a list of files,
49- // directories and filesystems under a given mountpoint for which events shall be created.
49+ // directories or a mountpoint for which events shall be created.
5050type Listener struct {
5151 // fd returned by fanotify_init
5252 fd int
@@ -73,13 +73,13 @@ type Listener struct {
7373// For cases where multiple mountpoints need to be monitored
7474// multiple listener instances need to be used.
7575//
76- // mountpoint can be any file/directory under the mount point being watched.
77- // Passing "true" to the entireMount flag monitors the entire mount point for marked
76+ // mountPoint can be any file/directory under the mount point being watched.
77+ // Passing "true" to the entireMount parameter monitors the entire mount point for marked
7878// events. Passing "false" allows specifying multiple paths (files/directories)
7979// under this mount point for monitoring filesystem events.
8080//
8181// The function returns a new instance of the listener. The fanotify flags are set
82- // based on the running kernel version. ErrCapSysAdmin is returned if the process does not
82+ // based on the running kernel version. [ ErrCapSysAdmin] is returned if the process does not
8383// have CAP_SYS_ADM capability.
8484//
8585// - For Linux kernel version 5.0 and earlier no additional information about the underlying filesystem object is available.
@@ -146,13 +146,12 @@ func (l *Listener) Stop() {
146146 close (l .Events )
147147}
148148
149- // MarkMount adds, modifies or removes the fanotify mark (passed in as eventTypes) for the entire
150- // mountpoint . Passing true to remove, removes the mark from the mountpoint .
149+ // MarkMount adds, modifies or removes the fanotify mark (eventTypes) for the entire
150+ // mount point . Passing true to remove, removes the mark from the mount point .
151151// This method returns an [ErrWatchPath] if the listener was not initialized to monitor
152- // the entire mountpoint . To mark specific files or directories use [AddWatch] method.
152+ // the entire mount point . To mark specific files or directories use [AddWatch] method.
153153// The entire mount cannot be monitored for the following events:
154- // [FileCreated], [FileAttribChanged], [FileMovedFrom],
155- // [FileMovedTo], [WatchedFileDeleted]
154+ // [FileCreated], [FileAttribChanged], [FileMovedFrom], [FileMovedTo], [WatchedFileDeleted]
156155// Passing any of these flags in eventTypes will return [ErrInvalidFlagCombination] error
157156func (l * Listener ) MarkMount (eventTypes EventType , remove bool ) error {
158157 if l .entireMount == false {
@@ -174,9 +173,9 @@ func (l *Listener) MarkMount(eventTypes EventType, remove bool) error {
174173// AddWatch adds or modifies the fanotify mark for the specified path.
175174// The events are only raised for the specified directory and does raise events
176175// for subdirectories. Calling AddWatch to mark the entire mountpoint results in
177- // [os.ErrInvalid]. To mark the entire mountpoint use [MarkMount] method.
176+ // [os.ErrInvalid]. To mark the entire mount point use [MarkMount] method.
178177// Certain flag combinations are known to cause issues.
179- // - [FileCreated] cannot be or-ed / combined with FileClosed. The fanotify system does not generate any event for this combination.
178+ // - [FileCreated] cannot be or-ed / combined with [ FileClosed] . The fanotify system does not generate any event for this combination.
180179// - [FileOpened] with any of the event types containing OrDirectory causes an event flood for the directory and then stopping raising any events at all.
181180// - [FileOrDirectoryOpened] with any of the other event types causes an event flood for the directory and then stopping raising any events at all.
182181func (l * Listener ) AddWatch (path string , eventTypes EventType ) error {
@@ -187,8 +186,8 @@ func (l *Listener) AddWatch(path string, eventTypes EventType) error {
187186}
188187
189188// DeleteWatch removes or modifies the fanotify mark for the specified path.
190- // Calling DeleteWatch on the listener initialized to monitor the entire mountpoint
191- // results in [os.ErrInvalid]. To modify the mark for the entire mountpoint use [MarkMount] method.
189+ // Calling DeleteWatch on the listener initialized to monitor the entire mount point
190+ // results in [os.ErrInvalid]. To modify the mark for the entire mount point use [MarkMount] method.
192191func (l * Listener ) DeleteWatch (parentDir string , eventTypes EventType ) error {
193192 if l .entireMount {
194193 return os .ErrInvalid
@@ -208,18 +207,18 @@ func (l *Listener) ClearWatch() error {
208207 return nil
209208}
210209
211- // Has returns true if event types contains the passed in event type (et).
212- func (eventTypes EventType ) Has (et EventType ) bool {
213- return eventTypes & et == et
210+ // Has returns true if event types (e) contains the passed in event type (et).
211+ func (e EventType ) Has (et EventType ) bool {
212+ return e & et == et
214213}
215214
216215// Or appends the specified event types to the set of event types to watch for
217- func (eventTypes EventType ) Or (et EventType ) EventType {
218- return eventTypes | et
216+ func (e EventType ) Or (et EventType ) EventType {
217+ return e | et
219218}
220219
221220// String prints event types
222- func (a EventType ) String () string {
221+ func (e EventType ) String () string {
223222 var eventTypes = map [EventType ]string {
224223 unix .FAN_ACCESS : "Access" ,
225224 unix .FAN_MODIFY : "Modify" ,
@@ -237,7 +236,7 @@ func (a EventType) String() string {
237236 }
238237 var eventTypeList []string
239238 for k , v := range eventTypes {
240- if a .Has (k ) {
239+ if e .Has (k ) {
241240 eventTypeList = append (eventTypeList , v )
242241 }
243242 }
0 commit comments