From 90bd02d5af84eaaffe5adb1a175c8fbb2295a7e4 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Tue, 14 Jul 2015 22:33:27 +0200 Subject: [PATCH] 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. --- sys/src/cmd/disk/9660/write.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sys/src/cmd/disk/9660/write.c b/sys/src/cmd/disk/9660/write.c index e45f21c19..263e803c9 100644 --- a/sys/src/cmd/disk/9660/write.c +++ b/sys/src/cmd/disk/9660/write.c @@ -53,6 +53,16 @@ rewritedotdot(Cdimg *cd, Direc *d, Direc *dparent) 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 @@ writefiles(Dump *d, Cdimg *cd, Direc *direc) 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; inchild; i++) writefiles(d, cd, &direc->child[i]); return;