Port scatterlist from Linux
authorXiao Jia <stfairy@gmail.com>
Thu, 17 Sep 2015 00:01:18 +0000 (17:01 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 23 Sep 2015 20:46:26 +0000 (16:46 -0400)
[brho: added the copyright from Linux's lib/scatterlist.c]

kern/src/Kbuild
kern/src/scatterlist.c [new file with mode: 0644]

index 745d16f..2302938 100644 (file)
@@ -43,6 +43,7 @@ obj-y                                         += radix.o
 obj-y                                          += readline.o
 obj-y                                          += rendez.o
 obj-y                                          += rwlock.o
+obj-y                                          += scatterlist.o
 obj-y                                          += schedule.o
 obj-y                                          += slab.o
 obj-y                                          += smallidpool.o
diff --git a/kern/src/scatterlist.c b/kern/src/scatterlist.c
new file mode 100644 (file)
index 0000000..aa4d05c
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2007 Jens Axboe <jens.axboe@oracle.com>
+ *
+ * Scatterlist handling helpers.
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2. See the file COPYING for more details.
+  */
+
+#include <linux_compat.h>
+
+void sg_init_table(struct scatterlist *sgl, unsigned int nents)
+{
+       memset(sgl, 0, sizeof(*sgl) * nents);
+       sg_mark_end(&sgl[nents - 1]);
+}
+
+struct scatterlist *sg_next(struct scatterlist *sg)
+{
+       if (sg_is_last(sg))
+               return NULL;
+
+       sg++;
+       if (unlikely(sg_is_chain(sg)))
+               sg = sg_chain_ptr(sg);
+
+       return sg;
+}