]> wirehaze git hosting - BOS.git/blob - kernel/vfs/vfs.asm

wirehaze git hosting

Completed FAT12 structures, added some for VFS.
[BOS.git] / kernel / vfs / vfs.asm
1 ;----------------------------------------------------------;
2 ; BOS kernel Christoffer Bubach, 2012-2015. ;
3 ;----------------------------------------------------------;
4 ; ;
5 ; VFS handling all devices and filesystems. ;
6 ; ;
7 ;----------------------------------------------------------;
8
9
10 ; file handles need to be dword, where the high
11 ; word contains drive number, and the low word
12 ; is the drive/FS specific handle. limits FS to
13 ; a max of 65535 opened files. should be alright. ;)
14
15
16 ;---------------------------------------------;
17 ; VFS main structure ;
18 ;---------------------------------------------;
19 struc VFS
20 {
21 .number: times 255 db 0 ; 00=FD, 0x10=HD, 0x60=CD, 0x80=VD, 90=RD, B0=ND
22 .storage:
23 times 255 * sizeof.VFS_storage db 0 ; storage driver structure
24 .filesystem:
25 times 255 * sizeof.VFS_filesystem db 0 ; filesystem driver structure
26 .mounted db 0 ; 1/0 switch if mounted
27 .current_path: times 255 db 0 ; drive opened path (increase max path size?)
28 }
29
30 virtual at 0 ; could use "at esi" instead
31 VFS VFS
32 sizeof.VFS = $-$$
33 end virtual
34
35 ;---------------------------------------------;
36 ; VFS storage driver structure ;
37 ;---------------------------------------------;
38 struc VFS_storage
39 {
40 .data_pointer dd 0 ; internal driver data
41 .init dd 0 ; pointer to init
42 .deinit dd 0 ; remove driver
43 .read dd 0 ; read device
44 .write dd 0 ; write device
45 .ioctl dd 0 ; handle device specific extras
46 }
47
48 virtual at 0
49 VFS_storage VFS_storage
50 sizeof.VFS_storage = $-$$
51 end virtual
52
53 ;---------------------------------------------;
54 ; VFS filesystem structure ;
55 ;---------------------------------------------;
56 struc VFS_filesystem
57 {
58 .data_pointer dd 0 ; internal driver data
59 .init dd 0 ; pointer to init
60 .deinit dd 0 ; remove driver
61 .format dd 0 ; format drive
62 .mount dd 0 ; mount drive
63 .unmount dd 0 ; unmount drive
64 .find dd 0 ; find file
65 .findnext dd 0 ; get next match
66 .open dd 0 ; open file, get handle
67 .read dd 0 ; read file from handle
68 .write dd 0 ; write file from handle
69 .seek dd 0 ; seek from handle
70 .remove dd 0 ; remove file/dir
71 .create dd 0 ; create file/dir
72 .ioctl dd 0 ; extra calls if exists
73 }
74
75 virtual at 0
76 VFS_filesystem VFS_filesystem
77 sizeof.VFS_filesystem = $-$$
78 end virtual
79
80 ;---------------------------------------------;
81 ; VFS structure pointer ;
82 ;---------------------------------------------;
83 VFS_structure dd 0
84
85
86 ;--------------------------------------------------------------;
87 ; init_vfs - detect connected drives ;
88 ;--------------------------------------------------------------;
89 ; ;
90 ; out: cf = set if failed ;
91 ; ;
92 ;--------------------------------------------------------------;
93 init_vfs:
94 push eax
95 push ebx
96
97 mov ebx, sizeof.VFS ; allocate structure size
98 call allocate_mem
99 cmp eax, 0
100 jne .ok
101 stc ; if error, set carry
102 mov ebx, 0
103
104 .ok:
105 mov dword [VFS_structure], ebx
106
107 pop ebx
108 pop eax
109 ret
110
111 ;--------------------------------------------------------------;
112 ; add_media - add media driver ;
113 ;--------------------------------------------------------------;
114 ; ;
115 ; in: reg = pointer to VFS drive info ;
116 ; ;
117 ; out: reg = pointer to struct(s) if FAT12 found ;
118 ; ;
119 ;--------------------------------------------------------------;
120 add_media:
121 push eax
122 ;...
123 pop eax
124 ret
125
126 ;--------------------------------------------------------------;
127 ; add_fs - add filesystem driver ;
128 ;--------------------------------------------------------------;
129 ; ;
130 ; in: reg = pointer to VFS drive info ;
131 ; ;
132 ; out: reg = pointer to struct(s) if FAT12 found ;
133 ; ;
134 ;--------------------------------------------------------------;
135 add_fs:
136 push eax
137 ;...
138 pop eax
139 ret