/* -*- Mode: C++; tab-width: 8; c-basic-offset: 8 -*-
 *
 */

#ifndef __LFSBlock_h__
#define __LFSBlock_h__

#include <linux/fs.h>
#include <linux/lfs_fs.h>
#include "LFSFileSystem.h"

class CLFSFileSystem;

class CLFSBlock {
public:
        CLFSBlock(CLFSFileSystem& fs, unsigned long addr);
	CLFSBlock(CLFSBlock& block);

	CLFSFileSystem& GetFS() {
		return m_fs;
	};

        void Read();

	char* const GetData();

	unsigned long GetAddr() {
		return m_addr;
	};

protected:
	void CheckValid();

        CLFSFileSystem& m_fs;
        unsigned long m_addr;
        char m_data[BLOCK_SIZE];
        bool m_valid;
};


class CLFSSuperBlock : public CLFSBlock {
public:
	CLFSSuperBlock(CLFSFileSystem& fs);

	unsigned short GetMagic();
	unsigned short GetSegments();
	unsigned short GetFreeSegments();
	unsigned short GetNextFreeSegment();
	unsigned long GetSegmentSize();
	unsigned long GetSegmentMap();
	unsigned long GetInodeMap();
	unsigned long GetInodes();
	unsigned long GetSegmentOne();
};


class CLFSInodeBlock : public CLFSBlock {
public:
	CLFSInodeBlock(CLFSFileSystem& fs, unsigned long addr);

	ino_t GetIno();
	unsigned short GetMode();
	unsigned short GetUID();
	unsigned short GetGID();
	unsigned short GetNLink();
	unsigned long GetSize();
	unsigned long GetBlocks();
	unsigned long GetCTime();
	unsigned long GetMTime();
	unsigned long GetZone(int zone);
};

class CLFSIBlock : public CLFSBlock {
public:
	CLFSIBlock(CLFSFileSystem& fs, unsigned long addr);

	unsigned long GetEntryAddr(unsigned int entry);
};


#endif __LFSBlock_h__

