mirror of
https://github.com/reactos/reactos.git
synced 2025-04-29 18:48:53 +00:00
Major fixes for partitions larger than 4GB. Thanks to Tamlin again.
svn path=/trunk/; revision=16883
This commit is contained in:
parent
7006f75f63
commit
c7cd667539
2 changed files with 37 additions and 21 deletions
|
@ -272,7 +272,7 @@ void read_boot(DOS_FS *fs)
|
||||||
unsigned total_sectors;
|
unsigned total_sectors;
|
||||||
unsigned short logical_sector_size, sectors;
|
unsigned short logical_sector_size, sectors;
|
||||||
unsigned fat_length;
|
unsigned fat_length;
|
||||||
off_t data_size;
|
loff_t data_size;
|
||||||
|
|
||||||
fs_read(0,sizeof(b),&b);
|
fs_read(0,sizeof(b),&b);
|
||||||
logical_sector_size = GET_UNALIGNED_W(b.sector_size);
|
logical_sector_size = GET_UNALIGNED_W(b.sector_size);
|
||||||
|
@ -286,7 +286,7 @@ void read_boot(DOS_FS *fs)
|
||||||
total_sectors = sectors ? sectors : CF_LE_L(b.total_sect);
|
total_sectors = sectors ? sectors : CF_LE_L(b.total_sect);
|
||||||
if (verbose) printf("Checking we can access the last sector of the filesystem\n");
|
if (verbose) printf("Checking we can access the last sector of the filesystem\n");
|
||||||
/* Can't access last odd sector anyway, so round down */
|
/* 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);
|
logical_sector_size);
|
||||||
fat_length = CF_LE_W(b.fat_length) ?
|
fat_length = CF_LE_W(b.fat_length) ?
|
||||||
CF_LE_W(b.fat_length) : CF_LE_L(b.fat32_length);
|
CF_LE_W(b.fat_length) : CF_LE_L(b.fat32_length);
|
||||||
|
@ -296,7 +296,7 @@ void read_boot(DOS_FS *fs)
|
||||||
fs->root_entries = GET_UNALIGNED_W(b.dir_entries);
|
fs->root_entries = GET_UNALIGNED_W(b.dir_entries);
|
||||||
fs->data_start = fs->root_start+ROUND_TO_MULTIPLE(fs->root_entries <<
|
fs->data_start = fs->root_start+ROUND_TO_MULTIPLE(fs->root_entries <<
|
||||||
MSDOS_DIR_BITS,logical_sector_size);
|
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->clusters = data_size/fs->cluster_size;
|
||||||
fs->root_cluster = 0; /* indicates standard, pre-FAT32 root dir */
|
fs->root_cluster = 0; /* indicates standard, pre-FAT32 root dir */
|
||||||
fs->fsinfo_start = 0; /* no FSINFO structure */
|
fs->fsinfo_start = 0; /* no FSINFO structure */
|
||||||
|
|
|
@ -101,17 +101,22 @@ void fs_read(loff_t pos,int size,void *data)
|
||||||
{
|
{
|
||||||
CHANGE *walk;
|
CHANGE *walk;
|
||||||
int got;
|
int got;
|
||||||
#if 1 // TMN:
|
#if 1 // TMN
|
||||||
const size_t readsize_aligned = size + (512 - (size % 512)); // TMN:
|
const size_t readsize_aligned = (size % 512) ? (size + (512 - (size % 512))) : size; // TMN:
|
||||||
const loff_t seekpos_aligned = pos - (pos % 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 seek_delta = (size_t)(pos - seekpos_aligned); // TMN:
|
||||||
const size_t readsize = (pos - seekpos_aligned) + readsize_aligned; // TMN:
|
const size_t readsize = (size_t)(pos - seekpos_aligned) + readsize_aligned; // TMN:
|
||||||
char* tmpBuf = malloc(readsize); // TMN:
|
char* tmpBuf = malloc(readsize_aligned); // TMN:
|
||||||
if (llseek(fd,seekpos_aligned,0) != seekpos_aligned) pdie("Seek to %lld",pos);
|
#ifdef _MSC_VER
|
||||||
if ((got = read(fd,tmpBuf,readsize_aligned)) < 0) pdie("Read %d bytes at %lld",size,pos);
|
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);
|
assert(got >= size);
|
||||||
got = size;
|
got = size;
|
||||||
assert(seek_delta + size < readsize);
|
assert(seek_delta + size <= readsize);
|
||||||
memcpy(data, tmpBuf+seek_delta, size);
|
memcpy(data, tmpBuf+seek_delta, size);
|
||||||
free(tmpBuf);
|
free(tmpBuf);
|
||||||
#else // TMN:
|
#else // TMN:
|
||||||
|
@ -122,10 +127,10 @@ void fs_read(loff_t pos,int size,void *data)
|
||||||
for (walk = changes; walk; walk = walk->next) {
|
for (walk = changes; walk; walk = walk->next) {
|
||||||
if (walk->pos < pos+size && walk->pos+walk->size > pos) {
|
if (walk->pos < pos+size && walk->pos+walk->size > pos) {
|
||||||
if (walk->pos < pos)
|
if (walk->pos < pos)
|
||||||
memcpy(data,(char *) walk->data+pos-walk->pos,min(size,
|
memcpy(data,(char *) walk->data+pos-walk->pos,min((size_t)size,
|
||||||
walk->size-pos+walk->pos));
|
(size_t)(walk->size-pos+walk->pos)));
|
||||||
else memcpy((char *) data+walk->pos-pos,walk->data,min(walk->size,
|
else memcpy((char *) data+walk->pos-pos,walk->data,min((size_t)walk->size,
|
||||||
size+pos-walk->pos));
|
(size_t)(size+pos-walk->pos)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,10 +141,21 @@ int fs_test(loff_t pos,int size)
|
||||||
void *scratch;
|
void *scratch;
|
||||||
int okay;
|
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);
|
if (llseek(fd,pos,0) != pos) pdie("Seek to %lld",pos);
|
||||||
scratch = alloc(size);
|
scratch = alloc(size);
|
||||||
okay = read(fd,scratch,size) == size;
|
okay = read(fd,scratch,size) == size;
|
||||||
free(scratch);
|
free(scratch);
|
||||||
|
#endif // TMN:
|
||||||
return okay;
|
return okay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,7 +234,7 @@ int fs_changed(void)
|
||||||
|
|
||||||
|
|
||||||
#define O_SHORT_LIVED _O_SHORT_LIVED
|
#define O_SHORT_LIVED _O_SHORT_LIVED
|
||||||
#define O_ACCMODE 3
|
//#define O_ACCMODE 3
|
||||||
#define O_NONE 3
|
#define O_NONE 3
|
||||||
#define O_BACKUP 0x10000
|
#define O_BACKUP 0x10000
|
||||||
#define O_SHARED 0x20000
|
#define O_SHARED 0x20000
|
||||||
|
@ -368,14 +384,14 @@ static loff_t WIN32llseek(int fd, loff_t offset, int whence)
|
||||||
long lo, hi;
|
long lo, hi;
|
||||||
DWORD err;
|
DWORD err;
|
||||||
|
|
||||||
lo = offset & 0xffffffff;
|
lo = (long)(offset & 0xffffffff);
|
||||||
hi = offset >> 32;
|
hi = (long)(offset >> 32);
|
||||||
lo = SetFilePointer((HANDLE)fd, lo, &hi, whence);
|
lo = SetFilePointer((HANDLE)fd, lo, &hi, whence);
|
||||||
if (lo == 0xFFFFFFFF && (err = GetLastError()) != NO_ERROR) {
|
if (lo == 0xFFFFFFFF && (err = GetLastError()) != NO_ERROR) {
|
||||||
errno = err;
|
errno = err;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return ((loff_t)hi << 32) | (off_t)lo;
|
return ((loff_t)hi << 32) | (__u32)lo;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fsctl(int fd, int code)
|
int fsctl(int fd, int code)
|
||||||
|
|
Loading…
Reference in a new issue