Date: Thu, 9 Jul 2015 15:19:45 +0000 (UTC) From: Mateusz Guzik <mjg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r285321 - head/sys/kern Message-ID: <201507091519.t69FJjC4003534@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mjg Date: Thu Jul 9 15:19:45 2015 New Revision: 285321 URL: https://svnweb.freebsd.org/changeset/base/285321 Log: fd: prepare do_dup for being exported - rename it to kern_dup. - prefix flags with FD - assert that correct flags were passed Modified: head/sys/kern/kern_descrip.c Modified: head/sys/kern/kern_descrip.c ============================================================================== --- head/sys/kern/kern_descrip.c Thu Jul 9 15:06:58 2015 (r285320) +++ head/sys/kern/kern_descrip.c Thu Jul 9 15:19:45 2015 (r285321) @@ -102,7 +102,7 @@ static uma_zone_t filedesc0_zone; static int closefp(struct filedesc *fdp, int fd, struct file *fp, struct thread *td, int holdleaders); -static int do_dup(struct thread *td, int flags, int old, int new); +static int kern_dup(struct thread *td, int flags, int old, int new); static int fd_first_free(struct filedesc *fdp, int low, int size); static int fd_last_used(struct filedesc *fdp, int size); static void fdgrowtable(struct filedesc *fdp, int nfd); @@ -111,10 +111,10 @@ static void fdunused(struct filedesc *fd static void fdused(struct filedesc *fdp, int fd); static int getmaxfd(struct thread *td); -/* Flags for do_dup() */ -#define DUP_FIXED 0x1 /* Force fixed allocation. */ -#define DUP_FCNTL 0x2 /* fcntl()-style errors. */ -#define DUP_CLOEXEC 0x4 /* Atomically set FD_CLOEXEC. */ +/* Flags for kern_dup() */ +#define FDDUP_FIXED 0x1 /* Force fixed allocation. */ +#define FDDUP_FCNTL 0x2 /* fcntl()-style errors. */ +#define FDDUP_CLOEXEC 0x4 /* Atomically set FD_CLOEXEC. */ /* * Each process has: @@ -361,7 +361,7 @@ int sys_dup2(struct thread *td, struct dup2_args *uap) { - return (do_dup(td, DUP_FIXED, (int)uap->from, (int)uap->to)); + return (kern_dup(td, FDDUP_FIXED, (int)uap->from, (int)uap->to)); } /* @@ -377,7 +377,7 @@ int sys_dup(struct thread *td, struct dup_args *uap) { - return (do_dup(td, 0, (int)uap->fd, 0)); + return (kern_dup(td, 0, (int)uap->fd, 0)); } /* @@ -487,22 +487,22 @@ kern_fcntl(struct thread *td, int fd, in switch (cmd) { case F_DUPFD: tmp = arg; - error = do_dup(td, DUP_FCNTL, fd, tmp); + error = kern_dup(td, FDDUP_FCNTL, fd, tmp); break; case F_DUPFD_CLOEXEC: tmp = arg; - error = do_dup(td, DUP_FCNTL | DUP_CLOEXEC, fd, tmp); + error = kern_dup(td, FDDUP_FCNTL | FDDUP_CLOEXEC, fd, tmp); break; case F_DUP2FD: tmp = arg; - error = do_dup(td, DUP_FIXED, fd, tmp); + error = kern_dup(td, FDDUP_FIXED, fd, tmp); break; case F_DUP2FD_CLOEXEC: tmp = arg; - error = do_dup(td, DUP_FIXED | DUP_CLOEXEC, fd, tmp); + error = kern_dup(td, FDDUP_FIXED | FDDUP_CLOEXEC, fd, tmp); break; case F_GETFD: @@ -795,7 +795,7 @@ getmaxfd(struct thread *td) * Common code for dup, dup2, fcntl(F_DUPFD) and fcntl(F_DUP2FD). */ static int -do_dup(struct thread *td, int flags, int old, int new) +kern_dup(struct thread *td, int flags, int old, int new) { struct filedesc *fdp; struct filedescent *oldfde, *newfde; @@ -807,6 +807,8 @@ do_dup(struct thread *td, int flags, int p = td->td_proc; fdp = p->p_fd; + MPASS((flags & ~(FDDUP_FIXED | FDDUP_FCNTL | FDDUP_CLOEXEC)) == 0); + /* * Verify we have a valid descriptor to dup from and possibly to * dup to. Unlike dup() and dup2(), fcntl()'s F_DUPFD should @@ -815,10 +817,10 @@ do_dup(struct thread *td, int flags, int if (old < 0) return (EBADF); if (new < 0) - return (flags & DUP_FCNTL ? EINVAL : EBADF); + return (flags & FDDUP_FCNTL ? EINVAL : EBADF); maxfd = getmaxfd(td); if (new >= maxfd) - return (flags & DUP_FCNTL ? EINVAL : EBADF); + return (flags & FDDUP_FCNTL ? EINVAL : EBADF); FILEDESC_XLOCK(fdp); if (fget_locked(fdp, old) == NULL) { @@ -826,9 +828,9 @@ do_dup(struct thread *td, int flags, int return (EBADF); } oldfde = &fdp->fd_ofiles[old]; - if (flags & DUP_FIXED && old == new) { + if (flags & FDDUP_FIXED && old == new) { td->td_retval[0] = new; - if (flags & DUP_CLOEXEC) + if (flags & FDDUP_CLOEXEC) fdp->fd_ofiles[new].fde_flags |= UF_EXCLOSE; FILEDESC_XUNLOCK(fdp); return (0); @@ -841,7 +843,7 @@ do_dup(struct thread *td, int flags, int * table is large enough to hold it, and grab it. Otherwise, just * allocate a new descriptor the usual way. */ - if (flags & DUP_FIXED) { + if (flags & FDDUP_FIXED) { if (new >= fdp->fd_nfiles) { /* * The resource limits are here instead of e.g. @@ -892,7 +894,7 @@ do_dup(struct thread *td, int flags, int filecaps_free(&newfde->fde_caps); memcpy(newfde, oldfde, fde_change_size); filecaps_copy(&oldfde->fde_caps, &newfde->fde_caps); - if ((flags & DUP_CLOEXEC) != 0) + if ((flags & FDDUP_CLOEXEC) != 0) newfde->fde_flags = oldfde->fde_flags | UF_EXCLOSE; else newfde->fde_flags = oldfde->fde_flags & ~UF_EXCLOSE; @@ -1988,7 +1990,7 @@ retry: if (fdp->fd_holdleaderscount > 0 && (p->p_leader->p_flag & P_ADVLOCK) != 0) { /* - * close() or do_dup() has cleared a reference + * close() or kern_dup() has cleared a reference * in a shared file descriptor table. */ fdp->fd_holdleaderswakeup = 1; @@ -2215,7 +2217,7 @@ fdcheckstd(struct thread *td) save = td->td_retval[0]; if (devnull != -1) { - error = do_dup(td, DUP_FIXED, devnull, i); + error = kern_dup(td, FDDUP_FIXED, devnull, i); } else { error = kern_openat(td, AT_FDCWD, "/dev/null", UIO_SYSSPACE, O_RDWR, 0);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201507091519.t69FJjC4003534>