UbixOS  2.0
ubixfs.h
Go to the documentation of this file.
1 /*#ifndef UBIXFS_H
2 #define UBIXFS_H
3 
4 #include <sys/types.h>
5 #include <unistd.h>
6 #include "fsAbstract.h"
7 #include "types.h"
8 #include "file.h"
9 
10 #define INODE_IN_USE 0x00000001
11 #define INODE_DIRECTORY 0x00000002
12 #define ATTR_INODE 0x00000004
13 #define INODE_LOGGED 0x00000008
14 #define INODE_DELETED 0x00000010
15 #define PERMANENT_FLAGS 0x0000ffff
16 #define INODE_NO_CACHE 0x00010000
17 #define INODE_WAS_WRITTEN 0x00020000
18 #define NO_TRANSACTION 0x00040000
19 
20 #define NUM_DIRECT_BLOCKS 64
21 #define MAX_FILENAME_LENGTH 256
22 
23 #define UBIXFS_MAGIC1 0xA0A0A0A
24 #define UBIXFS_MAGIC2 0xB0B0B0B
25 #define UBIXFS_MAGIC3 0xC0C0C0C
26 #define UBIXFS_INODE_MAGIC 0x3bbe0ad9
27 
28 *//* befs magic numbers
29 #define SUPER_BLOCK_MAGIC1 0x42465331 // BFS1
30 #define SUPER_BLOCK_MAGIC2 0xdd121031
31 #define SUPER_BLOCK_MAGIC3 0x15b6830e
32  *//*
33 #define UBIXFS_CLEAN 0x434C454E // CLEN
34 #define UBIXFS_DIRTY 0x44495254 // DIRT
35 
36 
37 typedef struct blockRun {
38  int AG __attribute__ ((packed));
39  unsigned short start __attribute__ ((packed));
40  unsigned short len __attribute__ ((packed));
41 } inodeAddr;
42 
43 struct bNode;
44 struct ubixfsInode;
45 class bTree;
46 
47 typedef union uPtr {
48  inodeAddr iAddr;
49  bNode * bPtr;
50  bTree * btPtr;
51  ubixfsInode * iPtr;
52  void * vPtr;
53  off_t offset;
54 };
55 
56 typedef struct diskSuperBlock {
57  char name[32] __attribute__ ((packed));
58  int32 magic1 __attribute__ ((packed));
59  int32 fsByteOrder __attribute__ ((packed));
60 
61 // blockSize on disk (4096 for UbixFS v2)
62  int32 blockSize __attribute__ ((packed));
63 
64 // number of bits needed to shift a block number to get a byte address
65  uInt32 blockShift __attribute__ ((packed));
66 
67  off_t numBlocks __attribute__ ((packed));
68  off_t usedBlocks __attribute__ ((packed));
69 
70 // BlockAllocationTable
71  uInt32 batSectors __attribute__ ((packed));
72 
73  uInt32 inodeCount __attribute__ ((packed));
74  uInt32 inodeSize __attribute__ ((packed));
75  uInt32 magic2 __attribute__ ((packed));
76  uInt32 blocksPerAG __attribute__ ((packed));
77  uInt32 AGShift __attribute__ ((packed));
78  uInt32 numAGs __attribute__ ((packed));
79  uInt32 lastUsedAG __attribute__ ((packed));
80 // flags tells whether the FS is clean (0x434C454E) or dirty (0x44495954)
81  int32 flags __attribute__ ((packed));
82 
83 // journal information
84  blockRun logBlocks __attribute__ ((packed));
85  off_t logStart __attribute__ ((packed));
86  off_t logEnd __attribute__ ((packed));
87 
88  int32 magic3 __attribute__ ((packed));
89 
90 // root dir of the SYS container
91  inodeAddr rootDir __attribute__ ((packed));
92 
93 // indicies
94  inodeAddr indicies __attribute__ ((packed));
95 
96  char pad[368] __attribute__ ((packed));
97 
98 } diskSuperBlock;
99 
100 typedef struct dataStream {
101  struct blockRun direct[NUM_DIRECT_BLOCKS] __attribute__ ((packed));
102  off_t maxDirectRange __attribute__ ((packed));
103  struct blockRun indirect __attribute__ ((packed));
104  off_t maxIndirectRange __attribute__ ((packed));
105  struct blockRun double_indirect __attribute__ ((packed));
106  off_t maxDoubleIndirectRange __attribute__ ((packed));
107  off_t size __attribute__ ((packed));
108 } dataStream;
109 
110 typedef struct ubixfsInode {
111  int32 magic1 __attribute__ ((packed));
112  inodeAddr inodeNum __attribute__ ((packed));
113  char name[MAX_FILENAME_LENGTH] __attribute__ ((packed));
114  uid_t uid __attribute__ ((packed));
115  gid_t gid __attribute__ ((packed));
116  int32 mode __attribute__ ((packed));
117  int32 flags __attribute__ ((packed));
118  // uInt64 createTime __attribute__ ((packed));
119  // uInt64 lastModifiedTime __attribute__ (packed));
120  inodeAddr attributes __attribute__ ((packed));
121  uInt32 type __attribute__ ((packed));
122  uInt32 inodeSize __attribute__ ((packed));
123  uPtr parent __attribute__ ((packed));
124  uPtr next __attribute__ ((packed));
125  uPtr prev __attribute__ ((packed));
126  uPtr data __attribute__ ((packed));
127  dataStream blocks __attribute__ ((packed));
128  uInt32 refCount __attribute__ ((packed));
129  char smallData[3200] __attribute__ ((packed));
130 } ubixfsInode;
131 
132 class UbixFS : public vfs_abstract {
133  protected:
134  signed char * freeBlockList;
135  diskSuperBlock * superBlock;
136  fileDescriptor * root;
137 
138  blockRun getFreeBlock(blockRun);
139  blockRun getFreeBlock(uInt32);
140  blockRun getFreeBlock(void);
141  blockRun get8FreeBlocks(uInt32);
142  uInt32 getNextAG(void);
143  void * mknod(const char *, ubixfsInode *, mode_t);
144  void printSuperBlock(void);
145  void printFreeBlockList(uInt32);
146  void setFreeBlock(blockRun);
147  public:
148  UbixFS(void);
149  UbixFS(device_t *);
150  virtual int vfs_init(void);
151  virtual int vfs_format(device_t *);
152  virtual void * vfs_mknod(const char *, mode_t);
153  virtual int vfs_mkdir(const char *, mode_t);
154  virtual int vfs_open(const char *, fileDescriptor *, int, ...);
155  virtual size_t vfs_read(fileDescriptor *, void *, off_t, size_t);
156  virtual size_t vfs_write(fileDescriptor *, void *, off_t, size_t);
157  virtual int vfs_sync(void);
158  virtual int vfs_stop(void);
159  virtual ~UbixFS(void);
160  friend class bTree;
161 }; // UbixFS
162 
163 #endif // !UBIXFS_H
164 */