:: [DNG] the openat suite of functions…
Inizio della pagina
Delete this message
Reply to this message
Autore: Hendrik Boom
Data:  
To: dng
Vecchi argomenti: Re: [DNG] terminology
Oggetto: [DNG] the openat suite of functions look useful.
On Fri, Aug 28, 2020 at 03:39:54PM +0200, Adam Borowski wrote:
> On Fri, Aug 28, 2020 at 08:37:07AM -0400, Hendrik Boom wrote:
> > > >>>> Is there an establiched word in the Linux/Unix xommunity
> > > >>>> for something which might be a file or a directory?
>
> > > Therefore it looks to me more like an implementation
> > > detail than a sensible concept.
> >
> > I do miss the ability to identify a directory independent of its name.
> > It can be important if a directory is renamed and you have active data in it.
> >
> > There's one directory that works for -- the current directory. If you
> > rename that directory you're still in it.
> >
> > In the 80's or 90's (I forget) there was a proposal to the ISO from
> > Japan to establish a standard OS-independent OS interface for
> > programmers to use. I lost against POSIX.
> >
> > But it had a machanism whereby opening a file could be done in two
> > phases.
> >
> > First you get a "lock" on a file. That gives you a connection to that
> > file. It's not an exclusive kind of lock (unless you ask it to be);
> > it's just a way of unambiguously identifying the file as long as it
> > exists and you keep the lock. It hangs on to the file even if someone
> > renames it. (not sure what happens if the file is deleted, though)
>
> _Any_ file descriptor does that. And a deleted file stays there, merely
> with a 0 link count -- if there's an open descriptor, you can link the file
> back into the filesystem. That's even the recommended way to create a new
> file atomically -- instead of the old write+fsync+rename trick that leaves
> junk upon a crash.
>
> And if you don't need to do any I/O on the file, O_PATH won't waste time.
>
> > Then afterward you can open it, close it, set exclusive
> > read/write access, release exclusive access, etc, using the lock instead
> > of the name.
> >
> > I've often regretted there's no such similar feature in Linux. The
> > assurance that several uses of a file or directory are indeed to the
> > same file or directory. You can do some of this by keeping a file open,
> > but I know of nothing like that for directories.
>
> man name_to_handle_at, open_by_handle_at. But this interface sucks and is
> superfluous with regular openat() -- which is also portable.
>
> So _always_ use openat() if you suspect something might happen to the
> underlying directories.


Very useful information! Thank you.

-- hendrik