Subversion Repositories Kolibri OS

Rev

Rev 2465 | Rev 3232 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2465 Rev 2987
Line 348... Line 348...
348
	xor	eax, eax	; the argument of malloc() is in eax
348
	xor	eax, eax	; the argument of malloc() is in eax
349
@@:
349
@@:
350
	inc	eax
350
	inc	eax
351
	cmp	byte [ebx+eax-1], 0
351
	cmp	byte [ebx+eax-1], 0
352
	jnz	@b
352
	jnz	@b
353
; 2b. Call the heap manager.
353
; 2b. Call the heap manager. Note that it can change ebx.
-
 
354
        push    ebx
354
	call	malloc
355
	call	malloc
-
 
356
        pop     ebx
355
; 2c. Check the result. If allocation failed, go to 7.
357
; 2c. Check the result. If allocation failed, go to 7.
356
	pop	esi		; restore allocated pointer to DISK
358
	pop	esi		; restore allocated pointer to DISK
357
	test	eax, eax
359
	test	eax, eax
358
	jz	.free
360
	jz	.free
359
; 2d. Store the allocated pointer to the DISK structure.
361
; 2d. Store the allocated pointer to the DISK structure.
Line 416... Line 418...
416
; Return value: none.
418
; Return value: none.
417
disk_del:
419
disk_del:
418
	push	esi	    ; save used registers to be stdcall
420
	push	esi	    ; save used registers to be stdcall
419
; 1. Force media to be removed. If the media is already removed, the
421
; 1. Force media to be removed. If the media is already removed, the
420
; call does nothing.
422
; call does nothing.
421
	mov	esi, [esp+4+8]	; esi = handle of the disk
423
        mov     esi, [esp+4+4]  ; esi = handle of the disk
422
	stdcall disk_media_changed, esi, 0
424
	stdcall disk_media_changed, esi, 0
423
; 2. Delete the structure from the global list.
425
; 2. Delete the structure from the global list.
424
; 2a. Acquire the mutex.
426
; 2a. Acquire the mutex.
425
	mov	ecx, disk_list_mutex
427
	mov	ecx, disk_list_mutex
426
	call	mutex_lock
428
	call	mutex_lock
Line 973... Line 975...
973
; and [ebp+4]=return address.
975
; and [ebp+4]=return address.
974
virtual at ebp+8
976
virtual at ebp+8
975
.start	dq	?
977
.start	dq	?
976
.length dq	?
978
.length dq	?
977
end virtual
979
end virtual
-
 
980
; When disk_add_partition is called, ebx contains a pointer to
-
 
981
; a two-sectors-sized buffer. This function saves ebx in the stack
-
 
982
; immediately before ebp.
-
 
983
virtual at ebp-4
-
 
984
.buffer dd      ?
-
 
985
end virtual
-
 
986
; 1. Read the bootsector to the buffer.
-
 
987
        mov     al, DISKFUNC.read
-
 
988
        mov     ebx, [.buffer]
-
 
989
        add     ebx, 512
-
 
990
        push    1
-
 
991
        stdcall disk_call_driver, ebx, dword [.start], dword [.start+4], esp
-
 
992
; 2. Run tests for all supported filesystems. If at least one test succeeded,
-
 
993
; go to 4.
-
 
994
; For tests: qword [ebp+8] = partition start, qword [ebp+10h] = partition
-
 
995
; length, [esp] = 0 if reading bootsector failed or 1 if succeeded,
-
 
996
; ebx points to the buffer for bootsector.
-
 
997
        call    fat_create_partition
-
 
998
        test    eax, eax
-
 
999
        jnz     .success
978
; Currently no file systems are supported, so just allocate the PARTITION
1000
; 3. No file system has recognized the volume, so just allocate the PARTITION
979
; structure without extra fields.
1001
; structure without extra fields.
980
; 1. Allocate and check result.
-
 
981
	push	sizeof.PARTITION
1002
	push	sizeof.PARTITION
982
	pop	eax
1003
	pop	eax
983
	call	malloc
1004
	call	malloc
984
	test	eax, eax
1005
	test	eax, eax
985
	jz	.nothing
1006
	jz	.nothing
986
; 2. Fill the common fields: copy .start and .length.
-
 
987
	mov	edx, dword [.start]
1007
	mov	edx, dword [.start]
988
	mov	dword [eax+PARTITION.FirstSector], edx
1008
	mov	dword [eax+PARTITION.FirstSector], edx
989
	mov	edx, dword [.start+4]
1009
	mov	edx, dword [.start+4]
990
	mov	dword [eax+PARTITION.FirstSector+4], edx
1010
	mov	dword [eax+PARTITION.FirstSector+4], edx
991
	mov	edx, dword [.length]
1011
	mov	edx, dword [.length]
992
	mov	dword [eax+PARTITION.Length], edx
1012
	mov	dword [eax+PARTITION.Length], edx
993
	mov	edx, dword [.length+4]
1013
	mov	edx, dword [.length+4]
994
	mov	dword [eax+PARTITION.Length+4], edx
1014
	mov	dword [eax+PARTITION.Length+4], edx
-
 
1015
        mov     [eax+PARTITION.Disk], esi
-
 
1016
        and     [eax+PARTITION.FSUserFunctions], 0
-
 
1017
.success:
995
.nothing:
1018
.nothing:
996
; 3. Return with eax = pointer to PARTITION or NULL.
1019
; 4. Return with eax = pointer to PARTITION or NULL.
-
 
1020
        pop     ecx
997
	ret
1021
	ret
Line 998... Line 1022...
998
 
1022
 
999
; This function is called from file_system_lfn.
1023
; This function is called from file_system_lfn.
1000
; This handler gets the control each time when fn 70 is called
1024
; This handler gets the control each time when fn 70 is called
Line 1059... Line 1083...
1059
; 5. Reference the disk.
1083
; 5. Reference the disk.
1060
        lock inc [ebx+DISK.RefCount]
1084
        lock inc [ebx+DISK.RefCount]
1061
; 6. Now we are sure that the DISK structure is not going to die at least
1085
; 6. Now we are sure that the DISK structure is not going to die at least
1062
; while we are working with it, so release the global mutex.
1086
; while we are working with it, so release the global mutex.
1063
	call	mutex_unlock
1087
	call	mutex_unlock
-
 
1088
        pop     ecx             ; pop from the stack saved value of esi
1064
; 7. Acquire the mutex for media object.
1089
; 7. Acquire the mutex for media object.
1065
	pop	edi		; restore edi
1090
	pop	edi		; restore edi
1066
	lea	ecx, [ebx+DISK.MediaLock]
1091
	lea	ecx, [ebx+DISK.MediaLock]
1067
	call	mutex_lock
1092
	call	mutex_lock
1068
; 8. Get the media object. If it is not NULL, reference it.
1093
; 8. Get the media object. If it is not NULL, reference it.
Line 1173... Line 1198...
1173
	test	eax, eax
1198
	test	eax, eax
1174
	jz	.nomedia
1199
	jz	.nomedia
1175
.main:
1200
.main:
1176
	cmp	ecx, [edx+DISK.NumPartitions]
1201
	cmp	ecx, [edx+DISK.NumPartitions]
1177
	jae	.notfound
1202
	jae	.notfound
-
 
1203
        mov     eax, [edx+DISK.Partitions]
-
 
1204
        mov     eax, [eax+ecx*4]
-
 
1205
        mov     edi, [eax+PARTITION.FSUserFunctions]
-
 
1206
        test    edi, edi
-
 
1207
        jz      .nofs
-
 
1208
        mov     ecx, [ebx]
-
 
1209
        cmp     [edi], ecx
-
 
1210
        jbe     .unsupported
-
 
1211
        push    edx
-
 
1212
        push    ebp
-
 
1213
        mov     ebp, eax
-
 
1214
        call    dword [edi+4+ecx*4]
-
 
1215
        pop     ebp
-
 
1216
        pop     edx
1178
	mov	dword [esp+32], ERROR_UNKNOWN_FS
1217
        mov     dword [esp+32], eax
-
 
1218
        mov     dword [esp+20], ebx
1179
.cleanup:
1219
.cleanup:
1180
	mov	esi, edx
1220
	mov	esi, edx
1181
	call	disk_media_dereference
1221
	call	disk_media_dereference
1182
	call	disk_dereference
1222
	call	disk_dereference
1183
	ret
1223
	ret
-
 
1224
.nofs:
-
 
1225
        mov     dword [esp+32], ERROR_UNKNOWN_FS
-
 
1226
        jmp     .cleanup
1184
.notfound:
1227
.notfound:
1185
	mov	dword [esp+32], ERROR_FILE_NOT_FOUND
1228
	mov	dword [esp+32], ERROR_FILE_NOT_FOUND
1186
	jmp	.cleanup
1229
	jmp	.cleanup
-
 
1230
.unsupported:
-
 
1231
        mov     dword [esp+32], ERROR_UNSUPPORTED_FS
-
 
1232
        jmp     .cleanup
1187
.nomedia:
1233
.nomedia:
1188
	test	ecx, ecx
1234
	test	ecx, ecx
1189
	jnz	.notfound
1235
	jnz	.notfound
1190
	test	byte [edx+DISK.DriverFlags], DISK_NO_INSERT_NOTIFICATION
1236
	test	byte [edx+DISK.DriverFlags], DISK_NO_INSERT_NOTIFICATION
1191
	jz	.deverror
1237
	jz	.deverror
1192
; if the driver does not support insert notifications and we are the only fs
1238
; if the driver does not support insert notifications and we are the only fs
1193
; operation with this disk, issue the fake insert notification; if media is
1239
; operation with this disk, issue the fake insert notification; if media is
1194
; still not inserted, 'disk_media_changed' will detect this and do nothing
1240
; still not inserted, 'disk_media_changed' will detect this and do nothing
1195
;;;        push    ebx
-
 
1196
	lea	ecx, [edx+DISK.MediaLock]
1241
	lea	ecx, [edx+DISK.MediaLock]
1197
	call	mutex_lock
1242
	call	mutex_lock
1198
	cmp	[edx+DISK.MediaRefCount], 1
1243
	cmp	[edx+DISK.MediaRefCount], 1
1199
	jnz	.noluck
1244
	jnz	.noluck
1200
	call	mutex_unlock
1245
	call	mutex_unlock