code:update - ikarishinjieva/unixV6-code-analyze-chs GitHub Wiki
7188
7189 /*
7190 * update is the internal name of
7191 * 'sync'. It goes through the disk
7192 * queues to initiate sandbagged IO;
7193 * goes through the I nodes to write
7194 * modified nodes; and it goes through
7195 * the mount table to initiate modified
7196 * super blocks.
7197 */
7198
7199
7200
7201 update()
7202 {
7203 register struct inode *ip;
7204 register struct mount *mp;
7205 register *bp;
7206
7207 if(updlock)
7208 return;
- 若updlock被置,表明update函数当前被锁,直接返回
- updlock定义在systm.h的第234行
7209 updlock++;
- 若updlock未被置,则置该标识,给update函数上锁
7210 for(mp = &mount[0]; mp < &mount[NMOUNT]; mp++)
7211 if(mp->m_bufp != NULL) {
7213 if(ip->s_fmod==0 || ip->s_ilock!=0 ||
7214 ip->s_flock!=0 || ip->s_ronly!=0)
7215 continue;
7216 bp = getblk(mp->m_dev, 1);
7217 ip->s_fmod = 0;
7218 ip->s_time[0] = time[0];
7219 ip->s_time[1] = time[1];
7220 bcopy(ip, bp->b_addr, 256);
7221 bwrite(bp);
7222 }
- 对于找到的装载文件系统,若其超级块被修改过(s_fmod != 0),同时inode队列与s_free队列未被锁,且其不为只读的
- 则清其s_fmod标识,将内存中的超级块更新到磁盘上
7223 for(ip = &inode[0]; ip < &inode[NINODE]; ip++)
7224 if((ip->i_flag&ILOCK) == 0) {
7225 ip->i_flag =| ILOCK;
7226 iupdat(ip, time);
7227 prele(ip);
7228 }
- 上锁
- 更新磁盘中对应inode
- 解锁
- NINODE定义在param.h第131行,其值为100
7229 updlock = 0;
- 解锁update函数
7230 bflush(NODEV);
- 处理所有与NODEV有关的缓存块
7231 }
7232 /* ------------------------- */
7233 /* ------------------------- */
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249