コード例 #1
0
ファイル: time.c プロジェクト: QiuLihua83/minix2009
/*===========================================================================*
 *				do_utime				     *
 *===========================================================================*/
PUBLIC int do_utime()
{
/* Perform the utime(name, timep) system call. */
  register int len;
  int r;
  uid_t uid;
  time_t actime, modtime;
  struct vnode *vp;
  
  /* Adjust for case of 'timep' being NULL;
   * utime_strlen then holds the actual size: strlen(name)+1.
   */
  len = m_in.utime_length;
  if (len == 0) len = m_in.utime_strlen;

  if (fetch_name(m_in.utime_file, len, M1) != OK) return(err_code);
  
  /* Request lookup */
  if ((r = lookup_vp(0 /*flags*/, 0 /*!use_realuid*/, &vp)) != OK) return r;

  /* Fill in request fields.*/
  if (m_in.utime_length == 0) {
        actime = modtime = clock_time();
  } else {
        actime = m_in.utime_actime;
        modtime = m_in.utime_modtime;
  }

  uid= fp->fp_effuid;

  r= OK;
  if (vp->v_uid != uid && uid != SU_UID) r = EPERM;
  if (m_in.utime_length == 0 && r != OK)
  {
	/* With a null times pointer, updating the times (to the current time)
	 * is allow if the object is writable. 
	 */
	r = forbidden(vp, W_BIT, 0 /*!use_realuid*/);
  }

  if (r != OK)
  {
	put_vnode(vp);
	return r;
  }
  
  /* Issue request */
  r= req_utime(vp->v_fs_e, vp->v_inode_nr, actime, modtime);
  put_vnode(vp);
  return r;
}
コード例 #2
0
ファイル: time.c プロジェクト: CesarBallardini/minix3
/*===========================================================================*
 *				do_utime				     *
 *===========================================================================*/
PUBLIC int do_utime()
{
/* Perform the utime(name, timep) system call. */
  register int len;
  int r;
  time_t actime, modtime;
  struct vnode *vp;
  struct vmnt *vmp;
  char fullpath[PATH_MAX];
  struct lookup resolve;

  lookup_init(&resolve, fullpath, PATH_NOFLAGS, &vmp, &vp);
  resolve.l_vmnt_lock = VMNT_WRITE;
  resolve.l_vnode_lock = VNODE_READ;

  /* Adjust for case of 'timep' being NULL;
   * utime_strlen then holds the actual size: strlen(name)+1 */
  len = m_in.utime_length;
  if (len == 0) len = m_in.utime_strlen;

  /* Temporarily open the file */
  if (fetch_name(m_in.utime_file, len, M1, fullpath) != OK) return(err_code);
  if ((vp = eat_path(&resolve, fp)) == NULL) return(err_code);

  /* Only the owner of a file or the super user can change its name. */
  r = OK;
  if (vp->v_uid != fp->fp_effuid && fp->fp_effuid != SU_UID) r = EPERM;
  if (m_in.utime_length == 0 && r != OK) r = forbidden(fp, vp, W_BIT);
  if (read_only(vp) != OK) r = EROFS; /* Not even su can touch if R/O */
  if (r == OK) {
	/* Issue request */
	if(m_in.utime_length == 0) {
		actime = modtime = clock_time();
	} else {
		actime = m_in.utime_actime;
		modtime = m_in.utime_modtime;
	}
	r = req_utime(vp->v_fs_e, vp->v_inode_nr, actime, modtime);
  }

  unlock_vnode(vp);
  unlock_vmnt(vmp);

  put_vnode(vp);
  return(r);
}
コード例 #3
0
ファイル: time.c プロジェクト: locosoft1986/nucleos
/*===========================================================================*
 *				scall_utime				     *
 *===========================================================================*/
int scall_utime(void)
{
	/* Perform the utime(name, timep) system call. */
	register int len;
	int r;
	time_t actime, modtime;
	struct utimbuf ut;
	struct vnode *vp;

	/* Adjust for case of 'timep' being NULL. */
	if (fetch_name(user_fullpath, PATH_MAX, m_in.utime_file) < 0)
		return(err_code);

	if ((vp = eat_path(PATH_NOFLAGS)) == NIL_VNODE) return(err_code);

	/* get times buffer if not 0 */
	if (m_in.utime_ptimes != 0) {
		r = sys_datacopy(who_e, (vir_bytes)m_in.utime_ptimes, ENDPT_SELF, (vir_bytes)&ut, sizeof(struct utimbuf));

		if (r != 0)
			return r;
	}

	/* Only the owner of a file or the super user can change its name. */
	r = 0;
	if (vp->v_uid != fp->fp_effuid && fp->fp_effuid != SU_UID) r = -EPERM;
	if (m_in.utime_ptimes == 0 && r != 0) r = forbidden(vp, W_BIT);
	if (read_only(vp) != 0) r = -EROFS; /* Not even su can touch if R/O */

	if (r == 0) {
		/* Issue request */
		if (m_in.utime_ptimes == 0) {
			actime = modtime = clock_time();
		} else {
			actime = ut.actime;
			modtime = ut.modtime;
		}
		r = req_utime(vp->v_fs_e, vp->v_inode_nr, actime, modtime);
	}

	put_vnode(vp);

	return(r);
}
コード例 #4
0
ファイル: time.c プロジェクト: michalwojciech/cs170s10proj2
/*===========================================================================*
 *				do_utime				     *
 *===========================================================================*/
PUBLIC int do_utime()
{
/* Perform the utime(name, timep) system call. */
  register int len;
  int r;
  uid_t uid;
  time_t actime, modtime;
  struct vnode *vp;
  
  /* Adjust for case of 'timep' being NULL;
   * utime_strlen then holds the actual size: strlen(name)+1 */
  len = m_in.utime_length;
  if(len == 0) len = m_in.utime_strlen;

  /* Temporarily open the file */
  if (fetch_name(m_in.utime_file, len, M1) != OK) return(err_code);
  if ((vp = eat_path(PATH_NOFLAGS)) == NIL_VNODE) return(err_code);

  /* Only the owner of a file or the super user can change its name. */  
  r = OK;
  if (vp->v_uid != fp->fp_effuid && fp->fp_effuid != SU_UID) r = EPERM;
  if (m_in.utime_length == 0 && r != OK) r = forbidden(vp, W_BIT);
  if (read_only(vp) != OK) r = EROFS; /* Not even su can touch if R/O */ 
  if (r == OK) {
	/* Issue request */
	if(m_in.utime_length == 0) {
		actime = modtime = clock_time();
	} else {
		actime = m_in.utime_actime;
		modtime = m_in.utime_modtime;
	}
	r = req_utime(vp->v_fs_e, vp->v_inode_nr, actime, modtime);
  }

  put_vnode(vp);
  return(r);
}