/*
mia oyra ton deleted block
einai oyra kai oxi stoiba epeidh me thn oyra gemizo na prota poy eleyhterothikan etsi to arxeio
einai fragmented pros to telos (ayto tah boithoyse se periptosh poy prostethei 
algorithmos gia defragmentation)
otan sbhnetai ena to bazoyme ekei, otan theloyme neo pairnoyme apo ekei
otan kleinei to arxeio xanetai

*/

class fobjectexcept : public except
{
public:
	fobjectexcept(const char *szdesc=0):except("Base file manager exception",szdesc){};
	~fobjectexcept(){};
};


class fileobject : public filewrapper
{
	queue<long>	_available;	

protected:

public:

	fileobject();
	virtual ~fileobject();

	virtual void	open(const char *);
	long			newblock();
	void			readblock(void *,long);
	void			writeblock(void *,long);
	void			delblock(long);
};

fileobject::fileobject()
{

}

fileobject::~fileobject()
{
}

void fileobject::open(const char *szname)
{
	_available.clear();

	filewrapper::open(szname);
}

long fileobject::newblock()
{
	if ( !_available.empty() ) 
		return _available.pop();

	char dump[BLOCKSIZE];
	memset(dump,0,BLOCKSIZE);
	

	long newpos = size();

	append(dump,BLOCKSIZE);
		
	return newpos;
}

void fileobject::readblock(void *pdata,long filepos)
{
	read(pdata,filepos,BLOCKSIZE);
}

void fileobject::writeblock(void *pdata,long filepos)
{
	write(pdata,filepos,BLOCKSIZE);
}

void fileobject::delblock(long pos)
{
	_available.append(pos);
}
