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

wirehaze git hosting

More VFS/FAT12 structure work
[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 ;---------------------------------------------;
11 ; VFS main structure ;
12 ;---------------------------------------------;
13 struc VFS
14 {
15 .number: times 255 db 0 ; 00=FD, 0x10=HD, 0x60=CD, 0x80=VD, 90=RD, B0=ND
16 .storage:
17 times 255 * sizeof.VFS_storage db 0 ; storage driver structure
18 .filesystem:
19 times 255 * sizeof.VFS_filesystem db 0 ; filesystem driver structure
20 .mounted db 0 ; 1/0 switch if mounted
21 .current_path: times 255 db 0 ; drive opened path (increase max path size?)
22 }
23
24 virtual at 0 ; could use "at esi" instead
25 VFS VFS
26 sizeof.VFS = $-$$
27 end virtual
28
29 ;---------------------------------------------;
30 ; VFS storage driver structure ;
31 ;---------------------------------------------;
32 struc VFS_storage
33 {
34 .data_pointer dd 0 ; internal driver data
35 .init dd 0 ; pointer to init
36 .deinit dd 0 ; remove driver
37 .read dd 0 ; read device
38 .write dd 0 ; write device
39 .ioctl dd 0 ; handle device specific extras
40 }
41
42 virtual at 0
43 VFS_storage VFS_storage
44 sizeof.VFS_storage = $-$$
45 end virtual
46
47 ;---------------------------------------------;
48 ; VFS filesystem structure ;
49 ;---------------------------------------------;
50 struc VFS_filesystem
51 {
52 .data_pointer dd 0 ; internal driver data
53 .FSname db 0,0,0,0,0 ; 5 char filesystem name
54 .init dd 0 ; pointer to init
55 .deinit dd 0 ; remove driver
56 .format dd 0 ; format drive
57 .mount dd 0 ; mount drive
58 .unmount dd 0 ; unmount drive
59 .find dd 0 ; find file
60 .findnext dd 0 ; get next match
61 .open dd 0 ; open file, get handle
62 .close dd 0 ; close file from handle
63 .attrib dd 0 ; get/set attrib. and time
64 .read dd 0 ; read file from handle
65 .write dd 0 ; write file from handle
66 .seek dd 0 ; seek from handle
67 .rename dd 0 ; rename file
68 .remove dd 0 ; remove file/dir
69 .create dd 0 ; create file/dir
70 .ioctl dd 0 ; extra calls if exists
71 }
72
73 virtual at 0
74 VFS_filesystem VFS_filesystem
75 sizeof.VFS_filesystem = $-$$
76 end virtual
77
78 ;---------------------------------------------;
79 ; VFS structure pointer ;
80 ;---------------------------------------------;
81 VFS_structure dd 0
82
83
84 ;--------------------------------------------------------------;
85 ; init_vfs - detect connected drives ;
86 ;--------------------------------------------------------------;
87 ; ;
88 ; out: cf = set if failed ;
89 ; ;
90 ;--------------------------------------------------------------;
91 init_vfs:
92 push eax
93 push ebx
94
95 mov ebx, sizeof.VFS ; allocate structure size
96 call allocate_mem
97 cmp eax, 0
98 jne .ok
99 stc ; if error, set carry
100 mov ebx, 0
101
102 .ok:
103 mov dword [VFS_structure], ebx
104
105 pop ebx
106 pop eax
107 ret
108
109 ;--------------------------------------------------------------;
110 ; add_media - add media driver ;
111 ;--------------------------------------------------------------;
112 ; ;
113 ; in: reg = pointer to VFS drive info ;
114 ; ;
115 ; out: reg = pointer to struct(s) if FAT12 found ;
116 ; ;
117 ;--------------------------------------------------------------;
118 add_media:
119 push eax
120 ;...
121 pop eax
122 ret
123
124 ;--------------------------------------------------------------;
125 ; add_fs - add filesystem driver ;
126 ;--------------------------------------------------------------;
127 ; ;
128 ; in: reg = pointer to VFS drive info ;
129 ; ;
130 ; out: reg = pointer to struct(s) if FAT12 found ;
131 ; ;
132 ;--------------------------------------------------------------;
133 add_fs:
134 push eax
135 ;...
136 pop eax
137 ret
138
139 ;--------------------------------------------------------------;
140 ; open_file - open file, return handle ;
141 ;--------------------------------------------------------------;
142 ; ;
143 ; in: reg = ASCIIZ file name and such ;
144 ; ;
145 ; out: reg = dword file handle ;
146 ; ;
147 ;--------------------------------------------------------------;
148 open_file:
149 push eax
150 ; file handles need to be dword, where the high
151 ; word contains drive number, and the low word
152 ; is the drive/FS specific handle. meaning no internal
153 ; table in VFS, created dynamically with FS info.
154 ; limits FS to a max of 65535 opened files. most use fewer
155 ; as default. FAT12 driver has 32.
156 ; FS reports error if handle is invalid.
157 pop eax
158 ret