VFS: I_PIPE is redundant
Also, use S_IS* macros instead of manual comparison.
This commit is contained in:
parent
755102d67f
commit
96bbc5da3e
9 changed files with 14 additions and 25 deletions
|
@ -19,6 +19,7 @@
|
|||
#include <minix/callnr.h>
|
||||
#include <minix/u64.h>
|
||||
#include <assert.h>
|
||||
#include <sys/stat.h>
|
||||
#include "fs.h"
|
||||
#include "file.h"
|
||||
#include "fproc.h"
|
||||
|
@ -570,14 +571,14 @@ struct filp *f;
|
|||
}
|
||||
|
||||
/* If the inode being closed is a pipe, release everyone hanging on it. */
|
||||
if (vp->v_pipe == I_PIPE) {
|
||||
if (S_ISFIFO(vp->v_mode)) {
|
||||
rw = (f->filp_mode & R_BIT ? WRITE : READ);
|
||||
release(vp, rw, NR_PROCS);
|
||||
}
|
||||
|
||||
/* If a write has been done, the inode is already marked as DIRTY. */
|
||||
if (--f->filp_count == 0) {
|
||||
if (vp->v_pipe == I_PIPE) {
|
||||
if (S_ISFIFO(vp->v_mode)) {
|
||||
/* Last reader or writer is going. Tell PFS about latest
|
||||
* pipe size.
|
||||
*/
|
||||
|
|
|
@ -373,11 +373,10 @@ struct vnode *vp;
|
|||
off_t newsize;
|
||||
{
|
||||
/* Truncate a regular file or a pipe */
|
||||
int r, file_type;
|
||||
int r;
|
||||
|
||||
assert(tll_locked_by_me(&vp->v_lock));
|
||||
file_type = vp->v_mode & I_TYPE;
|
||||
if (file_type != I_REGULAR && file_type != I_NAMED_PIPE) return(EINVAL);
|
||||
if (!S_ISREG(vp->v_mode) && !S_ISFIFO(vp->v_mode)) return(EINVAL);
|
||||
|
||||
/* We must not compare the old and the new size here: this function may be
|
||||
* called for open(2), which requires an update to the file times if O_TRUNC
|
||||
|
|
|
@ -246,7 +246,6 @@ int common_open(char path[PATH_MAX], int oflags, mode_t omode)
|
|||
tll_upgrade(&vp->v_lock);
|
||||
r = map_vnode(vp, PFS_PROC_NR);
|
||||
if (r == OK) {
|
||||
vp->v_pipe = I_PIPE;
|
||||
if (vp->v_ref_count == 1) {
|
||||
vp->v_pipe_rd_pos = 0;
|
||||
vp->v_pipe_wr_pos = 0;
|
||||
|
@ -499,8 +498,6 @@ static int pipe_open(struct vnode *vp, mode_t bits, int oflags)
|
|||
* processes hanging on the pipe.
|
||||
*/
|
||||
|
||||
vp->v_pipe = I_PIPE;
|
||||
|
||||
if ((bits & (R_BIT|W_BIT)) == (R_BIT|W_BIT)) return(ENXIO);
|
||||
|
||||
/* Find the reader/writer at the other end of the pipe */
|
||||
|
@ -547,8 +544,7 @@ int do_mknod()
|
|||
resolve.l_vnode_lock = VNODE_READ;
|
||||
|
||||
/* Only the super_user may make nodes other than fifos. */
|
||||
if (!super_user && (((mode_bits & I_TYPE) != I_NAMED_PIPE) &&
|
||||
((mode_bits & I_TYPE) != I_UNIX_SOCKET))) {
|
||||
if (!super_user && (!S_ISFIFO(mode_bits) && !S_ISSOCK(mode_bits))) {
|
||||
return(EPERM);
|
||||
}
|
||||
bits = (mode_bits & I_TYPE) | (mode_bits & ALL_MODES & fp->fp_umask);
|
||||
|
@ -558,7 +554,7 @@ int do_mknod()
|
|||
if ((vp = last_dir(&resolve, fp)) == NULL) return(err_code);
|
||||
|
||||
/* Make sure that the object is a directory */
|
||||
if ((vp->v_mode & I_TYPE) != I_DIRECTORY) {
|
||||
if (!S_ISDIR(vp->v_mode)) {
|
||||
r = ENOTDIR;
|
||||
} else if ((r = forbidden(fp, vp, W_BIT|X_BIT)) == OK) {
|
||||
r = req_mknod(vp->v_fs_e, vp->v_inode_nr, fullpath, fp->fp_effuid,
|
||||
|
@ -600,7 +596,7 @@ int do_mkdir()
|
|||
if ((vp = last_dir(&resolve, fp)) == NULL) return(err_code);
|
||||
|
||||
/* Make sure that the object is a directory */
|
||||
if ((vp->v_mode & I_TYPE) != I_DIRECTORY) {
|
||||
if (!S_ISDIR(vp->v_mode)) {
|
||||
r = ENOTDIR;
|
||||
} else if ((r = forbidden(fp, vp, W_BIT|X_BIT)) == OK) {
|
||||
r = req_mkdir(vp->v_fs_e, vp->v_inode_nr, fullpath, fp->fp_effuid,
|
||||
|
@ -632,7 +628,7 @@ int do_lseek()
|
|||
if ( (rfilp = get_filp(seekfd, VNODE_READ)) == NULL) return(err_code);
|
||||
|
||||
/* No lseek on pipes. */
|
||||
if (rfilp->filp_vno->v_pipe == I_PIPE) {
|
||||
if (S_ISFIFO(rfilp->filp_vno->v_mode)) {
|
||||
unlock_filp(rfilp);
|
||||
return(ESPIPE);
|
||||
}
|
||||
|
@ -692,7 +688,7 @@ int do_llseek()
|
|||
if ( (rfilp = get_filp(seekfd, VNODE_READ)) == NULL) return(err_code);
|
||||
|
||||
/* No lseek on pipes. */
|
||||
if (rfilp->filp_vno->v_pipe == I_PIPE) {
|
||||
if (S_ISFIFO(rfilp->filp_vno->v_mode)) {
|
||||
unlock_filp(rfilp);
|
||||
return(ESPIPE);
|
||||
}
|
||||
|
|
|
@ -105,7 +105,6 @@ int do_pipe()
|
|||
vp->v_inode_nr = res.inode_nr;
|
||||
vp->v_mapinode_nr = res.inode_nr;
|
||||
vp->v_mode = res.fmode;
|
||||
vp->v_pipe = I_PIPE;
|
||||
vp->v_pipe_rd_pos= 0;
|
||||
vp->v_pipe_wr_pos= 0;
|
||||
vp->v_fs_count = 1;
|
||||
|
|
|
@ -119,7 +119,7 @@ int read_write(int rw_flag, struct filp *f, char *buf, size_t size,
|
|||
|
||||
if (size > SSIZE_MAX) return(EINVAL);
|
||||
|
||||
if (vp->v_pipe == I_PIPE) {
|
||||
if (S_ISFIFO(vp->v_mode)) {
|
||||
if (fp->fp_cum_io_partial != 0) {
|
||||
panic("VFS: read_write: fp_cum_io_partial not clear");
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "fs.h"
|
||||
#include <sys/time.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/stat.h>
|
||||
#include <minix/com.h>
|
||||
#include <minix/u64.h>
|
||||
#include <string.h>
|
||||
|
@ -302,7 +303,7 @@ static int is_regular_file(struct filp *f)
|
|||
static int is_pipe(struct filp *f)
|
||||
{
|
||||
/* Recognize either anonymous pipe or named pipe (FIFO) */
|
||||
return(f && f->filp_vno && (f->filp_vno->v_mode & I_TYPE) == I_NAMED_PIPE);
|
||||
return(f && f->filp_vno && S_ISFIFO(f->filp_vno->v_mode));
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
|
|
|
@ -210,7 +210,7 @@ int do_fstat()
|
|||
if ((rfilp = get_filp(rfd, VNODE_READ)) == NULL) return(err_code);
|
||||
|
||||
/* If we read from a pipe, send position too */
|
||||
if (rfilp->filp_vno->v_pipe == I_PIPE) {
|
||||
if (S_ISFIFO(rfilp->filp_vno->v_mode)) {
|
||||
if (rfilp->filp_mode & R_BIT)
|
||||
if (ex64hi(rfilp->filp_pos) != 0) {
|
||||
panic("do_fstat: bad position in pipe");
|
||||
|
|
|
@ -89,7 +89,6 @@ struct vnode *get_free_vnode()
|
|||
|
||||
for (vp = &vnode[0]; vp < &vnode[NR_VNODES]; ++vp) {
|
||||
if (vp->v_ref_count == 0 && !is_vnode_locked(vp)) {
|
||||
vp->v_pipe = NO_PIPE;
|
||||
vp->v_uid = -1;
|
||||
vp->v_gid = -1;
|
||||
vp->v_sdev = NO_DEV;
|
||||
|
|
|
@ -16,7 +16,6 @@ EXTERN struct vnode {
|
|||
#if 0
|
||||
int v_ref_check; /* for consistency checks */
|
||||
#endif
|
||||
char v_pipe; /* set to I_PIPE if pipe */
|
||||
off_t v_pipe_rd_pos;
|
||||
off_t v_pipe_wr_pos;
|
||||
endpoint_t v_bfs_e; /* endpoint number for the FS proces in case
|
||||
|
@ -28,11 +27,6 @@ EXTERN struct vnode {
|
|||
tll_t v_lock; /* three-level-lock */
|
||||
} vnode[NR_VNODES];
|
||||
|
||||
|
||||
/* Field values. */
|
||||
#define NO_PIPE 0 /* i_pipe is NO_PIPE if inode is not a pipe */
|
||||
#define I_PIPE 1 /* i_pipe is I_PIPE if inode is a pipe */
|
||||
|
||||
/* vnode lock types mapping */
|
||||
#define VNODE_READ TLL_READ
|
||||
#define VNODE_OPCL TLL_READSER
|
||||
|
|
Loading…
Reference in a new issue