9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Alyssa M via 9fans" <9fans@9fans.net>
To: 9fans <9fans@9fans.net>
Subject: Re: [9fans] openat()
Date: Sun, 7 Apr 2024 11:00:19 -0400	[thread overview]
Message-ID: <17125020190.Dfc7b.875375@composer.9fans.topicbox.com> (raw)
In-Reply-To: <17124538090.BD80ABf5D.12467@composer.9fans.topicbox.com>

[-- Attachment #1: Type: text/plain, Size: 2408 bytes --]

I left the oven on for my partly-baked idea.

I'm now thinking that with fd 5 as an example:
 open ("#d/5dir/a/b/c", ...)
might be a practical way to do this (the  syntax I suggested earlier would require walking from a file, which wouldn't be sensible).

So I went snorkeling in the kernel to see how hard this would be...

devdup.c uses the bottom bit of the qid.path to distinguish #d/0 from #d/0ctl, so that would have to change to modulo 3 to allow the '5dir' virtual directory to be found when qid.path % 3 == 2, and twicefd would have to change to thricefd.
The idea is that a walk to #d/5dir would continue the walk at the cloned unopened directory fid that fd 5 is also holding in its chan (as I suggested in a previous post).

Currently, dupwalk just calls devwalk in dev.c, so we'd probably want to do the first step in dupwalk, doing fd2chan, much like dupopen does. Then call something else to walk from there. I'm not sure what though: walk() maybe?
I don't really know my way around the Plan 9 kernel, so this may not be the right way to do this. There are some scary creatures in dev.c, including a spikey backward pointing goto and some dark comments about contradictory rules and ugly bits... :o

You'd want to get the effect of having the directory open on fd 5 bound to #d/5dir without actually doing the bind (because you can't...).
Ideally if fd 5 is not a directory, then #d/5dir should not even appear.

The idea is that then:
int
openat (int fd, char *path, int mode)
{
        char newpath[PATHSIZE];
        sprintf (newpath, "#d/%ddir/%s", fd, path);
        return open (newpath, mode);
}

could be a function in a library somewhere that would parcel it up in a more convenient form, and the rest of the *at suite could follow the same pattern. Maybe someone would want this for a version of APE emulating Linux?

So the idea is still partly-baked, and still very much in the realm of the hypothetical: 

Ron Minnich wrote:
"I don't want this to turn into a debate on the merits of openat"

I'm approaching this in the spirit of "if we had to implement this, how would we do it while inflicting the least harm"... :)
------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/T675e737e776e5a9c-M124c4e12c40240ab85dbdea0
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

[-- Attachment #2: Type: text/html, Size: 3594 bytes --]

  reply	other threads:[~2024-04-07 15:00 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-05 19:50 ron minnich
2024-04-05 20:12 ` Gorka Guardiola
2024-04-05 20:15   ` Gorka Guardiola
2024-04-05 20:36     ` Gorka Guardiola
2024-04-05 21:22       ` ron minnich
2024-04-05 21:43         ` Bakul Shah via 9fans
2024-04-05 21:49         ` Alyssa M via 9fans
2024-04-05 22:29           ` Gorka Guardiola
2024-04-06  3:18             ` moody
2024-04-06 17:35               ` ron minnich
2024-04-06 19:23                 ` David Leimbach via 9fans
2024-04-06 19:54                 ` Bakul Shah via 9fans
2024-04-06 19:24               ` Alyssa M via 9fans
2024-04-06 20:51                 ` moody
2024-04-07  1:36                   ` Alyssa M via 9fans
2024-04-07 15:00                     ` Alyssa M via 9fans [this message]
2024-04-10 12:17                       ` wb.kloke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=17125020190.Dfc7b.875375@composer.9fans.topicbox.com \
    --to=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).