shithub: 9ferno

Download patch

ref: f167a2f5c1c4a71a5a091599ea3a3f625108b781
parent: 8d0725d57a988ed0ed2ef0a33e0cebe48a85b5db
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Sep 11 09:53:12 EDT 2021

9boot: fix isowalk() for directories spanning multiple sectors

directory entries cannot span sector boundaries, meaning
that the end of a sector would be zero padded until the
next sector.

we have to skip over these zero paddings to fully read
the directory.

--- a/os/boot/efi/iso.c	Fri Sep 10 19:52:01 2021
+++ b/os/boot/efi/iso.c	Sat Sep 11 09:53:12 2021
@@ -129,15 +129,19 @@
 		return 0;
 
 	for(;;){
-		if(readn(ex, &d, Dirsz) != Dirsz)
+		if(read(ex, &d.dirlen, 1) != 1)
 			break;
 		if(d.dirlen == 0)
+			continue;	/* zero padding to next sector */
+		if(read(ex, &d.dirlen + 1, Dirsz-1) != Dirsz-1)
 			break;
-		if(readn(ex, name, d.namelen) != d.namelen)
+		if(read(ex, name, d.namelen) != d.namelen)
 			break;
 		i = d.dirlen - (Dirsz + d.namelen);
-		while(i-- > 0)
-			read(ex, &c, 1);
+		while(i-- > 0){
+			if(read(ex, &c, 1) != 1)
+				break;
+		}
 		for(i=0; i<d.namelen; i++){
 			c = name[i];
 			if(c >= 'A' && c <= 'Z'){
--- a/os/boot/pc/iso.c	Fri Sep 10 19:52:01 2021
+++ b/os/boot/pc/iso.c	Sat Sep 11 09:53:12 2021
@@ -111,15 +111,19 @@
 	ex->len = *((ulong*)(ex->buf + 156 + 10));
 
 	for(;;){
-		if(readn(ex, &d, Dirsz) != Dirsz)
+		if(read(ex, &d.dirlen, 1) != 1)
 			break;
 		if(d.dirlen == 0)
+			continue;	/* zero padding to next sector */
+		if(read(ex, &d.dirlen + 1, Dirsz-1) != Dirsz-1)
 			break;
-		if(readn(ex, name, d.namelen) != d.namelen)
+		if(read(ex, name, d.namelen) != d.namelen)
 			break;
 		i = d.dirlen - (Dirsz + d.namelen);
-		while(i-- > 0)
-			read(ex, &c, 1);
+		while(i-- > 0){
+			if(read(ex, &c, 1) != 1)
+				break;
+		}
 		for(i=0; i<d.namelen; i++){
 			c = name[i];
 			if(c >= 'A' && c <= 'Z'){