Python Forum

Full Version: creating an unlinked invisible file, writing it, then linking it
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
in C on Linux (maybe also on POSIX) i can create a regular file on a specific filesystem that has no link and no inode (it is in memory, not on disk) making it invisible. i can then write() data to this file and even seek to that beginning and read it back. then without yet closing it, i can use linkat() to give it a name (a link) before finally closing it. this is done using O_TMPFILE|O_EXCL on open() as described by "man 2 open" on Linux (at least on Ubuntu).

how can i do this purely in Python3 (on the same platform(s) that i can do it in C)?

edit:

the last two steps in C are linkat() and close().
There is a linkat module in pypi that wraps the C function linkat() through cffi. Now the question is to fill that call with appropriate arguments.
(Feb-21-2023, 06:27 AM)Gribouillis Wrote: [ -> ]There is a linkat module in pypi that wraps the C function linkat() through cffi. Now the question is to fill that call with appropriate arguments.

just follow the way it's done in C. Python3 can do the flags for os.open and file descriptors so the arguments for a binding of linkat() should be easy enough. i'd want to double check the arguments that linkat() is expecting, to be sure.