revk,
@revk@toot.me.uk avatar
penguin42,
@penguin42@mastodon.org.uk avatar

@revk @torvalds Hmm does this already exist? I see in the flags for open(2) there's 'O_TMPFILE' - 'The pathname argument specifies a directory; an unnamed inode will be created in that directory's filesystem. Anything written to the resulting file will be lost when the last file descriptor is closed, unless the file is given a name.......linkat(2) can be used to link the temporary file into the filesystem, making it permanent,

penguin42,
@penguin42@mastodon.org.uk avatar

@revk @torvalds Also, don't underestimate how much of a true PITA the unnamed file stuff is on network filesystems; good luck with NFS .nfs* files

phlash,
@phlash@mastodon.me.uk avatar

@penguin42 @revk @torvalds
Close but no cigar I think - in order to use O_TMPFILE then linkat() to /replace/ an existing file, the existing directory entry needs to be unlink()'d which makes this a non-atomic replacement. Might be enough for RevK's purpose though (avoiding half-baked files).

Geoff,

@phlash @penguin42 @revk @torvalds there have been several discussions about a replace flag for linkat, not sure how far they got tho.

Eg https://lwn.net/Articles/810848/

penguin42,
@penguin42@mastodon.org.uk avatar

@phlash @revk @torvalds Hmm adding a flag to allow replace to linkat() would seem a fairly small extension then?

revk,
@revk@toot.me.uk avatar

@penguin42 @phlash @torvalds hmm, that is a pain, yes, linkat() allowing a replace makes sense. Bugger. So close.

mal3aby,

@revk @penguin42 @phlash It does at least make things a little better: it means you can make the critical window (where, if you crash, you leave a temporary file lying around) tiny - by creating the directory entry then immediately rename it into place - rather than the winow including the entire time taken to generate the file's content.

kitten_tech,
@kitten_tech@fosstodon.org avatar

@revk @torvalds you could do that with an fd-based (like fchmod instead od chmod) rename, perhaps? Create the file alongside the existing one with a .tmp suffix, immediately unlink, write at your leisure, then "rename" from the fd to the name. And that frename operation might be useful for other things too! Of course, it would be even better if there's a "create unlinked file on same filesystem as specified file, without even temporarily giving it a name" operation too...

kitten_tech,
@kitten_tech@fosstodon.org avatar

@revk @torvalds Huh, today I learned about linkat(2)!

f4grx,
@f4grx@chaos.social avatar

@kitten_tech @revk @torvalds there's a full collection of them, openat for example.

revk,
@revk@toot.me.uk avatar

@f4grx @kitten_tech @torvalds yeh, if renameat2() could do the file fd as old filename, that would work.

revk,
@revk@toot.me.uk avatar

@kitten_tech @torvalds yeh, I never knew of all the new …at() calls.

kitten_tech,
@kitten_tech@fosstodon.org avatar

@revk @torvalds I went and looked for an frename() in the spirit of fchmod(), believing the ...at() calls to all he about using an arbitrary directory fd as the cwd in order to support per-thread effective cwds, because that's what the man page said they were for...

revk,
@revk@toot.me.uk avatar

@kitten_tech @torvalds indeed, the use of a file not a directory and an empty path is clearly a total bodge. Messy at best.

FenTiger,
@FenTiger@mastodon.social avatar

@revk If I were to redesign from scratch, the actions of creating a file and adding it to a directory would be separate operations.

First you'd create the file, which would give you a FD referring to it. This would be the only reference to the file - just as you get today if you first create and then unlink a file.

Then you'd write to it.

Finally you'd add it to its containing directory, under the name you want it to have - atomically replacing any existing file which had that name.

revk,
@revk@toot.me.uk avatar

@FenTiger Yeh, making the directory on close of file makes a lot of sense.

ids1024,
@ids1024@fosstodon.org avatar

@FenTiger @revk open(2) suggests you can already do something like this, on Linux. O_TMPFILE "creates an unnamed temporary file", and says it can be made permanent with linkat. Which presumably would be atomic in exactly the way you suggest.

O_TMPFILE requires a directory so it knows what filesystem to create an inode on.

FenTiger,
@FenTiger@mastodon.social avatar

@ids1024 @revk That is more or less exactly how I envisioned it working.

Damn. Once again I have invented something that turns out to already exist. Story of my life... ;)

ids1024,
@ids1024@fosstodon.org avatar

@FenTiger @revk Of course if you want to write portable software, you don't get to use any of the cool APIs like this. Or need a fallback. (FreeBSD also has some neat APIs Linux doesn't have.)

revk, (edited )
@revk@toot.me.uk avatar

@ids1024 @FenTiger I am thinking like fopen() with like "W" or something simple to map to an open() call.

But sounds like it exits, in a way, as you say, which is interesting.

revk,
@revk@toot.me.uk avatar

@ids1024 @FenTiger that is basically what I want and totally new to me. I’ll have to have a play with that! The need to close() differently on a crash goes away as you link as last thing you do. A crash before that closes and loses the file.

Miq,

@revk @torvalds Uh, that may require a lot of buffering for the replacement file in the Linux file handling code, right? I know you are thinking of config files etc., but how would the code know what size the file will be?

revk,
@revk@toot.me.uk avatar

@Miq @torvalds Not sure, the notion of making a file not in a directory already exists. All that needs "buffering" is the path name of them file to replace on close.

ben,
@ben@hardill.me.uk avatar

@revk typo in the title...

[edit] not the title, just the URL

Sorry, didn't mean to be that guy...

scudderfish,
@scudderfish@ohai.social avatar

@ben @revk Also sorry to be that guy, but it looks like tagging has gone mad as this is what my RSS reader shows it as

revk,
@revk@toot.me.uk avatar
scudderfish,
@scudderfish@ohai.social avatar

@revk It seems that post has come with all the tags you've ever used when it popped up in my RSS reader

scudderfish,
@scudderfish@ohai.social avatar

@revk It appears on all the current posts of yours. The reader is a hosted instance on Miniflux that doesn't appear to be doing it with other feeds, only yours. I'll see if I can dig further.

revk,
@revk@toot.me.uk avatar

@scudderfish I had a trailing comma, I wonder.

scudderfish,
@scudderfish@ohai.social avatar

@revk I'm using this https://www.revk.uk/feeds/posts/default?alt=rss as the feed URL, and the result has all the tags

revk,
@revk@toot.me.uk avatar

@scudderfish I had no idea thunderbird could do that! I clicked and I have an rss feed of my own blog!

scudderfish,
@scudderfish@ohai.social avatar

@revk Do you get email notifications from Mastodon, or is this even more TB witchcraft? :)

revk,
@revk@toot.me.uk avatar

@scudderfish That link was TB somehow.

revk,
@revk@toot.me.uk avatar

@ben I know, and not sure if/how to fix that.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • DreamBathrooms
  • ngwrru68w68
  • tester
  • magazineikmin
  • thenastyranch
  • rosin
  • khanakhh
  • InstantRegret
  • Youngstown
  • slotface
  • Durango
  • kavyap
  • mdbf
  • tacticalgear
  • JUstTest
  • osvaldo12
  • normalnudes
  • cubers
  • cisconetworking
  • everett
  • GTA5RPClips
  • ethstaker
  • Leos
  • provamag3
  • anitta
  • modclub
  • megavids
  • lostlight
  • All magazines