From: James Hunt <james.hunt-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH] Explain how to read a single inotify event.
Date: Tue, 06 Dec 2011 09:40:53 +0000 [thread overview]
Message-ID: <4EDDE325.2080203@ubuntu.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 147 bytes --]
man7/inotify.7:
- Explain how to read a single inotify event.
- Add missing "struct" in explanation of event size.
Kind regards,
--
James Hunt
[-- Attachment #2: 0001-Explain-how-to-read-a-single-inotify-event.patch --]
[-- Type: text/x-diff, Size: 1787 bytes --]
>From 2c2e9150661fc12142725f97e3cebf8ff64e1264 Mon Sep 17 00:00:00 2001
From: James Hunt <james.hunt-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
Date: Tue, 6 Dec 2011 09:33:51 +0000
Subject: Explain how to read a single inotify event.
Also added missing "struct" to sizeof().
---
man7/inotify.7 | 24 +++++++++++++++++++++++-
1 files changed, 23 insertions(+), 1 deletions(-)
diff --git a/man7/inotify.7 b/man7/inotify.7
index ddeb5e5..742dec2 100644
--- a/man7/inotify.7
+++ b/man7/inotify.7
@@ -144,7 +144,7 @@ including the null bytes;
the length of each
.I inotify_event
structure is thus
-.IR "sizeof(inotify_event)+len" .
+.IR "sizeof(struct inotify_event)+len" .
The behavior when the buffer given to
.BR read (2)
@@ -417,6 +417,28 @@ be aware that by the time you create a watch for the new subdirectory,
new files may already have been created in the subdirectory.
Therefore, you may want to scan the contents of the subdirectory
immediately after adding the watch.
+
+To read a
+.B single
+event requires the buffer provided to
+.BR read (2)
+be large enough to hold the event. However, since inotify employs
+variable-length events for files in a watched directory (via the
+.I name
+field), it is not possible to know exactly how big such a
+buffer should be since the event itself has not yet been read. One
+method to overcome this limitation is to start with a buffer of size
+.I sizeof(struct inotify_event)
+and attempt to read the event. If this fails with
+.BR EINVAL ","
+continue to increase the buffer size by one byte up to
+.I "sizeof(struct inotify_event)+NAME_MAX"
+until
+.BR read (2)
+does not return
+.BR EINVAL "."
+Note that this technique is not particularly efficient.
+
.SH "BUGS"
In kernels before 2.6.16, the
.B IN_ONESHOT
--
1.7.5.4
next reply other threads:[~2011-12-06 9:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-06 9:40 James Hunt [this message]
[not found] ` <4EDDE325.2080203-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
2012-04-23 21:43 ` [PATCH] Explain how to read a single inotify event Michael Kerrisk (man-pages)
[not found] ` <CAKgNAkgB3_SUsnH0-c8X6Lute8amtEkw0VtrsCqFGWn+c4yfQA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-04-24 18:11 ` Eric Wong
[not found] ` <20120424181112.GA1458-yBiyF41qdooeIZ0/mPfg9Q@public.gmane.org>
2012-04-24 23:11 ` Michael Kerrisk (man-pages)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4EDDE325.2080203@ubuntu.com \
--to=james.hunt-gewih/nmzzlqt0dzr+alfa@public.gmane.org \
--cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.