#ifndef UBIXFS_H
#define UBIXFS_H
#include <sys/types.h>
#include <unistd.h>
#include "fsAbstract.h"
#include "types.h"
#define INODE_IN_USE 0x00000001
#define ATTR_INODE 0x00000004
#define INODE_LOGGED 0x00000008
#define INODE_DELETED 0x00000010
#define PERMANENT_FLAGS 0x0000ffff
#define INODE_NO_CACHE 0x00010000
#define INODE_WAS_WRITTEN 0x00020000
#define NO_TRANSACTION 0x00040000
#define NUM_DIRECT_BLOCKS 64
#define MAX_FILENAME_LENGTH 256
#define UBIXFS_MAGIC1 0x0A0A0A0A
#define UBIXFS_MAGIC2 0x0B0B0B0B
#define UBIXFS_MAGIC3 0x0C0C0C0C
#define UBIXFS_CLEAN 0x434C454E // CLEN
#define UBIXFS_DIRTY 0x44495254 // DIRT
struct bNode;
struct ubixfsInode;
typedef struct blockRun {
int allocationGroup __attribute__ ((packed));
unsigned short start __attribute__ ((packed));
unsigned short len __attribute__ ((packed));
} inodeAddr;
typedef union uPtr {
inodeAddr iAddr;
bNode * bPtr;
ubixfsInode * iPtr;
off_t offset;
};
typedef struct diskSuperBlock {
char name[32] __attribute__ ((packed));
int32 magic1 __attribute__ ((packed));
int32 fsByteOrder __attribute__ ((packed));
// blockSize on disk (4096 for UbixFS v2)
int32 blockSize __attribute__ ((packed));
// number of bits needed to shift a block number to get a byte address
int32 blockShift __attribute__ ((packed));
off_t numBlocks __attribute__ ((packed));
off_t usedBlocks __attribute__ ((packed));
// BlockAllocationTable
blockRun BAT __attribute__ ((packed));
uInt32 inodeCount __attribute__ ((packed));
int32 inodeSize __attribute__ ((packed));
int32 magic2 __attribute__ ((packed));
int32 blocksPerAG __attribute__ ((packed));
int32 AGShift __attribute__ ((packed));
int32 numAGs __attribute__ ((packed));
int32 lastUsedAG __attribute__ ((packed));
// flags tells whether the FS is clean (0x434C454E) or dirty (0x44495954)
int32 flags __attribute__ ((packed));
// journal information
blockRun logBlocks __attribute__ ((packed));
off_t logStart __attribute__ ((packed));
off_t logEnd __attribute__ ((packed));
int32 magic3 __attribute__ ((packed));
// root dir of the SYS container
inodeAddr rootDir __attribute__ ((packed));
// indicies
inodeAddr indicies __attribute__ ((packed));
char pad[364] __attribute__ ((packed));
} diskSuperBlock;
typedef struct dataStream {
struct blockRun direct[NUM_DIRECT_BLOCKS];
off_t maxDirectRange;
struct blockRun indirect;
off_t maxIndirectRange;
struct blockRun double_indirect;
off_t maxDoubleIndirectRange;
off_t size;
} dataStream;
typedef struct ubixfsInode {
int32 magic1 __attribute__ ((packed));
inodeAddr inodeNum __attribute__ ((packed));
char name[MAX_FILENAME_LENGTH] __attribute__ ((packed));
uid_t uid __attribute__ ((packed));
gid_t gid __attribute__ ((packed));
int32 mode __attribute__ ((packed));
int32 flags __attribute__ ((packed));
// uInt64 createTime __attribute_ ((packed));
// uInt64 lastModifiedTime __attribute__ (packed));
// inodeAddr attributes __attribute__ ((packed));
uInt32 type __attribute__ ((packed));
int32 inodeSize __attribute__ ((packed));
uPtr parent __attribute__ ((packed));
uPtr next __attribute__ ((packed));
uPtr prev __attribute__ ((packed));
// binodeEtc *etc ??
dataStream data __attribute__ ((packed));
char smallData[3220] __attribute__ ((packed));
} ubixfsInode;
class UbixFS : public vfs_abstract {
protected:
signed char * freeBlockList;
diskSuperBlock * superBlock;
blockRun getFreeBlock(uInt32);
blockRun getFreeBlock(void);
blockRun get8FreeBlocks(uInt32);
void * mknod(const char *, ubixfsInode *);
uInt32 getNextAG(void);
public:
UbixFS(device_t *);
virtual int vfs_init(void);
virtual int vfs_format(device_t *);
virtual void * vfs_mknod(const char *, mode_t);
virtual ~UbixFS(void);
}; // UbixFS
#endif // !UBIXFS_H