unsigned int rel, oldabs, oldrel;
blocks = 0;
-
+
oldabs = oldrel = rel = 0;
while (block <= This->last_fat && block != 1 && block) {
}
RelCluNr = where / clus_size;
-
+
if (RelCluNr >= This->PreviousRelCluNr){
CurCluNr = This->PreviousRelCluNr;
AbsCluNr = This->PreviousAbsCluNr;
AbsCluNr, NewCluNr);
exit(1);
}
- if(CurCluNr == RelCluNr + NrClu)
+ if(CurCluNr == RelCluNr + NrClu)
break;
if (NewCluNr > Fs->last_fat && mode == MT_WRITE){
/* if at end, and writing, extend it */
}
maximize(*len, (1 + CurCluNr - RelCluNr) * clus_size - offset);
-
+
end = where + *len;
if(batchmode &&
mode == MT_WRITE &&
end >= This->FileSize) {
+ /* In batch mode, when writing at end of file, "pad"
+ * to nearest cluster boundary so that we don't have
+ * to read that data back from disk. */
*len += ROUND_UP(end, clus_size) - end;
}
exit(1);
}
- *res = sectorsToBytes((Stream_t*)Fs,
+ *res = sectorsToBytes(Fs,
(This->PreviousAbsCluNr-2) * Fs->cluster_size +
- Fs->clus_start) + offset;
+ Fs->clus_start) + to_mt_off_t(offset);
return 1;
}
{
Fs_t *Fs = This->Fs;
- if(Fs->dir_len * Fs->sector_size + 0u < (size_t) where) {
+ if(Fs->dir_len * Fs->sector_size < where) {
*len = 0;
errno = ENOSPC;
return -2;
maximize(*len, Fs->dir_len * Fs->sector_size - where);
if (*len == 0)
return 0;
-
- *res = sectorsToBytes((Stream_t*)Fs, Fs->dir_start) + where;
+
+ *res = sectorsToBytes(Fs, Fs->dir_start) +
+ to_mt_off_t(where);
return 1;
}
-
+
static ssize_t read_file(Stream_t *Stream, char *buf, mt_off_t iwhere,
size_t ilen)
int err;
uint32_t where = truncMtOffTo32u(iwhere);
uint32_t len = truncSizeTo32u(ilen);
-
+
Stream_t *Disk = This->Fs->Next;
-
+
err = This->map(This, where, &len, MT_READ, &pos);
if(err <= 0)
return err;
uint32_t bytesWritten;
Stream_t *Disk = This->Fs->Next;
uint32_t where = truncMtOffTo32u(iwhere);
+ uint32_t maxLen = UINT32_MAX-where;
uint32_t len;
int err;
- if(iwhere+(mt_off_t)ilen > UINT32_MAX) {
- ilen=(size_t) (UINT32_MAX-iwhere);
- }
- len = truncSizeTo32u(ilen);
+ if(ilen > maxLen) {
+ len = maxLen;
+ } else
+ len = (uint32_t) ilen;
requestedLen = len;
err = This->map(This, where, &len, MT_WRITE, &pos);
if( err <= 0)
/* Error occured */
return ret;
if((uint32_t)ret > requestedLen)
+ /* More data than requested may be written to lower
+ * levels if batch mode is active, in order to "pad"
+ * the last cluster of a file, so that we don't have
+ * to read that back from disk */
bytesWritten = requestedLen;
else
- bytesWritten = requestedLen;
+ bytesWritten = (uint32_t)ret;
if (where + bytesWritten > This->FileSize )
This->FileSize = where + bytesWritten;
recalcPreallocSize(This);
- return ret;
+ return (ssize_t)bytesWritten;
}
{
struct timeval tv;
struct timezone tz;
-
+
gettimeofday(&tv, &tz);
tzone = tz.tz_minuteswest * 60L;
}
}
-static int get_file_data(Stream_t *Stream, time_t *date, mt_size_t *size,
+static int get_file_data(Stream_t *Stream, time_t *date, mt_off_t *size,
int *type, uint32_t *address)
{
DeclareThis(File_t);
if(date)
*date = conv_stamp(& This->direntry.dir);
if(size)
- *size = (mt_size_t) This->FileSize;
+ *size = to_mt_off_t(This->FileSize);
if(type)
*type = This->direntry.dir.attr & ATTR_DIR;
if(address)
static void init_hash(void)
{
static int is_initialised=0;
-
+
if(!is_initialised){
make_ht(func1, func2, comp, 20, &filehash);
is_initialised = 1;