/* kern_descrip.c 5.3 82/08/03 */
#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
;
if (uap
->i
&~ 077) { uap
->i
&= 077; dup2(); return; } /* XXX */
} *uap
= (struct a
*) u
.u_ap
;
register struct file
*fp
;
if (uap
->j
< 0 || uap
->j
>= NOFILE
) {
closef(u
.u_ofile
[uap
->j
], 0);
/* u.u_ofile[uap->j] = 0; */
} *uap
= (struct a
*)u
.u_ap
;
register struct file
*fp
;
/* WHAT IF u.u_error ? */
} *uap
= (struct a
*)u
.u_ap
;
register struct file
*fp
;
adtype
.dt_type
= 0; /* XXX */
adtype
.dt_protocol
= 0; /* XXX */
if (copyout((caddr_t
)&adtype
, (caddr_t
)uap
->dtypeb
,
sizeof (struct dtype
)) < 0) {
} *uap
= (struct a
*)u
.u_ap
;
register struct file
*fp
;
if (copyin((caddr_t
)uap
->dtypeb
, (caddr_t
)&adtype
,
sizeof (struct dtype
)) < 0) {
} *uap
= (struct a
*)u
.u_ap
;
} *uap
= (struct a
*)u
.u_ap
;
} *ap
= (struct uap
*)u
.u_ap
;
int nfds
= 0, readable
= 0, writeable
= 0;
if (ap
->rp
&& copyin((caddr_t
)ap
->rp
,(caddr_t
)&rd
,sizeof(fd_set
)))
if (ap
->wp
&& copyin((caddr_t
)ap
->wp
,(caddr_t
)&wr
,sizeof(fd_set
)))
u
.u_procp
->p_flag
|= SSEL
;
readable
= selscan(ap
->nfd
, rd
, &nfds
, FREAD
);
writeable
= selscan(ap
->nfd
, wr
, &nfds
, FWRITE
);
if (readable
|| writeable
)
rem
= (ap
->timo
+999)/1000 - (time
- t
);
if (ap
->timo
== 0 || rem
<= 0)
if ((u
.u_procp
->p_flag
& SSEL
) == 0 || nselcoll
!= ncoll
) {
u
.u_procp
->p_flag
&= ~SSEL
;
u
.u_procp
->p_flag
&= ~SSEL
;
tsel
= tsleep((caddr_t
)&selwait
, PZERO
+1, rem
);
rd
.fds_bits
[0] = readable
;
wr
.fds_bits
[0] = writeable
;
s
= (ap
->nfd
+ NBBY
- 1) / NBBY
;
(void) copyout((caddr_t
)&rd
, (caddr_t
)ap
->rp
, sizeof(fd_set
));
(void) copyout((caddr_t
)&wr
, (caddr_t
)ap
->wp
, sizeof(fd_set
));
selscan(nfd
, fds
, nfdp
, flag
)
if (fp
->f_type
== DTYPE_SOCKET
)
able
= soselect(fp
->f_socket
, flag
);
switch (ip
->i_mode
& IFMT
) {
(*cdevsw
[major(ip
->i_rdev
)].d_select
)
wakeup((caddr_t
)&selwait
);
if (p
->p_wchan
== (caddr_t
)&selwait
)
* 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
register struct file
*fp
;
register struct inode
*ip
;
register struct mount
*mp
;
if (fp
->f_type
== DTYPE_SOCKET
) {
soclose(fp
->f_socket
, nouser
);
if (nouser
== 0 && u
.u_error
)
mode
= ip
->i_mode
& IFMT
;
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
* chfile -- change all references to the inode named by
* device/inum to the file referred to by fd.
* Used by init to remove all references to the device.
register struct file
*fp
;
register struct inode
*from
;
register struct inode
*to
;
int device
; /* actually dev_t */
int inum
; /* actually ino_t */
uap
= (struct a
*) u
.u_ap
;
if (fp
->f_type
== DTYPE_SOCKET
) {
for (from
= &inode
[0]; from
< &inode
[ninode
]; from
++)
if (from
->i_number
== (ino_t
)uap
->inum
&& from
->i_dev
== (dev_t
)uap
->device
)
if (from
>= &inode
[ninode
]) {
for (fp
= &file
[0]; fp
< &file
[nfile
]; fp
++) {
if (fp
->f_count
> 0 && fp
->f_inode
== from
) {
rw
|= fp
->f_flag
& FWRITE
;
* This inode is no longer referenced.
* Switch out to the appropriate close
dev
= (dev_t
)from
->i_un
.i_rdev
;
switch(from
->i_mode
& IFMT
) {
(*cdevsw
[major(dev
)].d_close
)(dev
, rw
);
(*bdevsw
[major(dev
)].d_close
)(dev
, rw
);