Пример #1
0
// 设置当前的目录
int
vfs_set_curdir(struct inode *dir) {
    int ret = 0;
    lock_cfs();
    struct inode *old_dir;
    if ((old_dir = get_cwd_nolock()) != dir) { // 得到当前的工作目录的inode
        if (dir != NULL) {
            uint32_t type;
            if ((ret = vop_gettype(dir, &type)) != 0) {
                goto out;
            }
            if (!S_ISDIR(type)) {
                ret = -E_NOTDIR;
                goto out;
            }
            vop_ref_inc(dir);
        }
        set_cwd_nolock(dir);
        if (old_dir != NULL) {
            vop_ref_dec(old_dir);
        }
    }
out:
    unlock_cfs();
    return ret;
}
Пример #2
0
// 得到当前的目录所对应的inode
int
vfs_get_curdir(struct inode **dir_store) {
    struct inode *node;
    if ((node = get_cwd_nolock()) != NULL) {
        vop_ref_inc(node); // 增加对inode的ref_count计数
        *dir_store = node; // 记录下这个node
        return 0;
    }
    return -E_NOENT;
}
Пример #3
0
/*
 * Get current directory as a inode.
 * 
 * We do not synchronize current->fs_struct->pwd, because it belongs exclusively
 * to its own process(or threads) with the holding lock.
 */
int
vfs_get_curdir(struct inode **dir_store) {
    struct inode *node;
    if ((node = get_cwd_nolock()) != NULL) {
        vop_ref_inc(node);
        *dir_store = node;
        return 0;
    }
    return -E_NOENT;
}