* Convert a user supplied
* file descriptor into a pointer
* Only task is to check range
* Internal form of close.
* Decrement reference count on
* file structure and call closei
* Also make sure the pipe protocol
ip
->i_mode
=& ~(IREAD
|IWRITE
);
closei(rfp
->f_inode
, rfp
->f_flag
&FWRITE
);
* Decrement reference count on an
* inode due to the removal of a
* referencing file structure.
* On the last closei, switchout
* to the close entry point of special
* Note that the handler gets called
* on every open and only on the last
maj
= rip
->i_addr
[0].d_major
;
switch(rip
->i_mode
&IFMT
) {
(*cdevsw
[maj
].d_close
)(dev
, rw
);
(*bdevsw
[maj
].d_close
)(dev
, rw
);
* openi called to allow handler
* of special files to initialize and
* validate before actual IO.
* Called on all sorts of opens
maj
= rip
->i_addr
[0].d_major
;
switch(rip
->i_mode
&IFMT
) {
(*cdevsw
[maj
].d_open
)(dev
, rw
);
(*bdevsw
[maj
].d_open
)(dev
, rw
);
* Check mode permission on inode pointer.
* Mode is READ, WRITE or EXEC.
* In the case of WRITE, the
* read-only status of the file
* Also in WRITE, prototype text
* segments cannot be written.
* The mode is shifted to select
* the owner/group/other fields.
* The super user is granted all
* permissions except for EXEC where
* at least one of the EXEC bits must
if(getfs(ip
->i_dev
)->s_ronly
!= 0) {
if(m
== IEXEC
&& (ip
->i_mode
&
(IEXEC
| (IEXEC
>>3) | (IEXEC
>>6))) == 0)
if(u
.u_uid
!= ip
->i_uid
) {
* Look up a pathname and test if
* the resultant inode is owned by the
* If not, try for super-user.
* If permission is granted,
register struct inode
*ip
;
if ((ip
= namei(uchar
, 0)) == NULL
)
* Test if the current user is the
* 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.
* no file -- if there are no available
register struct file
*fp
;
for (fp
= &file
[0]; fp
< &file
[NFILE
]; fp
++)