diff options
author | Mateusz Guzik <mjg@FreeBSD.org> | 2014-10-31 09:19:46 +0000 |
---|---|---|
committer | Mateusz Guzik <mjg@FreeBSD.org> | 2014-10-31 09:19:46 +0000 |
commit | ffeb8905927767f8e93647fc3d6bb59529fdfcfb (patch) | |
tree | bb17546d37f2a5f27815e424658df2c3b42ea29b /sys/kern/kern_descrip.c | |
parent | 1a0c80a3dfa5e70ed9b7644092faf802264ca21c (diff) | |
download | src-ffeb8905927767f8e93647fc3d6bb59529fdfcfb.tar.gz src-ffeb8905927767f8e93647fc3d6bb59529fdfcfb.zip |
Notes
Diffstat (limited to 'sys/kern/kern_descrip.c')
-rw-r--r-- | sys/kern/kern_descrip.c | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index d476caea2d4e..27d258516974 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -238,8 +238,6 @@ static int fdisused(struct filedesc *fdp, int fd) { - FILEDESC_LOCK_ASSERT(fdp); - KASSERT(fd >= 0 && fd < fdp->fd_nfiles, ("file descriptor %d out of range (0, %d)", fd, fdp->fd_nfiles)); @@ -251,14 +249,21 @@ fdisused(struct filedesc *fdp, int fd) * Mark a file descriptor as used. */ static void -fdused(struct filedesc *fdp, int fd) +fdused_init(struct filedesc *fdp, int fd) { - FILEDESC_XLOCK_ASSERT(fdp); - KASSERT(!fdisused(fdp, fd), ("fd=%d is already used", fd)); fdp->fd_map[NDSLOT(fd)] |= NDBIT(fd); +} + +static void +fdused(struct filedesc *fdp, int fd) +{ + + FILEDESC_XLOCK_ASSERT(fdp); + + fdused_init(fdp, fd); if (fd > fdp->fd_lastfile) fdp->fd_lastfile = fd; if (fd == fdp->fd_freefile) @@ -1912,28 +1917,23 @@ fdcopy(struct filedesc *fdp) newfdp->fd_freefile = -1; for (i = 0; i <= fdp->fd_lastfile; ++i) { ofde = &fdp->fd_ofiles[i]; - if (ofde->fde_file != NULL && - ofde->fde_file->f_ops->fo_flags & DFLAG_PASSABLE) { - nfde = &newfdp->fd_ofiles[i]; - *nfde = *ofde; - filecaps_copy(&ofde->fde_caps, &nfde->fde_caps); - fhold(nfde->fde_file); - newfdp->fd_lastfile = i; - } else { + if (ofde->fde_file == NULL || + (ofde->fde_file->f_ops->fo_flags & DFLAG_PASSABLE) == 0) { if (newfdp->fd_freefile == -1) newfdp->fd_freefile = i; + continue; } - } - newfdp->fd_cmask = fdp->fd_cmask; - FILEDESC_SUNLOCK(fdp); - FILEDESC_XLOCK(newfdp); - for (i = 0; i <= newfdp->fd_lastfile; ++i) { - if (newfdp->fd_ofiles[i].fde_file != NULL) - fdused(newfdp, i); + nfde = &newfdp->fd_ofiles[i]; + *nfde = *ofde; + filecaps_copy(&ofde->fde_caps, &nfde->fde_caps); + fhold(nfde->fde_file); + fdused_init(newfdp, i); + newfdp->fd_lastfile = i; } if (newfdp->fd_freefile == -1) newfdp->fd_freefile = i; - FILEDESC_XUNLOCK(newfdp); + newfdp->fd_cmask = fdp->fd_cmask; + FILEDESC_SUNLOCK(fdp); return (newfdp); } |