understanding do_dup2() vs fd_install()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx -- +49-151-27565287



[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux