Re: [RFC] "final" flag for a directory
Laurent Lyaudet <[email protected]>
| Newsgroups | org.kernel.vger.linux-btrfs,org.kernel.vger.linux-fsdevel |
|---|---|
| Message-ID | <CAB1LBmvFnJz-Gx4xncyGUhztKs6r=JP0i0qFXurxba-+ZaVo7Q@mail.gmail.com> |
Hello, Thanks for your reply. Le mar. 18 août 2026 à 14:14, David Sterba <[email protected]> a écrit : > > On Mon, Aug 17, 2026 at 04:26:31PM +0200, Laurent Lyaudet wrote: > > I had an idea about adding a boolean flag "final" on directories in an > > advanced filesystem. > > In the same way, the "final" keyword on a class in OOP can be added to > > declare no subclass can exist, > > the "final" boolean flag on a directory could be added to say that the > > directory has no/must not have any subdirectory. > > Do you have an existing use case for that? Yes, I have two use cases : - For directories that are used for "technical" reasons. It is very frequent for cache subdirectories to be final. You add a cache subdirectory (for example in /tmp), and it's meant to receive a lot of small files. If you look also at the directories used in a DBMS like PostgreSQL, you will also see a lot of final directories. Etc. The examples are numerous. - For directories that are created manually by users, there are usually many more final directories. The depth of folders in the home of most users is kept low most of the time. In fact, it could be a feature that all folders that are created under /home/@somelogin@/ and that are not under some hidden directory like .config have a (sticky/recursive) flag "auto_must_be final". So far it means 4 boolean flags, if I add the one you suggest below: > > > So here we see that 2 flags could be added: > > - a configuration flag "must_be_final" forbidding to create a subdirectory, > > I see two possible semantics of that: > > - final, no subdirectories exist and new ones cannot be created > - no new subdirectories can be created, but some may exist > or one enum of 3 values on 2 bits, and 2 other boolean flags: 1. "must_be_final" and "no_new_subdirectory_can_be_created" (pseudo_final), 2. "auto_must_be final" -> flag/enum 1. has been set automatically or manually 3. "is_final" And when the user creates a folder in some Window environment like Gnome or KDE under its home directory, then Nautilus for example would set "must_be_final" with "auto_must_be final". If the user then goes in the properties of the folder, he could unset both or switch "auto_must_be final" to "manual_must_be final". Then when the user tries to create a subdirectory in this directory, if the current directory is "auto_must_be final", then "must_be_final" and "auto_must_be final" are both unset without any user action on top of creating a subdirectory. But if the user tries to create a directory when "must_be_final" and "manual_must_be final" are set, then Nautilus pops up a warning with confirmation required. > Also given how other attributes behave once set they can be unset. This > is up to the user, and possibly a restricted operation. > > > - a status flag "is_final" telling that no subdirectory currently exists. > > When the filesystem tracks the number of subdirectories already, then > it's an easy check. Otherwise a full search must be done, atomically wrt > creating new subdirectories. > I agree that a count on subdirectories is a better statistic. I think there should be both data: - a subdirectories count when the filesystem agrees to keep such statistics (along with files count, symlink counts, etc. this could be a whole other RFC) - a "is_final" flag for wider adoption and precise cases of optimization. So, if we look at the configuration status of a folder, we have an enum: - must_be_final_manual, - must_be_final_auto, - must_be_pseudo_final_manual, - must_be_pseudo_final_auto, - no_subdirectories restriction with final => pseudo_final With flags : F must_be_final P must_be_pseudo_final A/M 0 auto, 1 manual I is_final is_pseudo_final is always true, and brings nothing without a precise subdirectories count F P A/M I - must_be_final_manual, 1 1 1 1 - must_be_final_auto, 1 1 0 1 - must_be_pseudo_final_manual, 0 1 1 0 or 1 - must_be_pseudo_final_auto, 0 1 0 0 or 1 - no_subdirectories restriction 0 0 0 0 or 1 Already 8 combinations of flags have precise meaning. The following combinations are invalid: F P A I 1 1 1 0 1 1 0 0 1 0 1 1 1 0 1 0 1 0 0 1 1 0 0 0 0 0 1 1 0 0 1 0 And there are no other combinations left. Have a nice day, best regards, Laurent Lyaudet