replace all div() calls with ldiv() calls (solved problems readinf files >32kB)
Stefan Schuermans

Stefan Schuermans commited on 2012-05-06 17:15:36
Showing 1 changed files, with 15 additions and 15 deletions.

... ...
@@ -888,10 +888,10 @@ uint32_t DFS_ReadFile(PFILEINFO fileinfo, uint8_t *scratch, uint8_t *buffer, uin
888 888
 		// extra sectors to add to that number.
889 889
 		sector = fileinfo->volinfo->dataarea +
890 890
 		  ((fileinfo->cluster - 2) * fileinfo->volinfo->secperclus) +
891
-		  div(div(fileinfo->pointer,fileinfo->volinfo->secperclus * SECTOR_SIZE).rem, SECTOR_SIZE).quot;
891
+		  ldiv(ldiv(fileinfo->pointer,fileinfo->volinfo->secperclus * SECTOR_SIZE).rem, SECTOR_SIZE).quot;
892 892
 
893 893
 		// Case 1 - File pointer is not on a sector boundary
894
-		if (div(fileinfo->pointer, SECTOR_SIZE).rem) {
894
+		if (ldiv(fileinfo->pointer, SECTOR_SIZE).rem) {
895 895
 			uint16_t tempreadsize;
896 896
 
897 897
 			// We always have to go through scratch in this case
... ...
@@ -899,7 +899,7 @@ uint32_t DFS_ReadFile(PFILEINFO fileinfo, uint8_t *scratch, uint8_t *buffer, uin
899 899
 
900 900
 			// This is the number of bytes that we actually care about in the sector
901 901
 			// just read.
902
-			tempreadsize = SECTOR_SIZE - (div(fileinfo->pointer, SECTOR_SIZE).rem);
902
+			tempreadsize = SECTOR_SIZE - (ldiv(fileinfo->pointer, SECTOR_SIZE).rem);
903 903
 					
904 904
 			// Case 1A - We want the entire remainder of the sector. After this
905 905
 			// point, all passes through the read loop will be aligned on a sector
... ...
@@ -951,8 +951,8 @@ uint32_t DFS_ReadFile(PFILEINFO fileinfo, uint8_t *scratch, uint8_t *buffer, uin
951 951
 		*successcount += bytesread;
952 952
 
953 953
 		// check to see if we stepped over a cluster boundary
954
-		if (div(fileinfo->pointer - bytesread, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot !=
955
-		  div(fileinfo->pointer, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot) {
954
+		if (ldiv(fileinfo->pointer - bytesread, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot !=
955
+		  ldiv(fileinfo->pointer, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot) {
956 956
 			// An act of minor evil - we use bytesread as a scratch integer, knowing that
957 957
 			// its value is not used after updating *successcount above
958 958
 			bytesread = 0;
... ...
@@ -1011,20 +1011,20 @@ void DFS_Seek(PFILEINFO fileinfo, uint32_t offset, uint8_t *scratch)
1011 1011
 	// Case 3a - Seek size does not cross cluster boundary - 
1012 1012
 	// very simple case
1013 1013
 	// larwe 9/16/06 changed .rem to .quot in both div calls, bugfix
1014
-	if (div(fileinfo->pointer, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot ==
1015
-	  div(fileinfo->pointer + offset, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot) {
1014
+	if (ldiv(fileinfo->pointer, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot ==
1015
+	  ldiv(fileinfo->pointer + offset, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot) {
1016 1016
 		fileinfo->pointer = offset;
1017 1017
 	}
1018 1018
 	// Case 3b - Seeking across cluster boundary(ies)
1019 1019
 	else {
1020 1020
 		// round file pointer down to cluster boundary
1021
-		fileinfo->pointer = div(fileinfo->pointer, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot *
1021
+		fileinfo->pointer = ldiv(fileinfo->pointer, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot *
1022 1022
 		  fileinfo->volinfo->secperclus * SECTOR_SIZE;
1023 1023
 
1024 1024
 		// seek by clusters
1025 1025
 		// canny/reza 5/7  added endcluster related code
1026
-		endcluster = div(offset, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot;
1027
-		while ((uint16_t)div(fileinfo->pointer, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot != endcluster) {
1026
+		endcluster = ldiv(offset, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot;
1027
+		while (ldiv(fileinfo->pointer, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot != endcluster) {
1028 1028
 			fileinfo->cluster = DFS_GetFAT(fileinfo->volinfo, scratch, &tempint, fileinfo->cluster);
1029 1029
 			// Abort if there was an error
1030 1030
 			if (fileinfo->cluster == 0x0ffffff7) {
... ...
@@ -1101,10 +1101,10 @@ uint32_t DFS_WriteFile(PFILEINFO fileinfo, uint8_t *scratch, uint8_t *buffer, ui
1101 1101
 		// extra sectors to add to that number.
1102 1102
 		sector = fileinfo->volinfo->dataarea +
1103 1103
 		  ((fileinfo->cluster - 2) * fileinfo->volinfo->secperclus) +
1104
-		  div(div(fileinfo->pointer,fileinfo->volinfo->secperclus * SECTOR_SIZE).rem, SECTOR_SIZE).quot;
1104
+		  ldiv(ldiv(fileinfo->pointer,fileinfo->volinfo->secperclus * SECTOR_SIZE).rem, SECTOR_SIZE).quot;
1105 1105
 
1106 1106
 		// Case 1 - File pointer is not on a sector boundary
1107
-		if (div(fileinfo->pointer, SECTOR_SIZE).rem) {
1107
+		if (ldiv(fileinfo->pointer, SECTOR_SIZE).rem) {
1108 1108
 			uint16_t tempsize;
1109 1109
 
1110 1110
 			// We always have to go through scratch in this case
... ...
@@ -1112,7 +1112,7 @@ uint32_t DFS_WriteFile(PFILEINFO fileinfo, uint8_t *scratch, uint8_t *buffer, ui
1112 1112
 
1113 1113
 			// This is the number of bytes that we don't want to molest in the
1114 1114
 			// scratch sector just read.
1115
-			tempsize = div(fileinfo->pointer, SECTOR_SIZE).rem;
1115
+			tempsize = ldiv(fileinfo->pointer, SECTOR_SIZE).rem;
1116 1116
 					
1117 1117
 			// Case 1A - We are writing the entire remainder of the sector. After
1118 1118
 			// this point, all passes through the read loop will be aligned on a
... ...
@@ -1192,8 +1192,8 @@ uint32_t DFS_WriteFile(PFILEINFO fileinfo, uint8_t *scratch, uint8_t *buffer, ui
1192 1192
 		*successcount += byteswritten;
1193 1193
 
1194 1194
 		// check to see if we stepped over a cluster boundary
1195
-		if (div(fileinfo->pointer - byteswritten, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot !=
1196
-		  div(fileinfo->pointer, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot) {
1195
+		if (ldiv(fileinfo->pointer - byteswritten, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot !=
1196
+		  ldiv(fileinfo->pointer, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot) {
1197 1197
 		  	uint32_t lastcluster;
1198 1198
 
1199 1199
 		  	// We've transgressed into another cluster. If we were already at EOF,
1200 1200