예제 #1
0
파일: misc.c 프로젝트: Hooman3/minix
/*===========================================================================*
 *				do_fsync				     *
 *===========================================================================*/
int do_fsync(void)
{
/* Perform the fsync() system call. */
  struct filp *rfilp;
  struct vmnt *vmp;
  dev_t dev;
  int r = OK;

  scratch(fp).file.fd_nr = job_m_in.m_lc_vfs_fsync.fd;

  if ((rfilp = get_filp(scratch(fp).file.fd_nr, VNODE_READ)) == NULL)
	return(err_code);

  dev = rfilp->filp_vno->v_dev;
  unlock_filp(rfilp);

  for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; ++vmp) {
	if (vmp->m_dev != dev) continue;
	if ((r = lock_vmnt(vmp, VMNT_READ)) != OK)
		break;
	if (vmp->m_dev != NO_DEV && vmp->m_dev == dev &&
		vmp->m_fs_e != NONE && vmp->m_root_node != NULL) {

		req_sync(vmp->m_fs_e);
	}
	unlock_vmnt(vmp);
  }

  return(r);
}
예제 #2
0
/*===========================================================================*
 *				do_fsync				     *
 *===========================================================================*/
PUBLIC int do_fsync()
{
/* Perform the fsync() system call. */
  struct filp *rfilp;
  struct vmnt *vmp;
  dev_t dev;
  int r = OK;

  if ((rfilp = get_filp(m_in.m1_i1, VNODE_READ)) == NULL) return(err_code);
  dev = rfilp->filp_vno->v_dev;
  for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; ++vmp) {
	if (vmp->m_dev != NO_DEV && vmp->m_dev == dev &&
		vmp->m_fs_e != NONE && vmp->m_root_node != NULL) {

		if ((r = lock_vmnt(vmp, VMNT_EXCL)) != OK)
			break;
		req_sync(vmp->m_fs_e);
		unlock_vmnt(vmp);
	}
  }

  unlock_filp(rfilp);

  return(r);
}
예제 #3
0
파일: misc.c 프로젝트: mwilbur/minix
/*===========================================================================*
 *				do_sync					     *
 *===========================================================================*/
PUBLIC int do_sync()
{
  struct vmnt *vmp;
  for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; ++vmp) 
	  if (vmp->m_dev != NO_DEV) 
                  req_sync(vmp->m_fs_e);

  return(OK);
}
예제 #4
0
파일: misc.c 프로젝트: Hooman3/minix
/*===========================================================================*
 *				do_sync					     *
 *===========================================================================*/
int do_sync(void)
{
  struct vmnt *vmp;
  int r = OK;

  for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; ++vmp) {
	if ((r = lock_vmnt(vmp, VMNT_READ)) != OK)
		break;
	if (vmp->m_dev != NO_DEV && vmp->m_fs_e != NONE &&
		 vmp->m_root_node != NULL) {
		req_sync(vmp->m_fs_e);
	}
	unlock_vmnt(vmp);
  }

  return(r);
}
예제 #5
0
파일: mount.c 프로젝트: boostsup/minix3
/*===========================================================================*
 *                              mount                                        *
 *===========================================================================*/
PRIVATE int mount_fs(endpoint_t fs_e)
{
/* Perform the mount(name, mfile, rd_only) system call. */
  int rdir, mdir;               /* TRUE iff {root|mount} file is dir */
  int i, r, found, isroot, replace_root;
  struct fproc *tfp;
  struct dmap *dp;
  dev_t dev;
  message m;
  struct vnode *root_node, *mounted_on = NULL, *bspec;
  struct vmnt *vmp;
  char *label;
  struct node_details res;

  SANITYCHECK;
  
  /* Only the super-user may do MOUNT. */
  if (!super_user) return(EPERM);

  /* If FS not yet logged in, save message and suspend mount */
  if (last_login_fs_e != fs_e) {
      mount_m_in = m_in; 
      return SUSPEND;
  }
  
  /* Mount request got after FS login or 
   * FS login arrived after a suspended mount */
  last_login_fs_e = NONE;
  
  /* Clear endpoint field */
  mount_m_in.m1_p3 = (char *) NONE;

  /* If 'name' is not for a block special file, return error. */
  if (fetch_name(m_in.name1, m_in.name1_length, M1) != OK) return(err_code);
  
  /* Convert name to device number */
  if ((dev = name_to_dev()) == NO_DEV) return(err_code);

  /* Check whether there is a block special file open which uses the 
   * same device (partition) */
  for (bspec = &vnode[0]; bspec < &vnode[NR_VNODES]; ++bspec) {
      if (bspec->v_ref_count > 0 && bspec->v_sdev == dev) {
          /* Found, sync the buffer cache */
          req_sync(bspec->v_fs_e);          
          break;
          /* Note: there are probably some blocks in the FS process' buffer
           * cache which contain data on this minor, although they will be
           * purged since the handling moves to the new FS process (if
           * everything goes well with the mount...)
           */ 
      }
  }
  /* Didn't find? */
  if (bspec == &vnode[NR_VNODES] && bspec->v_sdev != dev)
      bspec = NULL;
  
  /* Scan vmnt table to see if dev already mounted, if not, 
   * find a free slot.*/
  found = FALSE; 
  vmp = NIL_VMNT;
  for (i = 0; i < NR_MNTS; ++i) {
        if (vmnt[i].m_dev == dev) {
            vmp = &vmnt[i];
            found = TRUE;
            break;
        }
        else if (!vmp && vmnt[i].m_dev == NO_DEV) {
            vmp = &vmnt[i];
        }
  }

  /* Partition was/is already mounted */
  if (found) {
	/* It is possible that we have an old root lying around that 
	 * needs to be remounted. */
	if (vmp->m_mounted_on || vmp->m_mounted_on == fproc[FS_PROC_NR].fp_rd) {
		/* Normally, m_mounted_on refers to the mount point. For a
		 * root filesystem, m_mounted_on is equal to the root vnode.
		 * We assume that the root of FS is always the real root. If
		 * the two vnodes are different or if the root of FS is equal
		 * to the root of the filesystem we found, we found a
		 * filesystem that is in use.
		 */
		return EBUSY;   /* already mounted */
	}

	if(vmp->m_mounted_on)
		panic("vfs", "root unexpectedly mounted somewhere", NO_NUM);

	if (root_dev == vmp->m_dev)
		panic("fs", "inconsistency remounting old root", NO_NUM);

	/* Now get the inode of the file to be mounted on. */
	if (fetch_name(m_in.name2, m_in.name2_length, M1) != OK) {
		return(err_code);
	}

	/* Request lookup */
	r = lookup_vp(0 /*flags*/, 0 /*!use_realuid*/, &mounted_on);
	if (r != OK) return r;

	if (mounted_on->v_ref_count != 1)
	{
		put_vnode(mounted_on);
		printf("vfs:mount_fs: mount point is busy\n");
		return EBUSY;
	}

	/* Issue mountpoint request */
	r = req_mountpoint(mounted_on->v_fs_e, mounted_on->v_inode_nr);
	if (r != OK)
	{
		put_vnode(mounted_on);
		printf("vfs:mount_fs: req_mountpoint_s failed with %d\n", r);
		return r;
	}

	/* Get the root inode of the mounted file system. */
	root_node = vmp->m_root_node;

	/* File types may not conflict. */
	if (r == OK) {
		mdir = ((mounted_on->v_mode & I_TYPE) == I_DIRECTORY); 
		/* TRUE iff dir */
		rdir = ((root_node->v_mode & I_TYPE) == I_DIRECTORY);
		if (!mdir && rdir) r = EISDIR;
	}

	/* If error, return the mount point. */
	if (r != OK) {
		put_vnode(mounted_on);

		return(r);
	}

	/* Nothing else can go wrong.  Perform the mount. */
	vmp->m_mounted_on = mounted_on;
	vmp->m_flags = m_in.rd_only;
	allow_newroot = 0;              /* The root is now fixed */

	return(OK);
  }

  /* Fetch the name of the mountpoint */
  if (fetch_name(m_in.name2, m_in.name2_length, M1) != OK) {
	return(err_code);
  }

  isroot= (strcmp(user_fullpath, "/") == 0);
  replace_root= (isroot && allow_newroot);

  if (!replace_root)
  {
	/* Get mount point and inform the FS it is on. */
#if 0
	printf("vfs:mount_fs: mount point at '%s'\n", user_fullpath);
#endif

	r = lookup_vp(0 /*flags*/, 0 /*!use_realuid*/, &mounted_on);
	if (r != OK)
		return r;

	/* Issue mountpoint request */
	r = req_mountpoint(mounted_on->v_fs_e, mounted_on->v_inode_nr);
	if (r != OK) {
		put_vnode(mounted_on);
		printf("vfs:mount_fs: req_mountpoint_s failed with %d\n", r);
		return r;
	}
  }

  /* We'll need a vnode for the root inode, check whether there is one */
  if ((root_node = get_free_vnode(__FILE__, __LINE__)) == NIL_VNODE) {
        printf("VFSmount: no free vnode available\n");
        return ENFILE;
  }
  

  /* Get driver process' endpoint */  
  dp = &dmap[(dev >> MAJOR) & BYTE];
  if (dp->dmap_driver == NONE) {
        printf("VFSmount: no driver for dev %x\n", dev);
        return(EINVAL);
  }
  label= dp->dmap_label;
  if (strlen(label) == 0)
  {
	panic(__FILE__, "vfs:mount_fs: no label for major", dev >> MAJOR);
  }