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;
}
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),
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;
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);
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;
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;
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;
{
/* Close a file. Will also unlock filp when done */
- int mode_word, rw;
+ int rw;
dev_t dev;
struct vnode *vp;
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
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;
}
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);
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,
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);
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);
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. */
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
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;
}
/* 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) {
/* 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;
/* 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 */
/* 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)
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. */
else vp = filp->filp_vno; /* Might be updated by
* dev_open/clone_opcl */
break;
- case I_BLOCK_SPECIAL:
+ case S_IFBLK:
lock_bsf();
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);
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);
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),
*/
#include "fs.h"
+#include <sys/stat.h>
#include <unistd.h>
#include <minix/callnr.h>
#include "file.h"
* 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;
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;
}
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;
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,
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);
}
/* 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 ");
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) {
*===========================================================================*/
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));
}
/*===========================================================================*
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])
/* 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);
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);
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 */
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*/