Have you considered using extended file attributes for metadata? Extended
attributes exist exactly for this kind of use case.
With xattrs, renaming a file would move its metadata with it. A separate
metadata file cannot be moved in the same operation as the original file, so in
case of a system crash, the metadata will be orphaned and the moved item will
lose its metadata (e.g.: flags).
Handling over a file descriptor for a message from one process to another
allows the second process to read/write metadata with fgetxattr/sgetxattr,
rather than requiring an additional fd for flags.
There's a precedent of this approach in Haiku's email program, which uses
extended attributes for message metadata:
https://www.haiku-os.org/docs/userguide/en/workshop-email.html
Curious to hear your thoughts.
Cheers,
--
Hugo