⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 time.c

📁 一个简单的操作系统minix的核心代码
💻 C
字号:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
				src/fs/time.c	 	 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

26400	/* This file takes care of those system calls that deal with time.
26401	 *
26402	 * The entry points into this file are
26403	 *   do_utime:  perform the UTIME system call
26404	 *   do_time:   perform the TIME system call
26405	 *   do_stime:  perform the STIME system call
26406	 *   do_tims:   perform the TIMES system call
26407	 */
26408	
26409	#include "fs.h"
26410	#include <minix/callnr.h>
26411	#include <minix/com.h>
26412	#include "file.h"
26413	#include "fproc.h"
26414	#include "inode.h"
26415	#include "param.h"
26416	
26417	PRIVATE message clock_mess;
26418	
26419	/*===========================================================================*
26420	 *                              do_utime                                     *
26421	 *===========================================================================*/
26422	PUBLIC int do_utime()
26423	{
26424	/* Perform the utime(name, timep) system call. */
26425	
26426	  register struct inode *rip;
26427	  register int len, r;
26428	
26429	  /* Adjust for case of NULL 'timep'. */
26430	  len = utime_length;
26431	  if (len == 0) len = m.m2_i2;
26432	
26433	  /* Temporarily open the file. */
26434	  if (fetch_name(utime_file, len, M1) != OK) return(err_code);
26435	  if ( (rip = eat_path(user_path)) == NIL_INODE) return(err_code);
26436	
26437	  /* Only the owner of a file or the super_user can change its time. */
26438	  r = OK;
26439	  if (rip->i_uid != fp->fp_effuid && !super_user) r = EPERM;
26440	  if (utime_length == 0 && r != OK) r = forbidden(rip, W_BIT);
26441	  if (read_only(rip) != OK) r = EROFS;  /* not even su can touch if R/O */
26442	  if (r == OK) {
26443	        if (utime_length == 0) {
26444	                rip->i_atime = clock_time();
26445	                rip->i_mtime = rip->i_atime;
26446	        } else {
26447	                rip->i_atime = utime_actime;
26448	                rip->i_mtime = utime_modtime;
26449	        }
26450	        rip->i_update = CTIME;  /* discard any stale ATIME and MTIME flags */
26451	        rip->i_dirt = DIRTY;
26452	  }
26453	
26454	  put_inode(rip);
26455	  return(r);
26456	}
	
	
26459	/*===========================================================================*
26460	 *                              do_time                                      *
26461	 *===========================================================================*/
26462	PUBLIC int do_time()
26463	
26464	{
26465	/* Perform the time(tp) system call. */
26466	
26467	  reply_l1 = clock_time();      /* return time in seconds */
26468	  return(OK);
26469	}
	
	
26472	/*===========================================================================*
26473	 *                              do_stime                                     *
26474	 *===========================================================================*/
26475	PUBLIC int do_stime()
26476	{
26477	/* Perform the stime(tp) system call. */
26478	
26479	  register int k;
26480	
26481	  if (!super_user) return(EPERM);
26482	  clock_mess.m_type = SET_TIME;
26483	  clock_mess.NEW_TIME = (long) tp;
26484	  if ( (k = sendrec(CLOCK, &clock_mess)) != OK) panic("do_stime error", k);
26485	  return(OK);
26486	}
	
	
26489	/*===========================================================================*
26490	 *                              do_tims                                      *
26491	 *===========================================================================*/
26492	PUBLIC int do_tims()
26493	{
26494	/* Perform the times(buffer) system call. */
26495	
26496	  clock_t t[5];
26497	
26498	  sys_times(who, t);
26499	  reply_t1 = t[0];
26500	  reply_t2 = t[1];
26501	  reply_t3 = t[2];
26502	  reply_t4 = t[3];
26503	  reply_t5 = t[4];
26504	  return(OK);
26505	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -