/* kern_descrip.c 5.25 83/06/12 */
#include "../h/socketvar.h"
* eliminate u.u_error side effects
* System calls on descriptors.
} *uap
= (struct a
*) u
.u_ap
;
if (uap
->i
&~ 077) { uap
->i
&= 077; dup2(); return; } /* XXX */
dupit(j
, fp
, u
.u_pofile
[uap
->i
]);
} *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
], 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
]);
register struct file
*fp
;
u
.u_pofile
[fd
] = lockflags
;
/* THIS DOESN'T BELONG HERE */
((struct inode
*)fp
->f_data
)->i_shlockc
++;
((struct inode
*)fp
->f_data
)->i_exlockc
++;
* The file control system call.
register struct file
*fp
;
uap
= (struct a
*)u
.u_ap
;
pop
= &u
.u_pofile
[uap
->fdes
];
if (i
< 0 || i
> NOFILE
) {
if ((i
= ufalloc(i
)) < 0)
*pop
= (*pop
&~ 1) | (uap
->arg
& 1);
u
.u_r
.r_val1
= fp
->f_flag
+FOPEN
;
fp
->f_flag
|= (uap
->arg
-FOPEN
) &~ FCNTLCANT
;
u
.u_error
= fset(fp
, FNDELAY
, fp
->f_flag
& FNDELAY
);
u
.u_error
= fset(fp
, FASYNC
, fp
->f_flag
& FASYNC
);
(void) fset(fp
, FNDELAY
, 0);
u
.u_error
= fsetown(fp
, uap
->arg
);
u
.u_error
= fgetown(fp
, &u
.u_r
.r_val1
);
return (fioctl(fp
, (int)(bit
== FNDELAY
? FIONBIO
: FIOASYNC
),
*valuep
= ((struct socket
*)fp
->f_data
)->so_pgrp
;
error
= fioctl(fp
, (int)TIOCGPGRP
, (caddr_t
)valuep
);
if (fp
->f_type
== DTYPE_SOCKET
) {
((struct socket
*)fp
->f_data
)->so_pgrp
= value
;
struct proc
*p
= pfind(value
);
return (fioctl(fp
, (int)TIOCSPGRP
, (caddr_t
)&value
));
return ((*fp
->f_ops
->fo_ioctl
)(fp
, cmd
, value
));
} *uap
= (struct a
*)u
.u_ap
;
register struct file
*fp
;
pf
= (u_char
*)&u
.u_pofile
[uap
->i
];
if (*pf
& (UF_SHLOCK
|UF_EXLOCK
))
/* WHAT IF u.u_error ? */
u
.u_ofile
[uap
->i
] = NULL
;
register struct file
*fp
;
uap
= (struct a
*)u
.u_ap
;
u
.u_error
= ino_stat((struct inode
*)fp
->f_data
, &ub
);
u
.u_error
= soo_stat((struct socket
*)fp
->f_data
, &ub
);
u
.u_error
= copyout(&ub
, uap
->sb
, sizeof (ub
));
* Allocate a user file descriptor.
if (u
.u_ofile
[i
] == NULL
) {
register int i
, avail
= 0;
for (i
= 0; i
< NOFILE
; i
++)
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.
register struct file
*fp
;
if ((unsigned)f
>= NOFILE
|| (fp
= u
.u_ofile
[f
]) == NULL
) {
* Internal form of close.
* Decrement reference count on file structure.
* If last reference not going away, but no more
* references except in message queues, run a
* garbage collect. This would better be done by
* forcing a gc() to happen sometime soon, rather
* than running one each time.
register struct file
*fp
;
if (fp
->f_count
== fp
->f_msgcount
)
(*fp
->f_ops
->fo_close
)(fp
);
* Apply an advisory lock on a file descriptor.
} *uap
= (struct a
*)u
.u_ap
;
register struct file
*fp
;
pf
= (u_char
*)&u
.u_pofile
[uap
->fd
];
* No reason to write lock a file we've already
* write locked, similarly with a read lock.
if ((*pf
& UF_EXLOCK
) && (cmd
& LOCK_EX
) ||
(*pf
& UF_SHLOCK
) && (cmd
& LOCK_SH
))
u
.u_error
= ino_lock((struct inode
*)fp
->f_data
, pf
, cmd
);
u
.u_error
= soo_lock((struct socket
*)fp
->f_data
, pf
, cmd
);
register struct file
*fp
;
if ((*pf
& (UF_SHLOCK
|UF_EXLOCK
)) == 0)
ino_unlock((struct inode
*)fp
->f_data
, *pf
);
soo_unlock((struct socket
*)fp
->f_data
, *pf
);
*pf
&= ~(UF_SHLOCK
|UF_EXLOCK
);