lkml.org 
[lkml]   [2004]   [Nov]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH 2.6.10-rc1 2/15] driver-model: flag type helpers added to moduleparam
 dp_02_module_param_flag.patch

This is the 2nd patch of 15 patches for devparam.

This patch implements module_param_flag() and module_param_invflag().
They appear as boolean parameter to the outside, and bitwise OR the
specified flag to flags when the specified boolean value is 1 and 0
respectively.


Signed-off-by: Tejun Heo <tj@home-tj.org>


Index: linux-export/include/linux/moduleparam.h
===================================================================
--- linux-export.orig/include/linux/moduleparam.h 2004-11-04 10:25:53.000000000 +0900
+++ linux-export/include/linux/moduleparam.h 2004-11-04 11:04:07.000000000 +0900
@@ -45,6 +45,12 @@ struct kparam_array
void *elem;
};

+/* Special one for flags */
+struct kparam_flag
+{
+ unsigned int *pflags, flag, inv;
+};
+
/* This is the fundamental function for registering boot/module
parameters. perm sets the visibility in driverfs: 000 means it's
not there, read bits mean it's readable, write bits mean it's
@@ -76,6 +82,20 @@ struct kparam_array
module_param_call(name, param_set_copystring, param_get_string, \
&__param_string_##name, perm)

+/* Bit flag */
+#define __module_param_flag(name, flags, flag, inv, perm) \
+ param_check_uint(name, &(flags)); \
+ static struct kparam_flag __param_flag_##name \
+ = { &(flags), flag, inv }; \
+ module_param_call(name, param_set_flag, param_get_flag, \
+ &__param_flag_##name, perm)
+
+#define module_param_flag(name, flags, flag, perm) \
+ __module_param_flag(name, flags, flag, 0, perm)
+
+#define module_param_invflag(name, flags, flag, perm) \
+ __module_param_flag(name, flags, flag, 1, perm)
+
/* Called on module insert or kernel boot */
extern int parse_args(const char *name,
char *args,
@@ -146,6 +166,9 @@ extern int param_array_get(char *buffer,
extern int param_set_copystring(const char *val, struct kernel_param *kp);
extern int param_get_string(char *buffer, struct kernel_param *kp);

+extern int param_set_flag(const char *val, struct kernel_param *kp);
+extern int param_get_flag(char *buffer, struct kernel_param *kp);
+
int param_array(const char *name,
const char *val,
unsigned int min, unsigned int max,
Index: linux-export/kernel/params.c
===================================================================
--- linux-export.orig/kernel/params.c 2004-11-04 11:04:07.000000000 +0900
+++ linux-export/kernel/params.c 2004-11-04 11:04:07.000000000 +0900
@@ -350,6 +350,32 @@ int param_get_string(char *buffer, struc
return strlcpy(buffer, kps->string, kps->maxlen);
}

+int param_set_flag(const char *val, struct kernel_param *kp)
+{
+ struct kparam_flag *kflag = kp->arg;
+ int boolval, ret;
+ struct kernel_param dummy = { .arg = &boolval };
+
+ ret = param_set_bool(val, &dummy);
+ if (ret == 0) {
+ if (boolval ^ kflag->inv)
+ *kflag->pflags |= kflag->flag;
+ else
+ *kflag->pflags &= ~kflag->flag;
+ }
+ return ret;
+}
+
+int param_get_flag(char *buffer, struct kernel_param *kp)
+{
+ struct kparam_flag *kflag = kp->arg;
+ int val;
+ struct kernel_param dummy = { .arg = &val };
+
+ val = (!!(*kflag->pflags & kflag->flag)) ^ kflag->inv;
+ return param_get_bool(buffer, &dummy);
+}
+
/* sysfs output in /sys/modules/XYZ/parameters/ */

extern struct kernel_param __start___param[], __stop___param[];
@@ -762,3 +788,5 @@ EXPORT_SYMBOL(param_array_set);
EXPORT_SYMBOL(param_array_get);
EXPORT_SYMBOL(param_set_copystring);
EXPORT_SYMBOL(param_get_string);
+EXPORT_SYMBOL(param_set_flag);
+EXPORT_SYMBOL(param_get_flag);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-03-22 14:07    [from the cache]
©2003-2011 Jasper Spaans