Python Forum
creating an unlinked invisible file, writing it, then linking it
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
creating an unlinked invisible file, writing it, then linking it
#1
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().
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
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.
Reply
#3
(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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  invisible temporary files that become linked permanent Skaperen 0 938 Feb-21-2023, 12:22 AM
Last Post: Skaperen
  reading and writing a image stored in a file Skaperen 4 2,250 Feb-12-2022, 04:03 AM
Last Post: Skaperen
  creating my own file-like object Skaperen 0 1,195 Feb-06-2022, 08:25 PM
Last Post: Skaperen
  creating a dummy file object Skaperen 1 1,944 Oct-27-2021, 07:50 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020