Re: Purpose of parameter in sysfs binary read

From: Greg KH
Date: Tue Aug 18 2009 - 11:17:08 EST


On Tue, Aug 18, 2009 at 08:55:29AM -0600, Rick L. Vinyard, Jr. wrote:
> The read function pointer of the sysfs bin_attribute structure has this
> signature:
>
> ssize_t (*read)(struct kobject *kobj, struct bin_attribute *attr,
> char *buf, loff_t offset, size_t size);
>
> I've figured out the purpose of all the parameters except the loff_t
> parameter.
>
> Obviously it's an offset of some sort, but what is the meaning of the offset?

The same as any read() call, it comes from the vfs.

> If I have binary data in a char* named bindata of size bsize, should it be
> copied into buf+offset in something like:
> memcpy(buf+offset, bindata, bsize);
>
> Or, is it an offset from both buf and bindata in something like:
> memcpy(buf+offset, bindata+offset, bsize-offset);

What are you using the binary sysfs attribute for? It should ONLY be
used as a pass-through to and from hardware, with no interpretation by
the kernel at all.

See the existing users of this interface in the kernel for examples of
how to use the offset parameter.

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/