示例#1
0
文件: sfs_fs.c 项目: lishuhuakai/CS
// 同步文件块
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;
}
示例#2
0
文件: sfs_fs.c 项目: spinlock/ucore
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;
}
示例#4
0
/* 
 * flush all dirty buffers to disk
 * return 0 if sync successful
 */
static int ffs_sync(struct fs *fs)
{
	//TODO
	return 0;
	FAT_PRINTF("[ffs_sync]\n");
	struct ffs_fs *ffs = fsop_info(fs, ffs);
	struct ffs_inode_list *inode_list = ffs->inode_list;
	while (inode_list->next != NULL) {
		inode_list = inode_list->next;
		vop_fsync(info2node(inode_list->f_inode, ffs_inode));
	}

	return 0;
}
示例#5
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;
}
示例#6
0
static void
lookup_pipe_nolock(struct pipe_fs *pipe, const char *name, struct inode **rnode_store, struct inode **wnode_store) {
    list_entry_t *list = &(pipe->pipe_list), *le = list;
    *rnode_store = *wnode_store = NULL;
    while ((le = list_next(le)) != list) {
        struct pipe_inode *pin = le2pin(le, pipe_link);
        if (strcmp(pin->name, name) == 0) {
            struct inode *node = info2node(pin, pipe_inode);
            switch (pin->pin_type) {
            case PIN_RDONLY: assert(*rnode_store == NULL); *rnode_store = node; break;
            case PIN_WRONLY: assert(*wnode_store == NULL); *wnode_store = node; break;
            default:
                panic("unknown pipe_inode type %d.\n", pin->pin_type);
            }
            if (vop_ref_inc(node) == 1) {
                pin->reclaim_count ++;
            }
        }
    }
}