Skip to contentSkip to conversation

proc_file_read() hack?

PATCH Todd Inglett 1 participant 1 message Mar 22, 2002

lore
Share & tools
lore
#0 lore raw

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. - [email protected] */

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

proc/generic.c +2 -2
diff -u -r1.6 generic.c
@@ -104,14 +104,14 @@
  		 * return the bytes, and set `start' to the desired offset
  		 * as an unsigned int. - [email protected]
 		 */
- 		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;