linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* understanding do_dup2() vs fd_install()
@ 2021-06-22 15:58 Enrico Weigelt, metux IT consult
  0 siblings, 0 replies; only message in thread
From: Enrico Weigelt, metux IT consult @ 2021-06-22 15:58 UTC (permalink / raw)
  To: linux-fsdevel

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-22 15:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-22 15:58 understanding do_dup2() vs fd_install() Enrico Weigelt, metux IT consult

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).