* More info about kobj_attribute store and show functions
@ 2014-09-04 0:03 Lucas Tanure
0 siblings, 0 replies; 9+ messages in thread
From: Lucas Tanure @ 2014-09-04 0:03 UTC (permalink / raw)
To: kernelnewbies
Hi,
I'm looking for some information about :
struct kobj_attribute {
struct attribute attr;
ssize_t (*show)(struct kobject *kobj, struct kobj_attribute
*attr, char *buf);
ssize_t (*store)(struct kobject *kobj, struct kobj_attribute
*attr, const char *buf, size_t count);
};
My function to handle the operation:
static ssize_t my_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t count)
{
char *buffer;
buffer = (char*) kcalloc(count, sizeof(char), GFP_KERNEL);
if (count == 13) {
if (buffer) {
copy_from_user(buffer, buf, count);
printk("A %s",buffer);
if (0) {
if (strcmp(buffer, eudyptula_id) == 0)
return count;
printk("erro na strcmp\n");
}
else
printk("erro na copia\n");
}
}
return -EINVAL;
}
So, this *const char *buf, *where ti come from ? Kernel space
--
Lucas Tanure
+55 (19) 988176559
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140903/394557fa/attachment-0001.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* More info about kobj_attribute store and show functions
@ 2014-09-04 0:04 Lucas Tanure
2014-09-04 0:10 ` Lucas Tanure
0 siblings, 1 reply; 9+ messages in thread
From: Lucas Tanure @ 2014-09-04 0:04 UTC (permalink / raw)
To: kernelnewbies
Sorry, didn't finish to write the email and Gmail sent.
I will re-send.
Sorry.
--
Lucas Tanure
+55 (19) 988176559
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140903/d63405a1/attachment.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* More info about kobj_attribute store and show functions
2014-09-04 0:04 More info about kobj_attribute store and show functions Lucas Tanure
@ 2014-09-04 0:10 ` Lucas Tanure
2014-09-04 0:23 ` Greg KH
2014-09-04 1:30 ` Jeff Haran
0 siblings, 2 replies; 9+ messages in thread
From: Lucas Tanure @ 2014-09-04 0:10 UTC (permalink / raw)
To: kernelnewbies
(Forget the last e-mail, please, stupid Gmail)
Hi,
I'm looking for some information about :
struct kobj_attribute {
struct attribute attr;
ssize_t (*show)(struct kobject *kobj, struct kobj_attribute
*attr, char *buf);
ssize_t (*store)(struct kobject *kobj, struct kobj_attribute
*attr, const char *buf, size_t count);
};
My function to handle the operation:
static ssize_t my_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t count) {
char *buffer;
buffer = (char*) kcalloc(count, sizeof(char), GFP_KERNEL);
copy_from_user(buffer, buf, count);
.....
.....
etc....
}
So, this *const char *buf, *where ti come from ? Kernel space?
My copy_from_user it's not working. Should return zero.
There any Macro or function to test if the pointer *buf *is a kernel
pointer ?
Thanks
Lucas Tanure
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140903/f170d026/attachment.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* More info about kobj_attribute store and show functions
2014-09-04 0:10 ` Lucas Tanure
@ 2014-09-04 0:23 ` Greg KH
2014-09-04 0:39 ` Lucas Tanure
2014-09-04 1:30 ` Jeff Haran
1 sibling, 1 reply; 9+ messages in thread
From: Greg KH @ 2014-09-04 0:23 UTC (permalink / raw)
To: kernelnewbies
On Wed, Sep 03, 2014 at 09:10:41PM -0300, Lucas Tanure wrote:
> (Forget the last e-mail, please, stupid Gmail)
>
> Hi,
>
> I'm looking for some information about :
>
> struct kobj_attribute {
> struct attribute attr;
> ssize_t (*show)(struct kobject *kobj, struct kobj_attribute
> *attr, char *buf);
> ssize_t (*store)(struct kobject *kobj, struct kobj_attribute
> *attr, const char *buf, size_t count);
> };
>
>
> My function to handle the operation:
>
> static ssize_t my_store(struct kobject *kobj, struct kobj_attribute *attr,
> const char *buf, size_t count) {
> char *buffer;
>
> buffer = (char*) kcalloc(count, sizeof(char), GFP_KERNEL);
>
> copy_from_user(buffer, buf, count);
> .....
> .....
> etc....
> }
>
> So, this *const char *buf, *where ti come from ? Kernel space?
I'm guessing you didn't read the kobject documentation that is in the
kernel tree?
^ permalink raw reply [flat|nested] 9+ messages in thread
* More info about kobj_attribute store and show functions
2014-09-04 0:23 ` Greg KH
@ 2014-09-04 0:39 ` Lucas Tanure
2014-09-04 0:56 ` Greg KH
0 siblings, 1 reply; 9+ messages in thread
From: Lucas Tanure @ 2014-09-04 0:39 UTC (permalink / raw)
To: kernelnewbies
Greg,
I'm still trying to understand the sysfs.
I indeed read the documentation, I was using your "Sample kobject
implementation" as base of my code. But as 4h of work there some points
that I didn't understand yet.
Thanks
--
Lucas Tanure
+55 (19) 988176559
On Wed, Sep 3, 2014 at 9:23 PM, Greg KH <greg@kroah.com> wrote:
> On Wed, Sep 03, 2014 at 09:10:41PM -0300, Lucas Tanure wrote:
> > (Forget the last e-mail, please, stupid Gmail)
> >
> > Hi,
> >
> > I'm looking for some information about :
> >
> > struct kobj_attribute {
> > struct attribute attr;
> > ssize_t (*show)(struct kobject *kobj, struct kobj_attribute
> > *attr, char *buf);
> > ssize_t (*store)(struct kobject *kobj, struct kobj_attribute
> > *attr, const char *buf, size_t count);
> > };
> >
> >
> > My function to handle the operation:
> >
> > static ssize_t my_store(struct kobject *kobj, struct kobj_attribute
> *attr,
> > const char *buf, size_t count) {
> > char *buffer;
> >
> > buffer = (char*) kcalloc(count, sizeof(char), GFP_KERNEL);
> >
> > copy_from_user(buffer, buf, count);
> > .....
> > .....
> > etc....
> > }
> >
> > So, this *const char *buf, *where ti come from ? Kernel space?
>
> I'm guessing you didn't read the kobject documentation that is in the
> kernel tree?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140903/126ea202/attachment.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* More info about kobj_attribute store and show functions
2014-09-04 0:39 ` Lucas Tanure
@ 2014-09-04 0:56 ` Greg KH
2014-09-04 1:39 ` Lucas Tanure
0 siblings, 1 reply; 9+ messages in thread
From: Greg KH @ 2014-09-04 0:56 UTC (permalink / raw)
To: kernelnewbies
A: No.
Q: Should I include quotations after my reply?
http://daringfireball.net/2007/07/on_top
On Wed, Sep 03, 2014 at 09:39:50PM -0300, Lucas Tanure wrote:
> Greg,?
>
> I'm still trying to understand the sysfs.?
Why? What are you using "raw kobjects" for? You should almost never
need them.
> I indeed read the documentation, I was using your "Sample kobject
> implementation" as base of my code.
Great, then it should "just work", right? :)
Care to post your non-working code?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 9+ messages in thread
* More info about kobj_attribute store and show functions
2014-09-04 0:10 ` Lucas Tanure
2014-09-04 0:23 ` Greg KH
@ 2014-09-04 1:30 ` Jeff Haran
1 sibling, 0 replies; 9+ messages in thread
From: Jeff Haran @ 2014-09-04 1:30 UTC (permalink / raw)
To: kernelnewbies
From: kernelnewbies-bounces+jharan=bytemobile.com@kernelnewbies.org [mailto:kernelnewbies-bounces+jharan=bytemobile.com at kernelnewbies.org] On Behalf Of Lucas Tanure
Sent: Wednesday, September 03, 2014 5:11 PM
To: kernelnewbies
Subject: Re: More info about kobj_attribute store and show functions
(Forget the last e-mail, please, stupid Gmail)
Hi,
I'm looking for some information about :
struct kobj_attribute {
struct attribute attr;
ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr, char *buf);
ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count);
};
My function to handle the operation:
static ssize_t my_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) {
char *buffer;
buffer = (char*) kcalloc(count, sizeof(char), GFP_KERNEL);
copy_from_user(buffer, buf, count);
.....
.....
etc....
}
So, this const char *buf, where ti come from ? Kernel space?
My copy_from_user it's not working. Should return zero.
There any Macro or function to test if the pointer buf is a kernel pointer ?
Thanks
Lucas Tanure
I haven?t written too many of these things, but the last time I wrote a store function I didn?t need to do the copy_to_user().
buf seemed to point to directly accessible kernel memory. I would think a simple memcpy above would do the trick.
Jeff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140904/77a444f4/attachment-0001.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* More info about kobj_attribute store and show functions
2014-09-04 0:56 ` Greg KH
@ 2014-09-04 1:39 ` Lucas Tanure
2014-09-04 2:22 ` Greg KH
0 siblings, 1 reply; 9+ messages in thread
From: Lucas Tanure @ 2014-09-04 1:39 UTC (permalink / raw)
To: kernelnewbies
Greg,
I was looking again to documentation, but didn't find a explanation about
the show and store functions. I'm missing something ?
Yes, everything work if I simple use the buffer from store function, but I
was looking for where it came from.
Like, It was from user space? So, I need to take care like
simple_write_to_buffer
does with user space memory ?
I said that because of file file_operations read and write, that I know
that comes from user space. But kobj_attribute I didn't understand yet.
What I meant posting one piece of my code was just show what I doing in
high level.
But, for some reason gmail sent in the middle of my writing.
static ssize_t id_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t count)
{
char *buffer;
buffer = kcalloc(cnt, sizeof(char), GFP_KERNEL);
if (buffer) {
if (copy_from_user(buffer, buf, cnt) == cnt) {
if (strcmp(buffer, "Tanure") == 0)
return cnt;
}
}
}
return -EINVAL;
}
The copy_from_user returns 6 when I write my name in the file. So, 6 means
that copy_from_user fails to copy 6 bytes from buf.
So there is my question, buf is a user pointer ? Or Can I just copy without
problems ?
All this e-mails got me in trouble here. I got kicked from eudyptula
challenge, what I still begging to be able to finish.
Thanks Greg for all the help.
--
Lucas Tanure
+55 (19) 988176559
On Wed, Sep 3, 2014 at 9:56 PM, Greg KH <greg@kroah.com> wrote:
>
> A: No.
> Q: Should I include quotations after my reply?
>
> http://daringfireball.net/2007/07/on_top
>
> On Wed, Sep 03, 2014 at 09:39:50PM -0300, Lucas Tanure wrote:
> > Greg,
> >
> > I'm still trying to understand the sysfs.
>
> Why? What are you using "raw kobjects" for? You should almost never
> need them.
>
> > I indeed read the documentation, I was using your "Sample kobject
> > implementation" as base of my code.
>
> Great, then it should "just work", right? :)
>
> Care to post your non-working code?
>
> thanks,
>
> greg k-h
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140903/a9a72f83/attachment.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* More info about kobj_attribute store and show functions
2014-09-04 1:39 ` Lucas Tanure
@ 2014-09-04 2:22 ` Greg KH
0 siblings, 0 replies; 9+ messages in thread
From: Greg KH @ 2014-09-04 2:22 UTC (permalink / raw)
To: kernelnewbies
On Wed, Sep 03, 2014 at 10:39:06PM -0300, Lucas Tanure wrote:
> Greg,?
>
> I was looking again to?documentation, but didn't find a explanation about the
> show and store functions. I'm missing something ??
>
> Yes, everything work if I simple use the buffer from store function, but I was
> looking for where it came from.?
> Like, It was from user space? So, I need to take care like?
> simple_write_to_buffer does with user space memory ??
If it came from userspace, it would have been marked with a __user
marking, so it's a kernel pointer.
> static ssize_t id_store(struct kobject *kobj, struct kobj_attribute *attr,
> const char *buf, size_t count)
> {
> char *buffer;
> buffer = kcalloc(cnt, sizeof(char), GFP_KERNEL);
> if (buffer) {
> if (copy_from_user(buffer, buf, cnt) == cnt) {
> if (strcmp(buffer, "Tanure") == 0)
> return cnt;
> }
> }
> }
> return -EINVAL;
> }
Just work with the buffer directly, sysfs is supposed to be "easy" to
use.
greg k-h
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2014-09-04 2:22 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-04 0:04 More info about kobj_attribute store and show functions Lucas Tanure
2014-09-04 0:10 ` Lucas Tanure
2014-09-04 0:23 ` Greg KH
2014-09-04 0:39 ` Lucas Tanure
2014-09-04 0:56 ` Greg KH
2014-09-04 1:39 ` Lucas Tanure
2014-09-04 2:22 ` Greg KH
2014-09-04 1:30 ` Jeff Haran
-- strict thread matches above, loose matches on Subject: below --
2014-09-04 0:03 Lucas Tanure
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).