Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inotify C headers

So I'm trying to write a C program that uses inotify. I've used pyinotify before so I understand how it works. However, I'm following some guide and it tells me to include <linux/inotify.h>. The problem is that this header only has macro definitions, not the funciton prototypes. It looks like the functions are prototyped in <sys/inotify.h>.

My question is what's the difference between linux/inotify.h and sys/inotify.h? Why are there both?

like image 808
Falmarri Avatar asked Dec 12 '10 07:12

Falmarri


People also ask

How does inotify work?

With Inotify, anti-virus detectors re-scan the file system for modified files to detect if any malicious intrusions have occurred. This kind of applications use a user-space device through which Inotify events are triggered between the kernel and user-space applications.

What is inotify used for?

DESCRIPTION top. The inotify API provides a mechanism for monitoring filesystem events. Inotify can be used to monitor individual files, or to monitor directories. When a directory is monitored, inotify will return events for the directory itself, and for files inside the directory.

What is inotify file descriptor?

Introducing inotify 13 kernel, Linux has included inotify, which allows a monitoring program to open a single file descriptor and watch one or more files or directories for a specified set of events, such as open, close, move/rename, delete, create or change attributes.

What is inotify watches?

Inotify Watch helps to keep track of the file changes under the directories on "watch" and report back to the application in a standard format using the API calls. We can monitor multiple file events under the watched directory using the API calls.


1 Answers

sys/inotify.h is part of the GNU C library. It exposes the structures and functions that your program will use in order to receive filesystem change notifications. It can be considered as the public API of the notification system.

linux/inotify.h is part of the Linux kernel. It defines the kernel structures and constants used to implement the notification system itself. You shouldn't include that file unless you're writing something like a kernel module, because it's Linux-specific and thus not portable.

like image 195
Frédéric Hamidi Avatar answered Sep 21 '22 18:09

Frédéric Hamidi