【问题标题】:Passing argument 1 of 'strcmp' from incompatible pointer type从不兼容的指针类型传递“strcmp”的参数 1
【发布时间】:2016-03-28 07:17:51
【问题描述】:

我知道这些问题一直被问到,但是在这种情况下,我不太确定正确的解决方案是什么。该函数是 3.4.x linux 内核 fork 中的 do_new_mount 的编辑函数,用于上下文。预期目的是检查文件系统的类型,如果条件正确,则依次发出异步标志。

行:

if (!err && ((!strcmp(type, "ext4") &&

完整功能(添加了异步部分,导致错误):

static int do_new_mount(struct path *path, const char *fstype, int flags,
            int mnt_flags, const char *name, void *data)
{
struct file_system_type *type;
struct user_namespace *user_ns;
struct vfsmount *mnt;
int err;

if (!fstype)
    return -EINVAL;

/* we need capabilities... */
user_ns = real_mount(path->mnt)->mnt_ns->user_ns;
if (!ns_capable(user_ns, CAP_SYS_ADMIN))
    return -EPERM;

type = get_fs_type(fstype);
if (!type)
    return -ENODEV;

if (user_ns != &init_user_ns) {
    if (!(type->fs_flags & FS_USERNS_MOUNT)) {
        put_filesystem(type);
        return -EPERM;
    }
    /* Only in special cases allow devices from mounts
     * created outside the initial user namespace.
     */
    if (!(type->fs_flags & FS_USERNS_DEV_MOUNT)) {
        flags |= MS_NODEV;
        mnt_flags |= MNT_NODEV;
    }
}

mnt = vfs_kern_mount(type, flags, name, data);
if (!IS_ERR(mnt) && (type->fs_flags & FS_HAS_SUBTYPE) &&
    !mnt->mnt_sb->s_subtype)
    mnt = fs_set_subtype(mnt, fstype);

put_filesystem(type);
if (IS_ERR(mnt))
    return PTR_ERR(mnt);

err = do_add_mount(real_mount(mnt), path, mnt_flags);
if (err)
    mntput(mnt);
#ifdef CONFIG_ASYNC_FSYNC
if (!err && ((!strcmp(type, "ext4") &&
    !strcmp(path->dentry->d_name.name, "data")) ||
    (!strcmp(type, "fuse") &&
    !strcmp(path->dentry->d_name.name, "emulated"))))
            mnt->mnt_sb->fsync_flags |= FLAG_ASYNC_FSYNC;
#endif
return err;
}

【问题讨论】:

  • struct file_system_type *type; strcmp(const char *s1, const char *s2); 类型不是char *
  • strcmp(type->name, "ext4")?
  • 对,但我不确定如何正确检查类型。将尝试该解决方案 kaylum,谢谢!

标签: c pointers strcmp incomplete-type


【解决方案1】:

显然typestruct file_system_type * 类型,这不是strcmp() 所期望的。我猜struct file_system_type 中的第一个字段是char*,所以它可以工作。

解决方案将type 转换为char* 或正确取消引用它的第一个成员。 (显然第二种方法更好)

【讨论】:

  • 是的,这就是计划。不会让我接受 x 分钟。
猜你喜欢
  • 2013-12-25
  • 1970-01-01
  • 1970-01-01
  • 2018-02-27
  • 1970-01-01
  • 2017-12-11
  • 2020-06-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多