Hello Anish <br><br>Thank you for the changes. Ya now I understoor dealing with store function. :) <br>And I did small change in ur code.<br><br>I have declared the show and store function as I declared before.<br><br>static ssize_t attr1_store(struct class *cls, struct class_attribute *attr, const char *buf, size_t count);<br>
static ssize_t attr1_show(struct class *cls, struct class_attribute *attr, char *buf);<br><br>instead.<br><br>static ssize_t attr1_store(struct class *cls, const char *buf, size_t count);<br>
static ssize_t attr1_show(struct class *cls, char *buf);<br><br>After this its working fine.<br><br><br><br><br><br><div class="gmail_quote">On Thu, Jun 21, 2012 at 9:04 AM, anish singh <span dir="ltr"><<a href="mailto:anish198519851985@gmail.com" target="_blank">anish198519851985@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Wed, Jun 20, 2012 at 11:32 PM, Jeshwanth Kumar N K Jeshu<br>
<<a href="mailto:jeshkumar555@gmail.com">jeshkumar555@gmail.com</a>> wrote:<br>
> Hello<br>
><br>
> Thank you anish for the reply, the code is I pasted below.<br>
> [code-starts]<br>
><br>
> #include <linux/init.h><br>
> #include <linux/module.h><br>
> #include <linux/kernel.h><br>
> #include <linux/fs.h><br>
> #include <linux/device.h><br>
> #include <linux/sysdev.h><br>
> #include <linux/major.h><br>
> #include <asm/uaccess.h><br>
> #include <linux/slab.h><br>
> #include <linux/cdev.h><br>
> #include <linux/kdev_t.h><br>
><br>
> static char *gvar = "BeHonest";<br>
> // Store and Show functions......<br>
> static ssize_t attr1_store(struct class *cls, struct class_attribute *attr,<br>
> const char *buf, size_t count);<br>
> static ssize_t attr1_show(struct class *cls, struct class_attribute *attr,<br>
> char *buf);<br>
><br>
> static struct class_attribute pwm_class_attrs[] = {<br>
> __ATTR(attr1, S_IRUGO | S_IWUSR , attr1_show, attr1_store),<br>
> __ATTR_NULL<br>
> };<br>
><br>
> static struct class pwm_class =<br>
> {<br>
> .name = "dev_jes",<br>
> .owner = THIS_MODULE,<br>
> .class_attrs = pwm_class_attrs<br>
> };<br>
><br>
><br>
> static int hello_init(void)<br>
> {<br>
> class_register(&pwm_class);<br>
> printk("In hello_init function \n");<br>
><br>
> return 0;<br>
> }<br>
><br>
> static ssize_t attr1_show(struct class *cls, struct class_attribute *attr,<br>
> char *buf)<br>
> {<br>
><br>
> printk("In attr1_show function\n");<br>
> return sprintf(buf, "%s\n", gvar);<br>
> }<br>
><br>
> static ssize_t attr1_store(struct class *cls, struct class_attribute *attr,<br>
> const char *buf, size_t count)<br>
> {<br>
> printk("the string is : %s\n",buf);<br>
> printk("In attr1_store function\n");<br>
> return 1;<br>
> //return sprintf(gvar, "%s\n", buf); --- If I put this line I<br>
> am getting ERROR :(<br>
> }<br>
><br>
><br>
> static void hello_exit(void)<br>
> {<br>
> class_unregister(&pwm_class);<br>
> printk("In hello_exit function \n");<br>
> }<br>
><br>
> module_init(hello_init);<br>
> module_exit(hello_exit);<br>
><br>
> MODULE_LICENSE("GPL");<br>
> MODULE_AUTHOR("Jeshwanth");<br>
> MODULE_DESCRIPTION("Learning sysfs");<br>
><br>
> [code-ends]<br>
><br>
> echo "jeshu" > /sys/class/dev_jes/attr1<br>
><br>
> And If I pass the command to atttribute I got result below in dmesg.<br>
><br>
> <a href="tel:%5B%203435.613057" value="+913435613057">[ 3435.613057</a>] the string is : jeshu<br>
> <a href="tel:%5B%203435.613061" value="+913435613061">[ 3435.613061</a>]<br>
> <a href="tel:%5B%203435.613066" value="+913435613066">[ 3435.613066</a>] In attr1_store function<br>
> <a href="tel:%5B%203435.613072" value="+913435613072">[ 3435.613072</a>] the string is : eshu<br>
> <a href="tel:%5B%203435.613074" value="+913435613074">[ 3435.613074</a>]<br>
> <a href="tel:%5B%203435.613078" value="+913435613078">[ 3435.613078</a>] In attr1_store function<br>
> <a href="tel:%5B%203435.613083" value="+913435613083">[ 3435.613083</a>] the string is : shu<br>
> <a href="tel:%5B%203435.613085" value="+913435613085">[ 3435.613085</a>]<br>
> <a href="tel:%5B%203435.613088" value="+913435613088">[ 3435.613088</a>] In attr1_store function<br>
> <a href="tel:%5B%203435.613093" value="+913435613093">[ 3435.613093</a>] the string is : hu<br>
> <a href="tel:%5B%203435.613095" value="+913435613095">[ 3435.613095</a>]<br>
> <a href="tel:%5B%203435.613098" value="+913435613098">[ 3435.613098</a>] In attr1_store function<br>
> <a href="tel:%5B%203435.613103" value="+913435613103">[ 3435.613103</a>] the string is : u<br>
> <a href="tel:%5B%203435.613105" value="+913435613105">[ 3435.613105</a>]<br>
> <a href="tel:%5B%203435.613108" value="+913435613108">[ 3435.613108</a>] In attr1_store function<br>
> <a href="tel:%5B%203435.613113" value="+913435613113">[ 3435.613113</a>] the string is :<br>
> <a href="tel:%5B%203435.613115" value="+913435613115">[ 3435.613115</a>]<br>
> <a href="tel:%5B%203435.613118" value="+913435613118">[ 3435.613118</a>] In attr1_store function<br>
><br>
><br>
> So please help me how to read the attribute in store function.. Thanks :)<br>
#include <linux/init.h><br>
#include <linux/module.h><br>
#include <linux/kernel.h><br>
#include <linux/fs.h><br>
#include <linux/device.h><br>
#include <linux/sysdev.h><br>
#include <linux/major.h><br>
#include <asm/uaccess.h><br>
#include <linux/slab.h><br>
#include <linux/cdev.h><br>
#include <linux/kdev_t.h><br>
<br>
</div></div>static char *gvar = NULL;<br>
static ssize_t attr1_store(struct class *cls, const char *buf, size_t count);<br>
static ssize_t attr1_show(struct class *cls, char *buf);<br>
<div class="im"><br>
static struct class_attribute pwm_class_attrs[] = {<br>
</div> __ATTR(attr1, 0666, attr1_show, attr1_store), //use macro for permission<br>
<div class="im"> __ATTR_NULL<br>
};<br>
<br>
static struct class pwm_class =<br>
{<br>
.name = "dev_jes",<br>
.owner = THIS_MODULE,<br>
.class_attrs = pwm_class_attrs<br>
};<br>
<br>
<br>
static int hello_init(void)<br>
{<br>
</div> char string[] = "nothing";<br>
gvar = kmalloc(sizeof(char)*strlen(string), GFP_KERNEL);<br>
class_register(&pwm_class);<br>
snprintf(gvar, sizeof(char)*strlen(string)+1, "%s", string);<br>
printk("anish In hello_init function \n");<br>
return 0;<br>
}<br>
<br>
static ssize_t attr1_show(struct class *cls, char *buf)<br>
<div class="im">{<br>
<br>
printk("In attr1_show function\n");<br>
</div> printk("%s\n", gvar);<br>
<div class="im"> printk("In attr1_show function\n");<br>
</div> return sprintf(buf, "%s", gvar);<br>
}<br>
<br>
static ssize_t attr1_store(struct class *cls, const char *buf, size_t count)<br>
{<br>
printk("the string is : %s count %d\n", buf, count);<br>
return snprintf(gvar, count, "%s\n", buf);<br>
<div class="im">}<br>
<br>
<br>
static void hello_exit(void)<br>
{<br>
class_unregister(&pwm_class);<br>
printk("In hello_exit function \n");<br>
}<br>
<br>
module_init(hello_init);<br>
module_exit(hello_exit);<br>
<br>
MODULE_LICENSE("GPL");<br>
MODULE_AUTHOR("Jeshwanth");<br>
MODULE_DESCRIPTION("Learning sysfs");<br>
</div>======================================================<br>
Hope you got the point.<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
><br>
><br>
> On Tue, Jun 19, 2012 at 4:02 PM, anish singh <<a href="mailto:anish198519851985@gmail.com">anish198519851985@gmail.com</a>><br>
> wrote:<br>
>><br>
>> On Tue, Jun 19, 2012 at 3:14 PM, jeshwanth Kumar N K<br>
>> <<a href="mailto:jeshkumar555@gmail.com">jeshkumar555@gmail.com</a>> wrote:<br>
>> > Hello all<br>
>> ><br>
>> > I am new to sysfs interface ans I read about in mochel's documentation.<br>
>> > And<br>
>> > doing some experiements on it. Let's come to Tue problem, in my module I<br>
>> > have a global variable type char* myglobal and it s static, I am putting<br>
>> > that value in my one and only class attribute using show function. But<br>
>> > for<br>
>> > the same if I a user put some value in to the using echo or something,<br>
>> > the<br>
>> > attribute value is not changing. And one more thing s after I passed the<br>
>> > value to the attribute my system not shutting down :( . Please help me<br>
>> > how<br>
>> > to read values.<br>
>> Why don't you post your code?As that will really help and moreover as<br>
>> this is your code<br>
>> you won't be breakign any law set by your company.<br>
>> ><br>
>> > // in store function I am doing this:<br>
>> > Myglobal = bus;<br>
>> ><br>
>> > Sent from my HTC<br>
>> ><br>
>> ><br>
>> ><br>
>> ><br>
>> > _______________________________________________<br>
>> > Kernelnewbies mailing list<br>
>> > <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
>> > <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
>> ><br>
><br>
><br>
><br>
><br>
> --<br>
> Regards<br>
> Jeshwanth Kumar N K<br>
> <a href="tel:%2B91-7411483498" value="+917411483498">+91-7411483498</a><br>
><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Regards<br>Jeshwanth Kumar N K<br>+91-7411483498<br><br>