shithub: riscv

Download patch

ref: 90bd02d5af84eaaffe5adb1a175c8fbb2295a7e4
parent: 2e85e328864c215c2efa228f129ce3fa6aa1db1f
author: cinap_lenrek <[email protected]>
date: Tue Jul 14 18:33:27 EDT 2015

mk9660: write data in alphabetical order

*after* writing, the directory tree gets alphabetically sorted for
path table. this causes data to not be in the same order as it was
written causing seeks when taring up the filesystem.

so instead write the files in alphabetical order as well to better
match the directory sorting.

--- a/sys/src/cmd/disk/9660/write.c
+++ b/sys/src/cmd/disk/9660/write.c
@@ -53,6 +53,16 @@
 	Cwrite(cd, buf, Blocksize);
 }
 
+static int
+alphacmp(void *va, void *vb)
+{
+	Direc *a, *b;
+
+	a = va;
+	b = vb;
+	return strcmp(a->name, b->name);
+}
+
 /*
  * Write each non-directory file.  We copy the file to
  * the cd image, and then if it turns out that we've
@@ -72,6 +82,9 @@
 	Dumpdir *dd;
 
 	if(direc->mode & DMDIR) {
+		/* write data in alphabetical order avoiding seeks */
+		qsort(direc->child, direc->nchild, sizeof(direc->child[0]), alphacmp);
+
 		for(i=0; i<direc->nchild; i++)
 			writefiles(d, cd, &direc->child[i]);
 		return;