Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9059045ybi; Wed, 10 Jul 2019 04:02:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqxx3BMZUcHIj1w4f5O+fxyFlUquO2TTFNzmMI88Sn6IAQ6xxaizPGJ2PUy4Amy5xJtv9kVV X-Received: by 2002:a17:902:a514:: with SMTP id s20mr35666323plq.162.1562756565870; Wed, 10 Jul 2019 04:02:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562756565; cv=none; d=google.com; s=arc-20160816; b=d73v74hqZNFmL3NMEbPqKzNroXdnkveweoUQyhrToOXsIKwp5ZTM1psL8Rnc85XliP ORny3kDWhij5031wShcN38Ofr/vvajQQoatPoOkG2/oHua4/nwc4aysxQZ1Xegs91sSH 5LvkR7ZIAFDqAIv0VL8enBAMtlHByF5t5t7nx698T5/RvnMtqQAv2ckIK7tpziDyMPuM yvQoXkQfVi33Zxvt86GSQz8LLt195RRRuJPZFrZD6fNd2Pd5zqY6CPoaOFWMfeiJXa9J UjnLniAVATkdjDi+DgJXOzbFL/fcNHKDHLYiIhUKy6ye/1NH2b0NM9Bh1T7YjsHty5ya cEiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:to :from; bh=dIAwiAyiQuYA7pOZXbFz/jfCFAg5iHwhmeaWKUqGU/8=; b=aDt4BNvhFC6FPn3jtlSdJJ9OefZgdK8gEIDP174ZGTJMpETJBRzTvbzANwYqF2mCdx s2Wvk389Fno9LdqGlQYA3PJTtNNlFvNzPj2y08A9CC5vo0JNZNHHgGFVjCoCi10zb6cO 66eHjmdlfU6I83Jl4aOyamyJbBwi5Z16xVszYyGtmKRo5aucqnHFlkr9vaorUOqMSMSo Od4X+er/wXsRzN6+eiOc0eWuNr81KQQblPzdyy5XX2MgBIhSh3oifbN2vdyP+o5FQBIF HZo+zn3NxN56DIIMZPV5cH1mMy6ouJiv8Wrq4VT9TLgscfzWppwq3a8o2TAkIJgfSXsp 56pA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z15si2042511pgf.85.2019.07.10.04.02.28; Wed, 10 Jul 2019 04:02:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727492AbfGJLAH (ORCPT + 99 others); Wed, 10 Jul 2019 07:00:07 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:38974 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725994AbfGJLAG (ORCPT ); Wed, 10 Jul 2019 07:00:06 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 32D0F41754D70F5E80C6; Wed, 10 Jul 2019 19:00:02 +0800 (CST) Received: from RH5885H-V3.huawei.com (10.90.53.225) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.439.0; Wed, 10 Jul 2019 18:59:53 +0800 From: SunKe To: , , , Subject: [PATCH] sample_configfs: bin_file read and write Date: Wed, 10 Jul 2019 19:05:37 +0800 Message-ID: <1562756737-124703-1-git-send-email-sunke32@huawei.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.90.53.225] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add bin_file read and write function Signed-off-by: SunKe --- samples/configfs/configfs_sample.c | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/samples/configfs/configfs_sample.c b/samples/configfs/configfs_sample.c index 004a4e2..c76b784 100644 --- a/samples/configfs/configfs_sample.c +++ b/samples/configfs/configfs_sample.c @@ -146,6 +146,8 @@ static struct childless childless_subsys = { struct simple_child { struct config_item item; int storeme; + void *data; + size_t len; }; static inline struct simple_child *to_simple_child(struct config_item *item) @@ -153,6 +155,46 @@ static inline struct simple_child *to_simple_child(struct config_item *item) return item ? container_of(item, struct simple_child, item) : NULL; } +static ssize_t simple_child_bin_storeme_bin_write(struct config_item *item, + const void *data, size_t size) +{ + struct simple_child *simple_child = to_simple_child(item); + + kfree(simple_child->data); + simple_child->data = NULL; + + simple_child->data = kmemdup(data, size, GFP_KERNEL); + if (!simple_child->data) + return -ENOMEM; + simple_child->len = size; + + return 0; +} + +static ssize_t simple_child_bin_storeme_bin_read(struct config_item *item, + void *data, size_t size) +{ + struct simple_child *simple_child = to_simple_child(item); + + if (!data) { + size = simple_child->len; + } else { + memcpy(data, simple_child->data, simple_child->len); + size = simple_child->len; + } + + return size; +} + +#define MAX_SIZE (128 * 1024) + +CONFIGFS_BIN_ATTR(simple_child_bin_, storeme_bin, NULL, MAX_SIZE); + +static struct configfs_bin_attribute *simple_child_bin_attrs[] = { + &simple_child_bin_attr_storeme_bin, + NULL, +}; + static ssize_t simple_child_storeme_show(struct config_item *item, char *page) { return sprintf(page, "%d\n", to_simple_child(item)->storeme); @@ -196,6 +238,7 @@ static struct configfs_item_operations simple_child_item_ops = { static const struct config_item_type simple_child_type = { .ct_item_ops = &simple_child_item_ops, .ct_attrs = simple_child_attrs, + .ct_bin_attrs = simple_child_bin_attrs, .ct_owner = THIS_MODULE, }; -- 2.7.4