Deleted Added
full compact
kern_descrip.c (47829) kern_descrip.c (49413)
1/*
2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94
1/*
2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94
39 * $Id: kern_descrip.c,v 1.63 1999/05/31 11:27:30 phk Exp $
39 * $Id: kern_descrip.c,v 1.64 1999/06/07 20:37:27 msmith Exp $
40 */
41
42#include "opt_compat.h"
43#include "opt_devfs.h"
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/sysproto.h>

--- 48 unchanged lines hidden (view full) ---

96 /* dump */ nodump,
97 /* psize */ nopsize,
98 /* flags */ 0,
99 /* maxio */ 0,
100 /* bmaj */ -1
101};
102
103static int finishdup __P((struct filedesc *fdp, int old, int new, register_t *retval));
40 */
41
42#include "opt_compat.h"
43#include "opt_devfs.h"
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/sysproto.h>

--- 48 unchanged lines hidden (view full) ---

96 /* dump */ nodump,
97 /* psize */ nopsize,
98 /* flags */ 0,
99 /* maxio */ 0,
100 /* bmaj */ -1
101};
102
103static int finishdup __P((struct filedesc *fdp, int old, int new, register_t *retval));
104static int badfo_readwrite __P((struct file *fp, struct uio *uio,
105 struct ucred *cred, int flags));
106static int badfo_ioctl __P((struct file *fp, u_long com, caddr_t data,
107 struct proc *p));
108static int badfo_poll __P((struct file *fp, int events,
109 struct ucred *cred, struct proc *p));
110static int badfo_close __P((struct file *fp, struct proc *p));
104/*
105 * Descriptor management.
106 */
107struct filelist filehead; /* head of list of open files */
108int nfiles; /* actual number of open files */
109extern int cmask;
110
111/*

--- 719 unchanged lines hidden (view full) ---

831 * Allocate a new file descriptor.
832 * If the process has file descriptor zero open, add to the list
833 * of open files at that point, otherwise put it at the front of
834 * the list of open files.
835 */
836 nfiles++;
837 MALLOC(fp, struct file *, sizeof(struct file), M_FILE, M_WAITOK);
838 bzero(fp, sizeof(struct file));
111/*
112 * Descriptor management.
113 */
114struct filelist filehead; /* head of list of open files */
115int nfiles; /* actual number of open files */
116extern int cmask;
117
118/*

--- 719 unchanged lines hidden (view full) ---

838 * Allocate a new file descriptor.
839 * If the process has file descriptor zero open, add to the list
840 * of open files at that point, otherwise put it at the front of
841 * the list of open files.
842 */
843 nfiles++;
844 MALLOC(fp, struct file *, sizeof(struct file), M_FILE, M_WAITOK);
845 bzero(fp, sizeof(struct file));
846 fp->f_count = 1;
847 fp->f_cred = p->p_ucred;
848 fp->f_ops = &badfileops;
849 fp->f_seqcount = 1;
850 crhold(fp->f_cred);
839 if ((fq = p->p_fd->fd_ofiles[0])) {
840 LIST_INSERT_AFTER(fq, fp, f_list);
841 } else {
842 LIST_INSERT_HEAD(&filehead, fp, f_list);
843 }
844 p->p_fd->fd_ofiles[i] = fp;
851 if ((fq = p->p_fd->fd_ofiles[0])) {
852 LIST_INSERT_AFTER(fq, fp, f_list);
853 } else {
854 LIST_INSERT_HEAD(&filehead, fp, f_list);
855 }
856 p->p_fd->fd_ofiles[i] = fp;
845 fp->f_count = 1;
846 fp->f_cred = p->p_ucred;
847 fp->f_seqcount = 1;
848 crhold(fp->f_cred);
849 if (resultfp)
850 *resultfp = fp;
851 if (resultfd)
852 *resultfd = i;
853 return (0);
854}
855
856/*

--- 216 unchanged lines hidden (view full) ---

1073 if ((fp->f_flag & FHASLOCK) && fp->f_type == DTYPE_VNODE) {
1074 lf.l_whence = SEEK_SET;
1075 lf.l_start = 0;
1076 lf.l_len = 0;
1077 lf.l_type = F_UNLCK;
1078 vp = (struct vnode *)fp->f_data;
1079 (void) VOP_ADVLOCK(vp, (caddr_t)fp, F_UNLCK, &lf, F_FLOCK);
1080 }
857 if (resultfp)
858 *resultfp = fp;
859 if (resultfd)
860 *resultfd = i;
861 return (0);
862}
863
864/*

--- 216 unchanged lines hidden (view full) ---

1081 if ((fp->f_flag & FHASLOCK) && fp->f_type == DTYPE_VNODE) {
1082 lf.l_whence = SEEK_SET;
1083 lf.l_start = 0;
1084 lf.l_len = 0;
1085 lf.l_type = F_UNLCK;
1086 vp = (struct vnode *)fp->f_data;
1087 (void) VOP_ADVLOCK(vp, (caddr_t)fp, F_UNLCK, &lf, F_FLOCK);
1088 }
1081 if (fp->f_ops)
1089 if (fp->f_ops != &badfileops)
1082 error = (*fp->f_ops->fo_close)(fp, p);
1083 else
1084 error = 0;
1085 ffree(fp);
1086 return (error);
1087}
1088
1089/*

--- 228 unchanged lines hidden (view full) ---

1318 devfs_token_stderr =
1319 devfs_add_devswf(&fildesc_cdevsw, 2, DV_CHR,
1320 UID_ROOT, GID_WHEEL, 0666,
1321 "stderr");
1322#endif
1323 }
1324}
1325
1090 error = (*fp->f_ops->fo_close)(fp, p);
1091 else
1092 error = 0;
1093 ffree(fp);
1094 return (error);
1095}
1096
1097/*

--- 228 unchanged lines hidden (view full) ---

1326 devfs_token_stderr =
1327 devfs_add_devswf(&fildesc_cdevsw, 2, DV_CHR,
1328 UID_ROOT, GID_WHEEL, 0666,
1329 "stderr");
1330#endif
1331 }
1332}
1333
1334struct fileops badfileops = {
1335 badfo_readwrite,
1336 badfo_readwrite,
1337 badfo_ioctl,
1338 badfo_poll,
1339 badfo_close
1340};
1341
1342static int
1343badfo_readwrite(fp, uio, cred, flags)
1344 struct file *fp;
1345 struct uio *uio;
1346 struct ucred *cred;
1347 int flags;
1348{
1349
1350 return (EBADF);
1351}
1352
1353static int
1354badfo_ioctl(fp, com, data, p)
1355 struct file *fp;
1356 u_long com;
1357 caddr_t data;
1358 struct proc *p;
1359{
1360
1361 return (EBADF);
1362}
1363
1364static int
1365badfo_poll(fp, events, cred, p)
1366 struct file *fp;
1367 int events;
1368 struct ucred *cred;
1369 struct proc *p;
1370{
1371
1372 return (0);
1373}
1374
1375static int
1376badfo_close(fp, p)
1377 struct file *fp;
1378 struct proc *p;
1379{
1380
1381 return (EBADF);
1382}
1383
1326SYSINIT(fildescdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,
1327 fildesc_drvinit,NULL)
1328
1329
1384SYSINIT(fildescdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,
1385 fildesc_drvinit,NULL)
1386
1387