From: Thomas Veerman Date: Wed, 25 Apr 2012 12:44:42 +0000 (+0000) Subject: VFS: use S_IS* macros X-Git-Tag: v3.2.1~567 X-Git-Url: http://zhaoyanbai.com/repos/man.dnssec-verify.html?a=commitdiff_plain;h=db8198d99d7d1e5b3bfb474c9acae5add19f52af;p=minix.git VFS: use S_IS* macros --- diff --git a/servers/vfs/device.c b/servers/vfs/device.c index f08f7df66..0426d8d31 100644 --- a/servers/vfs/device.c +++ b/servers/vfs/device.c @@ -668,8 +668,7 @@ int do_ioctl() if ((f = get_filp(scratch(fp).file.fd_nr, VNODE_READ)) == NULL) return(err_code); vp = f->filp_vno; /* get vnode pointer */ - if ((vp->v_mode & I_TYPE) != I_CHAR_SPECIAL && - (vp->v_mode & I_TYPE) != I_BLOCK_SPECIAL) { + if (!S_ISCHR(vp->v_mode) && !S_ISBLK(vp->v_mode)) { r = ENOTTY; } @@ -677,7 +676,7 @@ int do_ioctl() suspend_reopen = (f->filp_state != FS_NORMAL); dev = (dev_t) vp->v_sdev; - if ((vp->v_mode & I_TYPE) == I_BLOCK_SPECIAL) + if (S_ISBLK(vp->v_mode)) r = bdev_ioctl(dev, who_e, ioctlrequest, argx); else r = dev_io(VFS_DEV_IOCTL, dev, who_e, argx, cvu64(0), @@ -1013,7 +1012,7 @@ void cdev_up(int maj) rfilp = rfp->fp_filp[fd_nr]; vp = rfilp->filp_vno; if (!vp) panic("VFS: cdev_up: no vp"); - if ((vp->v_mode & I_TYPE) != I_CHAR_SPECIAL) continue; + if (!S_ISCHR(vp->v_mode)) continue; if (major(vp->v_sdev) != maj) continue; rfp->fp_flags |= FP_SUSP_REOPEN; @@ -1066,7 +1065,7 @@ int maj; for (rfilp = filp; rfilp < &filp[NR_FILPS]; rfilp++) { if (rfilp->filp_count < 1 || !(vp = rfilp->filp_vno)) continue; if (rfilp->filp_state != FS_NEEDS_REOPEN) continue; - if ((vp->v_mode & I_TYPE) != I_CHAR_SPECIAL) continue; + if (!S_ISCHR(vp->v_mode)) continue; major_dev = major(vp->v_sdev); minor_dev = minor(vp->v_sdev); @@ -1131,7 +1130,7 @@ int maj; vp = rfilp->filp_vno; if (!vp) panic("VFS: restart_reopen: no vp"); - if ((vp->v_mode & I_TYPE) != I_CHAR_SPECIAL) continue; + if (!S_ISCHR(vp->v_mode)) continue; if (major(vp->v_sdev) != maj) continue; rfp->fp_blocked_on = FP_BLOCKED_ON_NONE; @@ -1181,7 +1180,7 @@ void reopen_reply() return; } - if ((vp->v_mode & I_TYPE) != I_CHAR_SPECIAL) { + if (!S_ISCHR(vp->v_mode)) { printf("VFS: reopen_reply: bad mode 0%o for filp number %d" " (from driver %d)\n", vp->v_mode, filp_no, driver_e); return; diff --git a/servers/vfs/exec.c b/servers/vfs/exec.c index 87fe6704a..fe174e5f0 100644 --- a/servers/vfs/exec.c +++ b/servers/vfs/exec.c @@ -149,7 +149,7 @@ static int get_read_vp(struct exec_info *execi, char *fullpath, unlock_vmnt(execi->vmp); - if ((execi->vp->v_mode & I_TYPE) != I_REGULAR) + if (!S_ISREG(execi->vp->v_mode)) return ENOEXEC; else if ((r = forbidden(fp, execi->vp, X_BIT)) != OK) return r; diff --git a/servers/vfs/filedes.c b/servers/vfs/filedes.c index 65f503124..59a66e2fc 100644 --- a/servers/vfs/filedes.c +++ b/servers/vfs/filedes.c @@ -531,7 +531,7 @@ struct filp *f; { /* Close a file. Will also unlock filp when done */ - int mode_word, rw; + int rw; dev_t dev; struct vnode *vp; @@ -543,10 +543,9 @@ struct filp *f; if (f->filp_count - 1 == 0 && f->filp_mode != FILP_CLOSED) { /* Check to see if the file is special. */ - mode_word = vp->v_mode & I_TYPE; - if (mode_word == I_CHAR_SPECIAL || mode_word == I_BLOCK_SPECIAL) { + if (S_ISCHR(vp->v_mode) || S_ISBLK(vp->v_mode)) { dev = (dev_t) vp->v_sdev; - if (mode_word == I_BLOCK_SPECIAL) { + if (S_ISBLK(vp->v_mode)) { lock_bsf(); if (vp->v_bfs_e == ROOT_FS_E) { /* Invalidate the cache unless the special is @@ -556,15 +555,11 @@ struct filp *f; req_flush(vp->v_bfs_e, dev); } unlock_bsf(); - } - /* Do any special processing on device close. - * Ignore any errors, even SUSPEND. - */ - if (mode_word == I_BLOCK_SPECIAL) - (void) bdev_close(dev); - else - (void) dev_close(dev, f-filp); + (void) bdev_close(dev); /* Ignore errors on close */ + } else { + (void) dev_close(dev, f-filp); /* Ignore errors */ + } f->filp_mode = FILP_CLOSED; } diff --git a/servers/vfs/link.c b/servers/vfs/link.c index d498affed..128dc1909 100644 --- a/servers/vfs/link.c +++ b/servers/vfs/link.c @@ -123,7 +123,7 @@ int do_unlink() assert(vmp != NULL); /* We must have locked the vmnt */ /* Make sure that the object is a directory */ - if ((dirp->v_mode & I_TYPE) != I_DIRECTORY) { + if (!S_ISDIR(dirp->v_mode)) { unlock_vnode(dirp); unlock_vmnt(vmp); put_vnode(dirp); @@ -455,7 +455,7 @@ struct fproc *rfp; if ((vp = eat_path(&resolve, rfp)) == NULL) return(err_code); /* Make sure this is a symbolic link */ - if ((vp->v_mode & I_TYPE) != I_SYMBOLIC_LINK) + if (!S_ISLNK(vp->v_mode)) r = EINVAL; else r = req_rdlink(vp->v_fs_e, vp->v_inode_nr, NONE, (vir_bytes) link_path, @@ -500,7 +500,7 @@ int do_rdlink() if ((vp = eat_path(&resolve, fp)) == NULL) return(err_code); /* Make sure this is a symbolic link */ - if ((vp->v_mode & I_TYPE) != I_SYMBOLIC_LINK) + if (!S_ISLNK(vp->v_mode)) r = EINVAL; else r = req_rdlink(vp->v_fs_e, vp->v_inode_nr, who_e, buf, buf_size, 0); diff --git a/servers/vfs/lock.c b/servers/vfs/lock.c index f710055d1..0551a8401 100644 --- a/servers/vfs/lock.c +++ b/servers/vfs/lock.c @@ -42,8 +42,8 @@ int req; /* either F_SETLK or F_SETLKW */ mo = f->filp_mode; if (ltype != F_UNLCK && ltype != F_RDLCK && ltype != F_WRLCK) return(EINVAL); if (req == F_GETLK && ltype == F_UNLCK) return(EINVAL); - if ( (f->filp_vno->v_mode & I_TYPE) != I_REGULAR && - (f->filp_vno->v_mode & I_TYPE) != I_BLOCK_SPECIAL) return(EINVAL); + if (!S_ISREG(f->filp_vno->v_mode) && !S_ISBLK(f->filp_vno->v_mode)) + return(EINVAL); if (req != F_GETLK && ltype == F_RDLCK && (mo & R_BIT) == 0) return(EBADF); if (req != F_GETLK && ltype == F_WRLCK && (mo & W_BIT) == 0) return(EBADF); diff --git a/servers/vfs/misc.c b/servers/vfs/misc.c index 3617ee042..9cfed86af 100644 --- a/servers/vfs/misc.c +++ b/servers/vfs/misc.c @@ -229,7 +229,7 @@ int do_fcntl() signed long offset; /* Check if it's a regular file. */ - if ((f->filp_vno->v_mode & I_TYPE) != I_REGULAR) r = EINVAL; + if (!S_ISREG(f->filp_vno->v_mode)) r = EINVAL; else if (!(f->filp_mode & W_BIT)) r = EBADF; else /* Copy flock data from userspace. */ @@ -495,7 +495,7 @@ static void free_proc(struct fproc *exiter, int flags) if ((rfilp = rfp->fp_filp[i]) == NULL) continue; if (rfilp->filp_mode == FILP_CLOSED) continue; vp = rfilp->filp_vno; - if ((vp->v_mode & I_TYPE) != I_CHAR_SPECIAL) continue; + if (!S_ISCHR(vp->v_mode)) continue; if ((dev_t) vp->v_sdev != dev) continue; lock_filp(rfilp, VNODE_READ); (void) dev_close(dev, rfilp-filp); /* Ignore any errors, even diff --git a/servers/vfs/mount.c b/servers/vfs/mount.c index ebf0d1f1e..d949543e1 100644 --- a/servers/vfs/mount.c +++ b/servers/vfs/mount.c @@ -173,7 +173,6 @@ endpoint_t fs_e, int rdonly, char mount_label[LABEL_MAX] ) { - int rdir, mdir; /* TRUE iff {root|mount} file is dir */ int i, r = OK, found, isroot, mount_root, con_reqs, slot; struct fproc *tfp, *rfp; struct dmap *dp; @@ -348,9 +347,7 @@ char mount_label[LABEL_MAX] ) } /* File types may not conflict. */ - mdir = ((vp->v_mode & I_TYPE) == I_DIRECTORY); /*TRUE iff dir*/ - rdir = ((root_node->v_mode & I_TYPE) == I_DIRECTORY); - if (!mdir && rdir) r = EISDIR; + if (!S_ISDIR(vp->v_mode) && S_ISDIR(root_node->v_mode)) r = EISDIR; /* If error, return the super block and both inodes; release the vmnt. */ if (r != OK) { @@ -582,7 +579,7 @@ static dev_t name_to_dev(int allow_mountpt, char path[PATH_MAX]) /* Request lookup */ if ((vp = eat_path(&resolve, fp)) == NULL) return(NO_DEV); - if ((vp->v_mode & I_TYPE) == I_BLOCK_SPECIAL) { + if (S_ISBLK(vp->v_mode)) { dev = vp->v_sdev; } else if (allow_mountpt && vp->v_vmnt->m_root_node == vp) { dev = vp->v_dev; diff --git a/servers/vfs/open.c b/servers/vfs/open.c index 4b70a509f..b057d8a6d 100644 --- a/servers/vfs/open.c +++ b/servers/vfs/open.c @@ -131,7 +131,7 @@ int common_open(char path[PATH_MAX], int oflags, mode_t omode) /* If O_CREATE is set, try to make the file. */ if (oflags & O_CREAT) { - omode = I_REGULAR | (omode & ALL_MODES & fp->fp_umask); + omode = I_REGULAR | (omode & ALLPERMS & fp->fp_umask); vp = new_node(&resolve, oflags, omode); r = err_code; if (r == OK) exist = FALSE; /* We just created the file */ @@ -166,8 +166,8 @@ int common_open(char path[PATH_MAX], int oflags, mode_t omode) /* Check protections. */ if ((r = forbidden(fp, vp, bits)) == OK) { /* Opening reg. files, directories, and special files differ */ - switch (vp->v_mode & I_TYPE) { - case I_REGULAR: + switch (vp->v_mode & S_IFMT) { + case S_IFREG: /* Truncate regular file if O_TRUNC. */ if (oflags & O_TRUNC) { if ((r = forbidden(fp, vp, W_BIT)) != OK) @@ -175,11 +175,11 @@ int common_open(char path[PATH_MAX], int oflags, mode_t omode) truncate_vnode(vp, 0); } break; - case I_DIRECTORY: + case S_IFDIR: /* Directories may be read but not written. */ r = (bits & W_BIT ? EISDIR : OK); break; - case I_CHAR_SPECIAL: + case S_IFCHR: /* Invoke the driver for special processing. */ dev = (dev_t) vp->v_sdev; /* TTY needs to know about the O_NOCTTY flag. */ @@ -188,7 +188,7 @@ int common_open(char path[PATH_MAX], int oflags, mode_t omode) else vp = filp->filp_vno; /* Might be updated by * dev_open/clone_opcl */ break; - case I_BLOCK_SPECIAL: + case S_IFBLK: lock_bsf(); @@ -240,7 +240,7 @@ int common_open(char path[PATH_MAX], int oflags, mode_t omode) unlock_bsf(); break; - case I_NAMED_PIPE: + case S_IFIFO: /* Create a mapped inode on PFS which handles reads and writes to this named pipe. */ tll_upgrade(&vp->v_lock); @@ -547,7 +547,7 @@ int do_mknod() 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); + bits = (mode_bits & S_IFMT) | (mode_bits & ACCESSPERMS & fp->fp_umask); /* Open directory that's going to hold the new node. */ if (fetch_name(vname1, vname1_length, fullpath) != OK) return(err_code); diff --git a/servers/vfs/path.c b/servers/vfs/path.c index 7ecdb2895..6e8c2f8df 100644 --- a/servers/vfs/path.c +++ b/servers/vfs/path.c @@ -552,9 +552,7 @@ char ename[NAME_MAX + 1]; pos = make64(0, 0); - if ((dirp->v_mode & I_TYPE) != I_DIRECTORY) { - return(EBADF); - } + if (!S_ISDIR(dirp->v_mode)) return(EBADF); do { r = req_getdents(dirp->v_fs_e, dirp->v_inode_nr, pos, buf, sizeof(buf), diff --git a/servers/vfs/protect.c b/servers/vfs/protect.c index 90c77ebb0..c480d2697 100644 --- a/servers/vfs/protect.c +++ b/servers/vfs/protect.c @@ -9,6 +9,7 @@ */ #include "fs.h" +#include #include #include #include "file.h" @@ -268,8 +269,7 @@ int forbidden(struct fproc *rfp, struct vnode *vp, mode_t access_desired) * directories. Grant execute permission (for non-directories) if * and only if one of the 'X' bits is set. */ - if ( (bits & I_TYPE) == I_DIRECTORY || - bits & ((X_BIT << 6) | (X_BIT << 3) | X_BIT)) + if ( S_ISDIR(bits) || bits & ((X_BIT << 6) | (X_BIT << 3) | X_BIT)) perm_bits = R_BIT | W_BIT | X_BIT; else perm_bits = R_BIT | W_BIT; diff --git a/servers/vfs/read.c b/servers/vfs/read.c index c112582dc..a0024ed9c 100644 --- a/servers/vfs/read.c +++ b/servers/vfs/read.c @@ -108,8 +108,7 @@ int read_write(int rw_flag, struct filp *f, char *buf, size_t size, register struct vnode *vp; u64_t position, res_pos, new_pos; unsigned int cum_io, cum_io_incr, res_cum_io; - int op, oflags, r, block_spec, char_spec, regular; - mode_t mode_word; + int op, oflags, r; position = f->filp_pos; oflags = f->filp_flags; @@ -128,23 +127,14 @@ int read_write(int rw_flag, struct filp *f, char *buf, size_t size, } op = (rw_flag == READING ? VFS_DEV_READ : VFS_DEV_WRITE); - mode_word = vp->v_mode & I_TYPE; - regular = mode_word == I_REGULAR; - if ((char_spec = (mode_word == I_CHAR_SPECIAL ? 1 : 0))) { - if (vp->v_sdev == NO_DEV) - panic("VFS: read_write tries to access char dev NO_DEV"); - } - - if ((block_spec = (mode_word == I_BLOCK_SPECIAL ? 1 : 0))) { - if (vp->v_sdev == NO_DEV) - panic("VFS: read_write tries to access block dev NO_DEV"); - } - - if (char_spec) { /* Character special files. */ + if (S_ISCHR(vp->v_mode)) { /* Character special files. */ dev_t dev; int suspend_reopen; + if (vp->v_sdev == NO_DEV) + panic("VFS: read_write tries to access char dev NO_DEV"); + suspend_reopen = (f->filp_state != FS_NORMAL); dev = (dev_t) vp->v_sdev; @@ -155,7 +145,10 @@ int read_write(int rw_flag, struct filp *f, char *buf, size_t size, position = add64ul(position, r); r = OK; } - } else if (block_spec) { /* Block special files. */ + } else if (S_ISBLK(vp->v_mode)) { /* Block special files. */ + if (vp->v_sdev == NO_DEV) + panic("VFS: read_write tries to access block dev NO_DEV"); + lock_bsf(); r = req_breadwrite(vp->v_bfs_e, for_e, vp->v_sdev, position, size, @@ -167,7 +160,7 @@ int read_write(int rw_flag, struct filp *f, char *buf, size_t size, unlock_bsf(); } else { /* Regular files */ - if (rw_flag == WRITING && block_spec == 0) { + if (rw_flag == WRITING) { /* Check for O_APPEND flag. */ if (oflags & O_APPEND) position = cvul64(vp->v_size); } @@ -187,7 +180,7 @@ int read_write(int rw_flag, struct filp *f, char *buf, size_t size, /* On write, update file size and access time. */ if (rw_flag == WRITING) { - if (regular || mode_word == I_DIRECTORY) { + if (S_ISREG(vp->v_mode) || S_ISDIR(vp->v_mode)) { if (cmp64ul(position, vp->v_size) > 0) { if (ex64hi(position) != 0) { panic("read_write: file size too big "); @@ -223,7 +216,7 @@ int do_getdents() if (!(rfilp->filp_mode & R_BIT)) r = EBADF; - else if ((rfilp->filp_vno->v_mode & I_TYPE) != I_DIRECTORY) + else if (!S_ISDIR(rfilp->filp_vno->v_mode)) r = EBADF; if (r == OK) { diff --git a/servers/vfs/select.c b/servers/vfs/select.c index 1e6c26c08..c1290fbfc 100644 --- a/servers/vfs/select.c +++ b/servers/vfs/select.c @@ -294,7 +294,7 @@ static int is_deferred(struct selectentry *se) *===========================================================================*/ static int is_regular_file(struct filp *f) { - return(f && f->filp_vno && (f->filp_vno->v_mode & I_TYPE) == I_REGULAR); + return(f && f->filp_vno && S_ISREG(f->filp_vno->v_mode)); } /*===========================================================================* @@ -315,7 +315,7 @@ static int is_supported_major(struct filp *f) unsigned int m; if (!(f && f->filp_vno)) return(FALSE); - if ((f->filp_vno->v_mode & I_TYPE) != I_CHAR_SPECIAL) return(FALSE); + if (!S_ISCHR(f->filp_vno->v_mode)) return(FALSE); for (m = 0; m < SEL_MAJORS; m++) if (major(f->filp_vno->v_sdev) == select_majors[m]) @@ -785,7 +785,7 @@ int status; /* Find vnode and check we got a reply from the device we expected */ vp = f->filp_vno; assert(vp != NULL); - assert((vp->v_mode & I_TYPE) == I_CHAR_SPECIAL); + assert(S_ISCHR(vp->v_mode)); if (vp->v_sdev != dev) { printf("VFS (%s:%d): expected reply from dev %d not %d\n", __FILE__, __LINE__, vp->v_sdev, dev); @@ -882,7 +882,7 @@ int status; for (fd = 0; fd < se->nfds; fd++) { if ((f = se->filps[fd]) == NULL) continue; if ((vp = f->filp_vno) == NULL) continue; - if ((vp->v_mode & I_TYPE) != I_CHAR_SPECIAL) continue; + if (!S_ISCHR(vp->v_mode)) continue; if (vp->v_sdev != dev) continue; select_lock_filp(f, f->filp_select_ops); @@ -945,7 +945,7 @@ static void select_restart_filps() wantops = ops = f->filp_select_ops; vp = f->filp_vno; - assert((vp->v_mode & I_TYPE) == I_CHAR_SPECIAL); + assert(S_ISCHR(vp->v_mode)); r = do_select_request(se, fd, &wantops); if (r != OK && r != SUSPEND) break; /* Error or bogus return code; abort */ diff --git a/servers/vfs/stadir.c b/servers/vfs/stadir.c index 28eae3d08..793b7a825 100644 --- a/servers/vfs/stadir.c +++ b/servers/vfs/stadir.c @@ -140,7 +140,7 @@ static int change_into(struct vnode **result, struct vnode *vp) if (*result == vp) return(OK); /* Nothing to do */ /* It must be a directory and also be searchable */ - if ((vp->v_mode & I_TYPE) != I_DIRECTORY) + if (!S_ISDIR(vp->v_mode)) r = ENOTDIR; else r = forbidden(fp, vp, X_BIT); /* Check if dir is searchable*/