VFS: use S_IS* macros
This commit is contained in:
parent
96bbc5da3e
commit
db8198d99d
13 changed files with 52 additions and 70 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
*/
|
||||
|
||||
#include "fs.h"
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <minix/callnr.h>
|
||||
#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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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*/
|
||||
|
|
Loading…
Reference in a new issue