/* kern_descrip.c 5.23 83/01/17 */
#include "../h/socketvar.h"
#include "../h/descrip.h"
* ufalloc side effects are gross
* System calls on descriptors.
} *uap
= (struct a
*)u
.u_ap
;
register struct file
*fp
;
adtype
.dt_type
= 0; /* XXX */
adtype
.dt_protocol
= 0; /* XXX */
u
.u_error
= copyout((caddr_t
)&adtype
, (caddr_t
)uap
->dtypeb
,
} *uap
= (struct a
*) u
.u_ap
;
if (uap
->i
&~ 077) { uap
->i
&= 077; dup2(); return; } /* XXX */
dupit(j
, fp
, u
.u_pofile
[uap
->i
] & (UF_SHLOCK
|UF_EXLOCK
));
} *uap
= (struct a
*) u
.u_ap
;
register struct file
*fp
;
if (uap
->j
< 0 || uap
->j
>= NOFILE
) {
if (u
.u_pofile
[uap
->j
] & UF_MAPPED
)
closef(u
.u_ofile
[uap
->j
], 0, u
.u_pofile
[uap
->j
]);
/* u.u_ofile[uap->j] = 0; */
/* u.u_pofile[uap->j] = 0; */
dupit(uap
->j
, fp
, u
.u_pofile
[uap
->i
] & (UF_SHLOCK
|UF_EXLOCK
));
register struct file
*fp
;
u
.u_pofile
[fd
] = lockflags
;
fp
->f_inode
->i_shlockc
++;
fp
->f_inode
->i_exlockc
++;
} *uap
= (struct a
*)u
.u_ap
;
register struct file
*fp
;
if (u
.u_pofile
[uap
->i
] & UF_MAPPED
)
closef(fp
, 0, u
.u_pofile
[uap
->i
]);
/* WHAT IF u.u_error ? */
u
.u_ofile
[uap
->i
] = NULL
;
} *uap
= (struct a
*)u
.u_ap
;
register struct file
*fp
;
u
.u_error
= copyin((caddr_t
)uap
->dtypeb
, (caddr_t
)&adtype
,
} *uap
= (struct uap
*)u
.u_ap
;
obits
[0] = obits
[1] = obits
[2] = 0;
uap
->nd
= NOFILE
; /* forgiving, if slightly wrong */
#define getbits(name, x) \
u.u_error = copyin((caddr_t)uap->name, (caddr_t)&ibits[x], \
u
.u_error
= copyin((caddr_t
)uap
->tv
, (caddr_t
)&atv
,
s
= spl7(); timevaladd(&atv
, &time
); splx(s
);
u
.u_procp
->p_flag
|= SSEL
;
u
.u_r
.r_val1
= selscan(ibits
, obits
);
if (u
.u_error
|| u
.u_r
.r_val1
)
if (uap
->tv
&& timercmp(&time
, &atv
, >=)) {
if ((u
.u_procp
->p_flag
& SSEL
) == 0 || nselcoll
!= ncoll
) {
u
.u_procp
->p_flag
&= ~SSEL
;
u
.u_procp
->p_flag
&= ~SSEL
;
if (setjmp(&u
.u_qsave
)) {
untimeout(unselect
, (caddr_t
)u
.u_procp
);
timeout(unselect
, (caddr_t
)u
.u_procp
, hzto(&atv
));
sleep((caddr_t
)&selwait
, PZERO
+1);
untimeout(unselect
, (caddr_t
)u
.u_procp
);
#define putbits(name, x) \
int error = copyout((caddr_t)&obits[x], (caddr_t)uap->name, \
register int which
, bits
, i
;
for (which
= 0; which
< 3; which
++) {
if (fp
->f_type
== DTYPE_SOCKET
)
able
= soselect(fp
->f_socket
, flag
);
switch (ip
->i_mode
& IFMT
) {
(*cdevsw
[major(ip
->i_rdev
)].d_select
)
obits
[which
] |= (1<<(i
-1));
wakeup((caddr_t
)&selwait
);
if (p
->p_wchan
== (caddr_t
)&selwait
)
else if (p
->p_flag
& SSEL
)
* Allocate a user file descriptor.
if (u
.u_ofile
[i
] == NULL
) {
* Allocate a user file descriptor
* Initialize the descriptor
* to point at the file structure.
register struct file
*fp
;
for (fp
= lastf
; fp
< fileNFILE
; fp
++)
for (fp
= file
; fp
< lastf
; fp
++)
* Convert a user supplied file descriptor into a pointer
* to a file structure. Only task is to check range of the descriptor.
* Critical paths should use the GETF macro, defined in inline.h.
register struct file
*fp
;
if ((unsigned)f
>= NOFILE
|| (fp
= u
.u_ofile
[f
]) == NULL
) {
* Internal form of close.
* Decrement reference count on
* Also make sure the pipe protocol
* Decrement reference count on the inode following
* removal to the referencing file structure.
* Call device handler on last close.
* Nouser indicates that the user isn't available to present
* Handling locking at this level is RIDICULOUS.
closef(fp
, nouser
, flags
)
register struct file
*fp
;
register struct inode
*ip
;
register struct mount
*mp
;
if (fp
->f_type
== DTYPE_SOCKET
) {
u
.u_error
= soclose(fp
->f_socket
, nouser
);
if (nouser
== 0 && u
.u_error
)
mode
= ip
->i_mode
& IFMT
;
flags
&= UF_SHLOCK
|UF_EXLOCK
; /* conservative */
cfunc
= cdevsw
[major(dev
)].d_close
;
* We don't want to really close the device if it is mounted
for (mp
= mount
; mp
< &mount
[NMOUNT
]; mp
++)
if (mp
->m_bufp
!= NULL
&& mp
->m_dev
== dev
)
cfunc
= bdevsw
[major(dev
)].d_close
;
for (fp
= file
; fp
< fileNFILE
; fp
++) {
if (fp
->f_type
== DTYPE_SOCKET
) /* XXX */
if (fp
->f_count
&& (ip
= fp
->f_inode
) &&
ip
->i_rdev
== dev
&& (ip
->i_mode
&IFMT
) == mode
)
* On last close of a block device (that isn't mounted)
* we must invalidate any in core blocks
sleep((caddr_t
)&u
, PSLEP
);