linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Enrico Weigelt, metux IT consult" <lkml@metux.net>
To: linux-fsdevel@vger.kernel.org
Subject: understanding do_dup2() vs fd_install()
Date: Tue, 22 Jun 2021 17:58:34 +0200	[thread overview]
Message-ID: <674f31a9-eee7-4e4a-29c2-86ff43cd6b76@metux.net> (raw)

Hello folks,


while digging deeper into the fs internals, I began to wonder whether
there might be some overlap between do_dup2() and fd_install(), that
might go into a common function.

If I understood that correctly, both link a struct file* into some
process' fd table, the difference seems to be:

* fd_install() doesn't need to deref the old file, since callers
  allocated a fresh fdnum - while dup2() has to (if the fd was used)
* fd_install() picks the fdtable from the current process, while
  do_dup2() directly works on a given fdtable.

Oh, and there's also replace_fd(), which calls do_dup2()


Just phantasizing: can we put it into something like that ?

int do_assign_fd(struct fdtable *fdtable, int newfd, struct file *fp)

  --> put or replace fp into the fdtable
  --> if newfd == -1, pick a new slot, otherwise take newfd
  --> checks (eg. rlimit, etc)
  --> unref/close the old entry (if non-null)

int fd_install(unsigned int fd, struct file *f)
{
    do_assign_fd(current->files, fd, f)
}

Am I missing something vital here ?

By the way: do_dup2() is always called with "files" parameter being
current->files -- why do we need that parameter at all ?


thanks,

--mtx
-- 
---
Hinweis: unverschlüsselte E-Mails können leicht abgehört und manipuliert
werden ! Für eine vertrauliche Kommunikation senden Sie bitte ihren
GPG/PGP-Schlüssel zu.
---
Enrico Weigelt, metux IT consult
Free software and Linux embedded engineering
info@metux.net -- +49-151-27565287

                 reply	other threads:[~2021-06-22 15:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=674f31a9-eee7-4e4a-29c2-86ff43cd6b76@metux.net \
    --to=lkml@metux.net \
    --cc=linux-fsdevel@vger.kernel.org \
    /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).