LIBINOTIFY(3)
π¦ LIBINOTIFY(3) π¦
okay bestie, this is the Library Functions Manual page for libinotify, and the vibe is literally βmonitor file system events.β no cap. β¨
π NAME π
libinotify, inotify_init, inotify_init1, inotify_add_watch, inotify_rm_watch, libinotify_set_param, inotify_event, libinotify_direct_readv, libinotify_free_iovec, libinotify_direct_close β monitor file system events π
β¨ SYNOPSIS β¨
#include <sys/inotify.h>
int
inotify_init();
int
inotify_init1(int flags);
int
inotify_add_watch(int fd, const char *pathname, uint32_t mask);
int
inotify_rm_watch(int fd, int wd);
int
libinotify_set_param(int fd, int param, intptr_t value);
int
libinotify_direct_readv(int fd, struct iovec **events, int size,
int no_block);
void
libinotify_free_iovec(struct iovec *events);
int
libinotify_direct_close(int fd);
π DESCRIPTION π
inotify_init() and inotify_init1() create an inotify instance and return a file descriptor referring to the instance. inotify_init1() is similar to inotify_init() except it takes an additional flags parameter, and the values can be:
IN_NONBLOCKβ SetI_NONBLOCKfile status flag on the inotify file descriptor.IN_CLOSEXECβ SetFD_CLOEXECflag on the new file descriptor. See theO_CLOEXECflag inopen(2).IN_DIRECTβ libinotify-specific flag that enables direct mode (see below).
The function returns the file descriptor to the inotify handle if successful, otherwise it returns -1. Possible errno values are:
EINVALβ Invalid flag value passed.EMFILEβ System wide limit of inotify instances reached.ENFILEβ System limit on total number of fd's reached.ENOMEMβ Insufficient kernel memory.
inotify_add_watch() adds a new watch to the inotify instance. The list of possible masks is described below. If the watch for the given filename already exists, it gets updated with the new mask value passed. The function returns an integer called a watch descriptor if successful, otherwise -1.
Possible errno values are:
EACCESβ Permission for read access is denied for given file.EBADFβ Invalid file descriptor.EFAULTβ Pathname points outside process's allocated address space.EINVALβ Invalid event mask passed.ENOENTβ A component of path that must exist does not exist.ENOMEMβ Insufficient kernel memory available.ENOSPCβ User limit on total number of inotify watches has crossed or kernel failed to allocate a needed resource.
inotify_rm_watch() removes watch wd from the instance described by file descriptor fd. The function returns zero on success and -1 on error. Possible errno values are:
EBADFβ Invalid file descriptorfd.EINVALβ Invalid watch descriptorwd.
libinotify_set_param() is libinotify-specific. Replacement for the Linux procfs interface. Set an inotify parameter for the instance described by file descriptor fd. An fd value of -1 is used for setting global parameters. Possible param values are:
IN_SOCKBUFSIZEβ Size of communication socket buffer in bytes. Should matchread(2)buffer size for libinotify event consumers. Lower values can cause partial event reads. Bigger values are just wasting memory. Default value is arbitrary, has been acquired from the code sample in the Linuxinotify(7)man page and seems to be very common among inotify clients. Default value4096(exported asIN_DEF_SOCKBUFSIZE).IN_MAX_QUEUED_EVENTSβ Upper limit on the queue length per inotify handle. Linux's/proc/sys/fs/inotify/max_queued_eventscounterpart. Default value16384(exported asIN_DEF_MAX_QUEUED_EVENTS).IN_MAX_USER_INSTANCESβ Global upper limit on the number of inotify instances that can be created. Linux's/proc/sys/fs/inotify/max_user_instancescounterpart. Default value2147483646(exported asIN_DEF_MAX_USER_INSTANCES).
π§ inotify_event structure π§
struct inotify_event {
int wd; /* Watch descriptor */
uint32_t mask; /* Mask of events */
uint32_t cookie; /* Unique integer associating related events */
uint32_t len; /* Size of name field */
char name[]; /* Optional null-terminated name */
};
π inotify events β π
These are the masks supported by the libinotify implementation:
IN_OPENβ File was opened.IN_ACCESSβ File was accessed (read).IN_ATTRIBβ Metadata changed.IN_CREATEβ File/directory was created in watched directory.IN_CLOSE_WRITEβ File opened for writing was closed.IN_CLOSE_NOWRITEβ File not opened for writing was closed.IN_DELETEβ File/directory in watched directory was deleted.IN_DELETE_SELFβ Watched file/directory was deleted.IN_MODIFYβ File/Directory was modified.IN_MOVE_SELFβ Watched file/directory was moved.IN_MOVED_FROMβ A file in watched directory was moved out.IN_MOVED_TOβ A file was moved into watched directory.IN_ALL_EVENTSβ Bit mask of all the above events.IN_MOVEβ Equal toIN_MOVED_FROM|IN_MOVED_TO.IN_CLOSEβ Equal toIN_CLOSE_WRITE|IN_CLOSE_NOWRITE.
IN_DELETE_SELF and IN_MOVE_SELF can occur only for a watched file/directory. Other events can be marked for a file/directory in a watched directory. In that case, the name of the file for which the event is generated can be read by the name field in the inotify_event structure.
π«Ά extra bits you can set in mask when calling inotify_add_watch() π«Ά
IN_DONT_FOLLOWβ Don't dereference the path name if it's a symlink.IN_EXCL_UNLINKβ Do not generate events for unlinked children. (Currently not supported).IN_MASK_ADDβ Add event mask for watch for given pathname.IN_ONESHOTβ Remove watch after retrieving one event.IN_ONLYDIRβ Only watch the pathname if it is a directory.
πΈ bits that may be set by the mask field returned by read(3) πΈ
IN_IGNOREDβ Watch was removed (explicitly, revoked, or unmounted).IN_ISDIRβ Subject of this event is a directory.IN_Q_OVERFLOWβ Event queue has overflowed.IN_UNMOUNTβ File system containing watched file/directory was unmounted.
π DIRECT MODE π
In this mode, the fd handed over to the user isn't a read()able one, but is actually a kqueue fd. This allows reducing some copying overhead at the cost of being incompatible with how the Linux inotify fd works. The mode is activated by passing IN_DIRECT to inotify_init1().
libinotify_direct_readv() is a replacement for the read call in direct mode. Pass it an array of struct iovec* of desired size to fill it with lists of events. Each struct iovec* points to an array of structs terminated with a null iovec (iov_base = NULL). It is the caller responsibility to free these arrays.
libinotify_free_iovec() frees a list of iovec structs returned by the previous call.
libinotify_direct_close() is a replacement for the close call in direct mode.
π SEE ALSO π
π HISTORY π
inotify first appeared in Linux 2.6.13.
okay that's the whole page, bestie π brought to you by Debian, dated July 22, 2024, and officially titled LIBINOTIFY(3). mwah πβ¨
π¦ where this page comes from
- nixpkgs unstable: libinotify-kqueue 20240724
- Copyright (c) 2012 Vishesh Yadav
- Copyright (c) 2017 Vladimr Kondratyev
- Copyright (c) 2024 Serenity Cyber Security, LLC
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms