// 同步文件块 static int sfs_sync(struct fs *fs) { struct sfs_fs *sfs = fsop_info(fs, sfs); lock_sfs_fs(sfs); // 应该是用信号量锁定这个玩意 { list_entry_t *list = &(sfs->inode_list), *le = list; while ((le = list_next(le)) != list) { struct sfs_inode *sin = le2sin(le, inode_link); vop_fsync(info2node(sin, sfs_inode)); } } unlock_sfs_fs(sfs); int ret; if (sfs->super_dirty) { sfs->super_dirty = 0; if ((ret = sfs_sync_super(sfs)) != 0) { sfs->super_dirty = 1; return ret; } if ((ret = sfs_sync_freemap(sfs)) != 0) { sfs->super_dirty = 1; return ret; } } return 0; }
static int sfs_sync(struct fs *fs) { struct sfs_fs *sfs = fsop_info(fs, sfs); lock_sfs_fs(sfs); /* * Get the sfs_fs from the generic abstract fs. * * Note that the abstract struct fs, which is all the VFS * layer knows about, is actually a member of struct sfs_fs. * The pointer in the struct fs points back to the top of the * struct sfs_fs - essentially the same object. This can be a * little confusing at first. * * The following diagram may help: * * struct sfs_fs <-----------------\ * : | * : sfs_absfs (struct fs) | <------\ * : : | | * : : various members | | * : : | | * : : fs_info(__sfs_info) ---/ | * : : ...|... * : . VFS . * : . layer . * : other members ....... * : * : * * This construct is repeated with inodes and devices and other * similar things all over the place in ucore, so taking the * time to straighten it out in your mind is worthwhile. */ { list_entry_t *list = &(sfs->inode_list), *le = list; while ((le = list_next(le)) != list) { struct sfs_inode *sin = le2sin(le, inode_link); vop_fsync(info2node(sin, sfs_inode)); } } unlock_sfs_fs(sfs); int ret; if (sfs->super_dirty) { sfs->super_dirty = 0; /* If the superblock needs to be written, write it. */ if ((ret = sfs_sync_super(sfs)) != 0) { sfs->super_dirty = 1; return ret; } /* If the free block map needs to be written, write it. */ if ((ret = sfs_sync_freemap(sfs)) != 0) { sfs->super_dirty = 1; return ret; } } return 0; }
static int sfs_sync(struct fs *fs) { // debug // int u; // kprintf("--- %d ---\n", 1); // for (u = _initrd_begin; u < _initrd_end; ++u) { // kprintf("%02x ", *((char *)u)); // } // kprintf("\n"); struct sfs_fs *sfs = fsop_info(fs, sfs); lock_sfs_fs(sfs); { list_entry_t *list = &(sfs->inode_list), *le = list; while ((le = list_next(le)) != list) { struct sfs_inode *sin = le2sin(le, inode_link); vop_fsync(info2node(sin, sfs_inode)); } } unlock_sfs_fs(sfs); // kprintf("--- %d ---\n", 2); // for (u = _initrd_begin; u < _initrd_end; ++u) { // kprintf("%02x ", *((char *)u)); // } // kprintf("\n"); int ret; if (sfs->super_dirty) { sfs->super_dirty = 0; if ((ret = sfs_sync_super(sfs)) != 0) { sfs->super_dirty = 1; return ret; } if ((ret = sfs_sync_freemap(sfs)) != 0) { sfs->super_dirty = 1; return ret; } } // kprintf("--- %d ---\n", 3); // for (u = _initrd_begin; u < _initrd_end; ++u) { // kprintf("%02x ", *((char *)u)); // } // kprintf("\n"); swapper_all_block_sync(); return 0; }
/* * lookup_sfs_nolock - according ino, find related inode * * NOTICE: le2sin, info2node MACRO */ static struct inode * lookup_sfs_nolock(struct sfs_fs *sfs, uint32_t ino) { struct inode *node; list_entry_t *list = sfs_hash_list(sfs, ino), *le = list; while ((le = list_next(le)) != list) { struct sfs_inode *sin = le2sin(le, hash_link); if (sin->ino == ino) { node = info2node(sin, sfs_inode); if (vop_ref_inc(node) == 1) { sin->reclaim_count ++; } return node; } } return NULL; }