root / Whitix / branches / hybrid / include / fs / vfs.h

Revision 527, 8.1 kB (checked in by mwhitworth, 6 months ago)

Reorganise file.

Line 
1/*  This file is part of Whitix.
2 *
3 *  Whitix is free software; you can redistribute it and/or modify
4 *  it under the terms of the GNU General Public License as published by
5 *  the Free Software Foundation; either version 2 of the License, or
6 *  (at your option) any later version.
7 *
8 *  Whitix is distributed in the hope that it will be useful,
9 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *  GNU General Public License for more details.
12 *
13 *  You should have received a copy of the GNU General Public License
14 *  along with Whitix; if not, write to the Free Software
15 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16 *
17 */
18
19/* FIXME: Split file into separate headers. */
20
21#ifndef VFS_H
22#define VFS_H
23
24/* VFS includes. */
25#include <fs/exports.h>
26
27#include <llist.h>
28#include <sdevice.h>
29#include <typedefs.h>
30#include <types.h>
31#include <time.h>
32#include <wait.h>
33
34/* vNode flags */
35
36#define VFS_ATTR_FILE           1
37#define VFS_ATTR_DIR            2
38#define VFS_ATTR_READ           4
39#define VFS_ATTR_WRITE          8
40#define VFS_ATTR_BLOCK          16
41#define VFS_ATTR_CHAR           32
42#define VFS_ATTR_SOCKET         64
43
44/* Flags for SysOpen and NameToVNode */
45
46#define FILE_READ                       1
47#define FILE_WRITE                      2
48#define FILE_CREATE_OPEN        4
49#define FILE_FORCE_OPEN         8
50#define FILE_FORCE_CREATE       16
51#define FILE_DIRECTORY          32 /* Only open the file if it is a directory */
52
53/* General defines */
54#define MAX_FILES 10 /* Max files per task */
55#define PATH_MAX 2048
56
57struct VNode;
58struct File;
59struct FileSystem;
60struct VfsSuperBlock;
61struct PollItem;
62struct PollQueue;
63
64int VfsInit();
65int VfsMountRoot(struct StorageDevice* storageDev);
66int VNodeInitCache();
67
68/* Mount functions (super.c) */
69int VfsMount(char* mountPoint,char* deviceName,char* fsName,void* mData);
70struct VfsSuperBlock* VfsAllocSuper(struct StorageDevice* sDev,int flags);
71void VfsFreeSuper(struct VfsSuperBlock* superBlock);
72
73/* VNode functions (vnode.c) */
74int NameToVNode(struct VNode** retVal,char* path,int flags);
75struct VNode* DirNameVNode(char* path,char** retPath,int* retLen);
76
77/* VNode cache functions (vcache.c) */
78struct VNode* VNodeGet(struct VfsSuperBlock* superBlock,vid_t id);
79struct VNode* VNodeGetEmpty();
80void VNodeRelease(struct VNode* vNode);
81void VNodeLock(struct VNode* vNode);
82void VNodeUnlock(struct VNode* vNode);
83void VNodeWrite(struct VNode* vNode);
84int VNodeRead(struct VNode* vNode);
85void VNodeWaitOn(struct VNode* vNode);
86
87int VfsChangeDir(struct Process* process,char* dirName);
88
89/* vNode time functions */
90void VfsFileAccessed(struct VNode* vNode);
91void VfsFileModified(struct VNode* vNode,int create);
92
93/* File functions (file.cpp) */
94int FileGenericRead(struct File* file,BYTE* buffer,size_t size);
95int VfsGetFreeFd(struct Process* process);
96struct File* FileGet(int fd);
97int DoOpenFile(struct File* file,char* path,int flags,int perms);
98int DoReadFile(struct File* file,BYTE* buffer,size_t size);
99int DoWriteFile(struct File* file,BYTE* buffer,size_t size);
100int DoCloseFile(struct File* file);
101int DoSeekFile(struct File* file,int distance,int whence);
102
103/* For demand loading */
104int FileGenericReadPage(addr_t pageAddr,struct VNode* vNode,int offset);
105
106char* GetName(char* path);
107
108/* Move? */
109
110typedef struct
111{
112        WORD major;
113        WORD minor;
114} DevId;
115
116/* Used for the SysGetDirEntries system call */
117
118struct DirEntry
119{
120        DWORD vNodeNum; /* Need this? */
121        DWORD offset;
122        WORD length;
123        char name[1];
124};
125
126/* VNODE
127
128Represents an on-disk directory entry in memory
129
130*/
131
132#define VNODE_DIRTY 1
133
134struct VNode
135{
136        struct VNode* mountNode;
137        DWORD flags,refs,size,mode;
138        vid_t id;
139        struct VfsSuperBlock* superBlock;
140        struct VNodeOps* vNodeOps;
141        struct FileOps* fileOps;
142        struct ListHead next;
143        DevId devId;
144        WaitQueue waitQueue;
145        int lock;
146        void* extraInfo;
147        struct Time aTime,cTime,mTime;
148
149        /* Virtual memory */
150        struct ListHead sharedList;
151};
152
153#define SetVNodeDirty(vNode) (((vNode)->flags) |= VNODE_DIRTY)
154
155/* FILE
156
157File object. Used when reading/writing to a file (VNode doesn't need those
158things really)
159
160*/
161
162#define FILE_NONBLOCK   0x1
163
164struct File
165{
166        struct VNode* vNode;
167        int position; /* FIXME: Add position type soon. */
168        int flags;
169        struct FileOps* fileOps;
170};
171
172struct FileOps
173{
174        int (*open)(struct File* file);
175        int (*close)(struct File* file);
176        int (*read)(struct File* file,BYTE* buffer,DWORD size);
177        int (*write)(struct File* file,BYTE* buffer,DWORD size);
178        int (*seek)(struct File* file,int pos,int whence);
179        int (*readDir)(struct File* file,void* dirEntries);
180        int (*ioctl)(struct File* file,unsigned long code,char* data);
181        int (*poll)(struct File* file, struct PollItem* item, struct PollQueue* pollQueue);
182        int (*mMap)(struct VNode* vNode, DWORD address, DWORD offset);
183};
184
185int FillDir(void* dirEntry,char* name,int nameLen,DWORD vNodeNum);
186
187struct VNodeOps
188{
189        int (*create)(struct VNode** retVal,struct VNode* dir,char* name,int nameLength);
190        int (*remove)(struct VNode* dir,char* name,int nameLen);
191        int (*lookup)(struct VNode** retVal,struct VNode* dir,char* name,int nameLength);
192        int (*mkDir)(struct VNode** retVal,struct VNode* dir,char* name,int nameLength);
193        int (*rmDir)(struct VNode* dir,char* name,int nameLength);
194        int (*permission)(struct VNode* vNode,int access);
195        int (*blockMap)(struct VNode* vNode,int offset);
196        int (*truncate)(struct VNode* vNode,int size);
197};
198
199struct SuperBlockOps
200{
201        /* General vNode functions */
202        int (*allocVNode)(struct VNode* vNode);
203        int (*freeVNode)(struct VNode* vNode);
204        int (*readVNode)(struct VNode* vNode);
205        int (*writeVNode)(struct VNode* vNode);
206
207        /* General superblock functions */
208        int (*writeSuper)(struct VfsSuperBlock* superBlock);
209};
210
211#define SB_DIRTY        0x1
212#define SB_RDONLY       0x2
213
214struct VfsSuperBlock
215{
216        struct SuperBlockOps* sbOps; /* A field so it is easier to set up a VfsSuperBlock */
217        void* privData;
218        DWORD coveredId; /* VNode id of the covered vnode by the mount */
219        struct VfsSuperBlock* parent;
220        struct StorageDevice* sDevice; /* Can be null */
221        struct VNode* mount;
222        int flags;
223        struct ListHead vNodeList, sbList;
224};
225
226/* General defines for a superblock */
227
228#define BYTES_PER_SECTOR(s)             ((s)->sDevice->softBlockSize)
229
230struct Stat
231{
232        DWORD size,vNum,mode;
233        unsigned long aTime,cTime,mTime;
234}PACKED;
235
236/* The StorageDevice parameter can be ignored if, for example, the filesystem is a network one */
237typedef struct VfsSuperBlock* (*VfsReadSuperFunc)(struct StorageDevice* dev,int flags,char* data);
238
239struct FileSystem
240{
241        char* name;
242        VfsReadSuperFunc readSuper;
243        struct ListHead list;
244};
245
246/* For filesystem drivers */
247int VfsRegisterFileSystem(struct FileSystem* fs);
248int VfsDeregisterFileSystem(struct FileSystem* fs);
249
250/* Block cache functions and structures */
251
252/* Buffer flags */
253
254#define BUFFER_DIRTY    0x1
255#define BUFFER_LOCKED   0x2
256
257struct Buffer
258{
259        struct StorageDevice* device;
260        struct ListHead list;
261        DWORD blockNum;
262        int flags,refs;
263        BYTE* data;
264        WaitQueue waitQueue;
265};
266
267/* buffer.c */
268
269int BlockInit();
270struct Buffer* BlockRead(struct StorageDevice* device,DWORD blockNum);
271int BlockWrite(struct StorageDevice* device,struct Buffer* buffer);
272int BlockSyncAll();
273int BlockSyncDevice(struct StorageDevice* device);
274int BlockFree(struct Buffer* buffer);
275int BlockSetSize(struct StorageDevice* device,int blockSize);
276void WaitForBuffer(struct Buffer* buffer);
277void BufferUnlock(struct Buffer* buffer);
278void BufferLock(struct Buffer* buffer);
279struct Buffer* BlockBufferAlloc(struct StorageDevice* device,DWORD blockNum);
280int BlockSendRequest(struct StorageDevice* device,struct Buffer* buff,int type);
281int BlockSendRequestRaw(struct StorageDevice* device,struct Request* request);
282struct Buffer* BlockFindBuffer(struct StorageDevice* sDevice,DWORD blockNum);
283
284/* poll.c */
285#define POLL_IN         1
286#define POLL_OUT        2
287
288struct PollQueue
289{
290        int i;
291        int numFds;
292        WaitQueue** waitQueues;
293        struct WaitQueueEntry* waitEntries;
294};
295
296struct PollItem
297{
298        int fd;
299        short events;
300        short revents;
301};
302
303int PollAddWait(struct PollQueue* pollQueue, WaitQueue* waitQueue);
304
305#endif
Note: See TracBrowser for help on using the browser.