gpt4 book ai didi

c - 从不兼容的指针类型传递参数 1( 'strcmp')

转载 作者:行者123 更新时间:2023-11-30 19:40:52 24 4
gpt4 key购买 nike

我知道这些问题一直被问到,但是在这种情况下,我不太确定正确的解决方案是什么。该函数是 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;
}

最佳答案

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

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

关于c - 从不兼容的指针类型传递参数 1( 'strcmp'),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34408836/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com