lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Pine.LNX.4.44L0.0908181114020.3484-100000@iolanthe.rowland.org>
Date:	Tue, 18 Aug 2009 11:16:50 -0400 (EDT)
From:	Alan Stern <stern@...land.harvard.edu>
To:	"Rick L. Vinyard, Jr." <rvinyard@...nmsu.edu>
cc:	Linux USB <linux-usb@...r.kernel.org>,
	LKML <linux-kernel@...r.kernel.org>
Subject: Re: Purpose of parameter in sysfs binary read

On Tue, 18 Aug 2009, 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?

It's the same offset argument that's found in all read or write 
methods for all types of files.  It refers to the offset from the start 
of the file.

> 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);

Neither one.  If the kernel wanted to add an offset to buf, it would 
have done so before calling the function.  The code should be more like 
this:

	memcpy(buf, bindata + offset, min(size, bsize - offset));

Alan Stern

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ