"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/memory.cpp" between
bed-3.0.3.src.tar.xz and bed-3.1.0.src.tar.xz

About: bed is an adjustable data format binary editor.

memory.cpp  (bed-3.0.3.src.tar.xz):memory.cpp  (bed-3.1.0.src.tar.xz)
skipping to change at line 52 skipping to change at line 52
#include <ctype.h> #include <ctype.h>
#include "memory.h" #include "memory.h"
#include "system.h" #include "system.h"
#include "myalloc.h" #include "myalloc.h"
#include "main.h" #include "main.h"
#include "misc.h" #include "misc.h"
#ifdef USE_WINFILE #ifdef USE_WINFILE
#include <windows.h> #include <windows.h>
#include <winioctl.h> #include <winioctl.h>
#include "win.h" #include "win.h"
#include "winsparsecp.h"
#endif #endif
extern const char NEWFILENAME[]; extern const char NEWFILENAME[];
extern const int newfilenamelen; extern const int newfilenamelen;
const char NEWFILENAME[]="Untitled"; const char NEWFILENAME[]="Untitled";
const int newfilenamelen=sizeof(NEWFILENAME)-1; const int newfilenamelen=sizeof(NEWFILENAME)-1;
//s/sectoralloc(\([^;]*;\)$/alignedalloc(blocksize(),\1/g //s/sectoralloc(\([^;]*;\)$/alignedalloc(blocksize(),\1/g
//s/sectorfree\(.*\)$/alignedfree\1/g //s/sectorfree\(.*\)$/alignedfree\1/g
skipping to change at line 658 skipping to change at line 659
return 0; return 0;
} }
#endif #endif
int setblocksize(int bsize) { int setblocksize(int bsize) {
int BLOCKSIZE; int BLOCKSIZE;
if(userblocksize>0) { if(userblocksize>0) {
BLOCKSIZE=userblocksize; BLOCKSIZE=userblocksize;
} }
else { else {
if(bsize>0) if(bsize>STBLOCKSIZE)
BLOCKSIZE=bsize; BLOCKSIZE=bsize;
else else
BLOCKSIZE=STBLOCKSIZE; BLOCKSIZE=STBLOCKSIZE;
} }
return BLOCKSIZE; return BLOCKSIZE;
} }
#ifdef __FreeBSD__ #ifdef __FreeBSD__
int getblockreadonly(FILEHANDLE filehandle) int getblockreadonly(FILEHANDLE filehandle)
{ {
skipping to change at line 1001 skipping to change at line 1002
filename=myallocar( char,len+3); filename=myallocar( char,len+3);
memcpy(filename,name,len); memcpy(filename,name,len);
openfile(); openfile();
#ifdef BIOSDISK #ifdef BIOSDISK
if(infodisk) if(infodisk)
setregistrysize(infodisk,filesize); setregistrysize(infodisk,filesize);
#endif #endif
diskfilesize=filesize; diskfilesize=filesize;
useddiskfilesize=diskfilesize;
#if defined(USETHREADS) && !defined(INTSEARCH) #if defined(USETHREADS) && !defined(INTSEARCH)
if(filesize>(OFFTYPE)40000000L) if(filesize>(OFFTYPE)40000000L)
// lastforward|=0x10; // lastforward|=0x10;
#endif #endif
} }
int newfilesize=1024; int newfilesize=1024;
extern int newfilesize; extern int newfilesize;
Memory::Memory(const char *name): Memory::Memory(const char *name):
skipping to change at line 1085 skipping to change at line 1088
databuffree( iter->data.buf); databuffree( iter->data.buf);
tree.empty(); tree.empty();
return 0; return 0;
} }
Memory::~Memory() { Memory::~Memory() {
endfile(); endfile();
DESTROYUSELSEEK; DESTROYUSELSEEK;
} }
#ifdef USE_WINFILEnietgebruikt
int myftruncate(FILEHANDLE output,OFFTYPE size) {
if(setfilepos(output,size)!=size) {
return -1;
}
if(!SetEndOfFile(output)) {
return -1;
}
return 0;
}
#endif
#ifdef USE_WINFILE
#define myftruncate sparsesize
extern bool mksparse(HANDLE hOutFile) ;
#else
#define mksparse(x)
#endif
FILEHANDLE Memory::reopen() {
FILEHANDLE output=openreadwrite(filename);
if(output==MY_INVALID_HANDLE_VALUE)
return MY_INVALID_HANDLE_VALUE;
if(filesize!=diskfilesize) {
if(filesize>useddiskfilesize) {
mksparse(output);
if( FTRUNCATEHANDLE(output,useddiskfilesize)!=0) {
closefilehandle(output);
return MY_INVALID_HANDLE_VALUE;
}
}
if( FTRUNCATEHANDLE(output,filesize)!=0) {
closefilehandle(output);
return MY_INVALID_HANDLE_VALUE;
}
}
return output;
}
/* Bepaal of file veranderd is na opstarte of laatste keer saven */ /* Bepaal of file veranderd is na opstarte of laatste keer saven */
/* Ga alle nodes af en save die nodes. */ /* Ga alle nodes af en save die nodes. */
/* Nodes delete */ /* Nodes delete */
/* */ /* */
/* Saven van een node: */ /* Saven van een node: */
/* - ga naar positie file; */ /* - ga naar positie file; */
/* - schrijf gegevens in file */ /* - schrijf gegevens in file */
/* - delete gegevens */ /* - delete gegevens */
/* Sat Oct 3 00:50:05 1998 */ /* Sat Oct 3 00:50:05 1998 */
int Memory::savenode(FILEHANDLE output, Treel *node) { int Memory::savenode(FILEHANDLE output, Treel *node) {
DEBUG("Save " BLOCKPRINT "\n",node->data.blocknr); DEBUG("Save " BLOCKPRINT "\n",node->data.blocknr);
OFFTYPE diff=filesize-(node->data.blocknr*BLOCKSIZE); OFFTYPE diff=filesize-(node->data.blocknr*BLOCKSIZE);
if(diff>0) { if(diff>0) {
BEDS_SIZE_T size=(diff<BLOCKSIZE)?diff:BLOCKSIZE; BEDS_SIZE_T size=(diff<BLOCKSIZE)?diff:BLOCKSIZE;
if(node->data.size!=size) if(node->data.size<size) {
fprintf(stderr,"WARNING: savenode/1: not enough in node " fprintf(stderr,"WARNING: savenode/1: not enough in node "
BLOCKPRINT " " SIZE_TPRINT "!=" SIZE_TPRINT "\n",node->data.blocknr,size,node-> BLOCKPRINT " " SIZE_TPRINT "<" SIZE_TPRINT "\n",node->data.blocknr,size,node->d
data.size); ata.size);
return writeat(output,node->data.buf,node->data.size,node->data.b size=node->data.size;
locknr*BLOCKSIZE); }
return writeat(output,node->data.buf,size,node->data.blocknr*BLOC
KSIZE);
} }
return 0; return 0;
} }
int Memory::touched(void) { int Memory::touched(void) {
if(isnewfile()) if(isnewfile())
return 0; return 0;
#ifdef BIOSDISK #ifdef BIOSDISK
if(!infodisk) if(!infodisk)
#endif #endif
skipping to change at line 1149 skipping to change at line 1192
if(st.st_mtime!=statdata.st_mtime) if(st.st_mtime!=statdata.st_mtime)
return 5; return 5;
if(st.st_size!=statdata.st_size) if(st.st_size!=statdata.st_size)
return 3; return 3;
if(st.st_ino!=statdata.st_ino) if(st.st_ino!=statdata.st_ino)
return 4; return 4;
#endif #endif
} }
return 0; return 0;
} }
#ifdef USE_WINFILEnietgebruikt
int myftruncate(FILEHANDLE output,OFFTYPE size) {
if(setfilepos(output,size)!=size) {
return -1;
}
if(!SetEndOfFile(output)) {
return -1;
}
return 0;
}
#endif
OFFTYPE setfilepos(FILEHANDLE file,OFFTYPE offset) { OFFTYPE setfilepos(FILEHANDLE file,OFFTYPE offset) {
#ifdef USE_WINFILE #ifdef USE_WINFILE
LONG hi=offset>>32; LONG hi=offset>>32;
DWORD lo; DWORD lo;
lo=SetFilePointer(file, lo=SetFilePointer(file,
offset&0xFFFFFFFF, // number of bytes to move file pointer offset&0xFFFFFFFF, // number of bytes to move file pointer
&hi, // address of high-order word of distance to move &hi, // address of high-order word of distance to move
FILE_BEGIN FILE_BEGIN
); );
if(lo==0xFFFFFFFF&&GetLastError()) { if(lo==0xFFFFFFFF&&GetLastError()) {
return OFFTYPEINVALID; return OFFTYPEINVALID;
} }
return (lo|(((OFFTYPE)hi)<<32)); return (lo|(((OFFTYPE)hi)<<32));
#else #else
return LSEEK(file,offset,SEEK_SET); return LSEEK(file,offset,SEEK_SET);
#endif #endif
} }
int Memory::saveall(void) { int Memory::saveall(void) {
int errors=0; int errors=0;
#ifdef USE_WINFILE #ifdef USE_WINFILE
FILEHANDLE output=GetStdHandle(STD_ERROR_HANDLE); /* So it doesn't point to some one */ FILEHANDLE output=GetStdHandle(STD_ERROR_HANDLE); /* So it doesn't point to some one */
#else #else
FILEHANDLE output=STDERR_FILENO; /* So it doesn't point to someone */ FILEHANDLE output=STDERR_FILENO;
#endif #endif
if(readonly) { if(readonly) {
return -2; return -2;
} }
#ifdef BIOSDISK #ifdef BIOSDISK
if(infodisk) { if(infodisk) {
infodisk=diskreopen(infodisk,O_RDWR); infodisk=diskreopen(infodisk,O_RDWR);
for(Treel *iter=tree.treecontrol->roottree;iter!=tree.NIL;iter=tree.next( iter)) { for(Treel *iter=tree.treecontrol->roottree;iter!=tree.NIL;iter=tree.next( iter)) {
if(savenode(output,iter)<0) { if(savenode(output,iter)<0) {
skipping to change at line 1207 skipping to change at line 1240
databuffree( iter->data.buf); databuffree( iter->data.buf);
} }
tree.empty(); tree.empty();
infodisk=diskreopen(infodisk,O_RDONLY); infodisk=diskreopen(infodisk,O_RDONLY);
return errors; return errors;
} }
else else
#endif #endif
{ {
closefilehandle(filehandle); /*Because file is changed */ closefilehandle(filehandle); /*Because file is changed */
#ifdef USE_WINFILE
if(((output=openreadwrite(filename))==MY_INVALID_HANDLE_VALUE)||((diskfilesize>f if((output=reopen())==MY_INVALID_HANDLE_VALUE) {
ilesize&&((setfilepos(output,filesize)!=filesize)||!SetEndOfFile(filehandle)))&&
(CloseHandle(output),true))) {
#else
if((diskfilesize!=filesize&&(TRUNCATE(filename,filesize)<0))||((output=op
enreadwrite(filename))==MY_INVALID_HANDLE_VALUE)) {
#endif
// readonly=1; // readonly=1;
#ifdef USE_WINFILE #ifdef USE_WINFILE
errors=WINERROR; errors=WINERROR;
Memory::errors=GetLastError(); Memory::errors=GetLastError();
#else #else
if(errno) if(errno)
errors=errno; errors=errno;
else else
errors=-1; errors=-1;
#endif #endif
skipping to change at line 1287 skipping to change at line 1317
errors=-1; errors=-1;
#endif #endif
} }
#ifdef USE_WINFILE #ifdef USE_WINFILE
// STAT(filename,&statdata); // STAT(filename,&statdata);
getfileinfo(&FileInfo); getfileinfo(&FileInfo);
#else #else
FSTAT(filehandle,&statdata); FSTAT(filehandle,&statdata);
#endif #endif
diskfilesize=filesize; useddiskfilesize=diskfilesize=filesize;
return errors; return errors;
} }
} }
int Memory::zerochange(void) { int Memory::zerochange(void) {
if(filesize!=newfilesize) if(filesize!=newfilesize)
return 1; return 1;
char tmpbuf[newfilesize]; char tmpbuf[newfilesize];
getpart(0,newfilesize,tmpbuf); /*Niet verbonden aan file, sector grens ma akt niet uit*/ getpart(0,newfilesize,tmpbuf); /*Niet verbonden aan file, sector grens ma akt niet uit*/
int *ints=(int *) tmpbuf; int *ints=(int *) tmpbuf;
int len=newfilesize*sizeof(char)/sizeof(int); int len=newfilesize*sizeof(char)/sizeof(int);
skipping to change at line 1309 skipping to change at line 1339
if(ints[i]) if(ints[i])
return 1; return 1;
return 0; return 0;
} }
int Memory::changednode(Treel *node) { int Memory::changednode(Treel *node) {
char *tmpbuf=databufalloc(BLOCKSIZE); char *tmpbuf=databufalloc(BLOCKSIZE);
OFFTYPE diff=filesize-((OFFTYPE)node->data.blocknr*BLOCKSIZE); OFFTYPE diff=filesize-((OFFTYPE)node->data.blocknr*BLOCKSIZE);
int ret=0; int ret=0;
if(diff>0) { if(diff>0) {
BEDS_SIZE_T size=(diff<BLOCKSIZE)?diff:BLOCKSIZE; BEDS_SIZE_T size=(diff<BLOCKSIZE)?diff:BLOCKSIZE;
if(node->data.size!=size) if(node->data.size<size) {
fprintf(stderr,"WARNING: changednode/1: not enough in nod fprintf(stderr,"WARNING: changednode/1: not enough in nod
e " BLOCKPRINT" " SIZE_TPRINT "!=" SIZE_TPRINT "\n",node->data.blocknr,size,node e " BLOCKPRINT" " SIZE_TPRINT ">" SIZE_TPRINT "\n",node->data.blocknr,size,node-
->data.size); >data.size);
blockreadat(tmpbuf,node->data.size,node->data.blocknr*BLOCKSIZE); size=node->data.size;
ret= memcmp(tmpbuf, node->data.buf, node->data.size); }
blockreadat(tmpbuf,size,node->data.blocknr*BLOCKSIZE);
ret= memcmp(tmpbuf, node->data.buf, size);
} }
databuffree(tmpbuf); databuffree(tmpbuf);
return ret; return ret;
} }
int Memory::changed(void) { int Memory::changed(void) {
OFFTYPE disksize; OFFTYPE disksize;
if(isnewfile()) if(isnewfile())
disksize=(OFFTYPE)newfilesize; disksize=(OFFTYPE)newfilesize;
else else
skipping to change at line 1370 skipping to change at line 1402
if(ret<BLOCKSIZE) { if(ret<BLOCKSIZE) {
if(ret<0) if(ret<0)
return OFFTYPEINVALID; return OFFTYPEINVALID;
else else
break; break;
} }
} }
return buf-startbuf; return buf-startbuf;
} }
#if defined(USE_WINFILE) ||(defined(HAVE_SENDFILE) && defined(SEEK_DATA))
extern int nonsparsecp(FILEHANDLE inhandle,OFFTYPE instart,OFFTYPE inlen,FILEHAN
DLE uit) ;
//extern int sparsecp(FILEHANDLE inhandle,FILEHANDLE uit);
extern int sparsecp(int inhandle,OFFTYPE instart,OFFTYPE inlen,int uit) ;
int Memory::saveto(FILEHANDLE handle) { int Memory::saveto(FILEHANDLE handle) {
char *buf=databufalloc(BLOCKSIZE); if(useddiskfilesize<filesize) {
BLOCKTYPE nr; mksparse(handle);
BEDS_SIZE_T did, ret=0; if(FTRUNCATEHANDLE(handle,filesize)!=0)
for(nr=0;(did=getblock(nr, buf));nr++) { perror("ftruncate");
ret=writetofile(handle,buf,did); }
if(ret!=did) {
databuffree(buf); if(int res;filehandle!=MY_INVALID_HANDLE_VALUE&&(res=sparsecp(filehandle,
return -1; 0,useddiskfilesize,handle))!=0) {
} if(res!=-1)
}
databuffree(buf);
if((maxnum((OFFTYPE)(nr-1)*BLOCKSIZE,0)+ret)!=filesize)
return -1; return -1;
#ifndef USE_WINFILE
lseek(handle,0, SEEK_SET);
#endif
if(nonsparsecp(filehandle,0,useddiskfilesize,handle)<0) {
/* lseek(handle,0, SEEK_SET);
return nonsparsesaveto(handle);*/
return -2;
}
}
for(Treel *iter=tree.treecontrol->roottree;iter!=tree.NIL;iter=tree.next(
iter)) {
if(savenode(handle,iter)<0) {
return -3;
}
}
return 0;
}
int Memory::nonsparsesaveto(FILEHANDLE handle) {
#else
int Memory::saveto(FILEHANDLE handle) {
#endif
if(useddiskfilesize<filesize) {
mksparse(handle);
if(FTRUNCATEHANDLE(handle,filesize)!=0)
perror("ftruncate");
}
char *buf=databufalloc(BLOCKSIZE);
BLOCKTYPE nr;
BEDS_SIZE_T did, ret=0;
BLOCKTYPE endblock=(useddiskfilesize+BLOCKSIZE-1)/BLOCKSIZE;
for(nr=0;nr<endblock;nr++) {
did=getblock(nr, buf);
ret=writetofile(handle,buf,did);
if(ret!=did) {
databuffree(buf);
return -1;
}
}
databuffree(buf);
if(diskfilesize>=filesize) {
if((maxnum((OFFTYPE)(nr-1)*BLOCKSIZE,0)+ret)!=filesize) return -1
;
return 0; return 0;
} }
for(Treel *iter=tree.treecontrol->roottree;iter!=tree.NIL;iter=tree.next(
iter)) {
BLOCKTYPE bl=iter->data.blocknr;
if(bl>=endblock) {
OFFTYPE offset=bl*BLOCKSIZE;
int len=((offset+BLOCKSIZE)>filesize) ?(filesize-offset):
iter->data.size;
writeat(handle,iter->data.buf,len,offset);
}
}
/*
for(OFFTYPE offset=nr*BLOCKSIZE;offset<filesize;nr++,offset+=BLOCKSIZE) {
Treel *el=tree.search(nr);
if(el!=tree.NIL) {
int len=((offset+BLOCKSIZE)>filesize) ?(filesize-offset):
el->data.size;
writeat(handle,el->data.buf,len,offset);
}
} */
// if((maxnum((OFFTYPE)(nr-1)*BLOCKSIZE,0)+ret)!=filesize) return -1;
return 0;
}
BEDS_SIZE_T Memory::getblockpiece(OFFTYPE beg,BEDS_SIZE_T len,char *get) { BEDS_SIZE_T Memory::getblockpiece(OFFTYPE beg,BEDS_SIZE_T len,char *get) {
BLOCKTYPE onder=beg/BLOCKSIZE; BLOCKTYPE onder=beg/BLOCKSIZE;
BEDS_SIZE_T ret; BEDS_SIZE_T ret;
BEDS_SIZE_T in=beg%BLOCKSIZE; BEDS_SIZE_T in=beg%BLOCKSIZE;
Treel *el=tree.search(onder); Treel *el=tree.search(onder);
if(el!=tree.NIL) { if(el!=tree.NIL) {
ret=minnum(el->data.size,len); ret=minnum(el->data.size,len);
memmove(get,el->data.buf+in,ret); memmove(get,el->data.buf+in,ret);
} }
else { else {
ret=readat(get,len,beg); ret=readat(get,len,beg);
} }
return ret; return ret;
} }
#ifdef _WIN32 #ifdef _WIN32
OFFTYPE Memory::getpartaligned(const OFFTYPE beg,const OFFTYPE len,char *const g egs) { OFFTYPE Memory::getpartaligned(const OFFTYPE beg,const OFFTYPE len,char *const g egs) {
BLOCKTYPE start; BLOCKTYPE start;
BEDS_SIZE_T begover=beg%BLOCKSIZE; BEDS_SIZE_T begover=beg%BLOCKSIZE;
int blks=(len+begover-1)/BLOCKSIZE+1; int blks=(len+begover-1)/BLOCKSIZE+1;
char *tmpbuf= (char *)aligned_alloc(BLOCKSIZE, blks*BLOCKSIZE); char *tmpbuf= (char *)alignedalloc(BLOCKSIZE, blks*BLOCKSIZE);
start=(beg/BLOCKSIZE); start=(beg/BLOCKSIZE);
BLOCKTYPE end=start+blks; BLOCKTYPE end=start+blks;
char *ptr=tmpbuf; char *ptr=tmpbuf;
for(BLOCKTYPE nr=start;nr<end;nr++,ptr+=BLOCKSIZE) for(BLOCKTYPE nr=start;nr<end;nr++,ptr+=BLOCKSIZE)
getblock(nr, ptr); getblock(nr, ptr);
memcpy(gegs,tmpbuf+begover,len); memcpy(gegs,tmpbuf+begover,len);
free(tmpbuf); alignedfree(tmpbuf);
return len; return len;
} }
#endif #endif
OFFTYPE Memory::getpart(OFFTYPE beg,OFFTYPE len,char *gegs) { OFFTYPE Memory::getpart(OFFTYPE beg,OFFTYPE len,char *gegs) {
if(beg>=filesize) { if(beg>=filesize) {
if(beg==filesize&&!len) if(beg==filesize&&!len)
return 0; return 0;
else else
return OFFTYPEINVALID; return OFFTYPEINVALID;
} }
skipping to change at line 1494 skipping to change at line 1585
ptr=gegs+over; ptr=gegs+over;
for(BLOCKTYPE nr=start;nr<bl;nr++,ptr+=BLOCKSIZE) { for(BLOCKTYPE nr=start;nr<bl;nr++,ptr+=BLOCKSIZE) {
if((BLOCKSIZE!=putblock(nr, ptr))) if((BLOCKSIZE!=putblock(nr, ptr)))
return OFFTYPEINVALID; return OFFTYPEINVALID;
} }
if(putblockpiece(end-nog,nog,ptr)!=nog) if(putblockpiece(end-nog,nog,ptr)!=nog)
return OFFTYPEINVALID; return OFFTYPEINVALID;
} }
return len; return len;
} }
#if defined(USE_WINFILE) ||(defined(HAVE_SENDFILE) && defined(SEEK_DATA))
BEDS_SIZE_T Memory::saveto(FILEHANDLE handle,OFFTYPE beg,OFFTYPE len) { BEDS_SIZE_T Memory::saveto(FILEHANDLE handle,OFFTYPE beg,OFFTYPE len) {
mksparse(handle);
if(FTRUNCATEHANDLE(handle,len)!=0) {
perror("ftruncate");
}
if(filehandle!=MY_INVALID_HANDLE_VALUE) {
OFFTYPE left=useddiskfilesize-beg;
OFFTYPE disklen=minnum(left,len);
if(int res=sparsecp(filehandle,beg,disklen,handle);res!=0) {
if(res!=-1)
return -1;
#ifndef USE_WINFILE
lseek(handle,0, SEEK_SET);
#endif
if(nonsparsecp(filehandle,beg,disklen,handle)<0) {
/* lseek(handle,0, SEEK_SET);
return nonsparsesaveto(handle,beg, len) ;
*/
return -2;
}
}
}
OFFTYPE end=beg+len;
OFFTYPE startblock=beg/BLOCKSIZE;
OFFTYPE endblock=(end+BLOCKSIZE-1)/BLOCKSIZE;
for(Treel *node=tree.treecontrol->roottree;node!=tree.NIL;node=tree.next(
node)) {
auto blnr=node->data.blocknr;
if(blnr>=startblock&&blnr<endblock) {
OFFTYPE off=blnr*BLOCKSIZE;
OFFTYPE diff=end-off;
if(diff>0) {
int bufoff=0;
if(off<beg) {
bufoff=beg-off;
off=beg;
}
BEDS_SIZE_T size=(diff<BLOCKSIZE)?diff:BLOCKSIZE;
writeat(handle,node->data.buf+bufoff,size-bufoff,
off-beg);
}
}
}
return 0;
}
BEDS_SIZE_T Memory::nonsparsesaveto(FILEHANDLE handle,OFFTYPE beg,OFFTYPE len) {
#else
BEDS_SIZE_T Memory::saveto(FILEHANDLE handle,OFFTYPE beg,OFFTYPE len) {
#endif
if(beg>=filesize) { if(beg>=filesize) {
if(beg==filesize&&!len) if(beg==filesize&&!len)
return 0; return 0;
else else
return -1; return -1;
} }
OFFTYPE full; OFFTYPE full;
BEDS_SIZE_T over; BEDS_SIZE_T over;
// char buf[BLOCKSIZE]; // char buf[BLOCKSIZE];
sectorbuf buf(BLOCKSIZE, BLOCKSIZE); sectorbuf buf(BLOCKSIZE, BLOCKSIZE);
skipping to change at line 1688 skipping to change at line 1826
STOPUSELSEEK; STOPUSELSEEK;
return -2; return -2;
} }
STOPUSELSEEK; STOPUSELSEEK;
return ret; return ret;
#endif #endif
} }
} }
BEDS_SIZE_T Memory::blockreadat(char *ptr,BEDS_SIZE_T size,OFFTYPE offset) { BEDS_SIZE_T Memory::blockreadat(char *ptr,BEDS_SIZE_T size,OFFTYPE offset) {
if(offset>=useddiskfilesize) {
#ifdef HAVE_BZERO
bzero(ptr,size);
#else
memset(ptr,'\0',size);
#endif
return size;
}
#ifdef NEEDS_BLOCKMODE #ifdef NEEDS_BLOCKMODE
assert(((blockreadonly>1)?(((intptr_t)ptr)%BLOCKSIZE==0):true)); assert(((blockreadonly>1)?(((intptr_t)ptr)%BLOCKSIZE==0):true));
#endif #endif
BEDS_SIZE_T ret; BEDS_SIZE_T ret;
#ifdef BIOSDISK #ifdef BIOSDISK
if(infodisk) { if(infodisk) {
BEDS_SIZE_T count=size/blockreadonly; BEDS_SIZE_T count=size/blockreadonly;
if(count<=0) { if(count<=0) {
fprintf(stderr,"Memory::blockreadat " SIZE_TPRINT " is not a mu ltiple of %d ( disk blocksize)\n",size,blockreadonly); fprintf(stderr,"Memory::blockreadat " SIZE_TPRINT " is not a mu ltiple of %d ( disk blocksize)\n",size,blockreadonly);
return -5; return -5;
skipping to change at line 1765 skipping to change at line 1911
DIRECT: DIRECT:
return blockreadat( ptr,size,offset); return blockreadat( ptr,size,offset);
} }
} }
#else #else
inline BEDS_SIZE_T Memory::readat(char *ptr,BEDS_SIZE_T size,OFFTYPE offset) { inline BEDS_SIZE_T Memory::readat(char *ptr,BEDS_SIZE_T size,OFFTYPE offset) {
return blockreadat( ptr,size,offset); return blockreadat( ptr,size,offset);
} }
#endif #endif
BEDS_SIZE_T Memory::getblock(BLOCKTYPE blocknr,char *buf) { BEDS_SIZE_T Memory::getblock(BLOCKTYPE blocknr,char *buf) {
BEDS_SIZE_T ret;
OFFTYPE offset=(blocknr*BLOCKSIZE); OFFTYPE offset=(blocknr*BLOCKSIZE);
if(offset>=filesize) if(offset>=filesize)
return 0; return 0;
Treel *el=tree.search(blocknr); Treel *el=tree.search(blocknr);
if(el!=tree.NIL) { if(el!=tree.NIL) {
memmove(buf,el->data.buf,el->data.size); memmove(buf,el->data.buf,el->data.size);
ret=el->data.size; return minnum(filesize-offset,el->data.size);
} }
else { else {
int len=minnum(filesize-offset,BLOCKSIZE); int len=minnum(filesize-offset,BLOCKSIZE);
ret=blockreadat(buf,len,offset); return blockreadat(buf,len,offset);
} }
return minnum(filesize-offset,ret);
} }
BEDS_SIZE_T Memory::putblock(BLOCKTYPE blocknr,char *buf) { BEDS_SIZE_T Memory::putblock(BLOCKTYPE blocknr,char *buf) {
OFFTYPE offset=(blocknr*BLOCKSIZE); OFFTYPE offset=(blocknr*BLOCKSIZE);
if(offset>=filesize) if(offset>=filesize)
return 0; return 0;
BEDS_SIZE_T thissize=minnum(filesize-offset,BLOCKSIZE); BEDS_SIZE_T thissize=minnum(filesize-offset,BLOCKSIZE);
Treel *el=gettreel(blocknr); Treel *el=gettreel(blocknr);
memmove(el->data.buf,buf,thissize); memmove(el->data.buf,buf,thissize);
el->data.size=thissize; el->data.size=thissize;
skipping to change at line 1812 skipping to change at line 1956
OFFTYPE oldsize=filesize; OFFTYPE oldsize=filesize;
BLOCKTYPE under=oldsize/BLOCKSIZE; BLOCKTYPE under=oldsize/BLOCKSIZE;
Treel *el=tree.search(under); Treel *el=tree.search(under);
if(el==tree.NIL) { if(el==tree.NIL) {
char buf[BLOCKSIZE]; /*Alignment doesn't matter, you can't extend \\.\PhysicalDriveX */ char buf[BLOCKSIZE]; /*Alignment doesn't matter, you can't extend \\.\PhysicalDriveX */
OFFTYPE begin=under*BLOCKSIZE,sizebuf=filesize-begin; OFFTYPE begin=under*BLOCKSIZE,sizebuf=filesize-begin;
blockreadat(buf,sizebuf,begin); blockreadat(buf,sizebuf,begin);
putpart(begin,sizebuf,buf) ; putpart(begin,sizebuf,buf) ;
el=tree.search(under); el=tree.search(under);
} }
/* else {
long begin=(oldsize%BLOCKSIZE);
memset(el->data.buf+begin,'\0',BLOCKSIZE-begin);
} */
filesize=newsize; filesize=newsize;
OFFTYPE offset=under*BLOCKSIZE; OFFTYPE offset=under*BLOCKSIZE;
el->data.size=minnum(filesize-offset,BLOCKSIZE); el->data.size=minnum(filesize-offset,BLOCKSIZE);
return; return;
} }
void Memory::undotruncate(OFFTYPE newsize,OFFTYPE useddisk) {
//void Memory::undotruncate(OFFTYPE newsize) {
/* OFFTYPE wassize=filesize;
BLOCKTYPE bl=filesize/BLOCKSIZE;
char buf[BLOCKSIZE];
getblock(bl,buf); */
extend(newsize) ;
/*
if(newsize<=diskfilesize) {
useddiskfilesize=newsize;
}
else {
fprintf(stderr,"Undo truncate to larger file " OFFPRINT " > " OFF
PRINT "\n",newsize,diskfilesize);
}
*/
}
void Memory::truncatefile(OFFTYPE pos) { /* v2 */ void Memory::truncatefile(OFFTYPE pos) { /* v2 */
Treel *el=tree.search(filesize); Treel *el=tree.search(filesize);
if(el!=tree.NIL) { /* CAUTION old data is not removed. No pr oblem: extending goes always with putpart? (extend, undo, saveall?) */ if(el!=tree.NIL) { /* CAUTION old data is not removed. No pr oblem: extending goes always with putpart? (extend, undo, saveall?) */
el->data.size=BLOCKSIZE; el->data.size=BLOCKSIZE;
} }
filesize=pos; filesize=pos;
useddiskfilesize=minnum(useddiskfilesize,filesize);
setborder(pos); setborder(pos);
} }
BEDS_SIZE_T Memory::putblockpiece(OFFTYPE beg,BEDS_SIZE_T len,char *get) { BEDS_SIZE_T Memory::putblockpiece(OFFTYPE beg,BEDS_SIZE_T len,char *get) {
BLOCKTYPE onder=beg/BLOCKSIZE; BLOCKTYPE onder=beg/BLOCKSIZE;
BEDS_SIZE_T ret; BEDS_SIZE_T ret;
OFFTYPE bstart=onder*BLOCKSIZE; OFFTYPE bstart=onder*BLOCKSIZE;
BEDS_SIZE_T in=beg%BLOCKSIZE; BEDS_SIZE_T in=beg%BLOCKSIZE;
Treel *el=tree.search(onder); Treel *el=tree.search(onder);
BEDS_SIZE_T thissize=minnum(filesize-bstart,BLOCKSIZE); BEDS_SIZE_T thissize=minnum(filesize-bstart,BLOCKSIZE);
if(el!=tree.NIL) { if(el!=tree.NIL) {
 End of changes. 27 change blocks. 
52 lines changed or deleted 226 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)