public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Todd Inglett <tinglett@vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Subject: proc_file_read() hack?
Date: Fri, 22 Mar 2002 08:34:14 -0600	[thread overview]
Message-ID: <3C9B40E6.8010500@vnet.ibm.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 791 bytes --]

I'm trying to understand this little hack in 2.4.18's (and earlier) 
fs/proc/generic.c:

/* This is a hack to allow mangling of file pos independent
  * of actual bytes read.  Simply place the data at page,
  * return the bytes, and set `start' to the desired offset
  * as an unsigned int. - Paul.Russell@rustcorp.com.au
  */

I take it to mean that if I return a small integer for "start" instead 
of a ptr the hack will kick in.  However it compares pointers instead. 
I'll attach a patch that does it the way I am thinking -- but I may be 
misunderstanding the comment.

Or perhaps it is always assumed that I am copying my data to the given 
page?  If that is true, then the way it is coded will work but the patch 
trivially allows me to point "start" anywhere without copying.

-todd

[-- Attachment #2: fs-proc-generic.patch --]
[-- Type: text/plain, Size: 887 bytes --]

Index: fs/proc/generic.c
===================================================================
RCS file: /cvs/linuxppc64/linuxppc64_2_4/fs/proc/generic.c,v
retrieving revision 1.6
diff -u -r1.6 generic.c
--- fs/proc/generic.c	8 Oct 2001 19:19:59 -0000	1.6
+++ fs/proc/generic.c	22 Mar 2002 14:34:47 -0000
@@ -104,14 +104,14 @@
  		 * return the bytes, and set `start' to the desired offset
  		 * as an unsigned int. - Paul.Russell@rustcorp.com.au
 		 */
- 		n -= copy_to_user(buf, start < page ? page : start, n);
+ 		n -= copy_to_user(buf, (unsigned long)start < PROC_BLOCK_SIZE ? page : start, n);
 		if (n == 0) {
 			if (retval == 0)
 				retval = -EFAULT;
 			break;
 		}
 
-		*ppos += start < page ? (long)start : n; /* Move down the file */
+		*ppos += (unsigned long)start < PROC_BLOCK_SIZE ? (long)start : n; /* Move down the file */
 		nbytes -= n;
 		buf += n;
 		retval += n;

             reply	other threads:[~2002-03-22 14:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-22 14:34 Todd Inglett [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-03-23 11:40 proc_file_read() hack? J.D. Hood
2002-03-25 18:18 ` Todd Inglett
2002-03-25 19:45   ` Thomas Hood
2002-03-27 18:26     ` Todd Inglett
2002-03-28  1:02       ` Thomas Hood
2002-03-28 15:29         ` Todd Inglett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3C9B40E6.8010500@vnet.ibm.com \
    --to=tinglett@vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox