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

wirehaze git hosting

a067cce36c8d6d6e5b05157eb2385be0823a705e
[BOS.git] / kernel / vfs / parse.asm
1 ;--------------------------------------------------------------;
2 ; parse_path - parse path to get info on each part ;
3 ;--------------------------------------------------------------;
4 ; ;
5 ; in: esi = pointer to full ASCIIZ path ;
6 ; cl = part no. to extract or 0 for none ;
7 ; ;
8 ; out: bl = drive no. (VFS assigned) or zero ;
9 ; bh = number of elements or zero for none ;
10 ; edi = pointer to ASCIIZ part of path in ;
11 ; cl, or 0 on error or no input ;
12 ;--------------------------------------------------------------;
13 parse_path:
14 push eax
15 push ecx
16 push edx
17 push esi
18
19 cmp byte [esi], 0
20 je .error
21 cmp byte [esi+1], 0 ; minimum 3 chars drive
22 je .error
23 cmp byte [esi+2], 0
24 je .error
25
26 and byte [esi], 11011111b ; (0xDF) to uppercase
27 and byte [esi+1], 11011111b ; (0xDF) to uppercase
28
29 mov bl, 0x00 ; fd base is 0x00
30 cmp word [esi], 'FD' ; fd check
31 je .drive_found
32 mov bl, 0x0F ; hd base is 0x0F
33 cmp word [esi], 'HD' ; hd check
34 je .drive_found
35 mov bl, 0x5F ; cd base is 0x5F
36 cmp word [esi], 'CD' ; cd check
37 je .drive_found
38 mov bl, 0x7F ; rd base is 0x7F
39 cmp word [esi], 'RD' ; rd (ram drive) check
40 je .drive_found
41 mov bl, 0x8F ; rm base is 0x8F
42 cmp word [esi], 'RM' ; rm (removable/usb)
43 je .drive_found
44 mov bl, 0xAF ; nd base is 0xAF
45 cmp word [esi], 'ND' ; nd (net) check
46 je .drive_found
47
48 jmp .error ; no valid drive found
49
50 ;-----------------------;
51 ; get drive number ;
52 ;-----------------------;
53 .drive_found:
54 xor edx, edx ; esi offest for first /
55 cmp byte [esi+3], 0 ; end of path
56 je .one_number
57 cmp byte [esi+3], '/' ; one number
58 je .one_number
59
60 mov edx, 4 ; first / after numbers
61 xor eax, eax
62 mov ax, word [esi+2] ; get 2 bytes number
63 jmp .convert_cont
64 .one_number:
65 mov edx, 3 ; first / after numbers
66 xor eax, eax
67 mov al, byte [esi+2] ; 1 byte ASCII number
68 .convert_cont:
69 push ecx
70 xor ecx, ecx
71 cmp ah, 0
72 jne .cont_convert
73 pop ecx
74 sub al, 0x30 ; only one ASCII char.
75 jmp .number_found ; done.
76 .cont_convert:
77 mov cl, ah
78 sub cx, 0x30 ; take care of first
79 push ecx ; save it for later..
80 mov cl, al
81 sub cx, 0x30
82 shl cx, 1 ; multiply with 10 using
83 mov eax, ecx ; x*8 + x*2 =
84 shl cx, 2
85 add ax, cx ; x*10
86 pop ecx
87 add ax, cx ; add first number
88 pop ecx
89
90 .number_found:
91 add bl, al ; add number to base
92
93 ;------------------------;
94 ; parse parts of path ;
95 ;------------------------;
96 mov bh, 0 ; start at zero
97 add esi, edx ; add start offset
98
99 cmp byte [esi], '/'
100 jne .end ; root, no parts
101 xor eax, eax ; counter
102 .parts_loop: ; loop for path parts
103 inc esi
104 cmp byte [esi], 0 ; end of path?
105 je .end ; no inc in parts
106 cmp byte [esi], '/' ; end of part?
107 je .new_part
108 cmp eax, 0
109 jne .cont_parts
110 inc bh ; inc no. of parts
111 .cont_parts:
112 inc eax ; char count inc
113
114 cmp cl, bh ; check for part to
115 jne .parts_loop ; save, if match:
116 mov edi, .filename_buffer ; get buffer
117 dec edi ; offset starts at 1,
118 add edi, eax ; not 0 - so fixed now
119 push eax
120 mov al, byte [esi]
121 mov byte [edi], al ; put the byte
122 mov byte [edi+1], 0 ; make ASCIIZ
123 pop eax
124
125 jmp .parts_loop
126 .new_part:
127 xor eax, eax ; reset char count
128 jmp .parts_loop ; loop again
129
130 ;------------------------;
131 ; cleanup and return ;
132 ;------------------------;
133 .end:
134 mov edi, .filename_buffer
135 pop esi
136 pop edx
137 pop ecx
138 pop eax
139 ret
140 .error:
141 pop esi
142 pop edx
143 pop ecx
144 pop eax
145 mov edi, 0 ; not a valid part
146 mov bl, 0 ; not a valid drive
147 mov bh, 0 ; not a valid path
148 ret
149
150 .filename_buffer: times 256 db 0