Major fixes for partitions larger than 4GB. Thanks to Tamlin again.
Modified: trunk/rosapps/sysutils/dosfsck/boot.c
Modified: trunk/rosapps/sysutils/dosfsck/io.c

Modified: trunk/rosapps/sysutils/dosfsck/boot.c
--- trunk/rosapps/sysutils/dosfsck/boot.c	2005-07-29 21:59:06 UTC (rev 16882)
+++ trunk/rosapps/sysutils/dosfsck/boot.c	2005-07-29 22:22:12 UTC (rev 16883)
@@ -272,7 +272,7 @@
     unsigned total_sectors;
     unsigned short logical_sector_size, sectors;
     unsigned fat_length;
-    off_t data_size;
+    loff_t data_size;
 
     fs_read(0,sizeof(b),&b);
     logical_sector_size = GET_UNALIGNED_W(b.sector_size);
@@ -286,7 +286,7 @@
     total_sectors = sectors ? sectors : CF_LE_L(b.total_sect);
     if (verbose) printf("Checking we can access the last sector of the filesystem\n");
     /* Can't access last odd sector anyway, so round down */
-    fs_test((off_t)((total_sectors & ~1)-1)*(off_t)logical_sector_size,
+    fs_test((loff_t)((total_sectors & ~1)-1)*(loff_t)logical_sector_size,
 	    logical_sector_size);
     fat_length = CF_LE_W(b.fat_length) ?
 		 CF_LE_W(b.fat_length) : CF_LE_L(b.fat32_length);
@@ -296,7 +296,7 @@
     fs->root_entries = GET_UNALIGNED_W(b.dir_entries);
     fs->data_start = fs->root_start+ROUND_TO_MULTIPLE(fs->root_entries <<
       MSDOS_DIR_BITS,logical_sector_size);
-    data_size = (off_t)total_sectors*logical_sector_size-fs->data_start;
+    data_size = (loff_t)total_sectors*logical_sector_size-fs->data_start;
     fs->clusters = data_size/fs->cluster_size;
     fs->root_cluster = 0; /* indicates standard, pre-FAT32 root dir */
     fs->fsinfo_start = 0; /* no FSINFO structure */

Modified: trunk/rosapps/sysutils/dosfsck/io.c
--- trunk/rosapps/sysutils/dosfsck/io.c	2005-07-29 21:59:06 UTC (rev 16882)
+++ trunk/rosapps/sysutils/dosfsck/io.c	2005-07-29 22:22:12 UTC (rev 16883)
@@ -101,17 +101,22 @@
 {
     CHANGE *walk;
     int got;
-#if 1 // TMN:
-	const size_t readsize_aligned = size + (512 - (size % 512));        // TMN:
-	const loff_t seekpos_aligned = pos - (pos % 512);                   // TMN:
-	const size_t seek_delta = (size_t)(pos - seekpos_aligned);          // TMN:
-	const size_t readsize = (pos - seekpos_aligned) + readsize_aligned; // TMN: 
-	char* tmpBuf = malloc(readsize);                                    // TMN:
-    if (llseek(fd,seekpos_aligned,0) != seekpos_aligned) pdie("Seek to %lld",pos);
-    if ((got = read(fd,tmpBuf,readsize_aligned)) < 0) pdie("Read %d bytes at %lld",size,pos);
+#if 1 // TMN
+	const size_t readsize_aligned = (size % 512) ? (size + (512 - (size % 512))) : size;        // TMN:
+ 	const loff_t seekpos_aligned = pos - (pos % 512);                   // TMN:
+ 	const size_t seek_delta = (size_t)(pos - seekpos_aligned);          // TMN:
+	const size_t readsize = (size_t)(pos - seekpos_aligned) + readsize_aligned; // TMN: 
+	char* tmpBuf = malloc(readsize_aligned);                                    // TMN:
+#ifdef _MSC_VER
+    if (llseek(fd,seekpos_aligned,0) != seekpos_aligned) pdie("Seek to %I64d",pos);
+    if ((got = read(fd,tmpBuf,readsize_aligned)) < 0) pdie("Read %d bytes at %I64dd",size,pos);
+#else
+     if (llseek(fd,seekpos_aligned,0) != seekpos_aligned) pdie("Seek to %lld",pos);
+     if ((got = read(fd,tmpBuf,readsize_aligned)) < 0) pdie("Read %d bytes at %lld",size,pos);
+#endif
 	assert(got >= size);
-	got = size;
-	assert(seek_delta + size < readsize);
+	got = size;
+	assert(seek_delta + size <= readsize);
 	memcpy(data, tmpBuf+seek_delta, size);
 	free(tmpBuf);
 #else // TMN:
@@ -122,10 +127,10 @@
     for (walk = changes; walk; walk = walk->next) {
 	if (walk->pos < pos+size && walk->pos+walk->size > pos) {
 	    if (walk->pos < pos)
-		memcpy(data,(char *) walk->data+pos-walk->pos,min(size,
-		  walk->size-pos+walk->pos));
-	    else memcpy((char *) data+walk->pos-pos,walk->data,min(walk->size,
-		  size+pos-walk->pos));
+		memcpy(data,(char *) walk->data+pos-walk->pos,min((size_t)size,
+		  (size_t)(walk->size-pos+walk->pos)));
+	    else memcpy((char *) data+walk->pos-pos,walk->data,min((size_t)walk->size,
+		  (size_t)(size+pos-walk->pos)));
 	}
     }
 }
@@ -136,10 +141,21 @@
     void *scratch;
     int okay;
 
+#if 1 // TMN
+	const size_t readsize_aligned = (size % 512) ? (size + (512 - (size % 512))) : size;        // TMN:
+	const loff_t seekpos_aligned = pos - (pos % 512);                   // TMN:
+	const size_t seek_delta = (size_t)(pos - seekpos_aligned);          // TMN:
+	const size_t readsize = (size_t)(pos - seekpos_aligned) + readsize_aligned; // TMN: 
+    scratch = alloc(readsize_aligned);
+    if (llseek(fd,seekpos_aligned,0) != seekpos_aligned) pdie("Seek to %lld",pos);
+    okay = read(fd,scratch,readsize_aligned) == (int)readsize_aligned;
+    free(scratch);
+#else // TMN:
     if (llseek(fd,pos,0) != pos) pdie("Seek to %lld",pos);
     scratch = alloc(size);
     okay = read(fd,scratch,size) == size;
     free(scratch);
+#endif // TMN:
     return okay;
 }
 
@@ -218,7 +234,7 @@
 
 
 #define O_SHORT_LIVED   _O_SHORT_LIVED
-#define O_ACCMODE       3
+//#define O_ACCMODE       3
 #define O_NONE          3
 #define O_BACKUP        0x10000
 #define O_SHARED        0x20000
@@ -368,14 +384,14 @@
 	long lo, hi;
 	DWORD err;
 
-	lo = offset & 0xffffffff;
-	hi = offset >> 32;
+	lo = (long)(offset & 0xffffffff);
+	hi = (long)(offset >> 32);
 	lo = SetFilePointer((HANDLE)fd, lo, &hi, whence);
 	if (lo == 0xFFFFFFFF && (err = GetLastError()) != NO_ERROR) {
 		errno = err;
 		return -1;
 	}
-	return ((loff_t)hi << 32) | (off_t)lo;
+	return ((loff_t)hi << 32) | (__u32)lo;
 }
 
 int fsctl(int fd, int code)