从不兼容的指针类型传递 'strcmp' 的参数 1
Passing argument 1 of 'strcmp' from incompatible pointer type
我知道这些问题一直被问到,但在这种情况下,我不太确定正确的解决方案是什么。该函数是 3.4.x linux 内核 for context 的分支中 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;
}
显然 type
属于 struct file_system_type *
类型,这不是 strcmp()
所期望的类型。我猜 struct file_system_type
中的第一个字段是 char*
,所以它有效。
解决方案要么将 type
强制转换为 char*
,要么适当地取消引用它的第一个成员。 (显然第二种方法更好)
我知道这些问题一直被问到,但在这种情况下,我不太确定正确的解决方案是什么。该函数是 3.4.x linux 内核 for context 的分支中 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;
}
显然 type
属于 struct file_system_type *
类型,这不是 strcmp()
所期望的类型。我猜 struct file_system_type
中的第一个字段是 char*
,所以它有效。
解决方案要么将 type
强制转换为 char*
,要么适当地取消引用它的第一个成员。 (显然第二种方法更好)