proc_file_read() hack?

From: Todd Inglett (tinglett@vnet.ibm.com)
Date: Fri Mar 22 2002 - 09:34:14 EST


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

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;

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



This archive was generated by hypermail 2b29 : Sat Mar 23 2002 - 22:00:27 EST