ext4 has a
max_dir_size_kb mount option to limit the size of directories, but no similar option for regular files.
A process however can be prevented from creating a file bigger than a limit using limits as set by
setrlimit() or the
limit builtin of some shells. Most systems will also let you set those limits system-wide, per user.
When a process exceeds that limit, it receives a SIGXFSZ signal. And when it ignores that signal, the operation that would have caused that file size to be exceeded (like a
truncate() system call) fails with a
To move that limit to the file system, one trick you could do is use a fuse (file system in user space) file system, where the user space handler is started with that limit set.
bindfs is a good candidate for that.
If you run
bindfs dir dir (that is bind
dir over itself), with
bindfs started as (
(limit filesize 1M; trap '' XFSZ; bindfs dir dir)
Then any attempt to create a file bigger than 1M in that dir will fail.
bindfs forwards the
EFBIG error to the process writing the file.
Note that that limit only applies to regular files, that won't stop directories to grow past that limit (for instance by creating a large number of files in them).