Function inotify::get_buffer_size

source ·
pub fn get_buffer_size(path: &Path) -> Result<usize>
Expand description

Get the inotify event buffer size

The maximum size of an inotify event and thus the buffer size to hold it can be calculated using this formula: sizeof(struct inotify_event) + NAME_MAX + 1

See: https://man7.org/linux/man-pages/man7/inotify.7.html

The NAME_MAX size formula is: ABSOLUTE_PARENT_PATH_LEN + 1 + 255

  • ABSOLUTE_PARENT_PATH_LEN will be calculated at runtime.
  • Add 1 to account for a /, either in between the parent path and a filename or for the root directory.
  • Add the maximum number of chars in a filename, 255.

See: https://github.com/torvalds/linux/blob/master/include/uapi/linux/limits.h

Unfortunately, we can’t just do the same with max path length itself.

See: https://eklitzke.org/path-max-is-tricky

This function is really just a fallible wrapper around get_absolute_path_buffer_size().

path: A relative or absolute path for the inotify events.