2

这里

/*
 * Set bootfs_vnode.
 *
 * Bootfs_vnode is the vnode used for beginning path translation of
 * pathnames starting with /.
 *
 * It is also incidentally the system's first current directory.
 */
int
vfs_setbootfs(const char *fsname)
{
    char tmp[NAME_MAX+1];
    char *s;
    int result;
    struct vnode *newguy;

    vfs_biglock_acquire();

    snprintf(tmp, sizeof(tmp)-1, "%s", fsname);
    s = strchr(tmp, ':');
    if (s) {
        /* If there's a colon, it must be at the end */
        if (strlen(s)>0) {
            vfs_biglock_release();
            return EINVAL;
        }
    }
    else {
        strcat(tmp, ":");
    }

    result = vfs_chdir(tmp);
    if (result) {
        vfs_biglock_release();
        return result;
    }

    result = vfs_getcurdir(&newguy);
    if (result) {
        vfs_biglock_release();
        return result;
    }

    change_bootfs(newguy);

    vfs_biglock_release();
    return 0;
}

为什么应该strlen(s)等于零?换句话说,为什么如果它大于零然后返回错误?由于冒号应该在末尾(如果存在)(如评论所述),它的大小不应该是 1 吗?

4

0 回答 0