Subversion Repositories Kolibri OS

Rev

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

Rev 2150 Rev 2268
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2011. All rights reserved.      ;;
3
;; Copyright (C) KolibriOS team 2011. All rights reserved.      ;;
4
;; Distributed under terms of the GNU General Public License    ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 7... Line 7...
7
 
7
 
Line 8... Line 8...
8
$Revision: 2140 $
8
$Revision: 2257 $
9
 
9
 
10
; =============================================================================
10
; =============================================================================
11
; ================================= Constants =================================
11
; ================================= Constants =================================
Line 19... Line 19...
19
; Driver flags. Represent bits in DISK.DriverFlags.
19
; Driver flags. Represent bits in DISK.DriverFlags.
20
DISK_NO_INSERT_NOTIFICATION = 1
20
DISK_NO_INSERT_NOTIFICATION = 1
21
; Media flags. Represent bits in DISKMEDIAINFO.Flags.
21
; Media flags. Represent bits in DISKMEDIAINFO.Flags.
22
DISK_MEDIA_READONLY = 1
22
DISK_MEDIA_READONLY = 1
Line 23... Line 23...
23
 
23
 
24
; If we see too many partitions, probably there is some error on the disk.
24
; If too many partitions are detected,there is probably an error on the disk.
25
; 256 partitions should be enough for any reasonable use.
25
; 256 partitions should be enough for any reasonable use.
26
; Also, the same number is limiting the number of MBRs to process; if we see
26
; Also, the same number is limiting the number of MBRs to process; if
27
; too many MBRs, probably there is a loop in the MBR structure.
27
; too many MBRs are visible,there probably is a loop in the MBR structure.
Line 28... Line 28...
28
MAX_NUM_PARTITIONS = 256
28
MAX_NUM_PARTITIONS = 256
29
 
29
 
30
; =============================================================================
30
; =============================================================================
Line 83... Line 83...
83
; Optional, may be NULL.
83
; Optional, may be NULL.
84
; unsigned int adjust_cache_size(unsigned int suggested_size);
84
; unsigned int adjust_cache_size(unsigned int suggested_size);
85
; Return value: 0 = disable cache, otherwise = used cache size in bytes.
85
; Return value: 0 = disable cache, otherwise = used cache size in bytes.
86
ends
86
ends
Line 87... Line 87...
87
 
87
 
88
; This structure holds an information about a media.
88
; This structure holds information on a medium.
89
; Objects with this structure are allocated by the kernel as a part of DISK
89
; Objects with this structure are allocated by the kernel as a part of the DISK
90
; structure and filled by a driver in the 'querymedia' callback.
90
; structure and are filled by a driver in the 'querymedia' callback.
91
struct DISKMEDIAINFO
91
struct DISKMEDIAINFO
92
.Flags          dd      ?
92
.Flags		dd	?
93
; Combination of DISK_MEDIA_* bits.
93
; Combination of DISK_MEDIA_* bits.
94
.SectorSize     dd      ?
94
.SectorSize	dd	?
95
; Size of the sector.
95
; Size of the sector.
96
.Capacity       dq      ?
96
.Capacity	dq	?
97
; Size of the media in sectors.
97
; Size of the media in sectors.
Line 98... Line 98...
98
ends
98
ends
99
 
99
 
100
; This structure represents disk cache. To follow the old implementation,
100
; This structure represents the disk cache. To follow the old implementation,
101
; there are two distinct caches for a disk, one for "system" data, other
101
; there are two distinct caches for a disk, one for "system" data,and the other
102
; for "application" data.
102
; for "application" data.
103
struct DISKCACHE
103
struct DISKCACHE
104
.Lock           MUTEX
104
.Lock		MUTEX
Line 158... Line 158...
158
; Count of active references to the media object. One reference is kept during
158
; Count of active references to the media object. One reference is kept during
159
; the lifetime of the media between two calls to 'disk_media_changed'.
159
; the lifetime of the media between two calls to 'disk_media_changed'.
160
; Another reference is taken during any filesystem operation for this media.
160
; Another reference is taken during any filesystem operation for this media.
161
; The callback 'closemedia' is called when the reference count decrements to
161
; The callback 'closemedia' is called when the reference count decrements to
162
; zero: this usually occurs in 'disk_media_changed', but can be delayed to the
162
; zero: this usually occurs in 'disk_media_changed', but can be delayed to the
163
; end of last filesystem operation, if one is active.
163
; end of the last filesystem operation, if one is active.
164
.MediaInfo              DISKMEDIAINFO
164
.MediaInfo		DISKMEDIAINFO
165
; This field keeps an information about the current media.
165
; This field keeps information on the current media.
166
.NumPartitions  dd      ?
166
.NumPartitions	dd	?
167
; Number of partitions on this media.
167
; Number of partitions on this media.
168
.Partitions     dd      ?
168
.Partitions	dd	?
169
; Pointer to array of .NumPartitions pointers to PARTITION structures.
169
; Pointer to array of .NumPartitions pointers to PARTITION structures.
170
.cache_size     dd      ?
170
.cache_size	dd	?
Line 225... Line 225...
225
        dd      disk_list
225
	dd	disk_list
226
endg
226
endg
227
uglobal
227
uglobal
228
; This mutex guards all operations with the global list of DISK structures.
228
; This mutex guards all operations with the global list of DISK structures.
229
disk_list_mutex MUTEX
229
disk_list_mutex MUTEX
230
; * There are two dependent objects, a disk and a media. In the simplest case
230
; * There are two dependent objects, a disk and a media. In the simplest case,
231
;   disk and media are both non-removable. However, in the general case both
231
;   disk and media are both non-removable. However, in the general case both
232
;   can be removed at any time, simultaneously or only media, this makes things
232
;   can be removed at any time, simultaneously or only media,and this makes things
233
;   complicated.
233
;   complicated.
234
; * For efficiency, both disk and media objects are located in the one
234
; * For efficiency, both disk and media objects are located in the one
235
;   structure named DISK. However, logically they are different.
235
;   structure named DISK. However, logically they are different.
236
; * The following operations use data of disk object: adding (disk_add);
236
; * The following operations use data of disk object: adding (disk_add);
237
;   deleting (disk_del); filesystem (fs_lfn which eventually calls
237
;   deleting (disk_del); filesystem (fs_lfn which eventually calls
Line 339... Line 339...
339
        pop     eax
339
	pop	eax
340
        call    malloc
340
	call	malloc
341
; 1b. Check the result. If allocation failed, return (go to 9) with eax = 0.
341
; 1b. Check the result. If allocation failed, return (go to 9) with eax = 0.
342
        test    eax, eax
342
	test	eax, eax
343
        jz      .nothing
343
	jz	.nothing
344
; 2. Copy disk name to the DISK structure.
344
; 2. Copy the disk name to the DISK structure.
345
; 2a. Get length of the name, including the terminating zero.
345
; 2a. Get length of the name, including the terminating zero.
346
        mov     ebx, [esp+8+8]  ; ebx = pointer to name
346
	mov	ebx, [esp+8+8]	; ebx = pointer to name
347
        push    eax             ; save allocated pointer to DISK
347
	push	eax		; save allocated pointer to DISK
348
        xor     eax, eax        ; the argument of malloc() is in eax
348
	xor	eax, eax	; the argument of malloc() is in eax
349
@@:
349
@@:
Line 625... Line 625...
625
; The default implementation of DISKFUNC.adjust_cache_size.
625
; The default implementation of DISKFUNC.adjust_cache_size.
626
disk_default_adjust_cache_size:
626
disk_default_adjust_cache_size:
627
        mov     eax, [esp+4]
627
	mov	eax, [esp+4]
628
        ret     4
628
	ret	4
Line 629... Line 629...
629
 
629
 
630
; This is an internal function called from 'disk_media_changed' when new media
630
; This is an internal function called from 'disk_media_changed' when a new media
631
; is detected. It creates the list of partitions for the media.
631
; is detected. It creates the list of partitions for the media.
632
; If media is not partitioned, then the list consists of one partition which
632
; If media is not partitioned, then the list consists of one partition which
633
; covers all the media.
633
; covers all the media.
634
; esi = pointer to the DISK structure.
634
; esi = pointer to the DISK structure.
Line 686... Line 686...
686
        jnz     .mbr_failed
686
	jnz	.mbr_failed
687
; 8. The MBR is treated differently from EBRs. For MBR we additionally need to
687
; 8. The MBR is treated differently from EBRs. For MBR we additionally need to
688
; execute step 9 and possibly step 10.
688
; execute step 9 and possibly step 10.
689
        test    ebp, ebp
689
	test	ebp, ebp
690
        jnz     .mbr
690
	jnz	.mbr
691
; Partition table can be present or not present. In the first case, we just
691
; The partition table can be present or not present. In the first case, we just
692
; read the MBR. In the second case, we just read the bootsector for some
692
; read the MBR. In the second case, we just read the bootsector for a
693
; filesystem.
693
; filesystem.
694
; We use the following algorithm to distinguish between these cases.
694
; The following algorithm is used to distinguish between these cases.
695
; A. If at least one entry of the partition table is invalid, this is
695
; A. If at least one entry of the partition table is invalid, this is
696
;    a bootsector. See the description of 'is_partition_table_entry' for
696
;    a bootsector. See the description of 'is_partition_table_entry' for
697
;    definition of validity.
697
;    definition of validity.
698
; B. If all entries are empty (filesystem type field is zero) and the first
698
; B. If all entries are empty (filesystem type field is zero) and the first
699
;    byte is jmp opcode (0EBh or 0E9h), this is a bootsector which happens to
699
;    byte is jmp opcode (0EBh or 0E9h), this is a bootsector which happens to
700
;    have zeros in the place of partition table.
700
;    have zeros in the place of partition table.
701
; C. Otherwise, this is a MBR.
701
; C. Otherwise, this is an MBR.
702
; 9. Test for MBR vs bootsector.
702
; 9. Test for MBR vs bootsector.
703
; 9a. Check entries. If any is invalid, go to 10 (rule A).
703
; 9a. Check entries. If any is invalid, go to 10 (rule A).
704
        call    is_partition_table_entry
704
	call	is_partition_table_entry
705
        jc      .notmbr
705
	jc	.notmbr
706
        add     ecx, 10h
706
	add	ecx, 10h
Line 722... Line 722...
722
        cmp     byte [ebx], 0EBh
722
	cmp	byte [ebx], 0EBh
723
        jz      .notmbr
723
	jz	.notmbr
724
        cmp     byte [ebx], 0E9h
724
	cmp	byte [ebx], 0E9h
725
        jnz     .mbr
725
	jnz	.mbr
726
.notmbr:
726
.notmbr:
727
; 10. This is not MBR. The media is not partitioned. Create one partition
727
; 10. This is not an  MBR. The media is not partitioned. Create one partition
728
; which covers all the media and abort the loop.
728
; which covers all the media and abort the loop.
729
        stdcall disk_add_partition, 0, 0, \
729
	stdcall disk_add_partition, 0, 0, \
730
                dword [esi+DISK.MediaInfo.Capacity], dword [esi+DISK.MediaInfo.Capacity+4]
730
		dword [esi+DISK.MediaInfo.Capacity], dword [esi+DISK.MediaInfo.Capacity+4]
731
        jmp     .done
731
	jmp	.done
732
.mbr:
732
.mbr: