Next: linux daemonisation, Previous: linux timerfd, Up: linux [Index]
The inotify
API allows us to monitor file system events; for
an overview of the API we must refer to the inotify(7)
manual
page.
Scheme level representation of the C language type struct
inotify-event
, see the inotify(7)
manual page. It has the
following fields:
wd
An exact integer in the range of the C language type int
.
mask
An exact integer in the range of the C language type uint32_t
.
cookie
An exact integer in the range of the C language type uint32_t
.
len
An exact integer in the range of the C language type uint32_t
.
Zero or the number of bytes in the pathname represented by the
name
field.
name
A bytevector representing a file system pathname or #f
.
Build and return a new instance of struct-inotify-event
. When no
arguments are given: all the fields are set to the fixnum zero, but the
field name which is set to #f
.
Return #t
if obj is an instance of
struct-inotify-event
.
Accessors for the fields of struct-inotify-event
.
Mutators for the fields of struct-inotify-event
.
Interface to the C function inotify_init()
, see the manual page
inotify_init(2)
. Initialise a new inotify
instance; if
successful return a file descriptor associated to a new event queue,
else raise an exception.
Interface to the C function inotify_init1()
, see the manual page
inotify_init1(2)
. Initialise a new inotify
instance; if
successful return a file descriptor associated to a new event queue,
else raise an exception.
flags must be a fixnum representing the bitwise inclusive OR
combination of IN_NONBLOCK
and IN_CLOEXEC
.
Interface to the C function inotify_add_watch()
, see the manual
page inotify_add_watch(2)
. Add a watch to an initialised
inotify
instance; if successful return an exact integer
representing watch descriptor, else raise an exception.
fd must be a finxum representing the file descriptor associated to
the inotify
instance. pathname must be a Scheme string or
bytevector representing the pathname to watch. mask must be an
exact integer in the range of the C language type uint32_t
representing the watch mask.
Interface to the C function inotify_rm_watch()
, see the manual
page inotify_rm_watch(2)
. Remove an existing watch from an
inotify
instance; if successful return unspecified values, else
raise an exception.
fd must be a fixnum representing the file descriptor associated to
the inotify
instance. wd must be an exact integer in the
range of the C language type int
representing the watch
descriptor.
The following meaningless example shows how to watch for a modification event on a file:
#!r6rs (import (vicare) (prefix (vicare linux) lx.) (prefix (vicare posix) px.) (vicare platform constants) (vicare language-extensions syntaxes)) (let* ((infd (lx.inotify-init)) (pathname "inotify.test") (fd (px.open pathname (fxior O_CREAT O_EXCL O_RDWR) (fxior S_IRUSR S_IWUSR)))) (unwind-protect (let ((wd (lx.inotify-add-watch infd pathname IN_MODIFY))) (unwind-protect (begin (px.write fd #vu8(1 2 3)) ;; let the event happen (px.select-fd infd 1 0) (let ((ev (lx.inotify-read infd))) (lx.struct-inotify-event? ev) ⇒ #t (= wd (lx.struct-inotify-event-wd ev)) ⇒ #t (lx.struct-inotify-event-len ev) ⇒ 0 (lx.struct-inotify-event-name ev) ⇒ #f )) (lx.inotify-rm-watch infd wd))) (px.close fd) (delete-file pathname)))
Next: linux daemonisation, Previous: linux timerfd, Up: linux [Index]