示例#1
0
static int rfs_flt_paths_add(redirfs_filter filter, const char *buf,
        size_t count)
{
    struct rfs_flt *rflt = filter;
    struct rfs_path *rpath;
    struct redirfs_path_info info;

#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,19,0))
    struct nameidata nd;
#else
    struct rfs_nameidata nd;
#endif

    char *path;
    char type;
    int rv;

    path = kzalloc(sizeof(char) * PAGE_SIZE, GFP_KERNEL);
    if (!path)
        return -ENOMEM;

    if (sscanf(buf, "a:%c:%s", &type, path) != 2) {
        kfree(path);
        return -EINVAL;
    }

    if (type == 'i')
        info.flags = REDIRFS_PATH_INCLUDE;

    else if (type == 'e')
        info.flags = REDIRFS_PATH_EXCLUDE;

    else {
        kfree(path);
        return -EINVAL;
    }

    rv = rfs_path_lookup(path, &nd);
    if (rv) {
        kfree(path);
        return rv;
    }

    info.dentry = rfs_nameidata_dentry(&nd);
    info.mnt = rfs_nameidata_mnt(&nd);

    if (!rflt->ops || !rflt->ops->add_path) {
        rpath = redirfs_add_path(filter, &info);
        if (IS_ERR(rpath))
            rv = PTR_ERR(rpath);
        rfs_path_put(rpath);

    } else
        rv = rflt->ops->add_path(&info);

    rfs_nameidata_put(&nd);
    kfree(path);

    return rv;
}
示例#2
0
static int __init dummyflt_init(void)
{
	
	struct redirfs_path_info dummyflt_path_info;
	struct nameidata nd;
	redirfs_path path;
	

	int err;
	int rv;

	dummyflt = redirfs_register_filter(&dummyflt_info);
	
	if (IS_ERR(dummyflt)) {
		rv = PTR_ERR(dummyflt);
		printk(KERN_ERR "dummyflt: register filter failed(%d)\n", rv);
		return rv;
	}
	
	nl_sk=netlink_kernel_create(&init_net, NETLINK_USER, 0, initializer, NULL, THIS_MODULE);
	if(!nl_sk)
	{
	    printk(KERN_ALERT "Error creating socket.\n");
	    return 0;
	}

	rv = redirfs_set_operations(dummyflt, dummyflt_op_info);
	if (rv) {
		printk(KERN_ERR "dummyflt: set operations failed(%d)\n", rv);
		goto error;
	}

	
	rv = path_lookup("/home/ozgen/Desktop/test2", LOOKUP_FOLLOW, &nd);/*simdilik sadec denemek icin ileride module yuklenirken parametre olarak verilecek*/
	if (rv) {
		printk(KERN_ERR "dummyflt: path lookup failed(%d)\n", rv);
		goto error;
	}

	dummyflt_path_info.dentry = nd.path.dentry;
	dummyflt_path_info.mnt  = nd.path.mnt;
	dummyflt_path_info.flags  = REDIRFS_PATH_INCLUDE;

	path = redirfs_add_path(dummyflt, &dummyflt_path_info);
	if (IS_ERR(path)) {
		rv = PTR_ERR(path);
		printk(KERN_ERR "dummyflt: redirfs_set_path failed(%d)\n", rv);
		path_put(&nd.path);
		goto error;
	}

	path_put(&nd.path);
	redirfs_put_path(path);
	

	printk(KERN_INFO "Dummy Filter Version "
			DUMMYFLT_VERSION " <www.redirfs.org>\n");
	return 0;
error:
	err = redirfs_unregister_filter(dummyflt);
	if (err) {
		printk(KERN_ERR "dummyflt: unregister filter "
				"failed(%d)\n", err);
		return 0;
	}
	redirfs_delete_filter(dummyflt);
	return rv;
}