Rev 4265 | Rev 5565 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4265 | Rev 5201 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Contains ext2 block handling code. ;; |
3 | ;; Contains ext2 block handling code. ;; |
4 | ;; ;; |
4 | ;; ;; |
5 | ;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; |
5 | ;; Copyright (C) KolibriOS team 2013-2014. All rights reserved. ;; |
6 | ;; Distributed under the terms of the new BSD license. ;; |
6 | ;; Distributed under terms of the GNU General Public License ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
8 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
- | 9 | ||
- | 10 | $Revision: 4891 $ |
|
- | 11 | ||
9 | 12 | ||
10 | ;--------------------------------------------------------------------- |
13 | ;--------------------------------------------------------------------- |
11 | ; Write ext2 block from memory to disk. |
14 | ; Write ext2 block from memory to disk. |
12 | ; Input: eax = i_block (block number in ext2 terms); |
15 | ; Input: eax = i_block (block number in ext2 terms); |
13 | ; ebx = buffer address |
16 | ; ebx = buffer address |
14 | ; ebp = pointer to EXTFS |
17 | ; ebp = pointer to EXTFS |
15 | ; Output: eax = error code (0 implies no error) |
18 | ; Output: eax = error code (0 implies no error) |
16 | ;--------------------------------------------------------------------- |
19 | ;--------------------------------------------------------------------- |
17 | ext2_block_write: |
20 | ext2_block_write: |
18 | push edx ebx ecx |
21 | push edx ebx ecx |
19 | 22 | ||
20 | mov edx, fs_write32_sys |
23 | mov edx, fs_write32_sys |
21 | jmp ext2_block_modify |
24 | jmp ext2_block_modify |
22 | 25 | ||
23 | ;--------------------------------------------------------------------- |
26 | ;--------------------------------------------------------------------- |
24 | ; Read ext2 block from disk to memory. |
27 | ; Read ext2 block from disk to memory. |
25 | ; Input: eax = i_block (block number in ext2 terms); |
28 | ; Input: eax = i_block (block number in ext2 terms); |
26 | ; ebx = address of where to read block |
29 | ; ebx = address of where to read block |
27 | ; ebp = pointer to EXTFS |
30 | ; ebp = pointer to EXTFS |
28 | ; Output: eax = error code (0 implies no error) |
31 | ; Output: eax = error code (0 implies no error) |
29 | ;--------------------------------------------------------------------- |
32 | ;--------------------------------------------------------------------- |
30 | ext2_block_read: |
33 | ext2_block_read: |
31 | push edx ebx ecx |
34 | push edx ebx ecx |
32 | 35 | ||
33 | mov edx, fs_read32_sys |
36 | mov edx, fs_read32_sys |
34 | jmp ext2_block_modify |
37 | jmp ext2_block_modify |
35 | 38 | ||
36 | ;--------------------------------------------------------------------- |
39 | ;--------------------------------------------------------------------- |
37 | ; Modify ext2 block. |
40 | ; Modify ext2 block. |
38 | ; Input: eax = i_block (block number in ext2 terms); |
41 | ; Input: eax = i_block (block number in ext2 terms); |
39 | ; ebx = I/O buffer address; |
42 | ; ebx = I/O buffer address; |
40 | ; edx = fs_read/write32_sys |
43 | ; edx = fs_read/write32_sys |
41 | ; ebp = pointer to EXTFS |
44 | ; ebp = pointer to EXTFS |
42 | ; edx, ebx, ecx on stack. |
45 | ; edx, ebx, ecx on stack. |
43 | ; Output: eax = error code (0 implies no error) |
46 | ; Output: eax = error code (0 implies no error) |
44 | ;--------------------------------------------------------------------- |
47 | ;--------------------------------------------------------------------- |
45 | ext2_block_modify: |
48 | ext2_block_modify: |
46 | ; Get block number in hard-disk terms in eax. |
49 | ; Get block number in hard-disk terms in eax. |
47 | mov ecx, [ebp + EXTFS.log_block_size] |
50 | mov ecx, [ebp + EXTFS.log_block_size] |
48 | shl eax, cl |
51 | shl eax, cl |
49 | mov ecx, eax |
52 | mov ecx, eax |
50 | push [ebp + EXTFS.count_block_in_block] |
53 | push [ebp + EXTFS.count_block_in_block] |
51 | 54 | ||
52 | @@: |
55 | @@: |
53 | mov eax, ecx |
56 | mov eax, ecx |
54 | call edx |
57 | call edx |
55 | test eax, eax |
58 | test eax, eax |
56 | jnz .fail |
59 | jnz .fail |
57 | 60 | ||
58 | inc ecx |
61 | inc ecx |
59 | add ebx, 512 |
62 | add ebx, 512 |
60 | dec dword[esp] |
63 | dec dword[esp] |
61 | jnz @B |
64 | jnz @B |
62 | 65 | ||
63 | xor eax, eax |
66 | xor eax, eax |
64 | @@: |
67 | @@: |
65 | pop ecx |
68 | pop ecx |
66 | pop ecx ebx edx |
69 | pop ecx ebx edx |
67 | ret |
70 | ret |
68 | 71 | ||
69 | .fail: |
72 | .fail: |
70 | mov eax, ERROR_DEVICE |
73 | mov eax, ERROR_DEVICE |
71 | jmp @B |
74 | jmp @B |
72 | 75 | ||
73 | ;--------------------------------------------------------------------- |
76 | ;--------------------------------------------------------------------- |
74 | ; Zeroes a block. |
77 | ; Zeroes a block. |
75 | ; Input: ebx = block ID. |
78 | ; Input: ebx = block ID. |
76 | ; ebp = pointer to EXTFS. |
79 | ; ebp = pointer to EXTFS. |
77 | ; Output: eax = error code. |
80 | ; Output: eax = error code. |
78 | ;--------------------------------------------------------------------- |
81 | ;--------------------------------------------------------------------- |
79 | ext2_block_zero: |
82 | ext2_block_zero: |
80 | push ebx |
83 | push ebx |
81 | 84 | ||
82 | mov eax, ebx |
85 | mov eax, ebx |
83 | mov ebx, [ebp + EXTFS.ext2_temp_block] |
86 | mov ebx, [ebp + EXTFS.ext2_temp_block] |
84 | 87 | ||
85 | call ext2_block_read |
88 | call ext2_block_read |
86 | test eax, eax |
89 | test eax, eax |
87 | jnz .return |
90 | jnz .return |
88 | 91 | ||
89 | push edi ecx |
92 | push edi ecx |
90 | xor eax, eax |
93 | xor eax, eax |
91 | mov ecx, [ebp + EXTFS.block_size] |
94 | mov ecx, [ebp + EXTFS.block_size] |
92 | mov edi, [ebp + EXTFS.ext2_temp_block] |
95 | mov edi, [ebp + EXTFS.ext2_temp_block] |
93 | rep stosb |
96 | rep stosb |
94 | pop ecx edi |
97 | pop ecx edi |
95 | 98 | ||
96 | mov eax, [esp] |
99 | mov eax, [esp] |
97 | call ext2_block_write |
100 | call ext2_block_write |
98 | 101 | ||
99 | .return: |
102 | .return: |
100 | pop ebx |
103 | pop ebx |
101 | ret |
104 | ret |
102 | 105 | ||
103 | ;--------------------------------------------------------------------- |
106 | ;--------------------------------------------------------------------- |
104 | ; Allocates a block. |
107 | ; Allocates a block. |
105 | ; Input: eax = inode ID for "preference". |
108 | ; Input: eax = inode ID for "preference". |
106 | ; ebp = pointer to EXTFS. |
109 | ; ebp = pointer to EXTFS. |
107 | ; Output: Block marked as set in block group. |
110 | ; Output: Block marked as set in block group. |
108 | ; eax = error code. |
111 | ; eax = error code. |
109 | ; ebx = block ID. |
112 | ; ebx = block ID. |
110 | ;--------------------------------------------------------------------- |
113 | ;--------------------------------------------------------------------- |
111 | ext2_block_alloc: |
114 | ext2_block_alloc: |
112 | push [ebp + EXTFS.superblock + EXT2_SB_STRUC.blocks_count] |
115 | push [ebp + EXTFS.superblock + EXT2_SB_STRUC.blocks_count] |
113 | push EXT2_BLOCK_GROUP_DESC.free_blocks_count |
116 | push EXT2_BLOCK_GROUP_DESC.free_blocks_count |
114 | push [ebp + EXTFS.superblock + EXT2_SB_STRUC.blocks_per_group] |
117 | push [ebp + EXTFS.superblock + EXT2_SB_STRUC.blocks_per_group] |
115 | 118 | ||
116 | lea ebx, [ebp + EXTFS.superblock + EXT2_SB_STRUC.free_block_count] |
119 | lea ebx, [ebp + EXTFS.superblock + EXT2_SB_STRUC.free_block_count] |
117 | push ebx |
120 | push ebx |
118 | 121 | ||
119 | push ext2_bg_read_blk_bitmap |
122 | push ext2_bg_read_blk_bitmap |
120 | 123 | ||
121 | call ext2_resource_alloc |
124 | call ext2_resource_alloc |
122 | 125 | ||
123 | ret |
126 | ret |
124 | 127 | ||
125 | ;--------------------------------------------------------------------- |
128 | ;--------------------------------------------------------------------- |
126 | ; Zero-allocates a block. |
129 | ; Zero-allocates a block. |
127 | ; Input: eax = inode ID for "preference". |
130 | ; Input: eax = inode ID for "preference". |
128 | ; ebp = pointer to EXTFS. |
131 | ; ebp = pointer to EXTFS. |
129 | ; Output: Block marked as set in block group. |
132 | ; Output: Block marked as set in block group. |
130 | ; eax = error code. |
133 | ; eax = error code. |
131 | ; ebx = block ID. |
134 | ; ebx = block ID. |
132 | ;--------------------------------------------------------------------- |
135 | ;--------------------------------------------------------------------- |
133 | ext2_block_calloc: |
136 | ext2_block_calloc: |
134 | call ext2_block_alloc |
137 | call ext2_block_alloc |
135 | test eax, eax |
138 | test eax, eax |
136 | jnz @F |
139 | jnz @F |
137 | 140 | ||
138 | call ext2_block_zero |
141 | call ext2_block_zero |
139 | @@: |
142 | @@: |
140 | ret |
143 | ret |
141 | 144 | ||
142 | ;--------------------------------------------------------------------- |
145 | ;--------------------------------------------------------------------- |
143 | ; Frees a block. |
146 | ; Frees a block. |
144 | ; Input: eax = block ID. |
147 | ; Input: eax = block ID. |
145 | ; ebp = pointer to EXTFS. |
148 | ; ebp = pointer to EXTFS. |
146 | ; Output: Block marked as free in block group. |
149 | ; Output: Block marked as free in block group. |
147 | ; eax = error code. |
150 | ; eax = error code. |
148 | ;--------------------------------------------------------------------- |
151 | ;--------------------------------------------------------------------- |
149 | ext2_block_free: |
152 | ext2_block_free: |
150 | push edi ecx |
153 | push edi ecx |
151 | 154 | ||
152 | mov edi, ext2_bg_read_blk_bitmap |
155 | mov edi, ext2_bg_read_blk_bitmap |
153 | xor ecx, ecx |
156 | xor ecx, ecx |
154 | call ext2_resource_free |
157 | call ext2_resource_free |
155 | 158 | ||
156 | pop ecx edi |
159 | pop ecx edi |
157 | ret |
160 | ret |
158 | 161 | ||
159 | ;--------------------------------------------------------------------- |
162 | ;--------------------------------------------------------------------- |
160 | ; Find parent from file path in block. |
163 | ; Find parent from file path in block. |
161 | ; Input: esi = file path. |
164 | ; Input: esi = file path. |
162 | ; ebx = pointer to directory block. |
165 | ; ebx = pointer to directory block. |
163 | ; ebp = pointer to EXTFS structure. |
166 | ; ebp = pointer to EXTFS structure. |
164 | ; Output: esi = name without parent, or not changed. |
167 | ; Output: esi = name without parent, or not changed. |
165 | ; ebx = directory record matched. |
168 | ; ebx = directory record matched. |
166 | ;--------------------------------------------------------------------- |
169 | ;--------------------------------------------------------------------- |
167 | ext2_block_find_parent: |
170 | ext2_block_find_parent: |
168 | sub esp, 256 ; Space for EXT2 filename. |
171 | sub esp, 256 ; Space for EXT2 filename. |
169 | mov edx, ebx |
172 | mov edx, ebx |
170 | add edx, [ebp + EXTFS.block_size] ; Save block end. |
173 | add edx, [ebp + EXTFS.block_size] ; Save block end. |
171 | 174 | ||
172 | .start_rec: |
175 | .start_rec: |
173 | cmp [ebx + EXT2_DIR_STRUC.inode], 0 |
176 | cmp [ebx + EXT2_DIR_STRUC.inode], 0 |
174 | jz .next_rec |
177 | jz .next_rec |
175 | 178 | ||
176 | mov edi, esp |
179 | mov edi, esp |
177 | push esi |
180 | push esi |
178 | movzx ecx, [ebx + EXT2_DIR_STRUC.name_len] |
181 | movzx ecx, [ebx + EXT2_DIR_STRUC.name_len] |
179 | lea esi, [ebx + EXT2_DIR_STRUC.name] |
182 | lea esi, [ebx + EXT2_DIR_STRUC.name] |
180 | call utf8_to_cp866 |
183 | call utf8_to_cp866 |
181 | 184 | ||
182 | mov ecx, edi |
185 | mov ecx, edi |
183 | lea edi, [esp + 4] |
186 | lea edi, [esp + 4] |
184 | sub ecx, edi ; Number of bytes in resulting string. |
187 | sub ecx, edi ; Number of bytes in resulting string. |
185 | 188 | ||
186 | mov esi, [esp] |
189 | mov esi, [esp] |
187 | 190 | ||
188 | ; esi: original file path. |
191 | ; esi: original file path. |
189 | ; edi: converted string stored on stack. |
192 | ; edi: converted string stored on stack. |
190 | ; ecx: size of converted string. |
193 | ; ecx: size of converted string. |
191 | @@: |
194 | @@: |
192 | ; If no bytes left in resulting string, test it. |
195 | ; If no bytes left in resulting string, test it. |
193 | jecxz .test_find |
196 | jecxz .test_find |
194 | dec ecx |
197 | dec ecx |
195 | 198 | ||
196 | lodsb |
199 | lodsb |
197 | call char_toupper |
200 | call char_toupper |
198 | 201 | ||
199 | mov ah, [edi] |
202 | mov ah, [edi] |
200 | inc edi |
203 | inc edi |
201 | xchg al, ah |
204 | xchg al, ah |
202 | call char_toupper |
205 | call char_toupper |
203 | 206 | ||
204 | ; If both are same, check next byte. |
207 | ; If both are same, check next byte. |
205 | cmp al, ah |
208 | cmp al, ah |
206 | je @B |
209 | je @B |
207 | @@: ; Doesn't match. |
210 | @@: ; Doesn't match. |
208 | pop esi |
211 | pop esi |
209 | 212 | ||
210 | .next_rec: |
213 | .next_rec: |
211 | movzx eax, [ebx + EXT2_DIR_STRUC.rec_len] |
214 | movzx eax, [ebx + EXT2_DIR_STRUC.rec_len] |
212 | add ebx, eax ; Go to next record. |
215 | add ebx, eax ; Go to next record. |
213 | cmp ebx, edx ; Check if this is the end. |
216 | cmp ebx, edx ; Check if this is the end. |
214 | jb .start_rec |
217 | jb .start_rec |
215 | 218 | ||
216 | add esp, 256 |
219 | add esp, 256 |
217 | ret |
220 | ret |
218 | 221 | ||
219 | .test_find: |
222 | .test_find: |
220 | cmp byte [esi], 0 |
223 | cmp byte [esi], 0 |
221 | je .ret ; The end reached. |
224 | je .ret ; The end reached. |
222 | cmp byte [esi], '/' ; If not end of directory name, not matched. |
225 | cmp byte [esi], '/' ; If not end of directory name, not matched. |
223 | jne @B |
226 | jne @B |
224 | inc esi |
227 | inc esi |
225 | 228 | ||
226 | .ret: |
229 | .ret: |
227 | add esp, 256 + 4 |
230 | add esp, 256 + 4 |
228 | ret |
231 | ret |
229 | 232 | ||
230 | ;--------------------------------------------------------------------- |
233 | ;--------------------------------------------------------------------- |
231 | ; Finds free space in a directory block, modifying last entry appropriately. |
234 | ; Finds free space in a directory block, modifying last entry appropriately. |
232 | ; Input: ebp = pointer to EXTFS. |
235 | ; Input: ebp = pointer to EXTFS. |
233 | ; ecx = size of free space required. |
236 | ; ecx = size of free space required. |
234 | ; [EXTFS.ext2_temp_block] contains the block relevant. |
237 | ; [EXTFS.ext2_temp_block] contains the block relevant. |
235 | ; Output: edi = free entry. |
238 | ; Output: edi = free entry. |
236 | ; rec_len of free entry is set. |
239 | ; rec_len of free entry is set. |
237 | ; eax = error code; if the block doesn't link to the next one, this is 0x00000001 on failure. |
240 | ; eax = error code; if the block doesn't link to the next one, this is 0x00000001 on failure. |
238 | ; ; else, 0xFFFFFFFF. |
241 | ; ; else, 0xFFFFFFFF. |
239 | ;--------------------------------------------------------------------- |
242 | ;--------------------------------------------------------------------- |
240 | ext2_block_find_fspace: |
243 | ext2_block_find_fspace: |
241 | push ebx edx |
244 | push ebx edx |
242 | 245 | ||
243 | mov edi, [ebp + EXTFS.ext2_temp_block] |
246 | mov edi, [ebp + EXTFS.ext2_temp_block] |
244 | mov edx, edi |
247 | mov edx, edi |
245 | add edx, [ebp + EXTFS.block_size] |
248 | add edx, [ebp + EXTFS.block_size] |
246 | 249 | ||
247 | @@: |
250 | @@: |
248 | movzx eax, [edi + EXT2_DIR_STRUC.rec_len] |
251 | movzx eax, [edi + EXT2_DIR_STRUC.rec_len] |
249 | test eax, eax |
252 | test eax, eax |
250 | jz .zero_len |
253 | jz .zero_len |
251 | 254 | ||
252 | cmp [edi + EXT2_DIR_STRUC.inode], 0 |
255 | cmp [edi + EXT2_DIR_STRUC.inode], 0 |
253 | je .unused_entry |
256 | je .unused_entry |
254 | 257 | ||
255 | ; It's a used entry, so see if we can fit it between current one and next. |
258 | ; It's a used entry, so see if we can fit it between current one and next. |
256 | ; Subtract the size used by the name and the structure from rec_len. |
259 | ; Subtract the size used by the name and the structure from rec_len. |
257 | movzx ebx, [edi + EXT2_DIR_STRUC.name_len] |
260 | movzx ebx, [edi + EXT2_DIR_STRUC.name_len] |
258 | add ebx, 8 + 3 |
261 | add ebx, 8 + 3 |
259 | and ebx, 0xfffffffc ; Align it on the next 4-byte boundary. |
262 | and ebx, 0xfffffffc ; Align it on the next 4-byte boundary. |
260 | 263 | ||
261 | sub eax, ebx |
264 | sub eax, ebx |
262 | add edi, ebx |
265 | add edi, ebx |
263 | cmp eax, ecx |
266 | cmp eax, ecx |
264 | jb .next_iter |
267 | jb .next_iter |
265 | 268 | ||
266 | sub edi, ebx |
269 | sub edi, ebx |
267 | mov [edi + EXT2_DIR_STRUC.rec_len], bx ; Make previous entry point to us. |
270 | mov [edi + EXT2_DIR_STRUC.rec_len], bx ; Make previous entry point to us. |
268 | add edi, ebx |
271 | add edi, ebx |
269 | 272 | ||
270 | mov [edi + EXT2_DIR_STRUC.rec_len], ax ; Make current entry point to next one. |
273 | mov [edi + EXT2_DIR_STRUC.rec_len], ax ; Make current entry point to next one. |
271 | jmp .found |
274 | jmp .found |
272 | 275 | ||
273 | .unused_entry: |
276 | .unused_entry: |
274 | ; It's an unused inode. |
277 | ; It's an unused inode. |
275 | cmp eax, ecx |
278 | cmp eax, ecx |
276 | jge .found |
279 | jge .found |
277 | 280 | ||
278 | .next_iter: |
281 | .next_iter: |
279 | add edi, eax |
282 | add edi, eax |
280 | cmp edi, edx |
283 | cmp edi, edx |
281 | jb @B |
284 | jb @B |
282 | 285 | ||
283 | .not_found: |
286 | .not_found: |
284 | xor eax, eax |
287 | xor eax, eax |
285 | not eax |
288 | not eax |
286 | jmp .ret |
289 | jmp .ret |
287 | 290 | ||
288 | ; Zero length entry means we have the rest of the block for us. |
291 | ; Zero length entry means we have the rest of the block for us. |
289 | .zero_len: |
292 | .zero_len: |
290 | mov eax, edx |
293 | mov eax, edx |
291 | sub eax, edi |
294 | sub eax, edi |
292 | 295 | ||
293 | ; Point to next block. |
296 | ; Point to next block. |
294 | mov [edi + EXT2_DIR_STRUC.rec_len], ax |
297 | mov [edi + EXT2_DIR_STRUC.rec_len], ax |
295 | 298 | ||
296 | cmp eax, ecx |
299 | cmp eax, ecx |
297 | jge .fits |
300 | jge .fits |
298 | 301 | ||
299 | mov [edi + EXT2_DIR_STRUC.inode], 0 |
302 | mov [edi + EXT2_DIR_STRUC.inode], 0 |
300 | 303 | ||
301 | ; It doesn't fit, but the block doesn't link to the next block. |
304 | ; It doesn't fit, but the block doesn't link to the next block. |
302 | xor eax, eax |
305 | xor eax, eax |
303 | inc eax |
306 | inc eax |
304 | jmp .ret |
307 | jmp .ret |
305 | 308 | ||
306 | .fits: |
309 | .fits: |
307 | mov [edi + EXT2_DIR_STRUC.rec_len], cx |
310 | mov [edi + EXT2_DIR_STRUC.rec_len], cx |
308 | 311 | ||
309 | .found: |
312 | .found: |
310 | xor eax, eax |
313 | xor eax, eax |
311 | 314 | ||
312 | .ret: |
315 | .ret: |
313 | pop edx ebx |
316 | pop edx ebx |
314 | ret |
317 | ret |
315 | 318 | ||
316 | ;--------------------------------------------------------------------- |
319 | ;--------------------------------------------------------------------- |
317 | ; Gets the block group's descriptor. |
320 | ; Gets the block group's descriptor. |
318 | ; Input: eax = block group. |
321 | ; Input: eax = block group. |
319 | ; Output: eax = if zero, error; else, points to block group descriptor. |
322 | ; Output: eax = if zero, error; else, points to block group descriptor. |
320 | ; [EXTFS.ext2_temp_block] contains relevant block. |
323 | ; [EXTFS.ext2_temp_block] contains relevant block. |
321 | ; ebp = pointer to EXTFS. |
324 | ; ebp = pointer to EXTFS. |
322 | ;--------------------------------------------------------------------- |
325 | ;--------------------------------------------------------------------- |
323 | ext2_bg_read_desc: |
326 | ext2_bg_read_desc: |
324 | push edx ebx |
327 | push edx ebx |
325 | mov edx, 32 |
328 | mov edx, 32 |
326 | mul edx ; Get index of descriptor in global_desc_table. |
329 | mul edx ; Get index of descriptor in global_desc_table. |
327 | 330 | ||
328 | ; eax: block group descriptor offset relative to global descriptor table start |
331 | ; eax: block group descriptor offset relative to global descriptor table start |
329 | ; Find the block this block descriptor is in. |
332 | ; Find the block this block descriptor is in. |
330 | div [ebp + EXTFS.block_size] |
333 | div [ebp + EXTFS.block_size] |
331 | add eax, [ebp + EXTFS.superblock + EXT2_SB_STRUC.first_data_block] |
334 | add eax, [ebp + EXTFS.superblock + EXT2_SB_STRUC.first_data_block] |
332 | inc eax |
335 | inc eax |
333 | mov ebx, [ebp + EXTFS.ext2_temp_block] |
336 | mov ebx, [ebp + EXTFS.ext2_temp_block] |
334 | call ext2_block_read |
337 | call ext2_block_read |
335 | test eax, eax |
338 | test eax, eax |
336 | jnz .fail |
339 | jnz .fail |
337 | 340 | ||
338 | add ebx, edx ; edx: local index of descriptor inside block |
341 | add ebx, edx ; edx: local index of descriptor inside block |
339 | mov eax, ebx |
342 | mov eax, ebx |
340 | 343 | ||
341 | .return: |
344 | .return: |
342 | pop ebx edx |
345 | pop ebx edx |
343 | ret |
346 | ret |
344 | 347 | ||
345 | .fail: |
348 | .fail: |
346 | xor eax, eax |
349 | xor eax, eax |
347 | jmp .return |
350 | jmp .return |
348 | 351 | ||
349 | ;--------------------------------------------------------------------- |
352 | ;--------------------------------------------------------------------- |
350 | ; Writes a block group's descriptor. |
353 | ; Writes a block group's descriptor. |
351 | ; Input: eax = block group. |
354 | ; Input: eax = block group. |
352 | ; [EXTFS.ext2_temp_data] contains the block relevant. |
355 | ; [EXTFS.ext2_temp_data] contains the block relevant. |
353 | ; ebp = pointer to EXTFS. |
356 | ; ebp = pointer to EXTFS. |
354 | ; Output: eax = error code. |
357 | ; Output: eax = error code. |
355 | ;--------------------------------------------------------------------- |
358 | ;--------------------------------------------------------------------- |
356 | ext2_bg_write_desc: |
359 | ext2_bg_write_desc: |
357 | push edx ebx |
360 | push edx ebx |
358 | mov edx, 32 |
361 | mov edx, 32 |
359 | mul edx ; Get index of descriptor in global_desc_table. |
362 | mul edx ; Get index of descriptor in global_desc_table. |
360 | 363 | ||
361 | ; eax: block group descriptor offset relative to global descriptor table start |
364 | ; eax: block group descriptor offset relative to global descriptor table start |
362 | ; Find the block this block descriptor is in. |
365 | ; Find the block this block descriptor is in. |
363 | div [ebp + EXTFS.block_size] |
366 | div [ebp + EXTFS.block_size] |
364 | add eax, [ebp + EXTFS.superblock + EXT2_SB_STRUC.first_data_block] |
367 | add eax, [ebp + EXTFS.superblock + EXT2_SB_STRUC.first_data_block] |
365 | inc eax |
368 | inc eax |
366 | mov ebx, [ebp + EXTFS.ext2_temp_block] |
369 | mov ebx, [ebp + EXTFS.ext2_temp_block] |
367 | call ext2_block_write |
370 | call ext2_block_write |
368 | 371 | ||
369 | .return: |
372 | .return: |
370 | pop ebx edx |
373 | pop ebx edx |
371 | ret |
374 | ret |
372 | 375 | ||
373 | ;--------------------------------------------------------------------- |
376 | ;--------------------------------------------------------------------- |
374 | ; Gets the block group's block bitmap. |
377 | ; Gets the block group's block bitmap. |
375 | ; Input: eax = block group. |
378 | ; Input: eax = block group. |
376 | ; Output: eax = if zero, error; else, points to block group descriptor. |
379 | ; Output: eax = if zero, error; else, points to block group descriptor. |
377 | ; ebx = block bitmap's block (hard disk). |
380 | ; ebx = block bitmap's block (hard disk). |
378 | ;--------------------------------------------------------------------- |
381 | ;--------------------------------------------------------------------- |
379 | ext2_bg_read_blk_bitmap: |
382 | ext2_bg_read_blk_bitmap: |
380 | push ecx |
383 | push ecx |
381 | 384 | ||
382 | call ext2_bg_read_desc |
385 | call ext2_bg_read_desc |
383 | test eax, eax |
386 | test eax, eax |
384 | jz .fail |
387 | jz .fail |
385 | 388 | ||
386 | mov ebx, [eax + EXT2_BLOCK_GROUP_DESC.block_bitmap] ; Block number of block group bitmap - in ext2 terms. |
389 | mov ebx, [eax + EXT2_BLOCK_GROUP_DESC.block_bitmap] ; Block number of block group bitmap - in ext2 terms. |
387 | 390 | ||
388 | .return: |
391 | .return: |
389 | pop ecx |
392 | pop ecx |
390 | ret |
393 | ret |
391 | 394 | ||
392 | .fail: |
395 | .fail: |
393 | xor eax, eax |
396 | xor eax, eax |
394 | jmp .return |
397 | jmp .return |
395 | 398 | ||
396 | ;--------------------------------------------------------------------- |
399 | ;--------------------------------------------------------------------- |
397 | ; Updates superblock, plus backups. |
400 | ; Updates superblock, plus backups. |
398 | ; Input: ebp = pointer to EXTFS. |
401 | ; Input: ebp = pointer to EXTFS. |
399 | ; Output: eax = error code. |
402 | ; Output: eax = error code. |
400 | ;--------------------------------------------------------------------- |
403 | ;--------------------------------------------------------------------- |
401 | ext2_sb_update: |
404 | ext2_sb_update: |
402 | push ebx |
405 | push ebx |
403 | 406 | ||
404 | mov eax, 2 |
407 | mov eax, 2 |
405 | lea ebx, [ebp + EXTFS.superblock] |
408 | lea ebx, [ebp + EXTFS.superblock] |
406 | call fs_write32_sys |
409 | call fs_write32_sys |
407 | 410 | ||
408 | pop ebx |
411 | pop ebx |
409 | ret |
412 | ret |