From patchwork Fri Nov 12 18:18:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Achatz X-Patchwork-Id: 320632 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oACIIheT024190 for ; Fri, 12 Nov 2010 18:18:46 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756167Ab0KLSSl (ORCPT ); Fri, 12 Nov 2010 13:18:41 -0500 Received: from fmmailgate03.web.de ([217.72.192.234]:54428 "EHLO fmmailgate03.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756045Ab0KLSSk (ORCPT ); Fri, 12 Nov 2010 13:18:40 -0500 Received: from smtp04.web.de ( [172.20.0.225]) by fmmailgate03.web.de (Postfix) with ESMTP id ECF5C171D39A0; Fri, 12 Nov 2010 19:18:38 +0100 (CET) Received: from [84.57.56.184] (helo=[192.168.0.7]) by smtp04.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #24) id 1PGyCs-0002bW-00; Fri, 12 Nov 2010 19:18:38 +0100 Subject: [PATCH 1/2] sysfs: Introducing sysfs_create_bin_group() From: Stefan Achatz To: Greg Kroah-Hartman , "Eric W. Biederman" , "Serge E. Hallyn" , Tejun Heo , Jiri Kosina , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Torokhov , Benjamin Thery Date: Fri, 12 Nov 2010 19:18:38 +0100 Message-ID: <1289585918.2629.12.camel@neuromancer> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 (2.30.3-1.fc13) X-Sender: stefan_achatz@web.de X-Provags-ID: V01U2FsdGVkX19z42z4Ah/SpuvHrMCAsuorVmavaNGvzm8xLIUy cIU00IjHM5XuFQ5YlcvURGIglNHlujeXI0yhLPSnKu8iYp8Juu dpNHIohyN7JYm1P8PDMA== Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Fri, 12 Nov 2010 18:18:46 +0000 (UTC) diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 442f34f..841baed 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -27,7 +27,7 @@ static void remove_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, } static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, - const struct attribute_group *grp, int update) + const struct attribute_group *grp, int update, int type) { struct attribute *const* attr; int error = 0, i; @@ -45,7 +45,7 @@ static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, if (!mode) continue; } - error = sysfs_add_file_mode(dir_sd, *attr, SYSFS_KOBJ_ATTR, + error = sysfs_add_file_mode(dir_sd, *attr, type, (*attr)->mode | mode); if (unlikely(error)) break; @@ -57,7 +57,7 @@ static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, static int internal_create_group(struct kobject *kobj, int update, - const struct attribute_group *grp) + const struct attribute_group *grp, int type) { struct sysfs_dirent *sd; int error; @@ -75,7 +75,7 @@ static int internal_create_group(struct kobject *kobj, int update, } else sd = kobj->sd; sysfs_get(sd); - error = create_files(sd, kobj, grp, update); + error = create_files(sd, kobj, grp, update, type); if (error) { if (grp->name) sysfs_remove_subdir(sd); @@ -97,9 +97,16 @@ static int internal_create_group(struct kobject *kobj, int update, int sysfs_create_group(struct kobject *kobj, const struct attribute_group *grp) { - return internal_create_group(kobj, 0, grp); + return internal_create_group(kobj, 0, grp, SYSFS_KOBJ_ATTR); } +int sysfs_create_bin_group(struct kobject *kobj, + const struct attribute_group *grp) +{ + return internal_create_group(kobj, 0, grp, SYSFS_KOBJ_BIN_ATTR); +} +EXPORT_SYMBOL_GPL(sysfs_create_bin_group); + /** * sysfs_update_group - given a directory kobject, create an attribute group * @kobj: The kobject to create the group on @@ -120,10 +127,15 @@ int sysfs_create_group(struct kobject *kobj, int sysfs_update_group(struct kobject *kobj, const struct attribute_group *grp) { - return internal_create_group(kobj, 1, grp); + return internal_create_group(kobj, 1, grp, SYSFS_KOBJ_ATTR); } - +int sysfs_update_bin_group(struct kobject *kobj, + const struct attribute_group *grp) +{ + return internal_create_group(kobj, 1, grp, SYSFS_KOBJ_BIN_ATTR); +} +EXPORT_SYMBOL_GPL(sysfs_update_bin_group); void sysfs_remove_group(struct kobject * kobj, const struct attribute_group * grp) @@ -148,17 +160,15 @@ void sysfs_remove_group(struct kobject * kobj, sysfs_put(sd); } -/** - * sysfs_merge_group - merge files into a pre-existing attribute group. - * @kobj: The kobject containing the group. - * @grp: The files to create and the attribute group they belong to. - * - * This function returns an error if the group doesn't exist or any of the - * files already exist in that group, in which case none of the new files - * are created. - */ -int sysfs_merge_group(struct kobject *kobj, - const struct attribute_group *grp) +void sysfs_remove_bin_group(struct kobject * kobj, + const struct attribute_group * grp) +{ + sysfs_remove_group(kobj, grp); +} +EXPORT_SYMBOL_GPL(sysfs_remove_bin_group); + +int internal_merge_group(struct kobject *kobj, + const struct attribute_group *grp, int type) { struct sysfs_dirent *dir_sd; int error = 0; @@ -173,7 +183,7 @@ int sysfs_merge_group(struct kobject *kobj, return -ENOENT; for ((i = 0, attr = grp->attrs); *attr && !error; (++i, ++attr)) - error = sysfs_add_file(dir_sd, *attr, SYSFS_KOBJ_ATTR); + error = sysfs_add_file(dir_sd, *attr, type); if (error) { while (--i >= 0) sysfs_hash_and_remove(dir_sd, NULL, (*--attr)->name); @@ -182,8 +192,30 @@ int sysfs_merge_group(struct kobject *kobj, return error; } + +/** + * sysfs_merge_group - merge files into a pre-existing attribute group. + * @kobj: The kobject containing the group. + * @grp: The files to create and the attribute group they belong to. + * + * This function returns an error if the group doesn't exist or any of the + * files already exist in that group, in which case none of the new files + * are created. + */ +int sysfs_merge_group(struct kobject *kobj, + const struct attribute_group *grp) +{ + return internal_merge_group(kobj, grp, SYSFS_KOBJ_ATTR); +} EXPORT_SYMBOL_GPL(sysfs_merge_group); +int sysfs_merge_bin_group(struct kobject *kobj, + const struct attribute_group *grp) +{ + return internal_merge_group(kobj, grp, SYSFS_KOBJ_BIN_ATTR); +} +EXPORT_SYMBOL_GPL(sysfs_merge_bin_group); + /** * sysfs_unmerge_group - remove files from a pre-existing attribute group. * @kobj: The kobject containing the group. @@ -207,6 +239,12 @@ void sysfs_unmerge_group(struct kobject *kobj, } EXPORT_SYMBOL_GPL(sysfs_unmerge_group); +void sysfs_unmerge_bin_group(struct kobject *kobj, + const struct attribute_group *grp) +{ + sysfs_unmerge_group(kobj, grp); +} +EXPORT_SYMBOL_GPL(sysfs_unmerge_bin_group); EXPORT_SYMBOL_GPL(sysfs_create_group); EXPORT_SYMBOL_GPL(sysfs_update_group); diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 30b8815..653b0b0 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -169,6 +169,17 @@ int sysfs_merge_group(struct kobject *kobj, void sysfs_unmerge_group(struct kobject *kobj, const struct attribute_group *grp); +int sysfs_create_bin_group(struct kobject *kobj, + const struct attribute_group *grp); +int sysfs_update_bin_group(struct kobject *kobj, + const struct attribute_group *grp); +void sysfs_remove_bin_group(struct kobject * kobj, + const struct attribute_group * grp); +int sysfs_merge_bin_group(struct kobject *kobj, + const struct attribute_group *grp); +void sysfs_unmerge_bin_group(struct kobject *kobj, + const struct attribute_group *grp); + void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr); void sysfs_notify_dirent(struct sysfs_dirent *sd); struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,