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

📄 inode.c

📁 一个简单的操作系统minix的核心代码
💻 C
📖 第 1 页 / 共 2 页
字号:
21693	  /* Locate the appropriate super_block. */
21694	  sp = get_super(dev);
21695	  if (inumb <= 0 || inumb > sp->s_ninodes) return;
21696	  b = inumb;
21697	  free_bit(sp, IMAP, b);
21698	  if (b < sp->s_isearch) sp->s_isearch = b;
21699	}
	
21701	/*===========================================================================*
21702	 *                              update_times                                 *
21703	 *===========================================================================*/
21704	PUBLIC void update_times(rip)
21705	register struct inode *rip;     /* pointer to inode to be read/written */
21706	{
21707	/* Various system calls are required by the standard to update atime, ctime,
21708	 * or mtime.  Since updating a time requires sending a message to the clock
21709	 * task--an expensive business--the times are marked for update by setting
21710	 * bits in i_update.  When a stat, fstat, or sync is done, or an inode is 
21711	 * released, update_times() may be called to actually fill in the times.
21712	 */
21713	
21714	  time_t cur_time;
21715	  struct super_block *sp;
21716	
21717	  sp = rip->i_sp;               /* get pointer to super block. */
21718	  if (sp->s_rd_only) return;    /* no updates for read-only file systems */
21719	
21720	  cur_time = clock_time();
21721	  if (rip->i_update & ATIME) rip->i_atime = cur_time;
21722	  if (rip->i_update & CTIME) rip->i_ctime = cur_time;
21723	  if (rip->i_update & MTIME) rip->i_mtime = cur_time;
21724	  rip->i_update = 0;            /* they are all up-to-date now */
21725	}
	
	
21728	/*===========================================================================*
21729	 *                              rw_inode                                     *
21730	 *===========================================================================*/
21731	PUBLIC void rw_inode(rip, rw_flag)
21732	register struct inode *rip;     /* pointer to inode to be read/written */
21733	int rw_flag;                    /* READING or WRITING */
21734	{
21735	/* An entry in the inode table is to be copied to or from the disk. */
21736	
21737	  register struct buf *bp;
21738	  register struct super_block *sp;
21739	  d1_inode *dip;
21740	  d2_inode *dip2;
21741	  block_t b, offset;
21742	
21743	  /* Get the block where the inode resides. */
21744	  sp = get_super(rip->i_dev);   /* get pointer to super block */
21745	  rip->i_sp = sp;               /* inode must contain super block pointer */
21746	  offset = sp->s_imap_blocks + sp->s_zmap_blocks + 2;
21747	  b = (block_t) (rip->i_num - 1)/sp->s_inodes_per_block + offset;
21748	  bp = get_block(rip->i_dev, b, NORMAL);
21749	  dip  = bp->b_v1_ino + (rip->i_num - 1) % V1_INODES_PER_BLOCK;
21750	  dip2 = bp->b_v2_ino + (rip->i_num - 1) % V2_INODES_PER_BLOCK;
21751	
21752	  /* Do the read or write. */
21753	  if (rw_flag == WRITING) {
21754	        if (rip->i_update) update_times(rip);   /* times need updating */
21755	        if (sp->s_rd_only == FALSE) bp->b_dirt = DIRTY;
21756	  }
21757	
21758	  /* Copy the inode from the disk block to the in-core table or vice versa.
21759	   * If the fourth parameter below is FALSE, the bytes are swapped.
21760	   */
21761	  if (sp->s_version == V1)
21762	        old_icopy(rip, dip,  rw_flag, sp->s_native);
21763	  else
21764	        new_icopy(rip, dip2, rw_flag, sp->s_native);
21765	  
21766	  put_block(bp, INODE_BLOCK);
21767	  rip->i_dirt = CLEAN;
21768	}
	
	
21771	/*===========================================================================*
21772	 *                              old_icopy                                    *
21773	 *===========================================================================*/
21774	PRIVATE void old_icopy(rip, dip, direction, norm)
21775	register struct inode *rip;     /* pointer to the in-core inode struct */
21776	register d1_inode *dip;         /* pointer to the d1_inode inode struct */
21777	int direction;                  /* READING (from disk) or WRITING (to disk) */
21778	int norm;                       /* TRUE = do not swap bytes; FALSE = swap */
21779	
21780	{
21781	/* The V1.x IBM disk, the V1.x 68000 disk, and the V2 disk (same for IBM and
21782	 * 68000) all have different inode layouts.  When an inode is read or written
21783	 * this routine handles the conversions so that the information in the inode
21784	 * table is independent of the disk structure from which the inode came.
21785	 * The old_icopy routine copies to and from V1 disks.
21786	 */
21787	
21788	  int i;
21789	
21790	  if (direction == READING) {
21791	        /* Copy V1.x inode to the in-core table, swapping bytes if need be. */
21792	        rip->i_mode    = conv2(norm, (int) dip->d1_mode);
21793	        rip->i_uid     = conv2(norm, (int) dip->d1_uid );
21794	        rip->i_size    = conv4(norm,       dip->d1_size);
21795	        rip->i_mtime   = conv4(norm,       dip->d1_mtime);
21796	        rip->i_atime   = rip->i_mtime;
21797	        rip->i_ctime   = rip->i_mtime;
21798	        rip->i_nlinks  = (nlink_t) dip->d1_nlinks;      /* 1 char */
21799	        rip->i_gid     = (gid_t) dip->d1_gid;           /* 1 char */
21800	        rip->i_ndzones = V1_NR_DZONES;
21801	        rip->i_nindirs = V1_INDIRECTS;
21802	        for (i = 0; i < V1_NR_TZONES; i++)
21803	                rip->i_zone[i] = conv2(norm, (int) dip->d1_zone[i]);
21804	  } else {
21805	        /* Copying V1.x inode to disk from the in-core table. */
21806	        dip->d1_mode   = conv2(norm, (int) rip->i_mode);
21807	        dip->d1_uid    = conv2(norm, (int) rip->i_uid );
21808	        dip->d1_size   = conv4(norm,       rip->i_size);
21809	        dip->d1_mtime  = conv4(norm,       rip->i_mtime);
21810	        dip->d1_nlinks = (nlink_t) rip->i_nlinks;       /* 1 char */
21811	        dip->d1_gid    = (gid_t) rip->i_gid;            /* 1 char */
21812	        for (i = 0; i < V1_NR_TZONES; i++)
21813	                dip->d1_zone[i] = conv2(norm, (int) rip->i_zone[i]);
21814	  }
21815	}
	
	
21818	/*===========================================================================*
21819	 *                              new_icopy                                    *
21820	 *===========================================================================*/
21821	PRIVATE void new_icopy(rip, dip, direction, norm)
21822	register struct inode *rip;     /* pointer to the in-core inode struct */
21823	register d2_inode *dip; /* pointer to the d2_inode struct */
21824	int direction;                  /* READING (from disk) or WRITING (to disk) */
21825	int norm;                       /* TRUE = do not swap bytes; FALSE = swap */
21826	
21827	{
21828	/* Same as old_icopy, but to/from V2 disk layout. */
21829	
21830	  int i;
21831	
21832	  if (direction == READING) {
21833	        /* Copy V2.x inode to the in-core table, swapping bytes if need be. */
21834	        rip->i_mode    = conv2(norm,dip->d2_mode);
21835	        rip->i_uid     = conv2(norm,dip->d2_uid );
21836	        rip->i_nlinks  = conv2(norm,(int) dip->d2_nlinks);
21837	        rip->i_gid     = conv2(norm,(int) dip->d2_gid );
21838	        rip->i_size    = conv4(norm,dip->d2_size);
21839	        rip->i_atime   = conv4(norm,dip->d2_atime);
21840	        rip->i_ctime   = conv4(norm,dip->d2_ctime);
21841	        rip->i_mtime   = conv4(norm,dip->d2_mtime);
21842	        rip->i_ndzones = V2_NR_DZONES;
21843	        rip->i_nindirs = V2_INDIRECTS;
21844	        for (i = 0; i < V2_NR_TZONES; i++)
21845	                rip->i_zone[i] = conv4(norm, (long) dip->d2_zone[i]);
21846	  } else {
21847	        /* Copying V2.x inode to disk from the in-core table. */
21848	        dip->d2_mode   = conv2(norm,rip->i_mode);
21849	        dip->d2_uid    = conv2(norm,rip->i_uid );
21850	        dip->d2_nlinks = conv2(norm,rip->i_nlinks);
21851	        dip->d2_gid    = conv2(norm,rip->i_gid );
21852	        dip->d2_size   = conv4(norm,rip->i_size);
21853	        dip->d2_atime  = conv4(norm,rip->i_atime);
21854	        dip->d2_ctime  = conv4(norm,rip->i_ctime);
21855	        dip->d2_mtime  = conv4(norm,rip->i_mtime);
21856	        for (i = 0; i < V2_NR_TZONES; i++)
21857	                dip->d2_zone[i] = conv4(norm, (long) rip->i_zone[i]);
21858	  }
21859	}
	
	
21862	/*===========================================================================*
21863	 *                              dup_inode                                    *
21864	 *===========================================================================*/
21865	PUBLIC void dup_inode(ip)
21866	struct inode *ip;               /* The inode to be duplicated. */
21867	{
21868	/* This routine is a simplified form of get_inode() for the case where
21869	 * the inode pointer is already known.
21870	 */
21871	
21872	  ip->i_count++;
21873	}















⌨️ 快捷键说明

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