Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
== inotify [[toc:]] === Introduction This egg provides a nearly complete set of bindings to the Linux inotify API for watching file events. The authoritative source on its behavior is [[http://man7.org/linux/man-pages/man7/inotify.7.html|inotify(7)]]. === Author Vasilij Schneidermann === Repository [[https://depp.brause.cc/inotify]] === Current state of the bindings * Every inotify function except {{inotify_init1}} is covered * The low-level API provides the absolute basics for watching files. It is intended to be used by library authors who want to incorporate file watching into their egg. All API calls require a {{FD}} argument. * The high-level API stores the user instance file descriptor in a parameter and provides further convenience procedures. It is intended to be used by application authors. === Requirements This library requires a sufficiently recent Linux kernel, but has been tested on Linux 4.8.13 only. Please report any incompatibilities you run into with older Linux versions. === Common API ==== Events <procedure>(event? X)</procedure> <procedure>(event-wd EVENT)</procedure> <procedure>(event-flags EVENT)</procedure> <procedure>(event-cookie EVENT)</procedure> <procedure>(event-name EVENT)</procedure> Event predicate and accessors for event records. An event has a watch descriptor for associating it with a watch, a list of flags associated with the event, a cookie that is set for {{rename}} events to allow connecting the old and new file name and a name that is set for file events inside a watched directory. The event flag list consists of at least one of the following symbols: * {{access}} * {{attrib}} * {{close-write}} * {{close-nowrite}} * {{create}} * {{delete}} * {{delete-self}} * {{ignore}} * {{isdir}} * {{modify}} * {{move-self}} * {{moved-from}} * {{moved-to}} * {{open}} * {{q-overflow}} * {{unmount}} === Low-level API ==== Setup and Teardown <procedure>(%init!)</procedure> Initializes an user instance and returns its file descriptor. <procedure>(%clean-up! FD)</procedure> Frees the user instance associated with {{FD}} and all associated watches. ==== Watches <procedure>(%add-watch! FD PATH FLAGS)</procedure> Adds a watch for {{PATH}} which must be an absolute or relative path pointing to a file or directory. {{FLAGS}} is a list of at least one symbol describing the events one is interested in. Returns a watch descriptor associated with the watch. The event flag list consists of at least one of the following event type symbols: * {{access}} * {{attrib}} * {{close-write}} * {{close-nowrite}} * {{create}} * {{delete}} * {{delete-self}} * {{modify}} * {{move-self}} * {{moved-from}} * {{moved-to}} * {{open}} Further convenience flags: * {{move}} (equivalent to {{(moved-from moved-to)}}) * {{close}} (equivalent to {{(close-write close-nowrite)}}) * {{all-events}} (catches all event types) Further options: * {{dont-follow}} * {{excl-unlink}} * {{mask-add}} * {{oneshot}} * {{onlydir}} <procedure>(%remove-watch! FD WD)</procedure> Removes a watch as identified by the given watch descriptor {{WD}}. ==== Events <procedure>(%next-events! FD)</procedure> Blocks the current thread to wait for events and returns a list of at least one event record. Note that calling this procedure does ''not'' block other SRFI-18 threads. In other words, it is possible to have a background thread reacting to file events while other threads proceed normally. === High-level API ==== Setup and Teardown <procedure>(init!)</procedure> Initializes an user instance, returning {{#t}} when successful and {{#f}} if it has been initialized before. This procedure must be called before manipulating watches and fetching events. <procedure>(clean-up!)</procedure> Frees the user instance and all associated watches, returning {{#t}} when successful and {{#f}} on subsequent attempts. <parameter>(%fd)</parameter> <parameter>(%fd FD)</parameter> Parameter holding the user instance file descriptor. You shouldn't need to mess with this unless you insist on using more than one user instance for watching events. ==== Watches <procedure>(add-watch! PATH FLAGS)</procedure> Adds a watch for {{PATH}} which must be an absolute or relative path pointing to a file or directory. {{FLAGS}} is a list of at least one symbol describing the events one is interested in. Returns a watch descriptor associated with the watch. The event flag list consists of at least one of the following event type symbols: * {{access}} * {{attrib}} * {{close-write}} * {{close-nowrite}} * {{create}} * {{delete}} * {{delete-self}} * {{modify}} * {{move-self}} * {{moved-from}} * {{moved-to}} * {{open}} Further convenience flags: * {{move}} (equivalent to {{(moved-from moved-to)}}) * {{close}} (equivalent to {{(close-write close-nowrite)}}) * {{all-events}} (catches all event types) Further options: * {{dont-follow}} * {{excl-unlink}} * {{mask-add}} * {{oneshot}} * {{onlydir}} <procedure>(remove-watch! WD)</procedure> Removes a watch as identified by the given watch descriptor {{WD}}. <procedure>(add-watch-recursively! PATH FLAGS)</procedure> Adds a watch for {{PATH}} and traverses it recursively to add watches for any directories found in it. Each watch is applied with {{FLAGS}}, refer to the documentation of {{add-watch!}} for further details. Returns a list of watch descriptors associated with each established watch. Note that this procedure does ''not'' work in an atomic manner, it cannot be guaranteed that all directories in {{PATH}} will receive watches. <procedure>(wd->path WD)</procedure> Returns the path the watch associated with {{WD}} was created with. <procedure>(wd-list)</procedure> Returns a list of all known watch descriptors. <procedure>(path-list)</procedure> Returns a list of all watched paths. ==== Events <procedure>(next-events!)</procedure> Blocks the current thread to wait for events and returns a list of at least one event record. Note that calling this procedure does ''not'' block other SRFI-18 threads. In other words, it is possible to have a background thread reacting to file events while other threads proceed normally. <parameter>(%events)</parameter> <procedure>(next-event!)</procedure> Convenience procedure for fetching one event at a time. This calls {{next-events!}} internally for filling up an event queue and returns one event from it. The event queue itself is available under {{%events}} and can be manipulated with the queue procedures from the {{data-structures}} unit. <procedure>(event->pathname EVENT)</procedure> Convenience procedure for reconstructing the full path name from an event. ==== /proc Interface <procedure>(max-queued-events)</procedure> <procedure>(max-user-instances)</procedure> <procedure>(max-user-watches)</procedure> Convenience procedures for querying usage limits from {{/proc/sys/fs/inotify}}. === Examples <enscript highlight="scheme"> (import inotify) (init!) (on-exit clean-up!) (add-watch! "." '(all-events)) (let loop () (print (next-event!)) (loop)) </enscript> More realistic examples can be found [[https://depp.brause.cc/inotify/examples/fallkiste.scm|in the repository]]. === License Copyright (c) 2017, Vasilij Schneidermann Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. === Version History ==== 1.2 * Declare egg as Linux-only ==== 1.1 * Make examples easier to build ==== 1.0 * C5 port ==== 0.3 * Fix packaging mistake ==== 0.2 * Split up the API into a low-level and high-level one * Incorporated some feedback about the C code (thanks, florz!) * Added one more example ==== 0.1 * Initial release
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you add 17 to 21?