Ask For Comment: add offset_in_sg parameter for data copy in scatter list

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Hillf Danton
Date: Monday, October 4, 2010 - 4:43 am

Two routines, modeled from sg_copy_from/to_buffer, are added for cases that
offset_in_sg has to be taken as a parameter.

Then it seems that the procedure of sg_miter_start/next/stop in
sg_copy_buffer()
will no longer be modeled, and all __xyz elements of miter are
untouched as well,
outside scatter list.

Signed-off-by: Hillf Danton <dhillf@gmail.com>
---

--- o/linux-2.6.36-rc4/include/linux/scatterlist.h	2010-09-13
07:07:38.000000000 +0800
+++ m/linux-2.6.36-rc4/include/linux/scatterlist.h	2010-10-04
18:56:00.000000000 +0800
@@ -217,6 +217,12 @@ size_t sg_copy_from_buffer(struct scatte
 			   void *buf, size_t buflen);
 size_t sg_copy_to_buffer(struct scatterlist *sgl, unsigned int nents,
 			 void *buf, size_t buflen);
+size_t sg_copy_from_buffer_offset(struct scatterlist *sgl, unsigned int nents,
+			   void *buf, size_t buflen,
+			   unsigned int offset_in_sg);
+size_t sg_copy_to_buffer_offset(struct scatterlist *sgl, unsigned int nents,
+			 void *buf, size_t buflen,
+			 unsigned int offset_in_sg);

 /*
  * Maximum number of entries that will be allocated in one piece, if
--- o/linux-2.6.36-rc4/lib/scatterlist.c	2010-09-13 07:07:38.000000000 +0800
+++ m/linux-2.6.36-rc4/lib/scatterlist.c	2010-10-04 19:14:10.000000000 +0800
@@ -449,7 +449,8 @@ EXPORT_SYMBOL(sg_miter_stop);
  *
  **/
 static size_t sg_copy_buffer(struct scatterlist *sgl, unsigned int nents,
-			     void *buf, size_t buflen, int to_buffer)
+			     void *buf, size_t buflen, int to_buffer,
+			     unsigned int offset_in_sg)
 {
 	unsigned int offset = 0;
 	struct sg_mapping_iter miter;
@@ -462,6 +463,7 @@ static size_t sg_copy_buffer(struct scat
 		sg_flags |= SG_MITER_TO_SG;

 	sg_miter_start(&miter, sgl, nents, sg_flags);
+	miter.__offset = offset_in_sg;

 	local_irq_save(flags);

@@ -497,7 +499,7 @@ static size_t sg_copy_buffer(struct scat
 size_t sg_copy_from_buffer(struct scatterlist *sgl, unsigned int nents,
 			   void *buf, size_t buflen)
 {
-	return sg_copy_buffer(sgl, nents, buf, buflen, 0);
+	return sg_copy_buffer(sgl, nents, buf, buflen, 0, 0);
 }
 EXPORT_SYMBOL(sg_copy_from_buffer);

@@ -514,6 +516,28 @@ EXPORT_SYMBOL(sg_copy_from_buffer);
 size_t sg_copy_to_buffer(struct scatterlist *sgl, unsigned int nents,
 			 void *buf, size_t buflen)
 {
-	return sg_copy_buffer(sgl, nents, buf, buflen, 1);
+	return sg_copy_buffer(sgl, nents, buf, buflen, 1, 0);
 }
 EXPORT_SYMBOL(sg_copy_to_buffer);
+
+/*
+ * Like the above, and with parameter offset_in_sg
+ */
+
+size_t
+sg_copy_from_buffer_offset(struct scatterlist *sgl, unsigned int nents,
+			   void *buf, size_t buflen,
+			   unsigned int offset_in_sg)
+{
+	return sg_copy_buffer(sgl, nents, buf, buflen, 0, offset_in_sg);
+}
+EXPORT_SYMBOL(sg_copy_from_buffer_offset);
+
+size_t
+sg_copy_to_buffer_offset(struct scatterlist *sgl, unsigned int nents,
+			 void *buf, size_t buflen,
+			 unsigned int offset_in_sg);
+{
+	return sg_copy_buffer(sgl, nents, buf, buflen, 1, offset_in_sg);
+}
+EXPORT_SYMBOL(sg_copy_to_buffer_offset);
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Ask For Comment: add offset_in_sg parameter for data copy ..., Hillf Danton, (Mon Oct 4, 4:43 am)