From: Thomas Veerman Date: Mon, 16 Apr 2012 09:04:32 +0000 (+0000) Subject: VFS: I_PIPE is redundant X-Git-Tag: v3.2.1~568 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/verify-sign/verify.pl?a=commitdiff_plain;h=96bbc5da3ec6919dfc5c898ea0ea607e1df86f1e;p=minix.git VFS: I_PIPE is redundant Also, use S_IS* macros instead of manual comparison. --- diff --git a/servers/vfs/filedes.c b/servers/vfs/filedes.c index a3a820a0a..65f503124 100644 --- a/servers/vfs/filedes.c +++ b/servers/vfs/filedes.c @@ -19,6 +19,7 @@ #include #include #include +#include #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. */ diff --git a/servers/vfs/link.c b/servers/vfs/link.c index c343bce4c..d498affed 100644 --- a/servers/vfs/link.c +++ b/servers/vfs/link.c @@ -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 diff --git a/servers/vfs/open.c b/servers/vfs/open.c index 267c2bb4e..4b70a509f 100644 --- a/servers/vfs/open.c +++ b/servers/vfs/open.c @@ -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); } diff --git a/servers/vfs/pipe.c b/servers/vfs/pipe.c index 54274154c..d1cd7c0fc 100644 --- a/servers/vfs/pipe.c +++ b/servers/vfs/pipe.c @@ -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; diff --git a/servers/vfs/read.c b/servers/vfs/read.c index 7e72cbe04..c112582dc 100644 --- a/servers/vfs/read.c +++ b/servers/vfs/read.c @@ -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"); } diff --git a/servers/vfs/select.c b/servers/vfs/select.c index 3b2712f67..1e6c26c08 100644 --- a/servers/vfs/select.c +++ b/servers/vfs/select.c @@ -9,6 +9,7 @@ #include "fs.h" #include #include +#include #include #include #include @@ -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)); } /*===========================================================================* diff --git a/servers/vfs/stadir.c b/servers/vfs/stadir.c index 5f8003f01..28eae3d08 100644 --- a/servers/vfs/stadir.c +++ b/servers/vfs/stadir.c @@ -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"); diff --git a/servers/vfs/vnode.c b/servers/vfs/vnode.c index 14539e89a..7d8b4dc1d 100644 --- a/servers/vfs/vnode.c +++ b/servers/vfs/vnode.c @@ -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; diff --git a/servers/vfs/vnode.h b/servers/vfs/vnode.h index babb6aab4..bcea1f063 100644 --- a/servers/vfs/vnode.h +++ b/servers/vfs/vnode.h @@ -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